[svn:parrot] r40313 - in trunk: . config/gen/makefiles lib/Parrot/Pmc2c src/dynpmc t/dynpmc

cotto at svn.parrot.org cotto at svn.parrot.org
Tue Jul 28 20:39:11 UTC 2009


Author: cotto
Date: Tue Jul 28 20:39:11 2009
New Revision: 40313
URL: https://trac.parrot.org/parrot/changeset/40313

Log:
[pmc2c] make VTABLE function inheritance work between dynpmcs, plus a test (see TT #882)
flh++ for reporting and the MethodEmitter.pm part of this patch

Added:
   trunk/src/dynpmc/foo2.pmc   (contents, props changed)
   trunk/t/dynpmc/foo2.t   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/config/gen/makefiles/dynpmc.in
   trunk/lib/Parrot/Pmc2c/MethodEmitter.pm
   trunk/src/dynpmc/foo.pmc
   trunk/t/dynpmc/foo.t

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	Tue Jul 28 20:39:09 2009	(r40312)
+++ trunk/MANIFEST	Tue Jul 28 20:39:11 2009	(r40313)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Tue Jul 28 19:34:41 2009 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Tue Jul 28 20:21:00 2009 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1249,6 +1249,7 @@
 src/dynpmc/dynlexpad.pmc                                    [devel]src
 src/dynpmc/ext.pir                                          []
 src/dynpmc/foo.pmc                                          [devel]src
+src/dynpmc/foo2.pmc                                         [devel]src
 src/dynpmc/gdbmhash.pmc                                     [devel]src
 src/dynpmc/main.pasm                                        []
 src/dynpmc/rational.pmc                                     [devel]src
@@ -1670,6 +1671,7 @@
 t/distro/meta_yml.t                                         [test]
 t/dynpmc/dynlexpad.t                                        [test]
 t/dynpmc/foo.t                                              [test]
+t/dynpmc/foo2.t                                             [test]
 t/dynpmc/gdbmhash.t                                         [test]
 t/dynpmc/rational.t                                         [test]
 t/dynpmc/rotest.t                                           [test]

Modified: trunk/config/gen/makefiles/dynpmc.in
==============================================================================
--- trunk/config/gen/makefiles/dynpmc.in	Tue Jul 28 20:39:09 2009	(r40312)
+++ trunk/config/gen/makefiles/dynpmc.in	Tue Jul 28 20:39:11 2009	(r40313)
@@ -29,7 +29,7 @@
 # add your dynamic pmcs here
 PMC_TARGETS := \
   dynlexpad$(LOAD_EXT) \
-  foo$(LOAD_EXT) \
+  foo_group$(LOAD_EXT) \
   rotest$(LOAD_EXT) \
 #IF(has_gdbm):  gdbmhash$(LOAD_EXT) \
   rational$(LOAD_EXT) \
@@ -56,6 +56,14 @@
   sha256$(O) \
   sha512$(O)
 
+PMCS_FOO := \
+  foo.pmc \
+  foo2.pmc
+
+OBJS_FOO := \
+  foo$(O) \
+  foo2$(O)
+
 #IF(win32 and cc==gcc):LIB_GDBM := -llibgdbm
 #ELSIF(win32):LIB_GDBM := libgdbm.lib
 #ELSE:LIB_GDBM := -lgdbm
@@ -101,8 +109,14 @@
 dynlexpad.dump: dynlexpad.pmc
 	$(PMC2CD) dynlexpad.pmc
 
-foo$(LOAD_EXT): foo$(O)
-	$(LD) @ld_out at foo$(LOAD_EXT) foo$(O) $(LINKARGS)
+foo_group$(LOAD_EXT): $(OBJS_FOO) lib-foo_group$(O)
+	$(LD) @ld_out at foo_group$(LOAD_EXT) lib-foo_group$(O) $(OBJS_FOO) $(LINKARGS)
+
+lib-foo_group$(O): foo_group.c
+	$(CC) -c @cc_o_out at lib-foo_group$(O) $(INCLUDES) $(CFLAGS) foo_group.c
+
+foo_group.c: $(OBJS_FOO)
+	$(PMC2C) --library foo_group --c $(PMCS_FOO)
 
 foo$(O): foo.c
 	$(CC) -c @cc_o_out at foo$(O) $(INCLUDES) $(CFLAGS) foo.c
@@ -113,6 +127,15 @@
 foo.dump: foo.pmc
 	$(PMC2CD) foo.pmc
 
+foo2$(O): foo2.c
+	$(CC) -c @cc_o_out at foo2$(O) $(INCLUDES) $(CFLAGS) foo2.c
+
+foo2.c: foo2.dump foo.pmc
+	$(PMC2CC) foo2.pmc
+
+foo2.dump: foo2.pmc foo.dump
+	$(PMC2CD) foo2.pmc
+
 rotest$(LOAD_EXT): rotest$(O)
 	$(LD) @ld_out at rotest$(LOAD_EXT) rotest$(O) $(LINKARGS)
 

Modified: trunk/lib/Parrot/Pmc2c/MethodEmitter.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/MethodEmitter.pm	Tue Jul 28 20:39:09 2009	(r40312)
+++ trunk/lib/Parrot/Pmc2c/MethodEmitter.pm	Tue Jul 28 20:39:11 2009	(r40313)
@@ -267,7 +267,16 @@
             \bSUPER\b         # Macro: SUPER
             \(\s*(.*?)\)      # capture argument list
           }x,
