Skip to content

Commit 752ba01

Browse files
committed
[truffle] Auto-generate the TAST deserialization for if nodes too
1 parent fbed77a commit 752ba01

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/vm/jvm/Truffle.nqp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ class QAST::OperationsTruffle {
280280
my $cond := $comp.as_truffle($node[0], :want($OBJ));
281281
my $then := $comp.as_truffle($node[1], :want($result_type));
282282

283-
my @tree := [$op_name, $cond.tree, $then.tree];
284-
285-
nqp::push(@tree, $comp.as_truffle($node[2], :want($result_type)).tree) if $operands == 3;
283+
my @tree := $operands == 3
284+
?? [$op_name ~ '-else', $cond.tree, $then.tree, $comp.as_truffle($node[2], :want($result_type)).tree]
285+
!! [$op_name, $cond.tree, $then.tree];
286286

287287
return TAST.new($result_type, @tree);
288288
});

src/vm/jvm/runtime/org/perl6/nqp/truffle/TruffleCompiler.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ public NQPNode build(SixModelObject node, NQPScope scope, ThreadContext tc) {
5757
if (trySimple != null) return trySimple;
5858

5959
switch (node.at_pos_boxed(tc, 0).get_str(tc)) {
60-
case "unless":
61-
case "if":
62-
return new NQPIfNode(
63-
node.at_pos_boxed(tc, 0).get_str(tc) == "unless",
64-
build(node.at_pos_boxed(tc, 1), scope, tc),
65-
build(node.at_pos_boxed(tc, 2), scope, tc),
66-
node.elems(tc) == 4 ? build(node.at_pos_boxed(tc, 3), scope, tc) : null);
6760
case "declare-lexical":
6861
scope.addLexical(node.at_pos_boxed(tc, 1).get_str(tc));
6962
return build(node.at_pos_boxed(tc, 2), scope, tc);

src/vm/jvm/runtime/org/perl6/nqp/truffle/nodes/control/NQPIfNode.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.perl6.nqp.truffle.nodes.NQPNode;
4747
import org.perl6.nqp.truffle.nodes.NQPNodeWithBoolification;
4848

49+
import org.perl6.nqp.dsl.Deserializer;
4950

5051
@NodeInfo(shortName = "if")
5152
public final class NQPIfNode extends NQPNodeWithBoolification {
@@ -88,4 +89,19 @@ public void executeVoid(VirtualFrame frame) {
8889
}
8990
}
9091
}
92+
93+
@Deserializer("if")
94+
public static NQPIfNode createIf(NQPNode condNode, NQPNode thenNode) {
95+
return new NQPIfNode(false, condNode, thenNode, null);
96+
}
97+
98+
@Deserializer("unless")
99+
public static NQPIfNode createUnless(NQPNode condNode, NQPNode thenNode) {
100+
return new NQPIfNode(true, condNode, thenNode, null);
101+
}
102+
103+
@Deserializer("if-else")
104+
public static NQPIfNode createIfElse(NQPNode condNode, NQPNode thenNode, NQPNode elseNode) {
105+
return new NQPIfNode(false, condNode, thenNode, elseNode);
106+
}
91107
}

0 commit comments

Comments
 (0)