|
|
@ -331,6 +331,24 @@ static enum fh_error w_slash_mod(struct fh_thread_s *fh, const struct fh_word_s |
|
|
|
return FH_OK; |
|
|
|
return FH_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static enum fh_error w_mod(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)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (b == 0) { |
|
|
|
|
|
|
|
return FH_ERR_DIV_BY_ZERO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t rem = a % b; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TRY(ds_push(fh, rem)); |
|
|
|
|
|
|
|
return FH_OK; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const struct name_and_handler fh_builtins_arith[] = { |
|
|
|
const struct name_and_handler fh_builtins_arith[] = { |
|
|
|
/* Arithmetics */ |
|
|
|
/* Arithmetics */ |
|
|
|
{"base", wp_const, 0, MAGICADDR_BASE}, |
|
|
|
{"base", wp_const, 0, MAGICADDR_BASE}, |
|
|
@ -349,6 +367,7 @@ const struct name_and_handler fh_builtins_arith[] = { |
|
|
|
{"/", w_slash, 0, 0}, |
|
|
|
{"/", w_slash, 0, 0}, |
|
|
|
{"abs", w_abs, 0, 0}, |
|
|
|
{"abs", w_abs, 0, 0}, |
|
|
|
{"/mod", w_slash_mod, 0, 0}, |
|
|
|
{"/mod", w_slash_mod, 0, 0}, |
|
|
|
|
|
|
|
{"mod", w_mod, 0, 0}, |
|
|
|
{"invert", w_invert, 0, 0}, |
|
|
|
{"invert", w_invert, 0, 0}, |
|
|
|
{"negate", w_negate, 0, 0}, |
|
|
|
{"negate", w_negate, 0, 0}, |
|
|
|
{"0<", w_zero_less, 0, 0}, |
|
|
|
{"0<", w_zero_less, 0, 0}, |
|
|
|