<commit_before>(function(exports) {
    "use strict";

    function repeat(x, n) {
        var L = [];
        for (var i = 0; i < n; i++)
            L.push(x);
        return L;
    }

    function StructWrapper(props) {
        var type = props.StructName;
        var typeInfo = Runtime.typeInfo['%struct.' + type];
        var size = typeInfo.flatSize;

        var fieldNames = props.Fields;
        if (typeInfo.fields.length != fieldNames.length)
            throw new Error("Invalid fields");

        var constructor = function(ptr) {
            this.$internal = ptr;
        };
        constructor.type = type;
        constructor.typeInfo = typeInfo;
        constructor.size = typeInfo.flatSize;

        var descs = {};

        fieldNames.forEach(function(name, i) {
            var off = typeInfo.flatIndexes[i];
            var type = typeInfo.fields[i];
            descs[name] = { get: function() {
                return getValue(this.$internal + off, type);
            } };
        });

        Object.defineProperties(constructor.prototype, descs);

        return constructor;
    }

    function TypeWrapper(props) {
        var type = props.TypeName;
        var typeInfo = Runtime.typeInfo['%struct.' + type];
        var size = typeInfo.flatSize;

        var init = props.Initialize;
        var free = props.Finalize;

        var constructor = function() {
            this.__construct__();
            this.__init__();
        };

        constructor.type = type;
        constructor.typeInfo = typeInfo;
        constructor.size = size;

        var proto = constructor.prototype;
        props.AutoBind.forEach(function(desc) {
            var name = desc.name;
            var args = ['this'].concat(desc.args);
            var nargs = args.length;

            var cname = type + '_' + name.replace(/^_/, '');
            proto[name] = function() {
                var args = [].slice.call(arguments);
                args.unshift(this);
                args = args.map(function(x) {
                    if (x.$internal)
                        return x.$internal;
                    else
                        return x;
                });
                if (args.length != nargs)
                    throw new Error("Invalid number of args to " + cname);

                return ccall(cname, 'number', repeat('number', nargs), args);
            };
        });

        proto.__init__ = function() {
            this[init].apply(this, arguments);
        };

        proto.__construct__ = function() {
            this.$internal = _malloc(size);
        };

        proto.finalize = function() {
            _free(this.$internal);
            // it seems emscripten has issues with _free right now
            // this[free].apply(this, arguments);
        };

        return constructor;
    }

    var Box = new StructWrapper({
        StructName: 'pixman_box32',
        Fields: ['x1', 'y1', 'x2', 'y2']
    });
    Object.defineProperties(Box.prototype, {
        x: { get: function() { return this.x1; } },
        y: { get: function() { return this.y1; } },
        width: { get: function() { return this.x2 - this.x1; } },
        height: { get: function() { return this.y2 - this.y1; } },
    });
    Box.prototype.toString = function() {
        return "+{x}+{y}x{width}x{height}".replace(/{(\w+)}/g, (function(match, name) {
            return this[name];
        }).bind(this));
    };

    var Region = new TypeWrapper({
        TypeName: 'pixman_region32',
        Initialize: 'init',
        Finalize: 'fini',
        AutoBind: [
            {name: "init", args: []},<commit_msg>Properly free pixman regions<commit_after>(function(exports) {
    "use strict";

    function repeat(x, n) {
        var L = [];
        for (var i = 0; i < n; i++)
            L.push(x);
        return L;
    }

    function StructWrapper(props) {
        var type = props.StructName;
        var typeInfo = Runtime.typeInfo['%struct.' + type];
        var size = typeInfo.flatSize;

        var fieldNames = props.Fields;
        if (typeInfo.fields.length != fieldNames.length)
            throw new Error("Invalid fields");

        var constructor = function(ptr) {
            this.$internal = ptr;
        };
        constructor.type = type;
        constructor.typeInfo = typeInfo;
        constructor.size = typeInfo.flatSize;

        var descs = {};

        fieldNames.forEach(function(name, i) {
            var off = typeInfo.flatIndexes[i];
            var type = typeInfo.fields[i];
            descs[name] = { get: function() {
                return getValue(this.$internal + off, type);
            } };
        });

        Object.defineProperties(constructor.prototype, descs);

        return constructor;
    }

    function TypeWrapper(props) {
        var type = props.TypeName;
        var typeInfo = Runtime.typeInfo['%struct.' + type];
        var size = typeInfo.flatSize;

        var init = props.Initialize;
        var free = props.Finalize;

        var constructor = function() {
            this.__construct__();
            this.__init__();
        };

        constructor.type = type;
        constructor.typeInfo = typeInfo;
        constructor.size = size;

        var proto = constructor.prototype;
        props.AutoBind.forEach(function(desc) {
            var name = desc.name;
            var args = ['this'].concat(desc.args);
            var nargs = args.length;

            var cname = type + '_' + name.replace(/^_/, '');
            proto[name] = function() {
                var args = [].slice.call(arguments);
                args.unshift(this);
                args = args.map(function(x) {
                    if (x.$internal)
                        return x.$internal;
                    else
                        return x;
                });
                if (args.length != nargs)
                    throw new Error("Invalid number of args to " + cname);

                return ccall(cname, 'number', repeat('number', nargs), args);
            };
        });

        proto.__init__ = function() {
            this[init].apply(this, arguments);
        };

        proto.__construct__ = function() {
            this.$internal = _malloc(size);
        };

        proto.finalize = function() {
            this[free].apply(this, arguments);
        };

        return constructor;
    }

    var Box = new StructWrapper({
        StructName: 'pixman_box32',
        Fields: ['x1', 'y1', 'x2', 'y2']
    });
    Object.defineProperties(Box.prototype, {
        x: { get: function() { return this.x1; } },
        y: { get: function() { return this.y1; } },
        width: { get: function() { return this.x2 - this.x1; } },
        height: { get: function() { return this.y2 - this.y1; } },
    });
    Box.prototype.toString = function() {
        return "+{x}+{y}x{width}x{height}".replace(/{(\w+)}/g, (function(match, name) {
            return this[name];
        }).bind(this));
    };

    var Region = new TypeWrapper({
        TypeName: 'pixman_region32',
        Initialize: 'init',
        Finalize: 'fini',
        AutoBind: [
            {name: "init", args: []},
{'fraction_non_alphanumeric': 0.13579387186629527, 'fraction_numerical': 0.004178272980501393, 'mean_word_length': 1.6429885903570114, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4705501', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1961, 'n_words': 455}