diff --git a/builtin/core.wren b/builtin/core.wren index 33e753c4..8fe04790 100644 --- a/builtin/core.wren +++ b/builtin/core.wren @@ -58,12 +58,7 @@ class Sequence { } } -class String is Sequence { - import_(variable) { - loadModule_ - return lookUpVariable_(variable) - } -} +class String is Sequence {} class List is Sequence { addAll(other) { diff --git a/src/wren_compiler.c b/src/wren_compiler.c index e9de2c06..4bbacada 100644 --- a/src/wren_compiler.c +++ b/src/wren_compiler.c @@ -2911,10 +2911,14 @@ static void import(Compiler* compiler) wrenNewString(compiler->parser->vm, compiler->parser->previous.start, compiler->parser->previous.length)); + // Call "module".loadModule_ emitShortArg(compiler, CODE_CONSTANT, moduleConstant); - emitShortArg(compiler, CODE_CONSTANT, variableConstant); + emitShortArg(compiler, CODE_CALL_0, + methodSymbol(compiler, "loadModule_", 11)); // Call "module".import_("variable") + emitShortArg(compiler, CODE_CONSTANT, moduleConstant); + emitShortArg(compiler, CODE_CONSTANT, variableConstant); emitShortArg(compiler, CODE_CALL_1, methodSymbol(compiler, "import_ ", 8)); // Store the result in the variable here. diff --git a/src/wren_core.c b/src/wren_core.c index fdbd2e6b..0a57d71a 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -101,12 +101,7 @@ static const char* libSource = " }\n" "}\n" "\n" -"class String is Sequence {\n" -" import_(variable) {\n" -" loadModule_\n" -" return lookUpVariable_(variable)\n" -" }\n" -"}\n" +"class String is Sequence {}\n" "\n" "class List is Sequence {\n" " addAll(other) {\n" @@ -1316,7 +1311,7 @@ DEF_NATIVE(string_loadModule) return PRIM_VALUE; } -DEF_NATIVE(string_lookUpVariable) +DEF_NATIVE(string_import) { uint32_t moduleEntry = wrenMapFind(vm->modules, args[0]); ASSERT(moduleEntry != UINT32_MAX, "Should only look up loaded modules."); @@ -1560,7 +1555,7 @@ void wrenInitializeCore(WrenVM* vm) // TODO: Putting these on String is pretty strange. Find a better home for // them. NATIVE(vm->stringClass, "loadModule_", string_loadModule); - NATIVE(vm->stringClass, "lookUpVariable_ ", string_lookUpVariable); + NATIVE(vm->stringClass, "import_ ", string_import); // While bootstrapping the core types and running the core library, a number // string objects have been created, many of which were instantiated before