Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Quick implementation of reverse metaop.
  • Loading branch information
colomon committed Mar 15, 2010
1 parent ef3cd20 commit 01c8cc2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/Perl6/Actions.pm
Expand Up @@ -1918,10 +1918,19 @@ method infixish($/) {
my $sym := ~$<infix><sym>;
my $opsub := "&infix:<$metaop$sym>";
unless %*METAOPGEN{$opsub} {
@BLOCK[0].loadinit.push(
PAST::Op.new( :name('!gen_not_metaop'), $sym,
:pasttype('call') )
);
if $metaop eq '!' {
@BLOCK[0].loadinit.push(
PAST::Op.new( :name('!gen_not_metaop'), $sym,
:pasttype('call') )
);
}
if $metaop eq 'R' {
@BLOCK[0].loadinit.push(
PAST::Op.new( :name('!gen_reverse_metaop'), $sym,
:pasttype('call') )
);
}

%*METAOPGEN{$opsub} := 1;
}
make PAST::Op.new( :name($opsub), :pasttype('call') );
Expand Down
1 change: 1 addition & 0 deletions src/Perl6/Grammar.pm
Expand Up @@ -1216,6 +1216,7 @@ token infix:sym<?? !!> {

# item_assignment is probably wrong, but I don't know how to do what is right...
token infix_prefix_meta_operator:sym<!> { <sym> <O('%item_assignment')> }
token infix_prefix_meta_operator:sym<R> { <sym> <O('%item_assignment')> }

token infix:sym<:=> {
<sym> <O('%item_assignment, :reducecheck<bindish_check>')>
Expand Down
27 changes: 27 additions & 0 deletions src/builtins/metaops.pir
Expand Up @@ -35,6 +35,33 @@ src/builtins/metaops.pir - meta-op operations
.tailcall '&prefix:<!>'($P1)
.end

.sub '!gen_reverse_metaop'
.param string sym
.local string opname, metaname
$S0 = concat sym, '>'
opname = concat '&infix:<', $S0
metaname = concat '&infix:<R', $S0
$P0 = get_global metaname
unless null $P0 goto done
$P1 = box opname
.lex '$opname', $P1
.const 'Sub' metasub = '!reverse_metaop'
$P0 = newclosure metasub
set_global metaname, $P0
done:
.end

# XXX -- we might want this to be a Perl6MultiSub
.sub '!reverse_metaop' :anon :outer('!gen_reverse_metaop')
.param pmc a
.param pmc b
$P0 = find_lex '$opname'
$S0 = $P0
$P0 = get_global $S0
$P1 = $P0(b, a)
.return ($P1)
.end

# Local Variables:
# mode: pir
# fill-column: 100
Expand Down

0 comments on commit 01c8cc2

Please sign in to comment.