Skip to content

Commit

Permalink
Remove SET op during return
Browse files Browse the repository at this point in the history
  • Loading branch information
john-z-yang committed Dec 10, 2023
1 parent e94c63b commit 23bf8df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/compile/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,15 +556,12 @@ void Compiler::emitRet() {
handleTypeError(lambdaGrammar, te.expected, te.actual);
}

emitCode(OpCode::SET_STACK, 0);

for (const auto &local : locals) {
if (local.isCaptured) {
emitCode(OpCode::CLOSE_UPVALUE, local.stackOffset);
}
}

emitCode(OpCode::POP, stackOffset);
emitCode(OpCode::RETURN);
}

Expand Down
6 changes: 4 additions & 2 deletions src/runtime/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const SExpr *VM::exec() {
MAKE_CLOSURE: {
const auto proto = cast<Prototype>(readConst());
std::vector<std::shared_ptr<Upvalue>> upvalues;
for (unsigned int i{0}; i < proto->numUpvals; ++i) {
for (auto i = 0U; i < proto->numUpvals; ++i) {
auto isLocal = readByte();
auto idx = readByte();
if (isLocal == 1) {
Expand All @@ -144,15 +144,17 @@ CALL: { call(readByte()); }
goto *dispatchTable[readByte()];

RETURN: {
const auto res = stack.back();
if (callFrames.size() == 1) [[unlikely]] {
const auto res = stack.back();
reset();
return res;
}
stack.erase(stack.end() - (stack.size() - bp - 1), stack.end());
ip = callFrames.back().ip;
bp = callFrames.back().bp;
closure = callFrames.back().closure;
callFrames.pop_back();
stack.back() = res;
}
goto *dispatchTable[readByte()];

Expand Down

0 comments on commit 23bf8df

Please sign in to comment.