On Tue Feb 17 14:03:57 2009, bacek wrote:
> Hello.
> 
> There is implementation of triangle form of reduce metaop.
> Tests are coming.

Second patch for chained version.

-- 
Bacek
commit ea8a466adb691d7c9d0d9b4859142d1494a2ed24
Author: Vasily Chekalkin <ba...@bacek.com>
Date:   Wed Feb 18 20:21:02 2009 +1100

    Triangle version of chained metaop

diff --git a/src/builtins/assign.pir b/src/builtins/assign.pir
index 2c8c995..fa2ba1d 100644
--- a/src/builtins/assign.pir
+++ b/src/builtins/assign.pir
@@ -224,18 +224,23 @@ Implemented here as infix:// reduces to a PAST node rather than a call.
     .param string opname
     .param string identity
     .param pmc args                # already :slurpy array by caller
+    .param int triangle     :named('triangle')
 
-    .local int want_true
+    .local int want_true, cicle_count, elems
     want_true = identity == 'True'
+    cicle_count = 0
 
     args.'!flatten'()
-    $I0 = elements args
-    if $I0 > 1 goto reduce
+    elems = elements args
+    if elems > 1 goto reduce
+    cicle_count = elems
     if want_true goto true
   false:
+    if triangle goto build_triangle
     $P0 = get_hll_global [ 'Bool' ], 'False'
     .return ($P0)
   true:
+    if triangle goto build_triangle
     $P0 = get_hll_global [ 'Bool' ], 'True'
     .return ($P0)
 
@@ -246,6 +251,7 @@ Implemented here as infix:// reduces to a PAST node rather than a call.
     .local pmc a, b
     b = shift args
   reduce_loop:
+    inc cicle_count
     unless args goto reduce_done
     a = b
     b = shift args
@@ -254,6 +260,30 @@ Implemented here as infix:// reduces to a PAST node rather than a call.
     goto reduce_loop
   reduce_done:
     goto true
+  
+    # Building result list. 
+  build_triangle:
+    .local pmc res
+    res = 'list'()
+    #say cicle_count
+    #say elems
+    elems = elems - cicle_count
+    $P0 = get_hll_global [ 'Bool' ], 'True'
+  put_true:
+    if cicle_count == 0 goto put_false
+    res.'push'($P0)
+    dec cicle_count
+    goto put_true
+
+  put_false:
+    $P0 = get_hll_global [ 'Bool' ], 'False'
+  loop_false:
+    if elems == 0 goto return_res
+    res.'push'($P0)
+    dec elems
+    goto loop_false
+  return_res:
+    .return (res)
 .end
 
 

Reply via email to