project euler #4, fix bugs
authorcassowarii <2374677+cassowarii@users.noreply.github.com>
Wed, 8 Jul 2026 23:49:37 +0000 (16:49 -0700)
committercassowarii <2374677+cassowarii@users.noreply.github.com>
Wed, 8 Jul 2026 23:49:37 +0000 (16:49 -0700)
i need to add garbage collecting and print / global stuff for real

src/compile/emit.c
src/mem/pool.c
src/vm/bytecode.h
src/vm/exec.c

index 99741a0..9b341e5 100644 (file)
@@ -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:
index 990f91d..30fd5a3 100644 (file)
@@ -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 ++;
 }
index 5e8a48c..54368eb 100644 (file)
@@ -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
index 2687edb..bf9acdf 100644 (file)
@@ -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);