From bafc83a26f9b2b94d8ed04b4841825f67bb48fef Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Jul 2023 11:07:37 +0100 Subject: Tidy up structure of Patio AST --- .../org/shedlang/compiler/patio/PatioCodeGen.java | 6 +- .../compiler/patio/PatioCodeGenClosures.java | 6 +- .../compiler/patio/PatioCodeGenContext.java | 6 +- .../compiler/patio/PatioInstructionSerializer.java | 120 --------------------- .../compiler/patio/ast/PatioCompilationUnit.java | 11 ++ .../patio/ast/PatioCompilationUnitElement.java | 8 ++ .../patio/ast/PatioFunctionDefinition.java | 38 +++++++ .../shedlang/compiler/patio/ast/PatioLocal.java | 4 + .../compiler/patio/ast/PatioSerializer.java | 120 +++++++++++++++++++++ .../patio/ast/instructions/PatioAlloc.java | 11 ++ .../patio/ast/instructions/PatioCallPointer.java | 18 ++++ .../ast/instructions/PatioFunctionPointerGet.java | 10 ++ .../patio/ast/instructions/PatioInstruction.java | 7 ++ .../patio/ast/instructions/PatioIntGet.java | 10 ++ .../patio/ast/instructions/PatioLocalCopy.java | 14 +++ .../patio/ast/instructions/PatioMemoryLoad.java | 16 +++ .../patio/ast/instructions/PatioMemoryStore.java | 15 +++ .../patio/ast/instructions/PatioReturn.java | 10 ++ .../compiler/patio/instructions/PatioAlloc.java | 10 -- .../patio/instructions/PatioCallPointer.java | 17 --- .../patio/instructions/PatioCompilationUnit.java | 11 -- .../instructions/PatioCompilationUnitElement.java | 8 -- .../instructions/PatioFunctionDefinition.java | 38 ------- .../instructions/PatioFunctionPointerGet.java | 9 -- .../patio/instructions/PatioInstruction.java | 7 -- .../compiler/patio/instructions/PatioIntGet.java | 9 -- .../compiler/patio/instructions/PatioLocal.java | 4 - .../patio/instructions/PatioLocalCopy.java | 13 --- .../patio/instructions/PatioMemoryLoad.java | 15 --- .../patio/instructions/PatioMemoryStore.java | 14 --- .../compiler/patio/instructions/PatioReturn.java | 9 -- 31 files changed, 303 insertions(+), 291 deletions(-) delete mode 100644 src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioFunctionPointerGet.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntGet.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalCopy.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java create mode 100644 src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioAlloc.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnit.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnitElement.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionDefinition.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionPointerGet.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioIntGet.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioLocal.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalCopy.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java delete mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index 13e77b53..ff0434dc 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -1,8 +1,8 @@ package org.shedlang.compiler.patio; -import org.shedlang.compiler.patio.instructions.PatioIntGet; -import org.shedlang.compiler.patio.instructions.PatioLocal; -import org.shedlang.compiler.patio.instructions.PatioReturn; +import org.shedlang.compiler.patio.ast.instructions.PatioIntGet; +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.patio.ast.instructions.PatioReturn; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.stackir.instructions.*; diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index b7afeba2..839a0067 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -1,9 +1,9 @@ package org.shedlang.compiler.patio; import org.shedlang.compiler.ast.typed.FreeVariables; -import org.shedlang.compiler.patio.instructions.PatioCallPointer; -import org.shedlang.compiler.patio.instructions.PatioLocal; -import org.shedlang.compiler.patio.instructions.PatioMemoryLoad; +import org.shedlang.compiler.patio.ast.instructions.PatioCallPointer; +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.patio.ast.instructions.PatioMemoryLoad; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java index dd67f9f8..42287560 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java @@ -5,7 +5,11 @@ import org.pcollections.PMap; import org.pcollections.PStack; import org.pcollections.PVector; import org.shedlang.compiler.backends.llvm.NameAllocator; -import org.shedlang.compiler.patio.instructions.*; +import org.shedlang.compiler.patio.ast.PatioCompilationUnitElement; +import org.shedlang.compiler.patio.ast.PatioFunctionDefinition; +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.patio.ast.instructions.PatioInstruction; +import org.shedlang.compiler.patio.ast.instructions.PatioLocalCopy; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.util.P; diff --git a/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java b/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java deleted file mode 100644 index c5966bf8..00000000 --- a/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.shedlang.compiler.patio; - -import org.shedlang.compiler.patio.instructions.*; -import org.shedlang.compiler.treetext.Tree; - -import java.util.List; - -import static org.shedlang.compiler.treetext.TreeSerializer.serializeTree; -import static org.shedlang.compiler.treetext.Trees.*; - -public class PatioInstructionSerializer { - private PatioInstructionSerializer() {} - - public static void serializeCompilationUnitElement( - PatioCompilationUnitElement element, - StringBuilder builder - ) { - var tree = compilationUnitElementToTree(element); - serializeTree(tree, builder, 0); - } - - public static void serializeInstructions(List instructions, StringBuilder builder) { - var tree = instructionsToTree(instructions); - serializeTree(tree, builder, 0); - } - - public static void serializeInstruction(PatioInstruction instruction, StringBuilder builder) { - var tree = instructionToTree(instruction); - serializeTree(tree, builder, 0); - } - - private static Tree compilationUnitElementToTree(PatioCompilationUnitElement element) { - return switch (element) { - case PatioFunctionDefinition functionDefinition -> - treeListIndented( - treeIdentifier("function"), - treeString(element.name()), - treeNamed("is-private", treeBool(functionDefinition.isPrivate())) - ); - }; - } - - private static Tree instructionsToTree(List instructions) { - return treeListIndented( - instructions.stream() - .map(instruction -> instructionToTree(instruction)) - .toList() - ); - } - - private static Tree instructionToTree(PatioInstruction instruction) { - return switch (instruction) { - case PatioAlloc alloc -> - treeList( - treeIdentifier("alloc"), - localToTree(alloc.target()), - treeInt(alloc.bytes()) - ); - - case PatioCallPointer callPointer -> - treeList( - treeIdentifier("call-pointer"), - localToTree(callPointer.target()), - localToTree(callPointer.functionPointer()), - treeList( - callPointer.args().stream() - .map(arg -> localToTree(arg)) - .toList() - ) - ); - - case PatioIntGet intGet -> - treeList( - treeIdentifier("int-get"), - localToTree(intGet.target()), - treeInt(intGet.value()) - ); - - case PatioLocalCopy localCopy -> - treeList( - treeIdentifier("local-copy"), - localToTree(localCopy.target()), - localToTree(localCopy.value()) - ); - - case PatioMemoryLoad memoryLoad -> - treeList( - treeIdentifier("memory-load"), - localToTree(memoryLoad.target()), - treeNamed("pointer", localToTree(memoryLoad.pointer())), - treeNamed("offset", treeInt(memoryLoad.offset())) - ); - - case PatioMemoryStore memoryStore -> - treeList( - treeIdentifier("memory-store"), - treeNamed("pointer", localToTree(memoryStore.pointer())), - treeNamed("offset", treeInt(memoryStore.offset())), - treeNamed("value", localToTree(memoryStore.value())) - ); - - case PatioFunctionPointerGet functionPointerGet -> - treeList( - treeIdentifier("function-pointer-get"), - localToTree(functionPointerGet.target()), - treeString(functionPointerGet.name()) - ); - - case PatioReturn return_ -> - treeList( - treeIdentifier("return"), - localToTree(return_.value()) - ); - }; - } - - private static Tree localToTree(PatioLocal local) { - return treeString(local.name()); - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java new file mode 100644 index 00000000..227c38d2 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnit.java @@ -0,0 +1,11 @@ +package org.shedlang.compiler.patio.ast; + +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +public record PatioCompilationUnit( + List elements, + Source source +) { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java new file mode 100644 index 00000000..eecdd3c2 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioCompilationUnitElement.java @@ -0,0 +1,8 @@ +package org.shedlang.compiler.patio.ast; + +import org.shedlang.compiler.sources.Source; + +public sealed interface PatioCompilationUnitElement permits PatioFunctionDefinition { + String name(); + Source source(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java new file mode 100644 index 00000000..d421c290 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioFunctionDefinition.java @@ -0,0 +1,38 @@ +package org.shedlang.compiler.patio.ast; + +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.sources.Sources; + +public record PatioFunctionDefinition( + String name, + boolean isPrivate, + Source source +) implements PatioCompilationUnitElement { + public static Builder builder() { + return new Builder("f", true); + } + + public record Builder(String name, boolean isPrivate) { + public Builder withName(String name) { + return new Builder( + name, + this.isPrivate + ); + } + + public Builder withIsPrivate(boolean isPrivate) { + return new Builder( + this.name, + isPrivate + ); + } + + public PatioFunctionDefinition build() { + return new PatioFunctionDefinition( + this.name, + this.isPrivate, + Sources.NULL + ); + } + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java new file mode 100644 index 00000000..a5a7d9c5 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioLocal.java @@ -0,0 +1,4 @@ +package org.shedlang.compiler.patio.ast; + +public record PatioLocal(String name) { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java new file mode 100644 index 00000000..655e4fb4 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java @@ -0,0 +1,120 @@ +package org.shedlang.compiler.patio.ast; + +import org.shedlang.compiler.patio.ast.instructions.*; +import org.shedlang.compiler.treetext.Tree; + +import java.util.List; + +import static org.shedlang.compiler.treetext.TreeSerializer.serializeTree; +import static org.shedlang.compiler.treetext.Trees.*; + +public class PatioSerializer { + private PatioSerializer() {} + + public static void serializeCompilationUnitElement( + PatioCompilationUnitElement element, + StringBuilder builder + ) { + var tree = compilationUnitElementToTree(element); + serializeTree(tree, builder, 0); + } + + public static void serializeInstructions(List instructions, StringBuilder builder) { + var tree = instructionsToTree(instructions); + serializeTree(tree, builder, 0); + } + + public static void serializeInstruction(PatioInstruction instruction, StringBuilder builder) { + var tree = instructionToTree(instruction); + serializeTree(tree, builder, 0); + } + + private static Tree compilationUnitElementToTree(PatioCompilationUnitElement element) { + return switch (element) { + case PatioFunctionDefinition functionDefinition -> + treeListIndented( + treeIdentifier("function"), + treeString(element.name()), + treeNamed("is-private", treeBool(functionDefinition.isPrivate())) + ); + }; + } + + private static Tree instructionsToTree(List instructions) { + return treeListIndented( + instructions.stream() + .map(instruction -> instructionToTree(instruction)) + .toList() + ); + } + + private static Tree instructionToTree(PatioInstruction instruction) { + return switch (instruction) { + case PatioAlloc alloc -> + treeList( + treeIdentifier("alloc"), + localToTree(alloc.target()), + treeInt(alloc.bytes()) + ); + + case PatioCallPointer callPointer -> + treeList( + treeIdentifier("call-pointer"), + localToTree(callPointer.target()), + localToTree(callPointer.functionPointer()), + treeList( + callPointer.args().stream() + .map(arg -> localToTree(arg)) + .toList() + ) + ); + + case PatioIntGet intGet -> + treeList( + treeIdentifier("int-get"), + localToTree(intGet.target()), + treeInt(intGet.value()) + ); + + case PatioLocalCopy localCopy -> + treeList( + treeIdentifier("local-copy"), + localToTree(localCopy.target()), + localToTree(localCopy.value()) + ); + + case PatioMemoryLoad memoryLoad -> + treeList( + treeIdentifier("memory-load"), + localToTree(memoryLoad.target()), + treeNamed("pointer", localToTree(memoryLoad.pointer())), + treeNamed("offset", treeInt(memoryLoad.offset())) + ); + + case PatioMemoryStore memoryStore -> + treeList( + treeIdentifier("memory-store"), + treeNamed("pointer", localToTree(memoryStore.pointer())), + treeNamed("offset", treeInt(memoryStore.offset())), + treeNamed("value", localToTree(memoryStore.value())) + ); + + case PatioFunctionPointerGet functionPointerGet -> + treeList( + treeIdentifier("function-pointer-get"), + localToTree(functionPointerGet.target()), + treeString(functionPointerGet.name()) + ); + + case PatioReturn return_ -> + treeList( + treeIdentifier("return"), + localToTree(return_.value()) + ); + }; + } + + private static Tree localToTree(PatioLocal local) { + return treeString(local.name()); + } +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java new file mode 100644 index 00000000..61e3a6fe --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioAlloc.java @@ -0,0 +1,11 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +/** + * Allocate the given number of bytes, and store the pointer to the allocated + * memory in the target local. + */ +public record PatioAlloc(PatioLocal target, int bytes, Source source) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java new file mode 100644 index 00000000..f2e81241 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioCallPointer.java @@ -0,0 +1,18 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Call the function pointed to by the function pointer with the given + * arguments, and store the returned value in the target local. + */ +public record PatioCallPointer( + PatioLocal target, + PatioLocal functionPointer, + List args, + Source source +) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioFunctionPointerGet.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioFunctionPointerGet.java new file mode 100644 index 00000000..3ab85137 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioFunctionPointerGet.java @@ -0,0 +1,10 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +/** + * Store a pointer to the function with the given name in the target local. + */ +public record PatioFunctionPointerGet(PatioLocal target, String name, Source source) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java new file mode 100644 index 00000000..4cff67b4 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java @@ -0,0 +1,7 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.sources.Source; + +public sealed interface PatioInstruction permits PatioAlloc, PatioCallPointer, PatioFunctionPointerGet, PatioIntGet, PatioLocalCopy, PatioMemoryLoad, PatioMemoryStore, PatioReturn { + Source source(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntGet.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntGet.java new file mode 100644 index 00000000..2b92dd3d --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioIntGet.java @@ -0,0 +1,10 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +/** + * Store the given value in the target local. + */ +public record PatioIntGet(PatioLocal target, int value, Source source) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalCopy.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalCopy.java new file mode 100644 index 00000000..0fccbce8 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLocalCopy.java @@ -0,0 +1,14 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +/** + * Copy the given value into the target local. + */ +public record PatioLocalCopy( + PatioLocal target, + PatioLocal value, + Source source +) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java new file mode 100644 index 00000000..793445a0 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java @@ -0,0 +1,16 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +/** + * Load the value at the given offset from the given pointer and store it in the + * target local. + */ +public record PatioMemoryLoad( + PatioLocal target, + PatioLocal pointer, + int offset, + Source source +) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java new file mode 100644 index 00000000..444cbf1d --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java @@ -0,0 +1,15 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +/** + * Store the given value at the given offset from the given pointer. + */ +public record PatioMemoryStore( + PatioLocal pointer, + int offset, + PatioLocal value, + Source source +) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java new file mode 100644 index 00000000..1d022275 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioReturn.java @@ -0,0 +1,10 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.patio.ast.PatioLocal; +import org.shedlang.compiler.sources.Source; + +/** + * Return with the given value from the current function. + */ +public record PatioReturn(PatioLocal value, Source source) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioAlloc.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioAlloc.java deleted file mode 100644 index ae5599e0..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioAlloc.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Allocate the given number of bytes, and store the pointer to the allocated - * memory in the target local. - */ -public record PatioAlloc(PatioLocal target, int bytes, Source source) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java deleted file mode 100644 index 279a0c71..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -/** - * Call the function pointed to by the function pointer with the given - * arguments, and store the returned value in the target local. - */ -public record PatioCallPointer( - PatioLocal target, - PatioLocal functionPointer, - List args, - Source source -) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnit.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnit.java deleted file mode 100644 index 6c4f4a1a..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnit.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -public record PatioCompilationUnit( - List elements, - Source source -) { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnitElement.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnitElement.java deleted file mode 100644 index 7d29e082..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCompilationUnitElement.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -public sealed interface PatioCompilationUnitElement permits PatioFunctionDefinition { - String name(); - Source source(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionDefinition.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionDefinition.java deleted file mode 100644 index 9a81a879..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionDefinition.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; -import org.shedlang.compiler.sources.Sources; - -public record PatioFunctionDefinition( - String name, - boolean isPrivate, - Source source -) implements PatioCompilationUnitElement { - public static Builder builder() { - return new Builder("f", true); - } - - public record Builder(String name, boolean isPrivate) { - public Builder withName(String name) { - return new Builder( - name, - this.isPrivate - ); - } - - public Builder withIsPrivate(boolean isPrivate) { - return new Builder( - this.name, - isPrivate - ); - } - - public PatioFunctionDefinition build() { - return new PatioFunctionDefinition( - this.name, - this.isPrivate, - Sources.NULL - ); - } - } -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionPointerGet.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionPointerGet.java deleted file mode 100644 index 9e548464..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioFunctionPointerGet.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Store a pointer to the function with the given name in the target local. - */ -public record PatioFunctionPointerGet(PatioLocal target, String name, Source source) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java deleted file mode 100644 index c7ce5e85..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -public sealed interface PatioInstruction permits PatioAlloc, PatioCallPointer, PatioFunctionPointerGet, PatioIntGet, PatioLocalCopy, PatioMemoryLoad, PatioMemoryStore, PatioReturn { - Source source(); -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntGet.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntGet.java deleted file mode 100644 index 0d1bbfc2..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioIntGet.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Store the given value in the target local. - */ -public record PatioIntGet(PatioLocal target, int value, Source source) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocal.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocal.java deleted file mode 100644 index 97590ffe..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocal.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -public record PatioLocal(String name) { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalCopy.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalCopy.java deleted file mode 100644 index da3d92e2..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioLocalCopy.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Copy the given value into the target local. - */ -public record PatioLocalCopy( - PatioLocal target, - PatioLocal value, - Source source -) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java deleted file mode 100644 index cab95107..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryLoad.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Load the value at the given offset from the given pointer and store it in the - * target local. - */ -public record PatioMemoryLoad( - PatioLocal target, - PatioLocal pointer, - int offset, - Source source -) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java deleted file mode 100644 index 67776381..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioMemoryStore.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Store the given value at the given offset from the given pointer. - */ -public record PatioMemoryStore( - PatioLocal pointer, - int offset, - PatioLocal value, - Source source -) implements PatioInstruction { -} diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java deleted file mode 100644 index 81327631..00000000 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioReturn.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.shedlang.compiler.patio.instructions; - -import org.shedlang.compiler.sources.Source; - -/** - * Return with the given value from the current function. - */ -public record PatioReturn(PatioLocal value, Source source) implements PatioInstruction { -} -- cgit v1.2.3