From: cassowarii Date: Thu, 23 Jul 2026 18:05:08 +0000 (-0700) Subject: fix a couple bugs with the previous thing X-Git-Url: https://www.git.cassowary.me/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;p=sarabande.git fix a couple bugs with the previous thing --- diff --git a/src/compile/emit.c b/src/compile/emit.c index b73152b..04bc42a 100644 --- a/src/compile/emit.c +++ b/src/compile/emit.c @@ -511,7 +511,7 @@ void compile_ref(sbVmCompiler *cm, sbIrExpr *expr, flag is_lref) { } void compile_maybe_ref(sbVmCompiler *cm, sbIrExpr *expr, flag is_lref, sbOpcode op, sbOpcode op_ind) { - if (is_implicit_ref(expr->dot.target)) { + if (is_implicit_ref(expr)) { compile_ref(cm, expr, is_lref); EMIT(op_ind); } else if (expr->type == IR_E_OP && expr->op.type == AST_OP_DEREF) { @@ -541,7 +541,8 @@ void compile_op(sbVmCompiler *cm, sbAstOp op) { case AST_OP_NOT: EMIT(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_INDEXVAL); break; + /* because of constraints with maybe_ref, the index op is reversed. may fix this later */ + case AST_OP_INDEX: EMIT(BC_SWAP); EMIT(BC_OP_INDEXVAL); break; case AST_OP_RANGEINDEX: EMIT(BC_OP_RANGEINDEX); break; case AST_OP_DEREF: EMIT(BC_OP_DEREF); break; /* op range is currently only used in rangeindex; just pass them to it directly */ diff --git a/src/vm/operations.c b/src/vm/operations.c index d1ad06f..5feed68 100644 --- a/src/vm/operations.c +++ b/src/vm/operations.c @@ -128,8 +128,8 @@ hVal sbV_append(hVal *a, hVal *b) { } void sbV_index_value(hVm vm) { - hVal *a = sbVm_peek(vm, 1); - hVal *b = sbVm_peek(vm, 0); + hVal *a = sbVm_peek(vm, 0); + hVal *b = sbVm_peek(vm, 1); if (a->type == IT_LIST && b->type == IT_INTEGER) { sbVm_npop(vm, 2); hVal result = sbList_index_value(a->list, b->integer); @@ -149,8 +149,8 @@ void sbV_index_value(hVm vm) { } void sbV_index_ref(hVm vm, flag is_lref, flag is_indirect) { - hVal *a = sbVm_peek(vm, 1); - hVal *b = sbVm_peek(vm, 0); + hVal *a = sbVm_peek(vm, 0); + hVal *b = sbVm_peek(vm, 1); if (is_indirect) { if (a->type != IT_REF) {