Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f6ce9b11bc
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 353 lines (280 sloc) 9.222 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
$include_const 'call_bits.pasm';

class PACT.Packfile {
    // Constants
    var floats; // RFA
    var pmcs; // RPA
    var strings; // RSA

    // Root namespace
    var root; // Namespace

    // Main sub
    var main; // Subroutine

    // Opcode libraries
    var oplibs; // RPA of OpLibs

    // Header
    // Most header values can't really be changed, so aren't variables.
    var uuid_type; // Integer
    var uuid; // String

    function Packfile() {
        self.floats = new 'ResizableFloatArray';
        self.pmcs = new 'ResizablePMCArray';
        self.strings = new 'ResizableStringArray';
        self.root = new PACT.Packfile.Namespace();
        self.main = null;
        self.uuid_type = 0;
        self.uuid = '';

        self.oplibs = {
            'core_ops': new 'OpLib'(var('core_ops'))
        };
    }

    function set_uuid(int type, string uuid) {
        self.uuid_type = type;
        self.uuid = uuid;
    }

    function add_oplib(var name) {
        if (exists self.oplibs[name])
            return;

        var oplib = new 'OpLib'(name);
        if (oplib == null)
            die("Couldn't get oplib '"+name+"'");

        self.oplibs[name] = oplib;
    }

    function __dump(var dumper, string label) {
        :(string indent, string subindent) = dumper.newIndent();
        say('{');

        say(indent, 'uuid: ', self.uuid_type, ' "', self.uuid, '",');

        print(indent, 'floats: ');
        dumper.dump('floats', self.floats);

        print(",\n", indent, 'strings: ');
        dumper.dump('strings', self.strings);

        print(",\n", indent, 'pmcs: ');
        dumper.dump('pmcs', self.pmcs);

        print(",\n", indent, 'oplibs: ');
        dumper.dump('oplibs', self.oplibs);

        print(",\n", indent, 'root: ');
        dumper.dump('root', self.root);

        print(",\n", indent, 'main: ');
        print( (self.main == null) ? '(none)' : self.main.name );

        print("\n", subindent, '}');
        dumper.deleteIndent();
    }

    // Functions similar to PackfileView
}

namespace PACT.Packfile {
    class Namespace {
        var name; // String
        var contents; // Hash

        // Should act hash-like
        function Namespace() {
            self.Namespace('');
        }

        function Namespace(string name) {
            self.name = name;
            self.contents = {};
        }

        function __dump(dumper, label) {
            print( self.name, ": " );
            dumper.dump(label, self.contents);
        }
    }

    class Constant {
        var value;
        var type; // Integer, from call_bits

        function Constant(int value) {
            self.value = value;
            self.type = PARROT_ARG_INTVAL;
        }

        function Constant(string value) {
            self.value = value;
            self.type = PARROT_ARG_STRING;
        }

        function Constant(float value) {
            self.value = value;
            self.type = PARROT_ARG_FLOATVAL;
        }

        function Constant(var value) {
            self.value = value;
            self.type = PARROT_ARG_PMC;
        }

        function Constant(int type, var value) {
            self.type = type;
            switch (type) {
            case PARROT_ARG_INTVAL:
                self.value = int(value);
                break;

            case PARROT_ARG_STRING:
                self.value = string(value);
                break;

            case PARROT_ARG_FLOATVAL:
                self.value = float(value);
                break;

            case PARROT_ARG_PMC:
                self.value = value;
                break;

            default:
                die("Unknown type "+type);
            }
        }

        function __dump(var dumper, string label) {
            switch (self.type) {
            case PARROT_ARG_INTVAL:
                print('INT: ');
                break;

            case PARROT_ARG_STRING:
                print('STRING: ');
                break;

            case PARROT_ARG_FLOATVAL:
                print('FLOAT: ');
                break;

            case PARROT_ARG_PMC:
                print('PMC: ');
                break;

            default:
                print('???: ');
            }
            dumper.dump(label, self.value);
        }

