[svn:parrot] r35646 - in trunk/languages/pipp: docs src/pct

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

Modified:
   trunk/languages/pipp/docs/internals.pod
   trunk/languages/pipp/src/pct/actions.pm
   trunk/languages/pipp/src/pct/grammar.pg

Log:
[Pipp] Put class constants into a namespace.

Modified: trunk/languages/pipp/docs/internals.pod
==============================================================================
--- trunk/languages/pipp/docs/internals.pod	(original)
+++ trunk/languages/pipp/docs/internals.pod	Fri Jan 16 13:12:18 2009
@@ -39,6 +39,9 @@
 
 =item Class constants
 
+Class constants are stored a package variables in the namespace $?NS ~ '\\' ~ $?CLASS ~ '::'.
+The trailing '::' guarantees that there is no conflict with namespace constants.
+
 =item Class members
 
 =item function and method scope

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 13:12:18 2009
@@ -284,31 +284,31 @@
 
 # TODO: merge with rule 'constant'
 method class_constant($/) {
-    make
-        PAST::Op.new(
-            :name('constant'),
-            PAST::Val.new(
-                :returns('PhpString'),
-                :value( ~$/ ),
-            )
-        );
+    our $?NS;
+    make PAST::Var.new(
+        :scope('package'),
+        :namespace( $?NS ~ '\\' ~ $<CLASS_NAME> ~ '::'), 
+        :name(~$<CONSTANT_NAME>)
+    );
 }
 
 # class constants could probably also be set in a class init block
 method class_constant_definition($/) {
     our $?CLASS;
+    our $?NS;
     my $past := PAST::Block.new( :name('class_constant_definition') );
     my $loadinit := $past.loadinit();
     $loadinit.unshift(
         PAST::Op.new(
-            :pasttype('call'),
-            :name('define'),
-            :node( $/ ),
-            PAST::Val.new(
-                :value( $?CLASS ~ '::' ~ ~$<CONSTANT_NAME> ),
-                :returns('PhpString'),
+            :pasttype('bind'),
+            PAST::Var.new(
+                :name(~$<CONSTANT_NAME>),
+                :isdecl(1),                                                           
+                :scope('package'),
+                :viviself('PhpNull'),
+                :namespace( $?NS ~ '\\' ~ $?CLASS ~ '::')
             ),
-            $( $<literal> ),
+            $( $<literal> )
         )
     );
 

Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg	(original)
+++ trunk/languages/pipp/src/pct/grammar.pg	Fri Jan 16 13:12:18 2009
@@ -345,7 +345,7 @@
 }
 
 token class_constant {
-    <.CLASS_NAME> <.CLASS_CONSTANT_ACCESSOR> <.CONSTANT_NAME>
+    <CLASS_NAME> <.CLASS_CONSTANT_ACCESSOR> <CONSTANT_NAME>
     {*}
 }
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.