-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.h
More file actions
80 lines (56 loc) · 1.93 KB
/
script.h
File metadata and controls
80 lines (56 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef __SCRIPT_H__
#define __SCRIPT_H__
#include <stdint.h>
#include <stddef.h>
#define SCRIPT_MAX_WORD_LEN 32
#define SCRIPT_STACK_DEPTH 16
#define SCRIPT_TRUE ((script_cell_t)-1)
#define SCRIPT_FALSE ((script_cell_t)0)
#define SCRIPT_FLAG_IMMEDIATE (1 << 0)
#if __SIZEOF_POINTER__ == 4
typedef uint32_t script_cell_t;
typedef uint64_t script_double_cell_t;
#elif __SIZEOF_POINTER__ == 8
typedef uint64_t script_cell_t;
typedef unsigned __int128 script_double_cell_t;
#else
#error Unable to determine script cell size.
#endif
typedef script_cell_t * script_wordlist_t;
struct _script_state;
typedef void (*script_word_t)(struct _script_state *);
struct _script_state {
script_cell_t *ip;
// Current XT
script_cell_t w;
script_cell_t sp0[SCRIPT_STACK_DEPTH];
script_cell_t *sp;
script_cell_t *rp0[SCRIPT_STACK_DEPTH];
script_cell_t **rp;
const char *tib;
size_t tibpos;
size_t tiblen;
script_word_t accept;
script_word_t type;
script_cell_t base;
script_cell_t compiling;
uint8_t pad[sizeof(script_cell_t) * 8];
uint8_t *dp;
uint8_t *latest;
script_wordlist_t *current;
script_cell_t norder;
script_wordlist_t *context[16];
} __attribute__((packed));
typedef struct _script_state script_state_t;
int script_state_init(script_state_t *state);
void script_push(script_state_t *state, script_cell_t v);
script_cell_t script_pop(script_state_t *state);
script_word_t script_word_lookup(script_state_t *state, const char *s);
int script_word_ingest(script_state_t *state, const char *s);
int script_eval_str(script_state_t *state, const char *s);
int script_eval_buf(script_state_t *state, const char *s, size_t len);
void script_next(script_state_t *state);
#define SCRIPT_CODE_WORD(x) void script_word_ ## x (script_state_t *state)
#define SCRIPT_CELL_ALIGN(v) (((size_t)(v) % sizeof(script_cell_t)) ? ((v) + (sizeof(script_cell_t) - ((size_t)(v) % sizeof(script_cell_t)))) : (v))
SCRIPT_CODE_WORD(quit);
#endif /* __SCRIPT_H__ */