11#ifndef ARK_VM_VALUE_HPP
12#define ARK_VM_VALUE_HPP
72struct std::hash<
Ark::ValueType>
76 return std::hash<std::underlying_type_t<Ark::ValueType>> {}(
static_cast<std::underlying_type_t<Ark::ValueType>
>(s));
107 std::shared_ptr<Dict_t>,
134 template <typename T>
136 m_type(type), m_value(value)
139 explicit Value(
int value)
noexcept;
140 explicit Value(
double value)
noexcept;
141 explicit Value(
const String_t& value)
noexcept;
142 explicit Value(
const char* value)
noexcept;
145 explicit Value(List_t&& value)
noexcept;
148 explicit Value(Dict_t&& value)
noexcept;
149 explicit Value(Ref_t ref)
noexcept;
154 return m_type == ValueType::PageAddr || m_type == ValueType::Closure || m_type == ValueType::CProc ||
155 (m_type == ValueType::Reference && reference()->isFunction());
159 return m_type == ValueType::List || m_type == ValueType::String;
164 [[nodiscard]]
const String_t&
string()
const {
return std::get<String_t>(m_value); }
169 [[nodiscard]]
List_t&
list() {
return std::get<List_t>(m_value); }
174 [[nodiscard]]
const Dict_t&
dict()
const {
return *std::get<std::shared_ptr<Dict_t>>(m_value); }
175 [[nodiscard]]
Dict_t&
dictRef() {
return *std::get<std::shared_ptr<Dict_t>>(m_value); }
184 void push_back(
const Value& value);
191 void push_back(
Value&& value);
193 std::string toString(
VM& vm)
const noexcept;
201 friend struct std::hash<
Ark::
Value>;
207 [[nodiscard]] constexpr uint8_t typeNum() const noexcept {
return static_cast<uint8_t
>(m_type); }
210 [[nodiscard]]
const Procedure&
proc()
const {
return std::get<Procedure>(m_value); }
217 if (A.m_type != B.m_type)
218 return (A.typeNum() - B.typeNum()) < 0;
219 return A.m_value < B.m_value;
229 switch (A.valueType())
232 return A.constList().empty();
235 return A.number() == 0.0;
238 return A.string().empty();
259 const auto index =
static_cast<std::underlying_type_t<Ark::ValueType>
>(type);
265struct std::hash<
std::vector<Ark::Value>>
267 [[nodiscard]] std::size_t
operator()(
const std::vector<Ark::Value>& s)
const noexcept
269 return std::hash<const Ark::Value*> {}(s.data());
274struct std::hash<
std::shared_ptr<Ark::Value::Dict_t>>
276 [[nodiscard]] std::size_t
operator()(
const std::shared_ptr<Ark::Value::Dict_t>& s)
const noexcept
278 return std::hash<const Ark::Value::Dict_t*> {}(s.get());
283struct std::hash<
Ark::Value>
287 return std::hash<Ark::Value::Value_t> {}(s.m_value);
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 Dict_t & dict() const
const String_t & string() const
const List_t & constList() const
internal::Closure & refClosure()
const Procedure & proc() const
const internal::Closure & closure() const
bool isFunction() const noexcept
ValueType valueType() const noexcept
const UserType & usertype() const
bool isIndexable() const noexcept
std::variant< Number_t, String_t, internal::PageAddr_t, Procedure, internal::Closure, UserType, List_t, std::shared_ptr< Dict_t >, Ref_t > Value_t
internal::PageAddr_t pageAddr() const
std::vector< Value > List_t
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.
const auto True
ArkScript True value.
bool operator!=(const Value &A, const Value &B) noexcept
@ Any
Used only for typechecking.
std::string to_string(const Ark::ValueType type) noexcept
std::size_t operator()(const Ark::ValueType &s) const noexcept
std::size_t operator()(const Ark::Value &s) const noexcept
std::size_t operator()(const std::shared_ptr< Ark::Value::Dict_t > &s) const noexcept
std::size_t operator()(const std::vector< Ark::Value > &s) const noexcept