From 17cd878844f524ebae0024edb60c2f58ac56285d Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 12 Oct 2017 06:39:08 -0700 Subject: tprint and -t option: handle infinite list. Test case: txr -t '(gun "foo")' must run in constant memory. * eval.c (tprint): Rewritten to iterate over lists using open loop rather than mapdo. Classification of the sequence is done using the new seq_info, as must be for all new sequence functions. * txr.c (txr_main): Implementation of -t, -p and -P captures the result of the expression in a variable whose value is zapped when it is passed to the function. A gc_hint is added so that this isn't optimized away. Thus, this code won't hold on to the original pointer to a lazy, infinite list. --- txr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'txr.c') diff --git a/txr.c b/txr.c index cee8ac51..cd774de0 100644 --- a/txr.c +++ b/txr.c @@ -858,13 +858,19 @@ int txr_main(int argc, char **argv) tprint)); val args_saved = or2(orig_args, arg_list); val args_new; + val obj; reg_varl(self_path_s, lit("cmdline-expr")); reg_var(args_s, or2(orig_args, arg_list)); - pf(eval_intrinsic(lisp_parse(arg, std_error, colon_k, - lit("cmdline-expr"), colon_k), - make_env(bindings, nil, nil)), std_output); + + obj = eval_intrinsic(lisp_parse(arg, std_error, colon_k, + lit("cmdline-expr"), colon_k), + make_env(bindings, nil, nil)); + gc_hint(obj); + pf(z(obj), std_output); + evaled = t; + args_new = cdr(lookup_global_var(args_s)); if (args_new != args_saved) { arg_list = args_new; -- cgit v1.2.3