DEADSOFTWARE

7a776d695502bec8b53225c031e31f808d207841
[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_VOID,
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 };
51 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
52 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
54 struct oberon_type_t
55 {
56 enum oberon_type_kind class;
57 int size;
59 int num_decl;
60 oberon_type_t * base;
61 oberon_object_t * decl;
62 oberon_scope_t * scope;
64 bool sysproc;
65 GenerateFuncCallback genfunc;
66 GenerateProcCallback genproc;
68 oberon_module_t * module;
70 int recursive;
71 int initialized;
72 gen_type_t * gen_type;
73 };
75 enum oberon_object_kind
76 {
77 OBERON_CLASS_VAR,
78 OBERON_CLASS_TYPE,
79 OBERON_CLASS_PROC,
80 OBERON_CLASS_PARAM,
81 OBERON_CLASS_VAR_PARAM,
82 OBERON_CLASS_CONST,
83 OBERON_CLASS_FIELD,
84 OBERON_CLASS_MODULE
85 };
87 struct oberon_object_t
88 {
89 char * name;
90 enum oberon_object_kind class;
91 int export;
92 int read_only;
94 int local;
95 int linked;
96 int initialized;
98 oberon_object_t * parent;
99 oberon_type_t * parent_type;
101 oberon_scope_t * scope; // for proc
102 int has_return; // for proc
104 oberon_type_t * type;
105 oberon_item_t * value;
106 oberon_object_t * next;
108 oberon_module_t * module;
110 gen_var_t * gen_var;
111 gen_proc_t * gen_proc;
112 };
114 struct oberon_module_t
116 char * name;
117 int ready;
119 oberon_scope_t * decl;
121 oberon_module_t * next;
123 gen_module_t * gen_mod;
124 };
126 typedef const char * (*ModuleImportCallback)(const char * name);
128 struct oberon_context_t
130 /*** SCANER DATA ***/
131 const char * code;
132 int code_index;
134 char c;
135 int token;
136 char * string;
137 int64_t integer;
138 double real;
139 bool longmode;
140 /*** END SCANER DATA ***/
142 /*** PARSER DATA ***/
143 oberon_scope_t * decl;
144 oberon_module_t * mod;
145 /*** END PARSER DATA ***/
147 oberon_type_t * void_type;
148 oberon_type_t * void_ptr_type;
149 oberon_type_t * bool_type;
150 oberon_type_t * byte_type;
151 oberon_type_t * shortint_type;
152 oberon_type_t * int_type;
153 oberon_type_t * longint_type;
154 oberon_type_t * real_type;
155 oberon_type_t * longreal_type;
156 oberon_type_t * char_type;
157 oberon_type_t * string_type;
159 oberon_scope_t * world_scope;
160 oberon_module_t * module_list;
161 ModuleImportCallback import_module;
162 gen_context_t * gen_context;
163 };
165 enum oberon_mode_kind
167 MODE_VAR,
168 MODE_INTEGER,
169 MODE_BOOLEAN,
170 MODE_CALL,
171 MODE_INDEX,
172 MODE_FIELD,
173 MODE_DEREF,
174 MODE_NIL,
175 MODE_NEW,
176 MODE_REAL,
177 MODE_CHAR,
178 MODE_STRING
179 };
181 enum oberon_operator_kind
183 OP_UNARY_MINUS,
184 OP_BITWISE_NOT,
185 OP_LOGIC_NOT,
186 OP_ABS,
188 OP_ADD,
189 OP_SUB,
190 OP_MUL,
191 OP_DIV,
192 OP_MOD,
193 OP_BITWISE_AND,
194 OP_BITWISE_XOR,
195 OP_BITWISE_OR,
196 OP_LOGIC_AND,
197 OP_LOGIC_OR,
199 OP_EQ,
200 OP_NEQ,
201 OP_LSS,
202 OP_LEQ,
203 OP_GRT,
204 OP_GEQ,
206 OP_CAST
207 };
209 struct oberon_item_t
211 bool is_item; // == 1
212 oberon_type_t * result;
213 oberon_expr_t * next;
214 bool read_only;
216 enum oberon_mode_kind mode;
217 long integer;
218 double real;
219 int boolean;
220 char * string;
221 oberon_object_t * var;
223 oberon_item_t * parent;
225 int num_args;
226 oberon_expr_t * args;
227 };
229 struct oberon_oper_t
231 bool is_item; // == 0
232 oberon_type_t * result;
233 oberon_expr_t * next;
234 bool read_only;
236 enum oberon_operator_kind op;
237 oberon_expr_t * left;
238 oberon_expr_t * right;
239 };
241 union oberon_expr_t
243 struct {
244 bool is_item;
245 oberon_type_t * result;
246 oberon_expr_t * next;
247 bool read_only;
248 };
250 oberon_item_t item;
251 oberon_oper_t oper;
252 };
254 #endif // OBERON_INTERNALS_H