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

#include <Value.hpp>

Public Types

using ProcType = Value(*)(std::vector< Value > &, VM *)
 
using Iterator = std::vector< Value >::iterator
 
using ConstIterator = std::vector< Value >::const_iterator
 
using Value_t = std::variant< double, String, internal::PageAddr_t, ProcType, internal::Closure, UserType, std::vector< Value >, Value * >
 

Public Member Functions

 Value () noexcept
 Construct a new Value object.
 
 Value (ValueType type) noexcept
 Construct a new Value object.
 
template<typename T >
 Value (ValueType type, T &&value) noexcept
 Construct a new Value object.
 
 Value (int value) noexcept
 Construct a new Value object as a Number.
 
 Value (float value) noexcept
 Construct a new Value object as a Number.
 
 Value (double value) noexcept
 Construct a new Value object as a Number.
 
 Value (const std::string &value) noexcept
 Construct a new Value object as a String.
 
 Value (const String &value) noexcept
 Construct a new Value object as a String.
 
 Value (const char *value) noexcept
 Construct a new Value object as a String.
 
 Value (internal::PageAddr_t value) noexcept
 Construct a new Value object as a Function.
 
 Value (Value::ProcType value) noexcept
 Construct a new Value object from a C++ function.
 
 Value (std::vector< Value > &&value) noexcept
 Construct a new Value object as a List.
 
 Value (internal::Closure &&value) noexcept
 Construct a new Value object as a Closure.
 
 Value (UserType &&value) noexcept
 Construct a new Value object as a UserType.
 
 Value (Value *ref) noexcept
 Construct a new Value object as a reference to an internal object.
 
ValueType valueType () const noexcept
 Return the value type.
 
bool isFunction () const noexcept
 Check if a function is held.
 
double number () const
 Return the stored number.
 
const Stringstring () const
 Return the stored string.
 
const std::vector< Value > & constList () const
 Return the stored list.
 
const UserTypeusertype () const
 Return the stored user type.
 
std::vector< Value > & list ()
 Return the stored list as a reference.
 
StringstringRef ()
 Return the stored string as a reference.
 
UserTypeusertypeRef ()
 Return the stored user type as a reference.
 
Valuereference () const
 Return the stored internal object reference.
 
void push_back (const Value &value)
 Add an element to the list held by the value (if the value type is set to list)
 
void push_back (Value &&value)
 Add an element to the list held by the value (if the value type is set to list)
 
void toString (std::ostream &os, VM &vm) const noexcept
 

Private Member Functions

internal::PageAddr_t pageAddr () const
 Return the page address held by the value.
 
const ProcTypeproc () const
 Return the C Function held by the value.
 
const internal::Closureclosure () const
 Return the closure held by the value.
 
internal::ClosurerefClosure ()
 Return a reference to the closure held by the value.
 
bool isConst () const noexcept
 Check if the value is const or not.
 
void setConst (bool value) noexcept
 Set the Const object.
 

Private Attributes

uint8_t m_const_type
 First bit if for constness, right most bits are for type.
 
Value_t m_value
 

Friends

class Ark::VM
 
ARK_API_INLINE bool operator== (const Value &A, const Value &B) noexcept
 
ARK_API_INLINE bool operator< (const Value &A, const Value &B) noexcept
 
ARK_API_INLINE bool operator! (const Value &A) noexcept
 

Detailed Description

Definition at line 70 of file Value.hpp.

Member Typedef Documentation

◆ ConstIterator

using Ark::Value::ConstIterator = std::vector<Value>::const_iterator

Definition at line 75 of file Value.hpp.

◆ Iterator

using Ark::Value::Iterator = std::vector<Value>::iterator

Definition at line 74 of file Value.hpp.

◆ ProcType

using Ark::Value::ProcType = Value (*)(std::vector<Value>&, VM*)

Definition at line 73 of file Value.hpp.

◆ Value_t

using Ark::Value::Value_t = std::variant< double, String, internal::PageAddr_t, ProcType, internal::Closure, UserType, std::vector<Value>, Value* >

Definition at line 77 of file Value.hpp.

Constructor & Destructor Documentation

◆ Value() [1/15]

Ark::Value::Value ( )
noexcept

Construct a new Value object.

Definition at line 9 of file Value.cpp.

◆ Value() [2/15]

Ark::Value::Value ( ValueType  type)
explicitnoexcept

Construct a new Value object.

Parameters
typethe value type which is going to be held

Definition at line 15 of file Value.cpp.

References Ark::List, and Ark::String.

◆ Value() [3/15]

template<typename T >
Ark::Value::Value ( ValueType  type,
T &&  value 
)
inlinenoexcept

Construct a new Value object.

Use at your own risks. Asking for a value type N and putting a non-matching value will result in errors at runtime.

Template Parameters
T
Parameters
typevalue type wanted
valuevalue needed

Definition at line 112 of file Value.hpp.

◆ Value() [4/15]

Ark::Value::Value ( int  value)
explicitnoexcept

Construct a new Value object as a Number.

Parameters
value

Definition at line 62 of file Value.cpp.

◆ Value() [5/15]

Ark::Value::Value ( float  value)
explicitnoexcept

Construct a new Value object as a Number.

Parameters
value

Definition at line 66 of file Value.cpp.

◆ Value() [6/15]

Ark::Value::Value ( double  value)
explicitnoexcept

Construct a new Value object as a Number.

Parameters
value

Definition at line 70 of file Value.cpp.

◆ Value() [7/15]

Ark::Value::Value ( const std::string &  value)
explicitnoexcept

Construct a new Value object as a String.

Parameters
value

Definition at line 74 of file Value.cpp.

◆ Value() [8/15]

Ark::Value::Value ( const String value)
explicitnoexcept

