diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 14:30:42 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 14:30:42 +0100 |
| commit | 04fa68550d0826bdfd8a2cf56fdb0ad1df8c15cb (patch) | |
| tree | 694e4e3e73ddfedd9f1619155499e464d241084f /src/main/java/org/shedlang/compiler/stackir | |
| parent | ab91c6113f1b4cbcb3a6adf61fe5c5f19e710a50 (diff) | |
Generate stack IR for struct definition
Diffstat (limited to 'src/main/java/org/shedlang/compiler/stackir')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/stackir/StackCompiler.java | 22 |
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 |
