<commit_before>#include <boost/optional.hpp>
#include <cassert>
#include "data.hpp"
#include <fstream>
#include "interpret.hpp"
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <string>
#include "tape.hpp"
#include <unordered_map>
#include <vector>
#include "object.hpp"

using namespace mill;

int main(int argc, char const** argv) {
    assert(argc == 2);
    std::ifstream object_file_stream(argv[1], std::ios::binary);
    std::vector<unsigned char> object_file(
        (std::istreambuf_iterator<char>(object_file_stream)),
        std::istreambuf_iterator<char>()
    );
    auto object = read_object(object_file.begin(), object_file.end());

    std::unordered_map<std::string, handle> globals;
    globals.emplace("std::io::writeln", handle(subroutine([] (auto arguments_begin, auto) {
        std::cout << arguments_begin->template data<string>().data() << '\n';
        return handle(unit());
    })));
    globals.emplace("std::always::infix==", handle(subroutine([] (auto arguments_begin, auto) {
        auto a = (arguments_begin + 0)->template data<bool>();
        auto b = (arguments_begin + 1)->template data<bool>();
        return handle(a == b);
    })));

    auto& code = object.subroutines.at(0).body;
    tape<decltype(code.begin())> tape(code.begin(), code.end());
    std::vector<handle> arguments;
    interpret(
        tape,
        arguments.begin(),
        arguments.end(),
        [&] (auto index) -> boost::optional<handle> {
            try {
                return globals.at(object.strings.at(index));
            } catch (std::out_of_range const&) {
                return boost::none;
            }
        },
        [&] (auto index) -> boost::optional<handle> {
            try {
                return handle(string(object.strings.at(index)));
            } catch (std::out_of_range const&) {
                return boost::none;
            }
        }
    );

    return 0;
}<commit_msg>Load complete object file<commit_after>#include <boost/optional.hpp>
#include <cassert>
#include "data.hpp"
#include <fstream>
#include "interpret.hpp"
#include <iostream>
#include <iterator>
#include <stdexcept>
#include <string>
#include "tape.hpp"
#include <unordered_map>
#include <vector>
#include "object.hpp"

using namespace mill;

int main(int argc, char const** argv) {
    assert(argc == 2);
    std::ifstream object_file_stream(argv[1], std::ios::binary);
    std::vector<unsigned char> object_file(
        (std::istreambuf_iterator<char>(object_file_stream)),
        std::istreambuf_iterator<char>()
    );
    auto object = read_object(object_file.begin(), object_file.end());

    std::unordered_map<std::string, handle> globals;
    globals.emplace("std::io::writeln", handle(subroutine([] (auto arguments_begin, auto) {
        std::cout << arguments_begin->template data<string>().data() << '\n';
        return handle(unit());
    })));
    globals.emplace("std::always::infix==", handle(subroutine([] (auto arguments_begin, auto) {
        auto a = (arguments_begin + 0)->template data<bool>();
        auto b = (arguments_begin + 1)->template data<bool>();
        return handle(a == b);
    })));

    for (auto&& subroutine : object.subroutines) {
        globals.emplace(
            object.strings[object.name] + "::" + object.strings[subroutine.name],
            handle(mill::subroutine([&] (auto arguments_begin, auto arguments_end) {
                auto& code = subroutine.body;
                tape<decltype(code.begin())> tape(code.begin(), code.end());
                return interpret(
                    tape,
                    arguments_begin,
                    arguments_end,
                    [&] (auto index) -> boost::optional<handle> {
                        try {
                            return globals.at(object.strings.at(index));
                        } catch (std::out_of_range const&) {
                            return boost::none;
                        }
                    },
                    [&] (auto index) -> boost::optional<handle> {
                        try {
                            return handle(string(object.strings.at(index)));
                        } catch (std::out_of_range const&) {
                            return boost::none;
                        }
                    }
                );
            }))
        );
    }

    std::vector<handle> arguments;
    globals.at("main::MAIN").data<subroutine>()(arguments.begin(), arguments.end());

    return 0;
}
{'fraction_non_alphanumeric': 0.15430595528005314, 'fraction_numerical': 0.0024352446313925173, 'mean_word_length': 2.35910780669145, 'pattern_counts': {'":': 1, '<': 52, '<?xml version=': 0, '>': 54, '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': '3553033', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1308, 'n_words': 252}