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

[email protected]
Newsgroups perl.cvs.parrot
Message-ID <[email protected]>
Author: bernhard
Date: Fri Jan 16 06:17:18 2009
New Revision: 35631

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

Log:
[Pipp] Start to treat constants 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	Fri Jan 16 06:17:18 2009
@@ -124,6 +124,7 @@
         my $block :=
             PAST::Block.new(
                 :namespace($?NS),
+                :blocktype('immediate'),
                 $( $<statement_list> )
             );
         $?NS := '';
@@ -259,14 +260,25 @@
 }
 
 method constant($/) {
-    make
-        PAST::Op.new(
-            :name('constant'),
-            PAST::Val.new(
-                :returns('PhpString'),
-                :value( ~$<CONSTANT_NAME> ),
-            )
-        );
+    our $?NS;
+    if $?NS eq '' {
+        make
+            PAST::Op.new(
+                :name('constant'),
+                PAST::Val.new(
+                    :returns('PhpString'),
+                    :value( ~$<CONSTANT_NAME> ),
+                )
+            );
+    }
+    else {
+        make
+            PAST::Var.new(
+                :name(~$<CONSTANT_NAME>),
+                :scope('package'),
+                :namespace($?NS)
+            );
+    }
 }
 
 # TODO: merge with rule 'constant'
@@ -303,20 +315,32 @@
 
 method namespace_constant_definition($/) {
     our $?NS;
-    my $past := PAST::Block.new( :name('namespace_constant_definition') );
-    my $loadinit := $past.loadinit();
-    $loadinit.unshift(
+    my $past :=
         PAST::Op.new(
-            :pasttype('call'),
-            :name('define'),
-            :node( $/ ),
-            PAST::Val.new(
-                :value( $?NS ~ '\\' ~ ~$<CONSTANT_NAME> ),
-                :returns('PhpString'),
+            :pasttype('bind'),
+            PAST::Var.new(
+                :name(~$<CONSTANT_NAME>),
+                :isdecl(1),                                                           
+                :scope('package'),
+                :viviself('PhpNull'),
+                :namespace($?NS)
             ),
-            $( $<literal> ),
-        )
-    );
+            $( $<literal> )
+        );
+
+#   my $loadinit := $past.loadinit();
+#   $loadinit.unshift(
+#       PAST::Op.new(
+#           :pasttype('call'),
+#           :name('define'),
+#           :node( $/ ),
+#           PAST::Val.new(
+#               :value( $?NS ~ '\\' ~ ~$<CONSTANT_NAME> ),
+#               :returns('PhpString'),
+#           ),
+#           $( $<literal> ),
+#       )
+#   );
 
     make $past;
 }
@@ -496,7 +520,7 @@
 
 # Handle the operator precedence table.
 method expression($/, $key) {
-    if ($key eq 'end') {
+    if $key eq 'end' {
         make $( $<expr> );
     }
     else {
@@ -739,7 +763,7 @@
            $block.push( $($_) );
         }
 
-        my $methods_block := PAST::Block.new( :blocktype('immediate') );
+        my $methods_block := PAST::Block.new(:blocktype('immediate'));
 
         # declare the attributes
         for $<class_member_definition> {
@@ -882,7 +906,7 @@
 
 method quote_term($/, $key) {
     my $past;
-    if ($key eq 'literal') {
+    if $key eq 'literal' {
         $past := PAST::Val.new(
             :value( ~$<quote_literal> ),
             :returns('PhpString'),

Modified: trunk/languages/pipp/t/php/namespace.t
==============================================================================
--- trunk/languages/pipp/t/php/namespace.t	(original)
+++ trunk/languages/pipp/t/php/namespace.t	Fri Jan 16 06:17:18 2009
@@ -37,7 +37,7 @@
 CODE
 OUT
 
-language_output_is( 'Pipp', <<'CODE', <<'OUT', 'namespace A', todo => 'not implemented yet' );
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'namespace A' );
 <?php
 
 namespace A {
@@ -50,7 +50,7 @@
 FOO in A
 OUT
 
-language_output_is( 'Pipp', <<'CODE', <<'OUT', 'namespace A\B', todo => 'not implemented yet' );
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'namespace A\B' );
 <?php
 
 namespace A\B {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.