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 --- .../compiler/stackir/StackCompilerValTests.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/stackir/StackCompilerValTests.java (limited to 'src/test/java/org/shedlang/compiler/stackir') 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") + )); + } +} -- cgit v1.2.3