From 1232307b381528fd21411a602e7a125fdee1fffb Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 17 Sep 2023 18:14:17 +0100 Subject: Compile tuple expression into stack IR --- .../java/org/shedlang/compiler/stackir/StackCompiler.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java index 61932ada..12a32125 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -134,7 +134,7 @@ public class StackCompiler { compileStringLiteral(typedStringLiteralNode, context); case TypedTupleNode typedTupleNode -> - throw new UnsupportedOperationException("TODO"); + compileTuple(typedTupleNode, context); }; } @@ -414,6 +414,15 @@ public class StackCompiler { }; } + private static Context compileTuple(TypedTupleNode node, Context context) { + for (var elementNode : node.elements()) { + context = compileExpression(elementNode, context); + } + + var instruction = new TupleCreateInstruction(node.elements().size(), node.source()); + return context.addInstruction(instruction); + } + private static Context compileWhile(TypedWhileNode node, Context context) { context = context.enterBlock(node.body().boundVariableNames()); context = compileBlockWithoutYield(node.body(), context); -- cgit v1.2.3