Author: chromatic
Date: Sun Jun  3 21:43:16 2007
New Revision: 18795

Modified:
   trunk/lib/Parrot/Pmc2c/UtilFunctions.pm
   trunk/lib/Parrot/Pmc2c/default.pm
   trunk/tools/dev/gen_class.pl

Log:
[PMC] Use PMCNULL instead of casting 0 when generating C for PMCs and stub PMCs.

Also updated the copyright notices, especially in generated PMCs.

Modified: trunk/lib/Parrot/Pmc2c/UtilFunctions.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/UtilFunctions.pm     (original)
+++ trunk/lib/Parrot/Pmc2c/UtilFunctions.pm     Sun Jun  3 21:43:16 2007
@@ -1,3 +1,7 @@
+/*
+Copyright (C) 2007, The Perl Foundation.
+$Id$
+*/
 package Parrot::Pmc2c::UtilFunctions;
 use strict;
 use warnings;
@@ -52,14 +56,15 @@
 sub gen_ret {
     my ( $method, $body ) = @_;
 
-    my $ret;
     if ($body) {
-        $ret = $method->{type} eq 'void' ? "$body;" : "return $body;";
+        return "$body;" if $method->{type} eq 'void';
+        return "return $body;";
     }
     else {
-        $ret = $method->{type} eq 'void' ? "" : "return ($method->{type})0;";
+        return '' if $method->{type} eq 'void';
+        return "return PMCNULL;" if $method->{type} eq 'PMC*';
+        return "return ($method->{type})0;";
     }
-    $ret;
 }
 
 =item C<dynext_load_code($library_name, %classes)>

Modified: trunk/lib/Parrot/Pmc2c/default.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/default.pm   (original)
+++ trunk/lib/Parrot/Pmc2c/default.pm   Sun Jun  3 21:43:16 2007
@@ -1,4 +1,7 @@
-
+/*
+Copyright (C) 2007, The Perl Foundation.
+$Id$
+*/
 =head1 Parrot::Pmc2c::default Instance Methods
 
 =over 4
@@ -49,7 +52,8 @@
     if ( $method->{type} ne 'void' ) {
 
         # This cheats, assuming that all return types can be cast from zero.
-        $ret = "return ($method->{type})0;";
+        $ret = $method->{type} eq 'PMC*' ? "return PMCNULL;"
+                                         : "return ($method->{type})0;";
     }
 
     # I think that these will be out by one - NWC

Modified: trunk/tools/dev/gen_class.pl
==============================================================================
--- trunk/tools/dev/gen_class.pl        (original)
+++ trunk/tools/dev/gen_class.pl        Sun Jun  3 21:43:16 2007
@@ -1,5 +1,5 @@
 #! perl
-# Copyright (C) 2001-2003, The Perl Foundation.
+# Copyright (C) 2001-2007, The Perl Foundation.
 # $Id$
 
 =head1 NAME
@@ -42,7 +42,7 @@
 ## emit file header
 print <<"EOF";
 /* ${classname}.pmc
- *  Copyright (C) 2001-2003, The Perl Foundation.
+ *  Copyright (C) 2001-2007, The Perl Foundation.
  *  SVN Info
  *     \$Id\$
  *  Overview:
@@ -70,8 +70,10 @@
     }
 
     print "    $retval $methname ($args) {\n";
+
     if ( $retval ne 'void' ) {
-        print "        return ($retval)0;\n";
+        print $retval eq 'PMC*' ? "        return PMCNULL;\n"
+                                : "        return ($retval)0;\n";
     }
     print "    }\n\n";
 }

Reply via email to