mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:17:34 +00:00
LibJS: Implement the NewClass opcode
This commit is contained in:
parent
8b27917603
commit
d7c207beb9
4 changed files with 23 additions and 4 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <LibJS/Bytecode/Instruction.h>
|
#include <LibJS/Bytecode/Instruction.h>
|
||||||
#include <LibJS/Bytecode/Interpreter.h>
|
#include <LibJS/Bytecode/Interpreter.h>
|
||||||
#include <LibJS/Bytecode/Op.h>
|
#include <LibJS/Bytecode/Op.h>
|
||||||
|
#include <LibJS/Interpreter.h>
|
||||||
#include <LibJS/Runtime/GlobalEnvironment.h>
|
#include <LibJS/Runtime/GlobalEnvironment.h>
|
||||||
#include <LibJS/Runtime/GlobalObject.h>
|
#include <LibJS/Runtime/GlobalObject.h>
|
||||||
#include <LibJS/Runtime/Realm.h>
|
#include <LibJS/Runtime/Realm.h>
|
||||||
|
@ -193,6 +194,14 @@ ThrowCompletionOr<void> Interpreter::continue_pending_unwind(Label const& resume
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VM::InterpreterExecutionScope Interpreter::ast_interpreter_scope()
|
||||||
|
{
|
||||||
|
if (!m_ast_interpreter)
|
||||||
|
m_ast_interpreter = JS::Interpreter::create_with_existing_realm(m_realm);
|
||||||
|
|
||||||
|
return { *m_ast_interpreter };
|
||||||
|
}
|
||||||
|
|
||||||
AK::Array<OwnPtr<PassManager>, static_cast<UnderlyingType<Interpreter::OptimizationLevel>>(Interpreter::OptimizationLevel::__Count)> Interpreter::s_optimization_pipelines {};
|
AK::Array<OwnPtr<PassManager>, static_cast<UnderlyingType<Interpreter::OptimizationLevel>>(Interpreter::OptimizationLevel::__Count)> Interpreter::s_optimization_pipelines {};
|
||||||
|
|
||||||
Bytecode::PassManager& Interpreter::optimization_pipeline(Interpreter::OptimizationLevel level)
|
Bytecode::PassManager& Interpreter::optimization_pipeline(Interpreter::OptimizationLevel level)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibJS/Heap/Cell.h>
|
#include <LibJS/Heap/Cell.h>
|
||||||
#include <LibJS/Heap/Handle.h>
|
#include <LibJS/Heap/Handle.h>
|
||||||
|
#include <LibJS/Runtime/VM.h>
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
|
|
||||||
namespace JS::Bytecode {
|
namespace JS::Bytecode {
|
||||||
|
@ -34,7 +35,7 @@ public:
|
||||||
ThrowCompletionOr<Value> run(Bytecode::Executable const& executable, Bytecode::BasicBlock const* entry_point = nullptr)
|
ThrowCompletionOr<Value> run(Bytecode::Executable const& executable, Bytecode::BasicBlock const* entry_point = nullptr)
|
||||||
{
|
{
|
||||||
auto value_and_frame = run_and_return_frame(executable, entry_point);
|
auto value_and_frame = run_and_return_frame(executable, entry_point);
|
||||||
return value_and_frame.value;
|
return move(value_and_frame.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ValueAndFrame {
|
struct ValueAndFrame {
|
||||||
|
@ -78,6 +79,8 @@ public:
|
||||||
};
|
};
|
||||||
static Bytecode::PassManager& optimization_pipeline(OptimizationLevel = OptimizationLevel::Default);
|
static Bytecode::PassManager& optimization_pipeline(OptimizationLevel = OptimizationLevel::Default);
|
||||||
|
|
||||||
|
VM::InterpreterExecutionScope ast_interpreter_scope();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RegisterWindow& registers() { return m_register_windows.last(); }
|
RegisterWindow& registers() { return m_register_windows.last(); }
|
||||||
|
|
||||||
|
@ -93,6 +96,7 @@ private:
|
||||||
Executable const* m_current_executable { nullptr };
|
Executable const* m_current_executable { nullptr };
|
||||||
Vector<UnwindInfo> m_unwind_contexts;
|
Vector<UnwindInfo> m_unwind_contexts;
|
||||||
Handle<Value> m_saved_exception;
|
Handle<Value> m_saved_exception;
|
||||||
|
OwnPtr<JS::Interpreter> m_ast_interpreter;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern bool g_dump_bytecode;
|
extern bool g_dump_bytecode;
|
||||||
|
|
|
@ -536,10 +536,14 @@ ThrowCompletionOr<void> IteratorResultValue::execute_impl(Bytecode::Interpreter&
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ThrowCompletionOr<void> NewClass::execute_impl(Bytecode::Interpreter&) const
|
ThrowCompletionOr<void> NewClass::execute_impl(Bytecode::Interpreter& interpreter) const
|
||||||
{
|
{
|
||||||
(void)m_class_expression;
|
auto name = m_class_expression.name();
|
||||||
TODO();
|
auto scope = interpreter.ast_interpreter_scope();
|
||||||
|
auto& ast_interpreter = scope.interpreter();
|
||||||
|
auto class_object = TRY(m_class_expression.class_definition_evaluation(ast_interpreter, interpreter.global_object(), name, name.is_null() ? "" : name));
|
||||||
|
interpreter.accumulator() = class_object;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
String Load::to_string_impl(Bytecode::Executable const&) const
|
String Load::to_string_impl(Bytecode::Executable const&) const
|
||||||
|
|
|
@ -55,6 +55,8 @@ public:
|
||||||
InterpreterExecutionScope(Interpreter&);
|
InterpreterExecutionScope(Interpreter&);
|
||||||
~InterpreterExecutionScope();
|
~InterpreterExecutionScope();
|
||||||
|
|
||||||
|
Interpreter& interpreter() { return m_interpreter; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Interpreter& m_interpreter;
|
Interpreter& m_interpreter;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue