Skip to content
Browse files

Add in a few off-the-top-of-my-head files for a Packfile layer to add…

… a prettier interface over the Parrot Packfile PMCs
  • Loading branch information...
1 parent aa08679 commit 35cf74b29daabddf228100fd6728dcb093a87910 @Whiteknight Whiteknight committed Dec 7, 2011
View
76 src/packfile/Constant.winxed
@@ -0,0 +1,76 @@
+class PACT.Packfile.Constant
+{
+ var value;
+}
+
+class PACT.Packfile.Constant.Integer : PACT.Packfile.Constant
+{
+ function Integer(int value)
+ {
+ self.value = value;
+ }
+
+ function get_value()
+ {
+ return int(self.value);
+ }
+
+ function get_type()
+ {
+ return "int";
+ }
+}
+
+class PACT.Packfile.Constant.Number : PACT.Packfile.Constant
+{
+ function Number(float number)
+ {
+ self.value = number;
+ }
+
+ function get_value()
+ {
+ return float(self.value);
+ }
+
+ function get_type()
+ {
+ return "float";
+ }
+}
+
+class PACT.Packfile.Constant.String : PACT.Packfile.Constant
+{
+ function String(string s)
+ {
+ self.value = s;
+ }
+
+ function get_value()
+ {
+ return string(self.value);
+ {
+
+ function get_type()
+ {
+ return "string";
+ }
+}
+
+class PACT.Packfile.Constant.PMC : PACT.Packfile.Constant
+{
+ function PMC(var v)
+ {
+ self.value = v;
+ }
+
+ function get_value()
+ {
+ return self.value;
+ {
+
+ function get_type()
+ {
+ return "pmc";
+ }
+}
View
3 src/packfile/Label.winxed
@@ -0,0 +1,3 @@
+class PACT.Packfile.Label
+{
+}
View
53 src/packfile/Namespace.winxed
@@ -0,0 +1,53 @@
+class PACT.Packfile.Namespace
+{
+ var name;
+ var parent;
+ var children;
+
+ function Namespace(var parent, string name)
+ {
+ self.parent = parent;
+ self.name = name;
+ self.children = {}
+ }
+
+ function get_name()
+ {
+ return self.name;
+ }
+
+ function get_full_name()
+ {
+ if (self.parent == null) {
+ string full_name[] = [string(self.name)];
+ return full_name;
+ }
+ var name = self.parent.get_full_name();
+ push(string(self.name));
+ return name;
+ }
+
+ function __get_child(string n)
+ {
+ if (exists self.children[n])
+ return self.children[n];
+
+ var ns = new PACT.Packfile.Namespace(self, n);
+ self.children[n] = ns;
+ return ns;
+ }
+
+ function get_child_ns(var name)
+ {
+ if (name instanceof 'String') {
+ string n = string(name);
+ return self.__get_child(n);
+ } else {
+ string n = name.shift();
+ var child = self.__get_child(n);
+ if (elements(name) > 0)
+ child = child.get_child_ns(name);
+ return child
+ }
+ }
+}
View
46 src/packfile/Op.winxed
@@ -0,0 +1,46 @@
+class PACT.Packfile.Op
+{
+ var operation;
+ var results;
+ var operands;
+ var annotations;
+ var labels;
+
+ function Op(string name)
+ {
+ self.operation = name;
+ self.results = [];
+ self.operands = [];
+ self.annotations = {};
+ self.labels = [];
+ }
+
+ function add_results(var results [slurpy])
+ {
+ for (var r in results)
+ push(self.results, r);
+ }
+
+ function add_operands(var operands [slurpy])
+ {
+ for (var o in operands) {
+ push(self.operands, o);
+ }
+ }
+
+ function add_annotation(string name, string value)
+ {
+ self.annotations[name] = value;
+ }
+
+ function add_label(var label)
+ {
+ push(self.labels, label);
+ }
+
+ function get_opcode_pmc()
+ {
+ // TODO: Create and return a representation of this op expressed in
+ // terms of Parrot Opcode PMCs and raw argument arrays
+ }
+}
View
43 src/packfile/Packfile.winxed
@@ -0,0 +1,43 @@
+class PACT.Packfile
+{
+ var subs;
+ var name;
+ var root_ns;
+ var constants;
+
+ function Packfile(string name)
+ {
+ self.name = name;
+ self.root_ns = new PACT.Packfile.Namespace("");
+ self.constants = [];
+ }
+
+ function get_root_ns()
+ {
+ return self.root_ns;
+ }
+
+ function get_namespace(var name)
+ {
+ return self.root_ns.get_child_ns(name);
+ }
+
+ function new_sub(string name, var ns)
+ {
+ if (ns == null)
+ ns = self.root_ns;
+ var s = new PACT.Packfile.Subroutine(self, name, ns);
+ }
+
+ function add_constant(var constant)
+ {
+ // TODO: We need to de-duplicate. Do we do that on input or do that
+ // on output?
+ push(self.constants, constant);
+ }
+
+ function get_packfile()
+ {
+ // TODO: This is the biggie. Create the entire Packfile PMC structure
+ }
+}
View
111 src/packfile/Subroutine.winxed
@@ -0,0 +1,111 @@
+class PACT.Packfile.Subroutine
+{
+ var program;
+ var ops;
+ var name;
+ var flags;
+ var parent_namespace;
+ var annotations;
+ var identifier;
+ var variables;
+ var temp_variables;
+
+ function Subroutine(var program, string name, var parent_ns)
+ {
+ self.program = program;
+ self.parent_namespace = parent_ns;
+ self.name = name;
+ self.ops = [];
+ self.flags = {};
+ self.annotations = {};
+ self.variables = {};
+ self.temp_variables = [];
+ }
+
+ function add_flag(var flag)
+ {
+ string flag_name = flag.name();
+ self.flags[flag_name] = flag;
+ }
+
+ function add_ops(var ops [slurpy])
+ {
+ for (var o in ops)
+ push(self.ops, o);
+ }
+
+ function add_annotation(string name, string value)
+ {
+ self.annotations[name] = value;
+ }
+
+ function get_variable(string name, string type)
+ {
+ if (name != null && name != "") {
+ if (exists self.variables[name])
+ return self.variables[name];
+ }
+ var v;
+ switch(type) {
+ case "int":
+ v = new PACT.Packfile.Variable.Integer();
+ break;
+ case "float":
+ v = new PACT.Packfile.Variable.Number();
+ break;
+ case "string":
+ v = new PACT.Packfile.Variable.String();
+ break;
+ case "pmc":
+ v = new PACT.PAckfile.Variable.PMC();
+ break;
+ default:
+ die("Unknown variable type " + type);
+ }
+ if (name == null || name == "")
+ push(self.temp_variables, v);
+ else {
+ self.variables[name] = v;
+ v.set_id(name);
+ }
+ }
+
+ function get_constant(int i)
+ {
+ var c = new PACT.Packfile.Constant.Integer(i);
+ self.program.add_constant(c);
+ return c;
+ }
+
+ function get_constant(string s)
+ {
+ var c = new PACT.Packfile.Constant.String(s);
+ self.program.add_constant(c);
+ return c;
+ }
+
+ function get_constant(float n)
+ {
+ var c = new PACT.Packfile.Constant.Number(n);
+ self.program.add_constant(c);
+ return c;
+ }
+
+ function get_constant(var p)
+ {
+ var c = new PACT.Packfile.Constant.PMC(p);
+ self.program.add_constant(c);
+ return c;
+ }
+
+ // Get a value suitable to use with :subid
+ function get_unique_identifier()
+ {
+ string id = self.identifier;
+ if (id == null || id == "") {
+ id = self.__internal_get_unique_id();
+ self.identifier = id;
+ }
+ return id;
+ }
+}
View
28 src/packfile/Subroutine/Flag.winxed
@@ -0,0 +1,28 @@
+class PACT.Packfile.Subroutine.Flag
+{
+
+}
+
+class PACT.Packfile.Subroutine.Flag.Main : PACT.Packfile.Subroutine.Flag
+{
+}
+
+class PACT.Packfile.Subroutine.Flag.Tag : PACT.Packfile.Subroutine.Flag
+{
+ var tag_name;
+
+ function Tag(string name)
+ {
+ self.tag_name = name;
+ }
+}
+
+class PACT.Packfile.Subroutine.Flag.Outer : PACT.Packfile.Subroutine.Flag
+{
+ var outer_sub;
+
+ function Outer(var outer)
+ {
+ self.outer_sub = outer;
+ }
+}
View
64 src/packfile/Variable.winxed
@@ -0,0 +1,64 @@
+class PACT.Packfile.Variable
+{
+ var id; // A human-readable name for the variable
+ var index; // the actual register index (integer)
+ // TODO: It might be nice to store first/last use lifetime information for
+ // the register allocator to use.
+}
+
+class PACT.Packfile.Variable.Integer : PACT.Packfile.Variable
+{
+ function set_index(int idx)
+ {
+ }
+
+ function get_index()
+ {
+ }
+
+ function set_id(string id)
+ {
+ if (self.id != null && string(self.id) != "")
+ die("Cannot change a variable id once it has been set");
+ self.id = id;
+ }
+
+ function get_id()
+ {
+ string id = self.id;
+ if (id == null || id == "") {
+ id = self.__get_unique_id();
+ self.id = id;
+ }
+ return id;
+ }
+
+ function get_type()
+ {
+ return "int";
+ }
+}
+
+class PACT.Packfile.Variable.Number : PACT.Packfile.Packfile.Variable
+{
+ function get_type()
+ {
+ return "float";
+ }
+}
+
+class PACT.Packfile.Variable.String : PACT.Packfile.Variable
+{
+ function get_type()
+ {
+ return "string";
+ }
+}
+
+class PACT.Packfile.Variable.PMC : PACT.Packfile.Variable
+{
+ function get_type()
+ {
+ return "pmc";
+ }
+}

0 comments on commit 35cf74b

Please sign in to comment.
Something went wrong with that request. Please try again.