ArkScript
A small, lisp-inspired, functional scripting language
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 pushBack (uint16_t id, Value &&val) noexcept
 Put a value in the scope.
 
void pushBack (uint16_t id, const Value &val) noexcept
 Put a value in the scope.
 
void insertFront (const std::vector< pair_t > &values) noexcept
 Insert one or more pairs at the beginning of 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 9 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 106 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 116 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 98 of file ScopeView.cpp.

References Ark::MaxValue16Bits.

◆ insertFront()

void Ark::internal::ScopeView::insertFront ( const std::vector< pair_t > & values)
noexcept

Insert one or more pairs at the beginning of the scope.

This can ONLY be called on the last known scope, otherwise it will override the data of the next scope!

Parameters
values

Definition at line 35 of file ScopeView.cpp.

References Ark::Reference.

◆ maybeHas()

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

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 65 of file ScopeView.cpp.

◆ operator[]() [1/2]

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

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 84 of file ScopeView.cpp.

◆ operator[]() [2/2]

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

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 70 of file ScopeView.cpp.

◆ pushBack() [1/2]

void Ark::internal::ScopeView::pushBack ( 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 24 of file ScopeView.cpp.

◆ pushBack() [2/2]

void Ark::internal::ScopeView::pushBack ( 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 13 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 109 of file ScopeView.cpp.

References m_max_id, m_min_id, m_size, and Ark::MaxValue16Bits.

◆ size()

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

Return the size of the scope.

Returns
const std::size_t

Definition at line 131 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 141 of file ScopeView.hpp.

Friends And Related Symbol Documentation

◆ Ark::VM

friend class Ark::VM
friend

Definition at line 148 of file ScopeView.hpp.

◆ operator==

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

Definition at line 116 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 155 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 154 of file ScopeView.hpp.

Referenced by reset().

◆ m_size

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

Definition at line 153 of file ScopeView.hpp.

Referenced by reset().

◆ m_start

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

Definition at line 152 of file ScopeView.hpp.

◆ m_storage

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

Definition at line 151 of file ScopeView.hpp.


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