diff options
| author | Ben Winston | 2023-05-21 19:55:04 -0400 |
|---|---|---|
| committer | Ben Winston | 2023-05-21 19:55:04 -0400 |
| commit | a26bfccdc52ab50a83b8f8d170c9e1a3be0164a5 (patch) | |
| tree | b12118bebf7e22a29fa4d953ee3a8b7085008612 /compiler.d | |
| parent | 618de4c70d8916f64781997f3ae538e3e6109d00 (diff) | |
'or' control statement
Diffstat (limited to 'compiler.d')
| -rw-r--r-- | compiler.d | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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); |
