Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Generate better code for NQP's prefix:<!>.

  • Loading branch information...
commit 5a60f406799bab50062590d6e90d588c9e1ab6d5 1 parent 6247a45
@jnthn jnthn authored
Showing with 17 additions and 1 deletion.
  1. +1 −1  src/NQP/Grammar.pm
  2. +16 −0 src/NQP/Ops.pm
View
2  src/NQP/Grammar.pm
@@ -702,7 +702,7 @@ grammar NQP::Grammar is HLL::Grammar {
token prefix:sym<~> { <sym> <O('%symbolic_unary, :op<stringify>')> }
token prefix:sym<-> { <sym> <![>]> <!number> <O('%symbolic_unary, :op<neg_n>')> }
token prefix:sym<?> { <sym> <O('%symbolic_unary, :op<istrue>')> }
- token prefix:sym<!> { <sym> <O('%symbolic_unary, :op<isfalse>')> }
+ token prefix:sym<!> { <sym> <O('%symbolic_unary, :op<falsey>')> }
token prefix:sym<|> { <sym> <O('%symbolic_unary')> }
token infix:sym<*> { <sym> <O('%multiplicative, :op<mul_n>')> }
View
16 src/NQP/Ops.pm
@@ -95,3 +95,19 @@ $ops.add_hll_op('nqp', 'eqaddr', -> $qastcomp, $op {
QAST::Op.new( :op('where'), $op[1] )
))
});
+
+$ops.add_hll_op('nqp', 'falsey', -> $qastcomp, $op {
+ my $res := $*REGALLOC.fresh_i();
+ my $ops := PIRT::Ops.new(:result($res));
+ my $arg_post := $qastcomp.as_post($op[0]);
+ if nqp::lc($qastcomp.infer_type($arg_post.result)) eq 'i' {
+ $ops.push($arg_post);
+ $ops.push_pirop('not', $res, $arg_post);
+ }
+ else {
+ $arg_post := $qastcomp.coerce($arg_post, 'P');
+ $ops.push($arg_post);
+ $ops.push_pirop('isfalse', $res, $arg_post);
+ }
+ $ops
+});
Please sign in to comment.
Something went wrong with that request. Please try again.