mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibJS: Add support for various assignment operators
This commit is contained in:
parent
18ac7fde12
commit
6681415f58
Notes:
sideshowbarker
2024-07-18 12:40:47 +09:00
Author: https://github.com/ryangjchandler Commit: https://github.com/SerenityOS/serenity/commit/6681415f589 Pull-request: https://github.com/SerenityOS/serenity/pull/7893
1 changed files with 44 additions and 2 deletions
|
@ -177,8 +177,50 @@ Optional<Bytecode::Register> AssignmentExpression::generate_bytecode(Bytecode::G
|
|||
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;
|
||||
|
||||
if (m_op == AssignmentOp::Assignment) {
|
||||
generator.emit<Bytecode::Op::SetVariable>(identifier.string(), *rhs_reg);
|
||||
return rhs_reg;
|
||||
}
|
||||
|
||||
auto lhs_reg = m_lhs->generate_bytecode(generator);
|
||||
auto dst_reg = generator.allocate_register();
|
||||
|
||||
switch (m_op) {
|
||||
case AssignmentOp::AdditionAssignment:
|
||||
generator.emit<Bytecode::Op::Add>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::SubtractionAssignment:
|
||||
generator.emit<Bytecode::Op::Sub>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::MultiplicationAssignment:
|
||||
generator.emit<Bytecode::Op::Mul>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::DivisionAssignment:
|
||||
generator.emit<Bytecode::Op::Div>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::ModuloAssignment:
|
||||
generator.emit<Bytecode::Op::Mod>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::ExponentiationAssignment:
|
||||
generator.emit<Bytecode::Op::Exp>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::BitwiseAndAssignment:
|
||||
generator.emit<Bytecode::Op::BitwiseAnd>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::BitwiseOrAssignment:
|
||||
generator.emit<Bytecode::Op::BitwiseOr>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
case AssignmentOp::BitwiseXorAssignment:
|
||||
generator.emit<Bytecode::Op::BitwiseXor>(dst_reg, *lhs_reg, *rhs_reg);
|
||||
break;
|
||||
default:
|
||||
TODO();
|
||||
}
|
||||
|
||||
generator.emit<Bytecode::Op::SetVariable>(identifier.string(), dst_reg);
|
||||
|
||||
return dst_reg;
|
||||
}
|
||||
|
||||
if (is<MemberExpression>(*m_lhs)) {
|
||||
|
|
Loading…
Reference in a new issue