mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:18:12 +00:00
LibJS: Generate bytecode for do...while statements :^)
This was quite straightforward using the same label/jump machinery that we added for while statements. The main addition here is a new JumpIfTrue bytecode instruction.
This commit is contained in:
parent
bd1a5e282a
commit
f2863b5a89
4 changed files with 45 additions and 0 deletions
|
@ -105,4 +105,14 @@ Optional<Bytecode::Register> WhileStatement::generate_bytecode(Bytecode::Generat
|
|||
return body_result_reg;
|
||||
}
|
||||
|
||||
Optional<Bytecode::Register> DoWhileStatement::generate_bytecode(Bytecode::Generator& generator) const
|
||||
{
|
||||
auto head_label = generator.make_label();
|
||||
auto body_result_reg = m_body->generate_bytecode(generator);
|
||||
auto test_result_reg = m_test->generate_bytecode(generator);
|
||||
VERIFY(test_result_reg.has_value());
|
||||
generator.emit<Bytecode::Op::JumpIfTrue>(*test_result_reg, head_label);
|
||||
return body_result_reg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue