2 typedef struct decl_type
{
7 static inline decl_type
*init_decl_type(token_t type
, text
*name
) {
8 decl_type
*t
= malloc(sizeof(*t
));
10 t
->name
= (text
*) strdup((const char *) name
);
14 static inline void free_decl_type(decl_type
*type
) {
19 typedef struct decl_var
{
21 unsigned pointer_level
;
24 static inline decl_var
*init_decl_var(text
*name
, unsigned pl
) {
25 decl_var
*v
= malloc(sizeof(*v
));
26 v
->name
= (text
*) strdup((const char *) name
);
27 v
->pointer_level
= pl
;
31 static inline void free_decl_var(decl_var
*var
) {
36 typedef struct decl_arg
{
41 static inline decl_arg
*init_decl_arg(decl_type
*type
, decl_var
*var
) {
42 decl_arg
*arg
= malloc(sizeof(*arg
));
48 static inline void free_decl_arg(decl_arg
*arg
) {
49 free_decl_type(arg
->type
);
50 free_decl_var(arg
->var
);
54 typedef struct decl_vars
{
59 static inline decl_vars
*init_decl_vars(decl_var
*var
) {
60 decl_vars
*vars
= malloc(sizeof(*vars
));
62 vars
->vars
= malloc(sizeof(*vars
->vars
));
67 static inline decl_vars
*add_decl_var(decl_vars
*vars
, decl_var
*var
) {
68 vars
->vars
= realloc(vars
->vars
, ++vars
->count
* sizeof(*vars
->vars
));
69 vars
->vars
[vars
->count
-1] = var
;
73 static inline void free_decl_vars(decl_vars
*vars
) {
76 for (i
= 0; i
< vars
->count
; ++i
) {
77 free_decl_var(vars
->vars
[i
]);
83 typedef struct decl_args
{
88 static inline decl_args
*init_decl_args(decl_arg
*arg
) {
89 decl_args
*args
= malloc(sizeof(*args
));
91 args
->args
= malloc(sizeof(*args
->args
));
96 static inline decl_args
*add_decl_arg(decl_args
*args
, decl_arg
*arg
) {
97 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
98 args
->args
[args
->count
-1] = arg
;
102 static inline void free_decl_args(decl_args
*args
) {
105 for (i
= 0; i
< args
->count
; ++i
) {
106 free_decl_arg(args
->args
[i
]);
112 typedef struct decl
{
117 static inline decl
* init_decl(decl_arg
*func
, decl_args
*args
) {
118 decl
*d
= malloc(sizeof(*d
));
124 static inline void free_decl(decl
*d
) {
125 free_decl_arg(d
->func
);
126 free_decl_args(d
->args
);
130 typedef struct impl_type
{
135 static inline impl_type
*init_impl_type(token_t type
, text
*name
) {
136 impl_type
*t
= malloc(sizeof(*t
));
139 t
->name
= (text
*) strdup((const char *) name
);
143 static inline void free_impl_type(impl_type
*type
) {
148 typedef struct impl_var
{
150 unsigned reference
:1;
153 static inline impl_var
*init_impl_var(text
*name
, int is_reference
) {
154 impl_var
*var
= malloc(sizeof(*var
));
155 var
->name
= (text
*) strdup((const char *) name
);
156 var
->reference
= is_reference
;
160 static inline void free_impl_var(impl_var
*var
) {
165 typedef struct impl_def_val
{
174 static inline impl_def_val
*init_impl_def_val() {
175 impl_def_val
*def
= malloc(sizeof(*def
));
181 static inline void free_impl_def_val(impl_def_val
*def
) {
185 typedef struct impl_arg
{
191 static inline impl_arg
*init_impl_arg(impl_type
*type
, impl_var
*var
, impl_def_val
*def
) {
192 impl_arg
*arg
= malloc(sizeof(*arg
));
199 static inline void free_impl_arg(impl_arg
*arg
) {
200 free_impl_type(arg
->type
);
201 free_impl_var(arg
->var
);
203 free_impl_def_val(arg
->def
);
208 typedef struct impl_args
{
213 static inline impl_args
*init_impl_args(impl_arg
*arg
) {
214 impl_args
*args
= malloc(sizeof(*args
));
216 args
->args
= malloc(sizeof(*args
->args
));
221 static inline impl_args
*add_impl_arg(impl_args
*args
, impl_arg
*arg
) {
222 args
->args
= realloc(args
->args
, ++args
->count
* sizeof(*args
->args
));
223 args
->args
[args
->count
-1] = arg
;
227 static inline void free_impl_args(impl_args
*args
) {
230 for (i
= 0; i
< args
->count
; ++i
) {
231 free_impl_arg(args
->args
[i
]);
237 typedef struct impl_func
{
240 impl_type
*return_type
;
243 static inline impl_func
*init_impl_func(text
*name
, impl_args
*args
, impl_type
*type
) {
244 impl_func
*func
= malloc(sizeof(*func
));
245 func
->name
= (text
*) strdup((const char *) name
);
247 func
->return_type
= type
;
251 static inline void free_impl_func(impl_func
*f
) {
252 free_impl_type(f
->return_type
);
253 free_impl_args(f
->args
);
258 typedef struct let_func
{
263 static inline let_func
*init_let_func(token_t type
, text
*name
) {
264 let_func
*func
= malloc(sizeof(*func
));
266 func
->name
= (text
*) strdup((const char *) name
);
270 static inline void free_let_func(let_func
*func
) {
275 typedef struct let_value
{
278 unsigned null_pointer_ref
:1;
281 static inline let_value
*init_let_value(let_func
*func
, impl_var
*var
) {
282 let_value
*val
= malloc(sizeof(*val
));
285 val
->null_pointer_ref
= 1;
287 val
->null_pointer_ref
= 0;
295 static inline void free_let_value(let_value
*val
) {
297 free_let_func(val
->func
);
300 free_impl_var(val
->var
);
305 typedef struct let_stmt
{
310 static inline let_stmt
*init_let_stmt(decl_var
*var
, let_value
*val
) {
311 let_stmt
*let
= malloc(sizeof(*let
));
317 static inline void free_let_stmt(let_stmt
*stmt
) {
318 free_decl_var(stmt
->var
);
319 free_let_value(stmt
->val
);
323 typedef struct set_func
{
328 static inline set_func
*init_set_func(token_t type
, text
*name
) {
329 set_func
*func
= malloc(sizeof(*func
));
331 func
->name
= (text
*) strdup((const char *) name
);
335 static inline void free_set_func(set_func
*func
) {
340 typedef struct set_value
{
345 static inline set_value
*init_set_value(set_func
*func
, decl_vars
*vars
) {
346 set_value
*val
= malloc(sizeof(*val
));
352 static inline void free_set_value(set_value
*val
) {
353 free_set_func(val
->func
);
354 free_decl_vars(val
->vars
);
358 typedef struct set_stmt
{
363 static inline set_stmt
*init_set_stmt(impl_var
*var
, set_value
*val
) {
364 set_stmt
*set
= malloc(sizeof(*set
));
370 static inline void free_set_stmt(set_stmt
*set
) {
371 free_impl_var(set
->var
);
372 free_set_value(set
->val
);
376 typedef struct ret_stmt
{
381 static inline ret_stmt
*init_ret_stmt(set_func
*func
, decl_var
*decl
) {
382 ret_stmt
*ret
= malloc(sizeof(*ret
));
388 static inline void free_ret_stmt(ret_stmt
*ret
) {
389 free_set_func(ret
->func
);
390 free_decl_var(ret
->decl
);
394 typedef struct impl_stmt
{
404 static inline impl_stmt
*init_impl_stmt(token_t type
, void *ptr
) {
405 impl_stmt
*stmt
= malloc(sizeof(*stmt
));
411 static inline void free_impl_stmt(impl_stmt
*stmt
) {
412 switch (stmt
->type
) {
414 free_let_stmt(stmt
->s
.let
);
417 free_set_stmt(stmt
->s
.set
);
420 free_ret_stmt(stmt
->s
.ret
);
426 typedef struct impl_stmts
{
431 static inline impl_stmts
*init_impl_stmts(impl_stmt
*stmt
) {
432 impl_stmts
*stmts
= malloc(sizeof(*stmts
));
434 stmts
->stmts
= malloc(sizeof(*stmts
->stmts
));
435 stmts
->stmts
[0] = stmt
;
439 static inline impl_stmts
*add_impl_stmt(impl_stmts
*stmts
, impl_stmt
*stmt
) {
440 stmts
->stmts
= realloc(stmts
->stmts
, ++stmts
->count
* sizeof(*stmts
->stmts
));
441 stmts
->stmts
[stmts
->count
-1] = stmt
;
445 static inline void free_impl_stmts(impl_stmts
*stmts
) {
448 for (i
= 0; i
< stmts
->count
; ++i
) {
449 free_impl_stmt(stmts
->stmts
[i
]);
455 typedef struct impl
{
460 static inline impl
*init_impl(impl_func
*func
, impl_stmts
*stmts
) {
461 impl
*i
= malloc(sizeof(*i
));
467 static inline void free_impl(impl
*impl
) {
468 free_impl_func(impl
->func
);
469 free_impl_stmts(impl
->stmts
);