Author: leo
Date: Mon Mar 13 13:16:08 2006
New Revision: 11893
Modified:
trunk/src/pmc/float.pmc
trunk/t/pmc/float.t
Log:
PMCs - Float.new_from_cstring
* remove bogus instantiate
* implement Float.new_from_cstring
Modified: trunk/src/pmc/float.pmc
==============================================================================
--- trunk/src/pmc/float.pmc (original)
+++ trunk/src/pmc/float.pmc Mon Mar 13 13:16:08 2006
@@ -38,22 +38,23 @@
/*
-=item C<PMC* instantiate()>
+=item C<PMC new_from_string(STRING *rep)>
-Create a new Float 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);
- /* TODO non-PMC arguments */
- if (argcP)
- VTABLE_set_number_native(INTERP, res,
- VTABLE_get_number(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_num_val(res) = string_to_num(INTERP, rep);
return res;
}
Modified: trunk/t/pmc/float.t
==============================================================================
--- trunk/t/pmc/float.t (original)
+++ trunk/t/pmc/float.t Mon Mar 13 13:16:08 2006
@@ -6,7 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 45;
+use Parrot::Test tests => 46;
=head1 NAME
@@ -1363,3 +1363,13 @@
OUTPUT
+pir_output_is( <<'CODE', <<OUTPUT, "new_from_string");
+.sub main :main
+ .const .Float pi = "3.1"
+ print pi
+ print "\n"
+.end
+CODE
+3.1
+OUTPUT
+