Author: leo
Date: Mon Mar 13 12:25:10 2006
New Revision: 11892

Modified:
   trunk/src/pmc/integer.pmc
   trunk/src/pmc/string.pmc
   trunk/t/pmc/string.t

Log:
PMCs - mixed

* remove bogus instantiate
* implement String.new_from_cstring


Modified: trunk/src/pmc/integer.pmc
==============================================================================
--- trunk/src/pmc/integer.pmc   (original)
+++ trunk/src/pmc/integer.pmc   Mon Mar 13 12:25:10 2006
@@ -92,10 +92,6 @@
 
 Class method to construct an Integer from the string representation C<rep>.
 
-=item C<PMC* instantiate()>
-
-Class method to construct an Integer according to passed arguments.
-
 =cut
 
 */
@@ -113,64 +109,6 @@
         return res;
     }
 
-    PMC* instantiate() {
-        PMC *class = REG_PMC(2);
-        int argcP = REG_INT(3);
-        int argcS = REG_INT(2);
-        int base;
-        PMC *res, *arg;
-        STRING *num;
-        INTVAL type;
-        STRING *isa;
-
-        type = class->vtable->base_type;
-        if (!argcP) {
-            res = pmc_new(INTERP, type);
-            if (!argcS)
-                return res;
-            return DYNSELF.new_from_string(REG_STR(5), 0);
-        }
-        base = 10;
-        if (argcP == 2)
-            base = VTABLE_get_integer(INTERP, REG_PMC(6));
-        arg = REG_PMC(5);
-        isa = CONST_STRING(INTERP, "Integer");
-        if (VTABLE_isa(INTERP, arg, isa) && base == 10) {
-            res = pmc_new(INTERP, type);
-            PMC_int_val(res) = PMC_int_val(arg);
-            return res;
-        }
-
-        isa = CONST_STRING(INTERP, "Float");
-        if (VTABLE_isa(INTERP, arg, isa)) {
-            FLOATVAL d = VTABLE_get_number(INTERP, arg);
-            const char *sign = "-";
-            INTVAL i = VTABLE_get_integer(INTERP, arg);
-            d = floor(d);
-            if (d == i) {
-                res = pmc_new(INTERP, type);
-                PMC_int_val(res) = i;
-                return res;
-            }
-            if (!signbit(d))
-                sign = "";
-            d = fabs(d);
-            num = Parrot_sprintf_c(INTERP, "%s%.12g", sign, d);
-        }
-        else
-            num = VTABLE_get_string(INTERP, arg);
-        /* TODO preserved type */
-        res = pmc_new(INTERP, enum_class_BigInt);
-        VTABLE_set_string_keyed_int(INTERP, res, base, num);
-        if (num->strlen < 9) {  /* XXX */
-            /* TODO not if it would overflow */
-            INTVAL intnum = VTABLE_get_integer(INTERP, res);
-            res = pmc_new(INTERP, type); /*TODO morph */
-            PMC_int_val(res) = intnum;
-        }
-        return res;
-    }
-
 
 /*
 

Modified: trunk/src/pmc/string.pmc
==============================================================================
--- trunk/src/pmc/string.pmc    (original)
+++ trunk/src/pmc/string.pmc    Mon Mar 13 12:25:10 2006
@@ -42,23 +42,26 @@
 
 /*
 
-=item C<PMC* instantiate()>
+=item C<PMC new_from_string(STRING *rep)>
 
-Create a new String from the passed in argument. This is a class method,
-arguments are passed according to pdd03.
+Class method to construct an Integer from the string representation C<rep>.
 
 =cut
 
 */
-    PMC* instantiate() {
-        int argcP = REG_INT(3);
-        PMC *class = REG_PMC(2);
-        PMC *res = pmc_new(INTERP, class->vtable->base_type);
-        if (argcP)
-            VTABLE_set_string_native(INTERP, res,
-                    VTABLE_get_string(INTERP, REG_PMC(5)));
+    PMC* new_from_string(STRING *rep, INTVAL flags) {
+        INTVAL type;
+        PMC *res;
+
+        type = SELF->vtable->base_type;
+        if (flags & PObj_constant_FLAG)
+            res = constant_pmc_new(INTERP, type);
+        else
+            res = pmc_new(INTERP, type);
+        PMC_str_val(res) = rep;
         return res;
     }
+
 /*
 
 =item C<void mark()>

Modified: trunk/t/pmc/string.t
==============================================================================
--- trunk/t/pmc/string.t        (original)
+++ trunk/t/pmc/string.t        Mon Mar 13 12:25:10 2006
@@ -6,7 +6,7 @@
 use warnings;
 use lib qw( . lib ../lib ../../lib );
 use Test::More;
-use Parrot::Test tests => 38;
+use Parrot::Test tests => 39;
 
 =head1 NAME
 
@@ -1200,3 +1200,12 @@
 0
 1
 OUTPUT
+
+pir_output_is( <<'CODE', <<OUTPUT, "new_from_string");
+.sub main :main
+    .const .String ok = "ok\n"
+    print ok
+.end
+CODE
+ok
+OUTPUT

Reply via email to