<commit_before>/*
 * Thicket
 * https://github.com/d-plaindoux/thicket
 *
 * Copyright (c) 2015 <NAME>
 * Licensed under the LGPL2 license.
 */

module.exports = (function() {
    
    'use strict';

    var naming = require('./naming.js'),
        importgen = require('../Thicket/generator/dependency.js'),
        codegen = require('../Thicket/generator/code.js'),
        abstractSyntax = require('../Thicket/generator/code2.js'),
        code = require('../Thicket/generator/objcode.js'),
        typegen = require('../Thicket/generator/type.js'),
        list = require('../Data/list.js'),
        fs = require('fs');

    function Writer(directory) {
        this.directory = directory;
    }

    function replacer(key,value) {
        if (key === "$location") {
            return undefined;
        } 
        
        return value;
    }
    

    Writer.prototype.specification = function (name, dependencies, entitites, debug) {
        var destination = fs.openSync(this.directory + "/" + naming.specification(name), "w");

        var specifications = {
            dependencies: dependencies.map(function(dependency) { return importgen.dependency(dependency); }),
            definitions: entitites.map(function(entity) { return typegen.entity(entity); })
        };

        if (debug) {
            fs.writeSync(destination, JSON.stringify(specifications));
        } else {
            fs.writeSync(destination, JSON.stringify(specifications, replacer));        
        }

        fs.closeSync(destination);    
    };

    Writer.prototype.code = function (name, allEntities, entitites, debug) {
        var destination = fs.openSync(this.directory + "/" + naming.code(name),"w");

        fs.writeSync(destination,"(function() {\n");
        fs.writeSync(destination,"return function(runtime) {\n");
        fs.writeSync(destination,"runtime.module('" + name + "',function() {\n");        
        entitites.map(function (entity) {
            codegen.entity(list(allEntities), entity, debug).map(function (codegen) {
                fs.writeSync(destination, codegen);
                fs.writeSync(destination, ";\n");
            });
        });
        fs.writeSync(destination,"});\n");
        fs.writeSync(destination,"};\n");
        fs.writeSync(destination,"}());");

        fs.closeSync(destination);
        
        this.code2(name, allEntities, entitites, debug);
    };

    Writer.prototype.code2 = function (name, allEntities, entitites, debug) {
        var destination = fs.openSync(this.directory + "/" + naming.objcode(name),"w");


        entitites.map(function (entity) {
            abstractSyntax.entity(list(allEntities), entity, debug).map(function (syntax) {
                try {
                    fs.writeSync(destination, JSON.stringify(code.objCode(code.deBruijnIndex(syntax))));
                    fs.writeSync(destination, "\n");
                } catch (e) {
                    console.log(e.stack);
                }
            });
        });

        fs.closeSync(destination);
    };

    return function(directory) {
        return new Writer(directory);
    };
}());<commit_msg>Fix compiler method name<commit_after>/*
 * Thicket
 * https://github.com/d-plaindoux/thicket
 *
 * Copyright (c) 2015 <NAME>
 * Licensed under the LGPL2 license.
 */

module.exports = (function() {
    
    'use strict';

    var naming = require('./naming.js'),
        importgen = require('../Thicket/generator/dependency.js'),
        codegen = require('../Thicket/generator/code.js'),
        abstractSyntax = require('../Thicket/generator/code2.js'),
        code = require('../Thicket/generator/objcode.js'),
        typegen = require('../Thicket/generator/type.js'),
        list = require('../Data/list.js'),
        fs = require('fs');

    function Writer(directory) {
        this.directory = directory;
    }

    function replacer(key,value) {
        if (key === "$location") {
            return undefined;
        } 
        
        return value;
    }
    

    Writer.prototype.specification = function (name, dependencies, entitites, debug) {
        var destination = fs.openSync(this.directory + "/" + naming.specification(name), "w");

        var specifications = {
            dependencies: dependencies.map(function(dependency) { return importgen.dependency(dependency); }),
            definitions: entitites.map(function(entity) { return typegen.entity(entity); })
        };

        if (debug) {
            fs.writeSync(destination, JSON.stringify(specifications));
        } else {
            fs.writeSync(destination, JSON.stringify(specifications, replacer));        
        }

        fs.closeSync(destination);    
    };

    Writer.prototype.code = function (name, allEntities, entitites, debug) {
        var destination = fs.openSync(this.directory + "/" + naming.code(name),"w");

        fs.writeSync(destination,"(function() {\n");
        fs.writeSync(destination,"return function(runtime) {\n");
        fs.writeSync(destination,"runtime.module('" + name + "',function() {\n");        
        entitites.map(function (entity) {
            codegen.entity(list(allEntities), entity, debug).map(function (codegen) {
                fs.writeSync(destination, codegen);
                fs.writeSync(destination, ";\n");
            });
        });
        fs.writeSync(destination,"});\n");
        fs.writeSync(destination,"};\n");
        fs.writeSync(destination,"}());");

        fs.closeSync(destination);
        
        this.code2(name, allEntities, entitites, debug);
    };

    Writer.prototype.code2 = function (name, allEntities, entitites, debug) {
        var destination = fs.openSync(this.directory + "/" + naming.objcode(name),"w");


        entitites.map(function (entity) {
            abstractSyntax.entity(list(allEntities), entity, debug).map(function (syntax) {
                try {
                    fs.writeSync(destination, JSON.stringify(code.generateObjCode(code.deBruijnIndex(syntax))));
                    fs.writeSync(destination, "\n");
                } catch (e) {
                    console.log(e.stack);
                }
            });
        });

        fs.closeSync(destination);
    };

    return function(directory) {
        return new Writer(directory);
    };
}());
{'fraction_non_alphanumeric': 0.15211535414355887, 'fraction_numerical': 0.0025352559023926477, 'mean_word_length': 2.246913580246914, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5179640', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1710, 'n_words': 289}