diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-16 15:07:53 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-05-16 15:07:53 +0100 |
commit | bc42812715fb56e72717bf18809dd9ba59771b3a (patch) | |
tree | c7d3ac872afa5623cf9eae54c55c367b77e94aea /compile.c | |
parent | 8fbee891b305180bdce956fde177604782c3cdc0 (diff) |
Remove the insane "fold" operation, replace with saner "reduce".
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -320,15 +320,24 @@ block gen_collect(block expr) { gen_op_var_bound(LOADV, array_var)); } -block gen_fold(const char* varname, block init, block fold) { - block loop = BLOCK(fold, gen_op_var_unbound(STOREV, varname), gen_op_simple(BACKTRACK)); +block gen_reduce(const char* varname, block source, block init, block body) { + block res_var = block_bind(gen_op_var_unbound(STOREV, "reduce"), + gen_noop(), OP_HAS_VARIABLE); + + block loop = BLOCK(gen_op_simple(DUP), + source, + block_bind(gen_op_var_unbound(STOREV, varname), + BLOCK(gen_op_var_bound(LOADVN, res_var), + body, + gen_op_var_bound(STOREV, res_var)), + OP_HAS_VARIABLE), + gen_op_simple(BACKTRACK)); return BLOCK(gen_op_simple(DUP), init, - block_bind(gen_op_var_unbound(STOREV, varname), - BLOCK(gen_op_target(FORK, loop), - loop, - gen_op_var_unbound(LOADV, varname)), - OP_HAS_VARIABLE)); + res_var, + gen_op_target(FORK, loop), + loop, + gen_op_var_bound(LOADVN, res_var)); } block gen_definedor(block a, block b) { |