1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:57:35 +00:00

LibJS/Bytecode: Rename RegisterWindow to CallFrame

This is a better name for what it actually represents.
This commit is contained in:
Andreas Kling 2023-07-20 10:46:42 +02:00
parent 061ebd0b15
commit 6de22ec789
6 changed files with 43 additions and 43 deletions

View file

@ -58,8 +58,8 @@ void Interpreter::visit_edges(Cell::Visitor& visitor)
visitor.visit(*m_saved_return_value); visitor.visit(*m_saved_return_value);
if (m_saved_exception.has_value()) if (m_saved_exception.has_value())
visitor.visit(*m_saved_exception); visitor.visit(*m_saved_exception);
for (auto& window : m_register_windows) { for (auto& frame : m_call_frames) {
window.visit([&](auto& value) { value->visit_edges(visitor); }); frame.visit([&](auto& value) { value->visit_edges(visitor); });
} }
} }
@ -193,7 +193,7 @@ ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
return js_undefined(); return js_undefined();
} }
Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Executable& executable, BasicBlock const* entry_point, RegisterWindow* in_frame) Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Executable& executable, BasicBlock const* entry_point, CallFrame* in_frame)
{ {
dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter will run unit {:p}", &executable); dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter will run unit {:p}", &executable);
@ -219,9 +219,9 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Execu
TemporaryChange restore_current_block { m_current_block, entry_point ?: executable.basic_blocks.first() }; TemporaryChange restore_current_block { m_current_block, entry_point ?: executable.basic_blocks.first() };
if (in_frame) if (in_frame)
push_register_window(in_frame, executable.number_of_registers); push_call_frame(in_frame, executable.number_of_registers);
else else
push_register_window(make<RegisterWindow>(), executable.number_of_registers); push_call_frame(make<CallFrame>(), executable.number_of_registers);
for (;;) { for (;;) {
Bytecode::InstructionStreamIterator pc(m_current_block->instruction_stream()); Bytecode::InstructionStreamIterator pc(m_current_block->instruction_stream());
@ -321,7 +321,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Execu
} }
} }
auto frame = pop_register_window(); auto frame = pop_call_frame();
Value return_value = js_undefined(); Value return_value = js_undefined();
if (m_return_value.has_value()) { if (m_return_value.has_value()) {
@ -331,8 +331,8 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Execu
} }
// NOTE: The return value from a called function is put into $0 in the caller context. // NOTE: The return value from a called function is put into $0 in the caller context.
if (!m_register_windows.is_empty()) if (!m_call_frames.is_empty())
window().registers[0] = return_value; call_frame().registers[0] = return_value;
// At this point we may have already run any queued promise jobs via on_call_stack_emptied, // At this point we may have already run any queued promise jobs via on_call_stack_emptied,
// in which case this is a no-op. // in which case this is a no-op.
@ -349,13 +349,13 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Execu
Value thrown_value = m_saved_exception.value(); Value thrown_value = m_saved_exception.value();
m_saved_exception = {}; m_saved_exception = {};
m_saved_return_value = {}; m_saved_return_value = {};
if (auto* register_window = frame.get_pointer<NonnullOwnPtr<RegisterWindow>>()) if (auto* call_frame = frame.get_pointer<NonnullOwnPtr<CallFrame>>())
return { throw_completion(thrown_value), move(*register_window) }; return { throw_completion(thrown_value), move(*call_frame) };
return { throw_completion(thrown_value), nullptr }; return { throw_completion(thrown_value), nullptr };
} }
if (auto* register_window = frame.get_pointer<NonnullOwnPtr<RegisterWindow>>()) if (auto* call_frame = frame.get_pointer<NonnullOwnPtr<CallFrame>>())
return { return_value, move(*register_window) }; return { return_value, move(*call_frame) };
return { return_value, nullptr }; return { return_value, nullptr };
} }
@ -462,18 +462,18 @@ Realm& Interpreter::realm()
return *m_vm.current_realm(); return *m_vm.current_realm();
} }
void Interpreter::push_register_window(Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*> window, size_t register_count) void Interpreter::push_call_frame(Variant<NonnullOwnPtr<CallFrame>, CallFrame*> frame, size_t register_count)
{ {
m_register_windows.append(move(window)); m_call_frames.append(move(frame));
this->window().registers.resize(register_count); this->call_frame().registers.resize(register_count);
m_current_register_window = this->window().registers; m_current_call_frame = this->call_frame().registers;
} }
Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*> Interpreter::pop_register_window() Variant<NonnullOwnPtr<CallFrame>, CallFrame*> Interpreter::pop_call_frame()
{ {
auto window = m_register_windows.take_last(); auto frame = m_call_frames.take_last();
m_current_register_window = m_register_windows.is_empty() ? Span<Value> {} : this->window().registers; m_current_call_frame = m_call_frames.is_empty() ? Span<Value> {} : this->call_frame().registers;
return window; return frame;
} }
} }

