Compile imports to closures, not fibers.
This is simpler and marginally faster. We don't need the overhead of fibers since you can't have long or recursive import chains anyway. More importantly, this makes the behavior more well-defined when you do things like yield from an imported module. (Not that you should do that, but if you do, it shouldn't do weird things.)
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