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

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

From:
bernhard
Date:
January 23, 2009 03:55
Subject:
[svn:parrot] r35907 - in trunk/languages/pipp: docs src/pct t/php
Message ID:
20090123115501.21B6ECB9AE@x12.develooper.com
Author: bernhard
Date: Fri Jan 23 03:55:00 2009
New Revision: 35907

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

Log:
[Pipp] Start working on support for 'global'

Modified: trunk/languages/pipp/docs/internals.pod
==============================================================================
--- trunk/languages/pipp/docs/internals.pod	(original)
+++ trunk/languages/pipp/docs/internals.pod	Fri Jan 23 03:55:00 2009
@@ -32,14 +32,22 @@
 
 =over 4
 
-=item globals in top file
+=item variables outside a function in top file
 
 Lexical. Might need extra treatment.
 
-=item globals in included files
+=item variables outside a function in included files
 
 Lexical in scope of the included file.
 
+=item variables declared as 'global' in functions
+
+Lexical in outer scope. TODO: not sure of that
+
+=item variables declared as 'static' in functions
+
+????
+
 =item Class constants
 
 Class constants are stored a package variables in the namespace $?NS ~ '\\' ~ $?CLASS ~ '::'.

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 23 03:55:00 2009
@@ -328,6 +328,13 @@
     make $past;
 }
 
+method global_declaration($/) {
+    # for now just a placeholder
+    my $past := PAST::Stmts.new( :name('global_definition') );
+
+    make $past;
+}
+
 method argument_list($/) {
     my $past := PAST::Op.new(
                     :pasttype('call'),

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 23 03:55:00 2009
@@ -131,6 +131,7 @@
     | <echo_statement>                 {*}  #= echo_statement
     | <expression_statement>           {*}  #= expression_statement
     | <constant_definition>            {*}  #= constant_definition
+    | <global_declaration>             {*}  #= global_declaration
     | <if_statement>                   {*}  #= if_statement
     | <while_statement>                {*}  #= while_statement
     | <do_while_statement>             {*}  #= do_while_statement
@@ -243,7 +244,7 @@
 }
 
 
-# identifiers
+# identifiers and declarations
 
 token class_name {
     <ident>
@@ -287,6 +288,13 @@
     '$' <ident>
 }
 
+# TODO: is global only allowed in functions and methods ?
+# TODO: multiple globals can be declared
+rule global_declaration {
+    'global' <var_name> <.statement_delimiter>
+     {*}
+}
+
 # terms
 rule method_call {
     <var> '->' <method_name> '(' <argument_list> ')'

Modified: trunk/languages/pipp/t/php/functions.t
==============================================================================
--- trunk/languages/pipp/t/php/functions.t	(original)
+++ trunk/languages/pipp/t/php/functions.t	Fri Jan 23 03:55:00 2009
@@ -1,4 +1,4 @@
-# Copyright (C) 2008, The Perl Foundation.
+# Copyright (C) 2008-2009, The Perl Foundation.
 # $Id$
 
 =head1 NAME
@@ -20,7 +20,7 @@
 use FindBin;
 use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
 
-use Parrot::Test tests => 15;
+use Parrot::Test tests => 16;
 
 language_output_is( 'Pipp', <<'CODE', <<'OUT', 'function with no args' );
 <?php
@@ -300,3 +300,21 @@
 CODE
 I was a variable.
 OUT
+
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'global', todo => 'not working yet' );
+<?php
+
+$outer = "outer variable\n";
+
+function echo_outer( )  {
+  global $outer;
+  echo $outer;
+}
+
+echo_outer();
+
+?>
+CODE
+outer variable
+OUT



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