/
threads.c
63 lines (53 loc) · 1.2 KB
/
threads.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
#include "threads.h"
#include "eval.h"
#include "cell.h"
#include "symbol.h"
#include "reader.h"
#include "util.h"
#include "eval.h"
#include "environment.h"
#include "memory.h"
#include "liveness.h"
#include "errors.h"
#include "t_stream.h"
#include "filestream.h"
#include <stdio.h>
#include <setjmp.h>
extern symbol_table *global_symtab;
extern environ_t *special_forms;
extern jmp_buf __jmp_env;
int run_in_thread(const char *code) {
int __tl_eval_level = 0;
cell_t *orig_sexpr = NULL;
frame_t *live_root = NULL;
cell_t *cell=NULL;
cell_t *res=NULL;
STREAM s;
make_filestream(&s, stdin);
if (setjmp(__jmp_env)) {
__tl_eval_level = 0;
orig_sexpr = NULL;
res = NULL;
orig_sexpr = NULL;
dealloc_frames(&live_root);
/* Handle thread cleanup */
}
while (1) {
cell = read_intern(&s, global_symtab);
if(!cell) {
break;
}
orig_sexpr = cell;
push_liveness(&live_root, new_liveframe(2, cell, orig_sexpr));
res = evaluate(cell, NULL);
pop_liveness(&live_root);
if (res) {
pretty_print(res);
} else {
printf("Got NULL from eval of: ");
pretty_print(orig_sexpr);
}
orig_sexpr = NULL;
}
return 0;
}