DEADSOFTWARE

Исправлено присваивание NIL
[dsw-obn.git] / src / oberon-internals.h
1 #ifndef OBERON_INTERNALS_H
2 #define OBERON_INTERNALS_H
4 #include <stdint.h>
5 #include <stdbool.h>
7 typedef struct gen_module_t gen_module_t;
8 typedef struct gen_proc_t gen_proc_t;
9 typedef struct gen_type_t gen_type_t;
10 typedef struct gen_var_t gen_var_t;
11 typedef struct gen_label_t gen_label_t;
12 typedef struct gen_context_t gen_context_t;
14 typedef struct oberon_type_t oberon_type_t;
15 typedef struct oberon_object_t oberon_object_t;
16 typedef struct oberon_module_t oberon_module_t;
17 typedef struct oberon_context_t oberon_context_t;
18 typedef struct oberon_scope_t oberon_scope_t;
20 typedef struct oberon_item_t oberon_item_t;
21 typedef struct oberon_oper_t oberon_oper_t;
22 typedef union oberon_expr_t oberon_expr_t;
24 struct oberon_scope_t
25 {
26 oberon_context_t * ctx;
27 oberon_object_t * list;
28 oberon_scope_t * up;
30 int local;
31 oberon_object_t * parent;
32 oberon_type_t * parent_type;
34 gen_label_t * exit_label;
35 };
37 enum oberon_type_kind
38 {
39 OBERON_TYPE_NOTYPE,
40 OBERON_TYPE_INTEGER,
41 OBERON_TYPE_BOOLEAN,
42 OBERON_TYPE_PROCEDURE,
43 OBERON_TYPE_ARRAY,
44 OBERON_TYPE_RECORD,
45 OBERON_TYPE_POINTER,
46 OBERON_TYPE_REAL,
47 OBERON_TYPE_CHAR,
48 OBERON_TYPE_STRING,
49 OBERON_TYPE_SET,
50 OBERON_TYPE_NIL
51 };
53 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
54 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
56 struct oberon_type_t
57 {
58 enum oberon_type_kind class;
59 int size;
61 int num_decl;
62 oberon_type_t * base;
63 oberon_object_t * decl;
64 oberon_scope_t * scope;
66 bool sysproc;
67 GenerateFuncCallback genfunc;
68 GenerateProcCallback genproc;
70 oberon_module_t * module;
72 int recursive;
73 int initialized;
74 gen_type_t * gen_type;
75 };
77 enum oberon_object_kind
78 {
79 OBERON_CLASS_VAR,
80 OBERON_CLASS_TYPE,
81 OBERON_CLASS_PROC,
82 OBERON_CLASS_PARAM,
83 OBERON_CLASS_VAR_PARAM,
84 OBERON_CLASS_CONST,
85 OBERON_CLASS_FIELD,
86 OBERON_CLASS_MODULE
87 };
89 struct oberon_object_t
90 {
91 char * name;
92 enum oberon_object_kind class;
93 int export;
94 int read_only;
96 int local;
97 int linked;
98 int initialized;
100 oberon_object_t * parent;
101 oberon_type_t * parent_type;
103 oberon_scope_t * scope; // for proc
104 int has_return; // for proc
106 oberon_type_t * type;
107 oberon_item_t * value;
108 oberon_object_t * next;
110 oberon_module_t * module;
112 gen_var_t * gen_var;
113 gen_proc_t * gen_proc;
114 };
116 struct oberon_module_t
118 char * name;
119 int ready;
121 oberon_scope_t * decl;
123 oberon_module_t * next;
125 gen_module_t * gen_mod;
126 };
128 typedef const char * (*ModuleImportCallback)(const char * name);
130 struct oberon_context_t
132 /*** SCANER DATA ***/
133 const char * code;
134 int code_index;
136 char c;
137 int token;
138 char * string;
139 int64_t integer;
140 double real;
141 bool longmode;
142 /*** END SCANER DATA ***/
144 /*** PARSER DATA ***/
145 oberon_scope_t * decl;
146 oberon_module_t * mod;
147 /*** END PARSER DATA ***/
149 oberon_type_t * notype_type;
150 oberon_type_t * nil_type;
151 oberon_type_t * bool_type;
152 oberon_type_t * byte_type;
153 oberon_type_t * shortint_type;
154 oberon_type_t * int_type;
155 oberon_type_t * longint_type;
156 oberon_type_t * real_type;
157 oberon_type_t * longreal_type;
158 oberon_type_t * char_type;
159 oberon_type_t * string_type;
160 oberon_type_t * set_type;
162 oberon_scope_t * world_scope;
163 oberon_module_t * module_list;
164 ModuleImportCallback import_module;
165 gen_context_t * gen_context;
166 };
168 enum oberon_mode_kind
170 MODE_VAR,
171 MODE_INTEGER,
172 MODE_BOOLEAN,
173 MODE_CALL,
174 MODE_INDEX,
175 MODE_FIELD,
176 MODE_DEREF,
177 MODE_NIL,
178 MODE_NEW,
179 MODE_REAL,
180 MODE_CHAR,
181 MODE_STRING,
182 MODE_TYPE,
183 MODE_SET
184 };
186 enum oberon_operator_kind
188 OP_UNARY_MINUS,
189 OP_LOGIC_NOT,
190 OP_ABS,
192 OP_ADD,
193 OP_SUB,
194 OP_MUL,
195 OP_DIV,
196 OP_MOD,
197 OP_LOGIC_AND,
198 OP_LOGIC_OR,
200 OP_EQ,
201 OP_NEQ,
202 OP_LSS,
203 OP_LEQ,
204 OP_GRT,
205 OP_GEQ,
207 OP_CAST,
208 OP_IS,
210 OP_RANGE,
211 OP_UNION,
212 OP_INTERSECTION,
213 OP_DIFFERENCE,
214 OP_SYM_DIFFERENCE,
215 OP_COMPLEMENTATION,
216 OP_IN
217 };
219 struct oberon_item_t
221 bool is_item; // == 1
222 oberon_type_t * result;
223 oberon_expr_t * next;
224 bool read_only;
226 enum oberon_mode_kind mode;
227 long integer;
228 double real;
229 char * string;
230 oberon_object_t * var;
232 oberon_item_t * parent;
234 int num_args;
235 oberon_expr_t * args;
236 };
238 struct oberon_oper_t
240 bool is_item; // == 0
241 oberon_type_t * result;
242 oberon_expr_t * next;
243 bool read_only;
245 enum oberon_operator_kind op;
246 oberon_expr_t * left;
247 oberon_expr_t * right;
248 };
250 union oberon_expr_t
252 struct {
253 bool is_item;
254 oberon_type_t * result;
255 oberon_expr_t * next;
256 bool read_only;
257 };
259 oberon_item_t item;
260 oberon_oper_t oper;
261 };
263 #endif // OBERON_INTERNALS_H