From a26bfccdc52ab50a83b8f8d170c9e1a3be0164a5 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Sun, 21 May 2023 19:55:04 -0400 Subject: 'or' control statement --- compiler.d | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index c05aeaa..6482f50 100644 --- a/compiler.d +++ b/compiler.d @@ -242,6 +242,26 @@ class Compiler { } } + void compileOr(Form form) { + Or or_ = cast(Or)form; + + resolve(or_.clauses[0]); + int[] jumps; + jumps ~= jump(OpCode.OP_JUMP_IF_TRUE); + int count = 1; + while (count < or_.clauses.length) { + this.func.chunk.writeOp(OpCode.OP_POP, or_.line); + resolve(or_.clauses[count]); + jumps ~= jump(OpCode.OP_JUMP_IF_TRUE); + count++; + } + + // patch all the jumps + foreach (int jmp; jumps) { + patchJump(jmp); + } + } + void compileBlock(Form form) { Block block = cast(Block)form; beginScope(); @@ -327,6 +347,9 @@ class Compiler { case FormType.AND: this.compileAnd(form); break; + case FormType.OR: + this.compileOr(form); + break; default: write("not sure how to resolve: "); printForm(form); -- cgit v1.2.3