/** * TODO file description * * Created on 2021/11/13. */ #ifndef FORTH_H #define FORTH_H #include #include /* for printing */ #include #include #include "fh_config.h" #include "fh_error.h" struct fh_thread_s; struct fh_word_s; struct fh_instruction_s; /** Word handler typedef */ typedef enum fh_error (*word_exec_t)(struct fh_thread_s *fh); /** Forth runtime global state */ struct fh_global_s { /** Verbose logging enabled */ bool verbose; /** Interactive mode (i.e. not started with a file argument) */ bool interactive; }; extern struct fh_global_s fh_globals; /* logging */ #define LOG(format, ...) do { if(fh_globals.verbose) { fprintf(stderr, format "\n", ##__VA_ARGS__); } } while (0) #define LOGI(format, ...) fprintf(stderr, "\x1b[32m" format "\x1b[m\n", ##__VA_ARGS__) #define LOGE(format, ...) fprintf(stderr, "\x1b[31;1m" format "\x1b[m\n", ##__VA_ARGS__) /* Forth standard output. XXX should be stdout, but then colors get mangled if logging is used */ #define FHPRINT(format, ...) fprintf(stderr, "\x1b[33;1m" format "\x1b[m", ##__VA_ARGS__) #define FHPRINT_SVC(format, ...) fprintf(stderr, "" format "", ##__VA_ARGS__) enum fh_error fh_init_thread(struct fh_thread_s *fh); enum fh_error fh_process_line(struct fh_thread_s *fh, char *linebuf); #endif //FORTH_H