From 6acf0ef2012b6cbc412efb6958274504bc4c8fce Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 3 Jul 2023 13:39:48 +0100 Subject: Compile val node to IR instructions --- .../java/org/shedlang/compiler/stackir/StackCompiler.java | 14 +++++++++++++- 1 file changed, 13 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 7ff1338a..c0d1b04b 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -99,7 +99,7 @@ public class StackCompiler { compileExpressionStatement(expressionStatement); case TypedValNode val -> - throw new UnsupportedOperationException("TODO"); + compileVal(val); }; } @@ -146,4 +146,16 @@ public class StackCompiler { private static PVector compileStringLiteral(TypedStringLiteralNode node) { return P.vector(new PushStringInstruction(node.value(), node.source())); } + + private static PVector compileTarget(TypedTargetNode target) { + return switch (target) { + case TypedTargetNode.Variable variable -> + P.vector(new LocalStoreInstruction(variable.name(), variable.source())); + }; + } + + private static PVector compileVal(TypedValNode val) { + return compileExpression(val.expression()) + .plusAll(compileTarget(val.target())); + } } -- cgit v1.2.3