1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:58:11 +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:
Andreas Kling 2021-06-04 12:20:44 +02:00
parent bd1a5e282a
commit f2863b5a89
4 changed files with 45 additions and 0 deletions

View file

@ -64,6 +64,14 @@ void JumpIfFalse::execute(Bytecode::Interpreter& interpreter) const
interpreter.jump(m_target.value());
}
void JumpIfTrue::execute(Bytecode::Interpreter& interpreter) const
{
VERIFY(m_target.has_value());
auto result = interpreter.reg(m_result);
if (result.as_bool())
interpreter.jump(m_target.value());
}
String Load::to_string() const
{
return String::formatted("Load dst:{}, value:{}", m_dst, m_value.to_string_without_side_effects());
@ -116,4 +124,11 @@ String JumpIfFalse::to_string() const
return String::formatted("JumpIfFalse result:{}, target:<empty>", m_result);
}
String JumpIfTrue::to_string() const
{
if (m_target.has_value())
return String::formatted("JumpIfTrue result:{}, target:{}", m_result, m_target.value());
return String::formatted("JumpIfTrue result:{}, target:<empty>", m_result);
}
}