2021-06-03 10:46:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-06-05 15:53:36 +02:00
|
|
|
#include <AK/NonnullOwnPtrVector.h>
|
2021-06-04 12:07:38 +02:00
|
|
|
#include <LibJS/Bytecode/Label.h>
|
2021-06-03 10:46:30 +02:00
|
|
|
#include <LibJS/Bytecode/Register.h>
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2021-06-05 15:53:36 +02:00
|
|
|
using RegisterWindow = Vector<Value>;
|
|
|
|
|
2021-06-03 10:46:30 +02:00
|
|
|
class Interpreter {
|
|
|
|
public:
|
|
|
|
explicit Interpreter(GlobalObject&);
|
|
|
|
~Interpreter();
|
|
|
|
|
2021-06-05 15:53:36 +02:00
|
|
|
// FIXME: Remove this thing once we don't need it anymore!
|
|
|
|
static Interpreter* current();
|
|
|
|
|
2021-06-03 10:46:30 +02:00
|
|
|
GlobalObject& global_object() { return m_global_object; }
|
2021-06-03 18:26:13 +02:00
|
|
|
VM& vm() { return m_vm; }
|
2021-06-03 10:46:30 +02:00
|
|
|
|
2021-06-05 15:53:36 +02:00
|
|
|
Value run(Bytecode::Block const&);
|
2021-06-03 10:46:30 +02:00
|
|
|
|
2021-06-07 20:58:36 -07:00
|
|
|
ALWAYS_INLINE Value& accumulator() { return reg(Register::accumulator()); }
|
2021-06-05 15:53:36 +02:00
|
|
|
Value& reg(Register const& r) { return registers()[r.index()]; }
|
2021-06-03 10:46:30 +02:00
|
|
|
|
2021-06-04 12:07:38 +02:00
|
|
|
void jump(Label const& label) { m_pending_jump = label.address(); }
|
2021-06-05 15:53:36 +02:00
|
|
|
void do_return(Value return_value) { m_return_value = return_value; }
|
2021-06-04 12:07:38 +02:00
|
|
|
|
2021-06-03 10:46:30 +02:00
|
|
|
private:
|
2021-06-05 15:53:36 +02:00
|
|
|
RegisterWindow& registers() { return m_register_windows.last(); }
|
|
|
|
|
2021-06-03 18:26:13 +02:00
|
|
|
VM& m_vm;
|
2021-06-03 10:46:30 +02:00
|
|
|
GlobalObject& m_global_object;
|
2021-06-05 15:53:36 +02:00
|
|
|
NonnullOwnPtrVector<RegisterWindow> m_register_windows;
|
2021-06-04 12:07:38 +02:00
|
|
|
Optional<size_t> m_pending_jump;
|
2021-06-05 15:53:36 +02:00
|
|
|
Value m_return_value;
|
2021-06-03 10:46:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|