mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibJS: Rip out the AST interpreter :^)
This has been superseded by the bytecode VM, which is both faster and more capable.
This commit is contained in:
parent
fcc72a787b
commit
2eaa528a0e
41 changed files with 147 additions and 3734 deletions
|
@ -15,7 +15,6 @@
|
|||
#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>
|
||||
#include <LibJS/Runtime/BoundFunction.h>
|
||||
|
@ -188,19 +187,6 @@ void VM::enable_default_host_import_module_dynamically_hook()
|
|||
};
|
||||
}
|
||||
|
||||
Interpreter& VM::interpreter()
|
||||
{
|
||||
VERIFY(!m_interpreters.is_empty());
|
||||
return *m_interpreters.last();
|
||||
}
|
||||
|
||||
Interpreter* VM::interpreter_if_exists()
|
||||
{
|
||||
if (m_interpreters.is_empty())
|
||||
return nullptr;
|
||||
return m_interpreters.last();
|
||||
}
|
||||
|
||||
Bytecode::Interpreter& VM::bytecode_interpreter()
|
||||
{
|
||||
return *m_bytecode_interpreter;
|
||||
|
@ -211,29 +197,6 @@ Bytecode::Interpreter* VM::bytecode_interpreter_if_exists()
|
|||
return m_bytecode_interpreter;
|
||||
}
|
||||
|
||||
void VM::push_interpreter(Interpreter& interpreter)
|
||||
{
|
||||
m_interpreters.append(&interpreter);
|
||||
}
|
||||
|
||||
void VM::pop_interpreter(Interpreter& interpreter)
|
||||
{
|
||||
VERIFY(!m_interpreters.is_empty());
|
||||
auto* popped_interpreter = m_interpreters.take_last();
|
||||
VERIFY(popped_interpreter == &interpreter);
|
||||
}
|
||||
|
||||
VM::InterpreterExecutionScope::InterpreterExecutionScope(Interpreter& interpreter)
|
||||
: m_interpreter(interpreter)
|
||||
{
|
||||
m_interpreter.vm().push_interpreter(m_interpreter);
|
||||
}
|
||||
|
||||
VM::InterpreterExecutionScope::~InterpreterExecutionScope()
|
||||
{
|
||||
m_interpreter.vm().pop_interpreter(m_interpreter);
|
||||
}
|
||||
|
||||
void VM::gather_roots(HashTable<Cell*>& roots)
|
||||
{
|
||||
roots.set(m_empty_string);
|
||||
|
@ -356,15 +319,11 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern
|
|||
|
||||
ThrowCompletionOr<Value> VM::execute_ast_node(ASTNode const& node)
|
||||
{
|
||||
if (auto* bytecode_interpreter = bytecode_interpreter_if_exists()) {
|
||||
auto executable = TRY(Bytecode::compile(*this, node, FunctionKind::Normal, ""sv));
|
||||
auto result_or_error = bytecode_interpreter->run_and_return_frame(*current_realm(), *executable, nullptr);
|
||||
if (result_or_error.value.is_error())
|
||||
return result_or_error.value.release_error();
|
||||
return result_or_error.frame->registers[0];
|
||||
}
|
||||
|
||||
return TRY(node.execute(interpreter())).value();
|
||||
auto executable = TRY(Bytecode::compile(*this, node, FunctionKind::Normal, ""sv));
|
||||
auto result_or_error = bytecode_interpreter().run_and_return_frame(*current_realm(), *executable, nullptr);
|
||||
if (result_or_error.value.is_error())
|
||||
return result_or_error.value.release_error();
|
||||
return result_or_error.frame->registers[0];
|
||||
}
|
||||
|
||||
// 13.15.5.3 Runtime Semantics: PropertyDestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-propertydestructuringassignmentevaluation
|
||||
|
@ -385,8 +344,6 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
Reference assignment_target;
|
||||
if (auto identifier_ptr = property.name.get_pointer<NonnullRefPtr<Identifier const>>()) {
|
||||
assignment_target = TRY(resolve_binding((*identifier_ptr)->string(), environment));
|
||||
} else if (auto member_ptr = property.alias.get_pointer<NonnullRefPtr<MemberExpression const>>()) {
|
||||
assignment_target = TRY((*member_ptr)->to_reference(interpreter()));
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
@ -436,8 +393,8 @@ ThrowCompletionOr<void> VM::property_binding_initialization(BindingPattern const
|
|||
return TRY(resolve_binding(identifier->string(), environment));
|
||||
},
|
||||
[&](NonnullRefPtr<BindingPattern const> const&) -> ThrowCompletionOr<Optional<Reference>> { return Optional<Reference> {}; },
|
||||
[&](NonnullRefPtr<MemberExpression const> const& member_expression) -> ThrowCompletionOr<Optional<Reference>> {
|
||||
return TRY(member_expression->to_reference(interpreter()));
|
||||
[&](NonnullRefPtr<MemberExpression const> const&) -> ThrowCompletionOr<Optional<Reference>> {
|
||||
VERIFY_NOT_REACHED();
|
||||
}));
|
||||
|
||||
auto value_to_assign = TRY(object->get(name));
|
||||
|
@ -480,8 +437,8 @@ ThrowCompletionOr<void> VM::iterator_binding_initialization(BindingPattern const
|
|||
return TRY(resolve_binding(identifier->string(), environment));
|
||||
},
|
||||
[&](NonnullRefPtr<BindingPattern const> const&) -> ThrowCompletionOr<Optional<Reference>> { return Optional<Reference> {}; },
|
||||
[&](NonnullRefPtr<MemberExpression const> const& member_expression) -> ThrowCompletionOr<Optional<Reference>> {
|
||||
return TRY(member_expression->to_reference(interpreter()));
|
||||
[&](NonnullRefPtr<MemberExpression const> const&) -> ThrowCompletionOr<Optional<Reference>> {
|
||||
VERIFY_NOT_REACHED();
|
||||
}));
|
||||
|
||||
// BindingRestElement : ... BindingIdentifier
|
||||
|
@ -861,11 +818,6 @@ VM::StoredModule* VM::get_stored_module(ScriptOrModule const&, DeprecatedString
|
|||
return &(*end_or_module);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> VM::link_and_eval_module(Badge<Interpreter>, SourceTextModule& module)
|
||||
{
|
||||
return link_and_eval_module(module);
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> VM::link_and_eval_module(Badge<Bytecode::Interpreter>, SourceTextModule& module)
|
||||
{
|
||||
return link_and_eval_module(module);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue