New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of triangle form of reduce metaops. #705
Comments
From @bacekHello. There is implementation of triangle form of reduce metaop. -- |
From @bacekreduce_triangle.patchcommit 1134af2b6f8b7b18734ba8daff09fd2fbc515d4b
Author: Vasily Chekalkin <bacek@bacek.com>
Date: Wed Feb 18 09:01:06 2009 +1100
Implement triangle form of reduce metaop
diff --git a/build/gen_metaop_pir.pl b/build/gen_metaop_pir.pl
index 710dfff..afb5aaf 100644
--- a/build/gen_metaop_pir.pl
+++ b/build/gen_metaop_pir.pl
@@ -58,7 +58,8 @@ my $output = $ARGV[0] || '-';
my $assignfmt =
" optable.'newtok'('infix:%s=', 'equiv'=>'infix::=', 'lvalue'=>1)\n";
my $reducefmt =
- " optable.'newtok'('prefix:[%s]', 'equiv'=>'infix:=')\n";
+ " optable.'newtok'('prefix:[%s]', 'equiv'=>'infix:=')\n" .
+ " optable.'newtok'('prefix:[\\%s]', 'equiv'=>'infix:=')\n";
my $hyper_no_dwim_fmt =
" optable.'newtok'(%s, 'equiv'=>'infix:%s')\n" .
" optable.'newtok'('infix:%s', 'equiv'=>'infix:%s', 'subname'=>%s)\n";
@@ -85,12 +86,17 @@ while (@ops) {
}
# All ops work for reductions.
- push @gtokens, sprintf( $reducefmt, $opname );
+ push @gtokens, sprintf( $reducefmt, $opname, $opname );
my $chain = $op_type eq 'comp' ? 'CHAIN' : '';
push @code, qq(
.sub 'prefix:[$opname]'
.param pmc args :slurpy
- .tailcall '!REDUCEMETAOP$chain'('$opname', $identity, args)
+ .tailcall '!REDUCEMETAOP$chain'('$opname', $identity, args, 0 :named('triangle'))
+ .end\n);
+ push @code, qq(
+ .sub 'prefix:[\\\\$opname]'
+ .param pmc args :slurpy
+ .tailcall '!REDUCEMETAOP$chain'('$opname', $identity, args, 1 :named('triangle'))
.end\n);
# Cross operators.
diff --git a/src/builtins/assign.pir b/src/builtins/assign.pir
index 106f26d..2c8c995 100644
--- a/src/builtins/assign.pir
+++ b/src/builtins/assign.pir
@@ -164,6 +164,8 @@ src/builtins/assign.pir - assignments
.param string opname
.param pmc identity
.param pmc args # already :slurpy array by caller
+ .param int triangle :named('triangle')
+
args.'!flatten'()
if args goto reduce
@@ -174,17 +176,29 @@ src/builtins/assign.pir - assignments
.tailcall '!FAIL'()
reduce:
+ .local pmc result_list
+ unless triangle goto do_reduce
+ result_list = 'list'()
+ do_reduce:
opname = concat 'infix:', opname
.local pmc opfunc
opfunc = find_name opname
.local pmc result
result = shift args
+ unless triangle goto reduce_loop
+ result_list.'push'(result)
reduce_loop:
unless args goto reduce_done
$P0 = shift args
result = opfunc(result, $P0)
+ unless triangle goto reduce_loop
+ result_list.'push'(result)
goto reduce_loop
reduce_done:
+
+ unless triangle goto done
+ result = result_list
+ done:
.return (result)
.end
|
From @bacekOn Tue Feb 17 14:03:57 2009, bacek wrote:
Second patch for chained version. -- |
From @bacekreduce_triangle2.patchcommit ea8a466adb691d7c9d0d9b4859142d1494a2ed24
Author: Vasily Chekalkin <bacek@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
|
@bacek - Status changed from 'new' to 'open' |
From @moritzOn Tue Feb 17 14:03:57 2009, bacek wrote:
FYI, there are already tests in S03-operators/reduce-metaop.t Cheers, |
From @bacekMoritz Lenz via RT wrote:
And they partially wrong. I'm fixing them ATM. -- |
From @jnthnTriangle forms of meta-ops are now implemented, need to confirm they're |
From @moritzAmply tested in S03-metaops/reduce.t. |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#63292 (status was 'resolved')
Searchable as RT63292$
The text was updated successfully, but these errors were encountered: