fix word resolvable before finished

master
Ondřej Hruška 3 years ago
parent bcc804289f
commit 71dd84efee
  1. 2
      include/fh_runtime.h
  2. 10
      src/fh_builtins_meta.c
  3. 2
      src/fh_runtime.c

@ -119,6 +119,8 @@ extern const char *substatenames[FH_SUBSTATE_MAX];
#define WORDFLAG_CONSTANT 0x10 #define WORDFLAG_CONSTANT 0x10
/** Something CREATEd. When executed, put the data field address on stack */ /** Something CREATEd. When executed, put the data field address on stack */
#define WORDFLAG_CREATED 0x20 #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 */ /** Word struct as they are stored in the dictionary */
struct fh_word_s { struct fh_word_s {

@ -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; new_word->handler = w_user_word;
strncpy(new_word->name, wordname, namelen); strncpy(new_word->name, wordname, namelen);
new_word->name[namelen] = 0; new_word->name[namelen] = 0;
new_word->flags = WORDFLAG_WORD; new_word->flags = WORDFLAG_WORD | WORDFLAG_HIDDEN;
fh->dict_last = ptr; 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->param = fh->here;
new_word->handler = w_user_word; new_word->handler = w_user_word;
new_word->name[0] = 0; 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? 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, // XXX if there was another definition previously and it was used in some other compiled function,
// that old implementation will still be called. // 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; return FH_OK;
} }

@ -403,7 +403,7 @@ enum fh_error fh_find_word(struct fh_thread_s *fh, const char *name, size_t word
if (!w) { if (!w) {
break; 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) { if (addr_out) {
*addr_out = addr; *addr_out = addr;
} }

Loading…
Cancel
Save