2015-10-24 18:23:25 +02:00
|
|
|
#include "wren_opt_meta.h"
|
2015-03-22 22:16:53 +01:00
|
|
|
|
2015-10-24 18:23:25 +02:00
|
|
|
#if WREN_OPT_META
|
2015-03-22 22:16:53 +01:00
|
|
|
|
2015-03-26 04:20:26 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2015-10-18 07:09:48 +02:00
|
|
|
#include "wren_vm.h"
|
2015-10-24 18:23:25 +02:00
|
|
|
#include "wren_opt_meta.wren.inc"
|
2015-03-22 22:16:53 +01:00
|
|
|
|
2015-10-16 03:08:56 +02:00
|
|
|
void metaCompile(WrenVM* vm)
|
2015-03-22 22:16:53 +01:00
|
|
|
{
|
2015-10-16 03:08:56 +02:00
|
|
|
// Evaluate the code in the module where the calling function was defined.
|
|
|
|
|
// That's one stack frame back from the top since the top-most frame is the
|
|
|
|
|
// helper eval() method in Meta itself.
|
2016-03-26 22:00:17 +01:00
|
|
|
ObjClosure* caller = vm->fiber->frames[vm->fiber->numFrames - 2].closure;
|
|
|
|
|
ObjModule* module = caller->fn->module;
|
2015-10-24 18:23:25 +02:00
|
|
|
|
2015-04-04 06:22:58 +02:00
|
|
|
// Compile it.
|
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.
2015-12-16 19:22:42 +01:00
|
|
|
ObjFn* fn = wrenCompile(vm, module, wrenGetSlotString(vm, 1), false);
|
2015-10-24 18:23:25 +02:00
|
|
|
|
2015-10-16 03:08:56 +02:00
|
|
|
// Return the result. We can't use the public API for this since we have a
|
|
|
|
|
// bare ObjFn.
|
2016-03-26 22:00:17 +01:00
|
|
|
if (fn == NULL)
|
|
|
|
|
{
|
|
|
|
|
vm->apiStack[0] = NULL_VAL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wrenPushRoot(vm, (Obj*)fn);
|
|
|
|
|
vm->apiStack[0] = OBJ_VAL(wrenNewClosure(vm, fn));
|
|
|
|
|
wrenPopRoot(vm);
|
|
|
|
|
}
|
2015-03-22 22:16:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-17 15:49:43 +01:00
|
|
|
const char* wrenMetaSource()
|
|
|
|
|
{
|
|
|
|
|
return metaModuleSource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WrenForeignMethodFn wrenMetaBindForeignMethod(WrenVM* vm,
|
|
|
|
|
const char* className,
|
|
|
|
|
bool isStatic,
|
|
|
|
|
const char* signature)
|
2015-03-22 22:16:53 +01:00
|
|
|
{
|
2015-10-16 03:08:56 +02:00
|
|
|
// There is only one foreign method in the meta module.
|
|
|
|
|
ASSERT(strcmp(className, "Meta") == 0, "Should be in Meta class.");
|
|
|
|
|
ASSERT(isStatic, "Should be static.");
|
|
|
|
|
ASSERT(strcmp(signature, "compile_(_)") == 0, "Should be compile method.");
|
2016-03-17 15:49:43 +01:00
|
|
|
|
2015-10-16 03:08:56 +02:00
|
|
|
return metaCompile;
|
|
|
|
|
}
|
2015-03-26 04:20:26 +01:00
|
|
|
|
2015-03-22 22:16:53 +01:00
|
|
|
#endif
|