<commit_before>/*jshint browser: true, devel: true, bitwise: true, camelcase: true, curly: true, eqeqeq: true, forin: true, immed: true, indent: 4, latedef: true, newcap: true, noarg: true, noempty: true, nonew: true, regexp: true, undef: true, unused: true, strict: true*/
/*global require*/
require(["reader", "expander", "evaluator", "compiler", "util"], function (reader, expander, evaluator, compiler, util) {

    "use strict";
    
    function trace() {
        var arr = Array.prototype.slice.apply(arguments);
        var out = document.getElementById(arr[0]);
        out.innerHTML += arr.slice(1).join(" ") + "\n";
    }

    var errored = false;

    function run(cat, name, input, runner) {
        if (errored) {
            return;
        }
        document.getElementById(cat).parentNode.className = "block populated";
        trace(cat, name + ":");
        if (Array.isArray(input)) {
            for (var i = 0; i < input.length; i++) {
                trace(cat, input[i], "=", runner(input[i]));
            }
        } else {
            trace(cat, input, "=", runner(input));
        }
        trace(cat);
    }
    
    function read(name, input) {
        run("reader", name, input, function (x) {
            return util.printRawForm(reader.read(x));
        });
    } 
    
    function expand(name, input) {
        run("expander", name, input, function (x) {
            return util.printRawForm(expander.expand(reader.read(x)));
        });
    }    
    
    function evaluate(name, input) {
        run("evaluator", name, input, function (x) {
            return evaluator.print(evaluator.evaluate(expander.expand(reader.read(x))).value);
        });
    }    
    
    function compile(name, input) {
        run("compiler", name, input, function (x) {
            return "\n    " + compiler.compile(expander.expand(reader.read(x))).replace(/\n/g, "\n    ");
        });
    }

    window.onload = function () {

        var t = new Date().getTime();

        read("symbols", ["a", "lower", "UPPER", "camelCase", "CamelCase", "j0", "hyphen-ated", "under_scored", "dot.ted", ".length", "úņīčőđē"]);
        
        read("numbers", ["5", "5.2"]);
        read("hex numbers", "0xFF");
        
        read("booleans", ["#t", "#f"]);
        
        read("strings", ['"word"', '"how long is a piece of..."; string', '"escape \\"this\\""']);
        
        read("comments", ["; sup?", "; an expr:\n(do 1)"]);
        
        read("empty paren list", "()");
        read("empty bracket list", "[]");
        read("empty brace list", "{}");   
        
        read("1-item paren list", "(a)");
        read("1-item bracket list", "[a]");
        read("1-item brace list", "{a}");
        <commit_msg>Ev(a|i)luate compiler output<commit_after>/*jshint browser: true, devel: true, bitwise: true, camelcase: true, curly: true, eqeqeq: true, forin: true, immed: true, indent: 4, latedef: true, newcap: true, noarg: true, noempty: true, nonew: true, regexp: true, undef: true, unused: true, strict: true*/
/*global require*/
require(["reader", "expander", "evaluator", "compiler", "util"], function (reader, expander, evaluator, compiler, util) {

    "use strict";
    
    function trace() {
        var arr = Array.prototype.slice.apply(arguments);
        var out = document.getElementById(arr[0]);
        out.innerHTML += arr.slice(1).join(" ") + "\n";
    }

    var errored = false;

    function run(cat, name, input, runner) {
        if (errored) {
            return;
        }
        document.getElementById(cat).parentNode.className = "block populated";
        trace(cat, name + ":");
        if (Array.isArray(input)) {
            for (var i = 0; i < input.length; i++) {
                trace(cat, input[i], "=", runner(input[i]));
            }
        } else {
            trace(cat, input, "=", runner(input));
        }
        trace(cat);
    }
    
    function read(name, input) {
        run("reader", name, input, function (x) {
            return util.printRawForm(reader.read(x));
        });
    } 
    
    function expand(name, input) {
        run("expander", name, input, function (x) {
            return util.printRawForm(expander.expand(reader.read(x)));
        });
    }    
    
    function evaluate(name, input) {
        run("evaluator", name, input, function (x) {
            return evaluator.print(evaluator.evaluate(expander.expand(reader.read(x))).value);
        });
    }    
    
    function compile(name, input) {
        run("compiler", name, input, function (x) {
            /*jshint evil: true*/
            var js = compiler.compile(expander.expand(reader.read(x))).replace(/\n/g, "\n    ");
            return "\n    " + js + "\n" + prettyPrint(eval(js)) + "\n";
        });
    }
    
    function prettyPrint(value) {
        if (Array.isArray(value)) {
            var items = [];
            for (var i = 0, l = value.length; i < l; i++) {
                items[i] = prettyPrint(value[i]);
            }
            return "[" + items.join(", ") + "]";
        }
        if (typeof value === "string") {
            return '"' + value + '"';
        }
        return value.toString();
    }

    window.onload = function () {

        var t = new Date().getTime();

        read("symbols", ["a", "lower", "UPPER", "camelCase", "CamelCase", "j0", "hyphen-ated", "under_scored", "dot.ted", ".length", "úņīčőđē"]);
        
        read("numbers", ["5", "5.2"]);
        read("hex numbers", "0xFF");
        
        read("booleans", ["#t", "#f"]);
        
        read("strings", ['"word"', '"how long is a piece of..."; string', '"escape \\"this\\""']);
        
        read("comments", ["; sup?", "; an expr:\n(do 1)"]);
        
        read("empty paren list", "()");
        read("empty bracket list", "[]");
        read("empty brace list", "{}");   
        
        read("1-item paren list", "(a)");
        read("1-item bracket list", "[a]");
        read("1-item brace list", "{a}");
        
{'fraction_non_alphanumeric': 0.1887925283522348, 'fraction_numerical': 0.0045030020013342225, 'mean_word_length': 2.116943866943867, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 3, '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': '6459004', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1864, 'n_words': 442}