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:
Bob Nystrom
2018-03-17 16:33:33 +00:00
parent 2bbd385f69
commit cf05cd7c8c
7 changed files with 105 additions and 104 deletions
+6 -6
View File
@@ -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);
}
}
+3 -3
View File
@@ -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) {
+3 -3
View File
@@ -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"