On Mon, Oct 17, 2005 at 11:30:35AM -0700, chromatic wrote:
> Hi there,
> 
> Here's a proposed patch (for review, not application) to generate
> src/extend.c from vtable.tbl.  It has some limitations:

Problem is that src/extend.c has some functions that aren't vtable methods.
I think the better solution is going to be to keep them in src/extend.c,
and auto-generate a second file for the vtable calls. So the version attached
generates src/extend_vtable.c

> - I'm not sure if the Makefile magic is perfect

I don't think that it was. I've tweaked it.

> - it doesn't pick up all of the C types used in vtable.tbl
> - it makes everything it understands in that file available
> - it doesn't include behavioral documentation
> 
> I think the correct approach is to annotate vtable.tbl with more
> information -- including the documentation strings -- to make generating
> files easier.

That seems reasonable.

I don't think that your test build actually attempted to compile your
generated src/extend.c, as it had some illegal lines. Notably in void
functions:


   void retval;
   ...
   retval = ...;
   ...
   return retval;


:-)

The attached passes parrot's make test, and will build and pass ponie.
*However*, I've not tried to rip out any of the now obsolete hand-written
VTABLE wrappers in extend.c. As this have different names from the auto-
generated wrappers, I expect link failures will ensue, needing downstream
changes. How many projects in the languages subdirectory rely on the current
src/extend.c?

Nicholas Clark
Index: lib/Parrot/Vtable.pm
===================================================================
--- lib/Parrot/Vtable.pm        (revision 9513)
+++ lib/Parrot/Vtable.pm        (working copy)
@@ -293,6 +293,9 @@
 {
     my $vtable = shift;
 
+    my $funcs  = '';
+    my $protos = '';
+
     for my $entry (@$vtable)
     {
         my ($return_type, $name, $params, $section, $mmd) = @$entry;
@@ -304,26 +307,49 @@
 
         while (my ($type, $name) = splice( @params, 0, 2 ))
         {
-            push @sig, find_type( $type ) . ' ' . $name;
-            push @args, $name;
+           eval
+           {
+               push @sig, find_type( $type ) . ' ' . $name;
+               push @args, $name;
+            };
         }
 
+        next if $@;
+
         my $signature = join( ', ', @sig  );
         my $arguments = join( ', ', @args );
 
         my $ret_type  = find_type( $return_type );
 
-        printf 
-"%s Parrot_PMC_%s( %s )
+        $protos .= sprintf "extern %s Parrot_PMC_%s( %s );\n",
+            $ret_type, $name, $signature;
+
+        $funcs .= sprintf 
+"/*
+
+=item C<%s
+%s(%s)>
+
+=cut
+
+*/
+
+%s Parrot_PMC_%s( %s )
 {
-    %s retval;
-    PARROT_CALLIN_START( interp );
-    retval = VTABLE_%s( %s );
+", ($ret_type, $name, $signature) x 2;
+
+        $funcs .= "    $ret_type retval;\n" unless $ret_type eq 'void';
+       $funcs .= "    PARROT_CALLIN_START( interp );\n    ";
+        $funcs .= "retval = " unless $ret_type eq 'void';
+        $funcs .= "VTABLE_$name( $arguments );
     PARROT_CALLIN_END( interp );
-    return retval;
-}\n\n", $ret_type, $name, $signature, $ret_type, $name, $arguments;
+    return";
+        $funcs .= " retval" unless $ret_type eq 'void';
+        $funcs .= ";\n}\n\n";
 
     }
+
+    return ($funcs, $protos);
 }
 
 sub find_type
@@ -339,6 +365,7 @@
         'FLOATVAL' => 'Parrot_Float',
         'void'     => 'void',
         'UINTVAL'  => 'Parrot_Int',
+        'size_t'   => 'size_t',
     );
 
     die "Unknown type $type\n" unless exists $typemap{ $type };
Index: MANIFEST
===================================================================
--- MANIFEST    (revision 9513)
+++ MANIFEST    (working copy)
@@ -42,6 +42,7 @@
 build_tools/pbc2c.pl                              [devel]
 build_tools/pmc2c.pl                              []
 build_tools/revision_c.pl                         [devel]
+build_tools/vtable_extend.pl                      []
 build_tools/vtable_h.pl                           []
 charset/ascii.c                                   []
 charset/ascii.h                                   []
Index: include/parrot/extend.h
===================================================================
--- include/parrot/extend.h     (revision 9513)
+++ include/parrot/extend.h     (working copy)
@@ -55,6 +55,8 @@
 
 #endif
 
+#include "parrot/extend_vtable.h" /* the auto-generated prototypes    */
+
 Parrot_VTABLE Parrot_get_vtable(Parrot_INTERP, Parrot_Int);
 Parrot_PMC Parrot_PMC_get_pmc_intkey(Parrot_INTERP, Parrot_PMC, Parrot_Int);
 Parrot_STRING Parrot_PMC_get_string(Parrot_INTERP, Parrot_PMC);
Index: config/gen/makefiles/root.in
===================================================================
--- config/gen/makefiles/root.in        (revision 9513)
+++ config/gen/makefiles/root.in        (working copy)
@@ -224,7 +224,8 @@
     $(INC_DIR)/vtable.h \
     $(INC_DIR)/oplib/core_ops.h \
     $(INC_DIR)/oplib/ops.h \
-    $(INC_DIR)/oplib/core_ops_switch.h
+    $(INC_DIR)/oplib/core_ops_switch.h \
+    $(INC_DIR)/extend_vtable.h
 
 GEN_SOURCES = \
     $(SRC_DIR)/core_ops.c \
@@ -235,7 +236,8 @@
     $(SRC_DIR)/parrot_config.c \
     $(SRC_DIR)/null_config.c \
     $(SRC_DIR)/install_config.c \
-    $(SRC_DIR)/exec_cpu.c
+    $(SRC_DIR)/exec_cpu.c \
+    $(SRC_DIR)/extend_vtable.c
 
 GEN_MODULES = \
     lib/Parrot/OpLib/core.pm
@@ -425,6 +427,7 @@
     $(SRC_DIR)/mmd$(O) \
     $(SRC_DIR)/builtin$(O) \
     $(SRC_DIR)/extend$(O) \
+    $(SRC_DIR)/extend_vtable$(O) \
     $(SRC_DIR)/revision$(O) \
     $(PF_DIR)/pf_items$(O) \
     $(OPS_DIR)/core_ops$(O) \
@@ -895,6 +898,9 @@
 
 $(SRC_DIR)/exec_cpu$(O) : $(GENERAL_H_FILES) ${TEMP_exec_h} ${TEMP_jit_h} 
$(INC_DIR)/jit_emit.h
 
+$(INC_DIR)/extend_vtable.h $(SRC_DIR)/extend_vtable.c $(SRC_DIR)/vtable.h : 
vtable.tbl $(BUILD_TOOLS_DIR)/vtable_extend.pl lib/Parrot/Vtable.pm
+       $(PERL) $(BUILD_TOOLS_DIR)/vtable_extend.pl
+
 $(SRC_DIR)/exec_start$(O) : $(GENERAL_H_FILES) ${TEMP_exec_h}
 
 $(SRC_DIR)/exec_save$(O) : $(GENERAL_H_FILES) ${TEMP_exec_h}

Attachment: vtable_extend.pl
Description: Perl program

Reply via email to