develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35819 - in trunk: . languages/pipp/src/pct languages/pipp/t/php

From:
bernhard
Date:
January 20, 2009 08:56
Subject:
[svn:parrot] r35819 - in trunk: . languages/pipp/src/pct languages/pipp/t/php
Message ID:
20090120165611.AEA82CB9AE@x12.develooper.com
Author: bernhard
Date: Tue Jan 20 08:56:10 2009
New Revision: 35819

Modified:
   trunk/NEWS
   trunk/languages/pipp/src/pct/actions.pm
   trunk/languages/pipp/t/php/oo.t

Log:
[Pipp] Add support for __METHOD__

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Tue Jan 20 08:56:10 2009
@@ -35,7 +35,7 @@
     - back to working state
     - ported to pir
   + Pipp
-    - add support for predefined constant __CLASS__
+    - add support for predefined constant __CLASS__ and __METHOD__
     - add initial support for static members
     - add support for namespaced constants
     - constants are now handled as package vars

Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm	(original)
+++ trunk/languages/pipp/src/pct/actions.pm	Tue Jan 20 08:56:10 2009
@@ -688,12 +688,11 @@
     if $key eq 'open' {
         # note that $<param_list> creates a new PAST::Block.
         my $block := $( $<param_list> );
+        $block.name( ~$<method_name> );
+        $block.blocktype( 'method' );
+        $block.control('return_pir');
 
-        # set up scope 'package' for the superglobals
-        our @?SUPER_GLOBALS;
-        for ( @?SUPER_GLOBALS ) { $block.symbol( :scope('package'), $_ ); }
-
-        $block.unshift(
+        $block.push(
             PAST::Op.new(
                 :pasttype('bind'),
                 PAST::Var.new(
@@ -708,14 +707,36 @@
             )
         );
 
+        # set up scope 'package' for the superglobals
+        our @?SUPER_GLOBALS;
+        for ( @?SUPER_GLOBALS ) { $block.symbol( :scope('package'), $_ ); }
+
         @?BLOCK.unshift( $block );
     }
     else {
+        our $?NS;
+        our $?CLASS;
+        my $ns :=  $?NS ~ '\\' ~ $?CLASS ~ '::';
+
         my $block := @?BLOCK.shift();
 
-        $block.name( ~$<method_name> );
-        $block.blocktype( 'method' );
-        $block.control('return_pir');
+        $block.push(
+            PAST::Op.new(
+                :pasttype('bind'),
+                PAST::Var.new(
+                    :name('__METHOD__'),
+                    :isdecl(1),
+                    :scope('package'),
+                    :viviself('PhpNull'),
+                    :namespace($ns)
+                ),
+                PAST::Val.new(
+                    :value($block.name()),
+                    :returns('PhpString'),
+                )
+            )
+        );
+
         $block.push( $( $<statement_list> ) );
 
         make $block;

Modified: trunk/languages/pipp/t/php/oo.t
==============================================================================
--- trunk/languages/pipp/t/php/oo.t	(original)
+++ trunk/languages/pipp/t/php/oo.t	Tue Jan 20 08:56:10 2009
@@ -20,7 +20,7 @@
 use FindBin;
 use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
 
-use Parrot::Test tests => 16;
+use Parrot::Test tests => 17;
 
 language_output_is( 'Pipp', <<'CODE', <<'OUT', 'definition of a class' );
 <?php
@@ -358,3 +358,34 @@
 A
 OUT
 
+language_output_is( 'Pipp', <<'CODE', <<'OUT', '__METHOD__' );
+<?php
+
+class A {
+    function ecHO_class () {
+        echo __CLASS__;
+        echo "\n";
+        echo __METHOD__;
+        echo "\n";
+    }
+
+    function prinT_Class () {
+        echo __CLASS__;
+        echo "\n";
+        echo __METHOD__;
+        echo "\n";
+    }
+}
+
+$a = new A;
+$a->ecHO_class();
+$a->prinT_Class();
+
+?>
+CODE
+A
+ecHO_class
+A
+prinT_Class
+OUT
+



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About