more words implemented

This commit is contained in:
2021-11-21 13:47:31 +01:00
parent 37a1582801
commit bcc804289f
6 changed files with 88 additions and 12 deletions
+25
View File
@@ -96,6 +96,30 @@ static enum fh_error w_allot(struct fh_thread_s *fh, const struct fh_word_s *w)
return FH_OK;
}
static enum fh_error w_move(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
uint32_t count = 0, dst = 0, src = 0;
TRY(ds_pop(fh, &count));
TRY(ds_pop(fh, &dst));
TRY(ds_pop(fh, &src));
if (src+count>=HEAP_SIZE) {
LOGE("MOVE src out of bounds");
return FH_ERR_ILLEGAL_FETCH;
}
if (dst+count>=HEAP_SIZE) {
LOGE("MOVE dst out of bounds");
return FH_ERR_ILLEGAL_STORE;
}
fh_heap_copy(fh, dst, src, count);
return FH_OK;
}
static enum fh_error w_comma(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
@@ -202,6 +226,7 @@ const struct name_and_handler fh_builtins_mem[] = {
{"here", w_here, 0, 0},
{"state", wp_const, 0, MAGICADDR_STATE},
{"pad", w_pad, 0, 0},
{"move", w_move, 0, 0},
{ /* end marker */ }
};
+45 -2
View File
@@ -76,7 +76,19 @@ static enum fh_error w_dot(struct fh_thread_s *fh, const struct fh_word_s *w)
uint32_t a = 0;
TRY(ds_pop(fh, &a));
FHPRINT("%d ", (int32_t) a);
FHPRINT("%"PRIi32" ", (int32_t) a);
return FH_OK;
}
static enum fh_error w_u_dot(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
uint32_t a = 0;
TRY(ds_pop(fh, &a));
FHPRINT("%"PRIu32" ", a);
return FH_OK;
}
@@ -104,6 +116,21 @@ static enum fh_error w_type(struct fh_thread_s *fh, const struct fh_word_s *w)
return FH_OK;
}
static enum fh_error w_fill(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
uint32_t count = 0, addr = 0, ch;
TRY(ds_pop(fh, &ch));
TRY(pop_addr_len(fh, &addr, &count));
const char *str = fh_str_at(fh, addr);
if (!str) return FH_ERR_INTERNAL;
if (count > 0) {
memset((void*)str, (uint8_t)ch, count);
}
return FH_OK;
}
static enum fh_error wp_putc(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) fh;
@@ -203,6 +230,7 @@ static enum fh_error w_dot_quote(struct fh_thread_s *fh, const struct fh_word_s
char *start;
char c = (char)w->param;
uint32_t capacity = HEAP_END - addr;
LOG("dotquote end: %c", c);
if (c == '\\') {
start = (char *) &fh->heap[addr];
TRY(fh_input_read_quotedstring(fh, 1, start, capacity, &len));
@@ -352,6 +380,18 @@ static enum fh_error w_holds(struct fh_thread_s *fh, const struct fh_word_s *w)
return FH_OK;
}
static enum fh_error w_spaces(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
uint32_t num;
TRY(ds_pop(fh, &num));
while(num-->0) {
FHPRINT(" ");
}
return FH_OK;
}
static enum fh_error w_to_number(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
@@ -408,12 +448,15 @@ const struct name_and_handler fh_builtins_text[] = {
{".(", w_dot_quote, 1, ')'},
{".\\\"", w_dot_quote, 1, '\\'}, // escaped, this is non-standard
{".", w_dot, 0, 0},
{"u.", w_u_dot, 0, 0},
{"type", w_type, 0, 0},
{"fill", w_fill, 0, 0},
{"cr", wp_putc, 0, '\n'},
{"space", wp_putc, 0, ' '},
{"spaces", w_spaces, 0, 0},
{"bl", wp_const, 0, ' '},
{"u.r", w_u_r, 0, 0},
{"??", w_debug_dump, 0, 0},
{"??", w_debug_dump, 0, 0}, // XXX non-standard
{"emit", w_emit, 0, 0},
{"see", w_see, 0, 0},
{"<#", w_less_hash, 0, 0},