diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-07 18:36:27 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-07 18:36:27 +0100 |
| commit | 616f475a4cf4c3296028c1fe89e17e0105898f3c (patch) | |
| tree | 4a9d98eb7b7b8d014c308c1f19272129d8c6f33c /src/test/java | |
| parent | 856895255a261a0d21a8b4a0271a75ed3a2cf7ba (diff) | |
Add typed int not equal 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 33685c06..09af73cc 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java @@ -63,6 +63,18 @@ public class Typed { return new TypedIntLiteralNode(BigInteger.valueOf(value), Sources.NULL); } + public static TypedBinaryOperationNode intNotEqual( + TypedExpressionNode left, + TypedExpressionNode right + ) { + return new TypedBinaryOperationNode( + TypedBinaryOperator.INT_NOT_EQUAL, + left, + right, + Sources.NULL + ); + } + public static TypedBinaryOperationNode intSub( TypedExpressionNode left, TypedExpressionNode right diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntNotEqualTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntNotEqualTests.java new file mode 100644 index 00000000..63543b11 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerIntNotEqualTests.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 StackCompilerIntNotEqualTests { + @Test + public void intNotEqualsIsCompiledToIntNotEqualInstruction() { + var node = Typed.intNotEqual( + Typed.intLiteral(42), + Typed.intLiteral(47) + ); + + var instructions = StackCompiler.compileExpression(node); + + assertThat(instructions, isSequence( + isPushIntInstruction(42), + isPushIntInstruction(47), + isIntNotEqualInstruction() + )); + } +} 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 3768c6e1..a47e7c75 100644 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java +++ b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java @@ -41,6 +41,10 @@ public class InstructionMatchers { return instanceOf(IntEqualsInstruction.class); } + public static Matcher<Instruction> isIntNotEqualInstruction() { + return instanceOf(IntNotEqualInstruction.class); + } + public static Matcher<Instruction> isIntSubInstruction() { return instanceOf(IntSubInstruction.class); } |
