Author: jonathan
Date: Tue Apr 3 17:20:40 2007
New Revision: 17967
Modified:
trunk/lib/Parrot/Pmc2c.pm
trunk/lib/Parrot/Pmc2c/Utils.pm
trunk/src/inter_misc.c
trunk/src/mmd.c
trunk/src/ops/experimental.ops
trunk/src/pmc/class.pmc
trunk/src/pmc/complex.pmc
trunk/src/sub.c
Log:
Name-mangle NCI methods in PMCs. This allows you to have an NCI method with the
same name as a vtable method. We need this to implement PDD15.
Modified: trunk/lib/Parrot/Pmc2c.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c.pm (original)
+++ trunk/lib/Parrot/Pmc2c.pm Tue Apr 3 17:20:40 2007
@@ -972,22 +972,24 @@
foreach my $method ( @{ $self->{methods} } ) {
next unless $method->{loc} eq 'nci';
my $proto = proto( $method->{type}, $method->{parameters} );
+ my $symbol_name = defined $method->{symbol} ?
+ $method->{symbol} : $method->{meth};
if ( exists $method->{pre_block} ) {
$cout .= <<"EOC";
register_raw_nci_method_in_ns(interp, entry,
- F2DPTR(Parrot_${classname}_$method->{meth}), "$method->{meth}");
+ F2DPTR(Parrot_${classname}_$method->{meth}), "$symbol_name");
EOC
}
else {
$cout .= <<"EOC";
enter_nci_method(interp, entry,
F2DPTR(Parrot_${classname}_$method->{meth}),
- "$method->{meth}", "$proto");
+ "$symbol_name", "$proto");
EOC
}
if ( $method->{attrs}{write} ) {
$cout .= <<"EOC";
- Parrot_mark_method_writes(interp, entry, "$method->{meth}");
+ Parrot_mark_method_writes(interp, entry, "$symbol_name");
EOC
}
}
Modified: trunk/lib/Parrot/Pmc2c/Utils.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/Utils.pm (original)
+++ trunk/lib/Parrot/Pmc2c/Utils.pm Tue Apr 3 17:20:40 2007
@@ -694,11 +694,16 @@
$class_init = $method_hash;
}
else {
+ # Name-mangle NCI methods to avoid conflict with vtable methods.
+ if ($flag) {
+ $method_hash->{loc} = "nci" ;
+ $method_hash->{meth} = "nci_$methodname";
+ $method_hash->{symbol} = $methodname;
+ }
# name => method idx mapping
- $meth_hash{$methodname} = scalar @methods;
+ $meth_hash{$method_hash->{meth}} = scalar @methods;
- $method_hash->{loc} = "nci" if $flag;
$method_hash->{mmds} = [ ( $methodblock =~ /MMD_(\w+):/g ) ];
push @methods, $method_hash;
}
Modified: trunk/src/inter_misc.c
==============================================================================
--- trunk/src/inter_misc.c (original)
+++ trunk/src/inter_misc.c Tue Apr 3 17:20:40 2007
@@ -35,7 +35,7 @@
=cut
*/
-void Parrot_NCI_make_raw_nci(Interp *interp, PMC *method, void *func);
+void Parrot_NCI_nci_make_raw_nci(Interp *interp, PMC *method, void *func);
void
enter_nci_method(Parrot_Interp interp, const int type, void *func,
@@ -60,7 +60,7 @@
{
PMC * const method = pmc_new(interp, enum_class_NCI);
/* setup call func */
- Parrot_NCI_make_raw_nci(interp, method, func);
+ Parrot_NCI_nci_make_raw_nci(interp, method, func);
/* insert it into namespace */
VTABLE_set_pmc_keyed_str(interp, interp->vtables[type]->_namespace,
string_make(interp, name, strlen(name), NULL,
Modified: trunk/src/mmd.c
==============================================================================
--- trunk/src/mmd.c (original)
+++ trunk/src/mmd.c Tue Apr 3 17:20:40 2007
@@ -1176,7 +1176,7 @@
return da > db ? 1 : da < db ? -1 : 0;
}
-extern void Parrot_FixedPMCArray_sort(Interp* , PMC* pmc, PMC *cmp_func);
+extern void Parrot_FixedPMCArray_nci_sort(Interp* , PMC* pmc, PMC *cmp_func);
/*
@@ -1359,7 +1359,7 @@
/*
* sort it
*/
- Parrot_FixedPMCArray_sort(interp, sort, nci);
+ Parrot_FixedPMCArray_nci_sort(interp, sort, nci);
/*
* now helper has a sorted list of indices in the upper 16 bits
* fill helper with sorted candidates
Modified: trunk/src/ops/experimental.ops
==============================================================================
--- trunk/src/ops/experimental.ops (original)
+++ trunk/src/ops/experimental.ops Tue Apr 3 17:20:40 2007
@@ -2,7 +2,7 @@
** experimental.ops
*/
-extern PMC* Parrot_NameSpace_get_name(Interp* interp, PMC* pmc);
+extern PMC* Parrot_NameSpace_nci_get_name(Interp* interp, PMC* pmc);
VERSION = PARROT_VERSION;
@@ -255,7 +255,7 @@
=cut
op classname(out PMC, invar PMC) :object_base {
- PMC *ns = Parrot_NameSpace_get_name(interp,
+ PMC *ns = Parrot_NameSpace_nci_get_name(interp,
VTABLE_namespace(interp, $2));
if (PMC_IS_NULL(ns) || VTABLE_elements(interp, ns) < 2)
{
Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc (original)
+++ trunk/src/pmc/class.pmc Tue Apr 3 17:20:40 2007
@@ -49,7 +49,7 @@
if (!PMC_IS_NULL(class_info->namespace)) {
/* If we have a namespace name, make a key from it's name. */
/* XXX BAD AND WRONG! Need to call get_name method properly! */
- PMC *fq_name = Parrot_NameSpace_get_name(interp,
class_info->namespace);
+ PMC *fq_name = Parrot_NameSpace_nci_get_name(interp,
class_info->namespace);
int elements = VTABLE_elements(interp, fq_name);
int j;
for (j = 0; j < elements; j++) {
Modified: trunk/src/pmc/complex.pmc
==============================================================================
--- trunk/src/pmc/complex.pmc (original)
+++ trunk/src/pmc/complex.pmc Tue Apr 3 17:20:40 2007
@@ -1229,8 +1229,8 @@
METHOD PMC* tan() {
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_sin(INTERP, SELF);
- e = Parrot_Complex_cos(INTERP, SELF);
+ d = Parrot_Complex_nci_sin(INTERP, SELF);
+ e = Parrot_Complex_nci_cos(INTERP, SELF);
Parrot_Complex_i_divide_Complex(INTERP, d, e);
return d;
}
@@ -1238,8 +1238,8 @@
METHOD PMC* cot() {
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_cos(INTERP, SELF);
- e = Parrot_Complex_sin(INTERP, SELF);
+ d = Parrot_Complex_nci_cos(INTERP, SELF);
+ e = Parrot_Complex_nci_sin(INTERP, SELF);
Parrot_Complex_i_divide_Complex(INTERP, d, e);
return d;
}
@@ -1249,7 +1249,7 @@
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
RE(d) = 1.0;
IM(d) = 0.0;
- e = Parrot_Complex_cos(INTERP, SELF);
+ e = Parrot_Complex_nci_cos(INTERP, SELF);
Parrot_Complex_i_divide_Complex(INTERP, d, e);
return d;
}
@@ -1259,7 +1259,7 @@
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
RE(d) = 1.0;
IM(d) = 0.0;
- e = Parrot_Complex_sin(INTERP, SELF);
+ e = Parrot_Complex_nci_sin(INTERP, SELF);
Parrot_Complex_i_divide_Complex(INTERP, d, e);
return d;
}
@@ -1303,10 +1303,10 @@
e = Parrot_Complex_multiply_Complex(INTERP, SELF, SELF, e);
RE(e) = 1.0 - RE(e);
IM(e) = -IM(e);
- d = Parrot_Complex_sqrt(INTERP, e);
+ d = Parrot_Complex_nci_sqrt(INTERP, e);
RE(d) -= IM(SELF);
IM(d) += RE(SELF);
- d = Parrot_Complex_ln(INTERP, d);
+ d = Parrot_Complex_nci_ln(INTERP, d);
RE(e) = IM(d);
IM(e) = -RE(d);
return e;
@@ -1318,10 +1318,10 @@
e = Parrot_Complex_multiply_Complex(INTERP, SELF, SELF, e);
RE(e) = 1.0 - RE(e);
IM(e) = -IM(e);
- d = Parrot_Complex_sqrt(INTERP, e);
+ d = Parrot_Complex_nci_sqrt(INTERP, e);
RE(d) += IM(SELF);
IM(d) -= RE(SELF);
- e = Parrot_Complex_ln(INTERP, d);
+ e = Parrot_Complex_nci_ln(INTERP, d);
RE(d) = IM(e) + 2.0 * atan(1);
IM(d) = -RE(e);
return d;
@@ -1338,7 +1338,7 @@
RE(e) = -re;
IM(e) = 1 - im;
Parrot_Complex_i_divide_Complex(INTERP, d, e);
- d = Parrot_Complex_ln(INTERP, d);
+ d = Parrot_Complex_nci_ln(INTERP, d);
RE(e) = IM(d) / -2.0;
IM(e) = RE(d) / 2.0;
return e;
@@ -1353,7 +1353,7 @@
b = IM(SELF);
RE(d) = a/(a*a + b*b);
IM(d) = -b/(a*a + b*b);
- d = Parrot_Complex_atan(INTERP, d);
+ d = Parrot_Complex_nci_atan(INTERP, d);
return d;
}
@@ -1364,7 +1364,7 @@
b = IM(SELF);
RE(d) = a/(a*a + b*b);
IM(d) = -b/(a*a + b*b);
- d = Parrot_Complex_asin(INTERP, d);
+ d = Parrot_Complex_nci_asin(INTERP, d);
return d;
}
@@ -1375,7 +1375,7 @@
b = IM(SELF);
RE(d) = a/(a*a + b*b);
IM(d) = -b/(a*a + b*b);
- d = Parrot_Complex_acos(INTERP, d);
+ d = Parrot_Complex_nci_acos(INTERP, d);
return d;
}
@@ -1422,8 +1422,8 @@
METHOD PMC* tanh() {
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_sinh(INTERP, SELF);
- e = Parrot_Complex_cosh(INTERP, SELF);
+ d = Parrot_Complex_nci_sinh(INTERP, SELF);
+ e = Parrot_Complex_nci_cosh(INTERP, SELF);
Parrot_Complex_i_divide_Complex(INTERP, d, e);
return d;
}
@@ -1431,7 +1431,7 @@
METHOD PMC* coth() {
FLOATVAL a, b;
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_tanh(INTERP, SELF);
+ d = Parrot_Complex_nci_tanh(INTERP, SELF);
a = RE(d);
b = IM(d);
RE(d) = a/(a*a + b*b);
@@ -1442,7 +1442,7 @@
METHOD PMC* csch() {
FLOATVAL a, b;
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_sinh(INTERP, SELF);
+ d = Parrot_Complex_nci_sinh(INTERP, SELF);
a = RE(d);
b = IM(d);
RE(d) = a/(a*a + b*b);
@@ -1453,7 +1453,7 @@
METHOD PMC* sech() {
FLOATVAL a, b;
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_cosh(INTERP, SELF);
+ d = Parrot_Complex_nci_cosh(INTERP, SELF);
a = RE(d);
b = IM(d);
RE(d) = a/(a*a + b*b);
@@ -1494,7 +1494,7 @@
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
RE(d) = IM(SELF);
IM(d) = -RE(SELF);
- d = Parrot_Complex_asin(INTERP, d);
+ d = Parrot_Complex_nci_asin(INTERP, d);
RE(e) = -IM(d);
IM(e) = RE(d);
return e;
@@ -1503,7 +1503,7 @@
METHOD PMC* acosh() {
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_acos(INTERP, SELF);
+ d = Parrot_Complex_nci_acos(INTERP, SELF);
RE(e) = -IM(d);
IM(e) = RE(d);
return e;
@@ -1514,7 +1514,7 @@
PMC *e = pmc_new(INTERP, SELF->vtable->base_type);
RE(d) = IM(SELF);
IM(d) = -RE(SELF);
- d = Parrot_Complex_atan(INTERP, d);
+ d = Parrot_Complex_nci_atan(INTERP, d);
RE(e) = -IM(d);
IM(e) = RE(d);
return e;
@@ -1528,7 +1528,7 @@
b = IM(SELF);
RE(d) = a/(a*a + b*b);
IM(d) = -b/(a*a + b*b);
- d = Parrot_Complex_atanh(INTERP, d);
+ d = Parrot_Complex_nci_atanh(INTERP, d);
return d;
}
@@ -1539,7 +1539,7 @@
b = IM(SELF);
RE(d) = a/(a*a + b*b);
IM(d) = -b/(a*a + b*b);
- d = Parrot_Complex_asinh(INTERP, d);
+ d = Parrot_Complex_nci_asinh(INTERP, d);
return d;
}
@@ -1550,7 +1550,7 @@
b = IM(SELF);
RE(d) = a/(a*a + b*b);
IM(d) = -b/(a*a + b*b);
- d = Parrot_Complex_acosh(INTERP, d);
+ d = Parrot_Complex_nci_acosh(INTERP, d);
return d;
}
@@ -1581,8 +1581,8 @@
else
dest = pmc_new(INTERP, SELF->vtable->base_type);
l = Parrot_Complex_multiply_Complex(INTERP,
- Parrot_Complex_ln(INTERP, SELF), value, l);
- dest = Parrot_Complex_exp(INTERP, l);
+ Parrot_Complex_nci_ln(INTERP, SELF), value, l);
+ dest = Parrot_Complex_nci_exp(INTERP, l);
return dest;
}
MMD_DEFAULT: {
@@ -1592,8 +1592,8 @@
else
dest = pmc_new(INTERP, SELF->vtable->base_type);
l = Parrot_Complex_multiply(INTERP,
- Parrot_Complex_ln(INTERP, SELF), value, l);
- dest = Parrot_Complex_exp(INTERP, l);
+ Parrot_Complex_nci_ln(INTERP, SELF), value, l);
+ dest = Parrot_Complex_nci_exp(INTERP, l);
return dest;
}
}
@@ -1601,10 +1601,10 @@
/* sqrt(x) = exp(ln(x)/2) */
METHOD PMC* sqrt() {
PMC *d = pmc_new(INTERP, SELF->vtable->base_type);
- d = Parrot_Complex_ln(INTERP, SELF);
+ d = Parrot_Complex_nci_ln(INTERP, SELF);
RE(d) *= 0.5;
IM(d) *= 0.5;
- d = Parrot_Complex_exp(INTERP, d);
+ d = Parrot_Complex_nci_exp(INTERP, d);
return d;
}
Modified: trunk/src/sub.c
==============================================================================
--- trunk/src/sub.c (original)
+++ trunk/src/sub.c Tue Apr 3 17:20:40 2007
@@ -270,7 +270,7 @@
/* XXX use method lookup - create interface
* see also pbc.c
*/
-extern PMC* Parrot_NameSpace_get_name(Interp *interp, PMC* pmc);
+extern PMC* Parrot_NameSpace_nci_get_name(Interp *interp, PMC* pmc);
STRING*
Parrot_full_sub_name(Interp *interp, PMC* sub)
@@ -290,7 +290,7 @@
STRING *j;
Parrot_block_DOD(interp);
- ns_array = Parrot_NameSpace_get_name(interp, s->namespace_stash);
+ ns_array = Parrot_NameSpace_nci_get_name(interp, s->namespace_stash);
if (s->name) {
VTABLE_push_string(interp, ns_array, s->name);
}