[svn:parrot] r38085 - in branches/packfile_revamp: src/pmc t/pmc

bacek at svn.parrot.org bacek at svn.parrot.org
Sun Apr 12 09:54:40 UTC 2009


Author: bacek
Date: Sun Apr 12 09:54:40 2009
New Revision: 38085
URL: https://trac.parrot.org/parrot/changeset/38085

Log:
Override PackfileAnnotations.set_diretory method.

Find ConstantTable and propagate it into PackfileAnnotationKeys.
Also add small description for rationale of this behaviour.

Modified:
   branches/packfile_revamp/src/pmc/packfileannotations.pmc
   branches/packfile_revamp/src/pmc/packfileconstanttable.pmc
   branches/packfile_revamp/t/pmc/packfileannotations.t

Modified: branches/packfile_revamp/src/pmc/packfileannotations.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfileannotations.pmc	Sun Apr 12 09:54:21 2009	(r38084)
+++ branches/packfile_revamp/src/pmc/packfileannotations.pmc	Sun Apr 12 09:54:40 2009	(r38085)
@@ -16,6 +16,8 @@
 for the list of common methods every packfile segment pmc must implement; see
 PDD13 for the design spec.
 
+To works properly PackfileAnnotations has to be added to PackfileDirectory with
+PackfileConstantTable. Otherwise PackfileAnnotationKey can't be created.
 
 =head2 Methods
 
@@ -171,6 +173,38 @@
         VTABLE_set_pmc_keyed_int(interp, annotations, index, annotation);
     }
 
+/*
+
+=item C<void set_directory()>
+
+Handle setting of ownershit.
+
+Find PackfileConstantTable in PackfileDirectory and pass it to
+PackfileAnnotationKeys.
+
+=cut
+
+*/
+
+    METHOD set_directory(PMC *directory) {
+        Parrot_PackfileAnnotations_attributes *attrs =
+                PARROT_PACKFILEANNOTATIONS(SELF);
+        STRING *name;
+        PMC    *segment;
+
+        PMC *iter = VTABLE_get_iter(interp, directory);
+        while (VTABLE_get_bool(interp, iter)) {
+            name = VTABLE_shift_string(interp, iter);
+            segment = VTABLE_get_pmc_keyed_str(interp, directory, name);
+            if (VTABLE_isa(interp, segment,
+                    Parrot_str_new_constant(interp, "PackfileConstantTable"))) {
+                Parrot_PCCINVOKE(interp, attrs->keys,
+                        Parrot_str_new_constant(interp, "set_constant_table"),
+                        "P->", segment);
+                break;
+            }
+        }
+    }
 
 }
 /*

Modified: branches/packfile_revamp/src/pmc/packfileconstanttable.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfileconstanttable.pmc	Sun Apr 12 09:54:21 2009	(r38084)
+++ branches/packfile_revamp/src/pmc/packfileconstanttable.pmc	Sun Apr 12 09:54:40 2009	(r38085)
@@ -155,7 +155,7 @@
                 mem_allocate_zeroed_typed(PackFile_ConstTable);
         PackFile_Constant   * value;
         opcode_t              i;
-        
+
         pftable->base.type = PF_CONST_SEG;
 
         /* Copy all constanst with respect of type */
@@ -187,7 +187,7 @@
                         EXCEPTION_MALFORMED_PACKFILE,
                         "Unknown PackFile constant type: %d", value->type);
             }
-            
+
             pftable->constants[i] = value;
         }
 

Modified: branches/packfile_revamp/t/pmc/packfileannotations.t
==============================================================================
--- branches/packfile_revamp/t/pmc/packfileannotations.t	Sun Apr 12 09:54:21 2009	(r38084)
+++ branches/packfile_revamp/t/pmc/packfileannotations.t	Sun Apr 12 09:54:40 2009	(r38085)
@@ -19,8 +19,9 @@
 
 .sub 'main' :main
 .include 'test_more.pir'
-    plan(1)
+    plan(4)
     test_sanity()
+    test_handling_directory()
 .end
 
 
@@ -31,3 +32,26 @@
     $I0 = defined pf
     ok($I0, "PackfileAnnotations created")
 .end
+
+# Annotations should propogate ConstantTable to Keys.
+.sub 'test_handling_directory'
+    .local pmc keys, anns, pfdir
+
+    anns = new 'PackfileAnnotations'
+    keys = anns.'get_key_list'()
+    $I0 = defined keys
+    ok($I0, "Keys created")
+    $P0 = keys.'get_constant_table'()
+    $I0 = defined $P0
+    is($I0, 0, "    without ConstantTable")
+
+    pfdir = new 'PackfileDirectory'
+    $P0 = new 'PackfileConstantTable'
+    # Order does matter
+    pfdir['CONSTANTS'] = $P0
+    pfdir['ANNOTATIONS'] = anns
+    $P0 = keys.'get_constant_table'()
+    $I0 = defined $P0
+    ok($I0, 'PackfileConstantTable found and propogated to Keys')
+.end
+


More information about the parrot-commits mailing list