Go to the documentation of this file.
12 #define CASE_SENSITIVE 0
24 #define OP(name) op##name
37 #define DEBUG(s,v) printf(s, v)
38 #define SHOWOP(op) printf("\n%04x: _%s\t", PC, op)
47 _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
48 _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
49 _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
50 _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
51 _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
52 _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
53 _61, _62, _63, N, ...) N
56 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
57 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
58 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
59 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
60 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
61 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
62 #define _NARG0(...) _ARG_N(__VA_ARGS__)
63 #define _NARG(...) _NARG0(_, ##__VA_ARGS__, _NUM_N())
68 #define _CODE(seg, ...) _code(seg, _NARG(__VA_ARGS__), __VA_ARGS__)
69 #define _PRIM(seg, x) (_CODE(seg, op##x, opEXIT), op##x)
70 #define _COLON(seg, ...) _colon(seg, _NARG(__VA_ARGS__), __VA_ARGS__)
71 #define _IMMED(seg, ...) _immed(seg, _NARG(__VA_ARGS__), __VA_ARGS__)
72 #define _LABEL(...) _label(_NARG(__VA_ARGS__), __VA_ARGS__)
73 #define _BEGIN(...) _begin(_NARG(__VA_ARGS__), __VA_ARGS__)
77 #define _AGAIN(...) _again(_NARG(__VA_ARGS__), __VA_ARGS__)
78 #define _UNTIL(...) _until(_NARG(__VA_ARGS__), __VA_ARGS__)
79 #define _WHILE(...) _while(_NARG(__VA_ARGS__), __VA_ARGS__)
80 #define _REPEAT(...) _repeat(_NARG(__VA_ARGS__), __VA_ARGS__)
81 #define _IF(...) _if(_NARG(__VA_ARGS__), __VA_ARGS__)
82 #define _ELSE(...) _else(_NARG(__VA_ARGS__), __VA_ARGS__)
83 #define _THEN(...) _then(_NARG(__VA_ARGS__), __VA_ARGS__)
84 #define _FOR(...) _for(_NARG(__VA_ARGS__), __VA_ARGS__)
85 #define _NEXT(...) _nxt(_NARG(__VA_ARGS__), __VA_ARGS__)
86 #define _AFT(...) _aft(_NARG(__VA_ARGS__), __VA_ARGS__)
87 #define _DOTQ(str) _dotq(str)
91 #define BSET(d, c) (_byte[d]=(U8)(c))
95 #define BGET(d) (_byte[d])
96 #define SET(d, v) do { U16 a=(d); U16 x=(v); BSET(a,(x)>>8); BSET((a)+1,(x)&0xff); } while (0)
97 #define GET(d) ({ U16 a=(d); ((U16)BGET(a)<<8) | BGET((a)+1); })
98 #define STORE(v) do { SET(PC,(v)); PC+=CELLSZ; } while(0)
99 #define RPUSH(a) SET(FORTH_ROM_SZ - (++R)*CELLSZ, (a))
100 #define RPOP() ((U16)GET(FORTH_ROM_SZ - (R ? R-- : R)*CELLSZ))
101 #define VL(a, i) (((U16)(a)+CELLSZ*(i))&0xff)
102 #define VH(a, i) (((U16)(a)+CELLSZ*(i))>>8)
103 #define VAL(a, i) opDOLIT,VH(a,i),VL(a,i),opEXIT
104 #define CELLCPY(n) { \
109 va_start(argList, n); \
112 IU j = (IU)va_arg(argList, int); \
120 lit = (j==opDOLIT); \
135 #define MEMCPY(len, seq) { \
136 memcpy(&_byte[PC], seq, len); \
140 #define OPSTR(ip, seq) { \
141 SET(PC, ip | fCOLON); \
143 int len = strlen(seq); \
155 void _dump(
int b,
int u) {
166 for (
int i=b; i<u; i+=
sizeof(
IU)) {
167 if ((i+1)<u)
DEBUG(
" %04x",
GET(i));
174 for (
int i=1; i<=
R; i++) {
191 int len = lex & 0x1f;
200 int _code(
const char *seg,
int len, ...) {
204 va_start(argList, len);
206 U8 b = (
U8)va_arg(argList,
int);
216 int _colon(
const char *seg,
int len, ...) {
218 DEBUG(
" %s",
":_COLON");
227 int _immed(
const char *seg,
int len, ...) {
334 #endif // __EFORTH_ASM_H
#define RPUSH(a)
Definition: eforth_asm.h:99
#define DEBUG(s, v)
Definition: eforth_asm.h:40
@ OPCODES
Definition: eforth_asm.h:31
#define FORTH_ROM_SZ
Definition: eforth_config.h:38
#define fIMMD
Definition: eforth_asm.h:23
void _while(int len,...)
Definition: eforth_asm.h:253
int _colon(const char *seg, int len,...)
Definition: eforth_asm.h:216
#define GET(d)
Definition: eforth_asm.h:97
int _immed(const char *seg, int len,...)
Definition: eforth_asm.h:227
#define BSET(d, c)
Definition: eforth_asm.h:94
void _header(int lex, const char *seq)
Definition: eforth_asm.h:182
@ opNOP
opcodes start at 0
Definition: eforth_asm.h:30
int _label(int len,...)
Definition: eforth_asm.h:238
#define RPOP()
Definition: eforth_asm.h:100
void _for(int len,...)
Definition: eforth_asm.h:281
void _again(int len,...)
Definition: eforth_asm.h:275
IU _link
link to previous word
Definition: eforth_asm.c:17
eForth configurations and opcode list
void _then(int len,...)
Definition: eforth_asm.h:320
void _repeat(int len,...)
Definition: eforth_asm.h:262
#define SET(d, v)
Definition: eforth_asm.h:96
#define OPSTR(ip, seq)
Definition: eforth_asm.h:140
void _dump(int b, int u)
Definition: eforth_asm.h:164
void _else(int len,...)
Definition: eforth_asm.h:312
IU DOTQP
addr of output ops, used by _dotq, _strq, _abortq
Definition: eforth_asm.c:21
void _until(int len,...)
Definition: eforth_asm.h:269
void _begin(int len,...)
Definition: eforth_asm.h:248
U8 R
assembler return stack index
Definition: eforth_asm.c:15
#define CELLSZ
Definition: eforth_config.h:36
void _aft(int len,...)
Definition: eforth_asm.h:287
#define STORE(v)
Definition: eforth_asm.h:98
void _rdump()
dump return stack
Definition: eforth_asm.h:171
void _if(int len,...)
Definition: eforth_asm.h:305
U16 IU
instruction/address unit (16-bit)
Definition: eforth_config.h:28
#define CELLCPY(n)
Definition: eforth_asm.h:107
#define MEMCPY(len, seq)
Definition: eforth_asm.h:135
#define BGET(d)
Definition: eforth_asm.h:95
void _dotq(const char *seq)
Definition: eforth_asm.h:328
int _code(const char *seg, int len,...)
Definition: eforth_asm.h:200
void _nxt(int len,...)
Note: _next() is multi-defined in vm
Definition: eforth_asm.h:299
uint8_t U8
8-bit unsigned integer
Definition: eforth_config.h:22
IU PC
assembler program counter
Definition: eforth_asm.c:14
#define SHOWOP(op)
Definition: eforth_asm.h:41
U8 * _byte
assembler byte array (heap)
Definition: eforth_asm.c:16