From 7c1478a872495fab3333638c3a1960edc2b0ec03 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 5 Jul 2023 22:09:28 +0100 Subject: Compile return statements to stack IR --- .../compiler/stackir/StackCompilerReturnTests.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/stackir/StackCompilerReturnTests.java (limited to 'src/test/java/org/shedlang/compiler/stackir') diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerReturnTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerReturnTests.java new file mode 100644 index 00000000..69a3f735 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerReturnTests.java @@ -0,0 +1,22 @@ +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 StackCompilerReturnTests { + @Test + public void expressionIsEvaluatedAndTheResultDiscarded() { + var node = Typed.return_(Typed.stringLiteral("hello")); + + var instructions = StackCompiler.compileFunctionStatement(node); + + assertThat(instructions, isSequence( + isPushStringInstruction("hello"), + isReturnInstruction() + )); + } +} -- cgit v1.2.3