This commit is contained in:
Dominic Grimm 2022-12-23 20:52:25 +01:00
parent bd9b51be9a
commit 115dc530e1
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
6 changed files with 153 additions and 64 deletions

View file

@ -6,7 +6,7 @@
#include "result.h"
#include "number.h"
extern unsigned int hydroforth__hash_string(const char *const key, unsigned char len);
extern unsigned hydroforth__hash_string(const char *const key, unsigned char len);
extern bool hydroforth__is_space(char c);
@ -33,6 +33,7 @@ typedef struct HYDROFORTH__WORD
typedef struct HYDROFORTH__WORD_DEFINITION
{
HYDROFORTH__WORD *words;
unsigned char words_len;
} HYDROFORTH__WORD_DEFINITION;
typedef struct HYDROFORTH__WORD_DEFINITION_BASE_KEY
@ -58,10 +59,10 @@ typedef struct HYDROFORTH__INTERPRETER
unsigned long pos;
HYDROFORTH__WORD_DEFINITION_SINGLE_CHAR_WORD_KEY single_char_word_keys[32];
unsigned char single_char_word_keys_len;
HYDROFORTH__WORD_DEFINITION_WORD_KEY word_keys[256];
unsigned short word_keys_len;
unsigned short word_keys_max_len;
HYDROFORTH__WORD_DEFINITION_WORD_KEY *word_keys;
HYDROFORTH__WORD_DEFINITION word_definitions[256];
HYDROFORTH__WORD_DEFINITION word_definitions[256 + 32];
unsigned short word_definitions_len;
HYDROFORTH__WORD call_stack[256];
unsigned char call_stack_len;
int stack[256];
@ -76,23 +77,26 @@ typedef struct HYDROFORTH__SCAN_NEXT_WORD_RESULT
extern HYDROFORTH__SCAN_NEXT_WORD_RESULT hydroforth__scan_next_word(HYDROFORTH__INTERPRETER *interpreter);
extern void hydroforth__parse(HYDROFORTH__RESULT *const result, HYDROFORTH__INTERPRETER *interpreter);
extern void hydroforth__add_word_to_word_definition(HYDROFORTH__WORD_DEFINITION *word_def, HYDROFORTH__WORD word);
extern void hydroforth__run_call_stack(HYDROFORTH__RESULT *const result, HYDROFORTH__INTERPRETER *interpreter);
extern void hydroforth__parse(HYDROFORTH__RESULT *result, HYDROFORTH__INTERPRETER *interpreter, HYDROFORTH__WORD_DEFINITION *word_def);
extern void hydroforth__run(HYDROFORTH__RESULT *const result, HYDROFORTH__INTERPRETER *interpreter);
extern void hydroforth__run_call_stack(HYDROFORTH__RESULT *result, HYDROFORTH__INTERPRETER *interpreter);
extern void hydroforth__run(HYDROFORTH__RESULT *result, HYDROFORTH__INTERPRETER *interpreter);
typedef struct __HYDROFORTH
{
__HYDROFORTH__RESULT result;
__HYDROFORTH__NUMBER number;
unsigned int (*hash_string)(const char *const key, unsigned char len);
unsigned (*hash_string)(const char *const key, unsigned char len);
bool (*is_space)(char c);
HYDROFORTH__SCAN_NEXT_WORD_RESULT(*scan_next_word)
(HYDROFORTH__INTERPRETER *interpreter);
void (*parse)(HYDROFORTH__RESULT *const result, HYDROFORTH__INTERPRETER *interpreter);
void (*run_call_stack)(HYDROFORTH__RESULT *const result, HYDROFORTH__INTERPRETER *interpreter);
void (*run)(HYDROFORTH__RESULT *const result, HYDROFORTH__INTERPRETER *interpreter);
void (*add_word_to_word_definition)(HYDROFORTH__WORD_DEFINITION *word_def, HYDROFORTH__WORD word);
void (*parse)(HYDROFORTH__RESULT *result, HYDROFORTH__INTERPRETER *interpreter, HYDROFORTH__WORD_DEFINITION *word_def);
void (*run_call_stack)(HYDROFORTH__RESULT *result, HYDROFORTH__INTERPRETER *interpreter);
void (*run)(HYDROFORTH__RESULT *result, HYDROFORTH__INTERPRETER *interpreter);
} __HYDROFORTH;
static const __HYDROFORTH hydroforth = {
@ -111,6 +115,7 @@ static const __HYDROFORTH hydroforth = {
.hash_string = hydroforth__hash_string,
.is_space = hydroforth__is_space,
.scan_next_word = hydroforth__scan_next_word,
.add_word_to_word_definition = hydroforth__add_word_to_word_definition,
.parse = hydroforth__parse,
.run_call_stack = hydroforth__run_call_stack,
.run = hydroforth__run,

View file

@ -12,6 +12,7 @@ typedef enum HYDROFORTH__RESULT__ERROR
ERR_UNKNOWN_WORD,
ERR_UNTERMINATED_WORD_DEFINITION,
ERR_WORD_NAME_CANT_BE_NUMBER,
ERR_WORD_DEF_INSIDE_WORD_DEF,
} HYDROFORTH__RESULT__ERROR;
typedef HYDROFORTH__RESULT__ERROR HYDROFORTH__ERROR;