Author: chromatic
Date: Fri Feb 22 00:01:59 2008
New Revision: 25976

Modified:
   trunk/languages/lua/pmc/luastring.pmc

Log:
[Lua] Cleaned up LuaString PMC.

Modified: trunk/languages/lua/pmc/luastring.pmc
==============================================================================
--- trunk/languages/lua/pmc/luastring.pmc       (original)
+++ trunk/languages/lua/pmc/luastring.pmc       Fri Feb 22 00:01:59 2008
@@ -42,8 +42,7 @@
 
 */
     void init() {
-        PMC_str_val(SELF) =
-            string_make_empty(INTERP, enum_stringrep_one, 0);
+        PMC_str_val(SELF) = string_make_empty(INTERP, enum_stringrep_one, 0);
         PObj_custom_mark_SET(SELF);
     }
 
@@ -65,7 +64,8 @@
             res = constant_pmc_new(INTERP, type);
         else
             res = pmc_new(INTERP, type);
-        PMC_str_val(res) = string_copy(INTERP, rep);
+
+        VTABLE_set_string_native(INTERP, res, string_copy(INTERP, rep));
         PObj_custom_mark_SET(res);
         return res;
     }
@@ -94,10 +94,7 @@
 
 */
     PMC* clone() {
-        PMC* dest = pmc_new_noinit(INTERP, PMC_type(SELF));
-        PMC_str_val(dest) = string_copy(INTERP, PMC_str_val(SELF));
-        PObj_custom_mark_SET(dest);
-        return dest;
+        return VTABLE_new_from_string(INTERP, SELF, PMC_str_val(SELF), 0);
     }
 
 /*
@@ -152,20 +149,20 @@
 
 /*
 
-=item C<VOID set_string_native(STRING* value)>
+=item C<VOID set_string_native(STRING *value)>
 
 Sets the value of the string to that of the specified C<string>.
 
 =cut
 
 */
