2024-02-02 06:19:17 -03:00
|
|
|
/*
|
2025-11-22 08:27:51 -03:00
|
|
|
* Copyright (c) 2024-2025, Andreas Kling <andreas@ladybird.org>
|
2024-02-02 06:19:17 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
|
2025-07-19 14:41:08 -03:00
|
|
|
class Operand {
|
2024-02-02 06:19:17 -03:00
|
|
|
public:
|
|
|
|
|
[[nodiscard]] bool operator==(Operand const&) const = default;
|
|
|
|
|
|
2025-11-22 08:27:51 -03:00
|
|
|
enum class ShouldMakeInvalid { Indeed };
|
|
|
|
|
explicit Operand(ShouldMakeInvalid)
|
|
|
|
|
: m_raw(0xffffffffu)
|
2024-02-02 06:19:17 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-22 08:27:51 -03:00
|
|
|
[[nodiscard]] bool is_invalid() const { return m_raw == 0xffffffffu; }
|
|
|
|
|
[[nodiscard]] u32 raw() const { return m_raw; }
|
2024-02-02 06:19:17 -03:00
|
|
|
|
|
|
|
|
private:
|
2026-06-14 13:12:06 -03:00
|
|
|
Operand() = default;
|
|
|
|
|
|
2025-11-22 08:27:51 -03:00
|
|
|
u32 m_raw { 0 };
|
2024-02-02 06:19:17 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
2025-03-27 12:11:15 -03:00
|
|
|
|
|
|
|
|
namespace AK {
|
2025-05-13 08:06:33 -03:00
|
|
|
|
2025-03-27 12:11:15 -03:00
|
|
|
template<>
|
2026-03-18 16:43:56 -03:00
|
|
|
struct SentinelOptionalTraits<JS::Bytecode::Operand> {
|
|
|
|
|
static JS::Bytecode::Operand sentinel_value() { return JS::Bytecode::Operand { JS::Bytecode::Operand::ShouldMakeInvalid::Indeed }; }
|
|
|
|
|
static bool is_sentinel(JS::Bytecode::Operand const& value) { return value.is_invalid(); }
|
|
|
|
|
};
|
2025-03-27 12:11:15 -03:00
|
|
|
|
2026-03-18 16:43:56 -03:00
|
|
|
template<>
|
|
|
|
|
class Optional<JS::Bytecode::Operand> : public SentinelOptional<JS::Bytecode::Operand> {
|
2025-03-27 12:11:15 -03:00
|
|
|
public:
|
2026-03-18 16:43:56 -03:00
|
|
|
using SentinelOptional::SentinelOptional;
|
2025-03-27 12:11:15 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|