DEADSOFTWARE

c154d0127093d265ed6c970614f21549f9a0f557
[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 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 };
48 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
49 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
51 struct oberon_type_t
52 {
53 enum oberon_type_kind class;
54 int size;
56 int num_decl;
57 oberon_type_t * base;
58 oberon_object_t * decl;
59 oberon_scope_t * scope;
61 bool sysproc;
62 GenerateFuncCallback genfunc;
63 GenerateProcCallback genproc;
65 oberon_module_t * module;
67 int recursive;
68 int initialized;
69 gen_type_t * gen_type;
70 };
72 enum oberon_object_kind
73 {
74 OBERON_CLASS_VAR,
75 OBERON_CLASS_TYPE,
76 OBERON_CLASS_PROC,
77 OBERON_CLASS_PARAM,
78 OBERON_CLASS_VAR_PARAM,
79 OBERON_CLASS_CONST,
80 OBERON_CLASS_FIELD,
81 OBERON_CLASS_MODULE
82 };
84 struct oberon_object_t
85 {
86 char * name;
87 enum oberon_object_kind class;
88 int export;
89 int read_only;
91 int local;
92 int linked;
93 int initialized;
95 oberon_object_t * parent;
96 oberon_type_t * parent_type;
98 oberon_scope_t * scope; // for proc
99 int has_return; // for proc
101 oberon_type_t * type;
102 oberon_item_t * value;
103 oberon_object_t * next;
105 oberon_module_t * module;
107 gen_var_t * gen_var;
108 gen_proc_t * gen_proc;
109 };
111 struct oberon_module_t
113 char * name;
114 int ready;
116 oberon_scope_t * decl;
118 oberon_module_t * next;
120 gen_module_t * gen_mod;
121 };
123 typedef const char * (*ModuleImportCallback)(const char * name);
125 struct oberon_context_t
127 /*** SCANER DATA ***/
128 const char * code;
129 int code_index;
131 char c;
132 int token;
133 char * string;
134 int64_t integer;
135 double real;
136 bool longmode;
137 /*** END SCANER DATA ***/
139 /*** PARSER DATA ***/
140 oberon_scope_t * decl;
141 oberon_module_t * mod;
142 /*** END PARSER DATA ***/
144 oberon_type_t * void_type;
145 oberon_type_t * void_ptr_type;
146 oberon_type_t * bool_type;
147 oberon_type_t * byte_type;
148 oberon_type_t * shortint_type;
149 oberon_type_t * int_type;
150 oberon_type_t * longint_type;
151 oberon_type_t * real_type;
152 oberon_type_t * longreal_type;
153 oberon_type_t * char_type;
155 oberon_scope_t * world_scope;
156 oberon_module_t * module_list;
157 ModuleImportCallback import_module;
158 gen_context_t * gen_context;
159 };
161 enum oberon_mode_kind
163 MODE_VAR,
164 MODE_INTEGER,
165 MODE_BOOLEAN,
166 MODE_CALL,
167 MODE_INDEX,
168 MODE_FIELD,
169 MODE_DEREF,
170 MODE_NIL,
171 MODE_NEW,
172 MODE_REAL,
173 MODE_CHAR
174 };
176 enum oberon_operator_kind
178 OP_UNARY_MINUS,
179 OP_BITWISE_NOT,
180 OP_LOGIC_NOT,
181 OP_ABS,
183 OP_ADD,
184 OP_SUB,
185 OP_MUL,
186 OP_DIV,
187 OP_MOD,
188 OP_BITWISE_AND,
189 OP_BITWISE_XOR,
190 OP_BITWISE_OR,
191 OP_LOGIC_AND,
192 OP_LOGIC_OR,
194 OP_EQ,
195 OP_NEQ,
196 OP_LSS,
197 OP_LEQ,
198 OP_GRT,
199 OP_GEQ,
201 OP_CAST
202 };
204 struct oberon_item_t
206 bool is_item; // == 1
207 oberon_type_t * result;
208 oberon_expr_t * next;
209 bool read_only;
211 enum oberon_mode_kind mode;
212 long integer;
213 double real;
214 int boolean;
215 oberon_object_t * var;
217 oberon_item_t * parent;
219 int num_args;
220 oberon_expr_t * args;
221 };
223 struct oberon_oper_t
225 bool is_item; // == 0
226 oberon_type_t * result;
227 oberon_expr_t * next;
228 bool read_only;
230 enum oberon_operator_kind op;
231 oberon_expr_t * left;
232 oberon_expr_t * right;
233 };
235 union oberon_expr_t
237 struct {
238 bool is_item;
239 oberon_type_t * result;
240 oberon_expr_t * next;
241 bool read_only;
242 };
244 oberon_item_t item;
245 oberon_oper_t oper;
246 };
248 #endif // OBERON_INTERNALS_H