From 8edfdf255be1d66921458cc2bbd2725a7c353291 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 16 Nov 2019 19:01:16 +0100 Subject: [PATCH] core: hashq_get_handle: FIX! --- include/mes/builtins.h | 2 +- src/builtins.c | 2 +- src/eval-apply.c | 2 +- src/hash.c | 12 +++++------- src/module.c | 6 +++--- src/variable.c | 4 ++-- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/include/mes/builtins.h b/include/mes/builtins.h index 891a5711..3aafbae6 100644 --- a/include/mes/builtins.h +++ b/include/mes/builtins.h @@ -63,7 +63,7 @@ struct scm *gc (); /* src/hash.c */ struct scm *hashq (struct scm *x, struct scm *size); struct scm *hash (struct scm *x, struct scm *size); -struct scm *hashq_get_handle_ (struct scm *table, struct scm *key, struct scm *dflt); +struct scm *hashq_get_handle_ (struct scm *table, struct scm *key); struct scm *hashq_ref_ (struct scm *table, struct scm *key, struct scm *dflt); struct scm *hash_ref_ (struct scm *table, struct scm *key, struct scm *dflt); struct scm *hashq_set_handle_x (struct scm *table, struct scm *key, struct scm *value); diff --git a/src/builtins.c b/src/builtins.c index cfae324b..ec87f48f 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -173,7 +173,7 @@ mes_builtins (struct scm *a) /*:((internal)) */ /* src/hash.c */ a = init_builtin (builtin_type, "hashq", 2, &hashq, a); a = init_builtin (builtin_type, "hash", 2, &hash, a); - a = init_builtin (builtin_type, "core:hashq-get-handle", 3, &hashq_get_handle_, a); + a = init_builtin (builtin_type, "core:hashq-get-handle", 2, &hashq_get_handle_, a); a = init_builtin (builtin_type, "core:hashq-ref", 3, &hashq_ref_, a); a = init_builtin (builtin_type, "core:hash-ref", 3, &hash_ref_, a); a = init_builtin (builtin_type, "hashq-set-handle!", 3, &hashq_set_handle_x, a); diff --git a/src/eval-apply.c b/src/eval-apply.c index 17931b27..e89b718d 100644 --- a/src/eval-apply.c +++ b/src/eval-apply.c @@ -148,7 +148,7 @@ struct scm * macro_get_handle (struct scm *name) /*:((internal)) */ { if (name->type == TSYMBOL) - return hashq_get_handle_ (g_macros, name, cell_nil); + return hashq_get_handle_ (g_macros, name); return cell_f; } diff --git a/src/hash.c b/src/hash.c index 0d6b5e65..6f77fe60 100644 --- a/src/hash.c +++ b/src/hash.c @@ -66,7 +66,7 @@ hash (struct scm *x, struct scm *size) } struct scm * -hashq_get_handle_ (struct scm *table, struct scm *key, struct scm *dflt) +hashq_get_handle_ (struct scm *table, struct scm *key) { struct scm *s = struct_ref_ (table, 3); long size = s->value; @@ -74,8 +74,6 @@ hashq_get_handle_ (struct scm *table, struct scm *key, struct scm *dflt) struct scm *buckets = struct_ref_ (table, 4); struct scm *bucket = vector_ref_ (buckets, hash); struct scm *x = cell_f; - if (dflt->type == TPAIR) - x = dflt->car; if (bucket->type == TPAIR) x = assq (key, bucket); return x; @@ -84,9 +82,11 @@ hashq_get_handle_ (struct scm *table, struct scm *key, struct scm *dflt) struct scm * hashq_ref_ (struct scm *table, struct scm *key, struct scm *dflt) { - struct scm *x = hashq_get_handle_ (table, key, dflt); + struct scm *x = hashq_get_handle_ (table, key); if (x != cell_f) x = x->cdr; + else + x = dflt; return x; } @@ -98,9 +98,7 @@ hash_ref_ (struct scm *table, struct scm *key, struct scm *dflt) unsigned hash = hash_ (key, size); struct scm *buckets = struct_ref_ (table, 4); struct scm *bucket = vector_ref_ (buckets, hash); - struct scm *x = cell_f; - if (dflt->type == TPAIR) - x = dflt->car; + struct scm *x = dflt; if (bucket->type == TPAIR) { x = assoc (key, bucket); diff --git a/src/module.c b/src/module.c index a742fc06..55777210 100644 --- a/src/module.c +++ b/src/module.c @@ -46,7 +46,7 @@ current_module () /*:((internal)) */ if (booted_p->type == TPAIR && booted_p->cdr != cell_f) { */ - struct scm *module = hashq_get_handle_ (M0, cstring_to_symbol ("*current-module*"), cell_f); + struct scm *module = hashq_get_handle_ (M0, cstring_to_symbol ("*current-module*")); if (module->type == TPAIR && module->cdr != cell_f) return module->cdr; /* @@ -85,7 +85,7 @@ module_handle (struct scm *module, struct scm *name) /*:((internal)) */ eputs ("\n"); } - struct scm *handle = hashq_get_handle_ (table, name, cell_f); + struct scm *handle = hashq_get_handle_ (table, name); if (handle != cell_f) return handle; @@ -111,7 +111,7 @@ module_handle (struct scm *module, struct scm *name) /*:((internal)) */ } /* 4. Hack for Mes: always look in M0. */ - handle = hashq_get_handle_ (M0, name, cell_f); + handle = hashq_get_handle_ (M0, name); return handle; } diff --git a/src/variable.c b/src/variable.c index 7808c27c..5cee9d58 100644 --- a/src/variable.c +++ b/src/variable.c @@ -134,14 +134,14 @@ lookup_handle (struct scm *name, struct scm *define_p) if (define_p == cell_f) { if (module == M0) - handle = hashq_get_handle_ (M0, name, cell_f); + handle = hashq_get_handle_ (M0, name); else handle = module_handle (module, name); } else { struct scm *table = module_defines (module); - handle = hashq_get_handle_ (table, name, cell_f); + handle = hashq_get_handle_ (table, name); if (handle == cell_f) { if (g_debug > 0)