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"
|
|
|
|
|
|
|
|
enum fh_error fh_register_words_from_array(struct fh_thread_s *fh, const struct name_and_handler *p)
|
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
w.param = p->param;
|
|
|
|
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;
|
|
|
|
}
|