implement BUFFER:

master
Ondřej Hruška 3 years ago
parent a204966014
commit f2d0d82eb3
  1. 41
      src/fh_builtins_mem.c

@ -96,6 +96,46 @@ static enum fh_error w_allot(struct fh_thread_s *fh, const struct fh_word_s *w)
return FH_OK;
}
static enum fh_error rt_read_buffer_addr(struct fh_thread_s *fh, const struct fh_word_s *w)
{
enum fh_error rv;
TRY(ds_push(fh, w->param));
return FH_OK;
}
static enum fh_error w_buffer_colon(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
ENSURE_STATE(FH_STATE_INTERPRET);
uint32_t count = 0;
TRY(ds_pop(fh, &count));
TRY(fh_heap_reserve(fh, count, NULL));
char *wordname = NULL;
size_t namelen = 0;
fh_input_consume_spaces(fh);
TRY(fh_input_read_word(fh, &wordname, &namelen));
LOG("Buffer name: %.*s", namelen, wordname);
uint32_t ptr;
TRY(fh_heap_reserve(fh, DICTWORD_SIZE + count, &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 = ptr + DICTWORD_SIZE;
new_word->handler = rt_read_buffer_addr;
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_move(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
@ -218,6 +258,7 @@ const struct name_and_handler fh_builtins_mem[] = {
{"2@", w_two_fetch, 0, 0},
{"aligned", w_aligned, 0, 0},
{"allot", w_allot, 0, 0},
{"buffer:", w_buffer_colon, 0, 0},
{"align", w_align, 0, 0},
{",", w_comma, 0, 0},
{"c,", w_c_comma, 0, 0},

Loading…
Cancel
Save