mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:07:34 +00:00
LibJS: Move bytecode interpreter's inner loop to its own function
This commit is contained in:
parent
951a85992b
commit
9fe38245b2
2 changed files with 23 additions and 15 deletions
|
@ -161,22 +161,8 @@ ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
|
||||||
return js_undefined();
|
return js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executable, BasicBlock const* entry_point, CallFrame* in_frame)
|
void Interpreter::run_bytecode()
|
||||||
{
|
{
|
||||||
dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter will run unit {:p}", &executable);
|
|
||||||
|
|
||||||
TemporaryChange restore_executable { m_current_executable, &executable };
|
|
||||||
TemporaryChange restore_saved_jump { m_scheduled_jump, static_cast<BasicBlock const*>(nullptr) };
|
|
||||||
|
|
||||||
VERIFY(!vm().execution_context_stack().is_empty());
|
|
||||||
|
|
||||||
TemporaryChange restore_current_block { m_current_block, entry_point ?: executable.basic_blocks.first() };
|
|
||||||
|
|
||||||
if (in_frame)
|
|
||||||
push_call_frame(in_frame, executable.number_of_registers);
|
|
||||||
else
|
|
||||||
push_call_frame(make<CallFrame>(), executable.number_of_registers);
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
auto pc = InstructionStreamIterator { m_current_block->instruction_stream(), m_current_executable };
|
auto pc = InstructionStreamIterator { m_current_block->instruction_stream(), m_current_executable };
|
||||||
TemporaryChange temp_change { m_pc, Optional<InstructionStreamIterator&>(pc) };
|
TemporaryChange temp_change { m_pc, Optional<InstructionStreamIterator&>(pc) };
|
||||||
|
@ -185,6 +171,7 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executa
|
||||||
bool will_jump = false;
|
bool will_jump = false;
|
||||||
bool will_return = false;
|
bool will_return = false;
|
||||||
bool will_yield = false;
|
bool will_yield = false;
|
||||||
|
|
||||||
while (!pc.at_end()) {
|
while (!pc.at_end()) {
|
||||||
auto& instruction = *pc;
|
auto& instruction = *pc;
|
||||||
auto ran_or_error = instruction.execute(*this);
|
auto ran_or_error = instruction.execute(*this);
|
||||||
|
@ -260,6 +247,25 @@ Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executa
|
||||||
if (will_return)
|
if (will_return)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Interpreter::ValueAndFrame Interpreter::run_and_return_frame(Executable& executable, BasicBlock const* entry_point, CallFrame* in_frame)
|
||||||
|
{
|
||||||
|
dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter will run unit {:p}", &executable);
|
||||||
|
|
||||||
|
TemporaryChange restore_executable { m_current_executable, &executable };
|
||||||
|
TemporaryChange restore_saved_jump { m_scheduled_jump, static_cast<BasicBlock const*>(nullptr) };
|
||||||
|
|
||||||
|
VERIFY(!vm().execution_context_stack().is_empty());
|
||||||
|
|
||||||
|
TemporaryChange restore_current_block { m_current_block, entry_point ?: executable.basic_blocks.first() };
|
||||||
|
|
||||||
|
if (in_frame)
|
||||||
|
push_call_frame(in_frame, executable.number_of_registers);
|
||||||
|
else
|
||||||
|
push_call_frame(make<CallFrame>(), executable.number_of_registers);
|
||||||
|
|
||||||
|
run_bytecode();
|
||||||
|
|
||||||
dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter did run unit {:p}", &executable);
|
dbgln_if(JS_BYTECODE_DEBUG, "Bytecode::Interpreter did run unit {:p}", &executable);
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,8 @@ public:
|
||||||
void visit_edges(Cell::Visitor&);
|
void visit_edges(Cell::Visitor&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void run_bytecode();
|
||||||
|
|
||||||
CallFrame& call_frame()
|
CallFrame& call_frame()
|
||||||
{
|
{
|
||||||
return m_call_frames.last().visit([](auto& x) -> CallFrame& { return *x; });
|
return m_call_frames.last().visit([](auto& x) -> CallFrame& { return *x; });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue