• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 13900345969

17 Mar 2025 01:13PM UTC coverage: 78.852% (-0.1%) from 78.956%
13900345969

push

github

SuperFola
refactor: remove a layer of indirection when accessing the scopes storage

9 of 12 new or added lines in 4 files covered. (75.0%)

185 existing lines in 3 files now uncovered.

5865 of 7438 relevant lines covered (78.85%)

81043.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/include/Ark/VM/ScopeView.hpp
1
/**
2
 * @file Scope.hpp
3
 * @author Alexandre Plateau (lexplt.dev@gmail.com)
4
 * @brief The virtual machine scope system
5
 * @version 0.2
6
 * @date 2020-10-27
7
 *
8
 * @copyright Copyright (c) 2020-2025
9
 *
10
 */
11

12
#ifndef ARK_VM_SCOPE_HPP
13
#define ARK_VM_SCOPE_HPP
14

15
#include <array>
16
#include <cinttypes>
17

18
#include <Ark/Platform.hpp>
19
#include <Ark/VM/Value.hpp>
20

21
namespace Ark::internal
22
{
23
    /**
24
     * @brief A class to handle the VM scope more efficiently
25
     *
26
     */
27
    class ARK_API ScopeView
28
    {
29
    public:
30
        using pair_t = std::pair<uint16_t, Value>;
31

32
        /**
33
         * @brief Deleted constructor to avoid creating ScopeViews pointing to nothing. Helps catch bugs at compile time
34
         */
35
        ScopeView() = delete;
36

37
        /**
38
         * @brief Create a new ScopeView
39
         *
40
         * @param storage pointer to the shared scope storage
41
         * @param start first free starting position
42
         */
43
        ScopeView(pair_t* storage, std::size_t start) noexcept;
44

45
        /**
46
         * @brief Put a value in the scope
47
         *
48
         * @param id The symbol id of the variable
49
         * @param val The value linked to the symbol
50
         */
51
        void push_back(uint16_t id, Value&& val) noexcept;
52

53
        /**
54
         * @brief Put a value in the scope
55
         *
56
         * @param id The symbol id of the variable
57
         * @param val The value linked to the symbol
58
         */
59
        void push_back(uint16_t id, const Value& val) noexcept;
60

61
        /**
62
         * @brief Check if the scope maybe holds a specific symbol in memory
63
         *
64
         * @param id The id of the symbol
65
         * @return true On success
66
         * @return false Otherwise
67
         */
68
        bool maybeHas(uint16_t id) const noexcept;
69

70
        /**
71
         * @brief Get a value from its symbol id
72
         *
73
         * @param id_to_look_for
74
         * @return Value* Returns nullptr if the value can not be found
75
         */
76
        Value* operator[](uint16_t id_to_look_for) noexcept;
77

78
        /**
79
         * @brief Get a value from its symbol id
80
         *
81
         * @param id_to_look_for
82
         * @return const Value* Returns nullptr if the value can not be found
83
         */
84
        const Value* operator[](uint16_t id_to_look_for) const noexcept;
85

86
        /**
87
         * @brief Get the id of a variable based on its value ; used for debug only
88
         *
89
         * @param val
90
         * @return uint16_t
91
         */
92
        [[nodiscard]] uint16_t idFromValue(const Value& val) const noexcept;
93

94
        /**
95
         * @brief Return the start index of the current
96
         *
97
         * @return const std::size_t
98
         */
99
        [[nodiscard]] inline const pair_t& atPos(const std::size_t i) const noexcept
×
100
        {
×
NEW
101
            return m_storage[m_start + i];
×
102
        }
103

104
        /**
105
         * @brief Return the size of the scope
106
         *
107
         * @return const std::size_t
108
         */
109
        [[nodiscard]] inline std::size_t size() const noexcept
×
110
        {
×
111
            return m_size;
×
112
        }
113

114
        /**
115
         * @brief Compute the position of the first free slot in the shared storage, after this scope
116
         *
117
         * @return std::size_t
118
         */
119
        [[nodiscard]] inline std::size_t storageEnd() const noexcept
126,529✔
120
        {
126,529✔
121
            return m_start + m_size;
126,529✔
122
        }
123

124
        friend ARK_API bool operator==(const ScopeView& A, const ScopeView& B) noexcept;
125

126
        friend class Ark::VM;
127

128
    private:
129
        pair_t* m_storage;
130
        std::size_t m_start;
131
        std::size_t m_size;
132
        uint16_t m_min_id;  ///< Minimum stored ID, used for a basic bloom filter
133
        uint16_t m_max_id;  ///< Maximum stored ID, used for a basic bloom filter
134
    };
135
}
136

137
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc