ArkScript
A small, fast, functional and scripting language for video games
ClosureScope.cpp
Go to the documentation of this file.
2
4
5namespace Ark::internal
6{
7 void ClosureScope::push_back(const uint16_t id, Value&& val)
8 {
9 m_data.emplace_back(id, std::move(val));
10 }
11
12 void ClosureScope::push_back(const uint16_t id, const Value& val)
13 {
14 m_data.emplace_back(id, val);
15 }
16
17 Value* ClosureScope::operator[](const uint16_t id_to_look_for)
18 {
19 for (auto& [id, value] : m_data)
20 {
21 if (id == id_to_look_for)
22 return &value;
23 }
24 return nullptr;
25 }
26
28 {
29 for (auto& [id, value] : m_data)
30 {
31 if (value.valueType() == ValueType::Reference)
32 other.push_back(id, value);
33 else
34 other.push_back(id, Value(&value));
35 }
36 }
37
38 bool operator==(const ClosureScope& A, const ClosureScope& B) noexcept
39 {
40 return A.m_data == B.m_data;
41 }
42}
Subtype of the value type, handling closures.
A class to store fields captured by a closure.
void push_back(uint16_t id, Value &&val)
Put a value in the scope.
std::vector< std::pair< uint16_t, Value > > m_data
Value * operator[](uint16_t id_to_look_for)
void mergeRefInto(ScopeView &other)
Merge values from this scope as refs in the other scope.
A class to handle the VM scope more efficiently.
Definition ScopeView.hpp:27
void push_back(uint16_t id, Value &&val) noexcept
Put a value in the scope.
Definition ScopeView.cpp:11
bool operator==(const Namespace &A, const Namespace &B)
Definition Namespace.hpp:21