diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-04-22 11:03:23 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-04-22 21:12:47 +0430 |
commit | 2c0716e31480a2a91920b80ba3a5880a126cadd4 (patch) | |
tree | 826d9782c93474c704dc64bd9303019c065c2778 | |
parent | 846b2c8a99b517244af5e31a33d264f6518f5863 (diff) | |
download | serenity-2c0716e31480a2a91920b80ba3a5880a126cadd4.zip |
LibWasm: Simplify the return instruction execution code a bit
-rw-r--r-- | Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 89e9dff285..83586133c9 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -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(); |