develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r34672 - in trunk/languages/pipp/src: common pct

From:
bernhard
Date:
December 30, 2008 13:17
Subject:
[svn:parrot] r34672 - in trunk/languages/pipp/src: common pct
Message ID:
20081230211718.23C63CB9FA@x12.develooper.com
Author: bernhard
Date: Tue Dec 30 13:17:17 2008
New Revision: 34672

Modified:
   trunk/languages/pipp/src/common/guts.pir
   trunk/languages/pipp/src/pct/actions.pm

Log:
[Pipp] Use a plain 'Class' pmc for PHP classes.
Work on public class members.
Fail with setting up a default values of member variables.


Modified: trunk/languages/pipp/src/common/guts.pir
==============================================================================
--- trunk/languages/pipp/src/common/guts.pir	(original)
+++ trunk/languages/pipp/src/common/guts.pir	Tue Dec 30 13:17:17 2008
@@ -86,16 +86,32 @@
 
 .sub 'pipp_create_class'
     .param string name
-    .local pmc class
 
-    # Create class.
-    $P0 = get_root_global ['parrot'], 'P6metaclass'
-    class = $P0.'new_class'(name)
+    .local pmc class
+    class = newclass name
 
     .return (class)
 .end
 
 
+=item tipp_add_attribute(class, attr_name, attr_value)
+
+Adds an attribute with the given name to the class or role.
+See C<!keyword_has> in Rakudo.
+
+=cut
+
+.sub 'pipp_add_attribute'
+    .param pmc class
+    .param string attr_name
+
+    addattribute class, attr_name
+
+    .return ()
+.end
+
+
+
 =back
 
 =cut

Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm	(original)
+++ trunk/languages/pipp/src/pct/actions.pm	Tue Dec 30 13:17:17 2008
@@ -212,12 +212,9 @@
 method constructor_call($/) {
     make
         PAST::Op.new(
-            :name( 'new' ),
-            :pasttype( 'callmethod' ),
-            PAST::Var.new(
-                :name( ~$<CLASS_NAME> ),
-                :scope( 'package' ),
-            )
+            # :inline( "$S1 = 'member'\n$P2 = new 'PhpString'\n$P2 = 'workaround in actions.pm:215'\n%r = new %0\nsetattribute %r, $S1, $P2" ),
+            :inline( "%r = new %0" ),                                                   
+            ~$<CLASS_NAME>
         );
 }
 
@@ -621,7 +618,8 @@
     }
     else {
         my $block := @?BLOCK.shift();
-        $block.namespace( $<CLASS_NAME><ident> );
+        my $class_name := ~$<CLASS_NAME><ident>;
+        $block.namespace( $class_name );
         $block.push(
             # Start of class definition; make PAST to create class object if
             # we're creating a new class.
@@ -635,7 +633,7 @@
                 PAST::Op.new(
                     :pasttype('call'),
                     :name('pipp_create_class'),
-                    ~$<CLASS_NAME><ident> 
+                    PAST::Val.new( :value($class_name) )
                 )
             )
         );
@@ -651,12 +649,21 @@
         # declare the attributes
         for $<class_member_definition> {
             my $member_name := ~$_<VAR_NAME><ident>;
-            $methods_block.symbol( $member_name, :scope('attribute') );
-            $methods_block.push(
-                PAST::Var.new(
-                    :name(~$member_name),
-                    :scope('attribute'),
-                    :isdecl(1)
+            $methods_block.symbol(
+                $member_name,
+                :scope('attribute'),
+                :default( $( $_<literal> ) )
+            );
+
+            $block.push(
+                PAST::Op.new(
+                    :pasttype('call'),
+                    :name('pipp_add_attribute'),
+                    PAST::Var.new(
+                        :name('def'),
+                        :scope('register')
+                    ),
+                    PAST::Val.new( :value($member_name) )
                 )
             );
         }



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