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

LibJS: Some more opcodes for the bytecode VM

- NewString (allocates a new PrimitiveString from the GC heap)
- GetVariable (retrieves a variable in the current scope)
- SetVariable (assigns a variable in the current scope)
This commit is contained in:
Andreas Kling 2021-06-03 18:26:32 +02:00
parent 6da5d17416
commit 37cb70836b
4 changed files with 113 additions and 0 deletions

View file

@ -2282,4 +2282,31 @@ Optional<Bytecode::Register> NumericLiteral::generate_bytecode(Bytecode::Generat
return dst;
}
Optional<Bytecode::Register> StringLiteral::generate_bytecode(Bytecode::Generator& generator) const
{
auto dst = generator.allocate_register();
generator.emit<Bytecode::Op::NewString>(dst, m_value);
return dst;
}
Optional<Bytecode::Register> Identifier::generate_bytecode(Bytecode::Generator& generator) const
{
auto reg = generator.allocate_register();
generator.emit<Bytecode::Op::GetVariable>(reg, m_string);
return reg;
}
Optional<Bytecode::Register> AssignmentExpression::generate_bytecode(Bytecode::Generator& generator) const
{
if (is<Identifier>(*m_lhs)) {
auto& identifier = static_cast<Identifier const&>(*m_lhs);
auto rhs_reg = m_rhs->generate_bytecode(generator);
VERIFY(rhs_reg.has_value());
generator.emit<Bytecode::Op::SetVariable>(identifier.string(), *rhs_reg);
return rhs_reg;
}
TODO();
}
}