Git init
[external/mawk.git] / code.h
1
2 /********************************************
3 code.h
4 copyright 1991, Michael D. Brennan
5
6 This is a source file for mawk, an implementation of
7 the AWK programming language.
8
9 Mawk is distributed without warranty under the terms of
10 the GNU General Public License, version 2, 1991.
11 ********************************************/
12
13
14 /* $Log: code.h,v $
15  * Revision 1.5  1995/06/18  19:42:15  mike
16  * Remove some redundant declarations and add some prototypes
17  *
18  * Revision 1.4  1994/12/13  00:13:01  mike
19  * delete A statement to delete all of A at once
20  *
21  * Revision 1.3  1993/12/01  14:25:06  mike
22  * reentrant array loops
23  *
24  * Revision 1.2  1993/07/22  00:04:01  mike
25  * new op code _LJZ _LJNZ
26  *
27  * Revision 1.1.1.1  1993/07/03  18:58:10  mike
28  * move source to cvs
29  *
30  * Revision 5.3  1993/01/14  13:11:11  mike
31  * code2() -> xcode2()
32  *
33  * Revision 5.2  1993/01/07  02:50:33  mike
34  * relative vs absolute code
35  *
36  * Revision 5.1  1991/12/05  07:59:07  brennan
37  * 1.1 pre-release
38  *
39 */
40
41
42 /*  code.h  */
43
44 #ifndef  CODE_H
45 #define  CODE_H
46
47 #include "memory.h"
48
49 #define  PAGESZ 512
50         /* number of code instructions allocated at one time */
51 #define  CODEWARN        16
52
53 /* coding scope */
54 #define   SCOPE_MAIN    0
55 #define   SCOPE_BEGIN   1  
56 #define   SCOPE_END     2
57 #define   SCOPE_FUNCT   3
58
59
60 typedef struct {
61 INST *base, *limit, *warn, *ptr ;
62 } CODEBLOCK ;
63
64 extern CODEBLOCK active_code ;
65 extern CODEBLOCK *main_code_p, *begin_code_p, *end_code_p ;
66
67 extern INST *main_start, *begin_start, *end_start  ;
68 extern unsigned main_size, begin_size  ;
69 extern INST *execution_start ;
70 extern INST *next_label ;  /* next statements jump to here */
71 extern int dump_code_flag ;
72
73 #define code_ptr  active_code.ptr
74 #define code_base active_code.base
75 #define code_warn active_code.warn
76 #define code_limit active_code.limit
77 #define code_offset (code_ptr-code_base)
78
79 #define INST_BYTES(x) (sizeof(INST)*(unsigned)(x))
80
81 extern  CELL  eval_stack[] ;
82 extern int exit_code ;
83
84
85 #define  code1(x)  code_ptr++ -> op = (x)
86 /* shutup picky compilers */
87 #define  code2(x,p)  xcode2(x,(PTR)(p))
88
89 void  PROTO(xcode2, (int, PTR)) ;
90 void  PROTO(code2op, (int, int)) ;
91 INST *PROTO(code_shrink, (CODEBLOCK*, unsigned*)) ;
92 void  PROTO(code_grow, (void)) ;
93 void  PROTO(set_code, (void)) ;
94 void  PROTO(be_setup, (int)) ;
95 void  PROTO(dump_code, (void)) ;
96
97
98 /*  the machine opcodes  */
99 /* to avoid confusion with a ptr FE_PUSHA must have op code 0 */
100 /* unfortunately enums are less portable than defines */
101
102 #define FE_PUSHA       0
103 #define FE_PUSHI       1
104 #define F_PUSHA        2
105 #define F_PUSHI        3
106 #define NF_PUSHI       4
107 #define _HALT          5
108 #define _STOP          6
109 #define _PUSHC         7
110 #define _PUSHD         8
111 #define _PUSHS         9
112 #define _PUSHINT       10
113 #define _PUSHA         11
114 #define _PUSHI         12
115 #define L_PUSHA        13
116 #define L_PUSHI        14
117 #define AE_PUSHA       15
118 #define AE_PUSHI       16
119 #define A_PUSHA        17
120 #define LAE_PUSHA      18
121 #define LAE_PUSHI      19
122 #define LA_PUSHA       20
123 #define _POP           21
124 #define _ADD           22
125 #define _SUB           23
126 #define _MUL           24
127 #define _DIV           25
128 #define _MOD           26
129 #define _POW           27
130 #define _NOT           28
131 #define _TEST          29
132 #define A_TEST         30
133 #define A_DEL          31
134 #define ALOOP          32
135 #define A_CAT          33
136 #define _UMINUS        34
137 #define _UPLUS         35
138 #define _ASSIGN        36
139 #define _ADD_ASG       37
140 #define _SUB_ASG       38
141 #define _MUL_ASG       39
142 #define _DIV_ASG       40
143 #define _MOD_ASG       41
144 #define _POW_ASG       42
145 #define F_ASSIGN       43
146 #define F_ADD_ASG      44
147 #define F_SUB_ASG      45
148 #define F_MUL_ASG      46
149 #define F_DIV_ASG      47
150 #define F_MOD_ASG      48
151 #define F_POW_ASG      49
152 #define _CAT           50
153 #define _BUILTIN       51
154 #define _PRINT         52
155 #define _POST_INC      53
156 #define _POST_DEC      54
157 #define _PRE_INC       55
158 #define _PRE_DEC       56
159 #define F_POST_INC     57
160 #define F_POST_DEC     58
161 #define F_PRE_INC      59
162 #define F_PRE_DEC      60
163 #define _JMP           61
164 #define _JNZ           62
165 #define _JZ            63
166 #define _LJZ           64
167 #define _LJNZ          65
168 #define _EQ            66
169 #define _NEQ           67
170 #define _LT            68
171 #define _LTE           69
172 #define _GT            70
173 #define _GTE           71
174 #define _MATCH0        72
175 #define _MATCH1        73
176 #define _MATCH2        74
177 #define _EXIT          75
178 #define _EXIT0         76
179 #define _NEXT          77
180 #define _RANGE         78
181 #define _CALL          79
182 #define _RET           80
183 #define _RET0          81
184 #define SET_ALOOP      82
185 #define POP_AL         83
186 #define OL_GL          84
187 #define OL_GL_NR       85
188 #define _OMAIN         86
189 #define _JMAIN         87
190 #define DEL_A          88       
191
192 #endif  /* CODE_H */