12#ifndef ARK_VM_VALUE_HPP
13#define ARK_VM_VALUE_HPP
54 "List",
"Number",
"String",
"Function",
55 "CProc",
"Closure",
"UserType",
"Nil",
56 "Bool",
"Bool",
"Undefined",
"Reference",
100 template <typename T>
102 m_const_type(static_cast<uint8_t>(type)),
106 explicit Value(
int value)
noexcept;
107 explicit Value(
float value)
noexcept;
108 explicit Value(
double value)
noexcept;
109 explicit Value(
const std::string& value)
noexcept;
110 explicit Value(
const char* value)
noexcept;
112 explicit Value(ProcType value)
noexcept;
113 explicit Value(std::vector<Value>&& value)
noexcept;
121 const auto type = valueType();
122 return type == ValueType::PageAddr || type == ValueType::Closure || type == ValueType::CProc ||
123 (type == ValueType::Reference && reference()->isFunction());
126 [[nodiscard]]
double number()
const {
return std::get<double>(m_value); }
127 [[nodiscard]]
const std::string&
string()
const {
return std::get<std::string>(m_value); }
128 [[nodiscard]]
const std::vector<Value>&
constList()
const {
return std::get<std::vector<Value>>(m_value); }
130 [[nodiscard]] std::vector<Value>&
list() {
return std::get<std::vector<Value>>(m_value); }
131 [[nodiscard]] std::string&
stringRef() {
return std::get<std::string>(m_value); }
140 void push_back(
const Value& value);
147 void push_back(
Value&& value);
149 std::string toString(
VM& vm)
const noexcept;
161 [[nodiscard]]
constexpr uint8_t
type_num() const noexcept {
return m_const_type & 0x7f; }
164 [[nodiscard]]
const ProcType&
proc()
const {
return std::get<ProcType>(m_value); }
168 [[nodiscard]]
bool isConst() const noexcept {
return m_const_type & (1 << 7); }
172 m_const_type |= 1 << 7;
174 m_const_type = type_num();
181 if (A.type_num() != B.type_num())
187 return A.m_value == B.m_value;
192 if (A.type_num() != B.type_num())
193 return (A.type_num() - B.type_num()) < 0;
194 return A.m_value < B.m_value;
204 switch (A.valueType())
207 return A.constList().empty();
213 return A.string().empty();
Subtype of the value type, handling closures.
Subtype of the value, capable of handling any C++ type.
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()
constexpr uint8_t type_num() const noexcept
uint8_t m_const_type
First bit if for constness, right most bits are for type.
bool isConst() const noexcept
internal::Closure & refClosure()
const ProcType & proc() const
std::variant< double, std::string, internal::PageAddr_t, ProcType, internal::Closure, UserType, std::vector< Value >, Value * > Value_t
Value * reference() const
const internal::Closure & closure() const
bool isFunction() const noexcept
Value(*)(std::vector< Value > &, VM *) ProcType
void setConst(const bool value) noexcept
std::vector< Value >::iterator Iterator
ValueType valueType() const noexcept
const std::string & string() const
const UserType & usertype() const
internal::PageAddr_t pageAddr() const
std::string & stringRef()
const auto False
ArkScript False value.
bool operator!(const Value &A) noexcept
const auto Nil
ArkScript Nil value.
bool operator==(const Value &A, const Value &B) noexcept
@ Any
Used only for typechecking.
const auto True
ArkScript True value.
bool operator!=(const Value &A, const Value &B) noexcept
bool operator<(const Value &A, const Value &B) noexcept
const std::array< std::string, 13 > types_to_str