summaryrefslogtreecommitdiff
path: root/com.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-06-27 12:01:33 +0100
committerubq323 <ubq323@ubq323.website>2024-06-27 12:05:27 +0100
commit991e694b558691264f82d80a7aa1b86ef3d2c92c (patch)
tree881946b076bdcc6545aa167ef7d544b6e16f9abb /com.c
parenta559125a2d7af771784614b7a2092cc7fb707345 (diff)
more tests
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);