aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/stackir
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/shedlang/compiler/stackir')
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackCompiler.java22
1 files changed, 21 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 8e0ec59e..dc171e00 100644
--- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
+++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
@@ -365,7 +365,7 @@ public class StackCompiler {
compileFunctionDefinition(functionDefinition, context);
case TypedStructDefinitionNode structDefinition ->
- throw new UnsupportedOperationException("TODO");
+ compileStructDefinition(structDefinition, context);
};
}
@@ -393,6 +393,26 @@ public class StackCompiler {
return context.addInstruction(instruction);
}
+ private static Context compileStructDefinition(
+ TypedStructDefinitionNode node,
+ Context context
+ ) {
+ var defineStructInstruction = new DefineStructInstruction(
+ node.type(),
+ node.fields().stream()
+ .map(field -> new DefineStructInstruction.Field(field.name(), field.source()))
+ .toList(),
+ node.source()
+ );
+
+ var localName = context.shedVariableToLocal(node.type().name());
+ var storeInstruction = new LocalStoreInstruction(localName, node.source());
+
+ return context
+ .addInstruction(defineStructInstruction)
+ .addInstruction(storeInstruction);
+ }
+
private static Context compileTarget(
TypedTargetNode target,
Context context