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

ArkScript-lang / Ark / 14421412500

12 Apr 2025 04:30PM UTC coverage: 80.472% (+0.03%) from 80.447%
14421412500

Pull #523

github

web-flow
Merge 8ebcbb2cf into 3d9ea4b49
Pull Request #523: feat(compiler, vm, scopes): adding RESET_SCOPE instruction to be able to reuse a scope inside while loops

6 of 9 new or added lines in 4 files covered. (66.67%)

3 existing lines in 1 file now uncovered.

6169 of 7666 relevant lines covered (80.47%)

77509.85 hits per line

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

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

3
#include <limits>
4

5
namespace Ark::internal
6
{
7
    ScopeView::ScopeView(pair_t* storage, const std::size_t start) noexcept :
126,626✔
8
        m_storage(storage), m_start(start), m_size(0), m_min_id(std::numeric_limits<uint16_t>::max()), m_max_id(0)
126,626✔
9
    {}
253,252✔
10

11
    void ScopeView::push_back(uint16_t id, Value&& val) noexcept
16,340✔
12
    {
16,340✔
13
        if (id < m_min_id)
16,340✔
14
            m_min_id = id;
2,043✔
15
        if (id > m_max_id)
16,340✔
16
            m_max_id = id;
13,783✔
17

18
        m_storage[m_start + m_size] = std::make_pair(id, std::move(val));
16,340✔
19
        ++m_size;
16,340✔
20
    }
16,340✔
21

22
    void ScopeView::push_back(uint16_t id, const Value& val) noexcept
352,172✔
23
    {
352,172✔
24
        if (id < m_min_id)
352,172✔
25
            m_min_id = id;
131,103✔
26
        if (id > m_max_id)
352,172✔
27
            m_max_id = id;
224,266✔
28

29
        m_storage[m_start + m_size] = std::make_pair(id, val);
352,172✔
30
        ++m_size;
352,172✔
31
    }
352,172✔
32

33
    bool ScopeView::maybeHas(const uint16_t id) const noexcept
850,766✔
34
    {
850,766✔
35
        return m_min_id <= id && id <= m_max_id;
850,766✔
36
    }
37

38
    Value* ScopeView::operator[](const uint16_t id_to_look_for) noexcept
850,773✔
39
    {
850,773✔
40
        if (!maybeHas(id_to_look_for))
850,773✔
41
            return nullptr;
387,655✔
42

43
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
1,816,644✔
44
        {
45
            auto& [id, value] = m_storage[i];
1,353,526✔
46
            if (id == id_to_look_for)
1,353,526✔
47
                return &value;
447,951✔
48
        }
1,353,526✔
49
        return nullptr;
15,171✔
50
    }
850,773✔
51

52
    const Value* ScopeView::operator[](const uint16_t id_to_look_for) const noexcept
×
53
    {
×
54
        if (!maybeHas(id_to_look_for))
×
55
            return nullptr;
×
56

57
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
×
58
        {
59
            auto& [id, value] = m_storage[i];
×
60
            if (id == id_to_look_for)
×
61
                return &value;
×
62
        }
×
63
        return nullptr;
×
64
    }
×
65

66
    uint16_t ScopeView::idFromValue(const Value& val) const noexcept
×
67
    {
×
68
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
×
69
        {
70
            const auto& [id, value] = m_storage[i];
×
71
            if (value == val)
×
72
                return id;
×
73
        }
×
74
        return std::numeric_limits<uint16_t>::max();
×
75
    }
×
76

NEW
77
    bool operator==(const ScopeView& A, const ScopeView& B) noexcept
×
NEW
78
    {
×
79
        // if we have two scopes with the same number of elements and starting at the same position,
80
        // they must be identical, as we have a single storage for all scopes
NEW
81
        return A.m_size == B.m_size && A.m_start == B.m_start;
×
82
    }
83
}
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