Skip to content

Commit 5a60f40

Browse files
committed
Generate better code for NQP's prefix:<!>.
1 parent 6247a45 commit 5a60f40

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/NQP/Grammar.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ grammar NQP::Grammar is HLL::Grammar {
702702
token prefix:sym<~> { <sym> <O('%symbolic_unary, :op<stringify>')> }
703703
token prefix:sym<-> { <sym> <![>]> <!number> <O('%symbolic_unary, :op<neg_n>')> }
704704
token prefix:sym<?> { <sym> <O('%symbolic_unary, :op<istrue>')> }
705-
token prefix:sym<!> { <sym> <O('%symbolic_unary, :op<isfalse>')> }
705+
token prefix:sym<!> { <sym> <O('%symbolic_unary, :op<falsey>')> }
706706
token prefix:sym<|> { <sym> <O('%symbolic_unary')> }
707707

708708
token infix:sym<*> { <sym> <O('%multiplicative, :op<mul_n>')> }

src/NQP/Ops.pm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,19 @@ $ops.add_hll_op('nqp', 'eqaddr', -> $qastcomp, $op {
9595
QAST::Op.new( :op('where'), $op[1] )
9696
))
9797
});
98+
99+
$ops.add_hll_op('nqp', 'falsey', -> $qastcomp, $op {
100+
my $res := $*REGALLOC.fresh_i();
101+
my $ops := PIRT::Ops.new(:result($res));
102+
my $arg_post := $qastcomp.as_post($op[0]);
103+
if nqp::lc($qastcomp.infer_type($arg_post.result)) eq 'i' {
104+
$ops.push($arg_post);
105+
$ops.push_pirop('not', $res, $arg_post);
106+
}
107+
else {
108+
$arg_post := $qastcomp.coerce($arg_post, 'P');
109+
$ops.push($arg_post);
110+
$ops.push_pirop('isfalse', $res, $arg_post);
111+
}
112+
$ops
113+
});

0 commit comments

Comments
 (0)