1
0
forked from Mirror/wren

Move running the module fiber into C.

This commit is contained in:
Bob Nystrom
2015-02-16 10:16:42 -08:00
parent 36d100b8e4
commit 5b1447882b
3 changed files with 12 additions and 6 deletions

View File

@ -60,9 +60,7 @@ class Sequence {
class String is Sequence {
import_(variable) {
var result = loadModule_
if (result != null) result.call
loadModule_
return lookUpVariable_(variable)
}
}

View File

@ -103,9 +103,7 @@ static const char* libSource =
"\n"
"class String is Sequence {\n"
" import_(variable) {\n"
" var result = loadModule_\n"
" if (result != null) result.call\n"
"\n"
" loadModule_\n"
" return lookUpVariable_(variable)\n"
" }\n"
"}\n"
@ -1308,6 +1306,13 @@ DEF_NATIVE(string_loadModule)
// If it returned a string, it was an error message.
if (IS_STRING(args[0])) return PRIM_ERROR;
// If it returned a fiber, we want to call it.
if (IS_FIBER(args[0]))
{
AS_FIBER(args[0])->caller = fiber;
return PRIM_RUN_FIBER;
}
return PRIM_VALUE;
}

View File

@ -455,6 +455,9 @@ typedef struct
// Returns true if [value] is a closure.
#define IS_CLOSURE(value) (wrenIsObjType(value, OBJ_CLOSURE))
// Returns true if [value] is a fiber.
#define IS_FIBER(value) (wrenIsObjType(value, OBJ_FIBER))
// Returns true if [value] is a function object.
#define IS_FN(value) (wrenIsObjType(value, OBJ_FN))