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

ArkScript-lang / Ark / 24315463645

12 Apr 2026 08:15PM UTC coverage: 93.946%. Remained the same
24315463645

Pull #677

github

web-flow
Merge 888fd679e into a3329d309
Pull Request #677: wip

15 of 15 new or added lines in 2 files covered. (100.0%)

16 existing lines in 2 files now uncovered.

9870 of 10506 relevant lines covered (93.95%)

658861.2 hits per line

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

75.81
/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 :
173,771✔
10
        m_storage(storage), m_start(start), m_size(0), m_min_id(MaxValue16Bits), m_max_id(0)
173,771✔
11
    {}
347,542✔
12

13
    void ScopeView::insertFront(const std::vector<pair_t>& values) noexcept
1✔
14
    {
1✔
15
        const std::size_t offset_by = values.size();
1✔
16
        // If there is one day a bug with bad references, this can be caused by this code,
17
        // called when inserting plugins variables in a scope (because we invalidate said
18
        // references by moving them to another slot inside m_storage).
19
        for (std::size_t i = 0; i < m_size; ++i)
2✔
20
        {
21
            // This is a weak attempt to prevent / notice the bug before it goes in production,
22
            // if you hit this assertion read the comments carefully!
23
            assert(m_storage[m_start + m_size - i - 1].second.valueType() != ValueType::Reference && "References can not be moved around!");
1✔
24
            m_storage[m_start + m_size - i + offset_by - 1] = m_storage[m_start + m_size - i - 1];
1✔
25
        }
1✔
26

27
        std::size_t i = 0;
1✔
28
        for (const pair_t& pair : values)
2✔
29
        {
30
            const uint16_t id = pair.first;
1✔
31
            if (id < m_min_id)
1✔
UNCOV
32
                m_min_id = id;
×
33
            if (id > m_max_id)
1✔
34
                m_max_id = id;
1✔
35

36
            m_storage[m_start + i] = pair;
1✔
37
            ++i;
1✔
38
        }
1✔
39

40
        m_size += offset_by;
1✔
41
    }
1✔
42

43
    Value* ScopeView::operator[](const uint16_t id_to_look_for) noexcept
27,153,895✔
44
    {
27,153,895✔
45
        if (!maybeHas(id_to_look_for))
27,153,895✔
46
            return nullptr;
15,362,842✔
47

48
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
380,707,470✔
49
        {
50
            auto& [id, value] = m_storage[i];
368,916,417✔
51
            if (id == id_to_look_for)
368,916,417✔
52
                return &value;
11,751,076✔
53
        }
368,916,417✔
54
        return nullptr;
39,987✔
55
    }
27,153,895✔
56

UNCOV
57
    const Value* ScopeView::operator[](const uint16_t id_to_look_for) const noexcept
×
UNCOV
58
    {
×
UNCOV
59
        if (!maybeHas(id_to_look_for))
×
UNCOV
60
            return nullptr;
×
61

UNCOV
62
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
×
63
        {
UNCOV
64
            auto& [id, value] = m_storage[i];
×
UNCOV
65
            if (id == id_to_look_for)
×
UNCOV
66
                return &value;
×
UNCOV
67
        }
×
UNCOV
68
        return nullptr;
×
UNCOV
69
    }
×
70

71
    uint16_t ScopeView::idFromValue(const Value& val) const noexcept
2,096,142✔
72
    {
2,096,142✔
73
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
4,192,281✔
74
        {
75
            const auto& [id, value] = m_storage[i];
2,098,187✔
76
            if (value == val)
2,096,139✔
77
                return id;
2,048✔
78
        }
2,096,139✔
79
        return MaxValue16Bits;
2,094,094✔
80
    }
2,096,142✔
81

82
    void ScopeView::reset() noexcept
1,159,317✔
83
    {
1,159,317✔
84
        m_size = 0;
1,159,317✔
85
        m_min_id = MaxValue16Bits;
1,159,317✔
86
        m_max_id = 0;
1,159,317✔
87
    }
1,159,317✔
88

UNCOV
89
    bool operator==(const ScopeView& A, const ScopeView& B) noexcept
×
UNCOV
90
    {
×
91
        // if we have two scopes with the same number of elements and starting at the same position,
92
        // they must be identical, as we have a single storage for all scopes
UNCOV
93
        return A.m_size == B.m_size && A.m_start == B.m_start;
×
94
    }
95
}
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