From 83b0d35f5c30a66e8864e4eaab14ec3d0cd902a6 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 14 Oct 2018 07:38:51 +0200 Subject: [PATCH] core: Add cstring_to_symbol. * src/mes.c (make_symbol): Rename from lookup_symbol_. Update callers. (cstring_to_symbol): New function. * src/reader.c (reader_read_identifier_or_number): Use it. --- build-aux/mes-snarf.scm | 4 ++-- mes/module/mes/type-0.mes | 3 --- scaffold/mini-mes.c | 2 +- src/mes.c | 30 ++++++++++++++++++------------ src/reader.c | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/build-aux/mes-snarf.scm b/build-aux/mes-snarf.scm index 910ccdee..1bc4ffc6 100755 --- a/build-aux/mes-snarf.scm +++ b/build-aux/mes-snarf.scm @@ -146,8 +146,8 @@ exec ${GUILE-guile} --no-auto-compile -L $(dirname $0) -C $(dirname $0) -e '(mes (format #f "g_cells[cell_~a].string = MAKE_STRING (scm_~a.string);\n" (function.name f) (function.name f)) (format #f "g_cells[cell_~a].car = MAKE_STRING (scm_~a.car);\n" (function.name f) (function.name f))) (if %gcc? - (format #f "a = acons (lookup_symbol_ (scm_~a.string), ~a, a);\n\n" (function.name f) (function-cell-name f)) - (format #f "a = acons (lookup_symbol_ (scm_~a.car), ~a, a);\n\n" (function.name f) (function-cell-name f))))) + (format #f "a = acons (make_symbol (scm_~a.string), ~a, a);\n\n" (function.name f) (function-cell-name f)) + (format #f "a = acons (make_symbol (scm_~a.car), ~a, a);\n\n" (function.name f) (function-cell-name f))))) (define (disjoin . predicates) (lambda (. arguments) diff --git a/mes/module/mes/type-0.mes b/mes/module/mes/type-0.mes index 5c710215..a7b1059c 100644 --- a/mes/module/mes/type-0.mes +++ b/mes/module/mes/type-0.mes @@ -128,9 +128,6 @@ (define (symbol->keyword s) (core:make-cell (symbol->list s) 0)) -(define (list->symbol lst) - (core:lookup-symbol lst)) - (define (symbol->list s) (core:car s)) diff --git a/scaffold/mini-mes.c b/scaffold/mini-mes.c index f49a3607..7304a890 100644 --- a/scaffold/mini-mes.c +++ b/scaffold/mini-mes.c @@ -332,7 +332,7 @@ list_of_char_equal_p (SCM a, SCM b) ///((internal)) } SCM -lookup_symbol_ (SCM s) +list_to_symbol (SCM s) { SCM x = g_symbols; while (x) { diff --git a/src/mes.c b/src/mes.c index 1d0fbe76..11b02137 100644 --- a/src/mes.c +++ b/src/mes.c @@ -415,7 +415,7 @@ list_of_char_equal_p (SCM a, SCM b) ///((internal)) } SCM -lookup_symbol_ (SCM s) +list_to_symbol (SCM s) { SCM x = g_symbols; while (x) @@ -585,6 +585,12 @@ cstring_to_list (char const* s) return string_to_list (s, strlen (s)); } +SCM +cstring_to_symbol (char const *s) +{ + return list_to_symbol (cstring_to_list (s)); +} + // extra lib SCM assert_defined (SCM x, SCM e) ///((internal)) @@ -2147,50 +2153,50 @@ g_cells[cell_getenv_] = scm_getenv_; //mes.environment scm_cons.string = cstring_to_list (fun_cons.name); g_cells[cell_cons].string = MAKE_STRING (scm_cons.string); -a = acons (lookup_symbol_ (scm_cons.string), cell_cons, a); +a = acons (list_to_symbol (scm_cons.string), cell_cons, a); scm_car.string = cstring_to_list (fun_car.name); g_cells[cell_car].string = MAKE_STRING (scm_car.string); -a = acons (lookup_symbol_ (scm_car.string), cell_car, a); +a = acons (list_to_symbol (scm_car.string), cell_car, a); scm_cdr.string = cstring_to_list (fun_cdr.name); g_cells[cell_cdr].string = MAKE_STRING (scm_cdr.string); -a = acons (lookup_symbol_ (scm_cdr.string), cell_cdr, a); +a = acons (list_to_symbol (scm_cdr.string), cell_cdr, a); scm_list.string = cstring_to_list (fun_list.name); g_cells[cell_list].string = MAKE_STRING (scm_list.string); -a = acons (lookup_symbol_ (scm_list.string), cell_list, a); +a = acons (list_to_symbol (scm_list.string), cell_list, a); scm_null_p.string = cstring_to_list (fun_null_p.name); g_cells[cell_null_p].string = MAKE_STRING (scm_null_p.string); -a = acons (lookup_symbol_ (scm_null_p.string), cell_null_p, a); +a = acons (list_to_symbol (scm_null_p.string), cell_null_p, a); scm_eq_p.string = cstring_to_list (fun_eq_p.name); g_cells[cell_eq_p].string = MAKE_STRING (scm_eq_p.string); -a = acons (lookup_symbol_ (scm_eq_p.string), cell_eq_p, a); +a = acons (list_to_symbol (scm_eq_p.string), cell_eq_p, a); //math.environment scm_minus.string = cstring_to_list (fun_minus.name); g_cells[cell_minus].string = MAKE_STRING (scm_minus.string); -a = acons (lookup_symbol_ (scm_minus.string), cell_minus, a); +a = acons (list_to_symbol (scm_minus.string), cell_minus, a); scm_plus.string = cstring_to_list (fun_plus.name); g_cells[cell_plus].string = MAKE_STRING (scm_plus.string); -a = acons (lookup_symbol_ (scm_plus.string), cell_plus, a); +a = acons (list_to_symbol (scm_plus.string), cell_plus, a); //lib.environment scm_display_.string = cstring_to_list (fun_display_.name); g_cells[cell_display_].string = MAKE_STRING (scm_display_.string); -a = acons (lookup_symbol_ (scm_display_.string), cell_display_, a); +a = acons (list_to_symbol (scm_display_.string), cell_display_, a); scm_display_error_.string = cstring_to_list (fun_display_error_.name); g_cells[cell_display_error_].string = MAKE_STRING (scm_display_error_.string); -a = acons (lookup_symbol_ (scm_display_error_.string), cell_display_error_, a); +a = acons (list_to_symbol (scm_display_error_.string), cell_display_error_, a); //posix.environment scm_getenv_.string = cstring_to_list (fun_getenv_.name); g_cells[cell_getenv_].string = MAKE_STRING (scm_getenv_.string); -a = acons (lookup_symbol_ (scm_getenv_.string), cell_getenv_, a); +a = acons (list_to_symbol (scm_getenv_.string), cell_getenv_, a); #if !POSIX #undef function diff --git a/src/reader.c b/src/reader.c index b85c35bc..99b25fdf 100644 --- a/src/reader.c +++ b/src/reader.c @@ -103,7 +103,7 @@ reader_read_identifier_or_number (int c) } unreadchar (c); buf[i] = 0; - return lookup_symbol_ (cstring_to_list (buf)); + return cstring_to_symbol (buf); } SCM