wrenReturn___() -> wrenSlotSet___().

This turns those functions into general-purpose functions for writing
raw C values into slots on the foreign call stack.

Writing a return just means writing a value to slot 0.
This commit is contained in:
Bob Nystrom
2015-12-16 13:00:13 -08:00
parent 4b3c818ec5
commit 7fcdcf2f1a
16 changed files with 215 additions and 152 deletions

View File

@ -19,12 +19,10 @@ void metaCompile(WrenVM* vm)
// Compile it.
ObjFn* fn = wrenCompile(vm, module, wrenGetSlotString(vm, 1), false);
if (fn == NULL) return;
// Return the result. We can't use the public API for this since we have a
// bare ObjFn.
*vm->foreignStackStart = OBJ_VAL(fn);
vm->foreignStackStart = NULL;
vm->foreignStackStart[0] = fn != NULL ? OBJ_VAL(fn) : NULL_VAL;
}
static WrenForeignMethodFn bindMetaForeignMethods(WrenVM* vm,

View File

@ -92,14 +92,14 @@ static void randomFloat(WrenVM* vm)
// from 0 to 1.0 (half-inclusive).
result /= 9007199254740992.0;
wrenReturnDouble(vm, result);
wrenSetSlotDouble(vm, 0, result);
}
static void randomInt0(WrenVM* vm)
{
Well512* well = (Well512*)wrenGetSlotForeign(vm, 0);
wrenReturnDouble(vm, (double)advanceState(well));
wrenSetSlotDouble(vm, 0, (double)advanceState(well));
}
// TODO: The way these are wired up is pretty verbose and tedious. Also, the