summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
Diffstat (limited to 'com.c')
-rw-r--r--com.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/com.c b/com.c
index 695802a..2465777 100644
--- a/com.c
+++ b/com.c
@@ -180,18 +180,30 @@ void if_form(Compiler *C, AstVec l, Op _) {
// skip ->B
// A: if-false
// B:
+
+ int orig_stack_cur = C->stack_cur;
+
compile_node(C, l.vals[1]);
compile_opcode(C, OP_0BRANCH);
size_t ph_a = placeholder(C);
compile_node(C, l.vals[2]);
compile_opcode(C, OP_SKIP);
+
size_t ph_b = placeholder(C);
size_t dest_a = BYTECODE(C).len;
+ int stack_cur_a = C->stack_cur;
+ C->stack_cur = orig_stack_cur;
+
compile_node(C, l.vals[3]);
size_t dest_b = BYTECODE(C).len;
+ int stack_cur_b = C->stack_cur;
+
patch(C, ph_a, dest_a - ph_a - 2);
patch(C, ph_b, dest_b - ph_b - 2);
+
+ CHECK(stack_cur_a == stack_cur_b, "this should never happen");
+ CHECK(stack_cur_a == orig_stack_cur + 1, "this should never happen");
}
void while_form(Compiler *C, AstVec l, Op _) {
@@ -520,6 +532,7 @@ int main(int argc, char **argv) {
}
+
compile_opcode(&com, OP_HALT);
Thread th = thread_new(S);