From 2ec8502b72574b244c1ed1e07383d8735aa90ac0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 28 May 2021 23:52:49 -0700 Subject: parser: remove some parser access functions. * parser.c (lisp_parse_impl): Access pi->eof directly instead of going through parser_eof. We are using pi->errors in the same expression! This is the only place pi->eof is needed. (read_file_common): Don't call parser_eof. Assume that if error_val emerges, and errors is zero, it must be eof. (read_eval_ret_last): Simplify: the code actually does nothing specia for eof versus errors, so we just bail if error_var emerges. (get_parser): Function removed. (parse_errors): This is the only caller of get_parser, which now just calls gethash to fetch the parser. (parser_eof): Function removed. (parse_init): sys:get-parser, sys:parser-errors and sys:parser-eof intrinsics removed. The C function parser_errors still exists; it is used in a few places. * parser.h (get_parser, parser_eof): Declarations removed. * share/txr/stdlib/compiler.tl (compile-file-conditionally): Use the new parse-errors function instead of the removed sys:parser-errors. Since that works on the stream, we don't have to call sys:get-parser. Because it returns nil if there are no errors, we drop the > test. --- parser.c | 37 +++++-------------------------------- parser.h | 2 -- share/txr/stdlib/compiler.tl | 7 +++---- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/parser.c b/parser.c index 3358d7bd..822210ce 100644 --- a/parser.c +++ b/parser.c @@ -667,7 +667,7 @@ static val lisp_parse_impl(val self, enum prime_parser prime, parse(pi, if3(std_error != std_null, name, lit("")), prime); gc_state(gc); - if (pi->syntax_tree == nao && pi->errors == 0 && !parser_eof(parser)) + if (pi->syntax_tree == nao && pi->errors == 0 && !pi->eof) continue; break; @@ -749,9 +749,7 @@ static val read_file_common(val self, val stream, val error_stream, val compiled if (form == error_val) { if (parser_errors(parser) != zero) return nil; - if (parser_eof(parser)) - break; - continue; + break; } if (compiled && first) { @@ -780,9 +778,6 @@ static val read_file_common(val self, val stream, val error_stream, val compiled } else { (void) eval_intrinsic(form, nil); } - - if (parser_eof(parser)) - break; } return t; @@ -1160,18 +1155,11 @@ static val read_eval_ret_last(val env, val counter, for (;; lineno = succ(lineno)) { val form = lisp_parse(in_stream, out_stream, error_val, name, lineno); - val parser = get_parser(in_stream); - if (form == error_val) { - if (parser_errors(parser) != zero || parser_eof(parser)) - break; - continue; - } + if (form == error_val) + break; value = eval_intrinsic(form, nil); - - if (parser_eof(parser)) - break; } dyn_env = saved_dyn_env; @@ -1664,11 +1652,6 @@ val repl(val bindings, val in_stream, val out_stream, val env) #endif -val get_parser(val stream) -{ - return gethash(stream_parser_hash, stream); -} - val parser_errors(val parser) { val self = lit("parser-errors"); @@ -1676,18 +1659,11 @@ val parser_errors(val parser) return num(p->errors); } -val parser_eof(val parser) -{ - val self = lit("parser-eof"); - parser_t *p = coerce(parser_t *, cobj_handle(self, parser, parser_s)); - return tnil(p->eof); -} - val parse_errors(val stream) { val self = lit("parse-errors"); val errors = nil; - val parser = get_parser(stream); + val parser = gethash(stream_parser_hash, stream); if (parser) { parser_t *p = coerce(parser_t *, cobj_handle(self, parser, parser_s)); if (p->errors) @@ -1886,9 +1862,6 @@ void parse_init(void) reg_var(listener_greedy_eval_s, nil); reg_var(rec_source_loc_s, nil); reg_fun(circref_s, func_n1(circref)); - reg_fun(intern(lit("get-parser"), system_package), func_n1(get_parser)); - reg_fun(intern(lit("parser-errors"), system_package), func_n1(parser_errors)); - reg_fun(intern(lit("parser-eof"), system_package), func_n1(parser_eof)); reg_fun(intern(lit("parse-errors"), user_package), func_n1(parse_errors)); reg_fun(intern(lit("repl"), system_package), func_n4(repl)); reg_mac(json_s, func_n2(me_json)); diff --git a/parser.h b/parser.h index 3c2e2292..a8a64b97 100644 --- a/parser.h +++ b/parser.h @@ -138,10 +138,8 @@ void parser_common_init(parser_t *); void parser_cleanup(parser_t *); val parser(val stream, val name, val lineno); parser_t *parser_get_impl(val self, val parser); -val get_parser(val stream); val ensure_parser(val stream, val name); val parser_set_lineno(val self, val stream, val lineno); val parser_errors(val parser); -val parser_eof(val parser); val parse_errors(val stream); void parse_init(void); diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index e56dea66..e3d43658 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -2314,10 +2314,9 @@ (compile-form obj)) (dump-to-tlo out-stream out)) - (let ((parser (sys:get-parser in-stream))) - (when (> (sys:parser-errors parser) 0) - (error "~s: compilation of ~s failed" 'compile-file - (stream-get-prop in-stream :name))))) + (when (parse-errors in-stream) + (error "~s: compilation of ~s failed" 'compile-file + (stream-get-prop in-stream :name)))) (flush-stream out-stream) (set success t)))))) -- cgit v1.2.3