[svn:parrot] r38880 - in branches/tt504_annotations: src/pmc t/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sun May 17 22:17:52 UTC 2009


Author: bacek
Date: Sun May 17 22:17:52 2009
New Revision: 38880
URL: https://trac.parrot.org/parrot/changeset/38880

Log:
Reimplement unpack Annotations using new PMCs API

Modified:
   branches/tt504_annotations/src/pmc/packfileannotations.pmc
   branches/tt504_annotations/t/pmc/packfileannotations.t

Modified: branches/tt504_annotations/src/pmc/packfileannotations.pmc
==============================================================================
--- branches/tt504_annotations/src/pmc/packfileannotations.pmc	Sun May 17 21:40:34 2009	(r38879)
+++ branches/tt504_annotations/src/pmc/packfileannotations.pmc	Sun May 17 22:17:52 2009	(r38880)
@@ -31,6 +31,9 @@
 #include "pmc_packfileannotation.h"
 
 pmclass PackfileAnnotations extends PackfileSegment {
+    /* ConstantTable used for names lookup */
+    ATTR PMC *const_table;
+
     /* RPA of Annotation */
     ATTR PMC *annotations;
 
@@ -199,6 +202,7 @@
             segment = VTABLE_get_pmc_keyed_str(interp, directory, name);
             if (VTABLE_isa(interp, segment,
                     Parrot_str_new_constant(interp, "PackfileConstantTable"))) {
+                attrs->const_table = segment;
                 Parrot_PCCINVOKE(interp, attrs->keys,
                         Parrot_str_new_constant(interp, "set_constant_table"),
                         "P->", segment);
@@ -230,18 +234,33 @@
         /* Copy annotations to own array */
         VTABLE_set_integer_native(interp, attrs->annotations, a->num_entries);
         for (i = 0; i < a->num_entries; ++i) {
+            PackFile_Annotations_Entry *entry = a->entries[i];
+            PackFile_Annotations_Key   *key   = a->keys[entry->key];
             annotation = pmc_new(interp, enum_class_PackfileAnnotation);
 
             /* Poke directly to annotation attributes. */
-            /* FIXME We should just create proper Annotations */
-            /*
             annotation_attrs         = PARROT_PACKFILEANNOTATION(annotation);
-            annotation_attrs->value  = a->entries[i]->value;
-            annotation_attrs->key_id = a->entries[i]->key;
-            annotation_attrs->offset = a->entries[i]->bytecode_offset;
-
+            annotation_attrs->offset = entry->bytecode_offset;
+            annotation_attrs->name   = VTABLE_get_string_keyed_int(interp,
+                    attrs->const_table, key->name);
+            switch (key->type) {
+                case PF_ANNOTATION_KEY_TYPE_INT:
+                    VTABLE_set_integer_native(interp, annotation, entry->value);
+                    break;
+                case PF_ANNOTATION_KEY_TYPE_STR:
+                    VTABLE_set_string_native(interp, annotation,
+                        VTABLE_get_string_keyed_int(interp, attrs->const_table, entry->value));
+                    break;
+                case PF_ANNOTATION_KEY_TYPE_NUM:
+                    VTABLE_set_number_native(interp, annotation,
+                        VTABLE_get_number_keyed_int(interp, attrs->const_table, entry->value));
+                    break;
+                default:
+                    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE,
+                            "Unknown value type %d in Packfile Annotation", key->type);
+            }
+            
             VTABLE_set_pmc_keyed_int(interp, attrs->annotations, i, annotation);
-            */
         }
     }
 
@@ -294,6 +313,7 @@
             res->entries[i]->value              = entity_attrs->value;
             res->entries[i]->key                = entity_attrs->key_id;
         }
+        */
 
         return res;
     }

Modified: branches/tt504_annotations/t/pmc/packfileannotations.t
==============================================================================
--- branches/tt504_annotations/t/pmc/packfileannotations.t	Sun May 17 21:40:34 2009	(r38879)
+++ branches/tt504_annotations/t/pmc/packfileannotations.t	Sun May 17 22:17:52 2009	(r38880)
@@ -21,7 +21,7 @@
 
 .sub 'main' :main
 .include 'test_more.pir'
-    plan(14)
+    plan(16)
     test_sanity()
     test_handling_directory()
     test_unpack()
@@ -101,15 +101,17 @@
     constants = _find_segment_by_type(pf, "PackfileConstantTable")
     # "file"
     a = pfanns[0]
-    $I0 = a
-    $S0 = constants[$I0]
-    is($S0, "annotations.pir", "First annotation is correct")
+    $S0 = a.'get_name'()
+    is($S0, "file", "First annotation's name unpacked")
+    $S0 = a
+    is($S0, "annotations.pir", "First annotation's value is correct")
 
     # "creator"
     a = pfanns[1]
-    $I0 = a
-    $S0 = constants[$I0]
-    is($S0, "Parrot Foundation", "Second annotation is correct")
+    $S0 = a.'get_name'()
+    is($S0, "creator", "Second annotation's name unpacked")
+    $S0 = a
+    is($S0, "Parrot Foundation", "Second annotation's value is correct")
 
     # Two "line"
     a = pfanns[2]


More information about the parrot-commits mailing list