refactor: rename wrenGetArgument* to wrenGetSlot* and add IS_LIST macro for slot-based API

Migrate the foreign method argument access API from an argument-oriented naming
scheme to a slot-based one, renaming wrenGetArgumentCount to wrenGetSlotCount,
wrenGetArgumentBool to wrenGetSlotBool, and all other argument accessors
accordingly. Update every call site across the VM, modules (io, timer, meta,
random), and test files (benchmark, foreign_class) to use the new names. The
slot getters now assert the correct type at runtime rather than silently
returning defaults, shifting safety responsibility to the caller for
performance. Also add the IS_LIST type-checking macro to wren_value.h alongside
the existing IS_* macros.
This commit is contained in:
Bob Nystrom
2015-12-16 18:22:42 +00:00
parent e929c7c997
commit 234a98faef
10 changed files with 125 additions and 120 deletions
+7 -6
View File
@@ -5,17 +5,18 @@
static void arguments(WrenVM* vm)
{
double result = 0;
result += wrenGetArgumentDouble(vm, 1);
result += wrenGetArgumentDouble(vm, 2);
result += wrenGetArgumentDouble(vm, 3);
result += wrenGetArgumentDouble(vm, 4);
result += wrenGetSlotDouble(vm, 1);
result += wrenGetSlotDouble(vm, 2);
result += wrenGetSlotDouble(vm, 3);
result += wrenGetSlotDouble(vm, 4);
wrenReturnDouble(vm, result);
}
WrenForeignMethodFn benchmarkBindMethod(const char* signature)
{
if (strcmp(signature, "static Benchmark.arguments(_,_,_,_)") == 0) return arguments;
return NULL;
}
+13 -13
View File
@@ -18,15 +18,15 @@ static void counterAllocate(WrenVM* vm)
static void counterIncrement(WrenVM* vm)
{
double* value = (double*)wrenGetArgumentForeign(vm, 0);
double increment = wrenGetArgumentDouble(vm, 1);
double* value = (double*)wrenGetSlotForeign(vm, 0);
double increment = wrenGetSlotDouble(vm, 1);
*value += increment;
}
static void counterValue(WrenVM* vm)
{
double value = *(double*)wrenGetArgumentForeign(vm, 0);
double value = *(double*)wrenGetSlotForeign(vm, 0);
wrenReturnDouble(vm, value);
}
@@ -34,9 +34,9 @@ static void pointAllocate(WrenVM* vm)
{
double* coordinates = (double*)wrenAllocateForeign(vm, sizeof(double[3]));
// This gets called by both constructors, so sniff the argument count to see
// This gets called by both constructors, so sniff the slot count to see
// which one was invoked.
if (wrenGetArgumentCount(vm) == 1)
if (wrenGetSlotCount(vm) == 1)
{
coordinates[0] = 0.0;
coordinates[1] = 0.0;
@@ -44,23 +44,23 @@ static void pointAllocate(WrenVM* vm)
}
else
{
coordinates[0] = wrenGetArgumentDouble(vm, 1);
coordinates[1] = wrenGetArgumentDouble(vm, 2);
coordinates[2] = wrenGetArgumentDouble(vm, 3);
coordinates[0] = wrenGetSlotDouble(vm, 1);
coordinates[1] = wrenGetSlotDouble(vm, 2);
coordinates[2] = wrenGetSlotDouble(vm, 3);
}
}
static void pointTranslate(WrenVM* vm)
{
double* coordinates = (double*)wrenGetArgumentForeign(vm, 0);
coordinates[0] += wrenGetArgumentDouble(vm, 1);
coordinates[1] += wrenGetArgumentDouble(vm, 2);
coordinates[2] += wrenGetArgumentDouble(vm, 3);
double* coordinates = (double*)wrenGetSlotForeign(vm, 0);
coordinates[0] += wrenGetSlotDouble(vm, 1);
coordinates[1] += wrenGetSlotDouble(vm, 2);
coordinates[2] += wrenGetSlotDouble(vm, 3);
}
static void pointToString(WrenVM* vm)
{
double* coordinates = (double*)wrenGetArgumentForeign(vm, 0);
double* coordinates = (double*)wrenGetSlotForeign(vm, 0);
char result[100];
sprintf(result, "(%g, %g, %g)",
coordinates[0], coordinates[1], coordinates[2]);
+1 -1
View File
@@ -6,7 +6,7 @@ static WrenValue* value;
static void setValue(WrenVM* vm)
{
value = wrenGetArgumentValue(vm, 1);
value = wrenGetSlotValue(vm, 1);
}
static void getValue(WrenVM* vm)