From ea911841f3b5d8601f7ff9234e5bca442d58925b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Jul 2023 17:21:15 +0100 Subject: Add Patio bool type --- .../compiler/patio/ast/PatioSerializer.java | 3 +++ .../compiler/patio/ast/types/PatioBoolType.java | 5 +++++ .../compiler/patio/ast/types/PatioType.java | 2 +- .../compiler/patio/ast/types/PatioTypes.java | 1 + .../compiler/patio/PatioSerializerTests.java | 21 +++++++++++++++------ 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/types/PatioBoolType.java (limited to 'src') 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 @@ -218,6 +218,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 == -- cgit v1.2.3