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.
 
 
 
forth/src/fh_builtins_system.c

51 lines
1.1 KiB

#include "forth.h"
#include "fh_error.h"
#include "fh_runtime.h"
#include "fh_mem.h"
#include "fh_stack.h"
#include "fh_print.h"
#include "fh_builtins.h"
static enum fh_error w_depth(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
TRY(ds_push(fh, fh->data_stack_top));
return FH_OK;
}
static enum fh_error w_unused(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
TRY(ds_push(fh, HEAP_SIZE - fh->here));
return FH_OK;
}
// extension
static enum fh_error w_reset(struct fh_thread_s *fh, const struct fh_word_s *w)
{
(void) w;
enum fh_error rv;
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;
}
const struct name_and_handler fh_builtins_system[] = {
{"depth", w_depth, 0, 0},
{"unused", w_unused, 0, 0},
{"reset", w_reset, 1, 0},
{"bye", w_bye, 0, 0},
{ /* end marker */ }
};