-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontinue.c
115 lines (101 loc) · 2.98 KB
/
continue.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdlib.h>
#include <string.h>
#include "continue.h"
#include "gc.h"
static void init_cont(cont *c, int tag) {
c->type = tag;
}
cont *make_done() {
cont *c = (cont*)gc_malloc0(sizeof(cont));
init_cont(c, done_type);
return c;
}
cont *make_right_of_bin(int op, tagged *right, env *env, cont *rest) {
right_of_bin *c =gc_malloc3(sizeof(right_of_bin),
&right,
&env,
&rest);
init_cont(&c->c, right_of_bin_type);
c->op = op;
c->right = right;
c->env = env;
c->rest = rest;
return (cont*)c;
}
cont *make_finish_bin(int op, tagged *left_val, cont *rest) {
finish_bin *c = gc_malloc2(sizeof(finish_bin),
&left_val,
&rest);
init_cont(&c->c, finish_bin_type);
c->op = op;
c->left_val = left_val;
c->rest = rest;
return (cont*)c;
}
cont *make_right_of_app(tagged *right, env *env, cont *rest) {
right_of_app *c = gc_malloc3(sizeof(right_of_app),
&right,
&env,
&rest);
init_cont(&c->c, right_of_app_type);
c->right = right;
c->env = env;
c->rest = rest;
return (cont*)c;
}
cont *make_finish_app(tagged *left_val, cont *rest) {
finish_app *c = gc_malloc2(sizeof(finish_app),
&left_val,
&rest);
init_cont(&c->c, finish_app_type);
c->left_val = left_val;
c->rest = rest;
return (cont*)c;
}
cont *make_finish_if0(tagged *thn, tagged *els, env *env, cont *rest) {
finish_if0 *c = gc_malloc4(sizeof(finish_if0),
&thn,
&els,
&env,
&rest);
init_cont(&c->c, finish_if0_type);
c->thn = thn;
c->els = els;
c->env = env;
c->rest = rest;
return (cont*)c;
}
#if USE_JIT
static void init_jitted(jitted *j, jitted_proc code, jitted_proc tail_code, cont *rest) {
j->code = code;
j->tail_code = tail_code;
j->rest = rest;
}
cont *make_right_jitted(jitted_proc code, jitted_proc tail_code, cont *rest, env *env) {
right_jitted *c = gc_malloc2(sizeof(right_jitted),
&env,
&rest);
init_cont(&c->j.c, right_jitted_type);
init_jitted(&c->j, code, tail_code, rest);
c->env = env;
return (cont*)c;
}
cont *make_finish_jitted(jitted_proc code, jitted_proc tail_code, cont *rest, tagged* val) {
finish_jitted *c = gc_malloc2(sizeof(finish_jitted),
&rest,
&val);
init_cont(&c->j.c, finish_jitted_type);
init_jitted(&c->j, code, tail_code, rest);
c->val = val;
return (cont*)c;
}
cont *make_interp(tagged* expr, cont *rest) {
interp *c = gc_malloc2(sizeof(interp),
&expr,
&rest);
init_cont(&c->c, interp_type);
c->expr = expr;
c->rest = rest;
return (cont*)c;
}
#endif