Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor of flattening and better handling of duplicate named paramet…

…ers. Decidedly not perfect, but maybe the best we can easily do for now.
  • Loading branch information...
commit 029c30fcca91c20e99ad6f153744a7e2560b7bf6 1 parent 69136a4
@jnthn jnthn authored
View
59 src/Perl6/Actions.pm
@@ -2582,37 +2582,50 @@ class Perl6::Actions is HLL::Actions {
}
method arglist($/) {
- # Build up argument list, hanlding nameds and flattens
- # as we go.
- my $past := PAST::Op.new( :pasttype('call'), :node($/) );
+ my $past := PAST::Op.new( :pasttype('call'), :node($/) );
if $<EXPR> {
+ # Make first pass over arguments, finding any duplicate named
+ # arguments.
my $expr := $<EXPR>.ast;
- if $expr.name eq '&infix:<,>' {
- for $expr.list { $past.push(handle_parameter($_, $/)); }
+ my @args := $expr.name eq '&infix:<,>' ?? $expr.list !! [$expr];
+ my %named_counts;
+ for @args {
+ if $_ ~~ PAST::Op && $_.returns eq 'Pair' {
+ my $name := compile_time_value_str($_[1], 'LHS of pair', $/);
+ %named_counts{$name} := +%named_counts{$name} + 1;
+ $_[2].named($name);
+ }
+ }
+
+ # Make result.
+ for @args {
+ if $_ ~~ PAST::Op && $_.returns eq 'Pair' {
+ my $name := $_[2].named();
+ if %named_counts{$name} == 1 {
+ $past.push($_[2]);
+ $_[2]<before_promotion> := $_;
+ }
+ else {
+ %named_counts{$name} := %named_counts{$name} - 1;
+ }
+ }
+ elsif $_ ~~ PAST::Op && $_.name eq '&prefix:<|>' {
+ $past.push(PAST::Op.new(
+ :pasttype('callmethod'), :name('FLATTENABLE_LIST'),
+ $_[0], :flat(1)));
+ $past.push(PAST::Op.new(
+ :pasttype('callmethod'), :name('FLATTENABLE_HASH'),
+ $_[0], :flat(1), :named(1)));
+ }
+ else {
+ $past.push($_);
+ }
}
- else { $past.push(handle_parameter($expr, $/)); }
}
make $past;
}
- sub handle_parameter($arg, $/) {
- if $arg ~~ PAST::Op && $arg.returns eq 'Pair' {
- my $result := $arg[2];
- $result.named(compile_time_value_str($arg[1], 'LHS of pair', $/));
- $result<before_promotion> := $arg;
- $result;
- }
- elsif $arg ~~ PAST::Op && $arg.name eq '&prefix:<|>' {
- PAST::Op.new(
- :pasttype('callmethod'), :name('ARGLIST_FLATTENABLE'),
- :flat(1), $arg[0]);
- }
- else {
- $arg;
- }
- }
-
method term:sym<value>($/) { make $<value>.ast; }
method circumfix:sym<( )>($/) {
View
2  src/Perl6/ModuleLoader.pm
@@ -16,7 +16,7 @@ class Perl6::ModuleLoader {
if pir::exists($hll_ns, 'PROCESS') && pir::exists($hll_ns<PROCESS>.WHO, '@INC') {
my $INC := ($hll_ns<PROCESS>.WHO)<@INC>;
if pir::defined($INC) {
- my @INC := $INC.ARGLIST_FLATTENABLE();
+ my @INC := $INC.FLATTENABLE_LIST();
if +@INC {
return @INC;
}
View
4 src/core/Capture.pm
@@ -72,8 +72,8 @@ my class Capture {
self.elems
}
- # XXX TODO: Should include the hash part too...
- method ARGLIST_FLATTENABLE() { $!list }
+ method FLATTENABLE_LIST() { $!list ?? $!list !! nqp::list() }
+ method FLATTENABLE_HASH() { $!hash ?? $!hash !! nqp::hash() }
method pairs(Capture:D:) {
(self.list.pairs, self.hash.pairs).flat
View
5 src/core/EnumMap.pm
@@ -80,10 +80,11 @@ my class EnumMap does Associative {
$cap
}
- method ARGLIST_FLATTENABLE() {
+ method FLATTENABLE_LIST() { nqp::list() }
+ method FLATTENABLE_HASH() {
pir::defined($!storage) ||
nqp::bindattr(self, EnumMap, '$!storage', nqp::hash());
- $!storage
+ $!storage
}
method fmt($format = "%s\t\%s", $sep = "\n") {
View
3  src/core/List.pm
@@ -268,7 +268,8 @@ my class List does Positional {
nqp::bindpos($!items, nqp::unbox_i($pos), $v)
}
- method ARGLIST_FLATTENABLE() { self.gimme(*); $!items }
+ method FLATTENABLE_LIST() { self.gimme(*); $!items }
+ method FLATTENABLE_HASH() { nqp::hash() }
multi method DUMP(List:D:) {
self.DUMP-ID() ~ '('
View
3  src/core/Parcel.pm
@@ -98,7 +98,8 @@ my class Parcel does Positional {
self.DUMP-ID() ~ '(:storage(' ~ DUMP($!storage) ~ '))'
}
- method ARGLIST_FLATTENABLE() { $!storage }
+ method FLATTENABLE_LIST() { $!storage }
+ method FLATTENABLE_HASH() { nqp::hash() }
method fmt($format = '%s', $separator = ' ') {
self.list.fmt($format, $separator);
Please sign in to comment.
Something went wrong with that request. Please try again.