From: cassowarii <2374677+cassowarii@users.noreply.github.com> Date: Wed, 8 Jul 2026 23:49:37 +0000 (-0700) Subject: project euler #4, fix bugs X-Git-Url: https://www.git.cassowary.me/gitweb.cgi?a=commitdiff_plain;h=80ed59e12bc1dfed5d2cc3c7f218a843ee6fb7f5;p=sarabande.git project euler #4, fix bugs i need to add garbage collecting and print / global stuff for real --- diff --git a/src/compile/emit.c b/src/compile/emit.c index 99741a0..9b341e5 100644 --- a/src/compile/emit.c +++ b/src/compile/emit.c @@ -423,6 +423,8 @@ void compile_op(sbVmCompiler *cm, sbAstOp op) { case AST_OP_GT: EMIT(BC_OP_LE, BC_OP_NOT); break; case AST_OP_LE: EMIT(BC_OP_LE); break; case AST_OP_GE: EMIT(BC_OP_LT, BC_OP_NOT); break; + case AST_OP_AND: EMIT(BC_OP_AND); break; + case AST_OP_OR: EMIT(BC_OP_OR); break; case AST_OP_INDEX: EMIT(BC_OP_INDEX); break; case AST_OP_DIVBY: EMIT(BC_OP_MOD, BC_LD_IMM); EARG(0); EMIT(BC_OP_EQ); break; default: diff --git a/src/mem/pool.c b/src/mem/pool.c index 990f91d..30fd5a3 100644 --- a/src/mem/pool.c +++ b/src/mem/pool.c @@ -105,8 +105,11 @@ void alloc_new_block(hPool pl) { } pl->block_ptrs = new_block_ptrs; pl->used_counts = new_used_counts; + pl->block_ptr_capacity = new_capacity; + pl->next_block_id = pl->num_blocks; } pl->block_ptrs[pl->num_blocks] = new_block; + pl->used_counts[pl->num_blocks] = 0; pl->num_blocks ++; } diff --git a/src/vm/bytecode.h b/src/vm/bytecode.h index 5e8a48c..54368eb 100644 --- a/src/vm/bytecode.h +++ b/src/vm/bytecode.h @@ -48,6 +48,8 @@ typedef enum sbOpcode { BC_OP_DEREF, // dereference pointer BC_OP_LT, // less than BC_OP_LE, // less than or equal to + BC_OP_AND, // logical and + BC_OP_OR, // logical or BC_OP_INDEX, // index [] or :: BC_ALLOC_VARS, // create space in rstack for local variables BC_CLOSURE, // create closure from top elements of stack diff --git a/src/vm/exec.c b/src/vm/exec.c index 2687edb..bf9acdf 100644 --- a/src/vm/exec.c +++ b/src/vm/exec.c @@ -508,6 +508,20 @@ void execute_instruction(hVm vm) { npop_stack(vm, 2); push_stack_immediate(vm, &res); break; + case BC_OP_AND: + v = peek_stack(vm, 1); + w = peek_stack(vm, 0); + res = HVBOOL(!(sbV_c_falsy(v) || sbV_c_falsy(w))); + npop_stack(vm, 2); + push_stack_immediate(vm, &res); + break; + case BC_OP_OR: + v = peek_stack(vm, 1); + w = peek_stack(vm, 0); + res = HVBOOL(!(sbV_c_falsy(v) && sbV_c_falsy(w))); + npop_stack(vm, 2); + push_stack_immediate(vm, &res); + break; case BC_OP_ADD: v = peek_stack(vm, 1); w = peek_stack(vm, 0);