ArkScript
A small, fast, functional and scripting language for video games
ExecutionContext.hpp
Go to the documentation of this file.
1/**
2 * @file ExecutionContext.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief Keeping track of the internal data needed by the VM
5 * @date 2021-11-15
6 *
7 * @copyright Copyright (c) 2021-2025
8 *
9 */
10
11#ifndef ARK_VM_EXECUTIONCONTEXT_HPP
12#define ARK_VM_EXECUTIONCONTEXT_HPP
13
14#include <array>
15#include <limits>
16#include <memory>
17#include <optional>
18
19#include <Ark/Constants.hpp>
20#include <Ark/VM/Value.hpp>
21#include <Ark/VM/ScopeView.hpp>
23
24#ifdef max
25# undef max
26#endif
27
28namespace Ark::internal
29{
31 {
32 static inline unsigned Count = 0;
33
34 std::size_t ip {}; ///< Instruction pointer
35 std::size_t pp {}; ///< Page pointer
36 uint16_t sp {}; ///< Stack pointer
37 uint16_t fc {}; ///< Frame count
38 uint16_t last_symbol;
39 const bool primary; ///< Tells if the current ExecutionContext is the primary one or not
40
41 std::optional<ClosureScope> saved_scope {}; ///< Scope created by CAPTURE <x> instructions, used by the MAKE_CLOSURE instruction
42 std::vector<std::shared_ptr<ClosureScope>> stacked_closure_scopes {}; ///< Stack the closure scopes to keep the closure alive as long as we are calling them
43
44 std::vector<ScopeView> locals {};
45 std::array<ScopeView::pair_t, ScopeStackSize> scopes_storage {}; ///< All the ScopeView use this array to store id->value
46
47 std::array<Value, VMStackSize> stack {};
48
49 ExecutionContext() noexcept :
50 last_symbol(std::numeric_limits<uint16_t>::max()),
51 primary(Count == 0)
52 {
53 Count++;
54 }
55 };
56}
57
58#endif
Subtype of the value type, handling closures.
Constants used by ArkScript.
Default value type handled by the virtual machine.
std::array< ScopeView::pair_t, ScopeStackSize > scopes_storage
All the ScopeView use this array to store id->value.
std::vector< std::shared_ptr< ClosureScope > > stacked_closure_scopes
Stack the closure scopes to keep the closure alive as long as we are calling them.
std::array< Value, VMStackSize > stack
std::vector< ScopeView > locals
const bool primary
Tells if the current ExecutionContext is the primary one or not.
std::size_t ip
Instruction pointer.
std::optional< ClosureScope > saved_scope
Scope created by CAPTURE <x> instructions, used by the MAKE_CLOSURE instruction.