diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-05-18 20:46:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-05-18 20:46:23 -0700 |
commit | a2d98ba063616fc56c6888641c77b55b562fc9ab (patch) | |
tree | 6cf3e0c8a338be5d222ba48b7ffd4ab6165e2960 /match.c | |
parent | dc791857cfd41fec131d2645409bf6451eb4635b (diff) | |
download | txr-a2d98ba063616fc56c6888641c77b55b562fc9ab.tar.gz txr-a2d98ba063616fc56c6888641c77b55b562fc9ab.tar.bz2 txr-a2d98ba063616fc56c6888641c77b55b562fc9ab.zip |
New feature: self-load-path symbol macro.
* eval.c (self_load_path_s): New symbol variable.
(sys_load): Save, set-up and restore self-load-path
around load.
(set_get_symacro): New function.
(eval_init): Register load function using sys_load_s instead
of redundant intern.
* eval.h (set_get_symacro): Declared.
* match.c (v_load): Save, set-up and restore self-load-path
macro.
* parser.c (load_rcfile): Likewise.
* txr.c (txr_main: Set up self-load-path when opening
file.
* txr.1: Documented self-load-path.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -3771,29 +3771,33 @@ static val v_load(match_files_ctx *c) cons(target, nil)), lit("/"))); val stream, name; val txr_lisp_p = nil; + val ret = nil; + val self_load_path_old = nil; open_txr_file(path, &txr_lisp_p, &name, &stream); + uw_simple_catch_begin; + + self_load_path_old = set_get_symacro(self_load_path_s, name); + if (!txr_lisp_p) { int gc = gc_state(0); parser_t parser; + parse_once(stream, name, &parser); gc_state(gc); - close_stream(stream, nil); - if (parser.errors) sem_error(specline, lit("~s: errors encountered in ~a"), sym, path, nao); if (sym == include_s) { - return parser.syntax_tree; + ret = parser.syntax_tree; } else { val spec = parser.syntax_tree; val result = match_files(mf_spec(*c, spec)); if (!result) { debuglf(specline, lit("load: ~a failed"), path, nao); - return nil; } else { cons_bind (new_bindings, success, result); @@ -3812,7 +3816,7 @@ static val v_load(match_files_ctx *c) c->data = nil; } - return next_spec_k; + ret = next_spec_k; } } } else { @@ -3820,9 +3824,18 @@ static val v_load(match_files_ctx *c) close_stream(stream, nil); sem_error(specline, lit("load: ~a contains errors"), path, nao); } + + ret = (sym == include_s) ? nil : next_spec_k; + } + + uw_unwind { + set_get_symacro(self_load_path_s, self_load_path_old); close_stream(stream, nil); - return (sym == include_s) ? nil : next_spec_k; } + + uw_catch_end; + + return ret; } } |