Interpreter.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "Generator.h"
  8. #include <LibJS/Bytecode/Label.h>
  9. #include <LibJS/Bytecode/Register.h>
  10. #include <LibJS/Forward.h>
  11. #include <LibJS/Heap/Cell.h>
  12. #include <LibJS/Runtime/Value.h>
  13. namespace JS::Bytecode {
  14. using RegisterWindow = Vector<Value>;
  15. class Interpreter {
  16. public:
  17. explicit Interpreter(GlobalObject&);
  18. ~Interpreter();
  19. // FIXME: Remove this thing once we don't need it anymore!
  20. static Interpreter* current();
  21. GlobalObject& global_object() { return m_global_object; }
  22. VM& vm() { return m_vm; }
  23. Value run(Bytecode::ExecutionUnit const&);
  24. ALWAYS_INLINE Value& accumulator() { return reg(Register::accumulator()); }
  25. Value& reg(Register const& r) { return registers()[r.index()]; }
  26. void jump(Label const& label)
  27. {
  28. m_pending_jump = &label.block();
  29. }
  30. void do_return(Value return_value) { m_return_value = return_value; }
  31. private:
  32. RegisterWindow& registers() { return m_register_windows.last(); }
  33. VM& m_vm;
  34. GlobalObject& m_global_object;
  35. NonnullOwnPtrVector<RegisterWindow> m_register_windows;
  36. Optional<BasicBlock const*> m_pending_jump;
  37. Value m_return_value;
  38. };
  39. }