        // set from all types?
    }

    namespace Constant {
        // A reference to something in the constants table
        class Reference : Constant {
            // uses value as an index into a table
            var packfile; // needs this for lookups

            function Reference(var packfile, int type, var value) {
                self.type = type;
                self.value = value;
                self.packfile = packfile;
            }

            // dereference
        }

        class Key : Constant {
            function Key() {
                self.type = PARROT_ARG_PMC;
                self.value = [];
            }

            function Key[multi('_', 'Key')](var value) {
                self.Key();
                while (value != null) {
                    if (value.is_register_reference()) {
                        :PACT.Packfile.Register reg(value.get_type(),
                                value.get_register_idx());
                        push(self.value, reg);
                    } else {
                        :PACT.Packfile.Constant c(value.get_type(), value);
                        push(self.value, c);
                    }
                    value = shift_var(value);
                }
            }

            // convert to Key
        }
    }

    // Below are found in Namespace.contents

    class Subroutine {
        var name; // String
        var ops; // RPA
        
        // Stored by Sub PMC
        // visit: namespace_name, multi_sig, outer_sub, lex_info
        // freeze: start/end offset, flags, name, method_name, ns_entry_name
        // hll_name, comp_flags, vtable_index, registers, subid

        function Subroutine() {
            self.name = null;
            self.ops = [];
        }

        function Subroutine(string name) {
            self.Subroutine();
            self.name = name;
        }

        function __dump(var dumper, string label) {
            print(self.name, ': ');
            dumper.dump(label, self.ops);
        }
    }

    class Multi {
        var name; // String
        var canidates; // RPA

        function Multi(string name) {
            self.name = name;
            self.canidates = [];
        }
    }

    // Below are in Subroutine.ops

    class Op {
        var name; // String
        var args; // RPA

        function Op(string name) {
            self.name = name;
            self.args = [];
        }

        function __dump(var dumper, string label) {
            :(string indent, string subindent) = dumper.newIndent();
            print(self.name, " [");
            string comma = "\n";
            int size = elements(self.args);
            for(int i = 0; i < size; ++i) {
                print(comma, indent);
                dumper.dump(i, self.args[i]);
                comma = ",\n";
            }
            print("\n", subindent, "]");
            dumper.deleteIndent();
        }
    }

    class Label {
        var name; // String

        function Label(string name) {
            self.name = name;
        }

        function __dump(var dumper, string label) {
            print(self.name);
        }
    }

    class Register {
        var type; // Integer, from call_bits
        var number; // Integer

        function Register(int type, int number) {
            self.type = type;
            self.number = number;
        }

        function __dump(var dumper, string label) {
            switch (self.type) {
            case PARROT_ARG_INTVAL: print('I'); break;
            case PARROT_ARG_STRING: print('S'); break;
            case PARROT_ARG_PMC: print('P'); break;
            case PARROT_ARG_FLOATVAL: print('F'); break;
            default: print('?');
            }
            print(int(self.number));
        }
    }

    class Annotation {
        var name; // String
        var value; // Constant
        var pc; // Integer

        function Annotation(string name, var value) {
            if (!(value instanceof PACT.Packfile.Constant))
                die('Annotation value must be a constant');
            if (value.type == PARROT_ARG_FLOATVAL)
                die('Annotations can not be floats');

            self.name = name;
            self.value = value;
        }

        function __dump(var dumper, string label) {
            :(string indent, string subindent) = dumper.newIndent();
            print(self.name, ": {\n", indent);
            dumper.dump(self.name, self.value);
            print("\n", subindent, '}');
            dumper.deleteIndent();
        }
    }

    class Debug {
        var filename; // String
        var pc; // Integer

        function Debug(string filename) {
            self.filename = filename;
        }

        function __dump(var dumper, string label) {
            print(self.filename);
        }
    }
}
Something went wrong with that request. Please try again.