aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp
blob: 8a7facba2467b4e055029bc631b756607e4b6864 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "fuzz_ops.h"
#include "vm_apply.h"
#include "vm_defs.h"
#include "vm_parse.h"

#include <library/cpp/bit_io/bitinput.h>

#include <library/cpp/scheme/scheme.h>
#include <library/cpp/scheme/scimpl_private.h>

#include <util/generic/maybe.h>

namespace NSc::NUt {

    void FuzzOps(TStringBuf wire, bool log) {
        if (log) {
            NImpl::GetTlsInstance<NImpl::TSelfLoopContext>().ReportingMode = NImpl::TSelfLoopContext::EMode::Stderr;
        }

        // We start with a single TValue node
        TVMState st {wire, 1, 0};

        while (auto act = ParseNextAction(st)) {
            if (log) {
                Cerr << " STATE: " << st.ToString() << Endl;
                Cerr << "ACTION: " << (act ? act->ToString() : TString("(empty)")) << Endl;
            }

            if (!ApplyNextAction(st, *act)) {
                break;
            }
            if (!NSc::TValue::DefaultValue().IsNull()) {
                std::terminate();
            }
        }
    }
}