From a2049660142b0aed94fb880f664cb2098dc7d313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 21 Nov 2021 16:16:08 +0100 Subject: [PATCH] implement MARKER --- src/fh_builtins_meta.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/fh_builtins_meta.c b/src/fh_builtins_meta.c index 84fc652..be5e818 100644 --- a/src/fh_builtins_meta.c +++ b/src/fh_builtins_meta.c @@ -31,6 +31,42 @@ static enum fh_error w_colon(struct fh_thread_s *fh, const struct fh_word_s *w) return FH_OK; } +static enum fh_error rt_marker(struct fh_thread_s *fh, const struct fh_word_s *w) +{ + LOG("Restore dict to landmark sate \"%s\"", w->name); + fh->dict_last = w->param; + return FH_OK; +} + +static enum fh_error w_marker(struct fh_thread_s *fh, const struct fh_word_s *w) +{ + (void) w; + enum fh_error rv; + ENSURE_STATE(FH_STATE_INTERPRET); + + char *wordname = NULL; + size_t namelen = 0; + fh_input_consume_spaces(fh); + TRY(fh_input_read_word(fh, &wordname, &namelen)); + LOG("Marker name: %.*s", namelen, wordname); + + uint32_t ptr; + TRY(fh_heap_reserve(fh, DICTWORD_SIZE, &ptr)); + + struct fh_word_s *new_word = fh_word_at(fh, ptr); + if (!new_word) return FH_ERR_INTERNAL; + new_word->previous = fh->dict_last; + new_word->param = fh->dict_last; + new_word->handler = rt_marker; + strncpy(new_word->name, wordname, namelen); + new_word->name[namelen] = 0; + new_word->flags = WORDFLAG_WORD; + + fh->dict_last = ptr; + + return FH_OK; +} + static enum fh_error w_colon_noname(struct fh_thread_s *fh, const struct fh_word_s *w) { (void) w; @@ -655,5 +691,6 @@ const struct name_and_handler fh_builtins_meta[] = { {"[']", wp_tick, 1, 1}, {"execute", w_execute, 0, 0}, {"environment?", w_env_query, 0, 0}, + {"marker", w_marker, 0, 0}, { /* end marker */ } };