1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

LibJS: Add basic "if" statement support to the bytecode VM :^)

This also required making Bytecode::Op::Jump support lazy linking
to a target label.

I left a FIXME here about having the "if" statement return the result
value from the taken branch statement. That's what the AST interpreter
does but I'm not sure if it's actually required.
This commit is contained in:
Andreas Kling 2021-06-06 13:26:50 +02:00
parent 80b1604b0a
commit 79eac08f5b
4 changed files with 30 additions and 5 deletions

View file

@ -214,17 +214,19 @@ private:
class Jump final : public Instruction {
public:
explicit Jump(Label target)
: m_target(target)
explicit Jump(Optional<Label> target = {})
: m_target(move(target))
{
}
void set_target(Optional<Label> target) { m_target = move(target); }
virtual ~Jump() override { }
virtual void execute(Bytecode::Interpreter&) const override;
virtual String to_string() const override;
private:
Label m_target;
Optional<Label> m_target;
};
class JumpIfFalse final : public Instruction {