Construct a new Value object as a String.

Parameters
value

Definition at line 78 of file Value.cpp.

◆ Value() [9/15]

Ark::Value::Value ( const char *  value)
explicitnoexcept

Construct a new Value object as a String.

Parameters
value

Definition at line 82 of file Value.cpp.

◆ Value() [10/15]

Ark::Value::Value ( internal::PageAddr_t  value)
explicitnoexcept

Construct a new Value object as a Function.

Parameters
value

Definition at line 86 of file Value.cpp.

◆ Value() [11/15]

Ark::Value::Value ( Value::ProcType  value)
explicitnoexcept

Construct a new Value object from a C++ function.

Parameters
value

Definition at line 90 of file Value.cpp.

◆ Value() [12/15]

Ark::Value::Value ( std::vector< Value > &&  value)
explicitnoexcept

Construct a new Value object as a List.

Parameters
value

Definition at line 94 of file Value.cpp.

◆ Value() [13/15]

Ark::Value::Value ( internal::Closure &&  value)
explicitnoexcept

Construct a new Value object as a Closure.

Parameters
value

Definition at line 98 of file Value.cpp.

◆ Value() [14/15]

Ark::Value::Value ( UserType &&  value)
explicitnoexcept

Construct a new Value object as a UserType.

Parameters
value

Definition at line 102 of file Value.cpp.

◆ Value() [15/15]

Ark::Value::Value ( Value ref)
explicitnoexcept

Construct a new Value object as a reference to an internal object.

Parameters
ref

Definition at line 106 of file Value.cpp.

Member Function Documentation

◆ closure()

const internal::Closure & Ark::Value::closure ( ) const
inlineprivate

Return the closure held by the value.

Returns
const internal::Closure&

◆ constList()

const std::vector< Value > & Ark::Value::constList ( ) const
inline

Return the stored list.

Returns
const std::vector<Value>&

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

◆ isConst()

bool Ark::Value::isConst ( ) const
inlineprivatenoexcept

Check if the value is const or not.

Returns
true
false

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

◆ isFunction()

bool Ark::Value::isFunction ( ) const
inlinenoexcept

Check if a function is held.

Returns
true on success
false on failure

◆ list()

std::vector< Value > & Ark::Value::list ( )

Return the stored list as a reference.

Returns
std::vector<Value>&

Definition at line 112 of file Value.cpp.

References m_value.

Referenced by push_back(), and Ark::VM::safeRun().

◆ number()

double Ark::Value::number ( ) const
inline

Return the stored number.

Returns
double

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

◆ pageAddr()

internal::PageAddr_t Ark::Value::pageAddr ( ) const
inlineprivate

Return the page address held by the value.

Returns
internal::PageAddr_t

Referenced by Ark::VM::backtrace(), and Ark::VM::safeRun().

◆ proc()

const ProcType & Ark::Value::proc ( ) const
inlineprivate

Return the C Function held by the value.

Returns
const ProcType&

◆ push_back() [1/2]

void Ark::Value::push_back ( const Value value)

Add an element to the list held by the value (if the value type is set to list)

Parameters
value

Definition at line 139 of file Value.cpp.

References list().

Referenced by Ark::VM::safeRun(), and Ark::State::setArgs().

◆ push_back() [2/2]

void Ark::Value::push_back ( Value &&  value)

Add an element to the list held by the value (if the value type is set to list)

Parameters
value

Definition at line 144 of file Value.cpp.

References list().

◆ refClosure()

internal::Closure & Ark::Value::refClosure ( )
private

Return a reference to the closure held by the value.

Returns
internal::Closure&

Definition at line 117 of file Value.cpp.

References m_value.

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

◆ reference()

Value * Ark::Value::reference ( ) const

Return the stored internal object reference.

Returns
Value*

Definition at line 132 of file Value.cpp.

References m_value.

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

◆ setConst()

void Ark::Value::setConst ( bool  value)
inlineprivatenoexcept

Set the Const object.

Parameters
value

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

◆ string()

const String & Ark::Value::string ( ) const
inline

Return the stored string.

Returns
const String&

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

◆ stringRef()

String & Ark::Value::stringRef ( )

Return the stored string as a reference.

Returns
String&

Definition at line 122 of file Value.cpp.

References m_value.

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

◆ toString()

void Ark::Value::toString ( std::ostream &  os,
VM vm 
) const
noexcept

◆ usertype()

const UserType & Ark::Value::usertype ( ) const
inline

Return the stored user type.

Returns
const UserType&

◆ usertypeRef()

UserType & Ark::Value::usertypeRef ( )

Return the stored user type as a reference.

Returns
UserType&

Definition at line 127 of file Value.cpp.

References m_value.

◆ valueType()

ValueType Ark::Value::valueType ( ) const
inlinenoexcept

Return the value type.

Returns
ValueType

Referenced by Ark::VM::backtrace(), and Ark::VM::safeRun().

Friends And Related Function Documentation

◆ Ark::VM

friend class Ark::VM
friend

Definition at line 298 of file Value.hpp.

◆ operator!

ARK_API_INLINE bool operator! ( const Value A)
friend

◆ operator<

ARK_API_INLINE bool operator< ( const Value A,
const Value B 
)
friend

◆ operator==

ARK_API_INLINE bool operator== ( const Value A,
const Value B 
)
friend

Member Data Documentation

◆ m_const_type

uint8_t Ark::Value::m_const_type
private

First bit if for constness, right most bits are for type.

Definition at line 301 of file Value.hpp.

◆ m_value

Value_t Ark::Value::m_value
private

Definition at line 302 of file Value.hpp.

Referenced by list(), refClosure(), reference(), stringRef(), and usertypeRef().


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