Author: chromatic
Date: Sun Feb 24 14:50:10 2008
New Revision: 26050

Modified:
   trunk/languages/pheme/lib/PhemeCompiler.pir
   trunk/languages/pheme/lib/PhemeObjects.pir
   trunk/languages/pheme/lib/PhemeSymbols.pir
   trunk/languages/pheme/lib/pge2past.tg

Log:
[Pheme] Rewrote some PIR to use tail calls when possible.  This was an
experiment to see if it worked and if it is worth doing.

It looks worth doing.

Modified: trunk/languages/pheme/lib/PhemeCompiler.pir
==============================================================================
--- trunk/languages/pheme/lib/PhemeCompiler.pir (original)
+++ trunk/languages/pheme/lib/PhemeCompiler.pir Sun Feb 24 14:50:10 2008
@@ -77,17 +77,16 @@
 .end
 
 .sub get_parse_tree :method
-       .param pmc source
+    .param pmc source
 
-       .local pmc start_rule
-       .local pmc match
+    .local pmc start_rule
+    .local pmc match
 
-       start_rule = find_global 'Pheme::Grammar', 'prog'
-        $P0        = get_root_global ['parrot';'PGE'], 'Match'
-        source     = $P0.'new'(source, 'grammar'=>'Pheme::Grammar')
-       match      = start_rule( source )
+    start_rule = find_global 'Pheme::Grammar', 'prog'
+    match      = get_root_global ['parrot';'PGE'], 'Match'
+    source     = match.'new'(source, 'grammar'=>'Pheme::Grammar')
 
-       .return( match )
+    .return start_rule( source )
 .end
 
 .sub get_past_tree :method
@@ -111,9 +110,7 @@
        .local pmc ast_builder
        ast_builder = tge_past.apply( parse_tree )
 
-       .local pmc past_tree
-       past_tree = ast_builder.get( 'result' )
-       .return( past_tree )
+       .return ast_builder.get( 'result' )
 .end
 
 .sub get_post_tree :method
@@ -127,9 +124,7 @@
        .local pmc post_builder
        post_builder = tge_ost.apply( past_tree )
 
-       .local pmc post_tree
-       post_tree = post_builder.get( 'result' )
-       .return( post_tree )
+       .return post_builder.get( 'result' )
 .end
 
 .sub get_pir :method
@@ -141,19 +136,15 @@
        .local pmc pir_builder
        pir_builder = tge_pir.apply( post_tree )
 
-       .local pmc pir
-       pir = pir_builder.get( 'result' )
-       .return( pir )
+       .return pir_builder.get( 'result' )
 .end
 
 .sub compile_pir :method
        .param pmc pir
 
        .local pmc pir_compiler
-       .local pmc pir_compiled
-       pir_compiler = compreg "PIR" 
-       pir_compiled = pir_compiler( pir )
-       .return( pir_compiled )
+       pir_compiler = compreg "PIR"
+       .return pir_compiler( pir )
 .end
 
 .sub dump_parse_tree :method

Modified: trunk/languages/pheme/lib/PhemeObjects.pir
==============================================================================
--- trunk/languages/pheme/lib/PhemeObjects.pir  (original)
+++ trunk/languages/pheme/lib/PhemeObjects.pir  Sun Feb 24 14:50:10 2008
@@ -37,17 +37,17 @@
 .end
 
 .sub 'head' :method
-       .param pmc new_head  :optional
-       .param int have_head :opt_flag
+    .param pmc new_head  :optional
+    .param int have_head :opt_flag
 
-       unless have_head goto return_head
-       setattribute self, 'head', new_head
-       .return( new_head )
+    unless have_head goto return_head
+    setattribute self, 'head', new_head
+    .return( new_head )
 
   return_head:
-       .local pmc head
-       head = getattribute self, 'head'
-       .return( head )
+    .local pmc head
+    head = getattribute self, 'head'
+    .return( head )
 .end
 
 .sub get_integer :vtable :method
@@ -76,17 +76,17 @@
 .end
 
 .sub 'tail' :method
-       .param pmc new_tail  :optional
-       .param int have_tail :opt_flag
+    .param pmc new_tail  :optional
+    .param int have_tail :opt_flag
 
-       unless have_tail goto return_tail
-       setattribute self, 'tail', new_tail
-       .return( new_tail )
+    unless have_tail goto return_tail
+    setattribute self, 'tail', new_tail
+    .return( new_tail )
 
   return_tail:
