Remove the insane "fold" operation, replace with saner "reduce".

This commit is contained in:
Stephen Dolan committed 2013-05-16 15:07:53 +01:00
1 parent 8fbee891b3
commit bc42812715
7 files changed
+37 -38

No files matched your search

+16 -7
View File
@@ -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) {