Author: leo
Date: Thu Apr 21 07:32:55 2005
New Revision: 7902

Modified:
   trunk/classes/perlundef.pmc
   trunk/classes/scalar.pmc
   trunk/classes/string.pmc
   trunk/dynclasses/pystring.pmc
   trunk/dynclasses/tclstring.pmc
   trunk/src/mmd_fallback.c
   trunk/vtable.tbl
Log:
MMD 32 - string MMDs cnverted

* concat, repeat are done
* override pystring.add with .concatenate



Modified: trunk/classes/perlundef.pmc
==============================================================================
--- trunk/classes/perlundef.pmc (original)
+++ trunk/classes/perlundef.pmc Thu Apr 21 07:32:55 2005
@@ -381,40 +381,6 @@
     }
 
 
-/*
-
-=item C<void concatenate(PMC *value, PMC *dest)>
-
-=cut
-
-*/
-
-    void concatenate (PMC* value,  PMC* dest) {
-        Parrot_warn(INTERP, PARROT_WARNINGS_UNDEF_FLAG,
-        "Use of uninitialized value in concatenation");
-        VTABLE_set_string_native(INTERP, dest,
-            VTABLE_get_string(INTERP, value));
-    }
-
-/*
-
-=item C<void concatenate_str(STRING *value, PMC *dest)>
-
-All these methods warn of the use of an uninitialized value and return
-the calculated result in C<*dest>.
-
-In the division methods exceptions are raised for division by zero,
-if appropriate.
-
-=cut
-
-*/
-
-    void concatenate_str (STRING* value,  PMC* dest) {
-        Parrot_warn(INTERP, PARROT_WARNINGS_UNDEF_FLAG,
-        "Use of uninitialized value in concatenation");
-        VTABLE_set_string_native(INTERP, dest, value);
-    }
 
 /*
 
@@ -502,43 +468,6 @@
     }
 
 /*
-
-=item C<void repeat(PMC *value, PMC *dest)>
-
-=cut
-
-*/
-
-    void repeat (PMC* value,  PMC* dest) {
-        STRING * empty_string;
-        Parrot_warn(INTERP, PARROT_WARNINGS_UNDEF_FLAG,
-        "Use of uninitialized value in repeat");
-
-        empty_string = string_make_empty(INTERP,enum_stringrep_one,0);
-        VTABLE_set_string_native(INTERP, dest, empty_string);
-    }
-
-/*
-
-=item C<void repeat_int(INTVAL value, PMC *dest)>
-
-Warns of the use of an undefined value and returns an empty
-C<PerlString> in C<*dest>.
-
-=cut
-
-*/
-
-    void repeat_int (INTVAL value, PMC* dest) {
-        STRING * empty_string;
-        Parrot_warn(INTERP, PARROT_WARNINGS_UNDEF_FLAG,
-        "Use of uninitialized value in repeat");
-
-        empty_string = string_make_empty(INTERP,enum_stringrep_one,0);
-        VTABLE_set_string_native(INTERP, dest, empty_string);
-    }
-
-/*
 
 =item C<INTVAL defined()>
 

Modified: trunk/classes/scalar.pmc
==============================================================================
--- trunk/classes/scalar.pmc    (original)
+++ trunk/classes/scalar.pmc    Thu Apr 21 07:32:55 2005
@@ -1048,41 +1048,104 @@
 
 =over 4
 
-=item C<void concatenate(PMC *value, PMC *dest)>
+=item C<PMC* concatenate(PMC *value, PMC *dest)>
+
+=item C<PMC* concatenate_str(STRING *value, PMC *dest)>
 
 Returns in C<*dest> the result of concatenating the scalar and C<*value>.
 
+=item C<void concatenate(PMC *value)>
+
+=item C<void concatenate_str(STRING *value)>
+
+Concatenate the string C<value> in place.
+
 =cut
 
 */
 