View file

@ -19,7 +19,7 @@ namespace JS::Bytecode {
class InstructionStreamIterator; class InstructionStreamIterator;
class PassManager; class PassManager;
struct RegisterWindow { struct CallFrame {
void visit_edges(Cell::Visitor& visitor) void visit_edges(Cell::Visitor& visitor)
{ {
for (auto const& value : registers) for (auto const& value : registers)
@ -58,15 +58,15 @@ public:
struct ValueAndFrame { struct ValueAndFrame {
ThrowCompletionOr<Value> value; ThrowCompletionOr<Value> value;
OwnPtr<RegisterWindow> frame; OwnPtr<CallFrame> frame;
}; };
ValueAndFrame run_and_return_frame(Realm&, Bytecode::Executable&, Bytecode::BasicBlock const* entry_point, RegisterWindow* = nullptr); ValueAndFrame run_and_return_frame(Realm&, Bytecode::Executable&, Bytecode::BasicBlock const* entry_point, CallFrame* = nullptr);
ALWAYS_INLINE Value& accumulator() { return reg(Register::accumulator()); } ALWAYS_INLINE Value& accumulator() { return reg(Register::accumulator()); }
Value& reg(Register const& r) { return registers()[r.index()]; } Value& reg(Register const& r) { return registers()[r.index()]; }
auto& saved_lexical_environment_stack() { return window().saved_lexical_environments; } auto& saved_lexical_environment_stack() { return call_frame().saved_lexical_environments; }
auto& unwind_contexts() { return window().unwind_contexts; } auto& unwind_contexts() { return call_frame().unwind_contexts; }
void jump(Label const& label) void jump(Label const& label)
{ {
@ -101,25 +101,25 @@ public:
void visit_edges(Cell::Visitor&); void visit_edges(Cell::Visitor&);
private: private:
RegisterWindow& window() CallFrame& call_frame()
{ {
return m_register_windows.last().visit([](auto& x) -> RegisterWindow& { return *x; }); return m_call_frames.last().visit([](auto& x) -> CallFrame& { return *x; });
} }
RegisterWindow const& window() const CallFrame const& call_frame() const
{ {
return const_cast<Interpreter*>(this)->window(); return const_cast<Interpreter*>(this)->call_frame();
} }
Span<Value> registers() { return m_current_register_window; } Span<Value> registers() { return m_current_call_frame; }
ReadonlySpan<Value> registers() const { return m_current_register_window; } ReadonlySpan<Value> registers() const { return m_current_call_frame; }
void push_register_window(Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*>, size_t register_count); void push_call_frame(Variant<NonnullOwnPtr<CallFrame>, CallFrame*>, size_t register_count);
[[nodiscard]] Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*> pop_register_window(); [[nodiscard]] Variant<NonnullOwnPtr<CallFrame>, CallFrame*> pop_call_frame();
VM& m_vm; VM& m_vm;
Vector<Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*>> m_register_windows; Vector<Variant<NonnullOwnPtr<CallFrame>, CallFrame*>> m_call_frames;
Span<Value> m_current_register_window; Span<Value> m_current_call_frame;
Optional<BasicBlock const*> m_pending_jump; Optional<BasicBlock const*> m_pending_jump;
BasicBlock const* m_scheduled_jump { nullptr }; BasicBlock const* m_scheduled_jump { nullptr };
Optional<Value> m_return_value; Optional<Value> m_return_value;

View file

@ -14,7 +14,7 @@
namespace JS { namespace JS {
ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> AsyncGenerator::create(Realm& realm, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::RegisterWindow frame) ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> AsyncGenerator::create(Realm& realm, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::CallFrame frame)
{ {
auto& vm = realm.vm(); auto& vm = realm.vm();
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png) // This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
@ -190,7 +190,7 @@ void AsyncGenerator::execute(VM& vm, Completion completion)
VERIFY(!m_generating_function->bytecode_executable()->basic_blocks.find_if([next_block](auto& block) { return block == next_block; }).is_end()); VERIFY(!m_generating_function->bytecode_executable()->basic_blocks.find_if([next_block](auto& block) { return block == next_block; }).is_end());
Bytecode::RegisterWindow* frame = nullptr; Bytecode::CallFrame* frame = nullptr;
if (m_frame.has_value()) if (m_frame.has_value())
frame = &m_frame.value(); frame = &m_frame.value();

View file

@ -27,7 +27,7 @@ public:
Completed, Completed,
}; };
static ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> create(Realm&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow); static ThrowCompletionOr<NonnullGCPtr<AsyncGenerator>> create(Realm&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::CallFrame);
virtual ~AsyncGenerator() override = default; virtual ~AsyncGenerator() override = default;
@ -59,7 +59,7 @@ private:
GCPtr<ECMAScriptFunctionObject> m_generating_function; GCPtr<ECMAScriptFunctionObject> m_generating_function;
Value m_previous_value; Value m_previous_value;
Optional<Bytecode::RegisterWindow> m_frame; Optional<Bytecode::CallFrame> m_frame;
GCPtr<Promise> m_current_promise; GCPtr<Promise> m_current_promise;
}; };

View file

@ -14,7 +14,7 @@
namespace JS { namespace JS {
ThrowCompletionOr<NonnullGCPtr<GeneratorObject>> GeneratorObject::create(Realm& realm, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::RegisterWindow frame) ThrowCompletionOr<NonnullGCPtr<GeneratorObject>> GeneratorObject::create(Realm& realm, Value initial_value, ECMAScriptFunctionObject* generating_function, ExecutionContext execution_context, Bytecode::CallFrame frame)
{ {
auto& vm = realm.vm(); auto& vm = realm.vm();
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png) // This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
@ -111,7 +111,7 @@ ThrowCompletionOr<Value> GeneratorObject::execute(VM& vm, Completion const& comp
VERIFY(!m_generating_function->bytecode_executable()->basic_blocks.find_if([next_block](auto& block) { return block == next_block; }).is_end()); VERIFY(!m_generating_function->bytecode_executable()->basic_blocks.find_if([next_block](auto& block) { return block == next_block; }).is_end());
Bytecode::RegisterWindow* frame = nullptr; Bytecode::CallFrame* frame = nullptr;
if (m_frame.has_value()) if (m_frame.has_value())
frame = &m_frame.value(); frame = &m_frame.value();

View file

@ -16,7 +16,7 @@ class GeneratorObject : public Object {
JS_OBJECT(GeneratorObject, Object); JS_OBJECT(GeneratorObject, Object);
public: public:
static ThrowCompletionOr<NonnullGCPtr<GeneratorObject>> create(Realm&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::RegisterWindow); static ThrowCompletionOr<NonnullGCPtr<GeneratorObject>> create(Realm&, Value, ECMAScriptFunctionObject*, ExecutionContext, Bytecode::CallFrame);
virtual ~GeneratorObject() override = default; virtual ~GeneratorObject() override = default;
void visit_edges(Cell::Visitor&) override; void visit_edges(Cell::Visitor&) override;
@ -42,7 +42,7 @@ private:
ExecutionContext m_execution_context; ExecutionContext m_execution_context;
GCPtr<ECMAScriptFunctionObject> m_generating_function; GCPtr<ECMAScriptFunctionObject> m_generating_function;
Value m_previous_value; Value m_previous_value;
Optional<Bytecode::RegisterWindow> m_frame; Optional<Bytecode::CallFrame> m_frame;
GeneratorState m_generator_state { GeneratorState::SuspendedStart }; GeneratorState m_generator_state { GeneratorState::SuspendedStart };
Optional<StringView> m_generator_brand; Optional<StringView> m_generator_brand;
}; };