perl.cvs.parrot
[Top] [All Lists]

[svn:parrot] r20559 - in trunk: lib/Parrot/Pmc2c t/tools

Subject: [svn:parrot] r20559 - in trunk: lib/Parrot/Pmc2c t/tools
From:
Date: Wed, 8 Aug 2007 08:00:16 -0700 PDT
Newsgroups: perl.cvs.parrot

Author: particle
Date: Wed Aug  8 08:00:15 2007
New Revision: 20559

Modified:
   trunk/lib/Parrot/Pmc2c/MethodEmitter.pm
   trunk/lib/Parrot/Pmc2c/Parser.pm
   trunk/t/tools/pmc2c.t

Log:
[pmc2c]: added support for parsing and emitting PDD07-compliant types (e.g. 
'PMC *'.) we can now convert .pmc files to PDD07.

Modified: trunk/lib/Parrot/Pmc2c/MethodEmitter.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/MethodEmitter.pm     (original)
+++ trunk/lib/Parrot/Pmc2c/MethodEmitter.pm     Wed Aug  8 08:00:15 2007
@@ -98,7 +98,14 @@
     my $args    = $self->parameters;
     my $ro      = $pmc->flag('is_ro') ? '' : '';
     my $decs    = $self->decorators;
+
+    # convert 'type*' to 'type *' per PDD07
+    $ret =~ s/^(.*)\s*(\*)$/$1 $2/;
+
+    # convert args to PDD07
     $args = ", $args" if $args =~ /\S/;
+    $args =~ s/(\w+)\s*(\*)\s*/$1 $2/g;
+
     my ( $decorators, $export, $extern, $newl, $semi, $interp, $pmcvar );
     $decorators = length @$decs ? join $/ => @$decs, '' : '';
     if ($for_header eq 'HEADER') {
@@ -114,10 +121,11 @@
         $newl   = "\n";
         $semi   = "";
         $interp = 'interp';
-        $pmcvar    = ' pmc';
+        $pmcvar    = 'pmc';
     }
+
     return <<"EOC";
-$decorators$export$extern$ret${newl}Parrot_${pmcname}${ro}_$meth(PARROT_INTERP,
 PMC*$pmcvar$args)$semi
+$decorators$export$extern$ret${newl}Parrot_${pmcname}${ro}_$meth(PARROT_INTERP,
 PMC *$pmcvar$args)$semi
 EOC
 }
 
@@ -139,16 +147,25 @@
     "FLOATVAL" => "N",
     "double"   => "d",
     "STRING*"  => "S",
+    "STRING *" => "S",
     "char*"    => "t",
+    "char *"   => "t",
     "PMC*"     => "P",
+    "PMC *"    => "P",
     "short*"   => "2",
+    "short *"  => "2",
     "int*"     => "3",
+    "int *"    => "3",
     "long*"    => "4",
+    "long *"   => "4",
     "void"     => "v",
     "void*"    => "b",
+    "void *"   => "b",
     "void**"   => "B",
+    "void **"  => "B",
 
     #"BIGNUM*" => "???" # RT#43731
+    #"BIGNUM *"=> "???" # RT#43731
 );
 
 sub proto {

Modified: trunk/lib/Parrot/Pmc2c/Parser.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/Parser.pm    (original)
+++ trunk/lib/Parrot/Pmc2c/Parser.pm    Wed Aug  8 08:00:15 2007
@@ -80,8 +80,8 @@
         ((?:PARROT_\w+\s+)+)? #decorators
         ((?:PCC)?METHOD\s+)?  #method flag
 
-        (\w+\**)              #return type
-        \s+
+        (\w+(?:\s*\*)?)       #return type
+        \s*
         (\w+)                 #method name
         \s*
         \( ([^\(]*) \)        #parameters
@@ -103,7 +103,6 @@
         $decorators =~ s/^\s*(.*?)\s*$/$1/s;
         $decorators = [split /\s+/ => $decorators];
 
-
         my $method = Parrot::Pmc2c::Method->new( {
             name        => $methodname,
             parent_name => $pmc->name,

Modified: trunk/t/tools/pmc2c.t
==============================================================================
--- trunk/t/tools/pmc2c.t       (original)
+++ trunk/t/tools/pmc2c.t       Wed Aug  8 08:00:15 2007
@@ -155,7 +155,7 @@
     }
 }
 END_PMC
-Parrot_a_init(PARROT_INTERP, PMC* pmc)
+Parrot_a_init(PARROT_INTERP, PMC *pmc)
 {
 #line 2
 END_C
@@ -168,7 +168,7 @@
     }
 }
 END_PMC
-Parrot_a_init(PARROT_INTERP, PMC* pmc)
+Parrot_a_init(PARROT_INTERP, PMC *pmc)
 {
 #line 4
 END_C

<Prev in Thread] Current Thread [Next in Thread>
  • [svn:parrot] r20559 - in trunk: lib/Parrot/Pmc2c t/tools, particle <=