Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 98f44680b9
Fetching contributors…

Cannot retrieve contributors at this time

354 lines (281 sloc) 9.247 kb
$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) {
int type = value.get_type();
if (value.is_register_reference()) {
:PACT.Packfile.Register reg(type,
value.get_register_idx());
push(self.value, reg);
} else {
:PACT.Packfile.Constant c(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);
}
}
}
Jump to Line
Something went wrong with that request. Please try again.