This is a first step in hiding vtable functions - not only: Using these macros also provides more readable source files:

instead of:

   PMC* getprop (STRING* key) {
        return ((PMC *)SELF->data)->vtable->getprop(INTERP,
                (PMC *)SELF->data, key);
   }

this now is:

   PMC* getprop (STRING* key) {
        return VTABLE_1(getprop, (PMC*) SELF->data, key);
   }

If people are ok with this, next step would be actually using these macros all over the tree.

For reference plz s. also:
Date: Mon, 30 Dec 2002 16:36:31 +0100
From: Leopold Toetsch <[EMAIL PROTECTED]>
Subject: Variable/value vtable split

leo
--- parrot/lib/Parrot/Vtable.pm Fri Jun 21 21:00:02 2002
+++ parrot-leo/lib/Parrot/Vtable.pm     Sun Mar 23 10:58:52 2003
@@ -6,7 +6,7 @@
 use strict;
 
 @Parrot::Vtable::ISA = qw(Exporter);
[EMAIL PROTECTED]::Vtable::EXPORT = qw(parse_vtable vtbl_defs vtbl_struct);
[EMAIL PROTECTED]::Vtable::EXPORT = qw(parse_vtable vtbl_defs vtbl_struct vtbl_macros);
 
 sub make_re {
     my $re = shift;
@@ -22,6 +22,8 @@
 my $arglist_re = make_re('(?:'.$param_re.'(?:\s*,\s*'.$param_re.')*)?');
 my $method_re = 
make_re('^\s*('.$type_re.')\s+('.$ident_re.')\s*\(('.$arglist_re.')\)\s*$');
 
+my $max_args = 0;
+
 sub parse_vtable {
 
     my $file = defined $_[0] ? shift() : 'vtable.tbl';
@@ -37,6 +39,8 @@
         
         if (/^\s*($type_re)\s+($ident_re)\s*\(($arglist_re)\)\s*$/) {
             push @{$vtable}, [ $1, $2, $3 ];
+           my $args = split(/,/, $3);
+           $max_args = $args if ($args > $max_args);
         } else {
             die "Syntax error at $file line ".$fh->input_line_number()."\n";
         }
@@ -83,6 +87,28 @@
     $struct .= "};\n";
     
     return $struct;
+}
+
+sub vtbl_macros {
+    my $i;
+    my $macros = <<"EOM";
+
+/*
+ * vtable accessor macros
+ * VTABLE_0  ... no extra args after (interpreter, pmc)
+ * VTABLE_1  ... 1 extra arg
+ * ...
+ */
+
+EOM
+    for ($i = 0; $i <= $max_args; $i++) {
+       my $args = join('', map {", arg$_" } (1 .. $i));
+       $macros .= <<"EOM"
+#define VTABLE_$i(method, pmc$args) \\
+    (pmc)->vtable-> ##method## (interpreter, pmc$args)
+EOM
+    }
+    $macros;
 }
 
 "SQUAWK";
--- parrot/vtable_h.pl  Fri Jun 21 21:00:01 2002
+++ parrot-leo/vtable_h.pl      Sun Mar 23 10:59:07 2003
@@ -32,5 +32,7 @@
 
 print OUT vtbl_struct($vtable);
 
+print OUT vtbl_macros($vtable);
+
 print OUT "\n#endif\n";
 

Reply via email to