1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:38:11 +00:00

LibJS/Bytecode: Add Bytecode::Operand

An Operand is either a register, a local, or a constant (index into the
executable's constant table)
This commit is contained in:
Andreas Kling 2024-02-02 10:19:17 +01:00
parent c0ec924dc9
commit 3466771492
6 changed files with 85 additions and 1 deletions

View file

@ -67,6 +67,34 @@ void Interpreter::visit_edges(Cell::Visitor& visitor)
}
}
Value Interpreter::get(Operand op) const
{
switch (op.type()) {
case Operand::Type::Register:
return reg(Register { op.index() });
case Operand::Type::Local:
return vm().running_execution_context().locals[op.index()];
case Operand::Type::Constant:
return current_executable().constants[op.index()];
}
VERIFY_NOT_REACHED();
}
void Interpreter::set(Operand op, Value value)
{
switch (op.type()) {
case Operand::Type::Register:
reg(Register { op.index() }) = value;
return;
case Operand::Type::Local:
vm().running_execution_context().locals[op.index()] = value;
return;
case Operand::Type::Constant:
VERIFY_NOT_REACHED();
}
VERIFY_NOT_REACHED();
}
// 16.1.6 ScriptEvaluation ( scriptRecord ), https://tc39.es/ecma262/#sec-runtime-semantics-scriptevaluation
ThrowCompletionOr<Value> Interpreter::run(Script& script_record, JS::GCPtr<Environment> lexical_environment_override)
{