Skip to content

Commit

Permalink
LibJS: FDI bytecode WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kalenikaliaksandr committed May 9, 2024
1 parent 4c15ade commit b241b9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Userland/Libraries/LibJS/Bytecode/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ CodeGenerationErrorOr<void> Generator::emit_function_declaration_instantiation(E
for (auto const& variable_to_initialize : function.m_var_names_to_initialize_binding) {
auto const& id = variable_to_initialize.identifier;

auto initial_value = Operand { generator.allocate_register() };
auto initial_value = generator.allocate_register();
if (!variable_to_initialize.parameter_binding || variable_to_initialize.function_name) {
generator.emit<Op::Mov>(initial_value, generator.add_constant(js_undefined()));
} else {
Expand Down Expand Up @@ -178,7 +178,7 @@ CodeGenerationErrorOr<void> Generator::emit_function_declaration_instantiation(E
}

for (auto const& declaration : function.m_functions_to_initialize) {
auto dst = Operand(generator.allocate_register());
auto dst = generator.allocate_register();
generator.emit<Op::NewFunction>(dst, declaration, OptionalNone {});
if (declaration.name_identifier()->is_local()) {
generator.emit<Op::Mov>(generator.local(declaration.name_identifier()->local_variable_index()), dst);
Expand Down
10 changes: 5 additions & 5 deletions Userland/Libraries/LibJS/Bytecode/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,30 @@ Interpreter::~Interpreter()
ALWAYS_INLINE Value Interpreter::get(Operand op) const
{
switch (op.type()) {
case Operand::Type::Argument:
return m_arguments.data()[op.index()];
case Operand::Type::Register:
return reg(Register { op.index() });
case Operand::Type::Local:
return m_locals.data()[op.index()];
case Operand::Type::Constant:
return current_executable().constants[op.index()];
case Operand::Type::Argument:
return m_arguments.data()[op.index()];
}
__builtin_unreachable();
}

ALWAYS_INLINE void Interpreter::set(Operand op, Value value)
{
switch (op.type()) {
case Operand::Type::Argument:
m_arguments.data()[op.index()] = value;
return;
case Operand::Type::Register:
reg(Register { op.index() }) = value;
return;
case Operand::Type::Local:
m_locals.data()[op.index()] = value;
return;
case Operand::Type::Argument:
m_arguments.data()[op.index()] = value;
return;
case Operand::Type::Constant:
VERIFY_NOT_REACHED();
}
Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ ThrowCompletionOr<Value> ECMAScriptFunctionObject::internal_call(Value this_argu
callee_context->arguments.append(arguments_list.data(), arguments_list.size());
callee_context->program_counter = vm.bytecode_interpreter().program_counter();
callee_context->passed_argument_count = arguments_list.size();
callee_context->arguments.ensure_capacity(m_formal_parameters.size());
if (arguments_list.size() < m_formal_parameters.size()) {
for (size_t i = arguments_list.size(); i < m_formal_parameters.size(); ++i)
callee_context->arguments.append(js_undefined());
Expand Down Expand Up @@ -462,6 +463,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> ECMAScriptFunctionObject::internal_const
callee_context->arguments.append(arguments_list.data(), arguments_list.size());
callee_context->program_counter = vm.bytecode_interpreter().program_counter();
callee_context->passed_argument_count = arguments_list.size();
callee_context->arguments.ensure_capacity(m_formal_parameters.size());
if (arguments_list.size() < m_formal_parameters.size()) {
for (size_t i = arguments_list.size(); i < m_formal_parameters.size(); ++i)
callee_context->arguments.append(js_undefined());
Expand Down

0 comments on commit b241b9e

Please sign in to comment.