Author: tewk
Date: Fri Feb  2 16:40:44 2007
New Revision: 16875

Modified:
   trunk/   (props changed)
   trunk/compilers/pge/PGE/pmc/codestring.pmc

Log:
[pge] CodeString pmc update, it works now, but causes GC errors if you don't 
run with -G 


Modified: trunk/compilers/pge/PGE/pmc/codestring.pmc
==============================================================================
--- trunk/compilers/pge/PGE/pmc/codestring.pmc  (original)
+++ trunk/compilers/pge/PGE/pmc/codestring.pmc  Fri Feb  2 16:40:44 2007
@@ -58,33 +58,25 @@
 
 #include "parrot/parrot.h"
 
-static STRING *PERCENT;
-static STRING *COMMA;
-static STRING *NEWLINE;
-static STRING *SLASH_U;
-static STRING *SLASH_X;
-
-pmclass CodeString
-        extends String
-        does string
-        dynpmc
-        group pge
-        hll pge
+
+pmclass CodeString extends String does string dynpmc group pge
 {
+    void init () {
+        Parrot_String_init(interp, SELF);
+    }
+
+            /*
     void class_init () {
         if (pass) {
             PMC *global_serno = pmc_new(INTERP, enum_class_Integer);
             PMC * const cur_ns = CONTEXT(INTERP->ctx)->current_namespace;
 
-            PERCENT = string_from_const_cstring(INTERP, "%", 0);
-            COMMA   = string_from_const_cstring(INTERP, ",", 0);
-            NEWLINE = string_from_const_cstring(INTERP, "\n", 0);
-            SLASH_U = string_from_const_cstring(INTERP, "\\u", 0);
-            SLASH_X = string_from_const_cstring(INTERP, "\\x", 0);
+            PIO_printf(interp, "%d %Ss, %d\n", cur_ns, 
(STRING*)PMC_data(cur_ns), global_serno);
             VTABLE_set_integer_native(INTERP, global_serno, 10);
             Parrot_set_global(INTERP, cur_ns, 
string_from_const_cstring(INTERP, "$!serno", 0), global_serno);
         }
     }
+            */
 
 /*
 
@@ -110,12 +102,15 @@
 =cut
 
 */
-
-    METHOD void emit(STRING *orig_format, PMC *args, PMC *named_args) {
+    PMETHOD void emit(STRING *orig_format, PMC *args :slurpy, PMC *named_args 
:slurpy :named) {
         INTVAL position = 0;
+        INTVAL repl_len = 0;
         STRING *format;
         STRING *key;
         STRING *repl;
+        STRING *PERCENT = string_from_const_cstring(INTERP, "%", 0);
+        STRING *COMMA   = string_from_const_cstring(INTERP, ",", 0);
+        STRING *NEWLINE = string_from_const_cstring(INTERP, "\n", 0);
 
         format = string_copy(interp, orig_format);
 
@@ -124,7 +119,7 @@
         {
             key = string_substr(interp, format, position + 1, 1, NULL, 0);
             /* named substitution  %position */
-            if (VTABLE_exists_keyed_str(interp, named_args, key)) {
+            if ( named_args != PMCNULL && VTABLE_exists_keyed_str(interp, 
named_args, key)) {
                 repl = VTABLE_get_string_keyed_str(interp, named_args, key);
             }
             /* positional substutution  %7 */
@@ -137,7 +132,7 @@
                 int size = VTABLE_elements(interp, args);
                 repl = string_copy(interp, VTABLE_get_string_keyed_int(interp, 
args, 0));
                 for ( i=1; i<size; i++ ) {
-                    repl = Parrot_sprintf_c(interp, "%ss, %ss", repl, 
VTABLE_get_string_keyed_int(interp, args, i));
+                    repl = Parrot_sprintf_c(interp, "%Ss, %Ss", repl, 
VTABLE_get_string_keyed_int(interp, args, i));
                 }
             }
             /* %% */
@@ -150,15 +145,17 @@
                 continue;
             }
 
+            repl_len = string_length(interp, repl);
             string_replace(interp, format, position, 2, repl, NULL);
-            position += string_length(interp, repl);
+            position += repl_len;
             position = string_str_index(interp, format, PERCENT, position);
         }
 
-        if (!string_equal(interp, string_substr(interp, format, -1, 1, NULL, 
0), NEWLINE)) {
-            string_append(interp,  PMC_str_val(SELF), NEWLINE);
+        PMC_str_val(SELF) = string_append(interp, PMC_str_val(SELF), format);
+
+        if (string_equal(interp, string_substr(interp, format, -1, 1, NULL, 
0), NEWLINE)) {
+            PMC_str_val(SELF) = string_append(interp, PMC_str_val(SELF), 
NEWLINE);
         }
-        string_append(interp, PMC_str_val(SELF), format);
     }
 
 /*
@@ -175,19 +172,18 @@
 
 */
 
-    METHOD STRING* unique(STRING *format, INTVAL has_format) {
+    PMETHOD void unique(STRING *format :optional , INTVAL has_format 
:opt_flag) {
+        static INTVAL serno = 10;
         STRING *id;
-        PMC *serno;
-        PMC * const cur_ns = CONTEXT(interp->ctx)->current_namespace;
 
-        serno = Parrot_get_global(interp, cur_ns, 
string_from_const_cstring(interp, "$!serno", 0));
-        id = VTABLE_get_string(interp, serno);
-        VTABLE_increment(interp, serno);
+        int current_serno =serno++;
+
+        id = string_from_int(interp, current_serno);
 
-        if (has_format) {
-            id = Parrot_sprintf_c(interp, "%ss%ss", format, id);
+        if (has_format && format != PMCNULL) {
+            id = Parrot_sprintf_c(interp, "%Ss%Ss", format, id);
         }
-        return id;
+        preturn(STRING* id);
     }
 
 /*
@@ -202,12 +198,15 @@
 
 */
     METHOD STRING* escape(STRING *str) {
+        STRING *SLASH_U = string_from_const_cstring(INTERP, "\\u", 0);
+        STRING *SLASH_X = string_from_const_cstring(INTERP, "\\x", 0);
+
         str = string_escape_string(interp, str);
-        str = Parrot_sprintf_c(interp, "\"%ss\"", str);
+        str = Parrot_sprintf_c(interp, "\"%Ss\"", str);
         if (string_str_index(interp, str, SLASH_U, 0) >= 0
                 || string_str_index(interp, str, SLASH_X, 0) >= 0) {
+            str = string_concat(interp, string_from_const_cstring(interp, 
"unicode:", 0), str, 0);
         }
-        str = string_concat(interp, string_from_const_cstring(interp, 
"unicode:", 0), str, 0);
         return str;
     }
 }

Reply via email to