[svn:parrot] r46212 - in branches/pbc_frozen_strings1: include/parrot src src/pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Sun May 2 03:23:13 UTC 2010


Author: plobsing
Date: Sun May  2 03:23:12 2010
New Revision: 46212
URL: https://trac.parrot.org/parrot/changeset/46212

Log:
workaround for :immediate :anon magic subs

use a special marker const table index of -1 to indicate inline string use because the string isn't in the constant table

Modified:
   branches/pbc_frozen_strings1/include/parrot/packfile.h
   branches/pbc_frozen_strings1/include/parrot/pmc_freeze.h
   branches/pbc_frozen_strings1/src/packfile.c
   branches/pbc_frozen_strings1/src/packout.c
   branches/pbc_frozen_strings1/src/pmc/imageio.pmc
   branches/pbc_frozen_strings1/src/pmc/imageiosize.pmc
   branches/pbc_frozen_strings1/src/pmc_freeze.c

Modified: branches/pbc_frozen_strings1/include/parrot/packfile.h
==============================================================================
--- branches/pbc_frozen_strings1/include/parrot/packfile.h	Sat May  1 23:29:31 2010	(r46211)
+++ branches/pbc_frozen_strings1/include/parrot/packfile.h	Sun May  2 03:23:12 2010	(r46212)
@@ -501,9 +501,11 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 size_t PackFile_Constant_pack_size(PARROT_INTERP,
-    ARGIN(const PackFile_Constant *self))
+    ARGIN(const PackFile_Constant *self),
+    ARGIN(const PackFile_ConstTable *ct))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2);
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3);
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
@@ -856,7 +858,8 @@
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_PackFile_Constant_pack_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
-    , PARROT_ASSERT_ARG(self))
+    , PARROT_ASSERT_ARG(self) \
+    , PARROT_ASSERT_ARG(ct))
 #define ASSERT_ARGS_PackFile_Constant_unpack __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(constt) \

Modified: branches/pbc_frozen_strings1/include/parrot/pmc_freeze.h
==============================================================================
--- branches/pbc_frozen_strings1/include/parrot/pmc_freeze.h	Sat May  1 23:29:31 2010	(r46211)
+++ branches/pbc_frozen_strings1/include/parrot/pmc_freeze.h	Sun May  2 03:23:12 2010	(r46212)
@@ -131,9 +131,12 @@
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
-UINTVAL Parrot_freeze_pbc_size(PARROT_INTERP, ARGIN(PMC *pmc))
+UINTVAL Parrot_freeze_pbc_size(PARROT_INTERP,
+    ARGIN(PMC *pmc),
+    ARGIN(const PackFile_ConstTable *pf))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2);
+        __attribute__nonnull__(2)
+        __attribute__nonnull__(3);
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
@@ -192,7 +195,8 @@
     , PARROT_ASSERT_ARG(pf))
 #define ASSERT_ARGS_Parrot_freeze_pbc_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
-    , PARROT_ASSERT_ARG(pmc))
+    , PARROT_ASSERT_ARG(pmc) \
+    , PARROT_ASSERT_ARG(pf))
 #define ASSERT_ARGS_Parrot_freeze_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(pmc))

Modified: branches/pbc_frozen_strings1/src/packfile.c
==============================================================================
--- branches/pbc_frozen_strings1/src/packfile.c	Sat May  1 23:29:31 2010	(r46211)
+++ branches/pbc_frozen_strings1/src/packfile.c	Sun May  2 03:23:12 2010	(r46212)
@@ -3827,7 +3827,7 @@
 /*
 
 =item C<size_t PackFile_Constant_pack_size(PARROT_INTERP, const
-PackFile_Constant *self)>
+PackFile_Constant *self, const PackFile_ConstTable *ct)>
 
 Determines the size of the buffer needed in order to pack the PackFile Constant
 into a contiguous region of memory.
@@ -3839,7 +3839,8 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 size_t
-PackFile_Constant_pack_size(PARROT_INTERP, ARGIN(const PackFile_Constant *self))
+PackFile_Constant_pack_size(PARROT_INTERP, ARGIN(const PackFile_Constant *self), ARGIN(const
+    PackFile_ConstTable *ct))
 {
     ASSERT_ARGS(PackFile_Constant_pack_size)
     PMC    *component;
@@ -3865,7 +3866,7 @@
 
       case PFC_PMC:
         component = self->u.key; /* the pmc (Sub, ...) */
