Use bytecode to import variable, instead of builtin function.

This commit is contained in:
Bob Nystrom
2015-02-17 07:21:51 -08:00
parent 314c39e430
commit c6043d3c81
5 changed files with 91 additions and 54 deletions
+6 -4
View File
@@ -2484,6 +2484,9 @@ static int getNumArguments(const uint8_t* bytecode, const Value* constants,
case CODE_LOAD_MODULE:
return 2;
case CODE_IMPORT_VARIABLE:
return 4;
case CODE_CLOSURE:
{
int constant = (bytecode[ip + 1] << 8) | bytecode[ip + 2];
@@ -2917,10 +2920,9 @@ static void import(Compiler* compiler)
// Discard the unused result value from calling the module's fiber.
emit(compiler, CODE_POP);
// Call "module".import_("variable")
emitShortArg(compiler, CODE_CONSTANT, moduleConstant);
emitShortArg(compiler, CODE_CONSTANT, variableConstant);
emitShortArg(compiler, CODE_CALL_1, methodSymbol(compiler, "import_ ", 8));
// Load the variable from the other module.
emitShortArg(compiler, CODE_IMPORT_VARIABLE, moduleConstant);
emitShort(compiler, variableConstant);
// Store the result in the variable here.
defineVariable(compiler, slot);