Skip to content

Commit

Permalink
Resolve all 2-arg conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun committed Dec 7, 2017
1 parent 335ac1c commit 59be332
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions main.nqp
@@ -0,0 +1,3 @@
my $a := 0;
my int $b := $a || 40;
say($b);
25 changes: 13 additions & 12 deletions src/vm/moar/QAST/QASTOperationsMAST.nqp
Expand Up @@ -795,15 +795,15 @@ for <if unless with without> -> $op_name {
push_op(@ins,
resolve_condition_op(@comp_ops[0].result_kind, $op_name eq 'if' || $op_name eq 'with'),
$decont_reg,
($operands == 3 ?? $else_lbl !! $end_lbl)
$else_lbl
);
$regalloc.release_register($decont_reg, $MVM_reg_obj);
}
else {
push_op(@ins,
resolve_condition_op(@comp_ops[0].result_kind, $op_name eq 'if'),
@comp_ops[0].result_reg,
($operands == 3 ?? $else_lbl !! $end_lbl)
$else_lbl
);
}

Expand All @@ -818,7 +818,7 @@ for <if unless with without> -> $op_name {
$res_reg := $regalloc.fresh_register($coercion.result_kind);
push_op(@ins, 'set', $res_reg, $coercion.result_reg);
$res_kind := $coercion.result_kind;
if ($op_name eq 'unless' && $operands == 2 && @comp_ops[0].result_kind != $res_kind) {
if ($operands == 2 && @comp_ops[0].result_kind != $res_kind) {
my $coercion := $qastcomp.coercion(@comp_ops[0],
(nqp::defined($*WANT) ?? $*WANT !! $MVM_reg_obj));
$fix_coercion := $coercion;
Expand All @@ -832,12 +832,12 @@ for <if unless with without> -> $op_name {
}
$regalloc.release_register(@comp_ops[1].result_reg, @comp_ops[1].result_kind);

# Terminate the then branch first.
push_op(@ins, 'goto', $end_lbl);
nqp::push(@ins, $else_lbl);

# Handle else branch (coercion of condition result if 2-arg).
if $operands == 3 {
# Terminate the then branch first.
push_op(@ins, 'goto', $end_lbl);
nqp::push(@ins, $else_lbl);

push_ilist(@ins, @comp_ops[2]);
if !$is_void {
if @comp_ops[2].result_kind != $res_kind {
Expand All @@ -850,14 +850,15 @@ for <if unless with without> -> $op_name {
}
}
$regalloc.release_register(@comp_ops[2].result_reg, @comp_ops[2].result_kind);
} else {
if $fix_coercion {
push_ilist(@ins, $fix_coercion);
push_op(@ins, 'set', $res_reg, $fix_coercion.result_reg);
}
}
$regalloc.release_register(@comp_ops[0].result_reg, @comp_ops[0].result_kind);
nqp::push(@ins, $end_lbl);

if $fix_coercion {
push_ilist(@ins, $fix_coercion);
push_op(@ins, 'set', $res_reg, $fix_coercion.result_reg);
}
nqp::push(@ins, $end_lbl);

MAST::InstructionList.new(@ins, $res_reg, $res_kind)
});
Expand Down

0 comments on commit 59be332

Please sign in to comment.