Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert more BOOTSTRAPATTRs to Attributes #902

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/ChangeLog
Expand Up @@ -27,11 +27,14 @@ New in 2016.10
+ Fixed uncallable Dateish.IO
+ Fixed Exceptions::JSON for exceptions with no `message` method
+ Fixed Exceptions::JSON for exceptions with non-JSON-friendly attributes
+ Proc::Async decoding exceptions are now catchable
+ Prevented return handler being optimized out in `sub { 42.return }()`
+ Fixed error reporting when trying to invoke a native parameter
+ Removals:
+ Removed argument-taking Dateish candidates for is-leap-year,
days-in-month, and day-of-week [were never part of the spec]
+ Additions:
+ Added basic Unicode 9 support (more work needed for full support)
+ Added basic Unicode 9 support (NFG changes for latest TR#29 still to do))
+ X::Proc::Unsuccessful now includes command that was run
+ IO::Handle.new now uses 'utf8' encoding by default
+ Bare `put` now requires parentheses to call as sub
Expand All @@ -50,6 +53,8 @@ New in 2016.10
+ Int.new can now handle any value that can .Int
+ Can now detect and throw on overflow in infix:<*>(int, int)
+ Added shortname() method to CurriedRoleHOW
+ Proc::Async new, stdout, and stderr methods now take :enc
+ IO::Socket::Async listen, connect, and Supply methods now take :enc
+ Efficiency:
+ Made List.reverse about 5% faster
+ Made auto-threading about 10% faster
Expand Down
5 changes: 3 additions & 2 deletions lib/Pod/To/Text.pm6
Expand Up @@ -67,8 +67,9 @@ sub table2text($pod) {
my @rows = $pod.contents;
@rows.unshift($pod.headers.item) if $pod.headers;
my @maxes;
for 0..(@rows[1].elems - 1) -> $i {
@maxes.push([max] @rows.map({ $_[$i].chars }));
my $cols = [max] @rows.map({ .elems });
for 0..^$cols -> $i {
@maxes.push([max] @rows.map({ $i < $_ ?? $_[$i].chars !! 0 }));
}
my $ret;
if $pod.config<caption> {
Expand Down
1 change: 1 addition & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -4036,6 +4036,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
return 0 unless
# It's a simple operation.
nqp::istype($past, QAST::Op)
&& $past.op ne 'callmethod' # May be .return or similar
&& nqp::getcomp('QAST').operations.is_inlinable('perl6', $past.op) ||
# Just a variable lookup.
nqp::istype($past, QAST::Var) ||
Expand Down
77 changes: 42 additions & 35 deletions src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -1368,31 +1368,37 @@ BEGIN {
Proxy.HOW.compose_repr(Proxy);

# Helper for creating a scalar attribute. Sets it up as a real Perl 6
# Attribute instance, complete with container desciptor and auto-viv
# Attribute instance, complete with container descriptor and auto-viv
# container.
sub scalar_attr($name, $type, $package, :$associative_delegate) {
sub scalar_attr($name, $type, $package, :$associative_delegate, :$auto_viv_container = 1) {
my $cd := Perl6::Metamodel::ContainerDescriptor.new(
:of($type), :rw(1), :name($name));
my $scalar := nqp::create(Scalar);
nqp::bindattr($scalar, Scalar, '$!descriptor', $cd);
nqp::bindattr($scalar, Scalar, '$!value', $type);
return Attribute.new( :name($name), :type($type), :package($package),
:container_descriptor($cd), :auto_viv_container($scalar),
:$associative_delegate);
:of($type), :rw(1), :$name);
if $auto_viv_container {
my $scalar := nqp::create(Scalar);
nqp::bindattr($scalar, Scalar, '$!descriptor', $cd);
nqp::bindattr($scalar, Scalar, '$!value', $type);
return Attribute.new( :$name, :$type, :$package,
:container_descriptor($cd), :auto_viv_container($scalar),
:$associative_delegate );
}
else {
return Attribute.new( :$name, :$type, :$package,
:container_descriptor($cd), :$associative_delegate );
}
}

# class Signature is Any{
# has Mu $!params;
# has Mu $!returns;
# has Mu $!arity;
# has Mu $!count;
# has Mu $!code;
Signature.HOW.add_parent(Signature, Any);
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!params>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, Attribute.new(:name<$!params>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!returns>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!arity>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!count>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, BOOTSTRAPATTR.new(:name<$!code>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, Attribute.new(:name<$!arity>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, Attribute.new(:name<$!count>, :type(Mu), :package(Signature)));
Signature.HOW.add_attribute(Signature, Attribute.new(:name<$!code>, :type(Mu), :package(Signature)));
Signature.HOW.add_method(Signature, 'is_generic', nqp::getstaticcode(sub ($self) {
# If any parameter is generic, so are we.
my @params := nqp::getattr($self, Signature, '$!params');
Expand Down Expand Up @@ -1454,19 +1460,19 @@ BEGIN {
# has Mu $!attr_package;
# has Mu $!why;
Parameter.HOW.add_parent(Parameter, Any);
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!variable_name>, :type(str), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, Attribute.new(:name<$!variable_name>, :type(str), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!named_names>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!type_captures>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!flags>, :type(int), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!nominal_type>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, Attribute.new(:name<$!flags>, :type(int), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, Attribute.new(:name<$!nominal_type>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!post_constraints>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!coerce_type>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!coerce_method>, :type(str), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, scalar_attr('$!coerce_type', Mu, Parameter, :!auto_viv_container));
Parameter.HOW.add_attribute(Parameter, Attribute.new(:name<$!coerce_method>, :type(str), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!sub_signature>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!default_value>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!container_descriptor>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!attr_package>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, BOOTSTRAPATTR.new(:name<$!why>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, Attribute.new(:name<$!attr_package>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_attribute(Parameter, Attribute.new(:name<$!why>, :type(Mu), :package(Parameter)));
Parameter.HOW.add_method(Parameter, 'is_generic', nqp::getstaticcode(sub ($self) {
# If nonimnal type or attr_package is generic, so are we.
my $type := nqp::getattr($self, Parameter, '$!nominal_type');
Expand Down Expand Up @@ -1582,7 +1588,7 @@ BEGIN {
Code.HOW.add_parent(Code, Any);
Code.HOW.add_attribute(Code, Attribute.new(:name<$!do>, :type(Mu), :package(Code)));
Code.HOW.add_attribute(Code, Attribute.new(:name<$!signature>, :type(Mu), :package(Code)));
Code.HOW.add_attribute(Code, Attribute.new(:name<$!compstuff>, :type(Mu), :package(Code)));
Code.HOW.add_attribute(Code, scalar_attr('$!compstuff', Mu, Code, :!auto_viv_container));

# Need clone in here, plus generics instantiation.
Code.HOW.add_method(Code, 'clone', nqp::getstaticcode(sub ($self) {
Expand Down Expand Up @@ -1642,7 +1648,7 @@ BEGIN {
# has Mu $!why;
Block.HOW.add_parent(Block, Code);
Block.HOW.add_attribute(Block, BOOTSTRAPATTR.new(:name<$!phasers>, :type(Mu), :package(Block)));
Block.HOW.add_attribute(Block, BOOTSTRAPATTR.new(:name<$!why>, :type(Mu), :package(Block)));
Block.HOW.add_attribute(Block, scalar_attr('$!why', Mu, Block, :!auto_viv_container));
Block.HOW.add_method(Block, 'clone', nqp::getstaticcode(sub ($self) {
my $dcself := nqp::decont($self);
my $cloned := nqp::clone($dcself);
Expand Down Expand Up @@ -1677,16 +1683,16 @@ BEGIN {
# has Mu $!dispatch_order;
# has Mu $!dispatch_cache;
Routine.HOW.add_parent(Routine, Block);
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!dispatchees>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!dispatcher_cache>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!dispatcher>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!rw>, :type(int), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!inline_info>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!yada>, :type(int), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!package>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!onlystar>, :type(int), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!dispatch_order>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, BOOTSTRAPATTR.new(:name<$!dispatch_cache>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!dispatchees>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!dispatcher_cache>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!dispatcher>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!rw>, :type(int), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!inline_info>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!yada>, :type(int), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!package>, :type(Mu), :package(Routine)));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!onlystar>, :type(int), :package(Routine)));
Routine.HOW.add_attribute(Routine, scalar_attr('$!dispatch_order', Mu, Routine, :!auto_viv_container));
Routine.HOW.add_attribute(Routine, Attribute.new(:name<$!dispatch_cache>, :type(Mu), :package(Routine)));

Routine.HOW.add_method(Routine, 'is_dispatcher', nqp::getstaticcode(sub ($self) {
my $dc_self := nqp::decont($self);
Expand Down Expand Up @@ -2748,7 +2754,7 @@ BEGIN {
# class Array is List {
# has Mu $!descriptor;
Array.HOW.add_parent(Array, List);
Array.HOW.add_attribute(Array, BOOTSTRAPATTR.new(:name<$!descriptor>, :type(Mu), :package(Array)));
Array.HOW.add_attribute(Array, scalar_attr('$!descriptor', Mu, Array, :!auto_viv_container));
Array.HOW.compose_repr(Array);

# my class Map is Cool {
Expand All @@ -2760,7 +2766,7 @@ BEGIN {
# my class Hash is Map {
# has Mu $!descriptor;
Hash.HOW.add_parent(Hash, Map);
Hash.HOW.add_attribute(Hash, BOOTSTRAPATTR.new(:name<$!descriptor>, :type(Mu), :package(Hash)));
Hash.HOW.add_attribute(Hash, scalar_attr('$!descriptor', Mu, Hash, :!auto_viv_container));
Hash.HOW.compose_repr(Hash);

# class Capture is Any {
Expand Down Expand Up @@ -2813,6 +2819,7 @@ BEGIN {

# Set up Stash type, which is really just a hash with a name.
# class Stash is Hash {
# has str $!longname;
Stash.HOW.add_parent(Stash, Hash);
Stash.HOW.add_attribute(Stash, Attribute.new(:name<$!longname>, :type(str), :package(Stash)));
Stash.HOW.compose_repr(Stash);
Expand Down
20 changes: 5 additions & 15 deletions src/core/Any-iterable-methods.pm
Expand Up @@ -1891,21 +1891,11 @@ Did you mean to add a stub (\{...\}) or did you mean to .classify?"
)
}
multi method head(Any:D: Int(Cool) $n) {
return () if $n <= 0;

Seq.new( class :: does Iterator {
has Mu $!iter;
has int $!todo;
method !SET-SELF(\list,\todo) {
$!iter = list.iterator;
$!todo = todo;
self
}
method new(\list,\todo) { nqp::create(self)!SET-SELF(list,todo) }
method pull-one() is raw {
$!todo-- ?? $!iter.pull-one !! IterationEnd
}
}.new(self,$n))
nqp::if(
nqp::isle_i($n,0),
(),
Rakudo::Internals.SeqNextNFromIterator(self.iterator,$n)
)
}

proto method tail(|) { * }
Expand Down
6 changes: 5 additions & 1 deletion src/core/Cool.pm
Expand Up @@ -175,8 +175,12 @@ my class Cool { # declared in BOOTSTRAP
self.Stringy.split(|c);
}

proto method match(|) {*}
proto method match(|) {
$/ := nqp::getlexdyn('$/');
{*}
}
multi method match(Cool:D: $target, *%adverbs) {
$/ := nqp::getlexdyn('$/');
self.Stringy.match($target, |%adverbs)
}

Expand Down
14 changes: 12 additions & 2 deletions src/core/Cursor.pm
Expand Up @@ -176,14 +176,24 @@ my class Cursor does NQPCursorRole {
)
}

method CURSOR_MORE($overlap) { # from !cursor_more in nqp
method CURSOR_OVERLAP() { # adapted from !cursor_more in nqp
nqp::stmts(
(my $new := nqp::create(self)),
nqp::bindattr( $new,$?CLASS,'$!shared',$!shared),
nqp::bindattr_i($new,$?CLASS,'$!from',-1),
nqp::bindattr_i($new,$?CLASS,'$!pos',nqp::add_i($!from,1)),
$!regexsub($new)
)
}

method CURSOR_MORE() { # adapted from !cursor_more in nqp
nqp::stmts(
(my $new := nqp::create(self)),
nqp::bindattr( $new,$?CLASS,'$!shared',$!shared),
nqp::bindattr_i($new,$?CLASS,'$!from',-1),
nqp::bindattr_i($new,$?CLASS,'$!pos',
nqp::if(
$overlap || nqp::isge_i($!from,$!pos),
nqp::isge_i($!from,$!pos),
nqp::add_i($!from,1),
$!pos
)
Expand Down