From d510a260dd1755961fe85b6653e9832f49b34201 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 23 Sep 2016 21:38:50 -0700 Subject: Bugfix: -Dvar=val not seen in some Lisp code. TXR Lisp files run from the command line do not see -Dvar=val bindings, whereas -p expressions do. The REPL sees the bindings, but not code loaded from it using (load "file.tl") because they are lexical. Let's keep these bindings as local lexicals for -p and -e forms, but install them as global lexicals for the other situations. * parser.c (repl): Get rid of the local repl_env made from the bindings that are passed in. Instead, before starting the REPL, loop through the bindings and install them as global lexicals with reg_varl. * txr.c (txr_main): Before processing a Lisp file, install the bindings as global lexicals with reg_varl. --- parser.c | 10 +++++++--- txr.c | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/parser.c b/parser.c index aca71939..88e24475 100644 --- a/parser.c +++ b/parser.c @@ -667,7 +667,6 @@ val repl(val bindings, val in_stream, val out_stream) lino_t *ls = lino_make(c_num(ifd), c_num(ofd)); char *line_u8 = 0; char *prompt_u8 = 0; - val repl_env = make_env(bindings, nil, nil); val quit_k = intern(lit("quit"), keyword_package); val read_k = intern(lit("read"), keyword_package); val counter_sym = intern(lit("*n"), user_package); @@ -686,6 +685,11 @@ val repl(val bindings, val in_stream, val out_stream) val multi_line_var = lookup_global_var(listener_multi_line_p_s); val sel_inclusive_var = lookup_global_var(listener_sel_inclusive_p_s); + for (; bindings; bindings = cdr(bindings)) { + val binding = car(bindings); + reg_varl(car(binding), cdr(binding)); + } + reg_varl(result_hash_sym, result_hash); lino_set_completion_cb(ls, provide_completions, 0); @@ -761,8 +765,8 @@ val repl(val bindings, val in_stream, val out_stream) done = t; } else { val value = if3(form != read_k, - eval_intrinsic(form, repl_env), - read_eval_ret_last(repl_env, prev_counter, + eval_intrinsic(form, nil), + read_eval_ret_last(nil, prev_counter, in_stream, out_stream)); reg_varl(var_sym, value); sethash(result_hash, var_counter, value); diff --git a/txr.c b/txr.c index 15abb5ed..c0c38852 100644 --- a/txr.c +++ b/txr.c @@ -979,6 +979,11 @@ int txr_main(int argc, char **argv) } } + for (; bindings; bindings = cdr(bindings)) { + val binding = car(bindings); + reg_varl(car(binding), cdr(binding)); + } + { val result = read_eval_stream(parse_stream, std_error, t); -- cgit v1.2.3