From: cassowarii Date: Tue, 7 Jul 2026 07:03:48 +0000 (-0700) Subject: boolean literals + mod operator X-Git-Url: https://www.git.cassowary.me/gitweb.cgi?a=commitdiff_plain;h=955025907872ce2cd75852ea2a259050f5e8112b;p=sarabande.git boolean literals + mod operator --- diff --git a/src/compile/emit.c b/src/compile/emit.c index 7da4848..0ef10e8 100644 --- a/src/compile/emit.c +++ b/src/compile/emit.c @@ -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; diff --git a/src/compile/ir.c b/src/compile/ir.c index d30c345..42e37d5 100644 --- a/src/compile/ir.c +++ b/src/compile/ir.c @@ -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) { diff --git a/src/vm/exec.c b/src/vm/exec.c index 7360e36..2687edb 100644 --- a/src/vm/exec.c +++ b/src/vm/exec.c @@ -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: diff --git a/src/vm/operations.c b/src/vm/operations.c index adbf206..fdf10d6 100644 --- a/src/vm/operations.c +++ b/src/vm/operations.c @@ -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; diff --git a/src/vm/operations.h b/src/vm/operations.h index 8fa8778..cc40d61 100644 --- a/src/vm/operations.h +++ b/src/vm/operations.h @@ -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);