-        packed_size = PF_size_strlen(Parrot_freeze_pbc_size(interp, component));
+        packed_size = PF_size_strlen(Parrot_freeze_pbc_size(interp, component, ct));
         break;
 
       default:

Modified: branches/pbc_frozen_strings1/src/packout.c
==============================================================================
--- branches/pbc_frozen_strings1/src/packout.c	Sat May  1 23:29:31 2010	(r46211)
+++ branches/pbc_frozen_strings1/src/packout.c	Sun May  2 03:23:12 2010	(r46212)
@@ -163,7 +163,7 @@
     size_t size = 1;    /* const_count */
 
     for (i = 0; i < self->const_count; i++)
-        size += PackFile_Constant_pack_size(interp, self->constants[i]);
+        size += PackFile_Constant_pack_size(interp, self->constants[i], self);
     return size;
 }
 

Modified: branches/pbc_frozen_strings1/src/pmc/imageio.pmc
==============================================================================
--- branches/pbc_frozen_strings1/src/pmc/imageio.pmc	Sat May  1 23:29:31 2010	(r46211)
+++ branches/pbc_frozen_strings1/src/pmc/imageio.pmc	Sun May  2 03:23:12 2010	(r46212)
@@ -260,6 +260,7 @@
         break;
       case enum_PackID_normal:
         {
+            PMC * const todo    = PARROT_IMAGEIO(info)->todo;
             const INTVAL type = VTABLE_shift_integer(interp, info);
 
             PARROT_ASSERT(id - 1 == VTABLE_elements(interp, PARROT_IMAGEIO(info)->todo));
@@ -274,10 +275,7 @@
             pmc = Parrot_pmc_new_noinit(interp, type);
             VTABLE_thaw(interp, pmc, info);
 
-            {
-                PMC * const todo    = PARROT_IMAGEIO(info)->todo;
-                VTABLE_set_pmc_keyed_int(interp, todo, id - 1, pmc);
-            }
+            VTABLE_set_pmc_keyed_int(interp, todo, id - 1, pmc);
         }
         break;
       default:
@@ -549,15 +547,23 @@
                     &&  Parrot_encoding_number_of_str(interp, v)
                     ==  Parrot_encoding_number_of_str(interp, sc)
                     &&  Parrot_str_equal(interp, v, sc)) {
-                        SET_VISIT_CURSOR(SELF,
-                                (char *)PF_store_integer(GET_VISIT_CURSOR(SELF), i));
+                        STATICSELF.push_integer(i);
                         return;
                     }
                 }
             }
-            PANIC(INTERP, "string not previously in constant table when freezing to packfile");
+            /* XXX
+             * handle cases where the PMC has changed after Parrot_freeze_strings was called
+             * eg: :immediate subs
+             */
+            STATICSELF.push_integer(-1);
+            /* TODO
+             * should really be:
+             * PANIC(INTERP, "string not previously in constant table when freezing to packfile");
+             */
         }
