Interpreter.h 810 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Bytecode/Label.h>
  8. #include <LibJS/Bytecode/Register.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibJS/Heap/Cell.h>
  11. #include <LibJS/Runtime/Value.h>
  12. namespace JS::Bytecode {
  13. class Interpreter {
  14. public:
  15. explicit Interpreter(GlobalObject&);
  16. ~Interpreter();
  17. GlobalObject& global_object() { return m_global_object; }
  18. VM& vm() { return m_vm; }
  19. void run(Bytecode::Block const&);
  20. Value& reg(Register const& r) { return m_registers[r.index()]; }
  21. void jump(Label const& label) { m_pending_jump = label.address(); }
  22. private:
  23. VM& m_vm;
  24. GlobalObject& m_global_object;
  25. Vector<Value> m_registers;
  26. Optional<size_t> m_pending_jump;
  27. };
  28. }