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.c

41 lines
1.2 KiB

3 years ago
#include <string.h>
#include "fh_runtime.h"
#include "fh_error.h"
#include "fh_print.h"
3 years ago
#include "fh_builtins.h"
enum fh_error fh_register_words_from_array(struct fh_thread_s *fh, const struct name_and_handler *p)
3 years ago
{
// foreach
struct fh_word_s w;
enum fh_error rv;
while (p->handler) {
strcpy(w.name, p->name);
w.handler = p->handler;
w.flags = WORDFLAG_WORD | WORDFLAG_BUILTIN | (p->immediate ? WORDFLAG_IMMEDIATE : 0);
3 years ago
w.param = p->param;
3 years ago
rv = fh_add_word(&w, fh);
if (rv != FH_OK) {
return rv;
}
p++;
}
return FH_OK;
}
/** Add pointers to built-in word handlers to a runtime struct */
enum fh_error register_builtin_words(struct fh_thread_s *fh)
{
LOG("Adding builtin words");
enum fh_error rv;
TRY(fh_register_words_from_array(fh, fh_builtins_control));
TRY(fh_register_words_from_array(fh, fh_builtins_arith));
TRY(fh_register_words_from_array(fh, fh_builtins_stack));
TRY(fh_register_words_from_array(fh, fh_builtins_mem));
TRY(fh_register_words_from_array(fh, fh_builtins_meta));
TRY(fh_register_words_from_array(fh, fh_builtins_text));
TRY(fh_register_words_from_array(fh, fh_builtins_system));
return FH_OK;
}