Interpreter.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullOwnPtrVector.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::Block const&);
  24. Value& reg(Register const& r) { return registers()[r.index()]; }
  25. void jump(Label const& label) { m_pending_jump = label.address(); }
  26. void do_return(Value return_value) { m_return_value = return_value; }
  27. private:
  28. RegisterWindow& registers() { return m_register_windows.last(); }
  29. VM& m_vm;
  30. GlobalObject& m_global_object;
  31. NonnullOwnPtrVector<RegisterWindow> m_register_windows;
  32. Optional<size_t> m_pending_jump;
  33. Value m_return_value;
  34. };
  35. }