From af50498623bd37db5f5b60f2828e81b7e50d2ec4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 1 Oct 2023 20:34:41 +0100 Subject: Compile sum type definition to stack IR --- .../org/shedlang/compiler/stackir/StackCompiler.java | 16 +++++++++++++++- 1 file changed, 15 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 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 -- cgit v1.2.3