/* * Copyright (c) 2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include "Generator.h" #include #include #include #include #include #include #include namespace JS::Bytecode { using RegisterWindow = Vector; class Interpreter { public: explicit Interpreter(GlobalObject&); ~Interpreter(); // FIXME: Remove this thing once we don't need it anymore! static Interpreter* current(); GlobalObject& global_object() { return m_global_object; } VM& vm() { return m_vm; } Value run(Bytecode::Executable const&, Bytecode::BasicBlock const* entry_point = 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(); } void enter_frame(RegisterWindow const& frame) { ++m_manually_entered_frames; m_register_windows.append(make(frame)); } void leave_frame() { VERIFY(m_manually_entered_frames); --m_manually_entered_frames; m_register_windows.take_last(); } void jump(Label const& label) { m_pending_jump = &label.block(); } void do_return(Value return_value) { m_return_value = return_value; } void enter_unwind_context(Optional