@@ -54,7 +54,7 @@ static ByteString format_operand(StringView name, Operand operand, Bytecode::Exe
54
54
break ;
55
55
case Operand::Type::Constant: {
56
56
builder.append (" \033 [36m" sv);
57
- auto value = executable.constants [operand.index ()];
57
+ auto value = executable.constants [operand.index () - executable. number_of_registers ];
58
58
if (value.is_empty ())
59
59
builder.append (" <Empty>" sv);
60
60
else if (value.is_boolean ())
@@ -153,30 +153,12 @@ Interpreter::~Interpreter()
153
153
154
154
ALWAYS_INLINE Value Interpreter::get (Operand op) const
155
155
{
156
- switch (op.type ()) {
157
- case Operand::Type::Register:
158
- return m_registers.data ()[op.index ()];
159
- case Operand::Type::Local:
160
- return m_locals.data ()[op.index ()];
161
- case Operand::Type::Constant:
162
- return m_constants.data ()[op.index ()];
163
- }
164
- __builtin_unreachable ();
156
+ return m_registers_and_constants_and_locals.data ()[op.index ()];
165
157
}
166
158
167
159
ALWAYS_INLINE void Interpreter::set (Operand op, Value value)
168
160
{
169
- switch (op.type ()) {
170
- case Operand::Type::Register:
171
- m_registers.data ()[op.index ()] = value;
172
- return ;
173
- case Operand::Type::Local:
174
- m_locals.data ()[op.index ()] = value;
175
- return ;
176
- case Operand::Type::Constant:
177
- break ;
178
- }
179
- __builtin_unreachable ();
161
+ m_registers_and_constants_and_locals.data ()[op.index ()] = value;
180
162
}
181
163
182
164
// 16.1.6 ScriptEvaluation ( scriptRecord ), https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation
@@ -346,7 +328,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
346
328
347
329
auto & running_execution_context = this ->running_execution_context ();
348
330
auto * arguments = running_execution_context.arguments .data ();
349
- auto * locals = running_execution_context.locals .data ();
331
+ auto * registers_and_constants_and_locals = running_execution_context.registers_and_constants_and_locals .data ();
350
332
auto & accumulator = this ->accumulator ();
351
333
auto & executable = current_executable ();
352
334
auto const * bytecode = executable.bytecode .data ();
@@ -384,7 +366,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
384
366
385
367
handle_SetLocal: {
386
368
auto & instruction = *reinterpret_cast <Op::SetLocal const *>(&bytecode[program_counter]);
387
- locals [instruction.index ()] = get (instruction.src ());
369
+ registers_and_constants_and_locals [instruction.index ()] = get (instruction.src ());
388
370
DISPATCH_NEXT (SetLocal);
389
371
}
390
372
@@ -715,31 +697,35 @@ Interpreter::ResultAndReturnRegister Interpreter::run_executable(Executable& exe
715
697
VERIFY (!vm ().execution_context_stack ().is_empty ());
716
698
717
699
auto & running_execution_context = vm ().running_execution_context ();
718
- if (running_execution_context.registers .size () < executable.number_of_registers )
719
- running_execution_context.registers .resize (executable.number_of_registers );
700
+ u32 registers_and_contants_count = executable.number_of_registers + executable.constants .size ();
701
+ if (running_execution_context.registers_and_constants_and_locals .size () < registers_and_contants_count)
702
+ running_execution_context.registers_and_constants_and_locals .resize (registers_and_contants_count);
720
703
721
704
TemporaryChange restore_running_execution_context { m_running_execution_context, &running_execution_context };
722
705
TemporaryChange restore_arguments { m_arguments, running_execution_context.arguments .span () };
723
- TemporaryChange restore_registers { m_registers, running_execution_context.registers .span () };
724
- TemporaryChange restore_locals { m_locals, running_execution_context.locals .span () };
725
- TemporaryChange restore_constants { m_constants, executable.constants .span () };
706
+ TemporaryChange restore_registers_and_constants_and_locals { m_registers_and_constants_and_locals, running_execution_context.registers_and_constants_and_locals .span () };
726
707
727
708
reg (Register::accumulator ()) = initial_accumulator_value;
728
709
reg (Register::return_value ()) = {};
729
710
730
711
running_execution_context.executable = &executable;
731
712
713
+ for (size_t i = 0 ; i < executable.constants .size (); ++i) {
714
+ running_execution_context.registers_and_constants_and_locals [executable.number_of_registers + i] = executable.constants [i];
715
+ }
716
+
732
717
run_bytecode (entry_point.value_or (0 ));
733
718
734
719
dbgln_if (JS_BYTECODE_DEBUG, " Bytecode::Interpreter did run unit {:p}" , &executable);
735
720
736
721
if constexpr (JS_BYTECODE_DEBUG) {
737
- for (size_t i = 0 ; i < registers ().size (); ++i) {
722
+ auto const & registers_and_constants_and_locals = running_execution_context.registers_and_constants_and_locals ;
723
+ for (size_t i = 0 ; i < executable.number_of_registers ; ++i) {
738
724
String value_string;
739
- if (registers () [i].is_empty ())
725
+ if (registers_and_constants_and_locals [i].is_empty ())
740
726
value_string = " (empty)" _string;
741
727
else
742
- value_string = registers () [i].to_string_without_side_effects ();
728
+ value_string = registers_and_constants_and_locals [i].to_string_without_side_effects ();
743
729
dbgln (" [{:3}] {}" , i, value_string);
744
730
}
745
731
}
@@ -758,8 +744,8 @@ Interpreter::ResultAndReturnRegister Interpreter::run_executable(Executable& exe
758
744
vm ().finish_execution_generation ();
759
745
760
746
if (!exception.is_empty ())
761
- return { throw_completion (exception), running_execution_context.registers [0 ] };
762
- return { return_value, running_execution_context.registers [0 ] };
747
+ return { throw_completion (exception), running_execution_context.registers_and_constants_and_locals [0 ] };
748
+ return { return_value, running_execution_context.registers_and_constants_and_locals [0 ] };
763
749
}
764
750
765
751
void Interpreter::enter_unwind_context ()
0 commit comments