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

ArkScript-lang / Ark / 16862576586

10 Aug 2025 02:21PM UTC coverage: 87.685% (+0.8%) from 86.869%
16862576586

push

github

SuperFola
fix(ci): import tests/unittests/testmodule.arkm in artifacts

7633 of 8705 relevant lines covered (87.69%)

125464.93 hits per line

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

81.93
/src/arkreactor/VM/ScopeView.cpp
1
#include <Ark/VM/ScopeView.hpp>
2

3
#include <Ark/Constants.hpp>
4

5
#include <cassert>
6

7
namespace Ark::internal
8
{
9
    ScopeView::ScopeView(pair_t* storage, const std::size_t start) noexcept :
141,532✔
10
        m_storage(storage), m_start(start), m_size(0), m_min_id(MaxValue16Bits), m_max_id(0)
141,532✔
11
    {}
283,064✔
12

13
    void ScopeView::pushBack(uint16_t id, Value&& val) noexcept
31,743✔
14
    {
31,743✔
15
        if (id < m_min_id)
31,743✔
16
            m_min_id = id;
5,410✔
17
        if (id > m_max_id)
31,743✔
18
            m_max_id = id;
25,167✔
19

20
        m_storage[m_start + m_size] = std::make_pair(id, std::move(val));
31,743✔
21
        ++m_size;
31,743✔
22
    }
31,743✔
23

24
    void ScopeView::pushBack(uint16_t id, const Value& val) noexcept
239,002✔
25
    {
239,002✔
26
        if (id < m_min_id)
239,002✔
27
            m_min_id = id;
133,610✔
28
        if (id > m_max_id)
239,002✔
29
            m_max_id = id;
220,157✔
30

31
        m_storage[m_start + m_size] = std::make_pair(id, val);
239,002✔
32
        ++m_size;
239,002✔
33
    }
239,002✔
34

35
    void ScopeView::insertFront(const std::vector<pair_t>& values) noexcept
1✔
36
    {
1✔
37
        const std::size_t offset_by = values.size();
1✔
38
        // If there is one day a bug with bad references, this can be caused by this code,
39
        // called when inserting plugins variables in a scope (because we invalidate said
40
        // references by moving them to another slot inside m_storage).
41
        for (std::size_t i = 0; i < m_size; ++i)
2✔
42
        {
43
            // This is a weak attempt to prevent / notice the bug before it goes in production,
44
            // if you hit this assertion read the comments carefully!
45
            assert(m_storage[m_start + m_size - i - 1].second.valueType() != ValueType::Reference && "References can not be moved around!");
1✔
46
            m_storage[m_start + m_size - i + offset_by - 1] = m_storage[m_start + m_size - i - 1];
1✔
47
        }
1✔
48

49
        std::size_t i = 0;
1✔
50
        for (const pair_t& pair : values)
2✔
51
        {
52
            const uint16_t id = pair.first;
1✔
53
            if (id < m_min_id)
1✔
54
                m_min_id = id;
×
55
            if (id > m_max_id)
1✔
56
                m_max_id = id;
1✔
57

58
            m_storage[m_start + i] = pair;
1✔
59
            ++i;
1✔
60
        }
1✔
61

62
        m_size += offset_by;
1✔
63
    }
1✔
64

65
    bool ScopeView::maybeHas(const uint16_t id) const noexcept
1,101,509✔
66
    {
1,101,509✔
67
        return m_min_id <= id && id <= m_max_id;
1,101,509✔
68
    }
69

70
    Value* ScopeView::operator[](const uint16_t id_to_look_for) noexcept
1,101,518✔
71
    {
1,101,518✔
72
        if (!maybeHas(id_to_look_for))
1,101,518✔
73
            return nullptr;
602,653✔
74

75
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
2,961,395✔
76
        {
77
            auto& [id, value] = m_storage[i];
2,462,530✔
78
            if (id == id_to_look_for)
2,462,530✔
79
                return &value;
475,883✔
80
        }
2,462,530✔
81
        return nullptr;
22,985✔
82
    }
1,101,518✔
83

84
    const Value* ScopeView::operator[](const uint16_t id_to_look_for) const noexcept
×
85
    {
×
86
        if (!maybeHas(id_to_look_for))
×
87
            return nullptr;
×
88

89
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
×
90
        {
91
            auto& [id, value] = m_storage[i];
×
92
            if (id == id_to_look_for)
×
93
                return &value;
×
94
        }
×
95
        return nullptr;
×
96
    }
×
97

98
    uint16_t ScopeView::idFromValue(const Value& val) const noexcept
2,096,130✔
99
    {
2,096,130✔
100
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
4,192,262✔
101
        {
102
            const auto& [id, value] = m_storage[i];
2,098,180✔
103
            if (value == val)
2,096,132✔
104
                return id;
2,048✔
105
        }
2,096,132✔
106
        return MaxValue16Bits;
2,094,082✔
107
    }
2,096,130✔
108

109
    void ScopeView::reset() noexcept
31,128✔
110
    {
31,128✔
111
        m_size = 0;
31,128✔
112
        m_min_id = MaxValue16Bits;
31,128✔
113
        m_max_id = 0;
31,128✔
114
    }
31,128✔
115

116
    bool operator==(const ScopeView& A, const ScopeView& B) noexcept
×
117
    {
×
118
        // if we have two scopes with the same number of elements and starting at the same position,
119
        // they must be identical, as we have a single storage for all scopes
120
        return A.m_size == B.m_size && A.m_start == B.m_start;
×
121
    }
122
}
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