From 991e694b558691264f82d80a7aa1b86ef3d2c92c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 27 Jun 2024 12:01:33 +0100 Subject: more tests --- com.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'com.c') 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); -- cgit v1.2.3