DEADSOFTWARE

Добавлена конструкция FOR
[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;
33 };
35 enum oberon_type_kind
36 {
37 OBERON_TYPE_VOID,
38 OBERON_TYPE_INTEGER,
39 OBERON_TYPE_BOOLEAN,
40 OBERON_TYPE_PROCEDURE,
41 OBERON_TYPE_ARRAY,
42 OBERON_TYPE_RECORD,
43 OBERON_TYPE_POINTER,
44 OBERON_TYPE_REAL,
45 OBERON_TYPE_CHAR,
46 OBERON_TYPE_STRING
47 };
49 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
50 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
52 struct oberon_type_t
53 {
54 enum oberon_type_kind class;
55 int size;
57 int num_decl;
58 oberon_type_t * base;
59 oberon_object_t * decl;
60 oberon_scope_t * scope;
62 bool sysproc;
63 GenerateFuncCallback genfunc;
64 GenerateProcCallback genproc;
66 oberon_module_t * module;
68 int recursive;
69 int initialized;
70 gen_type_t * gen_type;
71 };
73 enum oberon_object_kind
74 {
75 OBERON_CLASS_VAR,
76 OBERON_CLASS_TYPE,
77 OBERON_CLASS_PROC,
78 OBERON_CLASS_PARAM,
79 OBERON_CLASS_VAR_PARAM,
80 OBERON_CLASS_CONST,
81 OBERON_CLASS_FIELD,
82 OBERON_CLASS_MODULE
83 };
85 struct oberon_object_t
86 {
87 char * name;
88 enum oberon_object_kind class;
89 int export;
90 int read_only;
92 int local;
93 int linked;
94 int initialized;
96 oberon_object_t * parent;
97 oberon_type_t * parent_type;
99 oberon_scope_t * scope; // for proc
100 int has_return; // for proc
102 oberon_type_t * type;
103 oberon_item_t * value;
104 oberon_object_t * next;
106 oberon_module_t * module;
108 gen_var_t * gen_var;
109 gen_proc_t * gen_proc;
110 };
112 struct oberon_module_t
114 char * name;
115 int ready;
117 oberon_scope_t * decl;
119 oberon_module_t * next;
121 gen_module_t * gen_mod;
122 };
124 typedef const char * (*ModuleImportCallback)(const char * name);
126 struct oberon_context_t
128 /*** SCANER DATA ***/
129 const char * code;
130 int code_index;
132 char c;
133 int token;
134 char * string;
135 int64_t integer;
136 double real;
137 bool longmode;
138 /*** END SCANER DATA ***/
140 /*** PARSER DATA ***/
141 oberon_scope_t * decl;
142 oberon_module_t * mod;
143 /*** END PARSER DATA ***/
145 oberon_type_t * void_type;
146 oberon_type_t * void_ptr_type;
147 oberon_type_t * bool_type;
148 oberon_type_t * byte_type;
149 oberon_type_t * shortint_type;
150 oberon_type_t * int_type;
151 oberon_type_t * longint_type;
152 oberon_type_t * real_type;
153 oberon_type_t * longreal_type;
154 oberon_type_t * char_type;
155 oberon_type_t * string_type;
157 oberon_scope_t * world_scope;
158 oberon_module_t * module_list;
159 ModuleImportCallback import_module;
160 gen_context_t * gen_context;
161 };
163 enum oberon_mode_kind
165 MODE_VAR,
166 MODE_INTEGER,
167 MODE_BOOLEAN,
168 MODE_CALL,
169 MODE_INDEX,
170 MODE_FIELD,
171 MODE_DEREF,
172 MODE_NIL,
173 MODE_NEW,
174 MODE_REAL,
175 MODE_CHAR,
176 MODE_STRING
177 };
179 enum oberon_operator_kind
181 OP_UNARY_MINUS,
182 OP_BITWISE_NOT,
183 OP_LOGIC_NOT,
184 OP_ABS,
186 OP_ADD,
187 OP_SUB,
188 OP_MUL,
189 OP_DIV,
190 OP_MOD,
191 OP_BITWISE_AND,
192 OP_BITWISE_XOR,
193 OP_BITWISE_OR,
194 OP_LOGIC_AND,
195 OP_LOGIC_OR,
197 OP_EQ,
198 OP_NEQ,
199 OP_LSS,
200 OP_LEQ,
201 OP_GRT,
202 OP_GEQ,
204 OP_CAST
205 };
207 struct oberon_item_t
209 bool is_item; // == 1
210 oberon_type_t * result;
211 oberon_expr_t * next;
212 bool read_only;
214 enum oberon_mode_kind mode;
215 long integer;
216 double real;
217 int boolean;
218 char * string;
219 oberon_object_t * var;
221 oberon_item_t * parent;
223 int num_args;
224 oberon_expr_t * args;
225 };
227 struct oberon_oper_t
229 bool is_item; // == 0
230 oberon_type_t * result;
231 oberon_expr_t * next;
232 bool read_only;
234 enum oberon_operator_kind op;
235 oberon_expr_t * left;
236 oberon_expr_t * right;
237 };
239 union oberon_expr_t
241 struct {
242 bool is_item;
243 oberon_type_t * result;
244 oberon_expr_t * next;
245 bool read_only;
246 };
248 oberon_item_t item;
249 oberon_oper_t oper;
250 };
252 #endif // OBERON_INTERNALS_H