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

ArkScript-lang / Ark / 14421428349

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

Pull #523

github

web-flow
Merge 5d10d242c 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%)

78497.4 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,663✔
8
        m_storage(storage), m_start(start), m_size(0), m_min_id(std::numeric_limits<uint16_t>::max()), m_max_id(0)
126,663✔
9
    {}
253,326✔
10

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

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

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

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

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

38
    Value* ScopeView::operator[](const uint16_t id_to_look_for) noexcept
853,723✔
39
    {
853,723✔
40
        if (!maybeHas(id_to_look_for))
853,723✔
41
            return nullptr;
389,172✔
42

43
        for (std::size_t i = m_start; i < m_start + m_size; ++i)
1,829,955✔
44
        {
45
            auto& [id, value] = m_storage[i];
1,365,404✔
46
            if (id == id_to_look_for)
1,365,404✔
47
                return &value;
449,346✔
48
        }
1,365,404✔
49
        return nullptr;
15,206✔
50
    }
853,723✔
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