From d408f4f80670ed7f73d09f8ccfefdcb8a7835406 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 27 Aug 2023 21:56:25 +0100 Subject: Add Patio code gen for loop instructions --- .../org/shedlang/compiler/patio/PatioCodeGen.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (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 0fa95c91..948bfd6a 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -346,14 +346,24 @@ public class PatioCodeGen { (local, c) -> c.temporaryPopIntoLocal(local, localStore.source()) ); - case LoopBreakInstruction loopBreakInstruction -> - throw new UnsupportedOperationException("TODO"); + case LoopBreakInstruction loopBreak -> + context.addInstruction(new PatioLoopBreak(loopBreak.source())); - case LoopContinueInstruction loopContinueInstruction -> - throw new UnsupportedOperationException("TODO"); + case LoopContinueInstruction loopContinue -> + context.addInstruction(new PatioLoopContinue(loopContinue.source())); - case LoopInstruction loopInstruction -> - throw new UnsupportedOperationException("TODO"); + case LoopInstruction loop -> { + context = context.enterBlock(); + context = generateInstructions(loop.body(), context); + + var bodyInstructionsResult = context.exitBlock(); + var bodyInstructions = bodyInstructionsResult.value(); + context = bodyInstructionsResult.context(); + + context = context.addInstruction(new PatioLoop(bodyInstructions, loop.source())); + + yield context; + } case NamespaceFieldStoreInstruction namespaceFieldStore -> { var fieldValueResult = context.temporaryPop(); -- cgit v1.2.3