mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:57:44 +00:00
LibJS/Bytecode: Simplify Bytecode::Interpreter lifetime model
The JS::VM now owns the one Bytecode::Interpreter. We no longer have multiple bytecode interpreters, and there is no concept of a "current" bytecode interpreter. If you ask for VM::bytecode_interpreter_if_exists(), it will return null if we're not running the program in "bytecode enabled" mode. If you ask for VM::bytecode_interpreter(), it will return a bytecode interpreter in all modes. This is used for situations where even the AST interpreter switches to bytecode mode (generators, etc.)
This commit is contained in:
parent
6150960671
commit
6537ed8fff
15 changed files with 117 additions and 106 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <LibFileSystem/FileSystem.h>
|
||||
#include <LibJS/AST.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibJS/Interpreter.h>
|
||||
#include <LibJS/Runtime/AbstractOperations.h>
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
|
@ -65,6 +66,8 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
|
|||
, m_error_messages(move(error_messages))
|
||||
, m_custom_data(move(custom_data))
|
||||
{
|
||||
m_bytecode_interpreter = make<Bytecode::Interpreter>(*this);
|
||||
|
||||
m_empty_string = m_heap.allocate_without_realm<PrimitiveString>(String {});
|
||||
|
||||
for (size_t i = 0; i < single_ascii_character_strings.size(); ++i)
|
||||
|
@ -166,6 +169,8 @@ VM::VM(OwnPtr<CustomData> custom_data, ErrorMessages error_messages)
|
|||
};
|
||||
}
|
||||
|
||||
VM::~VM() = default;
|
||||
|
||||
String const& VM::error_message(ErrorMessage type) const
|
||||
{
|
||||
VERIFY(type < ErrorMessage::__Count);
|
||||
|
@ -196,6 +201,18 @@ Interpreter* VM::interpreter_if_exists()
|
|||
return m_interpreters.last();
|
||||
}
|
||||
|
||||
Bytecode::Interpreter& VM::bytecode_interpreter()
|
||||
{
|
||||
return *m_bytecode_interpreter;
|
||||
}
|
||||
|
||||
Bytecode::Interpreter* VM::bytecode_interpreter_if_exists()
|
||||
{
|
||||
if (!Bytecode::Interpreter::enabled())
|
||||
return nullptr;
|
||||
return m_bytecode_interpreter;
|
||||
}
|
||||
|
||||
void VM::push_interpreter(Interpreter& interpreter)
|
||||
{
|
||||
m_interpreters.append(&interpreter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue