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

ArkScript-lang / Ark / 15453345670

04 Jun 2025 09:40PM UTC coverage: 86.735% (+0.1%) from 86.608%
15453345670

push

github

SuperFola
chore: updating fuzzing corpus

2 of 3 new or added lines in 2 files covered. (66.67%)

140 existing lines in 7 files now uncovered.

7258 of 8368 relevant lines covered (86.74%)

120482.26 hits per line

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

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

3
#include <utility>
4
#include <numeric>
5
#include <limits>
6
#include <fmt/core.h>
7
#include <fmt/color.h>
8
#include <fmt/ostream.h>
9

10
#include <Ark/Files.hpp>
11
#include <Ark/Utils.hpp>
12
#include <Ark/TypeChecker.hpp>
13
#include <Ark/Compiler/Instructions.hpp>
14

15
struct mapping
16
{
17
    char* name;
18
    Ark::Value (*value)(std::vector<Ark::Value>&, Ark::VM*);
19
};
20

21
namespace Ark
22
{
23
    using namespace internal;
24

25
    namespace helper
26
    {
27
        inline Value tail(Value* a)
337✔
28
        {
337✔
29
            if (a->valueType() == ValueType::List)
337✔
30
            {
31
                if (a->constList().size() < 2)
69✔
32
                    return Value(ValueType::List);
18✔
33

34
                std::vector<Value> tmp(a->constList().size() - 1);
51✔
35
                for (std::size_t i = 1, end = a->constList().size(); i < end; ++i)
327✔
36
                    tmp[i - 1] = a->constList()[i];
276✔
37
                return Value(std::move(tmp));
51✔
38
            }
52✔
39
            if (a->valueType() == ValueType::String)
268✔
40
            {
41
                if (a->string().size() < 2)
267✔
42
                    return Value(ValueType::String);
50✔
43

44
                Value b { *a };
217✔
45
                b.stringRef().erase(b.stringRef().begin());
217✔
46
                return b;
217✔
47
            }
217✔
48

49
            throw types::TypeCheckingError(
2✔
50
                "tail",
1✔
51
                { { types::Contract { { types::Typedef("value", ValueType::List) } },
2✔
52
                    types::Contract { { types::Typedef("value", ValueType::String) } } } },
1✔
53
                { *a });
1✔
54
        }
337✔
55

56
        inline Value head(Value* a)
1,131✔
57
        {
1,131✔
58
            if (a->valueType() == ValueType::List)
1,131✔
59
            {
60
                if (a->constList().empty())
863✔
61
                    return Builtins::nil;
×
62
                return a->constList()[0];
863✔
63
            }
64
            if (a->valueType() == ValueType::String)
268✔
65
            {
66
                if (a->string().empty())
267✔
67
                    return Value(ValueType::String);
1✔
68
                return Value(std::string(1, a->stringRef()[0]));
267✔
69
            }
70

71
            throw types::TypeCheckingError(
2✔
72
                "head",
1✔
73
                { { types::Contract { { types::Typedef("value", ValueType::List) } },
2✔
74
                    types::Contract { { types::Typedef("value", ValueType::String) } } } },
1✔
75
                { *a });
1✔
76
        }
1,131✔
77

78
        inline Value at(Value& container, Value& index, VM& vm)
15,198✔
79
        {
15,198✔
80
            if (index.valueType() != ValueType::Number)
15,198✔
81
                throw types::TypeCheckingError(
5✔
82
                    "@",
1✔
83
                    { { types::Contract { { types::Typedef("src", ValueType::List), types::Typedef("idx", ValueType::Number) } },
2✔
84
                        types::Contract { { types::Typedef("src", ValueType::String), types::Typedef("idx", ValueType::Number) } } } },
1✔
85
                    { container, index });
1✔
86

87
            const auto num = static_cast<long>(index.number());
15,197✔
88

89
            if (container.valueType() == ValueType::List)
15,197✔
90
            {
91
                const auto i = static_cast<std::size_t>(num < 0 ? static_cast<long>(container.list().size()) + num : num);
7,429✔
92
                if (i < container.list().size())
7,429✔
93
                    return container.list()[i];
7,428✔
94
                else
95
                    VM::throwVMError(
1✔
96
                        ErrorKind::Index,
97
                        fmt::format("{} out of range {} (length {})", num, container.toString(vm), container.list().size()));
1✔
98
            }
7,429✔
99
            else if (container.valueType() == ValueType::String)
7,768✔
100
            {
101
                const auto i = static_cast<std::size_t>(num < 0 ? static_cast<long>(container.string().size()) + num : num);
7,767✔
102
                if (i < container.string().size())
7,767✔
103
                    return Value(std::string(1, container.string()[i]));
7,766✔
104
                else
105
                    VM::throwVMError(
1✔
106
                        ErrorKind::Index,
107
                        fmt::format("{} out of range \"{}\" (length {})", num, container.string(), container.string().size()));
1✔
108
            }
7,767✔
109
            else
110
                throw types::TypeCheckingError(
2✔
111
                    "@",
1✔
112
                    { { types::Contract { { types::Typedef("src", ValueType::List), types::Typedef("idx", ValueType::Number) } },
2✔
113
                        types::Contract { { types::Typedef("src", ValueType::String), types::Typedef("idx", ValueType::Number) } } } },
1✔
114
                    { container, index });
1✔
115
        }
15,201✔
116
    }
117

118
    VM::VM(State& state) noexcept :
501✔
119
        m_state(state), m_exit_code(0), m_running(false)
167✔
120
    {
167✔
121
        m_execution_contexts.emplace_back(std::make_unique<ExecutionContext>());
167✔
122
    }
167✔
123

124
    void VM::init() noexcept
168✔
125
    {
168✔
126
        ExecutionContext& context = *m_execution_contexts.back();
168✔
127
        for (const auto& c : m_execution_contexts)
336✔
128
        {
129
            c->ip = 0;
168✔
130
            c->pp = 0;
168✔
131
            c->sp = 0;
168✔
132
        }
168✔
133

134
        context.sp = 0;
168✔
135
        context.fc = 1;
168✔
136

137
        m_shared_lib_objects.clear();
168✔
138
        context.stacked_closure_scopes.clear();
168✔
139
        context.stacked_closure_scopes.emplace_back(nullptr);
168✔
140

141
        context.saved_scope.reset();
168✔
142
        m_exit_code = 0;
168✔
143

144
        context.locals.clear();
168✔
145
        context.locals.reserve(128);
168✔
146
        context.locals.emplace_back(context.scopes_storage.data(), 0);
168✔
147

148
        // loading bound stuff
149
        // put them in the global frame if we can, aka the first one
150
        for (const auto& [sym_id, value] : m_state.m_binded)
348✔
151
        {
152
            auto it = std::ranges::find(m_state.m_symbols, sym_id);
172✔
153
            if (it != m_state.m_symbols.end())
172✔
154
                context.locals[0].push_back(static_cast<uint16_t>(std::distance(m_state.m_symbols.begin(), it)), value);
8✔
155
        }
172✔
156
    }
168✔
157

158
    Value VM::getField(Value* closure, const uint16_t id, ExecutionContext& context)
2,335✔
159
    {
2,335✔
160
        if (closure->valueType() != ValueType::Closure)
2,335✔
161
        {
162
            if (context.last_symbol < m_state.m_symbols.size()) [[likely]]
1✔
163
                throwVMError(
3✔
164
                    ErrorKind::Type,
165
                    fmt::format(
4✔
166
                        "`{}' is a {}, not a Closure, can not get the field `{}' from it",
1✔
167
                        m_state.m_symbols[context.last_symbol],
1✔
168
                        types_to_str[static_cast<std::size_t>(closure->valueType())],
1✔
169
                        m_state.m_symbols[id]));
1✔
170
            else
171
                throwVMError(ErrorKind::Type,
×
172
                             fmt::format(
×
173
                                 "{} is not a Closure, can not get the field `{}' from it",
×
174
                                 types_to_str[static_cast<std::size_t>(closure->valueType())],
167✔
175
                                 m_state.m_symbols[id]));
×
176
        }
177

178
        if (Value* field = closure->refClosure().refScope()[id]; field != nullptr)
4,668✔
179
        {
180
            // check for CALL instruction (the instruction because context.ip is already on the next instruction word)
181
            if (m_state.m_pages[context.pp][context.ip] == CALL)
2,332✔
182
                return Value(Closure(closure->refClosure().scopePtr(), field->pageAddr()));
1,358✔
183
            else
184
                return *field;
974✔
185
        }
186
        else
187
        {
188
            if (!closure->refClosure().hasFieldEndingWith(m_state.m_symbols[id], *this))
2✔
189
                throwVMError(
1✔
190
                    ErrorKind::Scope,
191
                    fmt::format(
2✔
192
                        "`{0}' isn't in the closure environment: {1}",
1✔
193
                        m_state.m_symbols[id],
1✔
194
                        closure->refClosure().toString(*this)));
1✔
195
            throwVMError(
1✔
196
                ErrorKind::Scope,
197
                fmt::format(
2✔
198
                    "`{0}' isn't in the closure environment: {1}. A variable in the package might have the same name as '{0}', "
1✔
199
                    "and name resolution tried to fully qualify it. Rename either the variable or the capture to solve this",
200
                    m_state.m_symbols[id],
1✔
201
                    closure->refClosure().toString(*this)));
1✔
202
        }
203
    }
2,335✔
204

205
    Value VM::createList(const std::size_t count, internal::ExecutionContext& context)
1,489✔
206
    {
1,489✔
207
        Value l(ValueType::List);
1,489✔
208
        if (count != 0)
1,489✔
209
            l.list().reserve(count);
541✔
210

211
        for (uint16_t i = 0; i < count; ++i)
2,881✔
212
            l.push_back(*popAndResolveAsPtr(context));
1,392✔
213

214
        return l;
1,489✔
215
    }
1,489✔
216

217
    void VM::listAppendInPlace(Value* list, const std::size_t count, ExecutionContext& context)
1,418✔
218
    {
1,418✔
219
        if (list->valueType() != ValueType::List)
1,418✔
220
        {
221
            std::vector<Value> args = { *list };
1✔
222
            for (std::size_t i = 0; i < count; ++i)
2✔
223
                args.push_back(*popAndResolveAsPtr(context));
1✔
224
            throw types::TypeCheckingError(
2✔
225
                "append!",
1✔
226
                { { types::Contract { { types::Typedef("list", ValueType::List), types::Typedef("value", ValueType::Any, /* variadic= */ true) } } } },
1✔
227
                args);
228
        }
1✔
229

230
        for (std::size_t i = 0; i < count; ++i)
2,834✔
231
            list->push_back(*popAndResolveAsPtr(context));
1,417✔
232
    }
1,418✔
233

234
    Value& VM::operator[](const std::string& name) noexcept
33✔
235
    {
33✔
236
        // find id of object
237
        const auto it = std::ranges::find(m_state.m_symbols, name);
33✔
238
        if (it == m_state.m_symbols.end())
33✔
239
        {
240
            m_no_value = Builtins::nil;
3✔
241
            return m_no_value;
3✔
242
        }
243

244
        const auto dist = std::distance(m_state.m_symbols.begin(), it);
30✔
245
        if (std::cmp_less(dist, std::numeric_limits<uint16_t>::max()))
30✔
246
        {
247
            ExecutionContext& context = *m_execution_contexts.front();
30✔
248

249
            const auto id = static_cast<uint16_t>(dist);
30✔
250
            Value* var = findNearestVariable(id, context);
30✔
251
            if (var != nullptr)
30✔
252
                return *var;
30✔
253
        }
30✔
254

255
        m_no_value = Builtins::nil;
×
256
        return m_no_value;
×
257
    }
33✔
258

259
    void VM::loadPlugin(const uint16_t id, ExecutionContext& context)
×
260
    {
×
261
        namespace fs = std::filesystem;
262

263
        const std::string file = m_state.m_constants[id].stringRef();
×
264

265
        std::string path = file;
×
266
        // bytecode loaded from file
267
        if (m_state.m_filename != ARK_NO_NAME_FILE)
×
268
            path = (fs::path(m_state.m_filename).parent_path() / fs::path(file)).relative_path().string();
×
269

270
        std::shared_ptr<SharedLibrary> lib;
×
271
        // if it exists alongside the .arkc file
272
        if (Utils::fileExists(path))
×
273
            lib = std::make_shared<SharedLibrary>(path);
×
274
        else
275
        {
276
            for (auto const& v : m_state.m_libenv)
×
277
            {
278
                std::string lib_path = (fs::path(v) / fs::path(file)).string();
×
279

280
                // if it's already loaded don't do anything
281
                if (std::ranges::find_if(m_shared_lib_objects, [&](const auto& val) {
×
282
                        return (val->path() == path || val->path() == lib_path);
×
283
                    }) != m_shared_lib_objects.end())
×
284
                    return;
×
285

286
                // check in lib_path
287
                if (Utils::fileExists(lib_path))
×
288
                {
289
                    lib = std::make_shared<SharedLibrary>(lib_path);
×
290
                    break;
×
291
                }
292
            }
×
293
        }
294

295
        if (!lib)
×
296
        {
297
            auto lib_path = std::accumulate(
×
298
                std::next(m_state.m_libenv.begin()),
×
299
                m_state.m_libenv.end(),
×
300
                m_state.m_libenv[0].string(),
×
301
                [](const std::string& a, const fs::path& b) -> std::string {
×
302
                    return a + "\n\t- " + b.string();
×
303
                });
×
304
            throwVMError(
×
305
                ErrorKind::Module,
306
                fmt::format("Could not find module '{}'. Searched under\n\t- {}\n\t- {}", file, path, lib_path));
×
307
        }
×
308

309
        m_shared_lib_objects.emplace_back(lib);
×
310

311
        // load the mapping from the dynamic library
312
        try
313
        {
314
            const mapping* map = m_shared_lib_objects.back()->get<mapping* (*)()>("getFunctionsMapping")();
×
315
            // load the mapping data
316
            std::size_t i = 0;
×
317
            while (map[i].name != nullptr)
×
318
            {
319
                // put it in the global frame, aka the first one
320
                auto it = std::ranges::find(m_state.m_symbols, std::string(map[i].name));
×
321
                if (it != m_state.m_symbols.end())
×
322
                    context.locals[0].push_back(static_cast<uint16_t>(std::distance(m_state.m_symbols.begin(), it)), Value(map[i].value));
×
323

324
                ++i;
×
325
            }
×
326
        }
×
327
        catch (const std::system_error& e)
328
        {
329
            throwVMError(
×
330
                ErrorKind::Module,
331
                fmt::format(
×
332
                    "An error occurred while loading module '{}': {}\nIt is most likely because the versions of the module and the language don't match.",
×
333
                    file, e.what()));
×
334
        }
×
335
    }
×
336

337
    void VM::exit(const int code) noexcept
×
338
    {
×
339
        m_exit_code = code;
×
340
        m_running = false;
×
341
    }
×
342

343
    ExecutionContext* VM::createAndGetContext()
6✔
344
    {
6✔
345
        const std::lock_guard lock(m_mutex);
6✔
346

347
        m_execution_contexts.push_back(std::make_unique<ExecutionContext>());
6✔
348
        ExecutionContext* ctx = m_execution_contexts.back().get();
6✔
349
        ctx->stacked_closure_scopes.emplace_back(nullptr);
6✔
350

351
        ctx->locals.reserve(m_execution_contexts.front()->locals.size());
6✔
352
        ctx->scopes_storage = m_execution_contexts.front()->scopes_storage;
6✔
353
        for (const auto& local : m_execution_contexts.front()->locals)
20✔
354
        {
355
            auto& scope = ctx->locals.emplace_back(ctx->scopes_storage.data(), local.m_start);
14✔
356
            scope.m_size = local.m_size;
14✔
357
            scope.m_min_id = local.m_min_id;
14✔
358
            scope.m_max_id = local.m_max_id;
14✔
359
        }
14✔
360

361
        return ctx;
6✔
362
    }
6✔
363

364
    void VM::deleteContext(ExecutionContext* ec)
5✔
365
    {
5✔
366
        const std::lock_guard lock(m_mutex);
5✔
367

368
        const auto it =
5✔
369
            std::ranges::remove_if(
10✔
370
                m_execution_contexts,
5✔
371
                [ec](const std::unique_ptr<ExecutionContext>& ctx) {
21✔
372
                    return ctx.get() == ec;
16✔
373
                })
374
                .begin();
5✔
375
        m_execution_contexts.erase(it);
5✔
376
    }
5✔
377

378
    Future* VM::createFuture(std::vector<Value>& args)
6✔
379
    {
6✔
380
        ExecutionContext* ctx = createAndGetContext();
6✔
381
        // so that we have access to the presumed symbol id of the function we are calling
382
        // assuming that the callee is always the global context
383
        ctx->last_symbol = m_execution_contexts.front()->last_symbol;
6✔
384

385
        // doing this after having created the context
386
        // because the context uses the mutex and we don't want a deadlock
387
        const std::lock_guard lock(m_mutex);
6✔
388
        m_futures.push_back(std::make_unique<Future>(ctx, this, args));
6✔
389

390
        return m_futures.back().get();
6✔
391
    }
6✔
392

1✔
UNCOV
393
    void VM::deleteFuture(Future* f)
×
394
    {
1✔
UNCOV
395
        const std::lock_guard lock(m_mutex);
×
396

1✔
397
        const auto it =
×
398
            std::ranges::remove_if(
×
399
                m_futures,
×
400
                [f](const std::unique_ptr<Future>& future) {
×
401
                    return future.get() == f;
×
402
                })
403
                .begin();
×
404
        m_futures.erase(it);
×
405
    }
×
406

407
    bool VM::forceReloadPlugins() const
×
408
    {
×
409
        // load the mapping from the dynamic library
410
        try
411
        {
412
            for (const auto& shared_lib : m_shared_lib_objects)
×
413
            {
414
                const mapping* map = shared_lib->template get<mapping* (*)()>("getFunctionsMapping")();
×
415
                // load the mapping data
416
                std::size_t i = 0;
×
417
                while (map[i].name != nullptr)
×
418
                {
419
                    // put it in the global frame, aka the first one
420
                    auto it = std::ranges::find(m_state.m_symbols, std::string(map[i].name));
×
421
                    if (it != m_state.m_symbols.end())
×
422
                        m_execution_contexts[0]->locals[0].push_back(
×
423
                            static_cast<uint16_t>(std::distance(m_state.m_symbols.begin(), it)),
×
424
                            Value(map[i].value));
×
425

426
                    ++i;
×
427
                }
×
428
            }
×
429

430
            return true;
×
431
        }
×
432
        catch (const std::system_error&)
433
        {
434
            return false;
×
435
        }
×
436
    }
×
437

438
    void VM::throwVMError(ErrorKind kind, const std::string& message)
32✔
439
    {
32✔
440
        throw std::runtime_error(std::string(errorKinds[static_cast<std::size_t>(kind)]) + ": " + message + "\n");
32✔
441
    }
32✔
442

443
    int VM::run(const bool fail_with_exception)
168✔
444
    {
168✔
445
        init();
168✔
446
        safeRun(*m_execution_contexts[0], 0, fail_with_exception);
168✔
447
        return m_exit_code;
168✔
448
    }
449

450
    int VM::safeRun(ExecutionContext& context, std::size_t untilFrameCount, bool fail_with_exception)
174✔
451
    {
174✔
452
#if ARK_USE_COMPUTED_GOTOS
453
#    define TARGET(op) TARGET_##op:
454
#    define DISPATCH_GOTO()            \
455
        _Pragma("GCC diagnostic push") \
456
            _Pragma("GCC diagnostic ignored \"-Wpedantic\"") goto* opcode_targets[inst];
457
        _Pragma("GCC diagnostic pop")
458
#    define GOTO_HALT() goto dispatch_end
459
#else
460
#    define TARGET(op) case op:
461
#    define DISPATCH_GOTO() goto dispatch_opcode
462
#    define GOTO_HALT() break
463
#endif
464

465
#define NEXTOPARG()                                                                      \
466
    do                                                                                   \
467
    {                                                                                    \
468
        inst = m_state.m_pages[context.pp][context.ip];                                  \
469
        padding = m_state.m_pages[context.pp][context.ip + 1];                           \
470
        arg = static_cast<uint16_t>((m_state.m_pages[context.pp][context.ip + 2] << 8) + \
471
                                    m_state.m_pages[context.pp][context.ip + 3]);        \
472
        context.ip += 4;                                                                 \
473
    } while (false)
474
#define DISPATCH() \
475
    NEXTOPARG();   \
476
    DISPATCH_GOTO();
477
#define UNPACK_ARGS()                                                                 \
478
    do                                                                                \
479
    {                                                                                 \
480
        secondary_arg = static_cast<uint16_t>((padding << 4) | (arg & 0xf000) >> 12); \
481
        primary_arg = arg & 0x0fff;                                                   \
482
    } while (false)
483

484
#if ARK_USE_COMPUTED_GOTOS
485
#    pragma GCC diagnostic push
486
#    pragma GCC diagnostic ignored "-Wpedantic"
487
            constexpr std::array opcode_targets = {
174✔
488
                // cppcheck-suppress syntaxError ; cppcheck do not know about labels addresses (GCC extension)
489
                &&TARGET_NOP,
490
                &&TARGET_LOAD_SYMBOL,
491
                &&TARGET_LOAD_SYMBOL_BY_INDEX,
492
                &&TARGET_LOAD_CONST,
493
                &&TARGET_POP_JUMP_IF_TRUE,
494
                &&TARGET_STORE,
495
                &&TARGET_SET_VAL,
496
                &&TARGET_POP_JUMP_IF_FALSE,
497
                &&TARGET_JUMP,
498
                &&TARGET_RET,
499
                &&TARGET_HALT,
500
                &&TARGET_PUSH_RETURN_ADDRESS,
501
                &&TARGET_CALL,
502
                &&TARGET_CAPTURE,
503
                &&TARGET_BUILTIN,
504
                &&TARGET_DEL,
505
                &&TARGET_MAKE_CLOSURE,
506
                &&TARGET_GET_FIELD,
507
                &&TARGET_PLUGIN,
508
                &&TARGET_LIST,
509
                &&TARGET_APPEND,
510
                &&TARGET_CONCAT,
511
                &&TARGET_APPEND_IN_PLACE,
512
                &&TARGET_CONCAT_IN_PLACE,
513
                &&TARGET_POP_LIST,
514
                &&TARGET_POP_LIST_IN_PLACE,
515
                &&TARGET_SET_AT_INDEX,
516
                &&TARGET_SET_AT_2_INDEX,
517
                &&TARGET_POP,
518
                &&TARGET_SHORTCIRCUIT_AND,
519
                &&TARGET_SHORTCIRCUIT_OR,
520
                &&TARGET_CREATE_SCOPE,
521
                &&TARGET_RESET_SCOPE_JUMP,
522
                &&TARGET_POP_SCOPE,
523
                &&TARGET_ADD,
524
                &&TARGET_SUB,
525
                &&TARGET_MUL,
526
                &&TARGET_DIV,
527
                &&TARGET_GT,
528
                &&TARGET_LT,
529
                &&TARGET_LE,
530
                &&TARGET_GE,
531
                &&TARGET_NEQ,
532
                &&TARGET_EQ,
533
                &&TARGET_LEN,
534
                &&TARGET_EMPTY,
535
                &&TARGET_TAIL,
536
                &&TARGET_HEAD,
537
                &&TARGET_ISNIL,
538
                &&TARGET_ASSERT,
539
                &&TARGET_TO_NUM,
540
                &&TARGET_TO_STR,
541
                &&TARGET_AT,
542
                &&TARGET_AT_AT,
543
                &&TARGET_MOD,
544
                &&TARGET_TYPE,
545
                &&TARGET_HASFIELD,
546
                &&TARGET_NOT,
547
                &&TARGET_LOAD_CONST_LOAD_CONST,
548
                &&TARGET_LOAD_CONST_STORE,
549
                &&TARGET_LOAD_CONST_SET_VAL,
550
                &&TARGET_STORE_FROM,
551
                &&TARGET_STORE_FROM_INDEX,
552
                &&TARGET_SET_VAL_FROM,
553
                &&TARGET_SET_VAL_FROM_INDEX,
554
                &&TARGET_INCREMENT,
555
                &&TARGET_INCREMENT_BY_INDEX,
556
                &&TARGET_INCREMENT_STORE,
557
                &&TARGET_DECREMENT,
558
                &&TARGET_DECREMENT_BY_INDEX,
559
                &&TARGET_DECREMENT_STORE,
560
                &&TARGET_STORE_TAIL,
561
                &&TARGET_STORE_TAIL_BY_INDEX,
562
                &&TARGET_STORE_HEAD,
563
                &&TARGET_STORE_HEAD_BY_INDEX,
564
                &&TARGET_STORE_LIST,
565
                &&TARGET_SET_VAL_TAIL,
566
                &&TARGET_SET_VAL_TAIL_BY_INDEX,
567
                &&TARGET_SET_VAL_HEAD,
568
                &&TARGET_SET_VAL_HEAD_BY_INDEX,
569
                &&TARGET_CALL_BUILTIN,
570
                &&TARGET_CALL_BUILTIN_WITHOUT_RETURN_ADDRESS,
571
                &&TARGET_LT_CONST_JUMP_IF_FALSE,
572
                &&TARGET_LT_CONST_JUMP_IF_TRUE,
573
                &&TARGET_LT_SYM_JUMP_IF_FALSE,
574
                &&TARGET_GT_CONST_JUMP_IF_TRUE,
575
                &&TARGET_GT_CONST_JUMP_IF_FALSE,
576
                &&TARGET_GT_SYM_JUMP_IF_FALSE,
577
                &&TARGET_EQ_CONST_JUMP_IF_TRUE,
578
                &&TARGET_EQ_SYM_INDEX_JUMP_IF_TRUE,
579
                &&TARGET_NEQ_CONST_JUMP_IF_TRUE,
580
                &&TARGET_NEQ_SYM_JUMP_IF_FALSE,
581
                &&TARGET_CALL_SYMBOL,
582
                &&TARGET_GET_FIELD_FROM_SYMBOL,
583
                &&TARGET_GET_FIELD_FROM_SYMBOL_INDEX,
584
                &&TARGET_AT_SYM_SYM,
585
                &&TARGET_AT_SYM_INDEX_SYM_INDEX,
586
                &&TARGET_CHECK_TYPE_OF,
587
                &&TARGET_CHECK_TYPE_OF_BY_INDEX,
588
                &&TARGET_APPEND_IN_PLACE_SYM,
589
                &&TARGET_APPEND_IN_PLACE_SYM_INDEX
590
            };
591

592
        static_assert(opcode_targets.size() == static_cast<std::size_t>(Instruction::InstructionsCount) && "Some instructions are not implemented in the VM");
593
#    pragma GCC diagnostic pop
594
#endif
595

596
        try
597
        {
598
            uint8_t inst = 0;
174✔
599
            uint8_t padding = 0;
174✔
600
            uint16_t arg = 0;
174✔
601
            uint16_t primary_arg = 0;
174✔
602
            uint16_t secondary_arg = 0;
174✔
603

604
            m_running = true;
174✔
605

606
            DISPATCH();
174✔
607
            // cppcheck-suppress unreachableCode ; analysis cannot follow the chain of goto... but it works!
608
            {
609
#if !ARK_USE_COMPUTED_GOTOS
610
            dispatch_opcode:
611
                switch (inst)
612
#endif
UNCOV
613
                {
×
614
#pragma region "Instructions"
615
                    TARGET(NOP)
616
                    {
UNCOV
617
                        DISPATCH();
×
618
                    }
144,949✔
619

620
                    TARGET(LOAD_SYMBOL)
621
                    {
622
                        push(loadSymbol(arg, context), context);
144,949✔
623
                        DISPATCH();
144,949✔
624
                    }
333,182✔
625

626
                    TARGET(LOAD_SYMBOL_BY_INDEX)
627
                    {
628
                        push(loadSymbolFromIndex(arg, context), context);
333,182✔
629
                        DISPATCH();
333,182✔
630
                    }
115,769✔
631

632
                    TARGET(LOAD_CONST)
633
                    {
634
                        push(loadConstAsPtr(arg), context);
115,769✔
635
                        DISPATCH();
115,769✔
636
                    }
28,240✔
637

638
                    TARGET(POP_JUMP_IF_TRUE)
639
                    {
640
                        if (Value boolean = *popAndResolveAsPtr(context); !!boolean)
35,096✔
641
                            context.ip = arg * 4;  // instructions are 4 bytes
6,856✔
642
                        DISPATCH();
28,240✔
643
                    }
400,538✔
644

645
                    TARGET(STORE)
646
                    {
647
                        store(arg, popAndResolveAsPtr(context), context);
400,538✔
648
                        DISPATCH();
400,538✔
649
                    }
22,429✔
650

651
                    TARGET(SET_VAL)
652
                    {
653
                        setVal(arg, popAndResolveAsPtr(context), context);
22,429✔
654
                        DISPATCH();
22,429✔
655
                    }
27,189✔
656

657
                    TARGET(POP_JUMP_IF_FALSE)
658
                    {
659
                        if (Value boolean = *popAndResolveAsPtr(context); !boolean)
29,184✔
660
                            context.ip = arg * 4;  // instructions are 4 bytes
1,995✔
661
                        DISPATCH();
27,189✔
662
                    }
206,550✔
663

664
                    TARGET(JUMP)
665
                    {
666
                        context.ip = arg * 4;  // instructions are 4 bytes
206,550✔
667
                        DISPATCH();
206,550✔
668
                    }
135,935✔
669

670
                    TARGET(RET)
671
                    {
672
                        {
673
                            Value ip_or_val = *popAndResolveAsPtr(context);
135,935✔
674
                            // no return value on the stack
675
                            if (ip_or_val.valueType() == ValueType::InstPtr) [[unlikely]]
135,935✔
676
                            {
677
                                context.ip = ip_or_val.pageAddr();
2,602✔
678
                                // we always push PP then IP, thus the next value
679
                                // MUST be the page pointer
680
                                context.pp = pop(context)->pageAddr();
2,602✔
681

682
                                returnFromFuncCall(context);
2,602✔
683
                                push(Builtins::nil, context);
2,602✔
684
                            }
2,602✔
685
                            // value on the stack
686
                            else [[likely]]
687
                            {
688
                                const Value* ip = popAndResolveAsPtr(context);
133,333✔
689
                                assert(ip->valueType() == ValueType::InstPtr && "Expected instruction pointer on the stack (is the stack trashed?)");
133,333✔
690
                                context.ip = ip->pageAddr();
133,333✔
691
                                context.pp = pop(context)->pageAddr();
133,333✔
692

693
                                returnFromFuncCall(context);
133,333✔
694
                                push(std::move(ip_or_val), context);
133,333✔
695
                            }
696

697
                            if (context.fc <= untilFrameCount)
135,935✔
698
                                GOTO_HALT();
6✔
699
                        }
135,935✔
700

701
                        DISPATCH();
135,929✔
702
                    }
58✔
703

704
                    TARGET(HALT)
705
                    {
706
                        m_running = false;
58✔
707
                        GOTO_HALT();
58✔
708
                    }
138,766✔
709

710
                    TARGET(PUSH_RETURN_ADDRESS)
711
                    {
712
                        push(Value(static_cast<PageAddr_t>(context.pp)), context);
138,766✔
713
                        // arg * 4 to skip over the call instruction, so that the return address points to AFTER the call
714
                        push(Value(ValueType::InstPtr, static_cast<PageAddr_t>(arg * 4)), context);
138,766✔
715
                        DISPATCH();
138,766✔
716
                    }
2,428✔
717

718
                    TARGET(CALL)
719
                    {
720
                        call(context, arg);
2,428✔
721
                        if (!m_running)
2,421✔
UNCOV
722
                            GOTO_HALT();
×
723
                        DISPATCH();
2,421✔
724
                    }
3,079✔
725

726
                    TARGET(CAPTURE)
727
                    {
728
                        if (!context.saved_scope)
3,079✔
729
                            context.saved_scope = ClosureScope();
616✔
730

731
                        const Value* ptr = findNearestVariable(arg, context);
3,079✔
732
                        if (!ptr)
3,079✔
UNCOV
733
                            throwVMError(ErrorKind::Scope, fmt::format("Couldn't capture `{}' as it is currently unbound", m_state.m_symbols[arg]));
×
734
                        else
735
                        {
736
                            ptr = ptr->valueType() == ValueType::Reference ? ptr->reference() : ptr;
3,079✔
737
                            context.saved_scope.value().push_back(arg, *ptr);
3,079✔
738
                        }
739

740
                        DISPATCH();
3,079✔
741
                    }
1,368✔
742

743
                    TARGET(BUILTIN)
744
                    {
745
                        push(Builtins::builtins[arg].second, context);
1,368✔
746
                        DISPATCH();
1,368✔
747
                    }
1✔
748

749
                    TARGET(DEL)
750
                    {
751
                        if (Value* var = findNearestVariable(arg, context); var != nullptr)
1✔
752
                        {
753
                            if (var->valueType() == ValueType::User)
×
754
                                var->usertypeRef().del();
×
755
                            *var = Value();
×
UNCOV
756
                            DISPATCH();
×
757
                        }
758

759
                        throwVMError(ErrorKind::Scope, fmt::format("Can not delete unbound variable `{}'", m_state.m_symbols[arg]));
1✔
760
                    }
616✔
761

762
                    TARGET(MAKE_CLOSURE)
763
                    {
764
                        push(Value(Closure(context.saved_scope.value(), m_state.m_constants[arg].pageAddr())), context);
616✔
765
                        context.saved_scope.reset();
616✔
766
                        DISPATCH();
616✔
767
                    }
6✔
768

769
                    TARGET(GET_FIELD)
770
                    {
771
                        Value* var = popAndResolveAsPtr(context);
6✔
772
                        push(getField(var, arg, context), context);
6✔
773
                        DISPATCH();
6✔
UNCOV
774
                    }
×
775

776
                    TARGET(PLUGIN)
777
                    {
778
                        loadPlugin(arg, context);
×
UNCOV
779
                        DISPATCH();
×
780
                    }
596✔
781

782
                    TARGET(LIST)
783
                    {
784
                        {
785
                            Value l = createList(arg, context);
596✔
786
                            push(std::move(l), context);
596✔
787
                        }
596✔
788
                        DISPATCH();
596✔
789
                    }
1,536✔
790

791
                    TARGET(APPEND)
792
                    {
793
                        {
794
                            Value* list = popAndResolveAsPtr(context);
1,536✔
795
                            if (list->valueType() != ValueType::List)
1,536✔
796
                            {
797
                                std::vector<Value> args = { *list };
1✔
798
                                for (uint16_t i = 0; i < arg; ++i)
2✔
799
                                    args.push_back(*popAndResolveAsPtr(context));
1✔
800
                                throw types::TypeCheckingError(
2✔
801
                                    "append",
1✔
802
                                    { { types::Contract { { types::Typedef("list", ValueType::List), types::Typedef("value", ValueType::Any, /* variadic= */ true) } } } },
1✔
803
                                    args);
804
                            }
1✔
805

806
                            const auto size = static_cast<uint16_t>(list->constList().size());
1,535✔
807

808
                            Value obj { *list };
1,535✔
809
                            obj.list().reserve(size + arg);
1,535✔
810

811
                            for (uint16_t i = 0; i < arg; ++i)
3,070✔
812
                                obj.push_back(*popAndResolveAsPtr(context));
1,535✔
813
                            push(std::move(obj), context);
1,535✔
814
                        }
1,535✔
815
                        DISPATCH();
1,535✔
816
                    }
12✔
817

818
                    TARGET(CONCAT)
819
                    {
820
                        {
821
                            Value* list = popAndResolveAsPtr(context);
12✔
822
                            Value obj { *list };
12✔
823

824
                            for (uint16_t i = 0; i < arg; ++i)
24✔
825
                            {
826
                                Value* next = popAndResolveAsPtr(context);
14✔
827

828
                                if (list->valueType() != ValueType::List || next->valueType() != ValueType::List)
14✔
829
                                    throw types::TypeCheckingError(
4✔
830
                                        "concat",
2✔
831
                                        { { types::Contract { { types::Typedef("dst", ValueType::List), types::Typedef("src", ValueType::List) } } } },
2✔
832
                                        { *list, *next });
2✔
833

834
                                std::ranges::copy(next->list(), std::back_inserter(obj.list()));
12✔
835
                            }
12✔
836
                            push(std::move(obj), context);
10✔
837
                        }
12✔
838
                        DISPATCH();
10✔
UNCOV
839
                    }
×
840

841
                    TARGET(APPEND_IN_PLACE)
842
                    {
843
                        Value* list = popAndResolveAsPtr(context);
×
844
                        listAppendInPlace(list, arg, context);
×
UNCOV
845
                        DISPATCH();
×
846
                    }
562✔
847

848
                    TARGET(CONCAT_IN_PLACE)
849
                    {
850
                        Value* list = popAndResolveAsPtr(context);
562✔
851

852
                        for (uint16_t i = 0; i < arg; ++i)
1,152✔
853
                        {
854
                            Value* next = popAndResolveAsPtr(context);
592✔
855

856
                            if (list->valueType() != ValueType::List || next->valueType() != ValueType::List)
592✔
857
                                throw types::TypeCheckingError(
4✔
858
                                    "concat!",
2✔
859
                                    { { types::Contract { { types::Typedef("dst", ValueType::List), types::Typedef("src", ValueType::List) } } } },
2✔
860
                                    { *list, *next });
2✔
861

862
                            std::ranges::copy(next->list(), std::back_inserter(list->list()));
590✔
863
                        }
590✔
864
                        DISPATCH();
560✔
865
                    }
6✔
866

867
                    TARGET(POP_LIST)
868
                    {
869
                        {
870
                            Value list = *popAndResolveAsPtr(context);
6✔
871
                            Value number = *popAndResolveAsPtr(context);
6✔
872

873
                            if (list.valueType() != ValueType::List || number.valueType() != ValueType::Number)
6✔
874
                                throw types::TypeCheckingError(
2✔
875
                                    "pop",
1✔
876
                                    { { types::Contract { { types::Typedef("list", ValueType::List), types::Typedef("index", ValueType::Number) } } } },
1✔
877
                                    { list, number });
1✔
878

879
                            long idx = static_cast<long>(number.number());
5✔
880
                            idx = idx < 0 ? static_cast<long>(list.list().size()) + idx : idx;
5✔
881
                            if (std::cmp_greater_equal(idx, list.list().size()) || idx < 0)
5✔
882
                                throwVMError(
2✔
883
                                    ErrorKind::Index,
884
                                    fmt::format("pop index ({}) out of range (list size: {})", idx, list.list().size()));
2✔
885

886
                            list.list().erase(list.list().begin() + idx);
3✔
887
                            push(list, context);
3✔
888
                        }
6✔
889
                        DISPATCH();
3✔
890
                    }
61✔
891

892
                    TARGET(POP_LIST_IN_PLACE)
893
                    {
894
                        {
895
                            Value* list = popAndResolveAsPtr(context);
61✔
896
                            Value number = *popAndResolveAsPtr(context);
61✔
897

898
                            if (list->valueType() != ValueType::List || number.valueType() != ValueType::Number)
61✔
899
                                throw types::TypeCheckingError(
2✔
900
                                    "pop!",
1✔
901
                                    { { types::Contract { { types::Typedef("list", ValueType::List), types::Typedef("index", ValueType::Number) } } } },
1✔
902
                                    { *list, number });
1✔
903

904
                            long idx = static_cast<long>(number.number());
60✔
905
                            idx = idx < 0 ? static_cast<long>(list->list().size()) + idx : idx;
60✔
906
                            if (std::cmp_greater_equal(idx, list->list().size()) || idx < 0)
60✔
907
                                throwVMError(
2✔
908
                                    ErrorKind::Index,
909
                                    fmt::format("pop! index ({}) out of range (list size: {})", idx, list->list().size()));
2✔
910

911
                            list->list().erase(list->list().begin() + idx);
58✔
912
                        }
61✔
913
                        DISPATCH();
58✔
914
                    }
490✔
915

916
                    TARGET(SET_AT_INDEX)
917
                    {
918
                        {
919
                            Value* list = popAndResolveAsPtr(context);
490✔
920
                            Value number = *popAndResolveAsPtr(context);
490✔
921
                            Value new_value = *popAndResolveAsPtr(context);
490✔
922

923
                            if (!list->isIndexable() || number.valueType() != ValueType::Number || (list->valueType() == ValueType::String && new_value.valueType() != ValueType::String))
490✔
924
                                throw types::TypeCheckingError(
2✔
925
                                    "@=",
1✔
926
                                    { { types::Contract {
3✔
927
                                          { types::Typedef("list", ValueType::List),
3✔
928
                                            types::Typedef("index", ValueType::Number),
1✔
929
                                            types::Typedef("new_value", ValueType::Any) } } },
1✔
930
                                      { types::Contract {
1✔
931
                                          { types::Typedef("string", ValueType::String),
3✔
932
                                            types::Typedef("index", ValueType::Number),
1✔
933
                                            types::Typedef("char", ValueType::String) } } } },
1✔
934
                                    { *list, number, new_value });
1✔
935

936
                            const std::size_t size = list->valueType() == ValueType::List ? list->list().size() : list->stringRef().size();
489✔
937
                            long idx = static_cast<long>(number.number());
489✔
938
                            idx = idx < 0 ? static_cast<long>(size) + idx : idx;
489✔
939
                            if (std::cmp_greater_equal(idx, size) || idx < 0)
489✔
940
                                throwVMError(
2✔
941
                                    ErrorKind::Index,
942
                                    fmt::format("@= index ({}) out of range (indexable size: {})", idx, size));
2✔
943

944
                            if (list->valueType() == ValueType::List)
487✔
945
                                list->list()[static_cast<std::size_t>(idx)] = new_value;
485✔
946
                            else
947
                                list->stringRef()[static_cast<std::size_t>(idx)] = new_value.string()[0];
2✔
948
                        }
490✔
949
                        DISPATCH();
487✔
950
                    }
12✔
951

952
                    TARGET(SET_AT_2_INDEX)
953
                    {
954
                        {
955
                            Value* list = popAndResolveAsPtr(context);
12✔
956
                            Value x = *popAndResolveAsPtr(context);
12✔
957
                            Value y = *popAndResolveAsPtr(context);
12✔
958
                            Value new_value = *popAndResolveAsPtr(context);
12✔
959

960
                            if (list->valueType() != ValueType::List || x.valueType() != ValueType::Number || y.valueType() != ValueType::Number)
12✔
961
                                throw types::TypeCheckingError(
2✔
962
                                    "@@=",
1✔
963
                                    { { types::Contract {
2✔
964
                                        { types::Typedef("list", ValueType::List),
4✔
965
                                          types::Typedef("x", ValueType::Number),
1✔
966
                                          types::Typedef("y", ValueType::Number),
1✔
967
                                          types::Typedef("new_value", ValueType::Any) } } } },
1✔
968
                                    { *list, x, y, new_value });
1✔
969

970
                            long idx_y = static_cast<long>(x.number());
11✔
971
                            idx_y = idx_y < 0 ? static_cast<long>(list->list().size()) + idx_y : idx_y;
11✔
972
                            if (std::cmp_greater_equal(idx_y, list->list().size()) || idx_y < 0)
11✔
973
                                throwVMError(
2✔
974
                                    ErrorKind::Index,
975
                                    fmt::format("@@= index (y: {}) out of range (list size: {})", idx_y, list->list().size()));
2✔
976

977
                            if (!list->list()[static_cast<std::size_t>(idx_y)].isIndexable() ||
13✔
978
                                (list->list()[static_cast<std::size_t>(idx_y)].valueType() == ValueType::String && new_value.valueType() != ValueType::String))
8✔
979
                                throw types::TypeCheckingError(
2✔
980
                                    "@@=",
1✔
981
                                    { { types::Contract {
3✔
982
                                          { types::Typedef("list", ValueType::List),
4✔
983
                                            types::Typedef("x", ValueType::Number),
1✔
984
                                            types::Typedef("y", ValueType::Number),
1✔
985
                                            types::Typedef("new_value", ValueType::Any) } } },
1✔
986
                                      { types::Contract {
1✔
987
                                          { types::Typedef("string", ValueType::String),
4✔
988
                                            types::Typedef("x", ValueType::Number),
1✔
989
                                            types::Typedef("y", ValueType::Number),
1✔
990
                                            types::Typedef("char", ValueType::String) } } } },
1✔
991
                                    { *list, x, y, new_value });
1✔
992

993
                            const bool is_list = list->list()[static_cast<std::size_t>(idx_y)].valueType() == ValueType::List;
8✔
994
                            const std::size_t size =
8✔
995
                                is_list
16✔
996
                                ? list->list()[static_cast<std::size_t>(idx_y)].list().size()
6✔
997
                                : list->list()[static_cast<std::size_t>(idx_y)].stringRef().size();
2✔
998

999
                            long idx_x = static_cast<long>(y.number());
8✔
1000
                            idx_x = idx_x < 0 ? static_cast<long>(size) + idx_x : idx_x;
8✔
1001
                            if (std::cmp_greater_equal(idx_x, size) || idx_x < 0)
8✔
1002
                                throwVMError(
2✔
1003
                                    ErrorKind::Index,
1004
                                    fmt::format("@@= index (x: {}) out of range (inner indexable size: {})", idx_x, size));
2✔
1005

1006
                            if (is_list)
6✔
1007
                                list->list()[static_cast<std::size_t>(idx_y)].list()[static_cast<std::size_t>(idx_x)] = new_value;
4✔
1008
                            else
1009
                                list->list()[static_cast<std::size_t>(idx_y)].stringRef()[static_cast<std::size_t>(idx_x)] = new_value.string()[0];
2✔
1010
                        }
12✔
1011
                        DISPATCH();
6✔
1012
                    }
2,411✔
1013

1014
                    TARGET(POP)
1015
                    {
1016
                        pop(context);
2,411✔
1017
                        DISPATCH();
2,411✔
1018
                    }
23,269✔
1019

1020
                    TARGET(SHORTCIRCUIT_AND)
1021
                    {
1022
                        if (!*peekAndResolveAsPtr(context))
23,269✔
1023
                            context.ip = arg * 4;
695✔
1024
                        else
1025
                            pop(context);
22,574✔
1026
                        DISPATCH();
23,269✔
1027
                    }
640✔
1028

1029
                    TARGET(SHORTCIRCUIT_OR)
1030
                    {
1031
                        if (!!*peekAndResolveAsPtr(context))
640✔
1032
                            context.ip = arg * 4;
178✔
1033
                        else
1034
                            pop(context);
462✔
1035
                        DISPATCH();
640✔
1036
                    }
2,645✔
1037

1038
                    TARGET(CREATE_SCOPE)
1039
                    {
1040
                        context.locals.emplace_back(context.scopes_storage.data(), context.locals.back().storageEnd());
2,645✔
1041
                        DISPATCH();
2,645✔
1042
                    }
30,897✔
1043

1044
                    TARGET(RESET_SCOPE_JUMP)
1045
                    {
1046
                        context.locals.back().reset();
30,897✔
1047
                        context.ip = arg * 4;  // instructions are 4 bytes
30,897✔
1048
                        DISPATCH();
30,897✔
1049
                    }
2,645✔
1050

1051
                    TARGET(POP_SCOPE)
1052
                    {
1053
                        context.locals.pop_back();
2,645✔
1054
                        DISPATCH();
2,645✔
1055
                    }
26,762✔
1056

1057
#pragma endregion
1058

1059
#pragma region "Operators"
1060

1061
                    TARGET(ADD)
1062
                    {
1063
                        Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
26,762✔
1064

1065
                        if (a->valueType() == ValueType::Number && b->valueType() == ValueType::Number)
26,762✔
1066
                            push(Value(a->number() + b->number()), context);
19,317✔
1067
                        else if (a->valueType() == ValueType::String && b->valueType() == ValueType::String)
7,445✔
1068
                            push(Value(a->string() + b->string()), context);
7,444✔
1069
                        else
1070
                            throw types::TypeCheckingError(
2✔
1071
                                "+",
1✔
1072
                                { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } },
2✔
1073
                                    types::Contract { { types::Typedef("a", ValueType::String), types::Typedef("b", ValueType::String) } } } },
1✔
1074
                                { *a, *b });
1✔
1075
                        DISPATCH();
26,761✔
1076
                    }
220✔
1077

1078
                    TARGET(SUB)
1079
                    {
1080
                        Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
220✔
1081

1082
                        if (a->valueType() != ValueType::Number || b->valueType() != ValueType::Number)
220✔
1083
                            throw types::TypeCheckingError(
2✔
1084
                                "-",
1✔
1085
                                { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
1✔
1086
                                { *a, *b });
1✔
1087
                        push(Value(a->number() - b->number()), context);
219✔
1088
                        DISPATCH();
219✔
1089
                    }
2,206✔
1090

1091
                    TARGET(MUL)
1092
                    {
1093
                        Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
2,206✔
1094

1095
                        if (a->valueType() != ValueType::Number || b->valueType() != ValueType::Number)
2,206✔
1096
                            throw types::TypeCheckingError(
2✔
1097
                                "*",
1✔
1098
                                { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
1✔
1099
                                { *a, *b });
1✔
1100
                        push(Value(a->number() * b->number()), context);
2,205✔
1101
                        DISPATCH();
2,205✔
1102
                    }
1,060✔
1103

1104
                    TARGET(DIV)
1105
                    {
1106
                        Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
1,060✔
1107

1108
                        if (a->valueType() != ValueType::Number || b->valueType() != ValueType::Number)
1,060✔
1109
                            throw types::TypeCheckingError(
2✔
1110
                                "/",
1✔
1111
                                { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
1✔
1112
                                { *a, *b });
1✔
1113
                        auto d = b->number();
1,059✔
1114
                        if (d == 0)
1,059✔
1115
                            throwVMError(ErrorKind::DivisionByZero, fmt::format("Can not compute expression (/ {} {})", a->toString(*this), b->toString(*this)));
1✔
1116

1117
                        push(Value(a->number() / d), context);
1,058✔
1118
                        DISPATCH();
1,058✔
1119
                    }
148✔
1120

1121
                    TARGET(GT)
1122
                    {
1123
                        const Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
148✔
1124
                        push(*b < *a ? Builtins::trueSym : Builtins::falseSym, context);
148✔
1125
                        DISPATCH();
148✔
1126
                    }
28,550✔
1127

1128
                    TARGET(LT)
1129
                    {
1130
                        const Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
28,550✔
1131
                        push(*a < *b ? Builtins::trueSym : Builtins::falseSym, context);
28,550✔
1132
                        DISPATCH();
28,550✔
1133
                    }
7,187✔
1134

1135
                    TARGET(LE)
1136
                    {
1137
                        const Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
7,187✔
1138
                        push((((*a < *b) || (*a == *b)) ? Builtins::trueSym : Builtins::falseSym), context);
7,187✔
1139
                        DISPATCH();
7,187✔
1140
                    }
5,730✔
1141

1142
                    TARGET(GE)
1143
                    {
1144
                        const Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
5,730✔
1145
                        push(!(*a < *b) ? Builtins::trueSym : Builtins::falseSym, context);
5,730✔
1146
                        DISPATCH();
5,730✔
1147
                    }
735✔
1148

1149
                    TARGET(NEQ)
1150
                    {
1151
                        const Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
735✔
1152
                        push(*a != *b ? Builtins::trueSym : Builtins::falseSym, context);
735✔
1153
                        DISPATCH();
735✔
1154
                    }
17,220✔
1155

1156
                    TARGET(EQ)
1157
                    {
1158
                        const Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
17,220✔
1159
                        push(*a == *b ? Builtins::trueSym : Builtins::falseSym, context);
17,220✔
1160
                        DISPATCH();
17,220✔
1161
                    }
12,080✔
1162

1163
                    TARGET(LEN)
1164
                    {
1165
                        const Value* a = popAndResolveAsPtr(context);
12,080✔
1166

1167
                        if (a->valueType() == ValueType::List)
12,080✔
1168
                            push(Value(static_cast<int>(a->constList().size())), context);
4,454✔
1169
                        else if (a->valueType() == ValueType::String)
7,626✔
1170
                            push(Value(static_cast<int>(a->string().size())), context);
7,625✔
1171
                        else
1172
                            throw types::TypeCheckingError(
2✔
1173
                                "len",
1✔
1174
                                { { types::Contract { { types::Typedef("value", ValueType::List) } },
2✔
1175
                                    types::Contract { { types::Typedef("value", ValueType::String) } } } },
1✔
1176
                                { *a });
1✔
1177
                        DISPATCH();
12,079✔
1178
                    }
540✔
1179

1180
                    TARGET(EMPTY)
1181
                    {
1182
                        const Value* a = popAndResolveAsPtr(context);
540✔
1183

1184
                        if (a->valueType() == ValueType::List)
540✔
1185
                            push(a->constList().empty() ? Builtins::trueSym : Builtins::falseSym, context);
86✔
1186
                        else if (a->valueType() == ValueType::String)
454✔
1187
                            push(a->string().empty() ? Builtins::trueSym : Builtins::falseSym, context);
453✔
1188
                        else
1189
                            throw types::TypeCheckingError(
2✔
1190
                                "empty?",
1✔
1191
                                { { types::Contract { { types::Typedef("value", ValueType::List) } },
2✔
1192
                                    types::Contract { { types::Typedef("value", ValueType::String) } } } },
1✔
1193
                                { *a });
1✔
1194
                        DISPATCH();
539✔
1195
                    }
335✔
1196

1197
                    TARGET(TAIL)
1198
                    {
1199
                        Value* const a = popAndResolveAsPtr(context);
335✔
1200
                        push(helper::tail(a), context);
336✔
1201
                        DISPATCH();
334✔
1202
                    }
1,099✔
1203

1204
                    TARGET(HEAD)
1205
                    {
1206
                        Value* const a = popAndResolveAsPtr(context);
1,099✔
1207
                        push(helper::head(a), context);
1,100✔
1208
                        DISPATCH();
1,098✔
1209
                    }
2,299✔
1210

1211
                    TARGET(ISNIL)
1212
                    {
1213
                        const Value* a = popAndResolveAsPtr(context);
2,299✔
1214
                        push((*a == Builtins::nil) ? Builtins::trueSym : Builtins::falseSym, context);
2,299✔
1215
                        DISPATCH();
2,299✔
1216
                    }
594✔
1217

1218
                    TARGET(ASSERT)
1219
                    {
1220
                        Value* const b = popAndResolveAsPtr(context);
594✔
1221
                        Value* const a = popAndResolveAsPtr(context);
594✔
1222

1223
                        if (b->valueType() != ValueType::String)
594✔
1224
                            throw types::TypeCheckingError(
2✔
1225
                                "assert",
1✔
1226
                                { { types::Contract { { types::Typedef("expr", ValueType::Any), types::Typedef("message", ValueType::String) } } } },
1✔
1227
                                { *a, *b });
1✔
1228

1229
                        if (*a == Builtins::falseSym)
593✔
UNCOV
1230
                            throw AssertionFailed(b->stringRef());
×
1231
                        DISPATCH();
593✔
1232
                    }
12✔
1233

1234
                    TARGET(TO_NUM)
1235
                    {
1236
                        const Value* a = popAndResolveAsPtr(context);
12✔
1237

1238
                        if (a->valueType() != ValueType::String)
12✔
1239
                            throw types::TypeCheckingError(
2✔
1240
                                "toNumber",
1✔
1241
                                { { types::Contract { { types::Typedef("value", ValueType::String) } } } },
1✔
1242
                                { *a });
1✔
1243

1244
                        double val;
1245
                        if (Utils::isDouble(a->string(), &val))
11✔
1246
                            push(Value(val), context);
8✔
1247
                        else
1248
                            push(Builtins::nil, context);
3✔
1249
                        DISPATCH();
11✔
1250
                    }
116✔
1251

1252
                    TARGET(TO_STR)
1253
                    {
1254
                        const Value* a = popAndResolveAsPtr(context);
116✔
1255
                        push(Value(a->toString(*this)), context);
116✔
1256
                        DISPATCH();
116✔
1257
                    }
1,041✔
1258

1259
                    TARGET(AT)
1260
                    {
1261
                        Value& b = *popAndResolveAsPtr(context);
1,041✔
1262
                        Value& a = *popAndResolveAsPtr(context);
1,041✔
1263
                        push(helper::at(a, b, *this), context);
1,045✔
1264
                        DISPATCH();
1,037✔
1265
                    }
26✔
1266

1267
                    TARGET(AT_AT)
1268
                    {
1269
                        {
1270
                            const Value* x = popAndResolveAsPtr(context);
26✔
1271
                            const Value* y = popAndResolveAsPtr(context);
26✔
1272
                            Value& list = *popAndResolveAsPtr(context);
26✔
1273

1274
                            if (y->valueType() != ValueType::Number || x->valueType() != ValueType::Number ||
26✔
1275
                                list.valueType() != ValueType::List)
25✔
1276
                                throw types::TypeCheckingError(
2✔
1277
                                    "@@",
1✔
1278
                                    { { types::Contract {
2✔
1279
                                        { types::Typedef("src", ValueType::List),
3✔
1280
                                          types::Typedef("y", ValueType::Number),
1✔
1281
                                          types::Typedef("x", ValueType::Number) } } } },
1✔
1282
                                    { list, *y, *x });
1✔
1283

1284
                            long idx_y = static_cast<long>(y->number());
25✔
1285
                            idx_y = idx_y < 0 ? static_cast<long>(list.list().size()) + idx_y : idx_y;
25✔
1286
                            if (std::cmp_greater_equal(idx_y, list.list().size()) || idx_y < 0)
25✔
1287
                                throwVMError(
2✔
1288
                                    ErrorKind::Index,
1289
                                    fmt::format("@@ index ({}) out of range (list size: {})", idx_y, list.list().size()));
2✔
1290

1291
                            const bool is_list = list.list()[static_cast<std::size_t>(idx_y)].valueType() == ValueType::List;
23✔
1292
                            const std::size_t size =
23✔
1293
                                is_list
46✔
1294
                                ? list.list()[static_cast<std::size_t>(idx_y)].list().size()
16✔
1295
                                : list.list()[static_cast<std::size_t>(idx_y)].stringRef().size();
7✔
1296

1297
                            long idx_x = static_cast<long>(x->number());
23✔
1298
                            idx_x = idx_x < 0 ? static_cast<long>(size) + idx_x : idx_x;
23✔
1299
                            if (std::cmp_greater_equal(idx_x, size) || idx_x < 0)
23✔
1300
                                throwVMError(
2✔
1301
                                    ErrorKind::Index,
1302
                                    fmt::format("@@ index (x: {}) out of range (inner indexable size: {})", idx_x, size));
2✔
1303

1304
                            if (is_list)
21✔
1305
                                push(list.list()[static_cast<std::size_t>(idx_y)].list()[static_cast<std::size_t>(idx_x)], context);
14✔
1306
                            else
1307
                                push(Value(std::string(1, list.list()[static_cast<std::size_t>(idx_y)].stringRef()[static_cast<std::size_t>(idx_x)])), context);
7✔
1308
                        }
1309
                        DISPATCH();
21✔
1310
                    }
16,351✔
1311

1312
                    TARGET(MOD)
1313
                    {
1314
                        const Value *b = popAndResolveAsPtr(context), *a = popAndResolveAsPtr(context);
16,351✔
1315
                        if (a->valueType() != ValueType::Number || b->valueType() != ValueType::Number)
16,351✔
1316
                            throw types::TypeCheckingError(
2✔
1317
                                "mod",
1✔
1318
                                { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
1✔
1319
                                { *a, *b });
1✔
1320
                        push(Value(std::fmod(a->number(), b->number())), context);
16,350✔
1321
                        DISPATCH();
16,350✔
1322
                    }
22✔
1323

1324
                    TARGET(TYPE)
1325
                    {
1326
                        const Value* a = popAndResolveAsPtr(context);
22✔
1327
                        push(Value(types_to_str[static_cast<unsigned>(a->valueType())]), context);
22✔
1328
                        DISPATCH();
22✔
1329
                    }
3✔
1330

1331
                    TARGET(HASFIELD)
1332
                    {
1333
                        {
1334
                            Value* const field = popAndResolveAsPtr(context);
3✔
1335
                            Value* const closure = popAndResolveAsPtr(context);
3✔
1336
                            if (closure->valueType() != ValueType::Closure || field->valueType() != ValueType::String)
3✔
1337
                                throw types::TypeCheckingError(
2✔
1338
                                    "hasField",
1✔
1339
                                    { { types::Contract { { types::Typedef("closure", ValueType::Closure), types::Typedef("field", ValueType::String) } } } },
1✔
1340
                                    { *closure, *field });
1✔
1341

1342
                            auto it = std::ranges::find(m_state.m_symbols, field->stringRef());
2✔
1343
                            if (it == m_state.m_symbols.end())
2✔
1344
                            {
1345
                                push(Builtins::falseSym, context);
1✔
1346
                                DISPATCH();
1✔
1347
                            }
1348

1349
                            auto id = static_cast<std::uint16_t>(std::distance(m_state.m_symbols.begin(), it));
1✔
1350
                            push(closure->refClosure().refScope()[id] != nullptr ? Builtins::trueSym : Builtins::falseSym, context);
1✔
1351
                        }
1352
                        DISPATCH();
1✔
1353
                    }
3,396✔
1354

1355
                    TARGET(NOT)
1356
                    {
1357
                        const Value* a = popAndResolveAsPtr(context);
3,396✔
1358
                        push(!(*a) ? Builtins::trueSym : Builtins::falseSym, context);
3,396✔
1359
                        DISPATCH();
3,396✔
1360
                    }
5,953✔
1361

1362
#pragma endregion
1363

1364
#pragma region "Super Instructions"
1365
                    TARGET(LOAD_CONST_LOAD_CONST)
1366
                    {
1367
                        UNPACK_ARGS();
5,953✔
1368
                        push(loadConstAsPtr(primary_arg), context);
5,953✔
1369
                        push(loadConstAsPtr(secondary_arg), context);
5,953✔
1370
                        DISPATCH();
5,953✔
1371
                    }
7,681✔
1372

1373
                    TARGET(LOAD_CONST_STORE)
1374
                    {
1375
                        UNPACK_ARGS();
7,681✔
1376
                        store(secondary_arg, loadConstAsPtr(primary_arg), context);
7,681✔
1377
                        DISPATCH();
7,681✔
1378
                    }
218✔
1379

1380
                    TARGET(LOAD_CONST_SET_VAL)
1381
                    {
1382
                        UNPACK_ARGS();
218✔
1383
                        setVal(secondary_arg, loadConstAsPtr(primary_arg), context);
218✔
1384
                        DISPATCH();
217✔
1385
                    }
19✔
1386

1387
                    TARGET(STORE_FROM)
1388
                    {
1389
                        UNPACK_ARGS();
19✔
1390
                        store(secondary_arg, loadSymbol(primary_arg, context), context);
19✔
1391
                        DISPATCH();
18✔
1392
                    }
1,096✔
1393

1394
                    TARGET(STORE_FROM_INDEX)
1395
                    {
1396
                        UNPACK_ARGS();
1,096✔
1397
                        store(secondary_arg, loadSymbolFromIndex(primary_arg, context), context);
1,096✔
1398
                        DISPATCH();
1,096✔
1399
                    }
547✔
1400

1401
                    TARGET(SET_VAL_FROM)
1402
                    {
1403
                        UNPACK_ARGS();
547✔
1404
                        setVal(secondary_arg, loadSymbol(primary_arg, context), context);
547✔
1405
                        DISPATCH();
547✔
1406
                    }
175✔
1407

1408
                    TARGET(SET_VAL_FROM_INDEX)
1409
                    {
1410
                        UNPACK_ARGS();
175✔
1411
                        setVal(secondary_arg, loadSymbolFromIndex(primary_arg, context), context);
175✔
1412
                        DISPATCH();
175✔
1413
                    }
16✔
1414

1415
                    TARGET(INCREMENT)
1416
                    {
1417
                        UNPACK_ARGS();
16✔
1418
                        {
1419
                            Value* var = loadSymbol(primary_arg, context);
16✔
1420

1421
                            // use internal reference, shouldn't break anything so far, unless it's already a ref
1422
                            if (var->valueType() == ValueType::Reference)
16✔
UNCOV
1423
                                var = var->reference();
×
1424

1425
                            if (var->valueType() == ValueType::Number)
16✔
1426
                                push(Value(var->number() + secondary_arg), context);
16✔
1427
                            else
1428
                                throw types::TypeCheckingError(
×
1429
                                    "+",
×
1430
                                    { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
×
UNCOV
1431
                                    { *var, Value(secondary_arg) });
×
1432
                        }
1433
                        DISPATCH();
16✔
1434
                    }
87,973✔
1435

1436
                    TARGET(INCREMENT_BY_INDEX)
1437
                    {
1438
                        UNPACK_ARGS();
87,973✔
1439
                        {
1440
                            Value* var = loadSymbolFromIndex(primary_arg, context);
87,973✔
1441

1442
                            // use internal reference, shouldn't break anything so far, unless it's already a ref
1443
                            if (var->valueType() == ValueType::Reference)
87,973✔
UNCOV
1444
                                var = var->reference();
×
1445

1446
                            if (var->valueType() == ValueType::Number)
87,973✔
1447
                                push(Value(var->number() + secondary_arg), context);
87,972✔
1448
                            else
1449
                                throw types::TypeCheckingError(
2✔
1450
                                    "+",
1✔
1451
                                    { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
1✔
1452
                                    { *var, Value(secondary_arg) });
1✔
1453
                        }
1454
                        DISPATCH();
87,972✔
1455
                    }
30,794✔
1456

1457
                    TARGET(INCREMENT_STORE)
1458
                    {
1459
                        UNPACK_ARGS();
30,794✔
1460
                        {
1461
                            Value* var = loadSymbol(primary_arg, context);
30,794✔
1462

1463
                            // use internal reference, shouldn't break anything so far, unless it's already a ref
1464
                            if (var->valueType() == ValueType::Reference)
30,794✔
UNCOV
1465
                                var = var->reference();
×
1466

1467
                            if (var->valueType() == ValueType::Number)
30,794✔
1468
                            {
1469
                                Value val = Value(var->number() + secondary_arg);
30,794✔
1470
                                setVal(primary_arg, &val, context);
30,794✔
1471
                            }
30,794✔
1472
                            else
1473
                                throw types::TypeCheckingError(
×
1474
                                    "+",
×
1475
                                    { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
×
UNCOV
1476
                                    { *var, Value(secondary_arg) });
×
1477
                        }
1478
                        DISPATCH();
30,794✔
1479
                    }
1,776✔
1480

1481
                    TARGET(DECREMENT)
1482
                    {
1483
                        UNPACK_ARGS();
1,776✔
1484
                        {
1485
                            Value* var = loadSymbol(primary_arg, context);
1,776✔
1486

1487
                            // use internal reference, shouldn't break anything so far, unless it's already a ref
1488
                            if (var->valueType() == ValueType::Reference)
1,776✔
UNCOV
1489
                                var = var->reference();
×
1490

1491
                            if (var->valueType() == ValueType::Number)
1,776✔
1492
                                push(Value(var->number() - secondary_arg), context);
1,776✔
1493
                            else
1494
                                throw types::TypeCheckingError(
×
1495
                                    "-",
×
1496
                                    { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
×
UNCOV
1497
                                    { *var, Value(secondary_arg) });
×
1498
                        }
1499
                        DISPATCH();
1,776✔
1500
                    }
194,404✔
1501

1502
                    TARGET(DECREMENT_BY_INDEX)
1503
                    {
1504
                        UNPACK_ARGS();
194,404✔
1505
                        {
1506
                            Value* var = loadSymbolFromIndex(primary_arg, context);
194,404✔
1507

1508
                            // use internal reference, shouldn't break anything so far, unless it's already a ref
1509
                            if (var->valueType() == ValueType::Reference)
194,404✔
UNCOV
1510
                                var = var->reference();
×
1511

1512
                            if (var->valueType() == ValueType::Number)
194,404✔
1513
                                push(Value(var->number() - secondary_arg), context);
194,403✔
1514
                            else
1515
                                throw types::TypeCheckingError(
2✔
1516
                                    "-",
1✔
1517
                                    { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
1✔
1518
                                    { *var, Value(secondary_arg) });
1✔
1519
                        }
1520
                        DISPATCH();
194,403✔
UNCOV
1521
                    }
×
1522

1523
                    TARGET(DECREMENT_STORE)
1524
                    {
UNCOV
1525
                        UNPACK_ARGS();
×
1526
                        {
UNCOV
1527
                            Value* var = loadSymbol(primary_arg, context);
×
1528

1529
                            // use internal reference, shouldn't break anything so far, unless it's already a ref
1530
                            if (var->valueType() == ValueType::Reference)
×
UNCOV
1531
                                var = var->reference();
×
1532

UNCOV
1533
                            if (var->valueType() == ValueType::Number)
×
1534
                            {
1535
                                Value val = Value(var->number() - secondary_arg);
×
1536
                                setVal(primary_arg, &val, context);
×
UNCOV
1537
                            }
×
1538
                            else
1539
                                throw types::TypeCheckingError(
×
1540
                                    "-",
×
1541
                                    { { types::Contract { { types::Typedef("a", ValueType::Number), types::Typedef("b", ValueType::Number) } } } },
×
UNCOV
1542
                                    { *var, Value(secondary_arg) });
×
1543
                        }
1544
                        DISPATCH();
×
UNCOV
1545
                    }
×
1546

1547
                    TARGET(STORE_TAIL)
1548
                    {
UNCOV
1549
                        UNPACK_ARGS();
×
1550
                        {
1551
                            Value* list = loadSymbol(primary_arg, context);
×
1552
                            Value tail = helper::tail(list);
×
1553
                            store(secondary_arg, &tail, context);
×
1554
                        }
×
UNCOV
1555
                        DISPATCH();
×
1556
                    }
1✔
1557

1558
                    TARGET(STORE_TAIL_BY_INDEX)
1559
                    {
1560
                        UNPACK_ARGS();
1✔
1561
                        {
1562
                            Value* list = loadSymbolFromIndex(primary_arg, context);
1✔
1563
                            Value tail = helper::tail(list);
1✔
1564
                            store(secondary_arg, &tail, context);
1✔
1565
                        }
1✔
1566
                        DISPATCH();
1✔
UNCOV
1567
                    }
×
1568

1569
                    TARGET(STORE_HEAD)
1570
                    {
UNCOV
1571
                        UNPACK_ARGS();
×
1572
                        {
1573
                            Value* list = loadSymbol(primary_arg, context);
×
1574
                            Value head = helper::head(list);
×
1575
                            store(secondary_arg, &head, context);
×
1576
                        }
×
UNCOV
1577
                        DISPATCH();
×
1578
                    }
31✔
1579

1580
                    TARGET(STORE_HEAD_BY_INDEX)
1581
                    {
1582
                        UNPACK_ARGS();
31✔
1583
                        {
1584
                            Value* list = loadSymbolFromIndex(primary_arg, context);
31✔
1585
                            Value head = helper::head(list);
31✔
1586
                            store(secondary_arg, &head, context);
31✔
1587
                        }
31✔
1588
                        DISPATCH();
31✔
1589
                    }
893✔
1590

1591
                    TARGET(STORE_LIST)
1592
                    {
1593
                        UNPACK_ARGS();
893✔
1594
                        {
1595
                            Value l = createList(primary_arg, context);
893✔
1596
                            store(secondary_arg, &l, context);
893✔
1597
                        }
893✔
1598
                        DISPATCH();
893✔
UNCOV
1599
                    }
×
1600

1601
                    TARGET(SET_VAL_TAIL)
1602
                    {
UNCOV
1603
                        UNPACK_ARGS();
×
1604
                        {
1605
                            Value* list = loadSymbol(primary_arg, context);
×
1606
                            Value tail = helper::tail(list);
×
1607
                            setVal(secondary_arg, &tail, context);
×
1608
                        }
×
UNCOV
1609
                        DISPATCH();
×
1610
                    }
1✔
1611

1612
                    TARGET(SET_VAL_TAIL_BY_INDEX)
1613
                    {
1614
                        UNPACK_ARGS();
1✔
1615
                        {
1616
                            Value* list = loadSymbolFromIndex(primary_arg, context);
1✔
1617
                            Value tail = helper::tail(list);
1✔
1618
                            setVal(secondary_arg, &tail, context);
1✔
1619
                        }
1✔
1620
                        DISPATCH();
1✔
UNCOV
1621
                    }
×
1622

1623
                    TARGET(SET_VAL_HEAD)
1624
                    {
UNCOV
1625
                        UNPACK_ARGS();
×
1626
                        {
1627
                            Value* list = loadSymbol(primary_arg, context);
×
1628
                            Value head = helper::head(list);
×
1629
                            setVal(secondary_arg, &head, context);
×
1630
                        }
×
UNCOV
1631
                        DISPATCH();
×
1632
                    }
1✔
1633

1634
                    TARGET(SET_VAL_HEAD_BY_INDEX)
1635
                    {
1636
                        UNPACK_ARGS();
1✔
1637
                        {
1638
                            Value* list = loadSymbolFromIndex(primary_arg, context);
1✔
1639
                            Value head = helper::head(list);
1✔
1640
                            setVal(secondary_arg, &head, context);
1✔
1641
                        }
1✔
1642
                        DISPATCH();
1✔
1643
                    }
776✔
1644

1645
                    TARGET(CALL_BUILTIN)
1646
                    {
1647
                        UNPACK_ARGS();
776✔
1648
                        // no stack size check because we do not push IP/PP since we are just calling a builtin
1649
                        callBuiltin(context, Builtins::builtins[primary_arg].second, secondary_arg);
776✔
1650
                        if (!m_running)
725✔
UNCOV
1651
                            GOTO_HALT();
×
1652
                        DISPATCH();
725✔
1653
                    }
11,045✔
1654

1655
                    TARGET(CALL_BUILTIN_WITHOUT_RETURN_ADDRESS)
1656
                    {
1657
                        UNPACK_ARGS();
11,045✔
1658
                        // no stack size check because we do not push IP/PP since we are just calling a builtin
1659
                        callBuiltin(context, Builtins::builtins[primary_arg].second, secondary_arg, /* remove_return_address= */ false);
11,045✔
1660
                        if (!m_running)
11,045✔
UNCOV
1661
                            GOTO_HALT();
×
1662
                        DISPATCH();
11,045✔
1663
                    }
857✔
1664

1665
                    TARGET(LT_CONST_JUMP_IF_FALSE)
1666
                    {
1667
                        UNPACK_ARGS();
857✔
1668
                        const Value* sym = popAndResolveAsPtr(context);
857✔
1669
                        if (!(*sym < *loadConstAsPtr(primary_arg)))
857✔
1670
                            context.ip = secondary_arg * 4;
122✔
1671
                        DISPATCH();
857✔
1672
                    }
21,902✔
1673

1674
                    TARGET(LT_CONST_JUMP_IF_TRUE)
1675
                    {
1676
                        UNPACK_ARGS();
21,902✔
1677
                        const Value* sym = popAndResolveAsPtr(context);
21,902✔
1678
                        if (*sym < *loadConstAsPtr(primary_arg))
21,902✔
1679
                            context.ip = secondary_arg * 4;
10,950✔
1680
                        DISPATCH();
21,902✔
1681
                    }
5,466✔
1682

1683
                    TARGET(LT_SYM_JUMP_IF_FALSE)
1684
                    {
1685
                        UNPACK_ARGS();
5,466✔
1686
                        const Value* sym = popAndResolveAsPtr(context);
5,466✔
1687
                        if (!(*sym < *loadSymbol(primary_arg, context)))
5,466✔
1688
                            context.ip = secondary_arg * 4;
520✔
1689
                        DISPATCH();
5,466✔
1690
                    }
172,498✔
1691

1692
                    TARGET(GT_CONST_JUMP_IF_TRUE)
1693
                    {
1694
                        UNPACK_ARGS();
172,498✔
1695
                        const Value* sym = popAndResolveAsPtr(context);
172,498✔
1696
                        const Value* cst = loadConstAsPtr(primary_arg);
172,498✔
1697
                        if (*cst < *sym)
172,498✔
1698
                            context.ip = secondary_arg * 4;
86,585✔
1699
                        DISPATCH();
172,498✔
1700
                    }
15✔
1701

1702
                    TARGET(GT_CONST_JUMP_IF_FALSE)
1703
                    {
1704
                        UNPACK_ARGS();
15✔
1705
                        const Value* sym = popAndResolveAsPtr(context);
15✔
1706
                        const Value* cst = loadConstAsPtr(primary_arg);
15✔
1707
                        if (!(*cst < *sym))
15✔
1708
                            context.ip = secondary_arg * 4;
3✔
1709
                        DISPATCH();
15✔
UNCOV
1710
                    }
×
1711

1712
                    TARGET(GT_SYM_JUMP_IF_FALSE)
1713
                    {
UNCOV
1714
                        UNPACK_ARGS();
×
UNCOV
1715
                        const Value* sym = popAndResolveAsPtr(context);
×
UNCOV
1716
                        const Value* rhs = loadSymbol(primary_arg, context);
×
UNCOV
1717
                        if (!(*rhs < *sym))
×
UNCOV
1718
                            context.ip = secondary_arg * 4;
×
UNCOV
1719
                        DISPATCH();
×
1720
                    }
1,175✔
1721

1722
                    TARGET(EQ_CONST_JUMP_IF_TRUE)
1723
                    {
1724
                        UNPACK_ARGS();
1,175✔
1725
                        const Value* sym = popAndResolveAsPtr(context);
1,175✔
1726
                        if (*sym == *loadConstAsPtr(primary_arg))
1,175✔
1727
                            context.ip = secondary_arg * 4;
188✔
1728
                        DISPATCH();
1,175✔
1729
                    }
86,933✔
1730

1731
                    TARGET(EQ_SYM_INDEX_JUMP_IF_TRUE)
1732
                    {
1733
                        UNPACK_ARGS();
86,933✔
1734
                        const Value* sym = popAndResolveAsPtr(context);
86,933✔
1735
                        if (*sym == *loadSymbolFromIndex(primary_arg, context))
86,933✔
1736
                            context.ip = secondary_arg * 4;
529✔
1737
                        DISPATCH();
86,933✔
1738
                    }
1✔
1739

1740
                    TARGET(NEQ_CONST_JUMP_IF_TRUE)
1741
                    {
1742
                        UNPACK_ARGS();
1✔
1743
                        const Value* sym = popAndResolveAsPtr(context);
1✔
1744
                        if (*sym != *loadConstAsPtr(primary_arg))
1✔
1745
                            context.ip = secondary_arg * 4;
1✔
1746
                        DISPATCH();
1✔
1747
                    }
15✔
1748

1749
                    TARGET(NEQ_SYM_JUMP_IF_FALSE)
1750
                    {
1751
                        UNPACK_ARGS();
15✔
1752
                        const Value* sym = popAndResolveAsPtr(context);
15✔
1753
                        if (*sym == *loadSymbol(primary_arg, context))
15✔
1754
                            context.ip = secondary_arg * 4;
5✔
1755
                        DISPATCH();
15✔
1756
                    }
135,559✔
1757

1758
                    TARGET(CALL_SYMBOL)
1759
                    {
1760
                        UNPACK_ARGS();
135,559✔
1761
                        call(context, secondary_arg, loadSymbol(primary_arg, context));
135,559✔
1762
                        if (!m_running)
135,558✔
UNCOV
1763
                            GOTO_HALT();
×
1764
                        DISPATCH();
135,558✔
1765
                    }
1,615✔
1766

1767
                    TARGET(GET_FIELD_FROM_SYMBOL)
1768
                    {
1769
                        UNPACK_ARGS();
1,615✔
1770
                        push(getField(loadSymbol(primary_arg, context), secondary_arg, context), context);
1,615✔
1771
                        DISPATCH();
1,615✔
1772
                    }
714✔
1773

1774
                    TARGET(GET_FIELD_FROM_SYMBOL_INDEX)
1775
                    {
1776
                        UNPACK_ARGS();
714✔
1777
                        push(getField(loadSymbolFromIndex(primary_arg, context), secondary_arg, context), context);
717✔
1778
                        DISPATCH();
711✔
1779
                    }
14,157✔
1780

1781
                    TARGET(AT_SYM_SYM)
1782
                    {
1783
                        UNPACK_ARGS();
14,157✔
1784
                        push(helper::at(*loadSymbol(primary_arg, context), *loadSymbol(secondary_arg, context), *this), context);
14,157✔
1785
                        DISPATCH();
14,157✔
UNCOV
1786
                    }
×
1787

1788
                    TARGET(AT_SYM_INDEX_SYM_INDEX)
1789
                    {
UNCOV
1790
                        UNPACK_ARGS();
×
UNCOV
1791
                        push(helper::at(*loadSymbolFromIndex(primary_arg, context), *loadSymbolFromIndex(secondary_arg, context), *this), context);
×
UNCOV
1792
                        DISPATCH();
×
1793
                    }
6✔
1794

1795
                    TARGET(CHECK_TYPE_OF)
1796
                    {
1797
                        UNPACK_ARGS();
6✔
1798
                        const Value* sym = loadSymbol(primary_arg, context);
6✔
1799
                        const Value* cst = loadConstAsPtr(secondary_arg);
6✔
1800
                        push(
6✔
1801
                            cst->valueType() == ValueType::String &&
12✔
1802
                                    types_to_str[static_cast<unsigned>(sym->valueType())] == cst->string()
6✔
1803
                                ? Builtins::trueSym
1804
                                : Builtins::falseSym,
1805
                            context);
6✔
1806
                        DISPATCH();
6✔
1807
                    }
68✔
1808

1809
                    TARGET(CHECK_TYPE_OF_BY_INDEX)
1810
                    {
1811
                        UNPACK_ARGS();
68✔
1812
                        const Value* sym = loadSymbolFromIndex(primary_arg, context);
68✔
1813
                        const Value* cst = loadConstAsPtr(secondary_arg);
68✔
1814
                        push(
68✔
1815
                            cst->valueType() == ValueType::String &&
136✔
1816
                                    types_to_str[static_cast<unsigned>(sym->valueType())] == cst->string()
68✔
1817
                                ? Builtins::trueSym
1818
                                : Builtins::falseSym,
1819
                            context);
68✔
1820
                        DISPATCH();
68✔
1821
                    }
1,406✔
1822

1823
                    TARGET(APPEND_IN_PLACE_SYM)
1824
                    {
1825
                        UNPACK_ARGS();
1,406✔
1826
                        listAppendInPlace(loadSymbol(primary_arg, context), secondary_arg, context);
1,406✔
1827
                        DISPATCH();
1,406✔
1828
                    }
12✔
1829

1830
                    TARGET(APPEND_IN_PLACE_SYM_INDEX)
1831
                    {
1832
                        UNPACK_ARGS();
12✔
1833
                        listAppendInPlace(loadSymbolFromIndex(primary_arg, context), secondary_arg, context);
12✔
1834
                        DISPATCH();
11✔
1835
                    }
1836
#pragma endregion
1837
                }
64✔
1838
#if ARK_USE_COMPUTED_GOTOS
1839
            dispatch_end:
1840
                do
64✔
1841
                {
1842
                } while (false);
64✔
1843
#endif
1844
            }
1845
        }
174✔
1846
        catch (const Error& e)
1847
        {
1848
            if (fail_with_exception)
68✔
1849
            {
1850
                std::stringstream stream;
68✔
1851
                backtrace(context, stream, /* colorize= */ false);
68✔
1852
                // It's important we have an Ark::Error here, as the constructor for NestedError
1853
                // does more than just aggregate error messages, hence the code duplication.
1854
                throw NestedError(e, stream.str());
68✔
1855
            }
68✔
1856
            else
1857
                showBacktraceWithException(Error(e.details(/* colorize= */ true)), context);
×
1858
        }
132✔
1859
        catch (const std::exception& e)
1860
        {
1861
            if (fail_with_exception)
42✔
1862
            {
1863
                std::stringstream stream;
42✔
1864
                backtrace(context, stream, /* colorize= */ false);
42✔
1865
                throw NestedError(e, stream.str());
42✔
1866
            }
42✔
1867
            else
1868
                showBacktraceWithException(e, context);
×
1869
        }
110✔
1870
        catch (...)
1871
        {
UNCOV
1872
            if (fail_with_exception)
×
UNCOV
1873
                throw;
×
1874

1875
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
1876
            throw;
1877
#endif
UNCOV
1878
            fmt::println("Unknown error");
×
UNCOV
1879
            backtrace(context);
×
UNCOV
1880
            m_exit_code = 1;
×
1881
        }
152✔
1882

1883
        return m_exit_code;
64✔
1884
    }
220✔
1885

1886
    uint16_t VM::findNearestVariableIdWithValue(const Value& value, ExecutionContext& context) const noexcept
2,047✔
1887
    {
2,047✔
1888
        for (auto& local : std::ranges::reverse_view(context.locals))
4,094✔
1889
        {
1890
            if (const auto id = local.idFromValue(value); id < m_state.m_symbols.size())
2,047✔
1891
                return id;
2,047✔
1892
        }
2,047✔
UNCOV
1893
        return std::numeric_limits<uint16_t>::max();
×
1894
    }
2,047✔
1895

1896
    void VM::throwArityError(std::size_t passed_arg_count, std::size_t expected_arg_count, internal::ExecutionContext& context)
5✔
1897
    {
5✔
1898
        std::vector<std::string> arg_names;
5✔
1899
        arg_names.reserve(expected_arg_count + 1);
5✔
1900
        if (expected_arg_count > 0)
5✔
1901
            arg_names.emplace_back("");  // for formatting, so that we have a space between the function and the args
5✔
1902

1903
        std::size_t index = 0;
5✔
1904
        while (m_state.m_pages[context.pp][index] == STORE)
12✔
1905
        {
1906
            const auto id = static_cast<uint16_t>((m_state.m_pages[context.pp][index + 2] << 8) + m_state.m_pages[context.pp][index + 3]);
7✔
1907
            arg_names.push_back(m_state.m_symbols[id]);
7✔
1908
            index += 4;
7✔
1909
        }
7✔
1910
        // we only the blank space for formatting and no arg names, probably because of a CALL_BUILTIN_WITHOUT_RETURN_ADDRESS
1911
        if (arg_names.size() == 1 && index == 0)
5✔
1912
        {
1913
            assert(m_state.m_pages[context.pp][0] == CALL_BUILTIN_WITHOUT_RETURN_ADDRESS && "expected a CALL_BUILTIN_WITHOUT_RETURN_ADDRESS instruction or STORE instructions");
2✔
1914
            for (std::size_t i = 0; i < expected_arg_count; ++i)
4✔
1915
                arg_names.push_back(std::string(1, static_cast<char>('a' + i)));
2✔
1916
        }
2✔
1917

1918
        std::vector<std::string> arg_vals;
5✔
1919
        arg_vals.reserve(passed_arg_count + 1);
5✔
1920
        if (passed_arg_count > 0)
5✔
1921
            arg_vals.emplace_back("");  // for formatting, so that we have a space between the function and the args
4✔
1922

1923
        for (std::size_t i = 0; i < passed_arg_count && i + 1 <= context.sp; ++i)
15✔
1924
            // -1 on the stack because we always point to the next available slot
1925
            arg_vals.push_back(context.stack[context.sp - i - 1].toString(*this));
10✔
1926

1927
        // set ip/pp to the callee location so that the error can pinpoint the line
1928
        // where the bad call happened
1929
        if (context.sp >= 2 + passed_arg_count)
5✔
1930
        {
1931
            context.ip = context.stack[context.sp - 1 - passed_arg_count].pageAddr();
5✔
1932
            context.pp = context.stack[context.sp - 2 - passed_arg_count].pageAddr();
5✔
1933
            returnFromFuncCall(context);
5✔
1934
        }
5✔
1935

1936
        std::string function_name = (context.last_symbol < m_state.m_symbols.size())
10✔
1937
            ? m_state.m_symbols[context.last_symbol]
5✔
1938
            : Value(static_cast<PageAddr_t>(context.pp)).toString(*this);
×
1939

1940
        throwVMError(
5✔
1941
            ErrorKind::Arity,
1942
            fmt::format(
10✔
1943
                "When calling `({}{})', received {} argument{}, but expected {}: `({}{})'",
5✔
1944
                function_name,
1945
                fmt::join(arg_vals, " "),
5✔
1946
                passed_arg_count,
1947
                passed_arg_count > 1 ? "s" : "",
5✔
1948
                expected_arg_count,
1949
                function_name,
1950
                fmt::join(arg_names, " ")));
5✔
1951
    }
10✔
1952

UNCOV
1953
    void VM::showBacktraceWithException(const std::exception& e, internal::ExecutionContext& context)
×
UNCOV
1954
    {
×
UNCOV
1955
        std::string text = e.what();
×
UNCOV
1956
        if (!text.empty() && text.back() != '\n')
×
UNCOV
1957
            text += '\n';
×
UNCOV
1958
        fmt::println("{}", text);
×
UNCOV
1959
        backtrace(context);
×
1960
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
1961
        // don't report a "failed" exit code so that the fuzzers can more accurately triage crashes
1962
        m_exit_code = 0;
1963
#else
UNCOV
1964
        m_exit_code = 1;
×
1965
#endif
UNCOV
1966
    }
×
1967

1968
    std::optional<InstLoc> VM::findSourceLocation(const std::size_t ip, const std::size_t pp)
2,158✔
1969
    {
2,158✔
1970
        std::optional<InstLoc> match = std::nullopt;
2,158✔
1971

1972
        for (const auto location : m_state.m_inst_locations)
8,461✔
1973
        {
1974
            if (location.page_pointer == pp && !match)
6,303✔
1975
                match = location;
2,158✔
1976

1977
            // select the best match: we want to find the location that's nearest our instruction pointer,
1978
            // but not equal to it as the IP will always be pointing to the next instruction,
1979
            // not yet executed. Thus, the erroneous instruction is the previous one.
1980
            if (location.page_pointer == pp && match && location.inst_pointer < ip / 4)
6,303✔
1981
                match = location;
2,197✔
1982

1983
            // early exit because we won't find anything better, as inst locations are ordered by ascending (pp, ip)
1984
            if (location.page_pointer > pp || (location.page_pointer == pp && location.inst_pointer >= ip / 4))
6,303✔
1985
                break;
10✔
1986
        }
6,303✔
1987

1988
        return match;
2,158✔
1989
    }
1990

UNCOV
1991
    std::string VM::debugShowSource()
×
UNCOV
1992
    {
×
UNCOV
1993
        const auto& context = m_execution_contexts.front();
×
UNCOV
1994
        auto maybe_source_loc = findSourceLocation(context->ip, context->pp);
×
UNCOV
1995
        if (maybe_source_loc)
×
1996
        {
UNCOV
1997
            const auto filename = m_state.m_filenames[maybe_source_loc->filename_id];
×
UNCOV
1998
            return fmt::format("{}:{} -- IP: {}, PP: {}", filename, maybe_source_loc->line + 1, maybe_source_loc->inst_pointer, maybe_source_loc->page_pointer);
×
UNCOV
1999
        }
×
UNCOV
2000
        return "No source location found";
×
UNCOV
2001
    }
×
2002

2003
    void VM::backtrace(ExecutionContext& context, std::ostream& os, const bool colorize)
110✔
2004
    {
110✔
2005
        const std::size_t saved_ip = context.ip;
110✔
2006
        const std::size_t saved_pp = context.pp;
110✔
2007
        const uint16_t saved_sp = context.sp;
110✔
2008
        const std::size_t max_consecutive_traces = 7;
110✔
2009

2010
        const auto maybe_location = findSourceLocation(context.ip, context.pp);
110✔
2011
        if (maybe_location)
110✔
2012
        {
2013
            const auto filename = m_state.m_filenames[maybe_location->filename_id];
110✔
2014

2015
            if (Utils::fileExists(filename))
110✔
2016
                Diagnostics::makeContext(
220✔
2017
                    os,
110✔
2018
                    filename,
2019
                    /* expr= */ std::nullopt,
110✔
2020
                    /* sym_size= */ 0,
2021
                    maybe_location->line,
110✔
2022
                    /* col_start= */ 0,
2023
                    /* maybe_context= */ std::nullopt,
110✔
2024
                    /* whole_line= */ true,
2025
                    /* colorize= */ colorize);
110✔
2026
            fmt::println(os, "");
110✔
2027
        }
110✔
2028

2029
        if (context.fc > 1)
110✔
2030
        {
2031
            // display call stack trace
2032
            const ScopeView old_scope = context.locals.back();
1✔
2033

2034
            std::string previous_trace;
1✔
2035
            std::size_t displayed_traces = 0;
1✔
2036
            std::size_t consecutive_similar_traces = 0;
1✔
2037

2038
            while (context.fc != 0)
2,048✔
2039
            {
2040
                const auto maybe_call_loc = findSourceLocation(context.ip, context.pp);
2,047✔
2041
                const auto loc_as_text = maybe_call_loc ? fmt::format(" ({}:{})", m_state.m_filenames[maybe_call_loc->filename_id], maybe_call_loc->line + 1) : "";
2,047✔
2042

2043
                if (context.pp != 0)
2,047✔
2044
                {
2045
                    const uint16_t id = findNearestVariableIdWithValue(
2,047✔
2046
                        Value(static_cast<PageAddr_t>(context.pp)),
2,047✔
2047
                        context);
2,047✔
2048
                    const auto func_name = (id < m_state.m_symbols.size()) ? m_state.m_symbols[id] : "???";
2,047✔
2049

2050
                    if (func_name + loc_as_text != previous_trace)
2,047✔
2051
                    {
2052
                        fmt::println(
2✔
2053
                            os,
1✔
2054
                            "[{:4}] In function `{}'{}",
1✔
2055
                            fmt::styled(context.fc, colorize ? fmt::fg(fmt::color::cyan) : fmt::text_style()),
1✔
2056
                            fmt::styled(func_name, colorize ? fmt::fg(fmt::color::green) : fmt::text_style()),
1✔
2057
                            loc_as_text);
2058
                        previous_trace = func_name + loc_as_text;
1✔
2059
                        ++displayed_traces;
1✔
2060
                        consecutive_similar_traces = 0;
1✔
2061
                    }
1✔
2062
                    else if (consecutive_similar_traces == 0)
2,046✔
2063
                    {
2064
                        fmt::println(os, "       ...");
1✔
2065
                        ++consecutive_similar_traces;
1✔
2066
                    }
1✔
2067

2068
                    const Value* ip;
2,047✔
2069
                    do
2,048✔
2070
                    {
2071
                        ip = popAndResolveAsPtr(context);
2,048✔
2072
                    } while (ip->valueType() != ValueType::InstPtr);
2,048✔
2073

2074
                    context.ip = ip->pageAddr();
2,047✔
2075
                    context.pp = pop(context)->pageAddr();
2,047✔
2076
                    returnFromFuncCall(context);
2,047✔
2077
                }
2,047✔
2078

2079
                if (displayed_traces > max_consecutive_traces)
2,047✔
2080
                {
UNCOV
2081
                    fmt::println(os, "       ...");
×
UNCOV
2082
                    break;
×
2083
                }
2084
            }
2,047✔
2085

2086
            if (context.pp == 0)
1✔
2087
            {
2088
                const auto maybe_call_loc = findSourceLocation(context.ip, context.pp);
1✔
2089
                const auto loc_as_text = maybe_call_loc ? fmt::format(" ({}:{})", m_state.m_filenames[maybe_call_loc->filename_id], maybe_call_loc->line + 1) : "";
1✔
2090
                fmt::println(os, "[{:4}] In global scope{}", fmt::styled(context.fc, colorize ? fmt::fg(fmt::color::cyan) : fmt::text_style()), loc_as_text);
1✔
2091
            }
1✔
2092

2093
            // display variables values in the current scope
2094
            fmt::println(os, "\nCurrent scope variables values:");
1✔
2095
            for (std::size_t i = 0, size = old_scope.size(); i < size; ++i)
3✔
2096
            {
2097
                fmt::println(
4✔
2098
                    os,
2✔
2099
                    "{} = {}",
2✔
2100
                    fmt::styled(m_state.m_symbols[old_scope.atPos(i).first], colorize ? fmt::fg(fmt::color::cyan) : fmt::text_style()),
2✔
2101
                    old_scope.atPos(i).second.toString(*this));
2✔
2102
            }
2✔
2103
        }
1✔
2104

2105
        fmt::println(
220✔
2106
            os,
110✔
2107
            "At IP: {}, PP: {}, SP: {}",
110✔
2108
            // dividing by 4 because the instructions are actually on 4 bytes
2109
            fmt::styled(saved_ip / 4, colorize ? fmt::fg(fmt::color::cyan) : fmt::text_style()),
110✔
2110
            fmt::styled(saved_pp, colorize ? fmt::fg(fmt::color::green) : fmt::text_style()),
110✔
2111
            fmt::styled(saved_sp, colorize ? fmt::fg(fmt::color::yellow) : fmt::text_style()));
110✔
2112
    }
110✔
2113
}
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