convert input parsing to pluggable specs

This commit is contained in:
2021-11-22 00:07:53 +01:00
parent cab55d835b
commit ab1b39598c
9 changed files with 316 additions and 51 deletions
+2
View File
@@ -34,4 +34,6 @@
#define MAGICADDR_UNRESOLVED 0xFFFFFBADULL
#define MAGICADDR_ENDCASE_UNRESOLVED 0xFFFC5BADULL
#define FH_PROMPT_STR "> "
#endif //FORTH_FH_CONFIG_H
+46
View File
@@ -0,0 +1,46 @@
/**
* TODO file description
*
* Created on 2021/11/21.
*/
#ifndef FORTH_FH_INPUT_H
#define FORTH_FH_INPUT_H
struct fh_thread_s;
struct fh_input_spec_s;
/** Refill the input buffer, returns false on failure / EOF */
typedef bool (*fh_input_refill_t)(struct fh_thread_s *fh, struct fh_input_spec_s *spec);
/** Spec free func */
typedef void (*fh_input_free_t)(void *spec);
struct fh_input_spec_s {
struct fh_input_spec_s *previous;
fh_input_refill_t refill_input_buffer;
fh_input_free_t free_self;
uint32_t linenum;
// saved values, filled when pushing
char saved_buffer[INPUT_BUFFER_SIZE];
uint32_t saved_inputptr;
uint32_t saved_inputlen;
};
/**
* Push current input spec and state, replace with new one
*/
void fh_push_input(struct fh_thread_s *fh, struct fh_input_spec_s *newinput);
/**
* Discard current input spec, restore previous.
* fh->input will be NULL if this was the topmost one
*/
void fh_pop_input(struct fh_thread_s *fh);
struct fh_input_spec_s *fh_create_input_from_filename(char *path);
struct fh_input_spec_s *fh_create_input_from_filestruct(FILE *f);
struct fh_input_spec_s *fh_create_input_from_string(char *str, size_t len);
void fh_input_teardown(struct fh_thread_s *fh);
#endif //FORTH_FH_INPUT_H
+6 -1
View File
@@ -217,6 +217,9 @@ struct fh_thread_s {
uint32_t parse_if_level;
bool executing_compiled;
/** Input spec */
struct fh_input_spec_s *input;
};
enum fh_error fh_loop_nest(struct fh_thread_s *fh, uint32_t indexvalue);
@@ -265,7 +268,9 @@ enum fh_error fh_find_word(struct fh_thread_s *fh, const char *name, size_t word
enum fh_error fh_init(struct fh_thread_s *fh);
enum fh_error fh_process_line(struct fh_thread_s *fh, const char *linebuf, size_t len);
//enum fh_error fh_process_line(struct fh_thread_s *fh, const char *linebuf, size_t len);
enum fh_error fh_runtime_start(struct fh_thread_s *fh, struct fh_input_spec_s *input);
static inline uint32_t word_addr(struct fh_thread_s *fh, const struct fh_word_s *w)
{
+1
View File
@@ -14,6 +14,7 @@
#include "fh_config.h"
#include "fh_error.h"
#include "fh_globals.h"
#include "fh_input.h"
#include "fh_runtime.h"
#include "fh_print.h"
+1
View File
@@ -23,6 +23,7 @@
#include "fh_helpers.h"
#include "fh_globals.h"
#include "fh_print.h"
#include "fh_input.h"
#include "fh_runtime.h"
#include "fh_mem.h"
#include "fh_stack.h"