diff options
Diffstat (limited to 'foci.h')
-rw-r--r-- | foci.h | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -0,0 +1,62 @@ +#ifndef FOCI_H +#define FOCI_H + +#include <stdint.h> + +#define NAKED __attribute__((naked)) + +#define ATTR_NATIVE (1 << 7) +#define ATTR_IMMEDIATE (1 << 6) +#define ATTR_LEN (0x3F) + +#define WORD(name, tname, prev, attr) \ + extern const void *name##_body[]; \ + struct word_t w_##name = { \ + name##_body, prev, attr + sizeof(tname) - 1, tname \ + }; \ + const void *name##_body[] = { +#define LIT(x) push, (void *)(x) +#define FTH(w) enter, (w##_body) +#define END fexit, }; +#define NATIVE(name, tname, prev, attr) \ + extern const void *name##_body[]; \ + NAKED void name(void); \ + struct word_t w_##name = { \ + name##_body, prev, \ + (attr | ATTR_NATIVE) + sizeof(tname) - 1, tname \ + }; \ + const void *name##_body[] = { name, fexit }; \ + NAKED void name(void) + +#define W(name, tname, prev) WORD(name, tname, prev, 0) +#define I(name, tname, prev) WORD(name, tname, prev, ATTR_IMMEDIATE) +#define N(name, tname, prev) NATIVE(name, tname, prev, 0) +#define C(name, tname, prev) NATIVE(name, tname, prev, ATTR_IMMEDIATE) + +#define STASH asm("push %r12; push %r13; push %r14; push %r15") +#define RESTORE asm("pop %r15; pop %r14; pop %r13; pop %r12") +#define NEXT { goto *(*++pp); } + +struct word_t +{ + const void **body; + struct word_t *prev; + unsigned char attr; + char name[]; +} __attribute__ ((packed)); + +register intptr_t tmp asm("r12"); +register intptr_t * sp asm("r13"); // pointer to stack cells +register intptr_t *** rp asm("r14"); // stack of pp +register intptr_t ** pp asm("r15"); // pointer to ip + +void init(void); +int depth(void); +int compiling(void); +void parse_word(const char *buf, const char *s); +void define(struct word_t *w); + +void fexit(void); // internal use only + +#endif // FOCI_H + |