-       .local pmc tail
-       tail = getattribute self, 'tail'
-       .return( tail )
+    .local pmc tail
+    tail = getattribute self, 'tail'
+    .return( tail )
 .end
 
 .namespace [ 'Pheme'; 'Atom' ]

Modified: trunk/languages/pheme/lib/PhemeSymbols.pir
==============================================================================
--- trunk/languages/pheme/lib/PhemeSymbols.pir  (original)
+++ trunk/languages/pheme/lib/PhemeSymbols.pir  Sun Feb 24 14:50:10 2008
@@ -25,9 +25,7 @@
 .sub __resolve_at_runtime :multi( [ 'Pheme'; 'Cons' ] )
        .param pmc args :slurpy
 
-       .local pmc result
-       result = __list_to_cons( args :flat )
-       .return( result )
+       .return __list_to_cons( args :flat )
 .end
 
 .sub __resolve_at_runtime :multi( string )
@@ -40,15 +38,10 @@
        unless function goto return_list
        pop_eh
 
-       .local pmc    result
-       result = function( args :flat )
-
-       .return( result )
+       .return function( args :flat )
 
   return_list:
-
-       result = __list_to_cons( symbol_name, args :flat )
-       .return( result )
+       .return __list_to_cons( symbol_name, args :flat )
 .end
 
 .sub __list_to_cons
@@ -100,9 +93,7 @@
 
        if first_type == 'String' goto call_func
 
-       .local pmc result
-       result = __list_to_cons( cons_list :flat )
-       .return( result )
+       .return __list_to_cons( cons_list :flat )
 
   call_func:
        first  = shift cons_list
@@ -110,10 +101,7 @@
        .local string func_name
        func_name = first
 
-       .local pmc result
-       result = __resolve_at_runtime( func_name, cons_list :flat )
-
-       .return( result )
+       .return __resolve_at_runtime( func_name, cons_list :flat )
 .end
 
 .sub '__evaluate' :multi( pmc )
@@ -141,9 +129,7 @@
        .param pmc cons
 
        .local pmc tail
-       tail = cons.'tail'()
-
-       .return( tail )
+       .return cons.'tail'()
 .end
 
 .sub include_file
@@ -188,8 +174,7 @@
        result = __evaluate( cond )
        unless result goto iter_loop
 
-       result = __evaluate( action )
-       .return( result )
+       .return __evaluate( action )
 
   iter_end:
        .return()
@@ -250,9 +235,7 @@
        l_tail = l_cons.'tail'()
        r_tail = r_cons.'tail'()
 
-       .local int tail_equal
-       tail_equal = 'eqlist?'( l_head, r_head )
-       .return( tail_equal )
+       .return 'eqlist?'( l_head, r_head )
 .end
 
 .sub 'eq?' :multi( pmc, pmc )
@@ -270,9 +253,7 @@
        .param pmc l_cons
        .param pmc r_cons
 
-       .local int result
-       result = 'eqlist?'( l_cons, r_cons )
-       .return( result )
+       .return 'eqlist?'( l_cons, r_cons )
 .end
 
 # XXX - return #t

Modified: trunk/languages/pheme/lib/pge2past.tg
==============================================================================
--- trunk/languages/pheme/lib/pge2past.tg       (original)
+++ trunk/languages/pheme/lib/pge2past.tg       Sun Feb 24 14:50:10 2008
@@ -87,8 +87,7 @@
     result.'pasttype'( 'call' )
     result.'push'( op )
 
-    result   = tree.'get'( key_name, result )
-    .return( result )
+    .return tree.'get'( key_name, result )
 }
 
 transform past (list_item) :language('PIR') {
@@ -101,10 +100,7 @@
     .local pmc    elem
     elem     = node[key_name]
 
-    .local pmc result
-    result   = tree.'get'( 'past', elem, key_name )
-
-    .return( result )
+    .return tree.'get'( 'past', elem, key_name )
 }
 
 transform special_form (PAST::Op) :language('PIR') {
@@ -120,9 +116,7 @@
     .local string form_name
     form_name = form_op.'name'()
 
-    .local pmc result
-    result = tree.'get'( form_name, make_cons )
-    .return( result )
+    .return tree.'get'( form_name, make_cons )
 }
 
 # this *may* be an application; this is an optimization

Reply via email to