-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructs.c
52 lines (37 loc) · 887 Bytes
/
structs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdlib.h>
#include "structs.h"
#include "gc.h"
Function *new_Function(t_point body_function, int params_count)
{
Function *f = (Function *) malloc(sizeof(Function));
f->body.structure = body_function;
f->params_count = params_count;
f->built_in = 0;
f->more_params = 0;
gc_collect(make_Func(f));
return f;
}
Cons *new_Cons(t_point a, t_point b)
{
Cons *l = (Cons *) malloc(sizeof(Cons));
l->a = a;
l->b = b;
gc_collect(make_Cons(l));
return l;
}
Thunk *new_Thunk(t_point fce, Cons *params)
{
Thunk *t = (Thunk *) malloc(sizeof(Thunk));
t->function = fce;
t->params = params;
gc_collect(make_Thunk(t));
return t;
}
Function *new_inner_Func(int params_count, int more_params, t_point (*link)(Cons *))
{
Function *f = new_Function(NIL, params_count);
f->built_in = 1;
f->body.link = link;
gc_inc_immortal(make_Func(f));
return f;
}