From 7fd41e35c1a5a700555ad92c47a303764221dc3b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 15 Dec 2023 11:04:35 +0000 Subject: Update naming for Shid matchers --- .../compiler/shid/ShidCodeGenAssignTests.java | 32 +-- .../compiler/shid/ShidCodeGenBlockReturnTests.java | 4 +- .../compiler/shid/ShidCodeGenBoolLiteralTests.java | 4 +- .../compiler/shid/ShidCodeGenBreakTests.java | 6 +- .../compiler/shid/ShidCodeGenCallTests.java | 14 +- .../shid/ShidCodeGenEffectDefinitionTests.java | 4 +- .../shid/ShidCodeGenExpressionStatementTests.java | 8 +- .../compiler/shid/ShidCodeGenFieldAccessTests.java | 17 +- .../shid/ShidCodeGenFunctionDefinitionTests.java | 26 +-- .../shid/ShidCodeGenFunctionExpressionTests.java | 22 +- .../shid/ShidCodeGenFunctionReturnTests.java | 6 +- .../shedlang/compiler/shid/ShidCodeGenIfTests.java | 44 ++-- .../compiler/shid/ShidCodeGenIntAddTests.java | 10 +- .../compiler/shid/ShidCodeGenIntEqualsTests.java | 8 +- .../compiler/shid/ShidCodeGenIntLiteralTests.java | 4 +- .../compiler/shid/ShidCodeGenIntNotEqualTests.java | 8 +- .../compiler/shid/ShidCodeGenIntSubTests.java | 8 +- .../compiler/shid/ShidCodeGenNamespaceTests.java | 34 +-- .../compiler/shid/ShidCodeGenReferenceTests.java | 10 +- .../compiler/shid/ShidCodeGenResumeTests.java | 6 +- .../compiler/shid/ShidCodeGenStringAddTests.java | 8 +- .../shid/ShidCodeGenStringLiteralTests.java | 4 +- .../shid/ShidCodeGenStructDefinitionTests.java | 4 +- .../shid/ShidCodeGenSumTypeDefinitionTests.java | 8 +- .../compiler/shid/ShidCodeGenTryTests.java | 8 +- .../compiler/shid/ShidCodeGenTupleTests.java | 10 +- .../compiler/shid/ShidCodeGenUnitLiteralTests.java | 4 +- .../compiler/shid/ShidCodeGenValTests.java | 54 ++--- .../compiler/shid/ShidCodeGenVarTests.java | 6 +- .../compiler/shid/ShidCodeGenWhenTests.java | 18 +- .../compiler/shid/ShidCodeGenWhileTests.java | 46 ++-- .../shid/instructions/InstructionMatchers.java | 246 --------------------- .../compiler/shid/instructions/ShidMatchers.java | 246 +++++++++++++++++++++ 33 files changed, 469 insertions(+), 468 deletions(-) delete mode 100644 src/test/java/org/shedlang/compiler/shid/instructions/InstructionMatchers.java create mode 100644 src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenAssignTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenAssignTests.java index 65e30e5a..caf83bc2 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenAssignTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenAssignTests.java @@ -5,7 +5,7 @@ import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -22,8 +22,8 @@ public class ShidCodeGenAssignTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("x__0"), - isDiscardInstruction() + isShidLocalLoad("x__0"), + isShidDiscard() )); } @@ -39,8 +39,8 @@ public class ShidCodeGenAssignTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isVarStoreInstruction("x__0") + isShidPushString("hello"), + isShidVarStore("x__0") )); } @@ -63,15 +63,15 @@ public class ShidCodeGenAssignTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("x__0"), - isDuplicateInstruction(), - isTupleGetInstruction(0), - isLocalStoreInstruction("a__0"), - isDuplicateInstruction(), - isTupleGetInstruction(1), - isLocalStoreInstruction("b__0"), - isTupleGetInstruction(2), - isLocalStoreInstruction("c__0") + isShidLocalLoad("x__0"), + isShidDuplicate(), + isShidTupleGet(0), + isShidLocalStore("a__0"), + isShidDuplicate(), + isShidTupleGet(1), + isShidLocalStore("b__0"), + isShidTupleGet(2), + isShidLocalStore("c__0") )); } @@ -87,8 +87,8 @@ public class ShidCodeGenAssignTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("x__0"), - isDiscardInstruction() + isShidLocalLoad("x__0"), + isShidDiscard() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBlockReturnTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBlockReturnTests.java index 082560b7..d5da9edd 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBlockReturnTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBlockReturnTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.isPushStringInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushString; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -16,7 +16,7 @@ public class ShidCodeGenBlockReturnTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello") + isShidPushString("hello") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBoolLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBoolLiteralTests.java index 965f9b3c..2949ec70 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBoolLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBoolLiteralTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.isPushBoolInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushBool; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -16,7 +16,7 @@ public class ShidCodeGenBoolLiteralTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushBoolInstruction(true) + isShidPushBool(true) )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBreakTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBreakTests.java index 90823945..aa931f9e 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBreakTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenBreakTests.java @@ -6,7 +6,7 @@ import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.UserDefinedEffect; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -22,8 +22,8 @@ public class ShidCodeGenBreakTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isBreakInstruction(EFFECT) + isShidPushString("hello"), + isShidEffectHandlerBreak(EFFECT) )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenCallTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenCallTests.java index 5d14cc31..e315b752 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenCallTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenCallTests.java @@ -5,7 +5,7 @@ import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -30,12 +30,12 @@ public class ShidCodeGenCallTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("f__0"), - isPushStringInstruction("p1"), - isPushStringInstruction("p2"), - isPushStringInstruction("n2"), - isPushStringInstruction("n1"), - isCallInstruction(2, List.of("x2", "x1")) + isShidLocalLoad("f__0"), + isShidPushString("p1"), + isShidPushString("p2"), + isShidPushString("n2"), + isShidPushString("n1"), + isShidCall(2, List.of("x2", "x1")) )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenEffectDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenEffectDefinitionTests.java index 4777f5a7..af601953 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenEffectDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenEffectDefinitionTests.java @@ -6,7 +6,7 @@ import org.shedlang.compiler.shid.instructions.ShidDefineEffect; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalStoreInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidLocalStore; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -25,7 +25,7 @@ public class ShidCodeGenEffectDefinitionTests { ShidDefineEffect.class, has("effect", x -> x.effect(), equalTo(effect)) ), - isLocalStoreInstruction("State__0") + isShidLocalStore("State__0") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenExpressionStatementTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenExpressionStatementTests.java index 05a47d39..8d3735f6 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenExpressionStatementTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenExpressionStatementTests.java @@ -3,8 +3,8 @@ 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.InstructionMatchers.isDiscardInstruction; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushStringInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidDiscard; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushString; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -17,8 +17,8 @@ public class ShidCodeGenExpressionStatementTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isDiscardInstruction() + isShidPushString("hello"), + isShidDiscard() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java index 0e869445..27559724 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java @@ -3,12 +3,13 @@ package org.shedlang.compiler.shid; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.shid.instructions.ShidFieldLoad; +import org.shedlang.compiler.shid.instructions.ShidMatchers; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isFieldLoadInstruction; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalLoadInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidFieldLoad; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidLocalLoad; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -27,8 +28,8 @@ public class ShidCodeGenFieldAccessTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("Project__0"), - isFieldLoadInstruction( + isShidLocalLoad("Project__0"), + ShidMatchers.isShidFieldLoad( new ShidFieldLoad.Receiver.Namespace(namespaceType.namespaceName()), "name" ) @@ -49,8 +50,8 @@ public class ShidCodeGenFieldAccessTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("user__0"), - isFieldLoadInstruction(structType, "name") + isShidLocalLoad("user__0"), + isShidFieldLoad(structType, "name") )); } @@ -68,8 +69,8 @@ public class ShidCodeGenFieldAccessTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("State__0"), - isFieldLoadInstruction( + isShidLocalLoad("State__0"), + ShidMatchers.isShidFieldLoad( new ShidFieldLoad.Receiver.Effect(effect), "read" ) diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionDefinitionTests.java index e0c63896..e26551b7 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionDefinitionTests.java @@ -6,7 +6,7 @@ import org.shedlang.compiler.ast.typed.TypedFunctionDefinitionNode; import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -31,22 +31,22 @@ public class ShidCodeGenFunctionDefinitionTests { ShidDefineFunction.class, has("name", x -> x.name(), equalTo("f")), has("positionalParams", x -> x.positionalParams(), isSequence( - isDefineFunctionInstructionParam("x__0") + isShidDefineFunction("x__0") )), has("namedParams", x -> x.namedParams(), isSequence( - isDefineFunctionInstructionParam("y__0") + isShidDefineFunction("y__0") )), has("freeVariables", x -> x.freeVariables(), containsExactly( has("name", x -> x.name(), equalTo("z__0")) )), - has("body", x -> x.body(), isBlockInstruction(isSequence( - isPushStringInstruction("hello"), - isDiscardInstruction(), - isPushUnitInstruction(), - isReturnInstruction() + has("body", x -> x.body(), isShidBlock(isSequence( + isShidPushString("hello"), + isShidDiscard(), + isShidPushUnit(), + isShidReturn() ))) ), - isLocalStoreInstruction("f__0") + isShidLocalStore("f__0") )); } @@ -64,12 +64,12 @@ public class ShidCodeGenFunctionDefinitionTests { assertThat(result.instructions(), isSequence( instanceOf( ShidDefineFunction.class, - has("body", x -> x.body(), isBlockInstruction(isSequence( - isPushStringInstruction("hello"), - isReturnInstruction() + has("body", x -> x.body(), isShidBlock(isSequence( + isShidPushString("hello"), + isShidReturn() ))) ), - isLocalStoreInstruction("f__0") + isShidLocalStore("f__0") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionExpressionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionExpressionTests.java index 2783a389..ae7c42f1 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionExpressionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionExpressionTests.java @@ -6,7 +6,7 @@ import org.shedlang.compiler.ast.typed.TypedFunctionExpressionNode; import org.shedlang.compiler.shid.instructions.ShidDefineFunction; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -30,19 +30,19 @@ public class ShidCodeGenFunctionExpressionTests { ShidDefineFunction.class, has("name", x -> x.name(), equalTo("anonymous")), has("positionalParams", x -> x.positionalParams(), isSequence( - isDefineFunctionInstructionParam("x__0") + isShidDefineFunction("x__0") )), has("namedParams", x -> x.namedParams(), isSequence( - isDefineFunctionInstructionParam("y__0") + isShidDefineFunction("y__0") )), has("freeVariables", x -> x.freeVariables(), containsExactly( has("name", x -> x.name(), equalTo("z__0")) )), - has("body", x -> x.body(), isBlockInstruction(isSequence( - isPushStringInstruction("hello"), - isDiscardInstruction(), - isPushUnitInstruction(), - isReturnInstruction() + has("body", x -> x.body(), isShidBlock(isSequence( + isShidPushString("hello"), + isShidDiscard(), + isShidPushUnit(), + isShidReturn() ))) ) )); @@ -61,9 +61,9 @@ public class ShidCodeGenFunctionExpressionTests { assertThat(result.instructions(), isSequence( instanceOf( ShidDefineFunction.class, - has("body", x -> x.body(), isBlockInstruction(isSequence( - isPushStringInstruction("hello"), - isReturnInstruction() + has("body", x -> x.body(), isShidBlock(isSequence( + isShidPushString("hello"), + isShidReturn() ))) ) )); diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionReturnTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionReturnTests.java index d6a63c1f..ddef4d90 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionReturnTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFunctionReturnTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -16,8 +16,8 @@ public class ShidCodeGenFunctionReturnTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isReturnInstruction() + isShidPushString("hello"), + isShidReturn() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIfTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIfTests.java index df07214d..8f21f322 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIfTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIfTests.java @@ -6,7 +6,7 @@ import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -33,15 +33,15 @@ public class ShidCodeGenIfTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("c__0"), - isIfInstruction( - isBlockInstruction(isSequence( - isPushIntInstruction(42) + isShidLocalLoad("c__0"), + isShidIf( + isShidBlock(isSequence( + isShidPushInt(42) )), - isBlockInstruction(isSequence( - isBlockInstruction(isSequence( - isPushStringInstruction("x"), - isReturnInstruction() + isShidBlock(isSequence( + isShidBlock(isSequence( + isShidPushString("x"), + isShidReturn() )) )) ) @@ -77,21 +77,21 @@ public class ShidCodeGenIfTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("c__0"), - isIfInstruction( - isBlockInstruction(isSequence( - isPushIntInstruction(42) + isShidLocalLoad("c__0"), + isShidIf( + isShidBlock(isSequence( + isShidPushInt(42) )), - isBlockInstruction(isSequence( - isLocalLoadInstruction("d__0"), - isIfInstruction( - isBlockInstruction(isSequence( - isPushIntInstruction(1) + isShidBlock(isSequence( + isShidLocalLoad("d__0"), + isShidIf( + isShidBlock(isSequence( + isShidPushInt(1) )), - isBlockInstruction(isSequence( - isBlockInstruction(isSequence( - isPushStringInstruction("x"), - isReturnInstruction() + isShidBlock(isSequence( + isShidBlock(isSequence( + isShidPushString("x"), + isShidReturn() )) )) ) diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntAddTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntAddTests.java index 4ff0e6eb..631e372c 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntAddTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntAddTests.java @@ -3,8 +3,8 @@ 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.InstructionMatchers.isIntAddInstruction; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushIntInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidIntAdd; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushInt; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -20,9 +20,9 @@ public class ShidCodeGenIntAddTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushIntInstruction(42), - isPushIntInstruction(47), - isIntAddInstruction() + isShidPushInt(42), + isShidPushInt(47), + isShidIntAdd() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntEqualsTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntEqualsTests.java index 464e73f4..68265547 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntEqualsTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntEqualsTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -19,9 +19,9 @@ public class ShidCodeGenIntEqualsTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushIntInstruction(42), - isPushIntInstruction(47), - isIntEqualsInstruction() + isShidPushInt(42), + isShidPushInt(47), + isShidIntEquals() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntLiteralTests.java index ed95e765..e9b85302 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntLiteralTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.isPushIntInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushInt; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -16,7 +16,7 @@ public class ShidCodeGenIntLiteralTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushIntInstruction(42) + isShidPushInt(42) )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntNotEqualTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntNotEqualTests.java index 9c55f222..6c645ea4 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntNotEqualTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntNotEqualTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -19,9 +19,9 @@ public class ShidCodeGenIntNotEqualTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushIntInstruction(42), - isPushIntInstruction(47), - isIntNotEqualInstruction() + isShidPushInt(42), + isShidPushInt(47), + isShidIntNotEqual() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntSubTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntSubTests.java index df3e9791..6cd3495a 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntSubTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenIntSubTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -19,9 +19,9 @@ public class ShidCodeGenIntSubTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushIntInstruction(42), - isPushIntInstruction(47), - isIntSubInstruction() + isShidPushInt(42), + isShidPushInt(47), + isShidIntSub() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java index 8caf7ba6..1e6a1000 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java @@ -8,7 +8,7 @@ import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -33,7 +33,7 @@ public class ShidCodeGenNamespaceTests { var shidNamespace = ShidCodeGen.compileNamespace(node); - assertThat(shidNamespace.body(), isBlockInstruction(isSequence( + assertThat(shidNamespace.body(), isShidBlock(isSequence( // TODO: test the builtin loading properly instanceOf(ShidNamespaceImport.class), instanceOf(ShidFieldLoad.class), @@ -43,9 +43,9 @@ public class ShidCodeGenNamespaceTests { ShidDefineFunction.class, has("name", x -> x.name(), equalTo("f")) ), - isLocalStoreInstruction("f__0"), - isLocalLoadInstruction("f__0"), - isNamespaceFieldStoreInstruction(namespaceName, "f") + isShidLocalStore("f__0"), + isShidLocalLoad("f__0"), + isShidNamespaceFieldStore(namespaceName, "f") ))); } @@ -60,16 +60,16 @@ public class ShidCodeGenNamespaceTests { var shidNamespace = ShidCodeGen.compileNamespace(node); - assertThat(shidNamespace.body(), isBlockInstruction(isSequence( + assertThat(shidNamespace.body(), isShidBlock(isSequence( // TODO: test the builtin loading properly instanceOf(ShidNamespaceImport.class), instanceOf(ShidFieldLoad.class), instanceOf(ShidLocalStore.class), - isNamespaceImportInstruction(NamespaceName.of("A")), - isLocalStoreInstruction("A__0"), - isNamespaceImportInstruction(NamespaceName.of("B")), - isLocalStoreInstruction("B__0") + isShidNamespaceImport(NamespaceName.of("A")), + isShidLocalStore("A__0"), + isShidNamespaceImport(NamespaceName.of("B")), + isShidLocalStore("B__0") ))); } @@ -93,7 +93,7 @@ public class ShidCodeGenNamespaceTests { var shidNamespace = ShidCodeGen.compileNamespace(node); - assertThat(shidNamespace.body(), isBlockInstruction(isSequence( + assertThat(shidNamespace.body(), isShidBlock(isSequence( // TODO: test the builtin loading properly instanceOf(ShidNamespaceImport.class), instanceOf(ShidFieldLoad.class), @@ -103,16 +103,16 @@ public class ShidCodeGenNamespaceTests { ShidDefineStruct.class, has("type", x -> x.type(), equalTo(structType)) ), - isLocalStoreInstruction("None__0"), + isShidLocalStore("None__0"), instanceOf( ShidDefineFunction.class, has("name", x -> x.name(), equalTo("f")) ), - isLocalStoreInstruction("f__0"), - isLocalLoadInstruction("f__0"), - isNamespaceFieldStoreInstruction(namespaceName, "f"), - isLocalLoadInstruction("None__0"), - isNamespaceFieldStoreInstruction(namespaceName, "None") + isShidLocalStore("f__0"), + isShidLocalLoad("f__0"), + isShidNamespaceFieldStore(namespaceName, "f"), + isShidLocalLoad("None__0"), + isShidNamespaceFieldStore(namespaceName, "None") ))); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java index c60d54de..2cad5cb5 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.BoundVariable; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -18,7 +18,7 @@ public class ShidCodeGenReferenceTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("x__0") + isShidLocalLoad("x__0") )); } @@ -35,9 +35,9 @@ public class ShidCodeGenReferenceTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushIntInstruction(0), - isVarStoreInstruction("x__0"), - isVarLoadInstruction("x__0") + isShidPushInt(0), + isShidVarStore("x__0"), + isShidVarLoad("x__0") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenResumeTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenResumeTests.java index 6992783d..727d07a4 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenResumeTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenResumeTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -16,8 +16,8 @@ public class ShidCodeGenResumeTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isResumeInstruction() + isShidPushString("hello"), + isShidResume() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringAddTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringAddTests.java index 56b2750e..387839a7 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringAddTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringAddTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -19,9 +19,9 @@ public class ShidCodeGenStringAddTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("a"), - isPushStringInstruction("b"), - isStringAddInstruction() + isShidPushString("a"), + isShidPushString("b"), + isShidStringAdd() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringLiteralTests.java index b308c300..5cc85089 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStringLiteralTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.isPushStringInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushString; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -16,7 +16,7 @@ public class ShidCodeGenStringLiteralTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello") + isShidPushString("hello") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStructDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStructDefinitionTests.java index 4e989e9b..c3a932df 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStructDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenStructDefinitionTests.java @@ -7,7 +7,7 @@ import org.shedlang.compiler.shid.instructions.ShidDefineStruct; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalStoreInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidLocalStore; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -34,7 +34,7 @@ public class ShidCodeGenStructDefinitionTests { has("name", x -> x.name(), equalTo("isActive")) )) ), - isLocalStoreInstruction("User__0") + isShidLocalStore("User__0") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenSumTypeDefinitionTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenSumTypeDefinitionTests.java index 74521d29..be7ca7d1 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenSumTypeDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenSumTypeDefinitionTests.java @@ -5,8 +5,8 @@ import org.shedlang.compiler.ast.typed.Typed; import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isLocalStoreInstruction; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushUnitInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidLocalStore; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushUnit; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -23,8 +23,8 @@ public class ShidCodeGenSumTypeDefinitionTests { var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( - isPushUnitInstruction(), - isLocalStoreInstruction("Option__0") + isShidPushUnit(), + isShidLocalStore("Option__0") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTryTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTryTests.java index ddcf1d08..c155eb4d 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTryTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTryTests.java @@ -9,8 +9,8 @@ import org.shedlang.compiler.shid.instructions.ShidTry; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.NamespaceName; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isBlockInstruction; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.isPushIntInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidBlock; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushInt; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.*; @@ -55,8 +55,8 @@ public class ShidCodeGenTryTests { equalTo("read"), equalTo("write") )), - has("body", x -> x.body(), isBlockInstruction(isSequence( - isPushIntInstruction(42) + has("body", x -> x.body(), isShidBlock(isSequence( + isShidPushInt(42) ))) ) )); diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTupleTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTupleTests.java index c3194182..dde77436 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTupleTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenTupleTests.java @@ -5,7 +5,7 @@ import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -22,10 +22,10 @@ public class ShidCodeGenTupleTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("a"), - isPushBoolInstruction(true), - isPushIntInstruction(4), - isTupleCreateInstruction(3) + isShidPushString("a"), + isShidPushBool(true), + isShidPushInt(4), + isShidTupleCreate(3) )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenUnitLiteralTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenUnitLiteralTests.java index 27b7ed6c..511c2f5e 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenUnitLiteralTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenUnitLiteralTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.isPushUnitInstruction; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidPushUnit; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -16,7 +16,7 @@ public class ShidCodeGenUnitLiteralTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isPushUnitInstruction() + isShidPushUnit() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java index fdf9300c..1e220855 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java @@ -7,7 +7,7 @@ import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -21,8 +21,8 @@ public class ShidCodeGenValTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isLocalStoreInstruction("x__0") + isShidPushString("hello"), + isShidLocalStore("x__0") )); } @@ -35,8 +35,8 @@ public class ShidCodeGenValTests { var result = ShidCodeGen.compileNamespaceStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isLocalStoreInstruction("x__0") + isShidPushString("hello"), + isShidLocalStore("x__0") )); } @@ -77,32 +77,32 @@ public class ShidCodeGenValTests { } assertThat(context.instructions(), isSequence( - isPushIntInstruction(10), - isLocalStoreInstruction("x__0"), - isLocalLoadInstruction("x__0"), - isDiscardInstruction(), - isPushBoolInstruction(true), - isIfInstruction( - isBlockInstruction(isSequence( - isPushIntInstruction(11), - isLocalStoreInstruction("x__1"), - isLocalLoadInstruction("x__1"), - isDiscardInstruction(), - isPushUnitInstruction() + isShidPushInt(10), + isShidLocalStore("x__0"), + isShidLocalLoad("x__0"), + isShidDiscard(), + isShidPushBool(true), + isShidIf( + isShidBlock(isSequence( + isShidPushInt(11), + isShidLocalStore("x__1"), + isShidLocalLoad("x__1"), + isShidDiscard(), + isShidPushUnit() )), - isBlockInstruction(isSequence( - isBlockInstruction(isSequence( - isPushIntInstruction(12), - isLocalStoreInstruction("x__2"), - isLocalLoadInstruction("x__2"), - isDiscardInstruction(), - isPushUnitInstruction() + isShidBlock(isSequence( + isShidBlock(isSequence( + isShidPushInt(12), + isShidLocalStore("x__2"), + isShidLocalLoad("x__2"), + isShidDiscard(), + isShidPushUnit() )) )) ), - isDiscardInstruction(), - isLocalLoadInstruction("x__0"), - isDiscardInstruction() + isShidDiscard(), + isShidLocalLoad("x__0"), + isShidDiscard() )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenVarTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenVarTests.java index a1e264ad..1f9c24e8 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenVarTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenVarTests.java @@ -3,7 +3,7 @@ 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.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -17,8 +17,8 @@ public class ShidCodeGenVarTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isPushStringInstruction("hello"), - isVarStoreInstruction("x__0") + isShidPushString("hello"), + isShidVarStore("x__0") )); } } diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhenTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhenTests.java index a7abfc69..b7529685 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhenTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhenTests.java @@ -7,7 +7,7 @@ import org.shedlang.compiler.types.Types; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -40,19 +40,19 @@ public class ShidCodeGenWhenTests { var result = ShidCodeGen.compileExpression(node, context); assertThat(result.instructions(), isSequence( - isLocalLoadInstruction("x__0"), - isSwitchInstruction( + isShidLocalLoad("x__0"), + isShidSwitch( isSequence( - isSwitchInstructionCase( + isShidSwitchCase( Types.struct(NAMESPACE_NAME, "A"), - isBlockInstruction(isSequence( - isPushStringInstruction("a") + isShidBlock(isSequence( + isShidPushString("a") )) ), - isSwitchInstructionCase( + isShidSwitchCase( Types.struct(NAMESPACE_NAME, "B"), - isBlockInstruction(isSequence( - isPushStringInstruction("b") + isShidBlock(isSequence( + isShidPushString("b") )) ) ) diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhileTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhileTests.java index 3307db91..5e1ce2c4 100644 --- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhileTests.java +++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenWhileTests.java @@ -5,7 +5,7 @@ import org.shedlang.compiler.ast.typed.Typed; import java.util.List; -import static org.shedlang.compiler.shid.instructions.InstructionMatchers.*; +import static org.shedlang.compiler.shid.instructions.ShidMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -24,20 +24,20 @@ public class ShidCodeGenWhileTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isLoopInstruction( - isBlockInstruction(isSequence( - isLocalLoadInstruction("c__0"), - isIfInstruction( - isBlockInstruction(isSequence()), - isBlockInstruction(isSequence( - isLoopBreakInstruction() + isShidLoop( + isShidBlock(isSequence( + isShidLocalLoad("c__0"), + isShidIf( + isShidBlock(isSequence()), + isShidBlock(isSequence( + isShidLoopBreak() )) ), - isBlockInstruction(isSequence( - isPushIntInstruction(42), - isDiscardInstruction() + isShidBlock(isSequence( + isShidPushInt(42), + isShidDiscard() )), - isLoopContinueInstruction() + isShidLoopContinue() )) ) )); @@ -59,20 +59,20 @@ public class ShidCodeGenWhileTests { var result = ShidCodeGen.compileFunctionStatement(node, context); assertThat(result.instructions(), isSequence( - isLoopInstruction( - isBlockInstruction(isSequence( - isLocalLoadInstruction("c__0"), - isIfInstruction( - isBlockInstruction(isSequence()), - isBlockInstruction(isSequence( - isLoopBreakInstruction() + isShidLoop( + isShidBlock(isSequence( + isShidLocalLoad("c__0"), + isShidIf( + isShidBlock(isSequence()), + isShidBlock(isSequence( + isShidLoopBreak() )) ), - isBlockInstruction(isSequence( - isPushIntInstruction(42), - isDiscardInstruction() + isShidBlock(isSequence( + isShidPushInt(42), + isShidDiscard() )), - isLoopContinueInstruction() + isShidLoopContinue() )) ) )); diff --git a/src/test/java/org/shedlang/compiler/shid/instructions/InstructionMatchers.java b/src/test/java/org/shedlang/compiler/shid/instructions/InstructionMatchers.java deleted file mode 100644 index 6e57a4b2..00000000 --- a/src/test/java/org/shedlang/compiler/shid/instructions/InstructionMatchers.java +++ /dev/null @@ -1,246 +0,0 @@ -package org.shedlang.compiler.shid.instructions; - -import org.shedlang.compiler.types.NamespaceName; -import org.shedlang.compiler.types.StructType; -import org.shedlang.compiler.types.UserDefinedEffect; -import org.zwobble.precisely.Matcher; - -import java.math.BigInteger; -import java.util.List; - -import static org.zwobble.precisely.Matchers.*; - -public class InstructionMatchers { - private InstructionMatchers() { - } - - public static Matcher isBlockInstruction( - Matcher> instructions - ) { - return instanceOf( - ShidBlock.class, - has("instructions", x -> x.instructions(), instructions) - ); - } - - public static Matcher isBreakInstruction(UserDefinedEffect effect) { - return instanceOf( - ShedEffectHandlerBreak.class, - has("effect", x -> x.effect(), equalTo(effect)) - ); - } - - public static Matcher isCallInstruction( - int positionalArgCount, - List namedArgNames - ) { - return instanceOf( - ShidCall.class, - has("positionalArgCount", x -> x.positionalArgCount(), equalTo(positionalArgCount)), - has("namedArgNames", x -> x.namedArgNames(), equalTo(namedArgNames)) - ); - } - - public static Matcher isDefineFunctionInstructionParam(String name) { - return has("name", x -> x.name(), equalTo(name)); - } - - public static Matcher isDiscardInstruction() { - return instanceOf( - ShidDiscard.class - ); - } - - public static Matcher isDuplicateInstruction() { - return instanceOf(ShidDuplicate.class); - } - - public static Matcher isFieldLoadInstruction( - ShidFieldLoad.Receiver receiver, - String fieldName - ) { - return instanceOf( - ShidFieldLoad.class, - has("receiver", x -> x.receiver(), equalTo(receiver)), - has("fieldName", x -> x.fieldName(), equalTo(fieldName)) - ); - } - - public static Matcher isFieldLoadInstruction( - StructType receiverType, - String fieldName - ) { - return isFieldLoadInstruction( - new ShidFieldLoad.Receiver.Struct(receiverType), - fieldName - ); - } - - public static Matcher isIfInstruction( - Matcher trueBody, - Matcher falseBody - ) { - return instanceOf( - ShidIf.class, - has("trueBody", x -> x.trueBody(), trueBody), - has("falseBody", x -> x.falseBody(), falseBody) - ); - } - - public static Matcher isIntAddInstruction() { - return instanceOf(ShidIntAdd.class); - } - - public static Matcher isIntEqualsInstruction() { - return instanceOf(ShidIntEquals.class); - } - - public static Matcher isIntNotEqualInstruction() { - return instanceOf(ShidIntNotEqual.class); - } - - public static Matcher isIntSubInstruction() { - return instanceOf(ShidIntSub.class); - } - - public static Matcher isLocalLoadInstruction(String name) { - return instanceOf( - ShidLocalLoad.class, - has("name", x -> x.name(), equalTo(name)) - ); - } - - public static Matcher isLocalStoreInstruction(String name) { - return instanceOf( - ShidLocalStore.class, - has("name", x -> x.name(), equalTo(name)) - ); - } - - public static Matcher isLoopInstruction( - Matcher body - ) { - return instanceOf( - ShidLoop.class, - has("body", x -> x.body(), body) - ); - } - - public static Matcher isLoopBreakInstruction() { - return instanceOf(ShidLoopBreak.class); - } - - public static Matcher isLoopContinueInstruction() { - return instanceOf(ShidLoopContinue.class); - } - - public static Matcher isNamespaceFieldStoreInstruction( - NamespaceName namespaceName, - String fieldName - ) { - return instanceOf( - ShidNamespaceFieldStore.class, - has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)), - has("fieldName", x -> x.fieldName(), equalTo(fieldName)) - ); - } - - public static Matcher isNamespaceImportInstruction( - NamespaceName namespaceName - ) { - return instanceOf( - ShidNamespaceImport.class, - has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)) - ); - } - - public static Matcher isPushBoolInstruction(boolean value) { - return instanceOf( - ShidPushBool.class, - has("value", x -> x.value(), equalTo(value)) - ); - } - - public static Matcher isPushIntInstruction(int value) { - return instanceOf( - ShidPushInt.class, - has("value", x -> x.value(), equalTo(BigInteger.valueOf(value))) - ); - } - - public static Matcher isPushStringInstruction(String value) { - return instanceOf( - ShidPushString.class, - has("value", x -> x.value(), equalTo(value)) - ); - } - - public static Matcher isPushUnitInstruction() { - return instanceOf( - ShidPushUnit.class - ); - } - - public static Matcher isResumeInstruction() { - return instanceOf( - ShidResume.class - ); - } - - public static Matcher isReturnInstruction() { - return instanceOf( - ShidReturn.class - ); - } - - public static Matcher isStringAddInstruction() { - return instanceOf(ShidStringAdd.class); - } - - public static Matcher isSwitchInstruction( - Matcher> cases - ) { - return instanceOf( - ShidSwitch.class, - has("cases", x -> x.cases(), cases) - ); - } - - public static Matcher isSwitchInstructionCase( - StructType caseType, - Matcher body - ) { - return allOf( - has("caseType", x -> x.caseType(), equalTo(caseType)), - has("body", x -> x.body(), body) - ); - } - - public static Matcher isTupleCreateInstruction(int elementCount) { - return instanceOf( - ShidTupleCreate.class, - has("elementCount", x -> x.elementCount(), equalTo(elementCount)) - ); - } - - public static Matcher isTupleGetInstruction(int elementIndex) { - return instanceOf( - ShidTupleGet.class, - has("elementIndex", x -> x.elementIndex(), equalTo(elementIndex)) - ); - } - - public static Matcher isVarLoadInstruction(String name) { - return instanceOf( - ShidVarLoad.class, - has("name", x -> x.name(), equalTo(name)) - ); - } - - public static Matcher isVarStoreInstruction(String name) { - return instanceOf( - ShidVarStore.class, - has("name", x -> x.name(), equalTo(name)) - ); - } -} diff --git a/src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java b/src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java new file mode 100644 index 00000000..70de8644 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/shid/instructions/ShidMatchers.java @@ -0,0 +1,246 @@ +package org.shedlang.compiler.shid.instructions; + +import org.shedlang.compiler.types.NamespaceName; +import org.shedlang.compiler.types.StructType; +import org.shedlang.compiler.types.UserDefinedEffect; +import org.zwobble.precisely.Matcher; + +import java.math.BigInteger; +import java.util.List; + +import static org.zwobble.precisely.Matchers.*; + +public class ShidMatchers { + private ShidMatchers() { + } + + public static Matcher isShidBlock( + Matcher> instructions + ) { + return instanceOf( + ShidBlock.class, + has("instructions", x -> x.instructions(), instructions) + ); + } + + public static Matcher isShidCall( + int positionalArgCount, + List namedArgNames + ) { + return instanceOf( + ShidCall.class, + has("positionalArgCount", x -> x.positionalArgCount(), equalTo(positionalArgCount)), + has("namedArgNames", x -> x.namedArgNames(), equalTo(namedArgNames)) + ); + } + + public static Matcher isShidDefineFunction(String name) { + return has("name", x -> x.name(), equalTo(name)); + } + + public static Matcher isShidDiscard() { + return instanceOf( + ShidDiscard.class + ); + } + + public static Matcher isShidDuplicate() { + return instanceOf(ShidDuplicate.class); + } + + public static Matcher isShidEffectHandlerBreak(UserDefinedEffect effect) { + return instanceOf( + ShedEffectHandlerBreak.class, + has("effect", x -> x.effect(), equalTo(effect)) + ); + } + + public static Matcher isShidFieldLoad( + ShidFieldLoad.Receiver receiver, + String fieldName + ) { + return instanceOf( + ShidFieldLoad.class, + has("receiver", x -> x.receiver(), equalTo(receiver)), + has("fieldName", x -> x.fieldName(), equalTo(fieldName)) + ); + } + + public static Matcher isShidFieldLoad( + StructType receiverType, + String fieldName + ) { + return isShidFieldLoad( + new ShidFieldLoad.Receiver.Struct(receiverType), + fieldName + ); + } + + public static Matcher isShidIf( + Matcher trueBody, + Matcher falseBody + ) { + return instanceOf( + ShidIf.class, + has("trueBody", x -> x.trueBody(), trueBody), + has("falseBody", x -> x.falseBody(), falseBody) + ); + } + + public static Matcher isShidIntAdd() { + return instanceOf(ShidIntAdd.class); + } + + public static Matcher isShidIntEquals() { + return instanceOf(ShidIntEquals.class); + } + + public static Matcher isShidIntNotEqual() { + return instanceOf(ShidIntNotEqual.class); + } + + public static Matcher isShidIntSub() { + return instanceOf(ShidIntSub.class); + } + + public static Matcher isShidLocalLoad(String name) { + return instanceOf( + ShidLocalLoad.class, + has("name", x -> x.name(), equalTo(name)) + ); + } + + public static Matcher isShidLocalStore(String name) { + return instanceOf( + ShidLocalStore.class, + has("name", x -> x.name(), equalTo(name)) + ); + } + + public static Matcher isShidLoop( + Matcher body + ) { + return instanceOf( + ShidLoop.class, + has("body", x -> x.body(), body) + ); + } + + public static Matcher isShidLoopBreak() { + return instanceOf(ShidLoopBreak.class); + } + + public static Matcher isShidLoopContinue() { + return instanceOf(ShidLoopContinue.class); + } + + public static Matcher isShidNamespaceFieldStore( + NamespaceName namespaceName, + String fieldName + ) { + return instanceOf( + ShidNamespaceFieldStore.class, + has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)), + has("fieldName", x -> x.fieldName(), equalTo(fieldName)) + ); + } + + public static Matcher isShidNamespaceImport( + NamespaceName namespaceName + ) { + return instanceOf( + ShidNamespaceImport.class, + has("namespaceName", x -> x.namespaceName(), equalTo(namespaceName)) + ); + } + + public static Matcher isShidPushBool(boolean value) { + return instanceOf( + ShidPushBool.class, + has("value", x -> x.value(), equalTo(value)) + ); + } + + public static Matcher isShidPushInt(int value) { + return instanceOf( + ShidPushInt.class, + has("value", x -> x.value(), equalTo(BigInteger.valueOf(value))) + ); + } + + public static Matcher isShidPushString(String value) { + return instanceOf( + ShidPushString.class, + has("value", x -> x.value(), equalTo(value)) + ); + } + + public static Matcher isShidPushUnit() { + return instanceOf( + ShidPushUnit.class + ); + } + + public static Matcher isShidResume() { + return instanceOf( + ShidResume.class + ); + } + + public static Matcher isShidReturn() { + return instanceOf( + ShidReturn.class + ); + } + + public static Matcher isShidStringAdd() { + return instanceOf(ShidStringAdd.class); + } + + public static Matcher isShidSwitch( + Matcher> cases + ) { + return instanceOf( + ShidSwitch.class, + has("cases", x -> x.cases(), cases) + ); + } + + public static Matcher isShidSwitchCase( + StructType caseType, + Matcher body + ) { + return allOf( + has("caseType", x -> x.caseType(), equalTo(caseType)), + has("body", x -> x.body(), body) + ); + } + + public static Matcher isShidTupleCreate(int elementCount) { + return instanceOf( + ShidTupleCreate.class, + has("elementCount", x -> x.elementCount(), equalTo(elementCount)) + ); + } + + public static Matcher isShidTupleGet(int elementIndex) { + return instanceOf( + ShidTupleGet.class, + has("elementIndex", x -> x.elementIndex(), equalTo(elementIndex)) + ); + } + + public static Matcher isShidVarLoad(String name) { + return instanceOf( + ShidVarLoad.class, + has("name", x -> x.name(), equalTo(name)) + ); + } + + public static Matcher isShidVarStore(String name) { + return instanceOf( + ShidVarStore.class, + has("name", x -> x.name(), equalTo(name)) + ); + } +} -- cgit v1.2.3