mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-03 17:58:49 +00:00
This introduces two new instructions: Jump and JumpIfFalse. Jumps are made to a Bytecode::Label, which is a simple object that represents a location in the bytecode stream. Note that you may not always know the target of a jump when adding the jump instruction itself, but we can just update the instruction later on during codegen once we know where the jump target is. The Bytecode::Interpreter now implements jumping via a jump slot that gets checked after each instruction to see if a jump is pending. If not, we just increment the PC as usual.
34 lines
628 B
C++
34 lines
628 B
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Format.h>
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
class Label {
|
|
public:
|
|
explicit Label(size_t address)
|
|
: m_address(address)
|
|
{
|
|
}
|
|
|
|
size_t address() const { return m_address; }
|
|
|
|
private:
|
|
size_t m_address { 0 };
|
|
};
|
|
|
|
}
|
|
|
|
template<>
|
|
struct AK::Formatter<JS::Bytecode::Label> : AK::Formatter<FormatString> {
|
|
void format(FormatBuilder& builder, JS::Bytecode::Label const& value)
|
|
{
|
|
return AK::Formatter<FormatString>::format(builder, "@{}", value.address());
|
|
}
|
|
};
|