From 616f475a4cf4c3296028c1fe89e17e0105898f3c Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 7 Jul 2023 18:36:27 +0100 Subject: Add typed int not equal node --- .../org/shedlang/compiler/ast/typed/Typed.java | 12 ++++++++++ .../stackir/StackCompilerIntNotEqualTests.java | 26 ++++++++++++++++++++++ .../stackir/instructions/InstructionMatchers.java | 4 ++++ 3 files changed, 42 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/stackir/StackCompilerIntNotEqualTests.java (limited to 'src/test/java') 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 isIntNotEqualInstruction() { + return instanceOf(IntNotEqualInstruction.class); + } + public static Matcher isIntSubInstruction() { return instanceOf(IntSubInstruction.class); } -- cgit v1.2.3