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/include/fh_builtins.h

43 lines
1.3 KiB

3 years ago
/**
* Forth built-ins
*
* Created on 2021/11/13.
*/
#ifndef FORTH_FH_BUILTINS_H
#define FORTH_FH_BUILTINS_H
struct name_and_handler {
const char *name;
word_exec_t handler;
bool immediate;
uint32_t param;
};
enum fh_error fh_register_words_from_array(struct fh_thread_s *fh, const struct name_and_handler *p);
3 years ago
enum fh_error register_builtin_words(struct fh_thread_s *fh);
#define TOBOOL(a) ((a) == 0 ? 0 : 0xFFFFFFFF)
#define ENSURE_STATE(__state) do { \
if (fh->state != (__state)) { \
LOGE("Invalid state %d, expected %d", fh->state, (__state)); \
return FH_ERR_INVALID_STATE; \
} \
} while (0)
extern const struct name_and_handler fh_builtins_control[];
extern const struct name_and_handler fh_builtins_arith[];
extern const struct name_and_handler fh_builtins_stack[];
extern const struct name_and_handler fh_builtins_mem[];
extern const struct name_and_handler fh_builtins_meta[];
extern const struct name_and_handler fh_builtins_text[];
extern const struct name_and_handler fh_builtins_system[];
enum fh_error wp_const(struct fh_thread_s *fh, const struct fh_word_s *w);
enum fh_error wp_mul(struct fh_thread_s *fh, const struct fh_word_s *w);
enum fh_error wp_add(struct fh_thread_s *fh, const struct fh_word_s *w);
3 years ago
#endif //FORTH_FH_BUILTINS_H