LibJS: Merge CallFrame into ExecutionContext

Before this change both ExecutionContext and CallFrame were created
before executing function/module/script with a couple exceptions:
- executable created for default function argument evaluation has to
  run in function's execution context.
- `execute_ast_node()` where executable compiled for ASTNode has to be
  executed in running execution context.

This change moves all members previously owned by CallFrame into
ExecutionContext, and makes two exceptions where an executable that does
not have a corresponding execution context saves and restores registers
before running.

Now, all execution state lives in a single entity, which makes it a bit
easier to reason about and opens opportunities for optimizations, such
as moving registers and local variables into a single array.
This commit is contained in:
Aliaksandr Kalenik
2024-05-01 19:33:49 +02:00
committed by Andreas Kling
parent 46b8a3afb7
commit 865e651a7d
Notes: sideshowbarker 2024-07-17 10:39:39 +09:00
15 changed files with 121 additions and 187 deletions

View File

@@ -289,11 +289,24 @@ ThrowCompletionOr<void> VM::binding_initialization(NonnullRefPtr<BindingPattern
ThrowCompletionOr<Value> VM::execute_ast_node(ASTNode const& node)
{
// FIXME: This function should be gone once we will emit bytecode for everything before executing instructions.
auto executable = TRY(Bytecode::compile(*this, node, {}, FunctionKind::Normal, ""sv));
auto result_or_error = bytecode_interpreter().run_and_return_frame(*executable, nullptr);
auto& running_execution_context = this->running_execution_context();
// Registers have to be saved and restored because executable for compiled ASTNode does not have its own execution context
auto saved_registers = running_execution_context.registers;
for (size_t i = 0; i < saved_registers.size(); ++i)
running_execution_context.registers[i] = {};
auto result_or_error = bytecode_interpreter().run_executable(*executable, nullptr);
for (size_t i = 0; i < saved_registers.size(); ++i)
running_execution_context.registers[i] = saved_registers[i];
if (result_or_error.value.is_error())
return result_or_error.value.release_error();
return result_or_error.frame->registers()[0];
return result_or_error.return_register_value;
}
// 13.15.5.3 Runtime Semantics: PropertyDestructuringAssignmentEvaluation, https://tc39.es/ecma262/#sec-runtime-semantics-propertydestructuringassignmentevaluation