ArkScript
A small, fast, functional and scripting language for video games
Ark::internal::ScopeView Class Reference

A class to handle the VM scope more efficiently. More...

#include <ScopeView.hpp>

Collaboration diagram for Ark::internal::ScopeView:
[legend]

Public Types

using pair_t = std::pair<uint16_t, Value>
 

Public Member Functions

 ScopeView ()=delete
 Deleted constructor to avoid creating ScopeViews pointing to nothing. Helps catch bugs at compile time.
 
 ScopeView (pair_t *storage, std::size_t start) noexcept
 Create a new ScopeView.
 
void push_back (uint16_t id, Value &&val) noexcept
 Put a value in the scope.
 
void push_back (uint16_t id, const Value &val) noexcept
 Put a value in the scope.
 
bool maybeHas (uint16_t id) const noexcept
 Check if the scope maybe holds a specific symbol in memory.
 
Valueoperator[] (uint16_t id_to_look_for) noexcept
 Get a value from its symbol id.
 
const Valueoperator[] (uint16_t id_to_look_for) const noexcept
 Get a value from its symbol id.
 
uint16_t idFromValue (const Value &val) const noexcept
 Get the id of a variable based on its value ; used for debug only.
 
const pair_tatPos (const std::size_t i) const noexcept
 Return the element at index in scope.
 
pair_tatPosReverse (const std::size_t i) noexcept
 Return the element at index, starting from the end.
 
void reset () noexcept
 Reset size, min and max id for the scope, to signify it's empty.
 
std::size_t size () const noexcept
 Return the size of the scope.
 
std::size_t storageEnd () const noexcept
 Compute the position of the first free slot in the shared storage, after this scope.
 

Private Attributes

pair_tm_storage
 
std::size_t m_start
 
std::size_t m_size
 
uint16_t m_min_id
 Minimum stored ID, used for a basic bloom filter.
 
uint16_t m_max_id
 Maximum stored ID, used for a basic bloom filter.
 

Friends

class Ark::VM
 
ARK_API bool operator== (const ScopeView &A, const ScopeView &B)
 

Detailed Description

A class to handle the VM scope more efficiently.

Definition at line 26 of file ScopeView.hpp.

Member Typedef Documentation

◆ pair_t

using Ark::internal::ScopeView::pair_t = std::pair<uint16_t, Value>

Definition at line 29 of file ScopeView.hpp.

Constructor & Destructor Documentation

◆ ScopeView() [1/2]

Ark::internal::ScopeView::ScopeView ( )
delete

Deleted constructor to avoid creating ScopeViews pointing to nothing. Helps catch bugs at compile time.

◆ ScopeView() [2/2]

Ark::internal::ScopeView::ScopeView ( pair_t * storage,
std::size_t start )
noexcept

Create a new ScopeView.

Parameters
storagepointer to the shared scope storage
startfirst free starting position

Definition at line 7 of file ScopeView.cpp.

Member Function Documentation

◆ atPos()

const pair_t & Ark::internal::ScopeView::atPos ( const std::size_t i) const
inlinenodiscardnoexcept

Return the element at index in scope.

Returns
const pair_t&

Definition at line 98 of file ScopeView.hpp.

Referenced by Ark::VM::backtrace().

◆ atPosReverse()

pair_t & Ark::internal::ScopeView::atPosReverse ( const std::size_t i)
inlinenodiscardnoexcept

Return the element at index, starting from the end.

Returns
const pair_t&

Definition at line 108 of file ScopeView.hpp.

◆ idFromValue()

uint16_t Ark::internal::ScopeView::idFromValue ( const Value & val) const
nodiscardnoexcept

Get the id of a variable based on its value ; used for debug only.

Parameters
val
Returns
uint16_t

Definition at line 66 of file ScopeView.cpp.

◆ maybeHas()

bool Ark::internal::ScopeView::maybeHas ( uint16_t id) const
noexcept

Check if the scope maybe holds a specific symbol in memory.

Parameters
idThe id of the symbol
Returns
true On success
false Otherwise

Definition at line 33 of file ScopeView.cpp.

◆ operator[]() [1/2]

const Value * Ark::internal::ScopeView::operator[] ( uint16_t id_to_look_for) const
noexcept

Get a value from its symbol id.

Parameters
id_to_look_for
Returns
const Value* Returns nullptr if the value can not be found

Definition at line 52 of file ScopeView.cpp.

◆ operator[]() [2/2]

Value * Ark::internal::ScopeView::operator[] ( uint16_t id_to_look_for)
noexcept

Get a value from its symbol id.

Parameters
id_to_look_for
Returns
Value* Returns nullptr if the value can not be found

Definition at line 38 of file ScopeView.cpp.

◆ push_back() [1/2]

void Ark::internal::ScopeView::push_back ( uint16_t id,
const Value & val )
noexcept

Put a value in the scope.

Parameters
idThe symbol id of the variable
valThe value linked to the symbol

Definition at line 22 of file ScopeView.cpp.

◆ push_back() [2/2]

void Ark::internal::ScopeView::push_back ( uint16_t id,
Value && val )
noexcept

Put a value in the scope.

Parameters
idThe symbol id of the variable
valThe value linked to the symbol

Definition at line 11 of file ScopeView.cpp.

Referenced by Ark::internal::ClosureScope::mergeRefInto().

◆ reset()

void Ark::internal::ScopeView::reset ( )
noexcept

Reset size, min and max id for the scope, to signify it's empty.

Definition at line 77 of file ScopeView.cpp.

References m_max_id, m_min_id, and m_size.

◆ size()

std::size_t Ark::internal::ScopeView::size ( ) const
inlinenodiscardnoexcept

Return the size of the scope.

Returns
const std::size_t

Definition at line 123 of file ScopeView.hpp.

Referenced by Ark::VM::backtrace().

◆ storageEnd()

std::size_t Ark::internal::ScopeView::storageEnd ( ) const
inlinenodiscardnoexcept

Compute the position of the first free slot in the shared storage, after this scope.

Returns
std::size_t

Definition at line 133 of file ScopeView.hpp.

Friends And Related Symbol Documentation

◆ Ark::VM

friend class Ark::VM
friend

Definition at line 140 of file ScopeView.hpp.

◆ operator==

ARK_API bool operator== ( const ScopeView & A,
const ScopeView & B )
friend

Definition at line 84 of file ScopeView.cpp.

Member Data Documentation

◆ m_max_id

uint16_t Ark::internal::ScopeView::m_max_id
private

Maximum stored ID, used for a basic bloom filter.

Definition at line 147 of file ScopeView.hpp.

Referenced by reset().

◆ m_min_id

uint16_t Ark::internal::ScopeView::m_min_id
private

Minimum stored ID, used for a basic bloom filter.

Definition at line 146 of file ScopeView.hpp.

Referenced by reset().

◆ m_size

std::size_t Ark::internal::ScopeView::m_size
private

Definition at line 145 of file ScopeView.hpp.

Referenced by reset().

◆ m_start

std::size_t Ark::internal::ScopeView::m_start
private

Definition at line 144 of file ScopeView.hpp.

◆ m_storage

pair_t* Ark::internal::ScopeView::m_storage
private

Definition at line 143 of file ScopeView.hpp.


The documentation for this class was generated from the following files: