reduce: handle empty updates (fix #1313)

This commit is contained in:
Nicolas Williams committed 2017-01-30 14:11:05 -06:00
1 parent e82147bbb8
commit e24af3c78e
4 files changed
+196 -69

No files matched your search

+16 -1
View File
@@ -704,12 +704,27 @@ static block bind_matcher(block matcher, block body) {
block gen_reduce(block source, block matcher, block init, block body) {
block res_var = gen_op_var_fresh(STOREV, "reduce");
block update_var = gen_op_bound(STOREV, res_var);
block jmp = gen_op_target(JUMP, body);
block loop = BLOCK(gen_op_simple(DUPN),
source,
bind_matcher(matcher,
BLOCK(gen_op_bound(LOADVN, res_var),
/*
* We fork to the body, jump to
* the STOREV. This means that
* if body produces no results
* (i.e., it just does empty)
* then we keep the current
* reduction state as-is.
*
* To break out of a
* reduction... use break.
*/
gen_op_target(FORK, jmp),
jmp,
body,
gen_op_bound(STOREV, res_var))),
update_var)),
gen_op_simple(BACKTRACK));
return BLOCK(gen_op_simple(DUP),
init,