refactor: change wrenCompileSource to return ObjClosure instead of ObjFiber and inline import execution
The compileInModule function now returns a closure directly instead of wrapping it in a fiber, simplifying the compilation pipeline and removing unnecessary fiber overhead for module imports. The wrenImportModule function is moved into wren_vm.c and rewritten to execute the imported module's closure immediately rather than returning a fiber for deferred execution. This change also adds a test for yielding from an imported module to verify correct behavior with the new execution model.
This commit is contained in:
@@ -14,18 +14,18 @@ void metaCompile(WrenVM* vm)
|
||||
bool printErrors = wrenGetSlotBool(vm, 3);
|
||||
|
||||
// TODO: Allow passing in module?
|
||||
ObjFiber* fiber = wrenCompileSource(vm, "main", source,
|
||||
isExpression, printErrors);
|
||||
|
||||
ObjClosure* closure = wrenCompileSource(vm, "main", source,
|
||||
isExpression, printErrors);
|
||||
|
||||
// Return the result. We can't use the public API for this since we have a
|
||||
// bare ObjFiber*.
|
||||
if (fiber == NULL)
|
||||
// bare ObjClosure*.
|
||||
if (closure == NULL)
|
||||
{
|
||||
vm->apiStack[0] = NULL_VAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->apiStack[0] = OBJ_VAL(fiber);
|
||||
vm->apiStack[0] = OBJ_VAL(closure);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ class Meta {
|
||||
static eval(source) {
|
||||
if (!(source is String)) Fiber.abort("Source code must be a string.")
|
||||
|
||||
var fiber = compile_(source, false, false)
|
||||
var closure = compile_(source, false, false)
|
||||
// TODO: Include compile errors.
|
||||
if (fiber == null) Fiber.abort("Could not compile source code.")
|
||||
if (closure == null) Fiber.abort("Could not compile source code.")
|
||||
|
||||
fiber.call()
|
||||
closure.call()
|
||||
}
|
||||
|
||||
static compileExpression(source) {
|
||||
|
||||
@@ -12,11 +12,11 @@ static const char* metaModuleSource =
|
||||
" static eval(source) {\n"
|
||||
" if (!(source is String)) Fiber.abort(\"Source code must be a string.\")\n"
|
||||
"\n"
|
||||
" var fiber = compile_(source, false, false)\n"
|
||||
" var closure = compile_(source, false, false)\n"
|
||||
" // TODO: Include compile errors.\n"
|
||||
" if (fiber == null) Fiber.abort(\"Could not compile source code.\")\n"
|
||||
" if (closure == null) Fiber.abort(\"Could not compile source code.\")\n"
|
||||
"\n"
|
||||
" fiber.call()\n"
|
||||
" closure.call()\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" static compileExpression(source) {\n"
|
||||
|
||||
Reference in New Issue
Block a user