11#ifndef ARK_VM_SCOPE_HPP
12#define ARK_VM_SCOPE_HPP
29 using pair_t = std::pair<uint16_t, Value>;
43 m_storage(storage), m_start(start), m_size(0), m_min_id(MaxValue16Bits), m_max_id(0)
59 m_storage[m_start + m_size] = std::make_pair(
id, std::move(val));
76 m_storage[m_start + m_size] = std::make_pair(
id, val);
86 void insertFront(
const std::vector<pair_t>& values)
noexcept;
95 [[nodiscard]] ARK_ALWAYS_INLINE
bool maybeHas(
const uint16_t
id)
const noexcept
97 return m_min_id <=
id &&
id <= m_max_id;
106 [[nodiscard]] ARK_ALWAYS_INLINE
Value*
operator[](
const uint16_t id_to_look_for)
noexcept
108 if (!maybeHas(id_to_look_for))
111 for (std::size_t i = m_start; i < m_start + m_size; ++i)
113 auto& [id, value] = m_storage[i];
114 if (
id == id_to_look_for)
126 [[nodiscard]] ARK_ALWAYS_INLINE
const Value*
operator[](
const uint16_t id_to_look_for)
const noexcept
128 if (!maybeHas(id_to_look_for))
131 for (std::size_t i = m_start; i < m_start + m_size; ++i)
133 auto& [id, value] = m_storage[i];
134 if (
id == id_to_look_for)
146 [[nodiscard]] uint16_t idFromValue(
const Value& val)
const noexcept;
153 [[nodiscard]] ARK_ALWAYS_INLINE
const pair_t&
atPos(
const std::size_t i)
const noexcept
155 return m_storage[m_start + i];
165 return m_storage[m_start + m_size - 1 - i];
171 ARK_ALWAYS_INLINE
void reset() noexcept
183 [[nodiscard]] ARK_ALWAYS_INLINE std::size_t
size() const noexcept
193 [[nodiscard]] ARK_ALWAYS_INLINE std::size_t
storageEnd() const noexcept
195 return m_start + m_size;
Constants used by ArkScript.
Default value type handled by the virtual machine.
The ArkScript virtual machine, executing ArkScript bytecode.
A class to handle the VM scope more efficiently.
ARK_ALWAYS_INLINE bool maybeHas(const uint16_t id) const noexcept
Check if the scope maybe holds a specific symbol in memory.
ARK_ALWAYS_INLINE void reset() noexcept
Reset size, min and max id for the scope, to signify it's empty.
ScopeView()=delete
Deleted constructor to avoid creating ScopeViews pointing to nothing. Helps catch bugs at compile tim...
ARK_ALWAYS_INLINE const pair_t & atPos(const std::size_t i) const noexcept
Return the element at index in scope.
uint16_t m_max_id
Maximum stored ID, used for a basic bloom filter.
ARK_ALWAYS_INLINE void pushBack(uint16_t id, const Value &val) noexcept
Put a value in the scope.
ARK_ALWAYS_INLINE pair_t & atPosReverse(const std::size_t i) const noexcept
Return the element at index, starting from the end.
std::pair< uint16_t, Value > pair_t
ARK_ALWAYS_INLINE void pushBack(uint16_t id, Value &&val) noexcept
Put a value in the scope.
ARK_ALWAYS_INLINE Value * operator[](const uint16_t id_to_look_for) noexcept
Get a value from its symbol id.
ARK_ALWAYS_INLINE std::size_t storageEnd() const noexcept
Compute the position of the first free slot in the shared storage, after this scope.
ARK_ALWAYS_INLINE ScopeView(pair_t *storage, const std::size_t start) noexcept
Create a new ScopeView.
ARK_ALWAYS_INLINE std::size_t size() const noexcept
Return the size of the scope.
ARK_ALWAYS_INLINE const Value * operator[](const uint16_t id_to_look_for) const noexcept
Get a value from its symbol id.
uint16_t m_min_id
Minimum stored ID, used for a basic bloom filter.
bool operator==(const Namespace &A, const Namespace &B)
constexpr uint16_t MaxValue16Bits