DEADSOFTWARE

Первые наработки бэкэнда для jvm
[dsw-obn.git] / src / oberon-internals.h
1 #ifndef OBERON_INTERNALS_H
2 #define OBERON_INTERNALS_H
4 typedef struct gen_module_t gen_module_t;
5 typedef struct gen_proc_t gen_proc_t;
6 typedef struct gen_type_t gen_type_t;
7 typedef struct gen_var_t gen_var_t;
8 typedef struct gen_block_t gen_block_t;
9 typedef struct gen_context_t gen_context_t;
11 typedef struct oberon_type_t oberon_type_t;
12 typedef struct oberon_object_t oberon_object_t;
13 typedef struct oberon_module_t oberon_module_t;
14 typedef struct oberon_context_t oberon_context_t;
15 typedef struct oberon_scope_t oberon_scope_t;
17 typedef struct oberon_item_t oberon_item_t;
18 typedef struct oberon_oper_t oberon_oper_t;
19 typedef union oberon_expr_t oberon_expr_t;
21 struct oberon_scope_t
22 {
23 oberon_context_t * ctx;
24 oberon_object_t * list;
25 oberon_scope_t * up;
27 oberon_object_t * parent;
28 int local;
29 };
31 enum
32 {
33 OBERON_TYPE_VOID,
34 OBERON_TYPE_INTEGER,
35 OBERON_TYPE_BOOLEAN,
36 OBERON_TYPE_PROCEDURE,
37 OBERON_TYPE_ARRAY,
38 OBERON_TYPE_RECORD,
39 OBERON_TYPE_POINTER,
40 OBERON_TYPE_REAL
41 };
43 struct oberon_type_t
44 {
45 int class;
46 int size;
48 int num_decl;
49 oberon_type_t * base;
50 oberon_object_t * decl;
52 oberon_module_t * module;
54 int recursive;
55 int initialized;
56 gen_type_t * gen_type;
57 };
59 enum
60 {
61 OBERON_CLASS_VAR,
62 OBERON_CLASS_TYPE,
63 OBERON_CLASS_PROC,
64 OBERON_CLASS_PARAM,
65 OBERON_CLASS_VAR_PARAM,
66 OBERON_CLASS_CONST,
67 OBERON_CLASS_FIELD,
68 OBERON_CLASS_MODULE
69 };
71 typedef oberon_expr_t * (*GenerateFuncCallback)(oberon_context_t *, int, oberon_expr_t *);
72 typedef void (*GenerateProcCallback)(oberon_context_t *, int, oberon_expr_t *);
74 struct oberon_object_t
75 {
76 char * name;
77 int class;
78 int export;
79 int read_only;
81 int local;
82 int linked;
83 int initialized;
85 oberon_object_t * parent;
87 oberon_scope_t * scope; // for proc
88 int has_return; // for proc
89 int sysproc;
90 GenerateFuncCallback genfunc;
91 GenerateProcCallback genproc;
93 oberon_type_t * type;
94 oberon_item_t * value;
95 oberon_object_t * next;
97 oberon_module_t * module;
99 gen_var_t * gen_var;
100 gen_proc_t * gen_proc;
101 };
103 struct oberon_module_t
105 char * name;
106 int ready;
108 oberon_scope_t * decl;
110 oberon_module_t * next;
112 gen_module_t * gen_mod;
113 };
115 typedef const char * (*ModuleImportCallback)(const char * name);
117 struct oberon_context_t
119 /*** SCANER DATA ***/
120 const char * code;
121 int code_index;
123 char c;
124 int token;
125 char * string;
126 long integer;
127 double real;
128 /*** END SCANER DATA ***/
130 /*** PARSER DATA ***/
131 oberon_scope_t * decl;
132 oberon_module_t * mod;
133 /*** END PARSER DATA ***/
135 oberon_type_t * int_type;
136 oberon_type_t * bool_type;
137 oberon_type_t * real_type;
138 oberon_type_t * void_type;
139 oberon_type_t * void_ptr_type;
140 oberon_scope_t * world_scope;
141 oberon_module_t * module_list;
142 ModuleImportCallback import_module;
143 gen_context_t * gen_context;
144 };
146 enum
148 MODE_VAR,
149 MODE_INTEGER,
150 MODE_BOOLEAN,
151 MODE_CALL,
152 MODE_INDEX,
153 MODE_FIELD,
154 MODE_DEREF,
155 MODE_NIL,
156 MODE_NEW,
157 MODE_REAL
158 };
160 enum
162 OP_UNARY_MINUS,
163 OP_BITWISE_NOT,
164 OP_LOGIC_NOT,
165 OP_ABS,
167 OP_ADD,
168 OP_SUB,
169 OP_MUL,
170 OP_DIV,
171 OP_MOD,
172 OP_BITWISE_AND,
173 OP_BITWISE_XOR,
174 OP_BITWISE_OR,
175 OP_LOGIC_AND,
176 OP_LOGIC_OR,
178 OP_EQ,
179 OP_NEQ,
180 OP_LSS,
181 OP_LEQ,
182 OP_GRT,
183 OP_GEQ
184 };
186 struct oberon_item_t
188 int is_item; // == 1
189 oberon_type_t * result;
190 oberon_expr_t * next;
191 int read_only;
193 int mode;
194 long integer;
195 double real;
196 int boolean;
197 oberon_object_t * var;
199 oberon_item_t * parent;
201 int num_args;
202 oberon_expr_t * args;
203 };
205 struct oberon_oper_t
207 int is_item; // == 0
208 oberon_type_t * result;
209 oberon_expr_t * next;
210 int read_only;
212 int op;
213 oberon_expr_t * left;
214 oberon_expr_t * right;
215 };
217 union oberon_expr_t
219 struct {
220 int is_item;
221 oberon_type_t * result;
222 oberon_expr_t * next;
223 int read_only;
224 };
226 oberon_item_t item;
227 oberon_oper_t oper;
228 };
230 extern void
231 oberon_error(oberon_context_t * ctx, const char * fmt, ...);
233 #endif // OBERON_INTERNALS_H