]> gitweb.factorcode.org Git - factor.git/blob - native/run.h
75d6e7aea75656a46f4ce5af1df92d8aba572f63
[factor.git] / native / run.h
1 #define USER_ENV 16
2
3 #define STDIN_ENV     0
4 #define STDOUT_ENV    1
5 #define STDERR_ENV    2
6 #define NAMESTACK_ENV 3
7 #define GLOBAL_ENV    4
8 #define BREAK_ENV     5
9
10 /* Error handlers restore this */
11 jmp_buf toplevel;
12
13 typedef struct {
14         /* TAGGED top of datastack; EMPTY if datastack is empty */
15         CELL dt;
16         /* TAGGED currently executing quotation */
17         CELL cf;
18         /* TAGGED pointer to datastack bottom */
19         CELL ds_bot;
20         /* raw pointer to datastack top */
21         CELL ds;
22         /* TAGGED pointer to callstack bottom */
23         CELL cs_bot;
24         /* raw pointer to callstack top */
25         CELL cs;
26         /* raw pointer to currently executing word */
27         WORD* w;
28         /* TAGGED bootstrap quotation */
29         CELL boot;
30         /* TAGGED user environment data */
31         CELL user[USER_ENV];
32 } ENV;
33
34 ENV env;
35
36 void clear_environment(void);
37 void init_environment(void);
38 void check_non_empty(CELL cell);
39
40 INLINE CELL dpop(void)
41 {
42         env.ds -= CELLS;
43         return get(env.ds);
44 }
45
46 INLINE void dpush(CELL top)
47 {
48         put(env.ds,top);
49         env.ds += CELLS;
50 }
51
52 INLINE CELL dpeek(void)
53 {
54         return get(env.ds - CELLS);
55 }
56
57 INLINE CELL cpop(void)
58 {
59         env.cs -= CELLS;
60         return get(env.cs);
61 }
62
63 INLINE void cpush(CELL top)
64 {
65         put(env.cs,top);
66         env.cs += CELLS;
67 }
68
69 INLINE CELL cpeek(void)
70 {
71         return get(env.cs - CELLS);
72 }
73
74 void run(void);
75 void undefined(void);
76 void call(void);
77 void primitive_execute(void);
78 void primitive_call(void);
79 void primitive_ifte(void);
80 void primitive_getenv(void);
81 void primitive_setenv(void);
82 void primitive_exit(void);