11#ifndef ARK_VM_VALUE_HPP
12#define ARK_VM_VALUE_HPP
108 template <typename T>
110 m_type(type), m_value(value)
113 explicit Value(
int value)
noexcept;
114 explicit Value(
double value)
noexcept;
115 explicit Value(
const std::string& value)
noexcept;
116 explicit Value(
const char* value)
noexcept;
119 explicit Value(std::vector<Value>&& value)
noexcept;
127 return m_type == ValueType::PageAddr || m_type == ValueType::Closure || m_type == ValueType::CProc ||
128 (m_type == ValueType::Reference && reference()->isFunction());
132 return m_type == ValueType::List || m_type == ValueType::String;
135 [[nodiscard]]
double number()
const {
return std::get<double>(m_value); }
136 [[nodiscard]]
const std::string&
string()
const {
return std::get<std::string>(m_value); }
137 [[nodiscard]]
const std::vector<Value>&
constList()
const {
return std::get<std::vector<Value>>(m_value); }
139 [[nodiscard]] std::vector<Value>&
list() {
return std::get<std::vector<Value>>(m_value); }
140 [[nodiscard]] std::string&
stringRef() {
return std::get<std::string>(m_value); }
149 void push_back(
const Value& value);
156 void push_back(
Value&& value);
158 std::string toString(
VM& vm)
const noexcept;
171 [[nodiscard]]
constexpr uint8_t
typeNum() const noexcept {
return static_cast<uint8_t
>(m_type); }
174 [[nodiscard]]
const Procedure&
proc()
const {
return std::get<Procedure>(m_value); }
182 if (A.m_type != B.m_type)
188 return A.m_value == B.m_value;
193 if (A.m_type != B.m_type)
194 return (A.typeNum() - B.typeNum()) < 0;
195 return A.m_value < B.m_value;
205 switch (A.valueType())
208 return A.constList().empty();
211 return A.number() == 0.0;
214 return A.string().empty();
Subtype of the value type, handling closures.
Wrapper object for user-defined functions.
Subtype of the value, capable of handling any C++ type.
This class is just a helper to.
Storage class to hold custom functions.
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 Procedure & proc() const
Value * reference() const
const internal::Closure & closure() const
bool isFunction() const noexcept
std::vector< Value >::iterator Iterator
ValueType valueType() const noexcept
const std::string & string() const
std::variant< double, std::string, internal::PageAddr_t, Procedure, internal::Closure, UserType, std::vector< Value >, Value * > Value_t
constexpr uint8_t typeNum() const noexcept
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