diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-24 21:54:59 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-24 21:54:59 +0100 |
| commit | 06f082a3c9d91a1f70f355f5229f1a8ea97fc70b (patch) | |
| tree | 000891a8024278fb47b772803b90c154a6b58e0e /src/test/java | |
| parent | 5b45f12110760bee7fd94cda9801fba54dc785d1 (diff) | |
Pass args to Patio functions more consistently
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java | 42 | ||||
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/instructions/Patio.java | 62 |
2 files changed, 58 insertions, 46 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java index afff0656..74c4ffa1 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java @@ -105,7 +105,7 @@ public class PatioSerializerTests { .addLocal(Patio.local("local1", PatioTypes.FUNCTION_POINTER)) .addLocal(Patio.local("local2", PatioTypes.INT)) .withReturnType(PatioTypes.VOID) - .addBodyInstruction(Patio.localStore("local2", Patio.int_(2))) + .addBodyInstruction(Patio.localStore(Patio.localRef("local2"), Patio.int_(2))) .build(); var string = PatioTesting.serializeCompilationUnitElement(element); @@ -130,7 +130,7 @@ public class PatioSerializerTests { @Test public void canSerializeAlloc() { var instruction = Patio.alloc( - "x", + Patio.localRef("x"), PatioDataLayouts.struct(List.of(PatioDataLayouts.INT, PatioDataLayouts.INT, PatioDataLayouts.BYTE)) ); @@ -181,9 +181,9 @@ public class PatioSerializerTests { @Test public void canSerializeCallPointer() { var instruction = Patio.callPointer( - "target", - "f", - List.of("a", "b", "c") + Patio.localRef("target"), + Patio.localRef("f"), + List.of(Patio.localRef("a"), Patio.localRef("b"), Patio.localRef("c")) ); var string = PatioTesting.serializeInstruction(instruction); @@ -195,7 +195,7 @@ public class PatioSerializerTests { @Test public void canSerializeDataPtrToInt() { - var instruction = Patio.dataPtrToInt("target", "value"); + var instruction = Patio.dataPtrToInt(Patio.localRef("target"), Patio.localRef("value")); var string = PatioTesting.serializeInstruction(instruction); @@ -214,8 +214,8 @@ public class PatioSerializerTests { Patio.localRef("condition"), Patio.block( List.of( - Patio.localStore("x1", Patio.int_(1)), - Patio.localStore("y1", Patio.int_(2)) + Patio.localStore(Patio.localRef("x1"), Patio.int_(1)), + Patio.localStore(Patio.localRef("y1"), Patio.int_(2)) ), List.of( Patio.localRef("x1"), @@ -224,8 +224,8 @@ public class PatioSerializerTests { ), Patio.block( List.of( - Patio.localStore("x2", Patio.int_(11)), - Patio.localStore("y2", Patio.int_(12)) + Patio.localStore(Patio.localRef("x2"), Patio.int_(11)), + Patio.localStore(Patio.localRef("y2"), Patio.int_(12)) ), List.of( Patio.localRef("x2"), @@ -262,7 +262,11 @@ public class PatioSerializerTests { @Test public void canSerializeIntAdd() { - var instruction = Patio.intAdd("target", "left", "right"); + var instruction = Patio.intAdd( + Patio.localRef("target"), + Patio.localRef("left"), + Patio.localRef("right") + ); var string = PatioTesting.serializeInstruction(instruction); @@ -327,7 +331,10 @@ public class PatioSerializerTests { @Test public void canSerializeIntToDataPtr() { - var instruction = Patio.intToDataPtr("target", "value"); + var instruction = Patio.intToDataPtr( + Patio.localRef("target"), + Patio.localRef("value") + ); var string = PatioTesting.serializeInstruction(instruction); @@ -336,7 +343,10 @@ public class PatioSerializerTests { @Test public void canSerializeLocalStore() { - var instruction = Patio.localStore("target", Patio.localRef("x")); + var instruction = Patio.localStore( + Patio.localRef("target"), + Patio.localRef("x") + ); var string = PatioTesting.serializeInstruction(instruction); @@ -346,8 +356,8 @@ public class PatioSerializerTests { @Test public void canSerializeMemoryLoad() { var instruction = Patio.memoryLoad( - "target", - "pointer", + Patio.localRef("target"), + Patio.localRef("pointer"), PatioDataLayouts.struct(List.of(PatioDataLayouts.INT, PatioDataLayouts.INT, PatioDataLayouts.BYTE)), List.of(1) ); @@ -368,7 +378,7 @@ public class PatioSerializerTests { @Test public void canSerializeMemoryStore() { var instruction = Patio.memoryStore( - "pointer", + Patio.localRef("pointer"), PatioDataLayouts.struct(List.of(PatioDataLayouts.INT, PatioDataLayouts.INT, PatioDataLayouts.BYTE)), List.of(1), "value" diff --git a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java index 2f99d04d..722e3022 100644 --- a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java +++ b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java @@ -14,8 +14,8 @@ import java.util.Optional; public class Patio { private Patio() {} - public static PatioInstruction alloc(String target, PatioDataLayout layout) { - return new PatioAlloc(new PatioLocalRef(target), layout, Sources.NULL); + public static PatioInstruction alloc(PatioLocalRef target, PatioDataLayout layout) { + return new PatioAlloc(target, layout, Sources.NULL); } public static PatioBlock block( @@ -29,7 +29,7 @@ public class Patio { return new PatioBool(value); } - public static PatioInstruction boolToInt(PatioLocalRef target, PatioLocalRef value) { + public static PatioInstruction boolToInt(PatioLocalRef target, PatioOperand value) { return new PatioBoolToInt(target, value, Sources.NULL); } @@ -47,16 +47,14 @@ public class Patio { } public static PatioInstruction callPointer( - String target, - String functionPointer, - List<String> args + PatioLocalRef target, + PatioOperand functionPointer, + List<PatioOperand> args ) { return new PatioCallPointer( - new PatioLocalRef(target), - new PatioLocalRef(functionPointer), - args.stream() - .<PatioOperand>map(arg -> new PatioLocalRef(arg)) - .toList(), + target, + functionPointer, + args, Sources.NULL ); } @@ -85,10 +83,10 @@ public class Patio { return new PatioDataPtr(name); } - public static PatioInstruction dataPtrToInt(String target, String value) { + public static PatioInstruction dataPtrToInt(PatioLocalRef target, PatioOperand value) { return new PatioDataPtrToInt( - new PatioLocalRef(target), - new PatioLocalRef(value), + target, + value, Sources.NULL ); } @@ -116,11 +114,15 @@ public class Patio { return new PatioInt(value); } - public static PatioInstruction intAdd(String target, String left, String right) { + public static PatioInstruction intAdd( + PatioLocalRef target, + PatioOperand left, + PatioOperand right + ) { return new PatioIntAdd( - new PatioLocalRef(target), - new PatioLocalRef(left), - new PatioLocalRef(right), + target, + left, + right, Sources.NULL ); } @@ -149,14 +151,14 @@ public class Patio { return new PatioIntSub(target, left, right, Sources.NULL); } - public static PatioInstruction intToBool(PatioLocalRef target, PatioLocalRef value) { + public static PatioInstruction intToBool(PatioLocalRef target, PatioOperand value) { return new PatioIntToBool(target, value, Sources.NULL); } - public static PatioInstruction intToDataPtr(String target, String value) { + public static PatioInstruction intToDataPtr(PatioLocalRef target, PatioOperand value) { return new PatioIntToDataPtr( - new PatioLocalRef(target), - new PatioLocalRef(value), + target, + value, Sources.NULL ); } @@ -165,9 +167,9 @@ public class Patio { return new PatioLocal(name, type); } - public static PatioInstruction localStore(String target, PatioOperand value) { + public static PatioInstruction localStore(PatioLocalRef target, PatioOperand value) { return new PatioLocalStore( - new PatioLocalRef(target), + target, value, Sources.NULL ); @@ -178,14 +180,14 @@ public class Patio { } public static PatioInstruction memoryLoad( - String target, - String pointer, + PatioLocalRef target, + PatioOperand pointer, PatioDataLayout layout, List<Integer> offset ) { return new PatioMemoryLoad( - new PatioLocalRef(target), - new PatioLocalRef(pointer), + target, + pointer, layout, offset, Sources.NULL @@ -193,13 +195,13 @@ public class Patio { } public static PatioInstruction memoryStore( - String pointer, + PatioOperand pointer, PatioDataLayout layout, List<Integer> offset, String value ) { return new PatioMemoryStore( - new PatioLocalRef(pointer), + pointer, layout, offset, new PatioLocalRef(value), |
