[svn:parrot] r43878 - branches/op_pmcs/src/pmc

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Thu Feb 11 02:45:42 UTC 2010


Author: whiteknight
Date: Thu Feb 11 02:45:38 2010
New Revision: 43878
URL: https://trac.parrot.org/parrot/changeset/43878

Log:
remove opfamily PMC, it was a non-starter. Flesh out oplib and opcode a little bit. Now contains all the basic functionality I think we need

Deleted:
   branches/op_pmcs/src/pmc/opfamily.pmc
Modified:
   branches/op_pmcs/src/pmc/opcode.pmc
   branches/op_pmcs/src/pmc/oplib.pmc

Modified: branches/op_pmcs/src/pmc/opcode.pmc
==============================================================================
--- branches/op_pmcs/src/pmc/opcode.pmc	Wed Feb 10 19:28:27 2010	(r43877)
+++ branches/op_pmcs/src/pmc/opcode.pmc	Thu Feb 11 02:45:38 2010	(r43878)
@@ -2,6 +2,7 @@
 
 pmclass Opcode {
     ATTR op_info_t *info;
+    ATTR INTVAL op_number;
     ATTR STRING *full_name_cache;
 
     VTABLE void set_pointer(void *i) {
@@ -9,6 +10,33 @@
         attrs->info = i;
     }
 
+    VTABLE void set_string_native(STRING *name) {
+        const char * const cstr = Parrot_str_to_cstring(INTERP, name);
+        const INTVAL num = interp->op_lib->op_code(cstr, 1);
+        Parrot_str_free_cstring(INTERP, cstr);
+        if (num == -1)
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
+                "Opcode: Opcode %S not found", name);
+        VTABLE_set_integer_native(INTERP, SELF, num);
+    }
+
+    VTABLE INTVAL get_integer() {
+        Parrot_Opcode_attributes * const attrs = PARROT_OPCODE(SELF);
+        if (!attrs->info)
+            return -1;
+        return attrs->op_number;
+    }
+
+    VTABLE void set_integer_native(INTVAL value) {
+        const INTVAL opcount = interp->op_lib->op_count;
+        Parrot_Opcode_attributes * const attrs = PARROT_OPCODE(SELF);
+        if (value >= opcount || value < 0)
+            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_OUT_OF_BOUNDS,
+                "Opcode: Opcode index %d out of bounds", value);
+        attrs->info = &(inter->op_info_table[value]);
+        attrs->op_number = value;
+    }
+
     VTABLE STRING *get_string() {
         Parrot_Opcode_attributes * const attrs = PARROT_OPCODE(SELF);
         if (attrs->full_name == NULL) {
@@ -19,5 +47,4 @@
         }
         return attrs->full_name_cache;
     }
-
-}
\ No newline at end of file
+}

Deleted: branches/op_pmcs/src/pmc/opfamily.pmc
==============================================================================
--- branches/op_pmcs/src/pmc/opfamily.pmc	Thu Feb 11 02:45:38 2010	(r43877)
+++ /dev/null	00:00:00 1970	(deleted)
@@ -1,22 +0,0 @@
-#include "parrot/parrot.h"
-
-pmclass OpFamily {
-    VTABLE void set_string_native(STRING *name) {
-        /* TODO: Set the name of this family. Look up in the oplib for all
-           ops with the same short-name and add them to the internal list */
-    }
-
-    VTABLE PMC *get_pmc_keyed_string(STRING *name) {
-        /* TODO: name will contain the signature "p_sc_i" of the specific op
-           to look up. Return a new Opcode PMC corresponding to that op */
-    }
-
-    VTABLE PMC *get_pmc_keyed_int(INTVAL value) {
-        /* TODO: Return the Opcode PMC with the given INTVAL number, PMCNULL
-           if it's not part of this family */
-    }
-
-    VTABLE STRING *get_string() {
-        /* TODO: Return the name of this family */
-    }
-}
\ No newline at end of file

Modified: branches/op_pmcs/src/pmc/oplib.pmc
==============================================================================
--- branches/op_pmcs/src/pmc/oplib.pmc	Wed Feb 10 19:28:27 2010	(r43877)
+++ branches/op_pmcs/src/pmc/oplib.pmc	Thu Feb 11 02:45:38 2010	(r43878)
@@ -2,11 +2,20 @@
 
 pmclass OpLib {
     VTABLE PMC *get_pmc_keyed_string(STRING *name) {
-        /* TODO: lookup the name in the table. Create and return an OpFamily
-           PMC with all the names */
+        PMC * const family = pmc_new(INTERP, enum_class_OpFamily);
+        VTABLE_set_string_native(INTERP, name);
+        if (!VTABLE_elements(INTERP, family))
+            return PMCNULL;
+        return family;
     }
 
     VTABLE PMC *get_pmc_keyed_int(INTVAL value) {
-        /* TODO: Return the Opcode PMC with the given number */
+        PMC * const op = pmc_new(INTERP, enum_class_Opcode)
+        VTABLE_set_integer_native(INTERP, op, value);
+        return op;
+    }
+
+    VTABLE INTVAL get_integer() {
+        return interp->op_lib->op_count;
     }
 }


More information about the parrot-commits mailing list