From 9361473290d317186768bd9d709ae76adf9d85b8 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Fri, 29 Dec 2017 16:52:52 -0800
Subject: read, iread: source location recording now conditional.

Recording of source location info incurs a time and space
penalty. We don't want to impose this on programs which are
just reading large amounts of Lisp data that isn't code.

* eval.c (eval_init): Register lisp-parse and read functions
to the newly introduced nread function rather than lisp_parse.
lisp_parse continues to record source location info
unconditionally.

* parser.c (rec_source_loc_s): New symbol variable.
(parser_common_init): Set the new member of the parser
structure, rec_source_loc, according to the current value of
the special var *rec-source-loc*.
(lisp_parse_impl): New second argument, rlcp_p. If true, it
overrides the rec_source_loc member of the parser structure
to true.
(lisp_parse): Pass true argument to rlcp_p parameter of
lisp_parse_impl, so parsing via lisp_parse always records
source loc info.
(nread): New function.
(iread): Pass true argument to rlcp_p parameter of
lisp_parse_impl, so *rec-source-loc* controls whether source
location info is recorded.
(parse_init): Initilize rec_source_loc_s symbol variable,
and register the *rec-source-loc* special var.

* parser.h (struct parser): New member, rec_source_loc.
(rec_source_loc_s, nread): Declared.

* parser.y (rlcp_parser): New static function. Like rlcp but
does nothing if parser->rec_source_loc is false.
(rlc): New macro.
(grammar): Replace rlcp uses with rlc, which expands to a call
to rlcp_parser.
(rlrec): Do nothing if source loc recording is not enabled in
the parser.
(make_expr, uref_helper): Replace rlcp with rlc. This is
possible because these functions have a parser local
variable that the macro expansion can refer to.
(parse_once): Override rec_source_loc in the parser to 1, so
that source loc info is always recorded when parsing is
invoked through this function.

* txr.1: Documented *rec-source-loc* and added text under
read and iread.
---
 eval.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'eval.c')

diff --git a/eval.c b/eval.c
index a3c79574..0ffe88f4 100644
--- a/eval.c
+++ b/eval.c
@@ -6085,8 +6085,8 @@ void eval_init(void)
   reg_var(intern(lit("*param-macro*"), user_package), pm_table);
 
   reg_fun(intern(lit("eval"), user_package), func_n2o(eval_intrinsic, 1));
-  reg_fun(intern(lit("lisp-parse"), user_package), func_n5o(lisp_parse, 0));
-  reg_fun(intern(lit("read"), user_package), func_n5o(lisp_parse, 0));
+  reg_fun(intern(lit("lisp-parse"), user_package), func_n5o(nread, 0));
+  reg_fun(intern(lit("read"), user_package), func_n5o(nread, 0));
   reg_fun(intern(lit("iread"), user_package), func_n5o(iread, 0));
   reg_fun(intern(lit("load"), user_package), func_n1(load));
   reg_var(load_path_s, nil);
-- 
cgit v1.2.3