1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 06:18:12 +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);
if (m_saved_exception.has_value())
visitor.visit(*m_saved_exception);
for (auto& window : m_register_windows) {
window.visit([&](auto& value) { value->visit_edges(visitor); });
for (auto& frame : m_call_frames) {
frame.visit([&](auto& value) { value->visit_edges(visitor); });
}
}
@ -193,7 +193,7 @@ ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
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);
@ -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() };
if (in_frame)
push_register_window(in_frame, executable.number_of_registers);
push_call_frame(in_frame, executable.number_of_registers);
else
push_register_window(make<RegisterWindow>(), executable.number_of_registers);
push_call_frame(make<CallFrame>(), executable.number_of_registers);
for (;;) {
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();
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.
if (!m_register_windows.is_empty())
window().registers[0] = return_value;
if (!m_call_frames.is_empty())
call_frame().registers[0] = return_value;
// 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.
@ -349,13 +349,13 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Realm& realm, Execu
Value thrown_value = m_saved_exception.value();
m_saved_exception = {};
m_saved_return_value = {};
if (auto* register_window = frame.get_pointer<NonnullOwnPtr<RegisterWindow>>())
return { throw_completion(thrown_value), move(*register_window) };
if (auto* call_frame = frame.get_pointer<NonnullOwnPtr<CallFrame>>())
return { throw_completion(thrown_value), move(*call_frame) };
return { throw_completion(thrown_value), nullptr };
}
if (auto* register_window = frame.get_pointer<NonnullOwnPtr<RegisterWindow>>())
return { return_value, move(*register_window) };
if (auto* call_frame = frame.get_pointer<NonnullOwnPtr<CallFrame>>())
return { return_value, move(*call_frame) };
return { return_value, nullptr };
}
@ -462,18 +462,18 @@ Realm& Interpreter::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));
this->window().registers.resize(register_count);
m_current_register_window = this->window().registers;
m_call_frames.append(move(frame));
this->call_frame().registers.resize(register_count);
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();
m_current_register_window = m_register_windows.is_empty() ? Span<Value> {} : this->window().registers;
return window;
auto frame = m_call_frames.take_last();
m_current_call_frame = m_call_frames.is_empty() ? Span<Value> {} : this->call_frame().registers;
return frame;
}
}

View file

@ -19,7 +19,7 @@ namespace JS::Bytecode {
class InstructionStreamIterator;
class PassManager;
struct RegisterWindow {
struct CallFrame {
void visit_edges(Cell::Visitor& visitor)
{
for (auto const& value : registers)
@ -58,15 +58,15 @@ public:
struct ValueAndFrame {
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()); }
Value& reg(Register const& r) { return registers()[r.index()]; }
auto& saved_lexical_environment_stack() { return window().saved_lexical_environments; }
auto& unwind_contexts() { return window().unwind_contexts; }
auto& saved_lexical_environment_stack() { return call_frame().saved_lexical_environments; }
auto& unwind_contexts() { return call_frame().unwind_contexts; }
void jump(Label const& label)
{
@ -101,25 +101,25 @@ public:
void visit_edges(Cell::Visitor&);
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; }
ReadonlySpan<Value> registers() const { return m_current_register_window; }
Span<Value> registers() { return m_current_call_frame; }
ReadonlySpan<Value> registers() const { return m_current_call_frame; }
void push_register_window(Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*>, size_t register_count);
[[nodiscard]] Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*> pop_register_window();
void push_call_frame(Variant<NonnullOwnPtr<CallFrame>, CallFrame*>, size_t register_count);
[[nodiscard]] Variant<NonnullOwnPtr<CallFrame>, CallFrame*> pop_call_frame();
VM& m_vm;
Vector<Variant<NonnullOwnPtr<RegisterWindow>, RegisterWindow*>> m_register_windows;
Span<Value> m_current_register_window;
Vector<Variant<NonnullOwnPtr<CallFrame>, CallFrame*>> m_call_frames;
Span<Value> m_current_call_frame;
Optional<BasicBlock const*> m_pending_jump;
BasicBlock const* m_scheduled_jump { nullptr };
Optional<Value> m_return_value;