Init
This commit is contained in:
commit
2a9968c4ce
8 changed files with 302 additions and 0 deletions
59
include/hydroforth/hydroforth.h
Normal file
59
include/hydroforth/hydroforth.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
#ifndef __HYDROFORTH_H__
|
||||
#define __HYDROFORTH_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "number.h"
|
||||
|
||||
typedef enum HYDROFORTH__WORD_TYPE
|
||||
{
|
||||
PUSH,
|
||||
CHAR_WORD,
|
||||
WORD,
|
||||
} HYDROFORTH__WORD_TYPE;
|
||||
|
||||
typedef union HYDROFORTH__WORD_DATA
|
||||
{
|
||||
int number;
|
||||
char char_word;
|
||||
char *word;
|
||||
} HYDROFORTH__WORD_DATA;
|
||||
|
||||
typedef struct HYDROFORTH__WORD
|
||||
{
|
||||
HYDROFORTH__WORD_TYPE type;
|
||||
HYDROFORTH__WORD_DATA data;
|
||||
} HYDROFORTH__WORD;
|
||||
|
||||
typedef struct HYDROFORTH__INTERPRETER
|
||||
{
|
||||
char *src;
|
||||
unsigned long pos;
|
||||
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__run(HYDROFORTH__INTERPRETER *interpreter);
|
||||
|
||||
typedef struct __HYDROFORTH
|
||||
{
|
||||
__HYDROFORTH__NUMBER number;
|
||||
bool (*step)(HYDROFORTH__INTERPRETER *interpreter);
|
||||
bool (*run)(HYDROFORTH__INTERPRETER *interpreter);
|
||||
} __HYDROFORTH;
|
||||
|
||||
static const __HYDROFORTH hydroforth = {
|
||||
.number = {
|
||||
.is_digit = hydroforth__number__is_digit,
|
||||
.parse_number = hydroforth__number__parse_number,
|
||||
.parse_number_with_sign = hydroforth__number__parse_number_with_sign,
|
||||
},
|
||||
.step = hydroforth__step,
|
||||
.run = hydroforth__run,
|
||||
};
|
||||
|
||||
#endif
|
19
include/hydroforth/number.h
Normal file
19
include/hydroforth/number.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#ifndef __HYDROFORTH__NUMBER_H__
|
||||
#define __HYDROFORTH__NUMBER_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
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__parse_number_with_sign(const char *const start, unsigned char len, int *const val);
|
||||
|
||||
typedef struct __HYDROFORTH__NUMBER
|
||||
{
|
||||
bool (*is_digit)(char c);
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue