[svn:parrot] r44854 - branches/ops_pct/compilers/opsc/src/Ops/Compiler

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Mar 10 10:18:36 UTC 2010


Author: bacek
Date: Wed Mar 10 10:18:35 2010
New Revision: 44854
URL: https://trac.parrot.org/parrot/changeset/44854

Log:
Start generating PAST top-down

Modified:
   branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
   branches/ops_pct/compilers/opsc/src/Ops/Compiler/Grammar.pm

Modified: branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Wed Mar 10 10:18:11 2010	(r44853)
+++ branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Wed Mar 10 10:18:35 2010	(r44854)
@@ -58,7 +58,7 @@
 method op($/) {
 
     # Handling flags.
-    my %flags := pir::new__Ps('OrderedHash');
+    my %flags := hash();
     for $<op_flag> {
         %flags{~$_<identifier>} := 1;
     }
@@ -74,10 +74,15 @@
 
     my $op := Ops::Op.new(
         :name(~$<op_name>),
-        $<op_body>.ast
+        #$<op_body>.ast
     );
 
-    $op.jump($<op_body>.ast<jump>);
+    for $<op_body><body_word> {
+        #say('# BANG');
+        $op.push($_.ast);
+    }
+
+    # FIXME op.jump($<op_body>.ast<jump>);
     $op<flags> := %flags;
     $op<args>  := @args;
     $op<type>  := ~$<op_type>;
@@ -86,7 +91,7 @@
     if !%flags<flow> {
         $op.push(PAST::Op.new(
             :pasttype('inline'),
-            :inline("\n" ~ '{{+=OP_SIZE}};')
+            :inline("\n" ~ 'goto_next')
             ));
     }
 
@@ -225,7 +230,7 @@
     make $past;
 }
 
-method op_body($/) {
+method _op_body($/) {
     my $past := PAST::Block.new(
         :node($/),
     );
@@ -293,6 +298,52 @@
     make $past;
 }
 
+method macro_param($/) {
+    make PAST::Var.new(
+        :name(~$/),
+        :node($/),
+    );
+}
+
+method body_word($/) {
+    #say('# body_word');
+    my $past;
+    if $<word> {
+        $past := PAST::Op.new(
+            :pasttype('inline'),
+            :inline(~$<word>)
+        );
+    }
+    elsif $<macro_param> {
+        $past := $<macro_param>.ast;
+    }
+    elsif $<op_macro> {
+        $past := $<op_macro>.ast;
+    }
+    else {
+        die('horribly');
+    }
+    #_dumper($past);
+    make $past;
+}
+
+method op_macro($/) {
+    #say('# op_macro');
+    my $macro_name := ~$<macro_type> ~ '_' ~ lc(~$<macro_destination>);
+    #if $macro_name eq 'restart_offset' || $macro_name eq 'goto_offset' {
+    #        $past<jump> := 'PARROT_JUMP_RELATIVE';
+    #}
+
+    my $past := PAST::Op.new(
+        :pasttype('call'),
+        :name($macro_name),
+    );
+
+    for $<body_word> {
+        $past.push($_.ast);
+    }
+    make $past;
+}
 
 method macro_sanity_checks($/) {
     #can't have NEXT with non-empty param

Modified: branches/ops_pct/compilers/opsc/src/Ops/Compiler/Grammar.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Compiler/Grammar.pm	Wed Mar 10 10:18:11 2010	(r44853)
+++ branches/ops_pct/compilers/opsc/src/Ops/Compiler/Grammar.pm	Wed Mar 10 10:18:35 2010	(r44854)
@@ -88,7 +88,6 @@
     '{' 
     <body_word>*?
     ^^ '}' 
-    {*}
 }
 
 #Process op body by breaking it into "words" consisting entirely of whitespace,
@@ -100,14 +99,17 @@
     | <op_macro>
     | $<word>=[<alnum>+|<punct>|<space>+]
     ]
+    {*}
 }
 
 token macro_param {
     '$' $<num>=[<digit>+]
+    {*}
 }
 
 rule op_macro {
-    <macro_type> <macro_destination> <macro_arg>
+    <macro_type> <macro_destination> '(' <body_word>? ')'
+    {*}
 }
 
 token macro_type {
@@ -129,10 +131,7 @@
 rule macro_arg {
     #XXX; needs to match balanced parens
     '('
-    [
-    | <macro_param>
-    | $<macro_word>=[[ <alnum>+ | <punct> | <space>+ ]*? ]
-    ]
+    <body_word>*?
     ')'
 }
 


More information about the parrot-commits mailing list