-    void concatenate (PMC* value,  PMC* dest) {
+    PMC* concatenate (PMC* value,  PMC* dest) {
         STRING* s = string_concat(INTERP,
             DYNSELF.get_string(),
             VTABLE_get_string(INTERP, value), 0);
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+        VTABLE_set_string_native(INTERP, dest, s);
+        return dest;
+    }
 
+    PMC* concatenate_str (STRING* value,  PMC* dest) {
+        STRING* s = string_concat(INTERP,
+            DYNSELF.get_string(), value, 0);
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
         VTABLE_set_string_native(INTERP, dest, s);
+        return dest;
+    }
+
+    void i_concatenate (PMC* value) {
+        STRING* s = DYNSELF.get_string();
+        STRING* v = VTABLE_get_string(INTERP, value);
+        DYNSELF.set_string_native(string_append(INTERP, s, v, 1));
+    }
+
+    void i_concatenate_str (STRING* value) {
+        STRING* s = DYNSELF.get_string();
+        DYNSELF.set_string_native( string_append(INTERP, s, value, 1));
     }
 
 /*
 
-=item C<void concatenate_str(STRING *value, PMC *dest)>
+=item C<PMC* repeat(PMC *value, PMC *dest)>
 
-Returns in C<*dest> the result of concatenating the scalar and C<*value>.
+=item C<PMC* repeat_int(INTVAL value, PMC *dest)>
+
+Returns in C<*dest> the result of repeating the scalar C<value> times.
+
+=item C<void i_repeat(PMC *value)>
+
+=item C<void i_repeat_int(INTVAL value)>
+
+Repeat the string C<SELF> in place C<value> times.
 
 =cut
 
 */
 
-    void concatenate_str (STRING* value,  PMC* dest) {
-        /* dest = SELF (concat) value */
-        STRING* s = string_concat(INTERP,
-            DYNSELF.get_string(),
-            value, 0);
+    PMC* repeat (PMC* value,  PMC* dest) {
+        STRING* s = DYNSELF.get_string();
+        UINTVAL n = (UINTVAL)VTABLE_get_integer(INTERP, value);
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+        VTABLE_set_string_native(INTERP, dest,
+            string_repeat(INTERP, s, n, NULL));
+        return dest;
+    }
 
-        VTABLE_set_string_native(INTERP, dest, s);
+    PMC* repeat_int (INTVAL value, PMC* dest) {
+        STRING* s = DYNSELF.get_string();
+        UINTVAL n = value;
+        if (!dest)
+            dest = pmc_new(INTERP, SELF->vtable->base_type);
+        VTABLE_set_string_native(INTERP, dest,
+            string_repeat(INTERP, s, n, NULL));
+        return dest;
+    }
+
+
+    void i_repeat (PMC* value) {
+        STRING* s = DYNSELF.get_string();
+        UINTVAL n = (UINTVAL)VTABLE_get_integer(INTERP, value);
+        DYNSELF.set_string_native(string_repeat(INTERP, s, n, NULL));
     }
 
+    void i_repeat_int (INTVAL value) {
+        STRING* s = DYNSELF.get_string();
+        UINTVAL n = value;
+        DYNSELF.set_string_native(string_repeat(INTERP, s, n, NULL));
+    }
+
+
 
 /*
 
@@ -1218,39 +1281,6 @@
             ! DYNSELF.get_bool());
     }
 
-/*
-
-=item C<void repeat(PMC *value, PMC *dest)>
-
-Returns in C<*dest> the result of repeating the scalar C<*value> times.
-
-
-=cut
-
-*/
-
-    void repeat (PMC* value,  PMC* dest) {
-        VTABLE_set_string_native(INTERP, dest,
-            string_repeat(INTERP, VTABLE_get_string(INTERP,SELF),
-                (UINTVAL)VTABLE_get_integer(INTERP, value), NULL) );
-    }
-
-/*
-
-=item C<void repeat_int(INTVAL value, PMC *dest)>
-
-Returns in C<*dest> the result of repeating the scalar C<value> times.
-
-=cut
-
-*/
-
-    void repeat_int (INTVAL value, PMC* dest) {
-        VTABLE_set_string_native(INTERP, dest,
-            string_repeat(INTERP, VTABLE_get_string(INTERP,SELF),
-                (UINTVAL)value, NULL) );
-    }
-
 
 /*
 

Modified: trunk/classes/string.pmc
==============================================================================
--- trunk/classes/string.pmc    (original)
+++ trunk/classes/string.pmc    Thu Apr 21 07:32:55 2005
@@ -408,38 +408,6 @@
 
 /*
 
-=item C<VOID concatenate(PMC* value, PMC* dest)>
-
-Concatenates the string with C<value> and places the result in C<dest>.
-
-=cut
-
-*/
-    void concatenate (PMC* value, PMC* dest) {
-        STRING *s = PMC_str_val(SELF);
-        STRING *v = VTABLE_get_string(INTERP, value);
-        STRING *o = string_concat(INTERP, s, v, 0);
-        VTABLE_set_string_native(
-            INTERP, dest, o);
-    }
-
-/*
-
-=item C<VOID concatenate_str(STRING* value, PMC* dest)>
-
-Concatenates the string with C<value> and places the result in C<dest>.
-
-=cut
-
-*/
-    void concatenate_str (STRING* value, PMC* dest) {
-        STRING *s = PMC_str_val(SELF);
-        STRING *o = string_concat(INTERP, s, value, 0);
-        VTABLE_set_string_native(INTERP, dest, o);
-    }
-
-/*
-
 =item C<INTVAL is_equal(PMC* value)>
 
 Compares the string with C<value>; returns true if
@@ -565,37 +533,6 @@
     }
 
 /*
-
-=item C<void repeat(PMC* value, PMC* dest)>
-
-Repeats the string C<value> times and places the result in C<dest>.
-
-=cut
-
-*/
-    void repeat (PMC* value, PMC* dest) {
-        INTVAL n = VTABLE_get_integer(INTERP, value);
-        STRING *s = PMC_str_val(SELF);
-        STRING *s2 = string_repeat(INTERP, s, n, NULL);
-        VTABLE_set_string_native(INTERP, dest, s2);
-    }
-
-/*
-
-=item C<void repeat_int(INTVAL value, PMC* dest)>
-
-Repeats the string C<value> times and places the result in C<dest>.
-
-=cut
-
-*/
-    void repeat_int (INTVAL value, PMC* dest) {
-        STRING *s = PMC_str_val(SELF);
-        STRING *s2 = string_repeat(INTERP, s, value, NULL);
-        VTABLE_set_string_native(INTERP, dest, s2);
-    }
-
-/*
 
 =item C<void substr(INTVAL offset, INTVAL length, PMC* dest)>
 

Modified: trunk/dynclasses/pystring.pmc
==============================================================================
--- trunk/dynclasses/pystring.pmc       (original)
+++ trunk/dynclasses/pystring.pmc       Thu Apr 21 07:32:55 2005
@@ -21,23 +21,37 @@
 #include "parrot/parrot.h"
 #include "pyconsts.h"
 
-pmclass PyString extends PyObject dynpmc group python_group {
+pmclass PyString extends PyObject extends String dynpmc group python_group {
 
-/*
-
-=item C<void mark()>
-
-Marks the string as live.
-
-=cut
-
-*/
-
-    void mark () {
-        if(PMC_str_val(SELF))
-            pobject_lives(INTERP, (PObj *)PMC_str_val(SELF));
+    void class_init() {
+        if (pass) {
+            /*
+             * redirect add to concatenate
+             */
+            MMD_init *e = _temp_mmd_init;
+            int i, n, is_pmc;
+            funcptr_t func;
+
+            n = (sizeof(_temp_mmd_init)/sizeof(_temp_mmd_init[0]));
+            /*
+             * if we find a ADD, install CONCAT
+             */
+            for (i = 0; i < n; ++i, ++e) {
+                if (e->func_nr == MMD_ADD && e->right == enum_class_String) {
+                    func = get_mmd_dispatch_type(interp,
+                            MMD_CONCAT, enum_class_String,
+                            e->right, &is_pmc);
+                    e->func_ptr = func;
+                }
+                if (e->func_nr == MMD_I_ADD && e->right == enum_class_String) {
+                    func = get_mmd_dispatch_type(interp,
+                            MMD_I_CONCAT, enum_class_String,
+                            e->right, &is_pmc);
+                    e->func_ptr = func;
+                }
+            }
+        }
     }
-
 /*
 
 =item C<PMC* "__getitem__"(PMC *self, PMC *idx)>
@@ -100,8 +114,14 @@
 */
 
     PMC* add (PMC * value, PMC* dest) {
-        SELF.concatenate(value, dest);
-        return dest;
+MMD_String: {
+            /* MMD is overridden in class_init */
+            return dest;
+        }
+MMD_DEFAULT: {
+            /* TODO through exception */
+            return dest;
+        }
     }
 
 /*
@@ -119,37 +139,7 @@
                   VTABLE_get_string(INTERP, value));
     }
 
-/*
-
-=item C<void concatenate(PMC *value, PMC *dest)>
-
-Concatenates the string and the stringified form of C<*value> and
-return the result in C<*dest>, morphing it to a PyString if required.
-
-=cut
-
-*/
-
-    void concatenate (PMC* value, PMC* dest) {
-        STRING* s = PMC_str_val(SELF);
-        VTABLE_morph(INTERP, dest, PyBuiltin_PyString);
-        PMC_str_val(dest) =
-            string_concat(INTERP, s, VTABLE_get_string(INTERP, value), 0);
-    }
-
-/*
 
-=item C<INTVAL elements ()>
-
-Return length of the string.
-
-=cut
-
-*/
-
-    INTVAL elements () {
-        return string_length(INTERP, PMC_str_val(SELF));
-    }
 
 /*
 

Modified: trunk/dynclasses/tclstring.pmc
==============================================================================
--- trunk/dynclasses/tclstring.pmc      (original)
+++ trunk/dynclasses/tclstring.pmc      Thu Apr 21 07:32:55 2005
@@ -18,7 +18,7 @@
 static INTVAL dynclass_TclInt;
 static STRING *true, *false, *yes, *no;
 
-pmclass TclString extends TclObject dynpmc group tcl_group {
+pmclass TclString extends TclObject extends String dynpmc group tcl_group {
 
     void class_init () {
         PMC *string_anchor;
@@ -43,23 +43,6 @@
         }
     }
 
-    void init () {
-        PMC_str_val(SELF) = string_make_empty(INTERP,enum_stringrep_one,0);
-        PObj_custom_mark_SET(SELF);
-    }
-
-    void mark () {
-        if (PMC_str_val(SELF))
-            pobject_lives(INTERP, (PObj *)PMC_str_val(SELF));
-    }
-
-    PMC* clone () {
-        PMC* dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
-        PObj_custom_mark_SET(dest);
-        PMC_str_val(dest) = string_copy(INTERP,PMC_str_val(SELF));
-        return dest;
-
-    }
 
    STRING* get_repr() {
      return SELF.get_string();
@@ -123,62 +106,4 @@
         PMC_str_val(value));
     }
 
-    # math ops? keep or kill?
-    # bitwise ops
-
-    void concatenate (PMC* value, PMC* dest) {
-        STRING* s = PMC_str_val(SELF);
-        VTABLE_morph(INTERP, dest, TclString_type);
-        PMC_str_val(dest) =
-            string_concat(INTERP, s, VTABLE_get_string(INTERP, value), 0);
-    }
-
-
-    voiid concatenate_native (STRING* value, PMC* dest) {
-        STRING* s = PMC_str_val(SELF);
-        VTABLE_morph(INTERP, dest, TclString_type);
-        PMC_str_val(dest) = string_concat(INTERP, s, value, 0);
-    }
-
-    INTVAL is_equal (PMC* value) {
-        return (INTVAL)( 0 == string_compare(INTERP,
-                                             PMC_str_val(SELF),
-                                             VTABLE_get_string(INTERP, value)
-                                            ));
-    }
-
-    INTVAL cmp(PMC* value) {
-        return string_compare(INTERP, PMC_str_val(SELF),
-                  VTABLE_get_string(INTERP, value));
-    }
-
-    void repeat (PMC* value, PMC* dest) {
-        DYNSELF.morph(TclString_type);
-        VTABLE_morph(INTERP, dest, TclString_type);
-        PMC_str_val(dest) =
-           string_repeat(INTERP, PMC_str_val(SELF),
-                         (UINTVAL)VTABLE_get_integer(INTERP, value), NULL
-                        );
-    }
-
-    void repeat_int (INTVAL value, PMC* dest) {
-        DYNSELF.morph(TclString_type);
-        VTABLE_morph(INTERP, dest, TclString_type);
-        PMC_str_val(dest) = string_repeat(INTERP,
-        PMC_str_val(SELF), (UINTVAL)value, NULL);
-    }
-
-
-    void substr (INTVAL offset, INTVAL length, PMC* dest) {
-        DYNSELF.morph(TclString_type);
-        VTABLE_morph(INTERP, dest, TclString_type);
-        PMC_str_val(dest) = string_substr(INTERP,
-            PMC_str_val(SELF), offset, length, NULL, 0);
-    }
-
-    STRING* substr_str (INTVAL offset, INTVAL length) {
-        return string_substr(INTERP, PMC_str_val(SELF), offset,
-            length, NULL, 0);
-    }
-
 }

Modified: trunk/src/mmd_fallback.c
==============================================================================
--- trunk/src/mmd_fallback.c    (original)
+++ trunk/src/mmd_fallback.c    Thu Apr 21 07:32:55 2005
@@ -591,7 +591,8 @@
 register_fallback_methods(Parrot_Interp interp) {
     /* Yeah, this first one's out of order logically, but it means
        the table doesn't have to keep being re-malloc'd */
-    assert(MMD_REPEAT == MMD_USER_FIRST - 1);
+    mmd_add_function(interp, MMD_USER_FIRST - 1, (funcptr_t)0);
+
     mmd_add_function(interp, MMD_REPEAT, (funcptr_t)mmd_fallback_repeat_pmc);
 
     mmd_add_function(interp, MMD_ADD, (funcptr_t)mmd_fallback_add_pmc);

Modified: trunk/vtable.tbl
==============================================================================
--- trunk/vtable.tbl    (original)
+++ trunk/vtable.tbl    Thu Apr 21 07:32:55 2005
@@ -287,11 +287,17 @@
 void logical_not(PMC* dest)
 
 [STRING]
-void concatenate(PMC* value, PMC* dest)        MMD_CONCAT
-void concatenate_str(STRING* value, PMC* dest) MMD_CONCAT_STR
+PMC* concatenate(PMC* value, PMC* dest)        MMD_CONCAT
+PMC* concatenate_str(STRING* value, PMC* dest) MMD_CONCAT_STR
 
-void repeat(PMC* value, PMC* dest)           MMD_REPEAT
-void repeat_int(INTVAL value, PMC* dest)     MMD_REPEAT_INT
+void i_concatenate(PMC* value)               MMD_I_CONCAT
+void i_concatenate_str(STRING* value)        MMD_I_CONCAT_STR
+
+PMC* repeat(PMC* value, PMC* dest)           MMD_REPEAT
+PMC* repeat_int(INTVAL value, PMC* dest)     MMD_REPEAT_INT
+
+void i_repeat(PMC* value)                    MMD_I_REPEAT
+void i_repeat_int(INTVAL value)              MMD_I_REPEAT_INT
 
 void substr(INTVAL offset, INTVAL length, PMC* dest)
 STRING* substr_str(INTVAL offset, INTVAL length)

Reply via email to