From 8016fd697ab25e3056cc32a90e6627f79bac65df Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Wed, 8 Feb 2023 23:20:35 -0800 Subject: [PATCH] Allow for redefinition of user defs. And some protection for inscribe, empty quotes or quotes that do not have a symbol at the first item are just consumed without affecting the user defs. Because the Gperf wordlist is checked before the user defs hash the inscribe command cannot overwrite the commands defined in the wordlist. --- implementations/C/joy.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/implementations/C/joy.c b/implementations/C/joy.c index eab72cf..eb37401 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -768,11 +768,12 @@ add_user_def(char *name, JoyList body) { struct user_def *s; HASH_FIND_STR(user_defs, name, s); - if (s) return; /* no overwrite */ - s = GC_malloc(sizeof *s); - s->name = name; + if (!s) { + s = GC_malloc(sizeof *s); + s->name = name; + HASH_ADD_KEYPTR(hh, user_defs, s->name, strlen(s->name), s); + } s->body = body; - HASH_ADD_KEYPTR(hh, user_defs, s->name, strlen(s->name), s); } @@ -780,6 +781,8 @@ void inscribe(JoyListPtr stack, __attribute__((unused)) JoyListPtr expression) { JoyList quote = pop_list(stack); + if (!quote) return; + if (joySymbol != quote->head->kind) return; add_user_def(quote->head->value.symbol, quote->tail); } -- 2.11.0