diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-21 16:52:22 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-21 16:52:22 +0100 |
| commit | 107df69fcf9d53c320165e7f3f946c03e3f5bfc4 (patch) | |
| tree | ba17b8d1bbec05e9bb80add6559f324aa32e73a9 /src/main/java | |
| parent | d9a377762129c72ff18c34c8268579517ae6c3bf (diff) | |
Add byte data values
Diffstat (limited to 'src/main/java')
4 files changed, 32 insertions, 0 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 8c02d3d3..62e7fa68 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java @@ -38,6 +38,14 @@ public class PatioSerializer { serializeTree(tree, builder, 0); } + public static void serializeDataValue( + PatioDataValue value, + StringBuilder builder + ) { + var tree = dataValueToTree(value); + serializeTree(tree, builder, 0); + } + public static void serializeInstructions(List<PatioInstruction> instructions, StringBuilder builder) { var tree = instructionsToTree(instructions); serializeTree(tree, builder, 0); @@ -302,6 +310,13 @@ public class PatioSerializer { }; } + private static Tree dataValueToTree(PatioDataValue value) { + return switch (value) { + case PatioDataValueByte byte_ -> + treeList(treeIdentifier("byte"), treeIdentifier(String.format("0x%02x", byte_.value()))); + }; + } + private static Tree visibilityToTree(PatioVisibility visibility) { return treeIdentifier(switch (visibility) { case PRIVATE -> "private"; diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValue.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValue.java new file mode 100644 index 00000000..5ccf1f21 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValue.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.ast.types; + +public sealed interface PatioDataValue permits PatioDataValueByte { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueByte.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueByte.java new file mode 100644 index 00000000..7ca2a997 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValueByte.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.ast.types; + +public record PatioDataValueByte(byte value) implements PatioDataValue { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValues.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValues.java new file mode 100644 index 00000000..88dd0898 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataValues.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.patio.ast.types; + +public class PatioDataValues { + private PatioDataValues() {} + + public static PatioDataValue byte_(int value) { + return new PatioDataValueByte((byte) value); + } +} |
