aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-20 17:21:15 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-20 17:21:15 +0100
commitea911841f3b5d8601f7ff9234e5bca442d58925b (patch)
tree29c6a83fddcf602f54187a9dd11ecad918f8f93a /src
parentb566789e4dd17ab81fc73917d24cb9bf2a678707 (diff)
Add Patio bool type
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java3
-rw-r--r--src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java5
-rw-r--r--src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java2
-rw-r--r--src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java1
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java21
5 files changed, 25 insertions, 7 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java
index 3b7e6a7b..850c2fcc 100644
--- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java
+++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java
@@ -206,6 +206,9 @@ public class PatioSerializer {
private static Tree typeToTree(PatioType type) {
return switch (type) {
+ case PatioBoolType boolType ->
+ treeIdentifier("bool");
+
case PatioDataPointerType dataPointerType ->
treeIdentifier("data-ptr");
diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java
new file mode 100644
index 00000000..3415335d
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java
@@ -0,0 +1,5 @@
+package org.shedlang.compiler.patio.ast.types;
+
+public record PatioBoolType() implements PatioType {
+ static final PatioBoolType INSTANCE = new PatioBoolType();
+}
diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java
index 69b07faf..fe90466f 100644
--- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java
+++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java
@@ -1,4 +1,4 @@
package org.shedlang.compiler.patio.ast.types;
-public sealed interface PatioType permits PatioDataPointerType, PatioFunctionPointerType, PatioIntType, PatioVoidType {
+public sealed interface PatioType permits PatioBoolType, PatioDataPointerType, PatioFunctionPointerType, PatioIntType, PatioVoidType {
}
diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java
index 95e07fbf..8e53c095 100644
--- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java
+++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java
@@ -6,6 +6,7 @@ public class PatioTypes {
private PatioTypes() {
}
+ public static final PatioBoolType BOOL = PatioBoolType.INSTANCE;
public static final PatioDataPointerType DATA_POINTER = PatioDataPointerType.INSTANCE;
public static final PatioFunctionPointerType FUNCTION_POINTER = PatioFunctionPointerType.INSTANCE;
public static final PatioIntType INT = PatioIntType.INSTANCE;
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java
index 4a43eb44..864095c2 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java
@@ -219,6 +219,15 @@ public class PatioSerializerTests {
// == Types ==
@Test
+ public void canSerializeBoolType() {
+ var type = PatioTypes.BOOL;
+
+ var string = PatioTesting.serializeType(type);
+
+ assertThat(string, equalTo("bool"));
+ }
+
+ @Test
public void canSerializeDataPointerType() {
var type = PatioTypes.DATA_POINTER;
@@ -237,21 +246,21 @@ public class PatioSerializerTests {
}
@Test
- public void canSerializeVoidType() {
- var type = PatioTypes.VOID;
+ public void canSerializeIntType() {
+ var type = PatioTypes.INT;
var string = PatioTesting.serializeType(type);
- assertThat(string, equalTo("void"));
+ assertThat(string, equalTo("int"));
}
@Test
- public void canSerializeIntType() {
- var type = PatioTypes.INT;
+ public void canSerializeVoidType() {
+ var type = PatioTypes.VOID;
var string = PatioTesting.serializeType(type);
- assertThat(string, equalTo("int"));
+ assertThat(string, equalTo("void"));
}
// == Data layouts ==