diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-17 19:23:35 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-17 19:23:35 +0100 |
| commit | cb79027f3045b979b964d5dd4e6229a6d0212b0e (patch) | |
| tree | 50daaaa29c8931476c95453a2e6fe1fb8bd9f13b /src/main/java | |
| parent | c8f15e5863666484de5e55a47079688d1f9d625a (diff) | |
Compile tuple target to stack IR
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/stackir/StackCompiler.java | 18 |
1 files changed, 17 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 12a32125..8c5bea8c 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -384,7 +384,23 @@ public class StackCompiler { } case TypedTargetNode.Tuple tuple -> { - throw new UnsupportedOperationException("TODO"); + if (tuple.elements().size() == 0) { + context = context.addInstruction(new DiscardInstruction(tuple.source())); + } + + for (var elementIndex = 0; elementIndex < tuple.elements().size(); elementIndex++) { + if (elementIndex < tuple.elements().size() - 1) { + context = context + .addInstruction(new DuplicateInstruction(tuple.source())); + } + + context = context + .addInstruction(new TupleGetInstruction(elementIndex, tuple.source())); + + context = compileTarget(tuple.elements().get(elementIndex), context); + } + + yield context; } case TypedTargetNode.Val val -> { |
