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.
This commit is contained in:
@@ -768,18 +768,21 @@ add_user_def(char *name, JoyList body)
|
||||
{
|
||||
struct user_def *s;
|
||||
HASH_FIND_STR(user_defs, name, s);
|
||||
if (s) return; /* no overwrite */
|
||||
if (!s) {
|
||||
s = GC_malloc(sizeof *s);
|
||||
s->name = name;
|
||||
s->body = body;
|
||||
HASH_ADD_KEYPTR(hh, user_defs, s->name, strlen(s->name), s);
|
||||
}
|
||||
s->body = body;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user