summaryrefslogtreecommitdiffstats
path: root/txr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-09-02 06:20:42 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-09-02 06:20:42 -0700
commitbc987afb87416418841573cd858258438be9f2ea (patch)
tree7d5586370f059e97a7315b1ed36fd37caf093bd0 /txr.c
parent9272b1d59ac9f7fbe05e4fd19a1a28b180732235 (diff)
downloadtxr-bc987afb87416418841573cd858258438be9f2ea.tar.gz
txr-bc987afb87416418841573cd858258438be9f2ea.tar.bz2
txr-bc987afb87416418841573cd858258438be9f2ea.zip
load: new *load-hooks* feature.
*load-hooks* lets a .txr, .tl or .tlo file specify actions to be taken when the loading of that file completes, whether normally or via an exception. They are also honored by process exit. For instance, with this, we can have a Lisp file that behaves like a script which cleans up after itself (e.g. removing temporary files) even if it is not run as a stand-alone program, but invoked via (load ...). Because it's not a stand-alone program, it cannot simply use the at-exit-call mechanism. The unwind-protect operator could be used, but it's inconvenient because it protects a single form. The *load-hooks* feature in effect protects all the top level forms of a load, similarly to unwind-protect. Also, unwind-protect does not guard against a process exit. (However, *load-hooks* does not guard against an abnormal exit, only normal termination). * eval.c (load_hooks_s): New symbol variable. (run_load_hooks): New function. (run_load_hooks_atexit): New static function. (load): bind *load-hooks* to nil around load. Implement the hooks processing via run_load_hooks, taking care to pass the load-time dynamic environment that has already been undone. (eval_init): Initialize load_hooks_s and register the *load-hooks* variable. Register run_load_hooks_atexit with atexit, so the current value of *load-hooks* is processed on process exit. * eval.h (load_hooks_s, run_load_hooks): Declared. * match.c (v_load): Similar changes as in load. * txr.c (txr_main): Run the load hooks with run_load_hooks immediately after processing the .txr or .tl file, before entering the listener. * tests/019/load-hook.tl: New directory and file * tests/load-hook.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
Diffstat (limited to 'txr.c')
-rw-r--r--txr.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/txr.c b/txr.c
index be675149..3157b879 100644
--- a/txr.c
+++ b/txr.c
@@ -1125,7 +1125,7 @@ int txr_main(int argc, char **argv)
gc_state(gc);
close_stream(parse_stream, nil);
-
+ run_load_hooks(dyn_env);
uw_release_deferred_warnings();
spec = parser->syntax_tree;
@@ -1172,6 +1172,7 @@ int txr_main(int argc, char **argv)
} else if (enter_repl) {
read_eval_stream_noerr(self, parse_stream, spec_file_str, std_error);
close_stream(parse_stream, nil);
+ run_load_hooks(dyn_env);
uw_release_deferred_warnings();
} else {
val result = read_eval_stream(self, parse_stream, std_error);