diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index 5f26593057d..32971a4b30d 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -563,17 +563,20 @@ private: class Label { public: - explicit Label(size_t arity, InstructionPointer continuation) + explicit Label(size_t arity, InstructionPointer continuation, size_t stack_height) : m_arity(arity) + , m_stack_height(stack_height) , m_continuation(continuation) { } auto continuation() const { return m_continuation; } auto arity() const { return m_arity; } + auto stack_height() const { return m_stack_height; } private: size_t m_arity { 0 }; + size_t m_stack_height { 0 }; InstructionPointer m_continuation { 0 }; }; @@ -592,31 +595,15 @@ public: auto& locals() { return m_locals; } auto& expression() const { return m_expression; } auto arity() const { return m_arity; } + auto label_index() const { return m_label_index; } + auto& label_index() { return m_label_index; } private: ModuleInstance const& m_module; Vector m_locals; Expression const& m_expression; size_t m_arity { 0 }; -}; - -class Stack { -public: - using EntryType = Variant; - Stack() = default; - - [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_data.is_empty(); } - ALWAYS_INLINE void push(EntryType entry) { m_data.append(move(entry)); } - ALWAYS_INLINE auto pop() { return m_data.take_last(); } - ALWAYS_INLINE auto& peek() const { return m_data.last(); } - ALWAYS_INLINE auto& peek() { return m_data.last(); } - - ALWAYS_INLINE auto size() const { return m_data.size(); } - ALWAYS_INLINE auto& entries() const { return m_data; } - ALWAYS_INLINE auto& entries() { return m_data; } - -private: - Vector m_data; + size_t m_label_index { 0 }; }; using InstantiationResult = AK::ErrorOr, InstantiationError>; diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index e32bd3b93fd..8e5ee208ae5 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -59,24 +59,19 @@ void BytecodeInterpreter::interpret(Configuration& configuration) void BytecodeInterpreter::branch_to_label(Configuration& configuration, LabelIndex index) { dbgln_if(WASM_TRACE_DEBUG, "Branch to label with index {}...", index.value()); - auto label = configuration.nth_label(index.value()); - dbgln_if(WASM_TRACE_DEBUG, "...which is actually IP {}, and has {} result(s)", label->continuation().value(), label->arity()); - auto results = pop_values(configuration, label->arity()); + for (size_t i = 0; i < index.value(); ++i) + configuration.label_stack().take_last(); + auto label = configuration.label_stack().last(); + dbgln_if(WASM_TRACE_DEBUG, "...which is actually IP {}, and has {} result(s)", label.continuation().value(), label.arity()); + auto results = pop_values(configuration, label.arity()); - size_t drop_count = index.value() + 1; - for (; !configuration.stack().is_empty();) { - auto& entry = configuration.stack().peek(); - if (entry.has