aboutsummaryrefslogtreecommitdiff
path: root/compiler.d
diff options
context:
space:
mode:
Diffstat (limited to 'compiler.d')
-rw-r--r--compiler.d23
1 files changed, 23 insertions, 0 deletions
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);