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 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
48 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
50 struct oberon_type_t
51 {
52 int class;
53 int size;
55 int num_decl;
56 oberon_type_t * base;
57 oberon_object_t * decl;
58 oberon_scope_t * scope;
60 bool sysproc;
61 GenerateFuncCallback genfunc;
62 GenerateProcCallback genproc;
64 oberon_module_t * module;
66 int recursive;
67 int initialized;
68 gen_type_t * gen_type;
69 };
71 enum
72 {
73 OBERON_CLASS_VAR,
74 OBERON_CLASS_TYPE,
75 OBERON_CLASS_PROC,
76 OBERON_CLASS_PARAM,
77 OBERON_CLASS_VAR_PARAM,
78 OBERON_CLASS_CONST,
79 OBERON_CLASS_FIELD,
80 OBERON_CLASS_MODULE
81 };
83 struct oberon_object_t
84 {
85 char * name;
86 int class;
87 int export;
88 int read_only;
90 int local;
91 int linked;
92 int initialized;
94 oberon_object_t * parent;
95 oberon_type_t * parent_type;
97 oberon_scope_t * scope; // for proc
98 int has_return; // for proc
100 oberon_type_t * type;
101 oberon_item_t * value;
102 oberon_object_t * next;
104 oberon_module_t * module;
106 gen_var_t * gen_var;
107 gen_proc_t * gen_proc;
108 };
110 struct oberon_module_t
112 char * name;
113 int ready;
115 oberon_scope_t * decl;
117 oberon_module_t * next;
119 gen_module_t * gen_mod;
120 };
122 typedef const char * (*ModuleImportCallback)(const char * name);
124 struct oberon_context_t
126 /*** SCANER DATA ***/
127 const char * code;
128 int code_index;
130 char c;
131 int token;
132 char * string;
133 int64_t integer;
134 double real;
135 bool longmode;
136 /*** END SCANER DATA ***/
138 /*** PARSER DATA ***/
139 oberon_scope_t * decl;
140 oberon_module_t * mod;
141 /*** END PARSER DATA ***/
143 oberon_type_t * bool_type;
144 oberon_type_t * byte_type;
145 oberon_type_t * shortint_type;
146 oberon_type_t * int_type;
147 oberon_type_t * longint_type;
148 oberon_type_t * real_type;
149 oberon_type_t * longreal_type;
150 oberon_type_t * void_type;
151 oberon_type_t * void_ptr_type;
153 oberon_scope_t * world_scope;
154 oberon_module_t * module_list;
155 ModuleImportCallback import_module;
156 gen_context_t * gen_context;
157 };
159 enum
161 MODE_VAR,
162 MODE_INTEGER,
163 MODE_BOOLEAN,
164 MODE_CALL,
165 MODE_INDEX,
166 MODE_FIELD,
167 MODE_DEREF,
168 MODE_NIL,
169 MODE_NEW,
170 MODE_REAL,
171 };
173 enum
175 OP_UNARY_MINUS,
176 OP_BITWISE_NOT,
177 OP_LOGIC_NOT,
178 OP_ABS,
180 OP_ADD,
181 OP_SUB,
182 OP_MUL,
183 OP_DIV,
184 OP_MOD,
185 OP_BITWISE_AND,
186 OP_BITWISE_XOR,
187 OP_BITWISE_OR,
188 OP_LOGIC_AND,
189 OP_LOGIC_OR,
191 OP_EQ,
192 OP_NEQ,
193 OP_LSS,
194 OP_LEQ,
195 OP_GRT,
196 OP_GEQ,
198 OP_CAST
199 };
201 struct oberon_item_t
203 int is_item; // == 1
204 oberon_type_t * result;
205 oberon_expr_t * next;
206 int read_only;
208 int mode;
209 long integer;
210 double real;
211 int boolean;
212 oberon_object_t * var;
214 oberon_item_t * parent;
216 int num_args;
217 oberon_expr_t * args;
218 };
220 struct oberon_oper_t
222 int is_item; // == 0
223 oberon_type_t * result;
224 oberon_expr_t * next;
225 int read_only;
227 int op;
228 oberon_expr_t * left;
229 oberon_expr_t * right;
230 };
232 union oberon_expr_t
234 struct {
235 int is_item;
236 oberon_type_t * result;
237 oberon_expr_t * next;
238 int read_only;
239 };
241 oberon_item_t item;
242 oberon_oper_t oper;
243 };
245 #endif // OBERON_INTERNALS_H