Need to mess with stack slots when import multiple things as locals

This commit is contained in:
K. Lange 2021-01-05 19:47:25 +09:00
parent a4a4da70df
commit 2a901a71a0

View File

@ -1319,14 +1319,22 @@ static void fromImportStatement() {
do {
consume(TOKEN_IDENTIFIER, "Expected member name");
size_t member = identifierConstant(&parser.previous);
emitBytes(OP_DUP, 0); /* Duplicate the package object so we can GET_PROPERTY on it? */
EMIT_CONSTANT_OP(OP_GET_PROPERTY, member);
if (match(TOKEN_AS)) {
consume(TOKEN_IDENTIFIER, "Expected identifier after `as`");
member = identifierConstant(&parser.previous);
}
declareVariable();
defineVariable(member);
if (current->scopeDepth) {
declareVariable();
defineVariable(member);
}
emitBytes(OP_DUP, 0); /* Duplicate the package object so we can GET_PROPERTY on it? */
EMIT_CONSTANT_OP(OP_GET_PROPERTY, member);
if (!current->scopeDepth) {
declareVariable();
defineVariable(member);
} else {
emitByte(OP_SWAP);
}
} while (match(TOKEN_COMMA));
emitByte(OP_POP); /* Pop the remaining copy of the module. */
}