|
|
|
@ -100,7 +100,7 @@ static enum fh_error w_zero_greater(struct fh_thread_s *fh, const struct fh_word |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t a = 0; |
|
|
|
|
TRY(ds_pop(fh, &a)); |
|
|
|
|
TRY(ds_push(fh, TOBOOL(a > 0))); |
|
|
|
|
TRY(ds_push(fh, TOBOOL((int32_t) a > 0))); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -132,11 +132,34 @@ static enum fh_error w_less(struct fh_thread_s *fh, const struct fh_word_s *w) |
|
|
|
|
uint32_t a = 0, b = 0; |
|
|
|
|
TRY(ds_pop(fh, &b)); |
|
|
|
|
TRY(ds_pop(fh, &a)); |
|
|
|
|
TRY(ds_push(fh, TOBOOL(a < b))); |
|
|
|
|
TRY(ds_push(fh, TOBOOL((int32_t) a < (int32_t) b))); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_greater(struct fh_thread_s *fh, const struct fh_word_s *w) |
|
|
|
|
{ |
|
|
|
|
(void) w; |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t a = 0, b = 0; |
|
|
|
|
TRY(ds_pop(fh, &b)); |
|
|
|
|
TRY(ds_pop(fh, &a)); |
|
|
|
|
TRY(ds_push(fh, TOBOOL((int32_t) a > (int32_t) b))); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static enum fh_error w_u_less(struct fh_thread_s *fh, const struct fh_word_s *w) |
|
|
|
|
{ |
|
|
|
|
(void) w; |
|
|
|
|
enum fh_error rv; |
|
|
|
|
uint32_t a = 0, b = 0; |
|
|
|
|
TRY(ds_pop(fh, &b)); |
|
|
|
|
TRY(ds_pop(fh, &a)); |
|
|
|
|
TRY(ds_push(fh, TOBOOL(a < b))); |
|
|
|
|
return FH_OK; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static enum fh_error w_u_greater(struct fh_thread_s *fh, const struct fh_word_s *w) |
|
|
|
|
{ |
|
|
|
|
(void) w; |
|
|
|
|
enum fh_error rv; |
|
|
|
@ -310,37 +333,39 @@ static enum fh_error w_slash_mod(struct fh_thread_s *fh, const struct fh_word_s |
|
|
|
|
|
|
|
|
|
const struct name_and_handler fh_builtins_arith[] = { |
|
|
|
|
/* Arithmetics */ |
|
|
|
|
{"base", wp_const, 0, MAGICADDR_BASE}, |
|
|
|
|
{"decimal", wp_setbase, 0, 10}, |
|
|
|
|
{"hex", wp_setbase, 0, 16}, |
|
|
|
|
{"false", wp_const, 0, 0}, |
|
|
|
|
{"true", wp_const, 0, 0xFFFFFFFF}, |
|
|
|
|
{"+", w_plus, 0, 0}, |
|
|
|
|
{"-", w_minus, 0, 0}, |
|
|
|
|
{"*", w_star, 0, 0}, |
|
|
|
|
{"*/", w_star_slash, 0, 0}, |
|
|
|
|
{"*/mod", w_star_slash_mod, 0, 0}, |
|
|
|
|
{"or", w_or, 0, 0}, |
|
|
|
|
{"and", w_and, 0, 0}, |
|
|
|
|
{"xor", w_xor, 0, 0}, |
|
|
|
|
{"/", w_slash, 0, 0}, |
|
|
|
|
{"abs", w_abs, 0, 0}, |
|
|
|
|
{"/mod", w_slash_mod, 0, 0}, |
|
|
|
|
{"invert", w_invert, 0, 0}, |
|
|
|
|
{"negate", w_negate, 0, 0}, |
|
|
|
|
{"0<", w_zero_less, 0, 0}, |
|
|
|
|
{"0=", w_zero_equals, 0, 0}, |
|
|
|
|
{"0<>", w_zero_not_equals, 0, 0}, |
|
|
|
|
{"0>", w_zero_greater, 0, 0}, |
|
|
|
|
{"<", w_less, 0, 0}, |
|
|
|
|
{"=", w_equals, 0, 0}, |
|
|
|
|
{"<>", w_not_equals, 0, 0}, |
|
|
|
|
{">", w_greater, 0, 0}, |
|
|
|
|
{"1+", wp_add, 0, 1}, |
|
|
|
|
{"1-", wp_add, 0, -1}, |
|
|
|
|
{"2+", wp_add, 0, 2}, |
|
|
|
|
{"2-", wp_add, 0, -2}, |
|
|
|
|
{"2*", wp_mul, 0, 2}, |
|
|
|
|
{"2/", wp_div, 0, 2}, |
|
|
|
|
{"base", wp_const, 0, MAGICADDR_BASE}, |
|
|
|
|
{"decimal", wp_setbase, 0, 10}, |
|
|
|
|
{"hex", wp_setbase, 0, 16}, |
|
|
|
|
{"false", wp_const, 0, 0}, |
|
|
|
|
{"true", wp_const, 0, 0xFFFFFFFF}, |
|
|
|
|
{"+", w_plus, 0, 0}, |
|
|
|
|
{"-", w_minus, 0, 0}, |
|
|
|
|
{"*", w_star, 0, 0}, |
|
|
|
|
{"*/", w_star_slash, 0, 0}, |
|
|
|
|
{"*/mod", w_star_slash_mod, 0, 0}, |
|
|
|
|
{"or", w_or, 0, 0}, |
|
|
|
|
{"and", w_and, 0, 0}, |
|
|
|
|
{"xor", w_xor, 0, 0}, |
|
|
|
|
{"/", w_slash, 0, 0}, |
|
|
|
|
{"abs", w_abs, 0, 0}, |
|
|
|
|
{"/mod", w_slash_mod, 0, 0}, |
|
|
|
|
{"invert", w_invert, 0, 0}, |
|
|
|
|
{"negate", w_negate, 0, 0}, |
|
|
|
|
{"0<", w_zero_less, 0, 0}, |
|
|
|
|
{"0=", w_zero_equals, 0, 0}, |
|
|
|
|
{"0<>", w_zero_not_equals, 0, 0}, |
|
|
|
|
{"0>", w_zero_greater, 0, 0}, |
|
|
|
|
{"<", w_less, 0, 0}, |
|
|
|
|
{"u<", w_u_less, 0, 0}, |
|
|
|
|
{"=", w_equals, 0, 0}, |
|
|
|
|
{"<>", w_not_equals, 0, 0}, |
|
|
|
|
{">", w_greater, 0, 0}, |
|
|
|
|
{"u>", w_u_greater, 0, 0}, |
|
|
|
|
{"1+", wp_add, 0, 1}, |
|
|
|
|
{"1-", wp_add, 0, -1}, |
|
|
|
|
{"2+", wp_add, 0, 2}, |
|
|
|
|
{"2-", wp_add, 0, -2}, |
|
|
|
|
{"2*", wp_mul, 0, 2}, |
|
|
|
|
{"2/", wp_div, 0, 2}, |
|
|
|
|
{ /* end marker */ } |
|
|
|
|
}; |
|
|
|
|