DEADSOFTWARE

1e92de1763923d410e342e0d21cb29ab68c2961e
[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;
55 oberon_scope_t * scope;
57 oberon_module_t * module;
59 int recursive;
60 int initialized;
61 gen_type_t * gen_type;
62 };
64 enum
65 {
66 OBERON_CLASS_VAR,
67 OBERON_CLASS_TYPE,
68 OBERON_CLASS_PROC,
69 OBERON_CLASS_PARAM,
70 OBERON_CLASS_VAR_PARAM,
71 OBERON_CLASS_CONST,
72 OBERON_CLASS_FIELD,
73 OBERON_CLASS_MODULE
74 };
76 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
77 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
79 struct oberon_object_t
80 {
81 char * name;
82 int class;
83 int export;
84 int read_only;
86 int local;
87 int linked;
88 int initialized;
90 oberon_object_t * parent;
91 oberon_type_t * parent_type;
93 oberon_scope_t * scope; // for proc
94 int has_return; // for proc
95 int sysproc;
96 GenerateFuncCallback genfunc;
97 GenerateProcCallback genproc;
99 oberon_type_t * type;
100 oberon_item_t * value;
101 oberon_object_t * next;
103 oberon_module_t * module;
105 gen_var_t * gen_var;
106 gen_proc_t * gen_proc;
107 };
109 struct oberon_module_t
111 char * name;
112 int ready;
114 oberon_scope_t * decl;
116 oberon_module_t * next;
118 gen_module_t * gen_mod;
119 };
121 typedef const char * (*ModuleImportCallback)(const char * name);
123 struct oberon_context_t
125 /*** SCANER DATA ***/
126 const char * code;
127 int code_index;
129 char c;
130 int token;
131 char * string;
132 int64_t integer;
133 double real;
134 bool longmode;
135 /*** END SCANER DATA ***/
137 /*** PARSER DATA ***/
138 oberon_scope_t * decl;
139 oberon_module_t * mod;
140 /*** END PARSER DATA ***/
142 oberon_type_t * bool_type;
143 oberon_type_t * byte_type;
144 oberon_type_t * shortint_type;
145 oberon_type_t * int_type;
146 oberon_type_t * longint_type;
147 oberon_type_t * real_type;
148 oberon_type_t * longreal_type;
149 oberon_type_t * void_type;
150 oberon_type_t * void_ptr_type;
152 oberon_scope_t * world_scope;
153 oberon_module_t * module_list;
154 ModuleImportCallback import_module;
155 gen_context_t * gen_context;
156 };
158 enum
160 MODE_VAR,
161 MODE_INTEGER,
162 MODE_BOOLEAN,
163 MODE_CALL,
164 MODE_INDEX,
165 MODE_FIELD,
166 MODE_DEREF,
167 MODE_NIL,
168 MODE_NEW,
169 MODE_REAL,
170 MODE_CAST
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
197 };
199 struct oberon_item_t
201 int is_item; // == 1
202 oberon_type_t * result;
203 oberon_expr_t * next;
204 int read_only;
206 int mode;
207 long integer;
208 double real;
209 int boolean;
210 oberon_object_t * var;
212 oberon_expr_t * parent;
214 int num_args;
215 oberon_expr_t * args;
216 };
218 struct oberon_oper_t
220 int is_item; // == 0
221 oberon_type_t * result;
222 oberon_expr_t * next;
223 int read_only;
225 int op;
226 oberon_expr_t * left;
227 oberon_expr_t * right;
228 };
230 union oberon_expr_t
232 struct {
233 int is_item;
234 oberon_type_t * result;
235 oberon_expr_t * next;
236 int read_only;
237 };
239 oberon_item_t item;
240 oberon_oper_t oper;
241 };
243 #endif // OBERON_INTERNALS_H