boolean literals + mod operator
authorcassowarii <cassowary@cassowary.me>
Tue, 7 Jul 2026 07:03:48 +0000 (00:03 -0700)
committercassowarii <cassowary@cassowary.me>
Tue, 7 Jul 2026 07:03:48 +0000 (00:03 -0700)
src/compile/emit.c
src/compile/ir.c
src/vm/exec.c
src/vm/operations.c
src/vm/operations.h

index 7da4848..0ef10e8 100644 (file)
@@ -416,6 +416,7 @@ void compile_op(sbVmCompiler *cm, sbAstOp op) {
     case AST_OP_SUB: EMIT(BC_OP_SUB); break;
     case AST_OP_MUL: EMIT(BC_OP_MUL); break;
     case AST_OP_FLDIV: EMIT(BC_OP_FLDIV); break;
+    case AST_OP_MOD: EMIT(BC_OP_MOD); break;
     case AST_OP_EQ: EMIT(BC_OP_EQ); break;
     case AST_OP_NE: EMIT(BC_OP_EQ, BC_OP_NOT); break;
     case AST_OP_LT: EMIT(BC_OP_LT); break;
index d30c345..42e37d5 100644 (file)
@@ -991,6 +991,8 @@ static sbIrExpr *compile_ast_expr(hIrChunk ck, sbAst node, flag list_context) {
     return expr_value(ck, &HVSTR(node->str));
   } else if (node->type == AST_VAL_SYMBOL) {
     return expr_value(ck, &HVSYM(node->symb));
+  } else if (node->type == AST_VAL_BOOLEAN) {
+    return expr_value(ck, &HVBOOL(node->i));
   } else if (node->type == AST_VAL_NIL) {
     return expr_value(ck, &HVNIL);
   } else if (node->type == AST_NODE_NAME) {
index 7360e36..2687edb 100644 (file)
@@ -345,6 +345,12 @@ void execute_instruction(hVm vm) {
       w = sbRef_deref(v->ref);
       push_stack(vm, w);
       break;
+    case BC_LD_TRUE:
+      push_stack_immediate(vm, &HVBOOL(1));
+      break;
+    case BC_LD_FALSE:
+      push_stack_immediate(vm, &HVBOOL(0));
+      break;
     case BC_LD_NIL:
       push_stack_immediate(vm, &HVNIL);
       break;
@@ -532,8 +538,14 @@ void execute_instruction(hVm vm) {
       npop_stack(vm, 2);
       push_stack_immediate(vm, &res);
       break;
-    case BC_OP_NEG:
     case BC_OP_MOD:
+      v = peek_stack(vm, 1);
+      w = peek_stack(vm, 0);
+      res = sbV_mod(v, w);
+      npop_stack(vm, 2);
+      push_stack_immediate(vm, &res);
+      break;
+    case BC_OP_NEG:
     case BC_OP_POW:
       PANIC("todo");
     case BC_OP_INCR:
index adbf206..fdf10d6 100644 (file)
@@ -59,6 +59,14 @@ hV sbV_floordiv(const hV *a, const hV *b) {
   }
 }
 
+hV sbV_mod(const hV *a, const hV *b) {
+  if (a->type == IT_INTEGER && b->type == IT_INTEGER) {
+    return sbV_int(a->integer % b->integer);
+  } else {
+    PANIC("todo");
+  }
+}
+
 void sbV_incr(hV *a) {
   if (a->type == IT_INTEGER) {
     a->integer += 1;
index 8fa8778..cc40d61 100644 (file)
@@ -10,6 +10,8 @@ hV sbV_mul(const hV *a, const hV *b);
 
 hV sbV_floordiv(const hV *a, const hV *b);
 
+hV sbV_mod(const hV *a, const hV *b);
+
 void sbV_incr(hV *a);
 
 void sbV_decr(hV *a);