mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
Compare commits
1 Commits
0.4.0-pre
...
stack-corr
| Author | SHA1 | Date | |
|---|---|---|---|
| 48a6a5f67a |
@ -1247,23 +1247,25 @@ void wrenInitializeCore(WrenVM* vm)
|
||||
PRIMITIVE(vm->fnClass->obj.classObj, "new(_)", fn_new);
|
||||
|
||||
PRIMITIVE(vm->fnClass, "arity", fn_arity);
|
||||
PRIMITIVE(vm->fnClass, "call()", fn_call0);
|
||||
PRIMITIVE(vm->fnClass, "call(_)", fn_call1);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_)", fn_call2);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_)", fn_call3);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_)", fn_call4);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_)", fn_call5);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_)", fn_call6);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_)", fn_call7);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_)", fn_call8);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_)", fn_call9);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_)", fn_call10);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_)", fn_call11);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_)", fn_call12);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call13);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call14);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call15);
|
||||
PRIMITIVE(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call16);
|
||||
|
||||
FUNCTION_CALL(vm->fnClass, "call()", fn_call0);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_)", fn_call1);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_)", fn_call2);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_)", fn_call3);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_)", fn_call4);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_)", fn_call5);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_)", fn_call6);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_)", fn_call7);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_)", fn_call8);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_)", fn_call9);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_)", fn_call10);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_)", fn_call11);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_)", fn_call12);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call13);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call14);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call15);
|
||||
FUNCTION_CALL(vm->fnClass, "call(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)", fn_call16);
|
||||
|
||||
PRIMITIVE(vm->fnClass, "toString", fn_toString);
|
||||
|
||||
vm->nullClass = AS_CLASS(wrenFindVariable(vm, coreModule, "Null"));
|
||||
|
||||
@ -16,6 +16,19 @@
|
||||
wrenBindMethod(vm, cls, symbol, method); \
|
||||
} while (false)
|
||||
|
||||
// Binds a primitive method named [name] (in Wren) implemented using C function
|
||||
// [fn] to `ObjClass` [cls], but as a FN call.
|
||||
#define FUNCTION_CALL(cls, name, function) \
|
||||
do \
|
||||
{ \
|
||||
int symbol = wrenSymbolTableEnsure(vm, \
|
||||
&vm->methodNames, name, strlen(name)); \
|
||||
Method method; \
|
||||
method.type = METHOD_FUNCTION_CALL; \
|
||||
method.as.primitive = prim_##function; \
|
||||
wrenBindMethod(vm, cls, symbol, method); \
|
||||
} while (false)
|
||||
|
||||
// Defines a primitive method whose C function name is [name]. This abstracts
|
||||
// the actual type signature of a primitive function and makes it clear which C
|
||||
// functions are invoked as primitives.
|
||||
|
||||
@ -359,6 +359,9 @@ typedef enum
|
||||
// this can directly manipulate the fiber's stack.
|
||||
METHOD_PRIMITIVE,
|
||||
|
||||
// A primitive that handles .call on Fn.
|
||||
METHOD_FUNCTION_CALL,
|
||||
|
||||
// A externally-defined C method.
|
||||
METHOD_FOREIGN,
|
||||
|
||||
|
||||
@ -1015,6 +1015,12 @@ static WrenInterpretResult runInterpreter(WrenVM* vm, register ObjFiber* fiber)
|
||||
}
|
||||
break;
|
||||
|
||||
case METHOD_FUNCTION_CALL:
|
||||
STORE_FRAME();
|
||||
method->as.primitive(vm, args);
|
||||
LOAD_FRAME();
|
||||
break;
|
||||
|
||||
case METHOD_FOREIGN:
|
||||
callForeign(vm, fiber, method->as.foreign, numArgs);
|
||||
if (wrenHasError(fiber)) RUNTIME_ERROR();
|
||||
|
||||
Reference in New Issue
Block a user