[svn:parrot] r38081 - branches/packfile_revamp/src/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sun Apr 12 09:53:35 UTC 2009


Author: bacek
Date: Sun Apr 12 09:53:35 2009
New Revision: 38081
URL: https://trac.parrot.org/parrot/changeset/38081

Log:
PackfileAnnotationKeys scaffolding and reader interface.

Modified:
   branches/packfile_revamp/src/pmc/packfileannotationkeys.pmc

Modified: branches/packfile_revamp/src/pmc/packfileannotationkeys.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfileannotationkeys.pmc	Sun Apr 12 09:53:19 2009	(r38080)
+++ branches/packfile_revamp/src/pmc/packfileannotationkeys.pmc	Sun Apr 12 09:53:35 2009	(r38081)
@@ -26,10 +26,94 @@
 
 #include "parrot/parrot.h"
 
+/*
+Fetch PackfileConstantTable from PackfileAnnotationKeys.
+Throw exception if table wasn't initilized.
+*/
+static PMC *
+fetch_const_table(PARROT_INTERP, PMC *self) {
+    PMC * table = PARROT_PACKFILEANNOTATIONKEYS(self)->const_table;
+    if (!table)
+        Parrot_ex_throw_from_c_args(interp, NULL,
+                EXCEPTION_PARROT_USAGE_ERROR, "Wrong Annotation initialization");
+
+    return table;
+}
+
 pmclass PackfileAnnotationKeys {
+    /* ConstantTable used for names lookup */
+    ATTR PMC *const_table;
+
+    /* RIA of Names */
+    ATTR PMC *names;
+
+    /* RIA of Types */
+    ATTR PMC *types;
+
+/*
+
+=item C<void init()>
+
+Initialize PackfileAnnotationKeys.
+
+=cut
+
+*/
+    VTABLE void init() {
+        Parrot_PackfileAnnotationKeys_attributes * attrs =
+                mem_allocate_zeroed_typed(Parrot_PackfileAnnotationKeys_attributes);
+
+        attrs->const_table = NULL;
+        attrs->names       = pmc_new(interp, enum_class_ResizableIntegerArray);
+        attrs->types       = pmc_new(interp, enum_class_ResizableIntegerArray);
+
+        PObj_custom_mark_destroy_SETALL(SELF);
+        PMC_data(SELF) = attrs;
+    }
 
 /*
 
+=item C<void mark()>
+
+Marks the object as live.
+
+=cut
+
+*/
+
+    VTABLE void mark() {
+        Parrot_PackfileAnnotationKeys_attributes * attrs =
+                PARROT_PACKFILEANNOTATIONKEYS(SELF);
+
+        if (attrs->const_table)
+            pobject_lives(interp, (PObj *)attrs->const_table);
+        if (attrs->names)
+            pobject_lives(interp, (PObj *)attrs->names);
+        if (attrs->types)
+            pobject_lives(interp, (PObj *)attrs->types);
+    }
+
+/*
+
+=item C<void destroy()>
+
+Destroys the PMC and frees all allocated memory.
+
+=cut
+
+*/
+
+    VTABLE void destroy() {
+        Parrot_PackfileAnnotationKeys_attributes * attrs =
+                PARROT_PACKFILEANNOTATIONKEYS(SELF);
+
+        if (attrs) {
+            mem_sys_free(attrs);
+            PMC_data(SELF) = NULL;
+        }
+    }
+/*
+
 =item C<STRING *get_string_keyed_int(INTVAL index)>
 
 Fetch the given entry's name key.
@@ -38,7 +122,13 @@
 
 */
     VTABLE STRING *get_string_keyed_int(INTVAL index)  {
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+        Parrot_PackfileAnnotationKeys_attributes *attrs =
+                PARROT_PACKFILEANNOTATIONKEYS(SELF);
+
+        PMC     *const_table = fetch_const_table(interp, SELF);
+        INTVAL   const_index = VTABLE_get_integer_keyed_int(interp,
+                attrs->names, index);
+        return VTABLE_get_string_keyed_int(interp, attrs->const_table, const_index);
     }
 
 
@@ -66,7 +156,13 @@
 
 */
     VTABLE INTVAL get_integer_keyed_int(INTVAL index)  {
-        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+        Parrot_PackfileAnnotationKeys_attributes *attrs =
+                PARROT_PACKFILEANNOTATIONKEYS(SELF);
+
+        /* Just ensure sematics */
+        PMC * const_table = fetch_const_table(interp, SELF);
+
+        return VTABLE_get_integer_keyed_int(interp, attrs->types, index);
     }
 
 
@@ -83,8 +179,44 @@
         Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
     }
 
+/*
+
+=item C<void set_const_table(PMC *table)>
+
+Set PackfileConstantTable used for Key names lookup.
+
+=cut
+
+*/
+    METHOD set_const_table(PMC *table) {
+        PARROT_PACKFILEANNOTATIONKEYS(SELF)->const_table = table;
+    }
+
+/*
+
+=item C<void set_pointer()>
+
+Initialize from PackFile_Annotation pointer.
+
+=cut
+
+*/
+    VTABLE void set_pointer(void *pointer) {
+        PackFile_Annotations *annotations = (PackFile_Annotations*)pointer;
+        Parrot_PackfileAnnotationKeys_attributes *attrs =
+                PARROT_PACKFILEANNOTATIONKEYS(SELF);
+        opcode_t i;
+
+        for (i = 0; i < annotations->num_keys; ++i) {
+            VTABLE_set_integer_keyed_int(interp, attrs->names,
+                    i, annotations->keys[i]->name);
+            VTABLE_set_integer_keyed_int(interp, attrs->types,
+                    i, annotations->keys[i]->type);
+        }
+    }
 
 }
+
 /*
 
 =back


More information about the parrot-commits mailing list