summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Bytecode/Interpreter.h
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-04-15 20:20:51 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-04-18 23:59:30 +0430
commitd5791c85b476b6a8698f0bb848839710e2333b24 (patch)
tree89c5486119e24b385b8a6ca466a0d423be345ca0 /Userland/Libraries/LibJS/Bytecode/Interpreter.h
parent063ea0088ed4798fc3be7dc47ce4e89dbf3e26f3 (diff)
downloadserenity-d5791c85b476b6a8698f0bb848839710e2333b24.zip
LibJS: Avoid copying the frame into the interpreter in BC generators
Diffstat (limited to 'Userland/Libraries/LibJS/Bytecode/Interpreter.h')
-rw-r--r--Userland/Libraries/LibJS/Bytecode/Interpreter.h35
1 files changed, 15 insertions, 20 deletions
diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.h b/Userland/Libraries/LibJS/Bytecode/Interpreter.h
index e118360597..78904f0ebf 100644
--- a/Userland/Libraries/LibJS/Bytecode/Interpreter.h
+++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.h
@@ -46,27 +46,13 @@ public:
ThrowCompletionOr<Value> value;
OwnPtr<RegisterWindow> frame;
};
- ValueAndFrame run_and_return_frame(Bytecode::Executable const&, Bytecode::BasicBlock const* entry_point);
+ ValueAndFrame run_and_return_frame(Bytecode::Executable const&, Bytecode::BasicBlock const* entry_point, RegisterWindow* = nullptr);
ALWAYS_INLINE Value& accumulator() { return reg(Register::accumulator()); }
Value& reg(Register const& r) { return registers()[r.index()]; }
- [[nodiscard]] RegisterWindow snapshot_frame() const { return m_register_windows.last(); }
- auto& saved_lexical_environment_stack() { return m_register_windows.last().saved_lexical_environments; }
- auto& saved_variable_environment_stack() { return m_register_windows.last().saved_variable_environments; }
-
- void enter_frame(RegisterWindow const& frame)
- {
- m_manually_entered_frames.append(true);
- m_register_windows.append(make<RegisterWindow>(frame));
- }
- NonnullOwnPtr<RegisterWindow> pop_frame()
- {
- VERIFY(!m_manually_entered_frames.is_empty());
- VERIFY(m_manually_entered_frames.last());
- m_manually_entered_frames.take_last();
- return m_register_windows.take_last();
- }
+ auto& saved_lexical_environment_stack() { return window().saved_lexical_environments; }
+ auto& saved_variable_environment_stack() { return window().saved_variable_environments; }
void jump(Label const& label)
{
@@ -89,15 +75,24 @@ public:
VM::InterpreterExecutionScope ast_interpreter_scope();
private:
- MarkedVector<Value>& registers() { return m_register_windows.last().registers; }
+ RegisterWindow& window()
+ {
+ return m_register_windows.last().visit([](auto& x) -> RegisterWindow& { return *x; });
+ }
+
+ RegisterWindow const& window() const
+ {
+ return const_cast<Interpreter*>(this)->window();
+ }
+
+ MarkedVector<Value>& registers() { return window().registers; }
static AK::Array<OwnPtr<PassManager>, static_cast<UnderlyingType<Interpreter::OptimizationLevel>>(Interpreter::OptimizationLevel::__Count)> s_optimization_pipelines;
VM& m_vm;
GlobalObject& m_global_object;
Realm& m_realm;
- NonnullOwnPtrVector<RegisterWindow> m_register_windows;
- Vector<bool> m_manually_entered_frames;
+ Vector<Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*>> m_register_windows;
Optional<BasicBlock const*> m_pending_jump;
Value m_return_value;
Executable const* m_current_executable { nullptr };