aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-10-02 10:47:03 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2017-10-02 10:47:03 +0300
commit66588068207f8186a14e3a35f62d4b0aefe75cdf (patch)
treeba20440317c011b71a44f25c6a64a6cbe2010bbe
parentInstall eimp binary with +x attribute (diff)
Generate more readable code for run_fold hooks
-rwxr-xr-xtools/hook_deps.sh25
1 files changed, 11 insertions, 14 deletions
diff --git a/tools/hook_deps.sh b/tools/hook_deps.sh
index 0d1994479..a3a685a2f 100755
--- a/tools/hook_deps.sh
+++ b/tools/hook_deps.sh
@@ -273,8 +273,6 @@ emit_module(RunDeps, RunFoldDeps, Specs, Dir, Module) ->
emit_export(Fd, RunFoldDeps, "run_fold hooks"),
emit_run_hooks(Fd, RunDeps, Specs),
emit_run_fold_hooks(Fd, RunFoldDeps, Specs),
- write(Fd, "bypass_stop({stop, Acc}) -> Acc;~n"
- "bypass_stop(Acc) -> Acc.~n", []),
file:close(Fd),
log("Module written to file ~s~n", [File])
catch _:{badmatch, {error, Reason}} ->
@@ -311,20 +309,19 @@ emit_run_fold_hooks(Fd, Deps, Specs) ->
emit_specs(Fd, Funs, Specs),
write(Fd, "%% called at ~s:~p~n", [File, LineNo]),
Args = [[N] || N <- lists:sublist(lists:seq($A, $Z), Arity - 1)],
- write(Fd, "~s(~s) ->", [Hook, string:join(["Acc"|Args], ", ")]),
- FunsCascade = make_funs_cascade(
- lists:reverse(lists:keysort(2, Funs)),
- 1, Args),
- write(Fd, "~s.~n~n", [FunsCascade])
+ write(Fd, "~s(~s) ->~n ", [Hook, string:join(["Acc0"|Args], ", ")]),
+ {Calls, _} = lists:mapfoldl(
+ fun({{Mod, Fun, _}, _Seq, _}, N) ->
+ Args1 = ["Acc" ++ integer_to_list(N)|Args],
+ {io_lib:format("Acc~p = ~s:~s(~s)",
+ [N+1, Mod, Fun,
+ string:join(Args1, ", ")]),
+ N + 1}
+ end, 0, lists:keysort(2, Funs)),
+ write(Fd, "~s,~n", [string:join(Calls, ",\n ")]),
+ write(Fd, " Acc~p.~n~n", [length(Funs)])
end, DepsList).
-make_funs_cascade([{{Mod, Fun, _}, _Seq, _}|Funs], N, Args) ->
- io_lib:format("~n~sbypass_stop(~s:~s(~s))",
- [lists:duplicate(N, " "),
- Mod, Fun, string:join([make_funs_cascade(Funs, N+1, Args)|Args], ", ")]);
-make_funs_cascade([], _N, _Args) ->
- "Acc".
-
emit_export(Fd, Deps, Comment) ->
DepsList = lists:sort(dict:to_list(Deps)),
Exports = lists:map(