-        else {
+
+        {
             const size_t len = PF_size_string(v) * sizeof (opcode_t);
             ensure_buffer_size(INTERP, SELF, len);
             SET_VISIT_CURSOR(SELF, (char *)PF_store_string(GET_VISIT_CURSOR(SELF), v));
@@ -633,14 +639,18 @@
     VTABLE STRING *shift_string() {
         if (PObj_flag_TEST(private1, SELF)) {
             PackFile_ConstTable *table = PARROT_IMAGEIO(SELF)->pf_ct;
-            opcode_t *pos              = GET_VISIT_CURSOR(SELF);
-            INTVAL i                   = PF_fetch_integer(PARROT_IMAGEIO(SELF)->pf,
-                                                (const opcode_t **)&pos);
-            SET_VISIT_CURSOR(SELF, (char *)pos);
-            BYTECODE_SHIFT_OK(SELF);
-            return table->constants[i]->u.string;
+            INTVAL i                   = STATICSELF.shift_integer();
+
+            if (i >= 0)
+                return table->constants[i]->u.string;
+
+            /* XXX
+             * only got here because constant table doesn't contain the string
+             * fallback on inline strings
+             */
         }
-        else {
+
+        {
             opcode_t *pos = GET_VISIT_CURSOR(SELF);
             STRING   *s   = PF_fetch_string(interp, PARROT_IMAGEIO(SELF)->pf,
                                                (const opcode_t **)&pos);

Modified: branches/pbc_frozen_strings1/src/pmc/imageiosize.pmc
==============================================================================
--- branches/pbc_frozen_strings1/src/pmc/imageiosize.pmc	Sat May  1 23:29:31 2010	(r46211)
+++ branches/pbc_frozen_strings1/src/pmc/imageiosize.pmc	Sun May  2 03:23:12 2010	(r46212)
@@ -64,10 +64,11 @@
 }
 
 pmclass ImageIOSize auto_attrs {
-    ATTR PMC             *seen;           /* seen hash */
-    ATTR PMC             *todo;           /* todo list */
-    ATTR struct PackFile *pf;
-    ATTR INTVAL           size;
+    ATTR PMC                        *seen; /* seen hash */
+    ATTR PMC                        *todo; /* todo list */
+    ATTR struct PackFile            *pf;
+    ATTR struct PackFile_ConstTable *pf_ct;
+    ATTR INTVAL                      size;
 
 /*
 
@@ -89,9 +90,10 @@
 
 */
     VTABLE void init() {
-        PARROT_IMAGEIOSIZE(SELF)->todo = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
-        PARROT_IMAGEIOSIZE(SELF)->pf   = PackFile_new(INTERP, 0);
-        PARROT_IMAGEIOSIZE(SELF)->size = 0;
+        PARROT_IMAGEIOSIZE(SELF)->todo  = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
+        PARROT_IMAGEIOSIZE(SELF)->pf    = PackFile_new(INTERP, 0);
+        PARROT_IMAGEIOSIZE(SELF)->pf_ct = NULL;
+        PARROT_IMAGEIOSIZE(SELF)->size  = 0;
 
         PARROT_IMAGEIOSIZE(SELF)->seen = Parrot_pmc_new(INTERP, enum_class_Hash);
         VTABLE_set_pointer(INTERP, PARROT_IMAGEIOSIZE(SELF)->seen,
@@ -111,12 +113,11 @@
 =cut
 
 */
-    VTABLE void init_pmc(PMC *pmc) {
-        UNUSED(pmc);
-
-        PARROT_IMAGEIOSIZE(SELF)->todo = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
-        PARROT_IMAGEIOSIZE(SELF)->pf   = PackFile_new(INTERP, 0);
-        PARROT_IMAGEIOSIZE(SELF)->size = 0;
+    VTABLE void init_pmc(PMC *pf_ct) {
+        PARROT_IMAGEIOSIZE(SELF)->todo  = Parrot_pmc_new(INTERP, enum_class_ResizablePMCArray);
+        PARROT_IMAGEIOSIZE(SELF)->pf    = PackFile_new(INTERP, 0);
+        PARROT_IMAGEIOSIZE(SELF)->pf_ct = VTABLE_get_pointer(interp, pf_ct);
+        PARROT_IMAGEIOSIZE(SELF)->size  = 0;
 
         PARROT_IMAGEIOSIZE(SELF)->seen = Parrot_pmc_new(INTERP, enum_class_Hash);
         VTABLE_set_pointer(INTERP, PARROT_IMAGEIOSIZE(SELF)->seen,
@@ -244,9 +245,35 @@
 
     VTABLE void push_string(STRING *v) {
         if (PObj_flag_TEST(private1, SELF)) {
-            STATICSELF.push_integer(0);
+            /* look for a reference to constant table entry of string */
+            int i;
+            PackFile_ConstTable *table = PARROT_IMAGEIOSIZE(SELF)->pf_ct;
+            for (i = 0; i < table->const_count; i++) {
+                PackFile_Constant *constant = table->constants[i];
+                if (constant->type == PFC_STRING) {
+                    STRING * const sc = constant->u.string;
+                    if (Parrot_charset_number_of_str(interp, v)
+                    ==  Parrot_charset_number_of_str(interp, sc)
+                    &&  Parrot_encoding_number_of_str(interp, v)
+                    ==  Parrot_encoding_number_of_str(interp, sc)
+                    &&  Parrot_str_equal(interp, v, sc)) {
+                        STATICSELF.push_integer(i);
+                        return;
+                    }
+                }
+            }
+            /* XXX
+             * handle cases where the PMC has changed after Parrot_freeze_strings was called
+             * eg: :immediate subs
+             */
+            STATICSELF.push_integer(-1);
+            /* TODO
+             * should really be:
+             * PANIC(INTERP, "string not previously in constant table when freezing to packfile");
+             */
         }
-        else {
+
+        {
             const size_t len = PF_size_string(v) * sizeof (opcode_t);
             PARROT_IMAGEIOSIZE(SELF)->size += len;
         }

Modified: branches/pbc_frozen_strings1/src/pmc_freeze.c
==============================================================================
--- branches/pbc_frozen_strings1/src/pmc_freeze.c	Sat May  1 23:29:31 2010	(r46211)
+++ branches/pbc_frozen_strings1/src/pmc_freeze.c	Sun May  2 03:23:12 2010	(r46212)
@@ -115,7 +115,8 @@
 
 /*
 
-=item C<UINTVAL Parrot_freeze_pbc_size(PARROT_INTERP, PMC *pmc)>
+=item C<UINTVAL Parrot_freeze_pbc_size(PARROT_INTERP, PMC *pmc, const
+PackFile_ConstTable *pf)>
 
 Get the size of an image if it were created using C<Parrot_freeze_pbc>.
 
@@ -126,16 +127,19 @@
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
 UINTVAL
-Parrot_freeze_pbc_size(PARROT_INTERP, ARGIN(PMC *pmc))
+Parrot_freeze_pbc_size(PARROT_INTERP, ARGIN(PMC *pmc), ARGIN(const PackFile_ConstTable *pf))
 {
     ASSERT_ARGS(Parrot_freeze_pbc_size)
-    UINTVAL  int_result;
-    PMC     *pmc_result;
-    PMC     *visitor = Parrot_pmc_new_init(interp, enum_class_ImageIOSize, PMCNULL);
+    PMC     *pf_pmc, *visitor, *pmc_result;
+
+    pf_pmc = Parrot_pmc_new(interp, enum_class_UnManagedStruct);
+    VTABLE_set_pointer(interp, pf_pmc, (void *)pf);
+
+    visitor = Parrot_pmc_new_init(interp, enum_class_ImageIOSize, pf_pmc);
     VTABLE_set_pmc(interp, visitor, pmc);
+
     pmc_result = VTABLE_get_pmc(interp, visitor);
-    int_result = VTABLE_get_integer(interp, pmc_result);
-    return int_result;
+    return VTABLE_get_integer(interp, pmc_result);
 }
 
 
@@ -145,8 +149,6 @@
 
 Get the strings of a PMC to be frozen.
 
-Used in C<???>.
-
 =cut
 
 */


More information about the parrot-commits mailing list