[svn:parrot] r41230 - in trunk: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sat Sep 12 13:37:59 UTC 2009
Author: bacek
Date: Sat Sep 12 13:37:58 2009
New Revision: 41230
URL: https://trac.parrot.org/parrot/changeset/41230
Log:
[cage] Remove more dead VTABLE_instantiate functions. Add Integer.init_pmc
Modified:
trunk/src/pmc/bigint.pmc
trunk/src/pmc/bignum.pmc
trunk/src/pmc/complex.pmc
trunk/src/pmc/integer.pmc
trunk/t/pmc/integer.t
Modified: trunk/src/pmc/bigint.pmc
==============================================================================
--- trunk/src/pmc/bigint.pmc Sat Sep 12 13:14:55 2009 (r41229)
+++ trunk/src/pmc/bigint.pmc Sat Sep 12 13:37:58 2009 (r41230)
@@ -591,40 +591,6 @@
RETURN(STRING *version);
}
-/*
-
-=item C<PMC *instantiate(PMC *sig)>
-
-Object constructor. SELF is a BigInt Class object. Return a new
-BigInt object.
-
-=cut
-
-*/
- VTABLE PMC *instantiate(PMC *sig) {
- UNUSED(sig)
- return PMCNULL;
-
- /* TODO -- actually build this thing */
-#if 0
- int argcP = REG_INT(interp, 3);
- int base;
- PMC *res;
- STRING *num;
-
- res = pmc_new(INTERP, enum_class_BigInt);
- if (!argcP) {
- return res;
- }
- base = 10;
- if (argcP == 2)
- base = VTABLE_get_integer(INTERP, REG_PMC(interp, 6));
- num = VTABLE_get_string(INTERP, REG_PMC(interp, 5));
- VTABLE_set_string_keyed_int(INTERP, res, base, num);
- return res;
-#endif
- }
-
VTABLE void init() {
bigint_init(INTERP, SELF);
PObj_custom_destroy_SET(SELF);
Modified: trunk/src/pmc/bignum.pmc
==============================================================================
--- trunk/src/pmc/bignum.pmc Sat Sep 12 13:14:55 2009 (r41229)
+++ trunk/src/pmc/bignum.pmc Sat Sep 12 13:37:58 2009 (r41230)
@@ -807,38 +807,6 @@
RETURN(STRING *version);
}
-/*
-
-=item C<PMC *instantiate(PMC *sig)>
-
-Object constructor. SELF is a BigNum Class object. Return a new
-BigNum object.
-
-=cut
-
-*/
- VTABLE PMC *instantiate(PMC *sig) {
-#ifdef PARROT_HAS_GMP
- int argcP = REG_INT(interp, 3);
- int base;
- PMC *res;
- STRING *num;
-
- res = pmc_new(INTERP, enum_class_BigNum);
- if (!argcP) {
- return res;
- }
- base = 10;
- if (argcP == 2)
- base = VTABLE_get_integer(INTERP, REG_PMC(interp, 6));
- num = VTABLE_get_string(INTERP, REG_PMC(interp, 5));
- VTABLE_set_string_keyed_int(INTERP, res, base, num);
- return res;
-#else
- return PMCNULL;
-#endif
- }
-
VTABLE void init() {
bignum_init(INTERP, SELF);
PObj_custom_destroy_SET(SELF);
Modified: trunk/src/pmc/complex.pmc
==============================================================================
--- trunk/src/pmc/complex.pmc Sat Sep 12 13:14:55 2009 (r41229)
+++ trunk/src/pmc/complex.pmc Sat Sep 12 13:37:58 2009 (r41230)
@@ -224,63 +224,6 @@
/*
-=item C<PMC *instantiate(PMC *sig)>
-
-Create a new complex PMC with passed arguments according to pdd03.
-
-=cut
-
-*/
-
- VTABLE PMC *instantiate(PMC *sig) {
- return PMCNULL;
-
- /* TODO -- really build this thing */
-#if 0
- PMC *res = pmc_new(INTERP, enum_class_Complex);
- FLOATVAL re = 0.0;
- FLOATVAL im = 0.0;
- int argcI = REG_INT(interp, 1);
- int argcS = REG_INT(interp, 2);
- int argcP = REG_INT(interp, 3);
- int argcN = REG_INT(interp, 4);
-
- /*
- * we can only allow 0..2 arguments of one kind. For
- * mixed (e.g. N, P) args the order of arguments isn't fixed
- */
- if (argcP) {
- re = VTABLE_get_number(INTERP, REG_PMC(interp, 5));
-
- if (argcP == 2)
- im = VTABLE_get_number(INTERP, REG_PMC(interp, 6));
- /* TODO throw exception if argument mismatch */
- }
- else if (argcN) {
- re = REG_NUM(interp, 5);
-
- if (argcN == 2)
- im = REG_NUM(interp, 6);
- }
- else if (argcI) {
- re = REG_INT(interp, 5);
-
- if (argcI == 2)
- im = REG_INT(interp, 6);
- }
- else if (argcS == 1) {
- complex_parse_string(INTERP, &RE(res), &IM(res), REG_STR(interp, 5));
- return res;
- }
-
- RE(res) = re;
- IM(res) = im;
- return res;
-#endif
- }
-
-/*
-
=item C<opcode_t *invoke(void *next)>
Pythonic object constructor. SELF is a Complex Class object. Return a new
Modified: trunk/src/pmc/integer.pmc
==============================================================================
--- trunk/src/pmc/integer.pmc Sat Sep 12 13:14:55 2009 (r41229)
+++ trunk/src/pmc/integer.pmc Sat Sep 12 13:37:58 2009 (r41230)
@@ -47,7 +47,8 @@
ATTR INTVAL iv; /* the value of this Integer */
/*
-=item C<PMC instantiate(PMC *sig)>
+
+=item C<PMC init_pmc(PMC *init)>
Create a new Integer with arguments passed according to pdd03.
@@ -59,37 +60,18 @@
*/
- VTABLE PMC *instantiate(PMC *sig) {
- PMC * const ret = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
- const opcode_t * const arg_op = interp->current_args;
- INTVAL init = 0;
-
- if (VTABLE_elements(interp, sig) == 2) {
- switch (VTABLE_get_integer_keyed_int(INTERP, sig, 1)) {
- case PARROT_ARG_I:
- init = REG_INT(interp, arg_op[3]);
- break;
- case PARROT_ARG_IC:
- init = arg_op[3];
- break;
- default:
- Parrot_ex_throw_from_c_args(INTERP, NULL,
- EXCEPTION_SYNTAX_ERROR,
- "Integer.instantiate: unhandled initializer");
- break;
- }
- }
+ VTABLE void init() {
+ Parrot_Integer_attributes * const attrs =
+ (Parrot_Integer_attributes *)PMC_data(SELF);
- VTABLE_set_integer_native(INTERP, ret, init);
- return ret;
+ attrs->iv = 0;
}
-
- VTABLE void init() {
+ VTABLE void init_pmc(PMC *init) {
Parrot_Integer_attributes * const attrs =
(Parrot_Integer_attributes *)PMC_data(SELF);
- attrs->iv = 0;
+ attrs->iv = VTABLE_get_integer(INTERP, init);
}
/*
Modified: trunk/t/pmc/integer.t
==============================================================================
--- trunk/t/pmc/integer.t Sat Sep 12 13:14:55 2009 (r41229)
+++ trunk/t/pmc/integer.t Sat Sep 12 13:37:58 2009 (r41230)
@@ -19,7 +19,8 @@
.sub 'test' :main
.include 'test_more.pir'
- plan(60)
+ plan(62)
+ test_init()
test_basic_math()
test_truthiness_and_definedness()
test_set_string_native()
@@ -40,6 +41,15 @@
test_cmp_RT59336()
.end
+.sub test_init
+ .local pmc i1, i2
+ i1 = new ['Integer']
+ is(i1, 0, "Default value of Integer is 0")
+ i1 = 42
+ i2 = new ['Integer'], i1
+ is(i2, 42, "Initialize with argument set correct value")
+.end
+
.sub test_get_as_base_bounds_check
throws_like(<<'CODE', ':s get_as_base\: base out of bounds', 'get_as_base lower bound check')
.sub main
More information about the parrot-commits
mailing list