From a1c033eea769012d08a094a4328017a691199157 Mon Sep 17 00:00:00 2001 From: sasagawa888 Date: Fri, 3 Jan 2025 16:40:56 +0900 Subject: [PATCH] thread safe readparse --- builtin.c | 6 +++--- extension.c | 2 +- main.c | 6 +++--- npl.h | 2 +- parser.c | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin.c b/builtin.c index ff2ed46..341287d 100644 --- a/builtin.c +++ b/builtin.c @@ -1038,7 +1038,7 @@ int b_read(int arglist, int rest, int th) input_stream = GET_CAR(arg1); repl_flag = 0; - temp = variable_to_call(readparse()); + temp = variable_to_call(readparse(th)); res = unify(arg2, temp, th); input_stream = save1; repl_flag = save2; @@ -3329,7 +3329,7 @@ int b_string_term(int arglist, int rest, int th) bridge[l + 1] = 0; read_string_term(0); //initilize bridge_flag = 1; - res = readparse(); + res = readparse(th); bridge_flag = 0; if (unify(arg2, res, th) == YES) return (prove_all(rest, sp[th], th)); @@ -3758,7 +3758,7 @@ int b_break(int arglist, int rest, int th) while (1) { printf("?= "); fflush(stdout); - query_break(variable_to_call(readparse()), th); + query_break(variable_to_call(readparse(th)), th); fflush(stdout); } } else if (ret == 1) { diff --git a/extension.c b/extension.c index a607bda..dc26a12 100644 --- a/extension.c +++ b/extension.c @@ -1197,7 +1197,7 @@ int str_to_pred(int x) memset(bridge, '\0', sizeof(bridge)); strcpy(bridge, GET_NAME(x)); read_string_term(0); - res = variable_to_call(readparse()); + res = variable_to_call(readparse(0)); memset(bridge, 0, sizeof(bridge)); bridge_flag = 0; return (res); diff --git a/main.c b/main.c index da56289..11daaa9 100644 --- a/main.c +++ b/main.c @@ -319,7 +319,7 @@ int main(int argc, char *argv[]) init_repl(); printf("?- "); fflush(stdout); - input = variable_to_call(readparse()); + input = variable_to_call(readparse(0)); if (!repl_flag) clear_input_buffer(); query(input, 0); @@ -1018,7 +1018,7 @@ void debugger(int goal, int bindings, int rest) printf("- "); fflush(stdout); - read = variable_to_call(readparse()); + read = variable_to_call(readparse(0)); if (read == FEND) goto break_exit; query(read, 0); @@ -1097,7 +1097,7 @@ void debugger(int goal, int bindings, int rest) case '@': printf("?- "); fflush(stdout); - read = variable_to_call(readparse()); + read = variable_to_call(readparse(0)); query(read, 0); fflush(stdout); break; diff --git a/npl.h b/npl.h index c7240f9..6260569 100644 --- a/npl.h +++ b/npl.h @@ -1206,7 +1206,7 @@ int prove(int goal, int bindings, int rest, int th); int prove_all(int goals, int bindings, int th); int quoted_option_p(int x); int quotient(int x, int y, int th); -int readparse(void); +int readparse(int th); int readitem(int th); int readitem1(int th); int readcurl(int th); diff --git a/parser.c b/parser.c index b29bd26..789da5e 100644 --- a/parser.c +++ b/parser.c @@ -5,14 +5,14 @@ //#define CHECK 1 //for parser debug check -int readparse(void) +int readparse(int th) { int res; paren_nest = 0; - res = parser(NIL, NIL, NIL, NIL, 0, 0, 0); + res = parser(NIL, NIL, NIL, NIL, 0, 0, th); if (paren_nest != 0) - error(SYNTAX_ERR, "extra paren ", NIL,0); + error(SYNTAX_ERR, "extra paren ", NIL,th); return (res); }