}
}
-hVal sbClosure_get_value(hClosure which, usize index) {
+hVal *sbClosure_get_value(hClosure which, usize index) {
sbClosure *c = find_closure_by_handle(which);
if (c->num_vars <= INLINE_VAR_COUNT) {
- return sbVar_get_value(&c->internal_vars[index]);
+ return sbVar_get_value_ptr(&c->internal_vars[index]);
} else {
- return sbVar_get_value(&c->external_vars[index]);
+ return sbVar_get_value_ptr(&c->external_vars[index]);
}
}
sbPool_initialize(&g_heapvar_pool, sizeof(HeapVar), VARS_PER_BLOCK);
}
+void sbVar_sys_deinit() {
+ //sbPool_deinitialize(&g_heapvar_pool, sizeof(HeapVar), VARS_PER_BLOCK);
+}
+
hVal sbVar_get_value(hVar v) {
if (v->value.type == ITX_HEAPVAR) {
return ((HeapVar*)v->value.ptrdata)->value;
}
sbVar sbVar_retain(hVar v) {
- sbVar_move_to_heap(v);
+ if (v->value.type != ITX_HEAPVAR) {
+ sbVar_move_to_heap(v);
+ }
+
((HeapVar*)v->value.ptrdata)->gcinfo.refcount ++;
return *v;
}
void print_stack(hVm vm) {
debug("Stack: ");
- for (hVal **p = (hVal**)vm->vstack; p < (hVal**)vm->vsp; p++) {
- debug("%16llx %16llx ", (long long)(*p)->type, (long long)(*p)->data);
+ for (hVal *p = (hVal*)vm->vstack; p < (hVal*)vm->vsp; p++) {
+ debug("%16llx %16llx ", (long long)p->type, (long long)p->data);
}
debug("\n");
}
/* bound method is just a symbol + a closure containing one variable */
hSymbol sym = (hSymbol)(to_call->type & ~IT_FLAG_BOUND_METHOD);
+ hVal *ref = sbVar_get_attached_ref(to_call);
/* we should already have parameters, so we just need to line it back up
* on the stack and call the method again */
CHECK("bound method call should receive an integer arg count!");
}
peek_stack(vm, 0)->integer ++;
- push_stack(vm, sbVar_get_attached_ref(to_call));
+ push_stack(vm, ref);
/* resolve method normally */
sbLib_resolve_method(vm);
void push_stack(hVm vm, hVal *value) {
*(hVal*)vm->vsp = *value;
- vm->vsp += sizeof(hVal*);
+ vm->vsp += sizeof(hVal);
}
void push_stack_immediate(hVm vm, const hVal *value) {
*(hVal*)vm->vsp = *value;
- vm->vsp += sizeof(hVal*);
+ vm->vsp += sizeof(hVal);
}
hVal *pop_stack(hVm vm) {
- vm->vsp -= sizeof(hVal*);
+ vm->vsp -= sizeof(hVal);
return (hVal*)vm->vsp;
}
hVal *npop_stack(hVm vm, usize count) {
- vm->vsp -= count * sizeof(hVal*);
+ vm->vsp -= count * sizeof(hVal);
return (hVal*)vm->vsp;
}
case BC_LD_UPVAL:
/* Hey, was there upval in there? */
param = get_param(vm);
- res = sbClosure_get_value(vm->fp->block_func.closure, param);
- push_stack(vm, &res);
+ v = sbClosure_get_value(vm->fp->block_func.closure, param);
+ push_stack(vm, v);
break;
case BC_LD_UPREF:
param = get_param(vm);
push_stack_immediate(vm, &HVFUNC(param, 0));
break;
case BC_LD_TRUE:
- push_stack_immediate(vm, &HVBOOL(1));
+ push_stack_immediate(vm, &HVBOOL(TRUE));
break;
case BC_LD_FALSE:
- push_stack_immediate(vm, &HVBOOL(0));
+ push_stack_immediate(vm, &HVBOOL(FALSE));
break;
case BC_LD_NIL:
push_stack_immediate(vm, &HVNIL);