aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/stackir
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-03 13:39:48 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-03 13:39:48 +0100
commit6acf0ef2012b6cbc412efb6958274504bc4c8fce (patch)
treeece325ecb6dce8146ff3c41bcab86ebd2fdb1e98 /src/test/java/org/shedlang/compiler/stackir
parent31a177c56a6e0efe9e433567d9c771008e0f47e8 (diff)
Compile val node to IR instructions
Diffstat (limited to 'src/test/java/org/shedlang/compiler/stackir')
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java
new file mode 100644
index 00000000..3126c82b
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java
@@ -0,0 +1,25 @@
+package org.shedlang.compiler.stackir;
+
+import org.junit.jupiter.api.Test;
+import org.shedlang.compiler.ast.typed.Typed;
+
+import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.isSequence;
+
+public class StackCompilerValTests {
+ @Test
+ public void expressionIsEvaluatedAndStoredAsLocal() {
+ var node = Typed.val(
+ Typed.targetVariable("x"),
+ Typed.stringLiteral("hello")
+ );
+
+ var instructions = StackCompiler.compileFunctionStatement(node);
+
+ assertThat(instructions, isSequence(
+ isPushStringInstruction("hello"),
+ isLocalStoreInstruction("x")
+ ));
+ }
+}