-            sub { "interp->vtables[$supertype]->$name(" . full_arguments($1) . ')' }
+            sub {
+              if($pmc->is_dynamic($super)) {
+                return "Parrot_" . $super .
+                  "_get_vtable(interp)->$name(" . full_arguments($1) .
+                  ')';
+              }
+              else {
+                return "interp->vtables[$supertype]->$name(" . full_arguments($1) . ')';
+              }
+            }
         );
     }
 

Modified: trunk/src/dynpmc/foo.pmc
==============================================================================
--- trunk/src/dynpmc/foo.pmc	Tue Jul 28 20:39:09 2009	(r40312)
+++ trunk/src/dynpmc/foo.pmc	Tue Jul 28 20:39:11 2009	(r40313)
@@ -8,7 +8,7 @@
  * proper inheritance - for testing only
  */
 
-pmclass Foo dynpmc provides scalar extends Integer {
+pmclass Foo dynpmc group foo_group provides scalar extends Integer {
 
     VTABLE INTVAL get_integer() {
         return 42;

Added: trunk/src/dynpmc/foo2.pmc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/src/dynpmc/foo2.pmc	Tue Jul 28 20:39:11 2009	(r40313)
@@ -0,0 +1,25 @@
+/*
+ * $Id$
+ * Copyright (C) 2009, Parrot Foundation.
+ */
+
+/*
+ * Sample Foo2 class used to verify dynamic loading and
+ * proper inheritance - for testing only
+ */
+
+pmclass Foo2 dynpmc group foo_group provides scalar extends Foo {
+
+    VTABLE INTVAL get_integer() {
+        INTVAL i = SUPER();
+        return i + 1;
+    }
+}
+
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Modified: trunk/t/dynpmc/foo.t
==============================================================================
--- trunk/t/dynpmc/foo.t	Tue Jul 28 20:39:09 2009	(r40312)
+++ trunk/t/dynpmc/foo.t	Tue Jul 28 20:39:11 2009	(r40313)
@@ -26,7 +26,7 @@
 pir_output_is( << 'CODE', << 'OUTPUT', "get_integer" );
 
 .sub main :main
-    loadlib $P1, "foo"
+    loadlib $P1, "foo_group"
     $P1 = new "Foo"
 
     $I1 = $P1
@@ -41,7 +41,7 @@
 .sub main :main
     ## load a relative pathname without the extension.  loadlib will convert the
     ## '/' characters to '\\' on windows.
-    $S0 = "runtime/parrot/dynext/foo"
+    $S0 = "runtime/parrot/dynext/foo_group"
     loadlib $P1, $S0
 
     ## ensure that we can still make Foo instances.
@@ -65,7 +65,7 @@
     ## convert cwd to an absolute pathname without the extension, and load it.
     ## this should always find the version in the build directory, since that's
     ## the only place "make test" will work.
-    $S0 = concat "/runtime/parrot/dynext/foo"
+    $S0 = concat "/runtime/parrot/dynext/foo_group"
     loadlib $P1, $S0
 
     ## ensure that we can still make Foo instances.
@@ -87,7 +87,7 @@
     $S0 = $P12["load_ext"]
 
     ## load a relative pathname with an extension.
-    $S0 = concat "runtime/parrot/dynext/foo", $S0
+    $S0 = concat "runtime/parrot/dynext/foo_group", $S0
     loadlib $P1, $S0
 
     ## ensure that we can still make Foo instances.
@@ -112,7 +112,7 @@
     ## convert $S0 to an absolute pathname with extension, and load it.
     ## this should always find the version in the build directory, since that's
     ## the only place "make test" will work.
-    $S0 = concat $S0, "/runtime/parrot/dynext/foo"
+    $S0 = concat $S0, "/runtime/parrot/dynext/foo_group"
     $S0 = concat $S0, $S1
     loadlib $P1, $S0
 
@@ -132,7 +132,7 @@
     pir_output_is( << 'CODE', << 'OUTPUT', "inherited add" );
 .sub _main :main
     .local pmc d, l, r
-    $P0 = loadlib "foo"
+    $P0 = loadlib "foo_group"
     print "ok\n"
     l = new "Foo"
     l = 42
@@ -157,7 +157,7 @@
 pir_output_is( <<'CODE', <<'OUTPUT', "Foo subclass isa Integer" );
 .sub main :main
     .local pmc F, f, d, r
-    loadlib F, "foo"
+    loadlib F, "foo_group"
     f = new "Foo"
     f = 1
     d = new 'Integer'
@@ -175,7 +175,7 @@
 # load our Foo test (pseudo) language
 # it defines one PMC type "Foo"
 .HLL "Fool"
-.loadlib "foo"
+.loadlib "foo_group"
 .sub main :main
     new $P1, "Foo"      # load by name
     $I1 = $P1
@@ -188,7 +188,7 @@
 
 pir_output_is( << 'CODE', << 'OUTPUT', ".HLL 2" );
 .HLL "Fool"
-.loadlib "foo"
+.loadlib "foo_group"
 .sub main :main
     new $P1, 'Foo'       # load by index
     $I1 = $P1

Added: trunk/t/dynpmc/foo2.t
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/t/dynpmc/foo2.t	Tue Jul 28 20:39:11 2009	(r40313)
@@ -0,0 +1,44 @@
+#! perl
+# Copyright (C) 2005, Parrot Foundation.
+# $Id$
+
+use strict;
+use warnings;
+use lib qw( . lib ../lib ../../lib );
+use Test::More;
+use Parrot::Test tests => 1;
+use Parrot::Config;
+
+=head1 NAME
+
+t/dynpmc/foo.t - Test for a very simple dynamic PMC
+
+=head1 SYNOPSIS
+
+        % prove t/dynpmc/foo.t
+
+=head1 DESCRIPTION
+
+Tests the Foo PMC.
+
+=cut
+
+pir_output_is( << 'CODE', << 'OUTPUT', "dynpmcs can use SUPER to call parent dynpmc VTABLE functions" );
+
+.sub main :main
+    $P0 = loadlib 'foo_group'
+    $P1 = new "Foo2"
+
+    $I1 = $P1
+    say $I1
+.end
+CODE
+43
+OUTPUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:


More information about the parrot-commits mailing list