From c6ab2a7d3ed8235f3731501c0affc69a59290069 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 18 May 2024 22:37:54 +0000 Subject: [PATCH] LibJS: Non-recursive normal calls --- .../Libraries/LibJS/Bytecode/Interpreter.cpp | 438 ++++++++++++++---- .../Libraries/LibJS/Bytecode/Interpreter.h | 26 +- .../Runtime/ECMAScriptFunctionObject.cpp | 1 + .../LibJS/Runtime/ECMAScriptFunctionObject.h | 1 + .../LibJS/Runtime/ExecutionContext.h | 2 + 5 files changed, 364 insertions(+), 104 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 952194df9775170..3738ba353b41653 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -161,6 +161,54 @@ ALWAYS_INLINE void Interpreter::set(Operand op, Value value) m_registers_and_constants_and_locals.data()[op.index()] = value; } +Optional Interpreter::leave_execution_context() +{ + VERIFY(m_depth > 0); + + m_depth--; + + vm().run_queued_promise_jobs(); + + vm().finish_execution_generation(); + + vm().pop_execution_context(); + + pop_frame(); + + auto dst = vm().running_execution_context().result_dst; + vm().running_execution_context().result_dst.clear(); + return dst; +} + +void Interpreter::push_frame() +{ + m_frame_stack.append({ + .scheduled_jump = m_scheduled_jump, + .current_executable = m_current_executable, + .realm = m_realm, + .global_object = m_global_object, + .global_declarative_environment = m_global_declarative_environment, + .program_counter = m_program_counter, + .arguments = m_arguments, + .registers_and_constants_and_locals = m_registers_and_constants_and_locals, + .running_execution_context = m_running_execution_context, + }); +} + +void Interpreter::pop_frame() +{ + auto frame = m_frame_stack.take_last(); + m_scheduled_jump = frame.scheduled_jump; + m_current_executable = frame.current_executable; + m_realm = frame.realm; + m_global_object = frame.global_object; + m_global_declarative_environment = frame.global_declarative_environment; + m_program_counter = frame.program_counter; + m_arguments = frame.arguments; + m_running_execution_context = frame.running_execution_context; + m_registers_and_constants_and_locals = frame.registers_and_constants_and_locals; +} + ALWAYS_INLINE Value Interpreter::do_yield(Value value, Optional