diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-01 20:34:41 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-01 20:34:41 +0100 |
| commit | af50498623bd37db5f5b60f2828e81b7e50d2ec4 (patch) | |
| tree | a8aea12ef93e0977a09bf8d300fd8385b2787c6a /src/main/java | |
| parent | c2cdddeb6abc41ed9bf4209aeeb5bbb44eb9b5e2 (diff) | |
Compile sum type definition to stack IR
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/stackir/StackCompiler.java | 16 |
1 files changed, 15 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 72e16389..e4f3d23f 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -385,7 +385,7 @@ public class StackCompiler { compileStructDefinition(structDefinition, context); case TypedSumTypeDefinitionNode sumDefinition -> - throw new UnsupportedOperationException("TODO"); + compileSumTypeDefinition(sumDefinition, context); }; } @@ -433,6 +433,20 @@ public class StackCompiler { .addInstruction(storeInstruction); } + private static Context compileSumTypeDefinition( + TypedSumTypeDefinitionNode node, + Context context + ) { + var defineSumTypeInstruction = new PushUnitInstruction(node.source()); + + var localName = context.shedVariableToLocal(node.type().name()); + var storeInstruction = new LocalStoreInstruction(localName, node.source()); + + return context + .addInstruction(defineSumTypeInstruction) + .addInstruction(storeInstruction); + } + private static Context compileTarget( TypedTargetNode target, Context context |
