cvsuser 05/04/05 04:36:49
Modified: dynclasses foo.pmc
lib/Parrot Pmc2c.pm
src mmd.c
t/dynclass foo.t
Log:
MMD 18 - rebuild MMD_table for dynamic PMCs
* after registering a dynmic PMC (group) the MMD_table is rebuilt
* test with the Foo pmc
Revision Changes Path
1.5 +3 -2 parrot/dynclasses/foo.pmc
Index: foo.pmc
===================================================================
RCS file: /cvs/public/parrot/dynclasses/foo.pmc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- foo.pmc 22 Aug 2004 09:00:15 -0000 1.4
+++ foo.pmc 5 Apr 2005 11:36:43 -0000 1.5
@@ -1,10 +1,11 @@
/*
- * Sample Foo class
+ * Sample Foo class used to verify dynamic loading and
+ * proper inheritance - used for testing only
*/
#include "parrot/parrot.h"
-pmclass Foo dynpmc {
+pmclass Foo dynpmc does scalar extends Integer {
INTVAL get_integer() {
return 42;
1.70 +13 -2 parrot/lib/Parrot/Pmc2c.pm
Index: Pmc2c.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/Pmc2c.pm,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- Pmc2c.pm 4 Apr 2005 08:39:42 -0000 1.69
+++ Pmc2c.pm 5 Apr 2005 11:36:47 -0000 1.70
@@ -200,7 +200,6 @@
EOC
while (my ($class, $info) = each %classes) {
next if $info->{flags}->{noinit};
- my $lc_class = lc $class;
$cout .= <<"EOC";
Parrot_${class}_class_init(interpreter, type$class, pass);
EOC
@@ -208,6 +207,18 @@
$cout .= <<"EOC";
}
+ /*
+ * force rebuilding of the static MMD_table
+ * TODO only for classes that have mmds
+ */
+EOC
+ while (my ($class, $info) = each %classes) {
+ next if $info->{flags}->{noinit};
+ $cout .= <<"EOC";
+ Parrot_mmd_rebuild_table(interpreter, type$class, -1);
+EOC
+ }
+ $cout .= <<"EOC";
return pmc;
}
1.64 +18 -13 parrot/src/mmd.c
Index: mmd.c
===================================================================
RCS file: /cvs/public/parrot/src/mmd.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- mmd.c 4 Apr 2005 16:03:27 -0000 1.63
+++ mmd.c 5 Apr 2005 11:36:48 -0000 1.64
@@ -1605,27 +1605,32 @@
table = interpreter->binop_mmd_funcs + func_nr;
x_funcs = table->x;
y_funcs = table->y;
- if (type >= x_funcs)
- return;
+ /* preallocat slot, resize */
+ if (type >= x_funcs || type >= y_funcs)
+ mmd_register(interpreter, func_nr, type, type, table->default_func);
+ x_funcs = table->x;
+ y_funcs = table->y;
/*
* go through MRO and install functions
*/
for (c = 1; c < nc; ++c) {
parent = VTABLE_get_pmc_keyed_int(interpreter, mro, c);
parent_type = parent->vtable->base_type;
- for (other = 0; other < (UINTVAL)enum_class_max; ++other) {
- if (other >= y_funcs)
- break;
+ if (parent_type >= type) {
+ /* XXX warning */
+ continue;
+ }
+ for (other = 0; other < type; ++other) {
/* (other, parent) */
offset = x_funcs * other + parent_type;
func = table->mmd_funcs[offset];
- if (func == table->default_func)
- continue;
- if (table->mmd_funcs[x_funcs * other + type] ==
- table->default_func) {
- if (other == parent_type)
- mmd_register(interpreter, func_nr, type, type, func);
- mmd_register(interpreter, func_nr, type, other, func);
+ if (func != table->default_func) {
+ if (table->mmd_funcs[x_funcs * other + type] ==
+ table->default_func) {
+ if (other == parent_type)
+ mmd_register(interpreter, func_nr, type, type, func);
+ mmd_register(interpreter, func_nr, type, other, func);
+ }
}
/* now for (parent, other) */
offset = x_funcs * parent_type + other;
1.2 +26 -3 parrot/t/dynclass/foo.t
Index: foo.t
===================================================================
RCS file: /cvs/public/parrot/t/dynclass/foo.t,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- foo.t 10 Mar 2005 22:46:06 -0000 1.1
+++ foo.t 5 Apr 2005 11:36:49 -0000 1.2
@@ -16,9 +16,9 @@
=cut
-use Parrot::Test tests => 1;
+use Parrot::Test tests => 2;
-pir_output_is(<< 'CODE', << 'OUTPUT', "abs");
+pir_output_is(<< 'CODE', << 'OUTPUT', "get_integer");
.sub main @MAIN
loadlib P1, "foo"
@@ -32,3 +32,26 @@
CODE
42
OUTPUT
+
+pir_output_is(<< 'CODE', << 'OUTPUT', "inherited add");
+.sub _main @MAIN
+ .local pmc d, l, r
+ $P0 = loadlib "foo"
+ print "ok\n"
+ l = new "Foo"
+ l = 3
+ r = new BigInt
+ r = 0x7ffffff
+ d = new Undef
+ add d, l, r
+ print d
+ print "\n"
+ $S0 = typeof d
+ print $S0
+ print "\n"
+.end
+CODE
+ok
+134217730
+BigInt
+OUTPUT