Trying to build a forth runtime in C
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#include "forth_internal.h"
|
|
|
|
|
|
|
|
// extension
|
|
|
|
static enum fh_error w_reset(struct fh_thread_s *fh, const struct fh_word_s *w)
|
|
|
|
{
|
|
|
|
(void) w;
|
|
|
|
ENSURE_STATE(FH_STATE_INTERPRET);
|
|
|
|
|
|
|
|
fh_init(fh);
|
|
|
|
return FH_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum fh_error w_bye(struct fh_thread_s *fh, const struct fh_word_s *w)
|
|
|
|
{
|
|
|
|
(void) w;
|
|
|
|
fh_setstate(fh, FH_STATE_SHUTDOWN, 0);
|
|
|
|
return FH_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum fh_error w_debug(struct fh_thread_s *fh, const struct fh_word_s *w)
|
|
|
|
{
|
|
|
|
(void) w;
|
|
|
|
enum fh_error rv;
|
|
|
|
uint32_t val;
|
|
|
|
TRY(ds_pop(fh, &val));
|
|
|
|
fh_globals.verbose = val;
|
|
|
|
return FH_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum fh_error w_exit(struct fh_thread_s *fh, const struct fh_word_s *w)
|
|
|
|
{
|
|
|
|
(void) w;
|
|
|
|
enum fh_error rv;
|
|
|
|
ENSURE_STATE(FH_STATE_COMPILE);
|
|
|
|
// let's just hope the return stack is not clobbered!
|
|
|
|
TRY(fh_put_instr(fh, FH_INSTR_ENDWORD, 0));
|
|
|
|
return FH_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct name_and_handler fh_builtins_system[] = {
|
|
|
|
{"reset", w_reset, 1, 0},
|
|
|
|
{"bye", w_bye, 0, 0},
|
|
|
|
{"debug", w_debug, 0, 0},
|
|
|
|
{"exit", w_exit, 1, 0},
|
|
|
|
|
|
|
|
{ /* end marker */ }
|
|
|
|
};
|