[svn:parrot] r38668 - in branches/pmc_pct/compilers/pmcc: src/parser t t/data

bacek at svn.parrot.org bacek at svn.parrot.org
Sun May 10 05:34:16 UTC 2009


Author: bacek
Date: Sun May 10 05:34:16 2009
New Revision: 38668
URL: https://trac.parrot.org/parrot/changeset/38668

Log:
Inprove parsing of MACRO call arguments

Modified:
   branches/pmc_pct/compilers/pmcc/src/parser/actions.pm
   branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg
   branches/pmc_pct/compilers/pmcc/t/06-body.t
   branches/pmc_pct/compilers/pmcc/t/data/class26.pmc

Modified: branches/pmc_pct/compilers/pmcc/src/parser/actions.pm
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/parser/actions.pm	Sun May 10 05:33:49 2009	(r38667)
+++ branches/pmc_pct/compilers/pmcc/src/parser/actions.pm	Sun May 10 05:34:16 2009	(r38668)
@@ -201,9 +201,22 @@
     $past<is_self>  := $key eq 'SELF';
     $past<is_super> := $key eq 'SUPER';
 
+    #say("PARAMS " ~ $<c_parameters>);
+    for $<c_parameters> {
+        $past.push($_.ast);
+    }
+
     make $past;
 }
 
+method c_parameters($/) {
+    #say("c_parameters " ~ $/);
+    make PAST::Val.new(
+        :node($/),
+        :value(~$/)
+    );
+}
+
 # Local Variables:
 #   mode: pir
 #   fill-column: 100

Modified: branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg
==============================================================================
--- branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg	Sun May 10 05:33:49 2009	(r38667)
+++ branches/pmc_pct/compilers/pmcc/src/parser/grammar.pg	Sun May 10 05:34:16 2009	(r38668)
@@ -137,18 +137,22 @@
 
 rule c_body_statement {
     | <c_body_macro> {*}        #= macro
-    | <-[{}]>+ {*}              #= characters
+    | <-[{}]>  {*}              #= characters
     | <c_body> {*}              #= body
 }
 
 # Various macros for VTABLE body
 rule c_body_macro {
-    | 'SELF.' :: <identifier> '(' <-[()]>* ')' {*}    #= SELF
-    | 'SUPER' :: '(' <-[()]>* ')' {*}                 #= SUPER
+    | 'SELF.' :: [ <identifier> '(' <c_parameters>? ')' || <.panic: "Syntax error in SELF macro"> ]
+      {*} #= SELF
+    | 'SUPER' :: '(' <c_parameters> ')'
+      {*} #= SUPER
 }
 
+# We don't parse parameters. We are PMC, not C99 compiler (yet).
+# FIXME Instead of "<-[()]>" it should be something meaningful.
 rule c_parameters {
-    
+    <-[()]>+ {*}
 }
 
 # It's really bad signature

Modified: branches/pmc_pct/compilers/pmcc/t/06-body.t
==============================================================================
--- branches/pmc_pct/compilers/pmcc/t/06-body.t	Sun May 10 05:33:49 2009	(r38667)
+++ branches/pmc_pct/compilers/pmcc/t/06-body.t	Sun May 10 05:34:16 2009	(r38668)
@@ -8,7 +8,7 @@
     load_bytecode 'pmcc.pbc'
     .local int total
 
-    plan(7)
+    plan(8)
 
     .local string filename
 
@@ -24,9 +24,10 @@
 
     filename = 't/data/class26.pmc'
     $S0 = _slurp('t/data/class26.pmc')
-    check_one_file(filename, $S0, "'VTABLE_Integer_decrement(interp, pmc)'", "SELF.decrement was rewriten")
-    check_one_file(filename, $S0, "'VTABLE_Integer_add_int'", "SELF.add_int was rewriten")
-    check_one_file(filename, $S0, "'VTABLE_Integer_add_int(interp, pmc, 2)'", "SELF.add_int was rewriten")
+    check_one_file(filename, $S0, "'Parrot_Integer_decrement'", "SELF.decrement was rewriten")
+    check_one_file(filename, $S0, "'Parrot_Integer_decrement(interp, pmc)'", "SELF.decrement was rewriten with params")
+    check_one_file(filename, $S0, "'Parrot_Integer_add_int'", "SELF.add_int was rewriten")
+    check_one_file(filename, $S0, "'Parrot_Integer_add_int(interp, pmc, 2)'", "SELF.add_int was rewriten with params")
 .end
 
 

Modified: branches/pmc_pct/compilers/pmcc/t/data/class26.pmc
==============================================================================
--- branches/pmc_pct/compilers/pmcc/t/data/class26.pmc	Sun May 10 05:33:49 2009	(r38667)
+++ branches/pmc_pct/compilers/pmcc/t/data/class26.pmc	Sun May 10 05:34:16 2009	(r38668)
@@ -2,7 +2,9 @@
     VTABLE void increment() {
         SELF.decrement();
         if (1) {
+            SELF.eat_kittens(42, kitten);
             SELF.add_int(2);
+            SELF.eat_kitten(kitten);
         }
     }
 }


More information about the parrot-commits mailing list