12#ifndef ARK_VM_VALUE_HPP
13#define ARK_VM_VALUE_HPP
53 "List",
"Number",
"String",
"Function",
54 "CProc",
"Closure",
"UserType",
"Nil",
55 "Bool",
"Bool",
"Undefined",
"Reference",
101 m_type(type), m_value(value)
104 explicit Value(
int value)
noexcept;
105 explicit Value(
double value)
noexcept;
106 explicit Value(
const std::string& value)
noexcept;
108 explicit Value(ProcType value)
noexcept;
109 explicit Value(std::vector<Value>&& value)
noexcept;
117 return m_type == ValueType::PageAddr || m_type == ValueType::Closure || m_type == ValueType::CProc ||
118 (m_type == ValueType::Reference && reference()->isFunction());
122 return m_type == ValueType::List || m_type == ValueType::String;
125 [[nodiscard]]
double number()
const {
return std::get<double>(m_value); }
126 [[nodiscard]]
const std::string&
string()
const {
return std::get<std::string>(m_value); }
127 [[nodiscard]]
const std::vector<Value>&
constList()
const {
return std::get<std::vector<Value>>(m_value); }
129 [[nodiscard]] std::vector<Value>&
list() {
return std::get<std::vector<Value>>(m_value); }
130 [[nodiscard]] std::string&
stringRef() {
return std::get<std::string>(m_value); }
139 void push_back(
const Value& value);
146 void push_back(
Value&& value);
148 std::string toString(
VM& vm)
const noexcept;
161 [[nodiscard]]
constexpr uint8_t
typeNum() const noexcept {
return static_cast<uint8_t
>(m_type); }
164 [[nodiscard]]
const ProcType&
proc()
const {
return std::get<ProcType>(m_value); }
172 if (A.m_type != B.m_type)
178 return A.m_value == B.m_value;
183 if (A.m_type != B.m_type)
184 return (A.typeNum() - B.typeNum()) < 0;
185 return A.m_value < B.m_value;
195 switch (A.valueType())
198 return A.constList().empty();
201 return A.number() == 0.0;
204 return A.string().empty();
Subtype of the value type, handling closures.
Subtype of the value, capable of handling any C++ type.
This class is just a helper to.
A class to be use C++ objects in ArkScript.
The ArkScript virtual machine, executing ArkScript bytecode.
const std::vector< Value > & constList() const
std::vector< Value > & list()
internal::Closure & refClosure()
const ProcType & proc() const
Value * reference() const
const internal::Closure & closure() const
bool isFunction() const noexcept
Value(*)(std::vector< Value > &, VM *) ProcType
std::vector< Value >::iterator Iterator
ValueType valueType() const noexcept
const std::string & string() const
constexpr uint8_t typeNum() const noexcept
std::variant< double, std::string, internal::PageAddr_t, ProcType, internal::Closure, UserType, std::vector< Value >, Value * > Value_t
const UserType & usertype() const
bool isIndexable() const noexcept
internal::PageAddr_t pageAddr() const
std::string & stringRef()
bool operator<(const Namespace &, const Namespace &)
bool operator==(const Namespace &A, const Namespace &B)
constexpr std::array types_to_str
const auto False
ArkScript False value.
bool operator!(const Value &A) noexcept
const auto Nil
ArkScript Nil value.
@ Any
Used only for typechecking.
const auto True
ArkScript True value.
bool operator!=(const Value &A, const Value &B) noexcept