From 71dd84efee8417efb353861b15840ebcf867d7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 21 Nov 2021 14:00:16 +0100 Subject: [PATCH] fix word resolvable before finished --- include/fh_runtime.h | 2 ++ src/fh_builtins_meta.c | 10 ++++++++-- src/fh_runtime.c | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/fh_runtime.h b/include/fh_runtime.h index 4a214cf..48ced42 100644 --- a/include/fh_runtime.h +++ b/include/fh_runtime.h @@ -119,6 +119,8 @@ extern const char *substatenames[FH_SUBSTATE_MAX]; #define WORDFLAG_CONSTANT 0x10 /** Something CREATEd. When executed, put the data field address on stack */ #define WORDFLAG_CREATED 0x20 +/** Word marked as hidden is not findable, e.g. because it is being compiled. */ +#define WORDFLAG_HIDDEN 0x40 /** Word struct as they are stored in the dictionary */ struct fh_word_s { diff --git a/src/fh_builtins_meta.c b/src/fh_builtins_meta.c index 01feda4..84fc652 100644 --- a/src/fh_builtins_meta.c +++ b/src/fh_builtins_meta.c @@ -24,7 +24,7 @@ static enum fh_error w_colon(struct fh_thread_s *fh, const struct fh_word_s *w) new_word->handler = w_user_word; strncpy(new_word->name, wordname, namelen); new_word->name[namelen] = 0; - new_word->flags = WORDFLAG_WORD; + new_word->flags = WORDFLAG_WORD | WORDFLAG_HIDDEN; fh->dict_last = ptr; @@ -50,7 +50,7 @@ static enum fh_error w_colon_noname(struct fh_thread_s *fh, const struct fh_word new_word->param = fh->here; new_word->handler = w_user_word; new_word->name[0] = 0; - new_word->flags = WORDFLAG_WORD; + new_word->flags = WORDFLAG_WORD; // noname word exists outside the dict, so HIDDEN is not needed TRY(ds_push(fh, ptr)); // TODO maybe should do this at semicolon? @@ -289,6 +289,12 @@ static enum fh_error w_semicolon(struct fh_thread_s *fh, const struct fh_word_s // XXX if there was another definition previously and it was used in some other compiled function, // that old implementation will still be called. + + // unhide the entry, if hidden (colon does this to make the word unresolvable before it's finished) + struct fh_word_s *ww = fh_word_at(fh, fh->dict_last); + if (ww && (ww->flags & WORDFLAG_WORD)) { + ww->flags &= ~WORDFLAG_HIDDEN; + } return FH_OK; } diff --git a/src/fh_runtime.c b/src/fh_runtime.c index f49eba7..47fb16c 100644 --- a/src/fh_runtime.c +++ b/src/fh_runtime.c @@ -403,7 +403,7 @@ enum fh_error fh_find_word(struct fh_thread_s *fh, const char *name, size_t word if (!w) { break; } - if (0 == strncasecmp(name, w->name, wordlen) && w->name[wordlen] == 0) { + if (EQ(name, w->name, wordlen) && 0 == (w->flags & WORDFLAG_HIDDEN)) { // skip hidden names if (addr_out) { *addr_out = addr; }