Skip to content

Commit 89dcd17

Browse files
committed
Simplify loop code-gen on Moar.
Don't need to keep result type of block at this level; it's not what NQP nor Rakudo need. Means we can convey more void context.
1 parent c6b76b9 commit 89dcd17

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/vm/moar/QAST/QASTOperationsMAST.nqp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -940,18 +940,17 @@ for ('', 'repeat_') -> $repness {
940940
QAST::Var.new( :name($cond_temp), :scope('local') ));
941941
}
942942

943-
# Compile each of the children; we'll need to look at the result
944-
# types and pick an overall result type if in non-void context.
943+
# Compile each of the children.
945944
my @comp_ops;
946945
my @comp_types;
947946
for @children {
948-
my $comp := $qastcomp.as_mast($_);
947+
my $comp := nqp::elems(@comp_ops) == 0
948+
?? $qastcomp.as_mast($_)
949+
!! $qastcomp.as_mast($_, :want($MVM_reg_void));
949950
@comp_ops.push($comp);
950951
@comp_types.push($comp.result_kind);
951952
}
952-
my $res_kind := @comp_types[0] == @comp_types[1]
953-
?? @comp_types[0]
954-
!! $MVM_reg_obj;
953+
my $res_kind := @comp_types[0];
955954
my $res_reg := $*REGALLOC.fresh_register($res_kind);
956955

957956
# Check operand count.
@@ -962,7 +961,6 @@ for ('', 'repeat_') -> $repness {
962961
# Test the condition and jump to the loop end if it's
963962
# not met.
964963
my @loop_il;
965-
my $coerced := $qastcomp.coerce(@comp_ops[0], $res_kind);
966964
if $repness {
967965
# It's a repeat_ variant, need to go straight into the
968966
# loop body unconditionally. Be sure to set the register
@@ -984,8 +982,8 @@ for ('', 'repeat_') -> $repness {
984982
push_op(@loop_il, 'goto', $redo_lbl);
985983
}
986984
nqp::push(@loop_il, $test_lbl);
987-
push_ilist(@loop_il, $coerced);
988-
push_op(@loop_il, 'set', $res_reg, $coerced.result_reg);
985+
push_ilist(@loop_il, @comp_ops[0]);
986+
push_op(@loop_il, 'set', $res_reg, @comp_ops[0].result_reg);
989987
if @comp_ops[0].result_kind == $MVM_reg_obj {
990988
push_op(@loop_il, 'decont', @comp_ops[0].result_reg, @comp_ops[0].result_reg);
991989
}
@@ -1004,7 +1002,6 @@ for ('', 'repeat_') -> $repness {
10041002
my $body := $qastcomp.coerce(@comp_ops[1], $res_kind);
10051003
nqp::push(@loop_il, $redo_lbl);
10061004
push_ilist(@loop_il, $body);
1007-
push_op(@loop_il, 'set', $res_reg, $body.result_reg);
10081005

10091006
# If there's a third child, evaluate it as part of the
10101007
# "next".

0 commit comments

Comments
 (0)