Skip to content

Commit 98a7d2e

Browse files
committed
Handle arity-1 loop constructs.
1 parent 800df5e commit 98a7d2e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,11 @@ for ('', 'repeat_') -> $repness {
10221022
nqp::die("Operation '$repness$op_name' needs 2 or 3 operands");
10231023
}
10241024

1025+
# See if there's an immediate block wanting to be passed the condition.
1026+
my $has_im := nqp::istype(@operands[1], QAST::Block) &&
1027+
@operands[1].blocktype eq 'immediate' &&
1028+
@operands[1].arity > 0;
1029+
10251030
# Create labels.
10261031
my $while_id := $qastcomp.unique($op_name);
10271032
my $test_lbl := JAST::Label.new( :name($while_id ~ '_test') );
@@ -1049,6 +1054,20 @@ for ('', 'repeat_') -> $repness {
10491054
my $cond_res := $qastcomp.as_jast_in_handler(@operands[0], $l_handler_id || $*HANDLER_IDX);
10501055
$testil.append($cond_res.jast);
10511056
$*STACK.obtain($testil, $cond_res);
1057+
if $has_im {
1058+
my $im_local := QAST::Node.unique('__IM_');
1059+
$*BLOCK.add_local(QAST::Var.new(
1060+
:name($im_local),
1061+
:returns(typeobj_from_rttype($cond_res.type))
1062+
));
1063+
@operands[1].blocktype('declaration');
1064+
@operands[1] := QAST::Op.new(
1065+
:op('call'), @operands[1],
1066+
QAST::Var.new( :name($im_local), :scope('local') )
1067+
);
1068+
$testil.append(dup_ins($cond_res.type));
1069+
$testil.append(JAST::Instruction.new( :op(store_ins($cond_res.type)), $im_local ));
1070+
}
10521071

10531072
# Compile loop body, then do any analysis of result type if
10541073
# in non-void context.

0 commit comments

Comments
 (0)