creole/creole.h

83 lines
1.5 KiB
C
Raw Normal View History

2023-02-05 06:44:37 -05:00
#ifndef CREOLE_H
#define CREOLE_H
#include <limits.h>
2023-02-07 00:25:30 -05:00
#include <stddef.h>
2023-02-05 06:44:37 -05:00
#ifndef CREOLE_WORD
# define CREOLE_WORD unsigned int
# define CREOLE_WORD_MAX UINT_MAX
#endif
#define CREOLE_MAX_ARG 3
typedef CREOLE_WORD creole_word;
enum creole_opcode {
CREOLE_NOOP = 0,
CREOLE_PUSH = 1,
CREOLE_POP = 2,
CREOLE_ADD = 3,
CREOLE_MUL = 4,
CREOLE_DIV = 5,
CREOLE_JL = 6,
CREOLE_CLB = 7,
CREOLE_SYS = 8,
CREOLE_OPCODE_LEN
};
enum creole_word_flag {
CREOLE_IMMEDIATE,
CREOLE_REGISTER,
CREOLE_WORD_FLAGS_LEN
};
enum creole_compiler_ret {
CREOLE_COMPILE_OK,
2023-02-07 23:15:54 -05:00
CREOLE_OPCODE_READ_ERROR,
CREOLE_OPCODE_MALFORMED,
CREOLE_ARG_READ_ERROR,
CREOLE_ARG_MALFORMED,
CREOLE_LAST_READ_ERROR,
CREOLE_LAST_MALFORMED,
2023-02-05 06:44:37 -05:00
CREOLE_LABEL_OVERFLOW,
CREOLE_TYPE_ERROR,
2023-02-09 11:16:41 -05:00
CREOLE_COMPILE_CLEARED_INSTRUCTION,
CREOLE_PROGRAM_OVERFLOW,
2023-02-05 06:44:37 -05:00
CREOLE_COMPILE_RET_LEN
};
struct creole_ins {
enum creole_opcode opcode;
unsigned char w_flags[3];
creole_word w[3];
};
struct creole_env {
creole_word *reg;
size_t reglen;
size_t *lab;
size_t lablen;
creole_word *stk;
size_t stkptr, stklen;
struct creole_ins *prg;
size_t prgptr, prgend, prglen;
};
struct creole_reader {
unsigned char *p;
size_t left;
};
2023-02-07 23:15:54 -05:00
int creole_encode(creole_word i, unsigned encode_to, unsigned high_bits,
unsigned char buf[7]);
enum creole_compiler_ret
creole_parse_line(struct creole_ins *ins, struct creole_reader *r);
2023-02-09 11:16:41 -05:00
enum creole_compiler_ret
creole_compile(struct creole_env *env, struct creole_reader *r);
2023-02-07 23:15:54 -05:00
2023-02-05 06:44:37 -05:00
#endif /* CREOLE_H */