-    void set_string_native(STRING* value) {
+    void set_string_native(STRING *value) {
         PMC_str_val(SELF) = value;
     }
 
 /*
 
-=item C<VOID set_pmc(PMC* value)>
+=item C<VOID set_pmc(PMC *value)>
 
 Sets the value of the string to the string value of
 the specified C<PMC>.
@@ -173,26 +170,25 @@
 =cut
 
 */
-    void set_pmc(PMC* value) {
+    void set_pmc(PMC *value) {
         PMC_str_val(SELF) = VTABLE_get_string(INTERP, value);
     }
 
 /*
 
-=item C<PMC* neg(PMC * dest)>
+=item C<PMC* neg(PMC *dest)>
 
 =cut
 
 */
-    PMC* neg(PMC * dest) {
-        PMC* n = SELF.tonumber();
-        if (PMC_type(n) == dynpmc_LuaNumber) {
+    PMC* neg(PMC *dest) {
+        PMC *n = SELF.tonumber();
+
+        if (PMC_type(n) == dynpmc_LuaNumber)
             return LuaNumber.n.neg(dest);
-        }
-        else {
-            real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value", 
SELF.name());
-        }
+
+        real_exception(INTERP, NULL, ILL_INHERIT,
+            "attempt to perform arithmetic on a %Ss value", SELF.name());
     }
 
 /*
@@ -203,14 +199,13 @@
 
 */
     void i_neg() {
-        PMC* n = SELF.tonumber();
-        if (PMC_type(n) == dynpmc_LuaNumber) {
+        PMC *n = SELF.tonumber();
+
+        if (PMC_type(n) == dynpmc_LuaNumber)
             LuaNumber.n.i_neg();
-        }
-        else {
+        else
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value", 
SELF.name());
-        }
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
     }
 
 /*
@@ -265,566 +260,539 @@
 
 =over 4
 
-=item C<PMC* add(PMC* value, PMC* dest)>
+=item C<PMC* add(PMC *value, PMC *dest)>
 
 =cut
 
 */
-    PMC* add(PMC* value, PMC* dest) {
+    PMC* add(PMC *value, PMC *dest) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_add_LuaNumber(INTERP, n, value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_add_LuaString(INTERP, n, value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value", 
SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__add");
-            if (meth != NULL) {
+            if (meth) {
                 dest = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(dest)) {
+                if (PMC_IS_NULL(dest))
                     dest = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return dest;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<void i_add(PMC* value)>
+=item C<void i_add(PMC *value)>
 
 =cut
 
 */
-    void i_add(PMC* value) {
+    void i_add(PMC *value) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_add_LuaNumber(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_add_LuaString(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__add");
-            if (meth != NULL) {
+            if (meth) {
                 SELF = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(SELF)) {
+                if (PMC_IS_NULL(SELF))
                     SELF = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<PMC* subtract(PMC* value, PMC* dest)>
+=item C<PMC* subtract(PMC *value, PMC *dest)>
 
 =cut
 
 */
-    PMC* subtract(PMC* value, PMC* dest) {
+    PMC* subtract(PMC *value, PMC *dest) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_subtract_LuaNumber(INTERP, n,
                                                            value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_subtract_LuaString(INTERP, n,
                                                            value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__sub");
-            if (meth != NULL) {
+            if (meth) {
                 dest = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(dest)) {
+                if (PMC_IS_NULL(dest))
                     dest = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return dest;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<void i_subtract(PMC* value)>
+=item C<void i_subtract(PMC *value)>
 
 =cut
 
 */
-    void i_subtract(PMC* value) {
+    void i_subtract(PMC *value) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_subtract_LuaNumber(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_subtract_LuaString(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__sub");
-            if (meth != NULL) {
+
+            if (meth) {
                 SELF = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(SELF)) {
+                if (PMC_IS_NULL(SELF))
                     SELF = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<PMC* multiply(PMC* value, PMC* dest)>
+=item C<PMC* multiply(PMC *value, PMC *dest)>
 
 =cut
 
 */
-    PMC* multiply(PMC* value, PMC* dest) {
+    PMC* multiply(PMC *value, PMC *dest) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_multiply_LuaNumber(INTERP, n,
                                                            value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_multiply_LuaString(INTERP, n,
                                                            value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__mul");
-            if (meth != NULL) {
+            if (meth) {
                 dest = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(dest)) {
+                if (PMC_IS_NULL(dest))
                     dest = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return dest;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<void i_multiply(PMC* value)>
+=item C<void i_multiply(PMC *value)>
 
 =cut
 
 */
-    void i_multiply(PMC* value) {
+    void i_multiply(PMC *value) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_multiply_LuaNumber(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_multiply_LuaString(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__mul");
-            if (meth != NULL) {
+            if (meth) {
                 SELF = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(SELF)) {
+                if (PMC_IS_NULL(SELF))
                     SELF = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<PMC* divide(PMC* value, PMC* dest)>
+=item C<PMC* divide(PMC *value, PMC *dest)>
 
 =cut
 
 */
-    PMC* divide(PMC* value, PMC* dest) {
+    PMC* divide(PMC *value, PMC *dest) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_divide_LuaNumber(INTERP, n,
                                                          value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_divide_LuaString(INTERP, n,
                                                          value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__div");
-            if (meth != NULL) {
+
+            if (meth) {
                 dest = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(dest)) {
+                if (PMC_IS_NULL(dest))
                     dest = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return dest;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<void i_divide(PMC* value)>
+=item C<void i_divide(PMC *value)>
 
 =cut
 
 */
-    void i_divide(PMC* value) {
+    void i_divide(PMC *value) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_divide_LuaNumber(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_divide_LuaString(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__div");
-            if (meth != NULL) {
+            if (meth) {
                 SELF = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(SELF)) {
+                if (PMC_IS_NULL(SELF))
                     SELF = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<PMC* modulus(PMC* value, PMC* dest)>
+=item C<PMC* modulus(PMC *value, PMC *dest)>
 
 =cut
 
 */
-    PMC* modulus(PMC* value, PMC* dest) {
+    PMC* modulus(PMC *value, PMC *dest) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_modulus_LuaNumber(INTERP, n,
                                                           value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_modulus_LuaString(INTERP, n,
                                                           value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__mod");
-            if (meth != NULL) {
+
+            if (meth) {
                 dest = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(dest)) {
+                if (PMC_IS_NULL(dest))
                     dest = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return dest;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<void i_modulus(PMC* value)>
+=item C<void i_modulus(PMC *value)>
 
 =cut
 
 */
-    void i_modulus(PMC* value) {
+    void i_modulus(PMC *value) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_modulus_LuaNumber(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_modulus_LuaString(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__mod");
-            if (meth != NULL) {
+            if (meth) {
                 SELF = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(SELF)) {
+                if (PMC_IS_NULL(SELF))
                     SELF = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<PMC* pow(PMC* value, PMC* dest)>
+=item C<PMC* pow(PMC *value, PMC *dest)>
 
 =cut
 
 */
-    PMC* pow(PMC* value, PMC* dest) {
+    PMC* pow(PMC *value, PMC *dest) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_pow_LuaNumber(INTERP, n, value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 return Parrot_LuaNumber_pow_LuaString(INTERP, n, value, dest);
-            }
-            else {
-                real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
-                        SELF.name());
-            }
+
+            real_exception(INTERP, NULL, ILL_INHERIT,
+                "attempt to perform arithmetic on a %Ss value", SELF.name());
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__pow");
-            if (meth != NULL) {
+
+            if (meth) {
                 dest = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(dest)) {
+                if (PMC_IS_NULL(dest))
                     dest = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return dest;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<void i_pow(PMC* value)>
+=item C<void i_pow(PMC *value)>
 
 =cut
 
 */
-    void i_pow(PMC* value) {
+    void i_pow(PMC *value) {
 MMD_LuaNumber: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_pow_LuaNumber(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_LuaString: {
-            PMC* n = SELF.tonumber();
-            if (PMC_type(n) == dynpmc_LuaNumber) {
+            PMC *n = SELF.tonumber();
+
+            if (PMC_type(n) == dynpmc_LuaNumber)
                 Parrot_LuaNumber_i_pow_LuaString(INTERP, n, value);
-            }
-            else {
+            else
                 real_exception(INTERP, NULL, ILL_INHERIT,
-                        "attempt to perform arithmetic on a %S value",
+                    "attempt to perform arithmetic on a %Ss value",
                         SELF.name());
-            }
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__pow");
-            if (meth != NULL) {
+
+            if (meth) {
                 SELF = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(SELF)) {
+                if (PMC_IS_NULL(SELF))
                     SELF = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to perform arithmetic on a %S value",
+                "attempt to perform arithmetic on a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<INTVAL is_equal(PMC* value)>
+=item C<INTVAL is_equal(PMC *value)>
 
 Compares the string with C<value>; returns true if
 they match.
@@ -832,7 +800,7 @@
 =cut
 
 */
-    INTVAL is_equal(PMC* value) {
+    INTVAL is_equal(PMC *value) {
 MMD_LuaString: {
             STRING *s = PMC_str_val(SELF);
             STRING *v = LuaString.value.get_string();
@@ -845,7 +813,7 @@
 
 /*
 
-=item C<INTVAL cmp(PMC* value)>
+=item C<INTVAL cmp(PMC *value)>
 
 Compares the string with C<value>; returns -1 if the
 string is smaller, 0 if they are equal, and 1 if C<value>
@@ -856,7 +824,7 @@
 =cut
 
 */
-    INTVAL cmp(PMC* value) {
+    INTVAL cmp(PMC *value) {
 MMD_LuaString: {
             STRING *s = PMC_str_val(SELF);
             STRING *v = LuaString.value.get_string();
@@ -864,7 +832,7 @@
         }
 MMD_DEFAULT: {
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to compare string with %Ss",
+                "attempt to compare string with %Ss",
                     VTABLE_name(INTERP, value));
         }
     }
@@ -876,69 +844,73 @@
 =cut
 
 */
-    PMC* concatenate(PMC* value,  PMC* dest) {
+    PMC* concatenate(PMC *value, PMC *dest) {
 MMD_LuaNumber: {
-            STRING* s = string_concat(INTERP,
-                SELF.get_string(),
-                LuaNumber.value.get_string(), 0);
+            STRING *s = string_concat(INTERP,
+                SELF.get_string(), LuaNumber.value.get_string(), 0);
+
             dest = pmc_new(INTERP, dynpmc_LuaString);
             VTABLE_set_string_native(INTERP, dest, s);
             return dest;
         }
 MMD_LuaString: {
-            STRING* s = string_concat(INTERP,
-                SELF.get_string(),
-                LuaString.value.get_string(), 0);
+            STRING *s = string_concat(INTERP,
+                SELF.get_string(), LuaString.value.get_string(), 0);
+
             dest = pmc_new(INTERP, dynpmc_LuaString);
             VTABLE_set_string_native(INTERP, dest, s);
             return dest;
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__concat");
-            if (meth != NULL) {
+
+            if (meth) {
                 dest = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(dest)) {
+                if (PMC_IS_NULL(dest))
                     dest = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return dest;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to concatenate a %S value",
+                "attempt to concatenate a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
 
 /*
 
-=item C<void i_concatenate(PMC* value)>
+=item C<void i_concatenate(PMC *value)>
 
 =cut
 
 */
-    void i_concatenate(PMC* value) {
+    void i_concatenate(PMC *value) {
 MMD_LuaNumber: {
-            STRING* s = SELF.get_string();
-            STRING* v = LuaNumber.value.get_string();
+            STRING *s = SELF.get_string();
+            STRING *v = LuaNumber.value.get_string();
             SELF.set_string_native(string_append(INTERP, s, v));
         }
 MMD_LuaString: {
-            STRING* s = SELF.get_string();
-            STRING* v = LuaString.value.get_string();
+            STRING *s = SELF.get_string();
+            STRING *v = LuaString.value.get_string();
             SELF.set_string_native(string_append(INTERP, s, v));
         }
 MMD_DEFAULT: {
             PMC *meth = find_meth(INTERP, value, "__concat");
-            if (meth != NULL) {
+
+            if (meth) {
                 SELF = Parrot_runops_fromc_args(INTERP, meth, "PPP",
                                                 SELF, value);
-                if (PMC_IS_NULL(SELF)) {
+                if (PMC_IS_NULL(SELF))
                     SELF = pmc_new(INTERP, dynpmc_LuaNil);
-                }
+
                 return;
             }
+
             real_exception(INTERP, NULL, ILL_INHERIT,
-                    "attempt to concatenate a %S value",
+                "attempt to concatenate a %Ss value",
                     VTABLE_name(INTERP, value));
         }
     }
@@ -960,9 +932,10 @@
         PMC *retval = Parrot_find_global_s(INTERP,
                              const_string(INTERP, "Lua::string"),
                              const_string(INTERP, "mt_string"));
-        if (NULL == retval)
-            retval = pmc_new(INTERP, dynpmc_LuaNil);
-        return retval;
+        if (retval)
+            return retval;
+
+        return pmc_new(INTERP, dynpmc_LuaNil);
     }
 
 /*
@@ -974,25 +947,28 @@
 
 */
     METHOD PMC* len() {
-        PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
-        PMC_num_val(retval) = SELF.elements();
+        PMC *retval         = pmc_new(INTERP, dynpmc_LuaNumber);
+        VTABLE_set_number_native(INTERP, retval, SELF.elements());
         return retval;
     }
 
 /*
 
-=item C<PMC* rawequal(PMC* value)>
+=item C<PMC* rawequal(PMC *value)>
 
 =cut
 
 */
-    METHOD PMC* rawequal(PMC* value) {
+    METHOD PMC* rawequal(PMC *value) {
         PMC *retval = pmc_new(INTERP, dynpmc_LuaBoolean);
+
         if (PMC_type(SELF) == PMC_type(value)
-         && 0 == string_equal(INTERP, PMC_str_val(SELF), PMC_str_val(value)))
-            PMC_int_val(retval) = 1;
+        && 0               == string_equal(INTERP, PMC_str_val(SELF),
+                                  VTABLE_get_string(INTERP, value)))
+            VTABLE_set_bool(INTERP, retval, 1);
         else
-            PMC_int_val(retval) = 0;
+            VTABLE_set_bool(INTERP, retval, 0);
+
         return retval;
     }
 
@@ -1015,7 +991,8 @@
             while (isspace((unsigned char)(*s2)))
                 s2++;
 
-            if (*s2 == '\0') {  /* no invalid trailing characters? */
+            /* no invalid trailing characters? */
+            if (*s2 == '\0') {
                 PMC *retval = pmc_new(INTERP, dynpmc_LuaNumber);
                 VTABLE_set_number_native(INTERP, retval, d);
                 string_cstring_free(s1);
@@ -1043,6 +1020,7 @@
         /* at least one valid digit? */
         if (s1 != s2) {
             string_cstring_free(s1);
+
             /* skip trailing spaces */
             while (isspace((unsigned char)(*s2)))
                 s2++;

Reply via email to