Skip to content

Commit

Permalink
Implement ||= and &&=, and re-work //= to short-circuit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Mar 17, 2009
1 parent 1ea27f2 commit b117c67
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
17 changes: 0 additions & 17 deletions src/builtins/assign.pir
Expand Up @@ -202,23 +202,6 @@ src/builtins/assign.pir - assignments
.end
=item infix:<//=>
Implemented here as infix:// reduces to a PAST node rather than a call.
=cut
.sub 'infix://='
.param pmc a
.param pmc b
$I0 = 'defined'(a)
if $I0 goto done
'infix:='(a, b)
done:
.return (a)
.end
.sub '!REDUCEMETAOPCHAIN'
.param string opname
.param string identity
Expand Down
14 changes: 14 additions & 0 deletions src/parser/actions.pm
Expand Up @@ -2586,6 +2586,20 @@ method EXPR($/, $key) {
$past.flat(1);
make $past;
}
elsif ~$type eq 'infix://=' || ~$type eq 'infix:||=' || ~$type eq 'infix:&&=' {
my $lhs := $( $/[0] );
my $rhs := $( $/[1] );
make PAST::Op.new(
:pasttype('call'),
:name('infix:='),
$lhs,
PAST::Op.new($lhs, $rhs, :pasttype(
~$type eq 'infix://=' ?? 'def_or' !!
(~$type eq 'infix:||=' ?? 'unless' !!
'if'))
)
);
}
else {
my $past := PAST::Op.new(
:node($/),
Expand Down
2 changes: 2 additions & 0 deletions src/parser/grammar-oper.pg
Expand Up @@ -144,6 +144,8 @@ proto infix:<::=> is equiv(infix:<:=>) { ... }
proto infix:<.=> is equiv(infix:<:=>) { ... }
proto infix:«=>» is equiv(infix:<:=>) { ... }
proto infix:<//=> is equiv(infix:<:=>) { ... }
proto infix:<&&=> is equiv(infix:<:=>) { ... }
proto infix:<||=> is equiv(infix:<:=>) { ... }

## loose unary
proto prefix:<true> is precedence('h=') is subname('true') { ... }
Expand Down

0 comments on commit b117c67

Please sign in to comment.