fix a couple bugs with the previous thing master
authorcassowarii <cassowary@cassowary.me>
Thu, 23 Jul 2026 18:05:08 +0000 (11:05 -0700)
committercassowarii <cassowary@cassowary.me>
Thu, 23 Jul 2026 18:05:08 +0000 (11:05 -0700)
src/compile/emit.c
src/vm/operations.c

index b73152b..04bc42a 100644 (file)
@@ -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) {
 }
 
 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) {
     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_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 */
     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 */
index d1ad06f..5feed68 100644 (file)
@@ -128,8 +128,8 @@ hVal sbV_append(hVal *a, hVal *b) {
 }
 
 void sbV_index_value(hVm vm) {
 }
 
 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);
   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) {
 }
 
 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) {
 
   if (is_indirect) {
     if (a->type != IT_REF) {