60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
#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
|