aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-09-17 18:14:17 +0100
committerMichael Williamson <mike@zwobble.org>2023-09-17 18:14:17 +0100
commit1232307b381528fd21411a602e7a125fdee1fffb (patch)
tree1a19c2bdd65903e05748c6590e8d1eed1f3ffc4e /src/main/java
parentc2b45daf5ddab7b518aed9a51026a599fe4bccef (diff)
Compile tuple expression into stack IR
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackCompiler.java11
1 files changed, 10 insertions, 1 deletions
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);