diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-07 18:32:50 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-07 18:32:50 +0100 |
| commit | 856895255a261a0d21a8b4a0271a75ed3a2cf7ba (patch) | |
| tree | e7a2f83fc9970729970a97ee2581fa9844826e31 /src/test/java | |
| parent | d42333cb45df71c033d8b542f6df5b3b4fcdf8b4 (diff) | |
Add typed int equals node
Diffstat (limited to 'src/test/java')
3 files changed, 42 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java index 18fe79cf..33685c06 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java @@ -47,6 +47,18 @@ public class Typed { ); } + public static TypedBinaryOperationNode intEquals( + TypedExpressionNode left, + TypedExpressionNode right + ) { + return new TypedBinaryOperationNode( + TypedBinaryOperator.INT_EQUALS, + left, + right, + Sources.NULL + ); + } + public static TypedIntLiteralNode intLiteral(int value) { return new TypedIntLiteralNode(BigInteger.valueOf(value), Sources.NULL); } diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntEqualsTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntEqualsTests.java new file mode 100644 index 00000000..805c23ac --- /dev/null +++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntEqualsTests.java @@ -0,0 +1,26 @@ +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 StackCompilerIntEqualsTests { + @Test + public void intEqualsIsCompiledToIntEqualsInstruction() { + var node = Typed.intEquals( + Typed.intLiteral(42), + Typed.intLiteral(47) + ); + + var instructions = StackCompiler.compileExpression(node); + + assertThat(instructions, isSequence( + isPushIntInstruction(42), + isPushIntInstruction(47), + isIntEqualsInstruction() + )); + } +} 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 08f02227..3768c6e1 100644 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java +++ b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java @@ -37,6 +37,10 @@ public class InstructionMatchers { return instanceOf(IntAddInstruction.class); } + public static Matcher<Instruction> isIntEqualsInstruction() { + return instanceOf(IntEqualsInstruction.class); + } + public static Matcher<Instruction> isIntSubInstruction() { return instanceOf(IntSubInstruction.class); } |
