Skip to content

Commit

Permalink
LibJS: Non-recursive normal calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kalenikaliaksandr committed May 19, 2024
1 parent a0898ac commit 8ab8dc8
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 103 deletions.
430 changes: 328 additions & 102 deletions Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion Userland/Libraries/LibJS/Bytecode/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Interpreter {
[[nodiscard]] Value get(Operand) const;
void set(Operand, Value);

Optional<Operand> leave_execution_context();

Value do_yield(Value value, Optional<Label> continuation);
void do_return(Value value)
{
Expand All @@ -80,6 +82,8 @@ class Interpreter {

ExecutionContext& running_execution_context() { return *m_running_execution_context; }

friend class Op::Call;

private:
void run_bytecode(size_t entry_point);

Expand All @@ -95,10 +99,30 @@ class Interpreter {
GCPtr<Realm> m_realm { nullptr };
GCPtr<Object> m_global_object { nullptr };
GCPtr<DeclarativeEnvironment> m_global_declarative_environment { nullptr };
Optional<size_t&> m_program_counter;
size_t m_program_counter { 0 };
Span<Value> m_arguments;
Span<Value> m_registers_and_constants_and_locals;
ExecutionContext* m_running_execution_context { nullptr };

size_t m_depth { 0 };
// Vector<ExecutionContext*> m_test_stack;
// Vector<NonnullGCPtr<Executable>> m_executable_stack;
struct Frame {
Optional<size_t> scheduled_jump;
GCPtr<Executable> current_executable;
GCPtr<Realm> realm;
GCPtr<Object> global_object;
GCPtr<DeclarativeEnvironment> global_declarative_environment;
size_t program_counter;
Span<Value> arguments;
Span<Value> registers_and_constants_and_locals;
ExecutionContext* running_execution_context { nullptr };
};

Vector<Frame> m_frame_stack;

void push_frame();
void pop_frame();
};

extern bool g_dump_bytecode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
m_bytecode_executable = m_ecmascript_code->bytecode_executable();
}

VERIFY(vm.running_execution_context().registers_and_constants_and_locals.size() == 0);
vm.running_execution_context().registers_and_constants_and_locals.resize(m_local_variables_names.size() + m_bytecode_executable->number_of_registers + m_bytecode_executable->constants.size());

auto result_and_frame = vm.bytecode_interpreter().run_executable(*m_bytecode_executable, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class ECMAScriptFunctionObject final : public FunctionObject {
Variant<PropertyKey, PrivateName, Empty> const& class_field_initializer_name() const { return m_class_field_initializer_name; }

friend class Bytecode::Generator;
friend class Bytecode::Op::Call;

protected:
virtual bool is_strict_mode() const final { return m_strict; }
Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibJS/Runtime/ExecutionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ struct ExecutionContext : RefCounted<ExecutionContext> {
Vector<Bytecode::UnwindInfo> unwind_contexts;
Vector<Optional<size_t>> previously_scheduled_jumps;
Vector<GCPtr<Environment>> saved_lexical_environments;

Optional<Bytecode::Operand> result_dst;
};

struct StackTraceElement {
Expand Down
4 changes: 4 additions & 0 deletions Userland/Libraries/LibJS/Runtime/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ void VM::load_imported_module(ImportedModuleReferrer referrer, ModuleRequest con

void VM::push_execution_context(NonnullRefPtr<ExecutionContext> context)
{
// if (!context->executable) {
// dbgln(">PUSH EC WITHOUT EXECUTABLE!");
// VERIFY_NOT_REACHED();
// }
if (!m_execution_context_stack.is_empty())
m_execution_context_stack.last()->program_counter = bytecode_interpreter().program_counter();
m_execution_context_stack.append(move(context));
Expand Down

0 comments on commit 8ab8dc8

Please sign in to comment.