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 * @version 0.1
6 * @date 2021-11-15
7 *
8 * @copyright Copyright (c) 2021-2024
9 *
10 */
11
12#ifndef ARK_VM_EXECUTIONCONTEXT_HPP
13#define ARK_VM_EXECUTIONCONTEXT_HPP
14
15#include <array>
16#include <limits>
17#include <memory>
18#include <optional>
19
20#include <Ark/Constants.hpp>
21#include <Ark/VM/Value.hpp>
22#include <Ark/VM/Scope.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<Scope> saved_scope {}; ///< Scope created by CAPTURE <x> instructions, used by the MAKE_CLOSURE instruction
42 std::vector<Scope> locals {};
43 std::vector<std::shared_ptr<Scope>> stacked_closure_scopes {}; ///< Stack the closure scopes to keep the closure alive as long as we are calling them
44 std::array<Value, VMStackSize> stack {};
45
46 ExecutionContext() noexcept :
47 last_symbol(std::numeric_limits<uint16_t>::max()),
48 primary(Count == 0)
49 {
50 Count++;
51 }
52 };
53}
54
55#endif
Constants used by ArkScript.
The virtual machine scope system.
std::array< Value, VMStackSize > stack
std::optional< Scope > saved_scope
Scope created by CAPTURE <x> instructions, used by the MAKE_CLOSURE instruction.
const bool primary
Tells if the current ExecutionContext is the primary one or not.
std::size_t ip
Instruction pointer.
std::vector< std::shared_ptr< Scope > > stacked_closure_scopes
Stack the closure scopes to keep the closure alive as long as we are calling them.