This commit is contained in:
Dominic Grimm 2022-12-22 16:02:45 +01:00
parent 2a9968c4ce
commit d8cff2488a
No known key found for this signature in database
GPG key ID: 6F294212DEAAC530
7 changed files with 230 additions and 21 deletions

View file

@ -5,6 +5,8 @@
#include "number.h"
extern unsigned int hydroforth__hash_string(const char *const key, unsigned char length);
typedef enum HYDROFORTH__WORD_TYPE
{
PUSH,
@ -25,34 +27,69 @@ typedef struct HYDROFORTH__WORD
HYDROFORTH__WORD_DATA data;
} HYDROFORTH__WORD;
typedef struct HYDROFORTH__WORD_DEFINITION
{
HYDROFORTH__WORD *words;
} HYDROFORTH__WORD_DEFINITION;
typedef struct HYDROFORTH__WORD_DEFINITION_BASE_KEY
{
unsigned char word_definition_index;
} HYDROFORTH__WORD_DEFINITION_BASE_KEY;
typedef struct HYDROFORTH__WORD_DEFINITION_SINGLE_CHAR_WORD_KEY
{
char c;
HYDROFORTH__WORD_DEFINITION_BASE_KEY key;
} HYDROFORTH__WORD_DEFINITION_SINGLE_CHAR_WORD_KEY;
typedef struct HYDROFORTH__WORD_DEFINITION_WORD_KEY
{
unsigned int hash;
HYDROFORTH__WORD_DEFINITION_BASE_KEY key;
} HYDROFORTH__WORD_DEFINITION_WORD_KEY;
typedef struct HYDROFORTH__INTERPRETER
{
char *src;
unsigned long pos;
HYDROFORTH__WORD_DEFINITION_SINGLE_CHAR_WORD_KEY single_char_word_keys[32];
unsigned char single_char_word_keys_len;
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 call_stack[256];
unsigned char call_stack_len;
int stack[256];
unsigned char stack_len;
} HYDROFORTH__INTERPRETER;
extern bool hydroforth__step(HYDROFORTH__INTERPRETER *interpreter);
extern bool hydroforth__parse(HYDROFORTH__INTERPRETER *interpreter);
extern bool hydroforth__run_call_stack(HYDROFORTH__INTERPRETER *interpreter);
extern bool hydroforth__run(HYDROFORTH__INTERPRETER *interpreter);
typedef struct __HYDROFORTH
{
__HYDROFORTH__NUMBER number;
bool (*step)(HYDROFORTH__INTERPRETER *interpreter);
unsigned int (*hash_string)(const char *const key, unsigned char len);
bool (*parse)(HYDROFORTH__INTERPRETER *interpreter);
bool (*run_call_stack)(HYDROFORTH__INTERPRETER *interpreter);
bool (*run)(HYDROFORTH__INTERPRETER *interpreter);
} __HYDROFORTH;
static const __HYDROFORTH hydroforth = {
.number = {
.is_digit = hydroforth__number__is_digit,
.convert_hex_digit = hydroforth__number__convert_hex_digit,
.parse_number_hex = hydroforth__number__parse_number_hex,
.parse_number = hydroforth__number__parse_number,
.parse_number_with_sign = hydroforth__number__parse_number_with_sign,
},
.step = hydroforth__step,
.hash_string = hydroforth__hash_string,
.parse = hydroforth__parse,
.run_call_stack = hydroforth__run_call_stack,
.run = hydroforth__run,
};

View file

@ -5,15 +5,18 @@
extern bool hydroforth__number__is_digit(char c);
extern bool hydroforth__number__parse_number(const char *const start, unsigned char len, int *const val);
extern bool hydroforth__number__convert_hex_digit(char c, unsigned char *const val);
extern bool hydroforth__number__parse_number_with_sign(const char *const start, unsigned char len, int *const val);
extern bool hydroforth__number__parse_number_hex(const char *const start, unsigned char len, int *const val);
extern bool hydroforth__number__parse_number(const char *const start, unsigned char len, int *const val);
typedef struct __HYDROFORTH__NUMBER
{
bool (*is_digit)(char c);
bool (*convert_hex_digit)(char c, unsigned char *const val);
bool (*parse_number_hex)(const char *const start, unsigned char len, int *const val);
bool (*parse_number)(const char *const start, unsigned char len, int *const val);
bool (*parse_number_with_sign)(const char *const start, unsigned char len, int *const val);
} __HYDROFORTH__NUMBER;
#endif