DEADSOFTWARE

Исправлены выражения с операторами
[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_block_t gen_block_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
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 };
47 struct oberon_type_t
48 {
49 int class;
50 int size;
52 int num_decl;
53 oberon_type_t * base;
54 oberon_object_t * decl;
56 oberon_module_t * module;
58 int recursive;
59 int initialized;
60 gen_type_t * gen_type;
61 };
63 enum
64 {
65 OBERON_CLASS_VAR,
66 OBERON_CLASS_TYPE,
67 OBERON_CLASS_PROC,
68 OBERON_CLASS_PARAM,
69 OBERON_CLASS_VAR_PARAM,
70 OBERON_CLASS_CONST,
71 OBERON_CLASS_FIELD,
72 OBERON_CLASS_MODULE
73 };
75 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
76 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
78 struct oberon_object_t
79 {
80 char * name;
81 int class;
82 int export;
83 int read_only;
85 int local;
86 int linked;
87 int initialized;
89 oberon_object_t * parent;
90 oberon_type_t * parent_type;
92 oberon_scope_t * scope; // for proc
93 int has_return; // for proc
94 int sysproc;
95 GenerateFuncCallback genfunc;
96 GenerateProcCallback genproc;
98 oberon_type_t * type;
99 oberon_item_t * value;
100 oberon_object_t * next;
102 oberon_module_t * module;
104 gen_var_t * gen_var;
105 gen_proc_t * gen_proc;
106 };
108 struct oberon_module_t
110 char * name;
111 int ready;
113 oberon_scope_t * decl;
115 oberon_module_t * next;
117 gen_module_t * gen_mod;
118 };
120 typedef const char * (*ModuleImportCallback)(const char * name);
122 struct oberon_context_t
124 /*** SCANER DATA ***/
125 const char * code;
126 int code_index;
128 char c;
129 int token;
130 char * string;
131 int64_t integer;
132 double real;
133 bool longmode;
134 /*** END SCANER DATA ***/
136 /*** PARSER DATA ***/
137 oberon_scope_t * decl;
138 oberon_module_t * mod;
139 /*** END PARSER DATA ***/
141 oberon_type_t * bool_type;
142 oberon_type_t * byte_type;
143 oberon_type_t * shortint_type;
144 oberon_type_t * int_type;
145 oberon_type_t * longint_type;
146 oberon_type_t * real_type;
147 oberon_type_t * longreal_type;
148 oberon_type_t * void_type;
149 oberon_type_t * void_ptr_type;
151 oberon_scope_t * world_scope;
152 oberon_module_t * module_list;
153 ModuleImportCallback import_module;
154 gen_context_t * gen_context;
155 };
157 enum
159 MODE_VAR,
160 MODE_INTEGER,
161 MODE_BOOLEAN,
162 MODE_CALL,
163 MODE_INDEX,
164 MODE_FIELD,
165 MODE_DEREF,
166 MODE_NIL,
167 MODE_NEW,
168 MODE_REAL,
169 MODE_CAST
170 };
172 enum
174 OP_UNARY_MINUS,
175 OP_BITWISE_NOT,
176 OP_LOGIC_NOT,
177 OP_ABS,
179 OP_ADD,
180 OP_SUB,
181 OP_MUL,
182 OP_DIV,
183 OP_MOD,
184 OP_BITWISE_AND,
185 OP_BITWISE_XOR,
186 OP_BITWISE_OR,
187 OP_LOGIC_AND,
188 OP_LOGIC_OR,
190 OP_EQ,
191 OP_NEQ,
192 OP_LSS,
193 OP_LEQ,
194 OP_GRT,
195 OP_GEQ
196 };
198 struct oberon_item_t
200 int is_item; // == 1
201 oberon_type_t * result;
202 oberon_expr_t * next;
203 int read_only;
205 int mode;
206 long integer;
207 double real;
208 int boolean;
209 oberon_object_t * var;
211 oberon_expr_t * parent;
213 int num_args;
214 oberon_expr_t * args;
215 };
217 struct oberon_oper_t
219 int is_item; // == 0
220 oberon_type_t * result;
221 oberon_expr_t * next;
222 int read_only;
224 int op;
225 oberon_expr_t * left;
226 oberon_expr_t * right;
227 };
229 union oberon_expr_t
231 struct {
232 int is_item;
233 oberon_type_t * result;
234 oberon_expr_t * next;
235 int read_only;
236 };
238 oberon_item_t item;
239 oberon_oper_t oper;
240 };
242 #endif // OBERON_INTERNALS_H