aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/stackir
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-10 10:10:02 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-10 10:10:02 +0100
commite7025e11b5718393d776e42ec83bef1521bf8a20 (patch)
treed20d98a46674c209b60c184a51b2b9dd5d51f222 /src/test/java/org/shedlang/compiler/stackir
parent4a550a5ae083518815ec70c73346705f3778df93 (diff)
Compile int literal to stack instruction
Diffstat (limited to 'src/test/java/org/shedlang/compiler/stackir')
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/StackCompilerIntLiteralTests.java21
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java9
2 files changed, 30 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntLiteralTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntLiteralTests.java
new file mode 100644
index 00000000..38448bb9
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntLiteralTests.java
@@ -0,0 +1,21 @@
+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.isPushIntInstruction;
+import static org.zwobble.precisely.AssertThat.assertThat;
+import static org.zwobble.precisely.Matchers.isSequence;
+
+public class StackCompilerIntLiteralTests {
+ @Test
+ public void intLiteralIsCompiledToPushIntInstruction() {
+ var node = Typed.intLiteral(42);
+
+ var instructions = StackCompiler.compileExpression(node);
+
+ assertThat(instructions, isSequence(
+ isPushIntInstruction(42)
+ ));
+ }
+}
diff --git a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java
index 7b90c614..053cf645 100644
--- a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java
+++ b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java
@@ -2,6 +2,8 @@ package org.shedlang.compiler.stackir.instructions;
import org.zwobble.precisely.Matcher;
+import java.math.BigInteger;
+
import static org.zwobble.precisely.Matchers.*;
public class InstructionMatchers {
@@ -14,4 +16,11 @@ public class InstructionMatchers {
has("value", x -> x.value(), equalTo(value))
);
}
+
+ public static Matcher<Instruction> isPushIntInstruction(int value) {
+ return instanceOf(
+ PushIntInstruction.class,
+ has("value", x -> x.value(), equalTo(BigInteger.valueOf(value)))
+ );
+ }
}