[svn:parrot] r49282 - in trunk: compilers/imcc src t/pmc

plobsing at svn.parrot.org plobsing at svn.parrot.org
Fri Sep 24 03:56:50 UTC 2010


Author: plobsing
Date: Fri Sep 24 03:56:49 2010
New Revision: 49282
URL: https://trac.parrot.org/parrot/changeset/49282

Log:
modify Key.get_repr appropriately and use it to de-dup keys in IMCC
this acheives the PBC size reduction that should have been had with typesafe_consttable

Modified:
   trunk/compilers/imcc/pbc.c
   trunk/src/key.c
   trunk/t/pmc/key.t

Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c	Fri Sep 24 01:19:35 2010	(r49281)
+++ trunk/compilers/imcc/pbc.c	Fri Sep 24 03:56:49 2010	(r49282)
@@ -1656,7 +1656,21 @@
         }
     }
 
-    k = add_const_table_pmc(interp, head);
+    {
+        STRING *name      = key_set_to_string(interp, head);
+        const char *cname = Parrot_str_to_cstring(interp, name);
+        SymReg * const r  = _get_sym(&IMCC_INFO(interp)->globals->cs->key_consts, cname);
+
+        if (r) {
+            k = r->color;
+        }
+        else {
+            k = add_const_table_pmc(interp, head);
+            store_key_const(interp, cname, k);
+        }
+
+        Parrot_str_free_cstring(cname);
+    }
 
     /* single 'S' keys already have their color assigned */
     if (key_reg->set == 'K')

Modified: trunk/src/key.c
==============================================================================
--- trunk/src/key.c	Fri Sep 24 01:19:35 2010	(r49281)
+++ trunk/src/key.c	Fri Sep 24 03:56:49 2010	(r49282)
@@ -590,6 +590,10 @@
     ASSERT_ARGS(key_set_to_string)
     STRING * const semicolon = CONST_STRING(interp, " ; ");
     STRING * const quote     = CONST_STRING(interp, "'");
+    STRING * const P         = CONST_STRING(interp, "P");
+    STRING * const S         = CONST_STRING(interp, "S");
+    STRING * const N         = CONST_STRING(interp, "N");
+    STRING * const I         = CONST_STRING(interp, "I");
     STRING        *value     = Parrot_str_new(interp, "[ ", 2);
     PMC           *next_key;
     INTVAL         int_key;
@@ -619,31 +623,23 @@
             break;
           case KEY_integer_FLAG | KEY_register_FLAG:
             GETATTR_Key_int_key(interp, key, int_key);
-            value = Parrot_str_concat(interp, value,
-                        Parrot_str_from_int(interp,
-                            REG_INT(interp, int_key)));
+            value = Parrot_str_concat(interp, value, I);
+            value = Parrot_str_concat(interp, value, Parrot_str_from_int(interp, int_key));
             break;
           case KEY_number_FLAG | KEY_register_FLAG:
             GETATTR_Key_int_key(interp, key, int_key);
-            value = Parrot_str_concat(interp, value,
-                        Parrot_str_from_num(interp,
-                            REG_NUM(interp, int_key)));
+            value = Parrot_str_concat(interp, value, N);
+            value = Parrot_str_concat(interp, value, Parrot_str_from_int(interp, int_key));
             break;
           case KEY_string_FLAG | KEY_register_FLAG:
-            value = Parrot_str_concat(interp, value, quote);
             GETATTR_Key_int_key(interp, key, int_key);
-            value = Parrot_str_concat(interp, value,
-                    REG_STR(interp, int_key));
-            value = Parrot_str_concat(interp, value, quote);
+            value = Parrot_str_concat(interp, value, S);
+            value = Parrot_str_concat(interp, value, Parrot_str_from_int(interp, int_key));
             break;
           case KEY_pmc_FLAG | KEY_register_FLAG:
-            {
-                PMC *reg;
-                GETATTR_Key_int_key(interp, key, int_key);
-                reg = REG_PMC(interp, int_key);
-                value = Parrot_str_concat(interp, value,
-                            VTABLE_get_string(interp, reg));
-            }
+            GETATTR_Key_int_key(interp, key, int_key);
+            value = Parrot_str_concat(interp, value, P);
+            value = Parrot_str_concat(interp, value, Parrot_str_from_int(interp, int_key));
             break;
           default:
             value = Parrot_str_concat(interp, value, CONST_STRING(interp, "Key type unknown"));

Modified: trunk/t/pmc/key.t
==============================================================================
--- trunk/t/pmc/key.t	Fri Sep 24 01:19:35 2010	(r49281)
+++ trunk/t/pmc/key.t	Fri Sep 24 03:56:49 2010	(r49282)
@@ -19,13 +19,14 @@
 .sub main :main
     .include 'test_more.pir'
 
-    plan(9)
+    plan(12)
 
     traverse_key_chain()
     extract_int_from_string_keys()
     extract_string_from_int_keys()
     use_number_keys()
     do_not_collect_string_keys_early_rt_60128()
+    'get_repr'()
 .end
 
 .sub traverse_key_chain
@@ -175,6 +176,31 @@
   set_global 'call_chain', $P1
 .end
 
+.sub 'get_repr'
+    $P0 = new ['Key']
+    $P0 = 42
+    repr_is($P0, '[ 42 ]')
+
+    $P0 = new ['Key']
+    $P0 = "xyzzy"
+    repr_is($P0, "[ 'xyzzy' ]") # nothing happens (hopefully)
+
+    $P0 = new ['Key']
+    $P0.'set_register'(1, 4) # register 1 of set 4 (S1)
+    # XXX PCC treats key arguments as special. Don't pass keys to subroutines.
+    # repr_is($P0, '[ S1 ]')
+    $S0 = get_repr $P0
+    is($S0, '[ S1 ]')
+.end
+
+.sub repr_is
+    .param pmc x
+    .param pmc repr
+    .include 'test_more.pir'
+    $S0 = get_repr x
+    is($S0, repr)
+.end
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100


More information about the parrot-commits mailing list