-
-
Save FROGGS/9bf9c160196cec89f617 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/vm/moar/QAST/QASTOperationsMAST.nqp b/src/vm/moar/QAST/QASTOperationsMAST.nqp | |
index 6972dde..4f74ffd 100644 | |
--- a/src/vm/moar/QAST/QASTOperationsMAST.nqp | |
+++ b/src/vm/moar/QAST/QASTOperationsMAST.nqp | |
@@ -410,6 +410,47 @@ class QAST::MASTOperations { | |
} | |
} | |
+# Chaining. | |
+QAST::MASTOperations.add_core_op('chain', -> $qastcomp, $op { | |
+ # First, we build up the list of nodes in the chain | |
+ my @clist; | |
+ my $cpast := $op; | |
+ while $cpast ~~ QAST::Op && $cpast.op eq 'chain' { | |
+ nqp::push(@clist, $cpast); | |
+ $cpast := $cpast[0]; | |
+ } | |
+ | |
+ my $ops := MAST::InstructionList.new(:result($*REGALLOC.fresh_o())); | |
+ my $endlabel := MAST::Label.new(:name($qastcomp.unique('chain_end_'))); | |
+ | |
+ $cpast := nqp::pop(@clist); | |
+ my $apast := $cpast[0]; | |
+ my $apost := $qastcomp.coerce($qastcomp.as_mast($apast), $MVM_reg_obj); | |
+ $ops.push($apost); | |
+ | |
+ my $more := 1; | |
+ while $more { | |
+ my $bpast := $cpast[1]; | |
+ my $bpost := $qastcomp.coerce($qastcomp.as_mast($bpast), $MVM_reg_obj); | |
+ $ops.push($bpost); | |
+ | |
+ my $name := nqp::escape($cpast.name()); | |
+ push_op($ops, 'call', $name, $apost, $bpost, :result($ops)); | |
+ | |
+ if @clist { | |
+ push_op($ops, 'unless_o', $ops, $endlabel); | |
+ $cpast := nqp::pop(@clist); | |
+ $apost := $bpost; | |
+ } | |
+ else { | |
+ $more := 0; | |
+ } | |
+ } | |
+ | |
+ $ops.push($endlabel); | |
+ $ops | |
+}); | |
+ | |
# Set of sequential statements | |
QAST::MASTOperations.add_core_op('stmts', -> $qastcomp, $op { | |
$qastcomp.as_mast(QAST::Stmts.new( |@($op) )) | |
@@ -2053,8 +2094,9 @@ sub resolve_condition_op($kind, $negated) { | |
nqp::die("unhandled kind $kind") | |
} | |
-sub push_op(@dest, $op, *@args) { | |
+sub push_op(@dest, $op, :$result, *@args) { | |
#$op := $op.name if nqp::istype($op, QAST::Op); | |
+ nqp::push(@dest, MAST::Call.new( :result($result) )) if $result; | |
nqp::push(@dest, MAST::Op.new( | |
:op($op), | |
|@args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<diakopter> $ops.push is wrong, MAST::InstructionList.new(:result is wrong, should leave the .as_mast calls with :want instead of wrapping with .coerce