<commit_before>#include "primops.hh"
#include "eval-inline.hh"

#include "../../toml11/toml.hpp"

namespace nix {

static void prim_fromTOML(EvalState & state, const Pos & pos, Value * * args, Value & val)
{
    auto toml = state.forceStringNoCtx(*args[0], pos);

    std::istringstream tomlStream(toml);

    std::function<void(Value &, toml::value)> visit;

    visit = [&](Value & v, toml::value t) {

        switch(t.type())
        {
            case toml::value_t::table:
                {
                    auto table = toml::get<toml::table>(t);

                    size_t size = 0;
                    for (auto & i : table) { (void) i; size++; }

                    state.mkAttrs(v, size);

                    for(auto & elem: table) {

                        auto & v2 = *state.allocAttr(v, state.symbols.create(elem.first));
                        visit(v2, elem.second);
                    }
                }
                break;;
            case toml::value_t::array:
                {
                    auto array = toml::get<std::vector<toml::value>>(t);

                    size_t size = array.size();
                    state.mkList(v, size);
                    for (size_t i = 0; i < size; ++i)
                        visit(*(v.listElems()[i] = state.allocValue()), array[i]);
                }
                break;;
            case toml::value_t::boolean:
                mkBool(v, toml::get<bool>(t));
                break;;
            case toml::value_t::integer:
                mkInt(v, toml::get<long>(t));
                break;;
            case toml::value_t::floating:
                mkFloat(v, toml::get<double>(t));
                break;;
            case toml::value_t::string:
                mkString(v, toml::get<std::string>(t));
                break;;
            case toml::value_t::local_datetime:
            case toml::value_t::offset_datetime:
            case toml::value_t::local_date:
            case toml::value_t::local_time:
                // We fail since Nix doesn't have date and time types
                throw std::runtime_error("Dates and times are not supported");
                break;;
            case toml::value_t::empty:
                mkNull(v);
                break;;

        }<commit_msg>Use int64_t and NixFloat in fromTOML types<commit_after>#include "primops.hh"
#include "eval-inline.hh"

#include "../../toml11/toml.hpp"

namespace nix {

static void prim_fromTOML(EvalState & state, const Pos & pos, Value * * args, Value & val)
{
    auto toml = state.forceStringNoCtx(*args[0], pos);

    std::istringstream tomlStream(toml);

    std::function<void(Value &, toml::value)> visit;

    visit = [&](Value & v, toml::value t) {

        switch(t.type())
        {
            case toml::value_t::table:
                {
                    auto table = toml::get<toml::table>(t);

                    size_t size = 0;
                    for (auto & i : table) { (void) i; size++; }

                    state.mkAttrs(v, size);

                    for(auto & elem: table) {

                        auto & v2 = *state.allocAttr(v, state.symbols.create(elem.first));
                        visit(v2, elem.second);
                    }
                }
                break;;
            case toml::value_t::array:
                {
                    auto array = toml::get<std::vector<toml::value>>(t);

                    size_t size = array.size();
                    state.mkList(v, size);
                    for (size_t i = 0; i < size; ++i)
                        visit(*(v.listElems()[i] = state.allocValue()), array[i]);
                }
                break;;
            case toml::value_t::boolean:
                mkBool(v, toml::get<bool>(t));
                break;;
            case toml::value_t::integer:
                mkInt(v, toml::get<int64_t>(t));
                break;;
            case toml::value_t::floating:
                mkFloat(v, toml::get<NixFloat>(t));
                break;;
            case toml::value_t::string:
                mkString(v, toml::get<std::string>(t));
                break;;
            case toml::value_t::local_datetime:
            case toml::value_t::offset_datetime:
            case toml::value_t::local_date:
            case toml::value_t::local_time:
                // We fail since Nix doesn't have date and time types
                throw std::runtime_error("Dates and times are not supported");
                break;;
            case toml::value_t::empty:
                mkNull(v);
                break;;

        }
{'fraction_non_alphanumeric': 0.1350412505427703, 'fraction_numerical': 0.0039079461571862786, 'mean_word_length': 1.4107796964939823, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5301823', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1310, 'n_words': 270}