diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-02-02 19:57:08 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-02-02 20:13:20 +0000 |
| commit | 67cfee13acaea27b5d4daf5b58ade49d9a14363b (patch) | |
| tree | fb283fe6ae2a5918e74b1dc6ba6af1b9bb77e283 /src/test/java | |
| parent | c318dac1f71e09e6baa2b090264c221f45021868 (diff) | |
Generate Shid instructions for int multiply
Diffstat (limited to 'src/test/java')
3 files changed, 43 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 6c058686..cd65a2c9 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java @@ -189,6 +189,18 @@ public class Typed { return new TypedIntLiteralNode(BigInteger.valueOf(value), Sources.NULL); } + public static TypedBinaryOperationNode intMultiply( + TypedExpressionNode left, + TypedExpressionNode right + ) { + return new TypedBinaryOperationNode( + TypedBinaryOperator.INT_MULTIPLY, + left, + right, + Sources.NULL + ); + } + public static TypedBinaryOperationNode intNotEqual( TypedExpressionNode left, TypedExpressionNode right diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntMultiplyTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntMultiplyTests.java new file mode 100644 index 00000000..41b3ed01 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntMultiplyTests.java @@ -0,0 +1,27 @@ +package org.shedlang.compiler.shid; + +import org.junit.jupiter.api.Test; +import org.shedlang.compiler.ast.typed.Typed; + +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.isSequence; + +public class ShidCodeGenIntMultiplyTests { + @Test + public void intMultiplyIsCompiledToIntMultiplyInstruction() { + var node = Typed.intMultiply( + Typed.intLiteral(42), + Typed.intLiteral(47) + ); + var context = ShidCodeGen.Context.EMPTY; + + var result = ShidCodeGen.compileExpression(node, context); + + assertThat(result.instructions(), isSequence( + isShidPushInt(42), + isShidPushInt(47), + isShidIntMultiply() + )); + } +} diff --git a/src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java b/src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java index 328d3311..715b0b42 100644 --- a/src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java +++ b/src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java @@ -111,6 +111,10 @@ public class ShidMatchers { return instanceOf(ShidIntLessThanOrEqual.class); } + public static Matcher<ShidInstruction> isShidIntMultiply() { + return instanceOf(ShidIntMultiply.class); + } + public static Matcher<ShidInstruction> isShidIntNotEqual() { return instanceOf(ShidIntNotEqual.class); } |
