diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-12-29 16:52:52 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-12-29 16:52:52 -0800 |
commit | 9361473290d317186768bd9d709ae76adf9d85b8 (patch) | |
tree | b4f649994b1491d2749b164cb8b05c308355b7fc /parser.h | |
parent | 079cf1d067ec21e590f0ec025cbc282f8290e2fa (diff) | |
download | txr-9361473290d317186768bd9d709ae76adf9d85b8.tar.gz txr-9361473290d317186768bd9d709ae76adf9d85b8.tar.bz2 txr-9361473290d317186768bd9d709ae76adf9d85b8.zip |
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.
Diffstat (limited to 'parser.h')
-rw-r--r-- | parser.h | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -62,6 +62,7 @@ struct parser { struct yy_token recent_tok; struct yy_token tok_pushback[4]; int tok_idx; + int rec_source_loc; }; #endif @@ -71,6 +72,7 @@ extern const int have_yydebug; extern const wchar_t *spec_file; extern val form_to_ln_hash; extern val parser_s, unique_s, circref_s; +extern val rec_source_loc_s; void yydebug_onoff(int); void yyerror(scanner_t *scanner, parser_t *, const char *s); void yyerr(scanner_t *scanner, const char *s); @@ -114,6 +116,8 @@ val rlcp_tree(val to, val from); val regex_parse(val string, val error_stream); val lisp_parse(val source_in, val error_stream, val error_return_val, val name_in, val lineno); +val nread(val source_in, val error_stream, val error_return_val, + val name_in, val lineno); val iread(val source_in, val error_stream, val error_return_val, val name_in, val lineno); val read_eval_stream(val stream, val error_stream); |