diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-08-27 21:47:31 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-08-27 21:47:31 +0100 |
| commit | 03a34c054113843846a4eaf4fbd24f9dd99c826e (patch) | |
| tree | efde7f1dab58e78e6fc9d534947c461204dc36c5 /src/main/java | |
| parent | 0110c68debe431369dcd4f107daf142d478b8496 (diff) | |
Add Patio loop instructions
Diffstat (limited to 'src/main/java')
5 files changed, 51 insertions, 1 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 276d4cbf..5868ce3e 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java @@ -252,6 +252,22 @@ public class PatioSerializer { operandToTree(localStore.value()) ); + case PatioLoop loop -> + treeListIndented( + treeIdentifier("loop"), + instructionsToTree(loop.body()) + ); + + case PatioLoopBreak loopBreak -> + treeList( + treeIdentifier("break") + ); + + case PatioLoopContinue loopContinue -> + treeList( + treeIdentifier("continue") + ); + case PatioMemoryLoad memoryLoad -> treeListIndented( treeIdentifier("memory-load"), 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 index 26c92715..0c8d5721 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioInstruction.java @@ -2,6 +2,6 @@ package org.shedlang.compiler.patio.ast.instructions; import org.shedlang.compiler.sources.Source; -public sealed interface PatioInstruction permits PatioAllocHeap, PatioAllocStack, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioVarLoad, PatioVarStore { +public sealed interface PatioInstruction permits PatioAllocHeap, PatioAllocStack, PatioBoolToInt, PatioCall, PatioCallPointer, PatioDataPtrToInt, PatioIf, PatioIntAdd, PatioIntEquals, PatioIntNotEqual, PatioIntSub, PatioIntToBool, PatioIntToDataPtr, PatioLocalStore, PatioLoop, PatioLoopBreak, PatioLoopContinue, PatioMemoryLoad, PatioMemoryStore, PatioReturn, PatioVarLoad, PatioVarStore { Source source(); } diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoop.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoop.java new file mode 100644 index 00000000..94d33a24 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoop.java @@ -0,0 +1,16 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.sources.Source; + +import java.util.List; + +/** + * Execute the body. The <code>continue</code> instruction can jump back to the + * start of the body. The <code>break</code> instruction can jump to the end of + * the body. + */ +public record PatioLoop( + List<PatioInstruction> body, + Source source +) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopBreak.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopBreak.java new file mode 100644 index 00000000..a276a5ad --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopBreak.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Jump to the end of the enclosing <code>loop</code> instruction's body. + */ +public record PatioLoopBreak(Source source) implements PatioInstruction { +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopContinue.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopContinue.java new file mode 100644 index 00000000..f8afd614 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioLoopContinue.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.patio.ast.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Jump to the start of the enclosing <code>loop</code> instruction's body. + */ +public record PatioLoopContinue(Source source) implements PatioInstruction { +} |
