1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:38:10 +00:00

LibWasm: Simplify the return instruction execution code a bit

This commit is contained in:
Ali Mohammad Pur 2022-04-22 11:03:23 +04:30 committed by Ali Mohammad Pur
parent 846b2c8a99
commit 2c0716e314

View file

@ -461,18 +461,21 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi
}
case Instructions::return_.value(): {
auto& frame = configuration.frame();
size_t end = configuration.stack().size() - frame.arity();
size_t start = end;
for (; start + 1 > 0 && start < configuration.stack().size(); --start) {
auto& entry = configuration.stack().entries()[start];
if (entry.has<Frame>()) {
// Leave the frame, _and_ its label.
start += 2;
break;
Checked checked_index { configuration.stack().size() };
checked_index -= frame.arity();
VERIFY(!checked_index.has_overflow());
auto index = checked_index.value();
size_t i = 1;
for (; i <= index; ++i) {
auto& entry = configuration.stack().entries()[index - i];
if (entry.has<Label>()) {
if (configuration.stack().entries()[index - i - 1].has<Frame>())
break;
}
}
configuration.stack().entries().remove(start, end - start);
configuration.stack().entries().remove(index - i + 1, i - 1);
// Jump past the call/indirect instruction
configuration.ip() = configuration.frame().expression().instructions().size();