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

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

#include <Scope.hpp>

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

Public Member Functions

 Scope () noexcept
 Construct a new Scope object.
 
void mergeRefInto (Scope &other)
 Merge values from this scope as refs in the other scope.
 
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 has (uint16_t id) noexcept
 Check if the scope has 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.
 
std::size_t size () const noexcept
 Return the size of the scope.
 

Private Attributes

std::vector< std::pair< uint16_t, Value > > m_data
 
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
 
class Ark::internal::Closure
 
ARK_API bool operator== (const Scope &A, const Scope &B)
 

Detailed Description

A class to handle the VM scope more efficiently.

Definition at line 27 of file Scope.hpp.

Constructor & Destructor Documentation

◆ Scope()

Ark::internal::Scope::Scope ( )
noexcept

Construct a new Scope object.

Definition at line 7 of file Scope.cpp.

References m_data.

Member Function Documentation

◆ has()

bool Ark::internal::Scope::has ( uint16_t id)
noexcept

Check if the scope has a specific symbol in memory.

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

Definition at line 44 of file Scope.cpp.

◆ idFromValue()

uint16_t Ark::internal::Scope::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 69 of file Scope.cpp.

◆ mergeRefInto()

void Ark::internal::Scope::mergeRefInto ( Scope & other)

Merge values from this scope as refs in the other scope.

This scope must be kept alive for the ref to be used

Parameters
other

Definition at line 13 of file Scope.cpp.

References m_data, push_back(), and Ark::Reference.

◆ operator[]() [1/2]

const Value * Ark::internal::Scope::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 59 of file Scope.cpp.

◆ operator[]() [2/2]

Value * Ark::internal::Scope::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 49 of file Scope.cpp.

◆ push_back() [1/2]

void Ark::internal::Scope::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 34 of file Scope.cpp.

◆ push_back() [2/2]

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

Referenced by mergeRefInto().

◆ size()

std::size_t Ark::internal::Scope::size ( ) const
nodiscardnoexcept

Return the size of the scope.

Returns
const std::size_t

Definition at line 79 of file Scope.cpp.

References m_data.

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

Friends And Related Symbol Documentation

◆ Ark::internal::Closure

friend class Ark::internal::Closure
friend

Definition at line 102 of file Scope.hpp.

◆ Ark::VM

friend class Ark::VM
friend

Definition at line 101 of file Scope.hpp.

◆ operator==

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

Definition at line 84 of file Scope.cpp.

Member Data Documentation

◆ m_data

std::vector<std::pair<uint16_t, Value> > Ark::internal::Scope::m_data
private

Definition at line 105 of file Scope.hpp.

Referenced by Ark::VM::backtrace(), mergeRefInto(), Scope(), and size().

◆ m_max_id

uint16_t Ark::internal::Scope::m_max_id
private

Maximum stored ID, used for a basic bloom filter.

Definition at line 107 of file Scope.hpp.

◆ m_min_id

uint16_t Ark::internal::Scope::m_min_id
private

Minimum stored ID, used for a basic bloom filter.

Definition at line 106 of file Scope.hpp.


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