ArkScript
A small, fast, functional and scripting language for video games
ClosureScope.hpp
Go to the documentation of this file.
1/**
2 * @file ClosureScope.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief Subtype of the value type, handling closures
5 * @date 2025-03-17
6 *
7 * @copyright Copyright (c) 2025
8 *
9 */
10
11#ifndef ARK_VM_VALUE_CLOSURESCOPE_HPP
12#define ARK_VM_VALUE_CLOSURESCOPE_HPP
13
14#include <vector>
15#include <utility>
16#include <cinttypes>
17
18#include <Ark/Platform.hpp>
19#include <Ark/VM/Value.hpp>
20
21namespace Ark::internal
22{
23 class ScopeView;
24
25 /**
26 * @brief A class to store fields captured by a closure
27 */
29 {
30 public:
31 /**
32 * @brief Create a new ClosureScope
33 */
34 ClosureScope() noexcept = default;
35
36 /**
37 * @brief Put a value in the scope
38 *
39 * @param id The symbol id of the variable
40 * @param val The value linked to the symbol
41 */
42 void push_back(uint16_t id, Value&& val);
43
44 /**
45 * @brief Put a value in the scope
46 *
47 * @param id The symbol id of the variable
48 * @param val The value linked to the symbol
49 */
50 void push_back(uint16_t id, const Value& val);
51
52 Value* operator[](uint16_t id_to_look_for);
53
54 /**
55 * @brief Merge values from this scope as refs in the other scope
56 * @details This scope must be kept alive for the ref to be used
57 * @param other
58 */
59 void mergeRefInto(ScopeView& other);
60
61 friend class Closure;
62
63 friend ARK_API bool operator==(const ClosureScope& A, const ClosureScope& B) noexcept;
64
65 private:
66 std::vector<std::pair<uint16_t, Value>> m_data;
67 };
68}
69
70#endif // ARK_VM_VALUE_CLOSURESCOPE_HPP
#define ARK_API
Definition Module.hpp:28
ArkScript configuration macros.
Default value type handled by the virtual machine.
A class to store fields captured by a closure.
ClosureScope() noexcept=default
Create a new ClosureScope.
Closure management.
Definition Closure.hpp:36
A class to handle the VM scope more efficiently.
Definition ScopeView.hpp:27