|
|
|
@ -73,6 +73,79 @@ static enum fh_error w_semicolon(struct fh_thread_s *fh) |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_dup(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t a = 0; |
|
|
|
|
TRY(ds_peek(fh, &a)); |
|
|
|
|
TRY(ds_push(fh, a)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_drop(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t a = 0; |
|
|
|
|
TRY(ds_pop(fh, &a)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_swap(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
TRY(ds_roll(fh, 1)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_rot(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
TRY(ds_roll(fh, 2)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_over(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t a = 0; |
|
|
|
|
TRY(ds_peek_n(fh, &a, 1)); |
|
|
|
|
TRY(ds_push(fh, a)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_tuck(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t a = 0; |
|
|
|
|
uint32_t b = 0; |
|
|
|
|
TRY(ds_pop(fh, &a)); |
|
|
|
|
TRY(ds_pop(fh, &b)); |
|
|
|
|
TRY(ds_push(fh, a)); |
|
|
|
|
TRY(ds_push(fh, b)); |
|
|
|
|
TRY(ds_push(fh, a)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_pick(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t nth = 0; |
|
|
|
|
uint32_t a = 0; |
|
|
|
|
TRY(ds_pop(fh, &nth)); |
|
|
|
|
TRY(ds_peek_n(fh, &a, nth)); |
|
|
|
|
TRY(ds_push(fh, a)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_roll(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t n = 0; |
|
|
|
|
TRY(ds_pop(fh, &n)); |
|
|
|
|
TRY(ds_roll(fh, n)); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_dot(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
enum fh_error rv; |
|
|
|
@ -108,6 +181,15 @@ static enum fh_error w_space(struct fh_thread_s *fh) |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_dump(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
(void) fh; |
|
|
|
|
for (int i = 0; i < fh->data_stack_top; i++) { |
|
|
|
|
FHPRINT("%d ", fh->data_stack[i]); |
|
|
|
|
} |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_s_quote(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
fh_setsubstate(fh, FH_SUBSTATE_SQUOTE); |
|
|
|
@ -134,7 +216,6 @@ static enum fh_error w_paren(struct fh_thread_s *fh) |
|
|
|
|
|
|
|
|
|
static enum fh_error w_bye(struct fh_thread_s *fh) |
|
|
|
|
{ |
|
|
|
|
LOG("state=SHUTDOWN"); |
|
|
|
|
fh_setstate(fh, FH_STATE_SHUTDOWN, 0); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
@ -153,19 +234,30 @@ enum fh_error register_builtin_words(struct fh_thread_s *fh) |
|
|
|
|
{".\"", w_dot_quote, 1}, |
|
|
|
|
/* Compiler control words */ |
|
|
|
|
{"bye", w_bye, 0}, |
|
|
|
|
/* Basic arithmetics */ |
|
|
|
|
/* Arithmetics */ |
|
|
|
|
{"+", w_add, 0}, |
|
|
|
|
{"-", w_sub, 0}, |
|
|
|
|
{"*", w_mul, 0}, |
|
|
|
|
/* Control words */ |
|
|
|
|
{":", w_colon, 0}, |
|
|
|
|
{";", w_semicolon, 1}, |
|
|
|
|
/* Stack manip */ |
|
|
|
|
{"dup", w_dup, 0}, |
|
|
|
|
{"drop", w_drop, 0}, |
|
|
|
|
{"swap", w_swap, 0}, |
|
|
|
|
{"rot", w_rot, 0}, |
|
|
|
|
{"over", w_over, 0}, |
|
|
|
|
{"tuck", w_tuck, 0}, |
|
|
|
|
{"pick", w_pick, 0}, |
|
|
|
|
{"roll", w_roll, 0}, |
|
|
|
|
/* Printing */ |
|
|
|
|
{".", w_dot, 0}, |
|
|
|
|
{"type", w_type, 0}, |
|
|
|
|
{"cr", w_cr, 0}, |
|
|
|
|
{"space", w_space, 0}, |
|
|
|
|
{"\\", w_backslash, 0}, // line comment
|
|
|
|
|
{"(", w_paren, 0}, // enclosed comment
|
|
|
|
|
{"dump", w_dump, 0}, |
|
|
|
|
/* Control words */ |
|
|
|
|
{":", w_colon, 0}, |
|
|
|
|
{";", w_semicolon, 1}, |
|
|
|
|
{"\\", w_backslash, 1}, // line comment
|
|
|
|
|
{"(", w_paren, 1}, // enclosed comment
|
|
|
|
|
{ /* end marker */ } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|