feat: expose wrenEnsureSlots API and rename foreignStackStart to apiStack for slot access outside foreign methods

Replace the internal `foreignStackStart` pointer with a public `apiStack` field
that tracks the base of available C API slots. Extract the static
`ensureStack` helper into a non-static `wrenEnsureStack` function declared in
the header, enabling `wrenEnsureSlots()` to create a fiber and stack when
called outside a foreign method. Update `callForeign` to use `apiStack` and
adjust `metaCompile` to write results through the new pointer. Add a
`ensureOutsideForeign` test that allocates slots on a fresh VM, verifies
slot count grows from 0 to 20, and exercises all 20 slots with double values
to confirm the stack is correctly initialized and usable.
This commit is contained in:
Bob Nystrom
2015-12-28 15:43:17 +00:00
parent 278d66bdc1
commit 6abebbe906
7 changed files with 157 additions and 99 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ void metaCompile(WrenVM* vm)
// Return the result. We can't use the public API for this since we have a
// bare ObjFn.
vm->foreignStackStart[0] = fn != NULL ? OBJ_VAL(fn) : NULL_VAL;
vm->apiStack[0] = fn != NULL ? OBJ_VAL(fn) : NULL_VAL;
}
static WrenForeignMethodFn bindMetaForeignMethods(WrenVM* vm,