aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-01-22 19:33:36 +0000
committerMichael Williamson <mike@zwobble.org>2024-01-22 22:36:18 +0000
commit7a83b6e88268277871788a3d8d86a3b8e044b142 (patch)
treefac8d0532ddfbea1453df175fe1e261f375bff91 /src/test/java
parent70906ba9e9213391b524260acd653852e9b8f428 (diff)
Replace Patio instructions for size/offset with operands
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java50
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java77
-rw-r--r--src/test/java/org/shedlang/compiler/patio/instructions/Patio.java43
3 files changed, 77 insertions, 93 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
index 6a5545ab..d25d5e94 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java
@@ -767,22 +767,24 @@ public abstract class PatioExampleTests {
.withName(FUNCTION_NAME)
.withReturnType(PatioTypes.INT)
.addLocal(Patio.val("x", PatioTypes.INT))
- .addBodyInstruction(Patio.byteOffsetOf(
+ .addBodyInstruction(Patio.localStore(
Patio.localRef("x"),
- PatioDataLayouts.struct(List.of(
+ Patio.intConst(Patio.intValueByteOffsetOf(
PatioDataLayouts.struct(List.of(
- PatioDataLayouts.BYTE,
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE
+ )),
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE
+ )),
PatioDataLayouts.BYTE
)),
- PatioDataLayouts.struct(List.of(
- PatioDataLayouts.BYTE,
- PatioDataLayouts.BYTE,
- PatioDataLayouts.BYTE,
- PatioDataLayouts.BYTE
- )),
- PatioDataLayouts.BYTE
- )),
- List.of(1, 2)
+ List.of(1, 2)
+ ))
))
.addBodyInstruction(Patio.return_(
Patio.localRef("x")
@@ -803,20 +805,22 @@ public abstract class PatioExampleTests {
.withName(FUNCTION_NAME)
.withReturnType(PatioTypes.INT)
.addLocal(Patio.val("x", PatioTypes.INT))
- .addBodyInstruction(Patio.byteSizeOf(
+ .addBodyInstruction(Patio.localStore(
Patio.localRef("x"),
- PatioDataLayouts.struct(List.of(
- PatioDataLayouts.struct(List.of(
- PatioDataLayouts.BYTE,
- PatioDataLayouts.BYTE
- )),
+ Patio.intConst(Patio.intValueByteSizeOf(
PatioDataLayouts.struct(List.of(
- PatioDataLayouts.BYTE,
- PatioDataLayouts.BYTE,
- PatioDataLayouts.BYTE,
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE
+ )),
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE,
+ PatioDataLayouts.BYTE
+ )),
PatioDataLayouts.BYTE
- )),
- PatioDataLayouts.BYTE
+ ))
))
))
.addBodyInstruction(Patio.return_(
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java
index 0e4a1c14..637d0e9b 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java
@@ -181,50 +181,6 @@ public class PatioSerializerTests {
}
@Test
- public void canSerializeByteOffsetOf() {
- var instruction = Patio.byteOffsetOf(
- Patio.localRef("destination"),
- PatioDataLayouts.struct(List.of(
- PatioDataLayouts.INT,
- PatioDataLayouts.BYTE
- )),
- List.of(1, 2)
- );
-
- var string = PatioTesting.serializeInstruction(instruction);
-
- assertThat(string, equalTo("""
- (
- byte-offset-of
- (local "destination")
- (struct (int byte))
- (1 2)
- )"""
- ));
- }
-
- @Test
- public void canSerializeByteSizeOf() {
- var instruction = Patio.byteSizeOf(
- Patio.localRef("destination"),
- PatioDataLayouts.struct(List.of(
- PatioDataLayouts.INT,
- PatioDataLayouts.BYTE
- ))
- );
-
- var string = PatioTesting.serializeInstruction(instruction);
-
- assertThat(string, equalTo("""
- (
- byte-size-of
- (local "destination")
- (struct (int byte))
- )"""
- ));
- }
-
- @Test
public void canSerializeCallWithoutTarget() {
var instruction = Patio.call(
Optional.empty(),
@@ -804,10 +760,39 @@ public class PatioSerializerTests {
// == Int values ==
@Test
+ public void canSerializeIntValueByteOffsetOf() {
+ var intValue = Patio.intValueByteOffsetOf(
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.INT,
+ PatioDataLayouts.BYTE
+ )),
+ List.of(1, 2)
+ );
+
+ var string = PatioTesting.serializeIntValue(intValue);
+
+ assertThat(string, equalTo("(byte-offset-of (struct (int byte)) (1 2))"));
+ }
+
+ @Test
+ public void canSerializeIntValueByteSizeOf() {
+ var intValue = Patio.intValueByteSizeOf(
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.INT,
+ PatioDataLayouts.BYTE
+ ))
+ );
+
+ var string = PatioTesting.serializeIntValue(intValue);
+
+ assertThat(string, equalTo("(byte-size-of (struct (int byte)))"));
+ }
+
+ @Test
public void canSerializeIntValueLiteral() {
- var operand = Patio.intValueLiteral(42);
+ var intValue = Patio.intValueLiteral(42);
- var string = PatioTesting.serializeIntValue(operand);
+ var string = PatioTesting.serializeIntValue(intValue);
assertThat(string, equalTo("42"));
}
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 8129dcff..532f2d2a 100644
--- a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java
+++ b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java
@@ -6,6 +6,8 @@ import org.shedlang.compiler.patio.types.PatioDataLayout;
import org.shedlang.compiler.patio.types.PatioDataValue;
import org.shedlang.compiler.patio.types.PatioType;
import org.shedlang.compiler.patio.values.PatioIntValue;
+import org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf;
+import org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf;
import org.shedlang.compiler.patio.values.PatioIntValueLiteral;
import org.shedlang.compiler.sources.Sources;
@@ -34,30 +36,6 @@ public class Patio {
return new PatioBoolToInt(destination, value, Sources.NULL);
}
- public static PatioInstruction byteOffsetOf(
- PatioLocalRef destination,
- PatioDataLayout layout,
- List<Integer> offset
- ) {
- return new PatioByteOffsetOf(
- destination,
- layout,
- offset,
- Sources.NULL
- );
- }
-
- public static PatioInstruction byteSizeOf(
- PatioLocalRef destination,
- PatioDataLayout layout
- ) {
- return new PatioByteSizeOf(
- destination,
- layout,
- Sources.NULL
- );
- }
-
public static PatioInstruction call(
Optional<PatioLocalRef> destination,
String name,
@@ -156,6 +134,10 @@ public class Patio {
return PatioIntConst.of(value);
}
+ public static PatioOperand intConst(PatioIntValue value) {
+ return new PatioIntConst(value);
+ }
+
public static PatioInstruction intAdd(
PatioLocalRef destination,
PatioOperand left,
@@ -205,6 +187,19 @@ public class Patio {
);
}
+ public static PatioIntValue intValueByteOffsetOf(
+ PatioDataLayout layout,
+ List<Integer> offset
+ ) {
+ return new PatioIntValueByteOffsetOf(layout, offset);
+ }
+
+ public static PatioIntValue intValueByteSizeOf(
+ PatioDataLayout layout
+ ) {
+ return new PatioIntValueByteSizeOf(layout);
+ }
+
public static PatioIntValue intValueLiteral(int value) {
return new PatioIntValueLiteral(value);
}