-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathembed1.c
87 lines (71 loc) · 1.27 KB
/
embed1.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
#include <ol/ol.h>
// olvm:
ol_t ol;
extern unsigned char REPL[];
void ol_new_ol()
{
OL_new(&ol, REPL);
OL_eval(&ol, new_string(&ol, "(import (main))"), 0);
OL_eval(&ol, new_string(&ol, "(born-blinky)"), 0);
}
void ol_delete_ol()
{
OL_delete(&ol);
}
uintptr_t ol_points()
{
return OL_eval(&ol,
new_string(&ol, "points"),
0);
}
void ol_get_blinky(int* x, int* y)
{
uintptr_t xy = OL_eval(&ol,
new_string(&ol, "(get-blinky)"),
0);
assert (is_pair(xy));
*x = ol2int(car(xy));
*y = ol2int(cdr(xy));
}
uintptr_t ol_get_used_memory()
{
uintptr_t m = OL_eval(&ol,
new_string(&ol, "(ref (syscall 1117) 1)"),
0);
assert(is_number(m));
return (size_t) ol2int(m);
}
size_t ol_get_heap_memory()
{
uintptr_t m = OL_eval(&ol,
new_string(&ol, "(ref (syscall 1117) 3)"),
0);
assert (is_number(m));
return (size_t) ol2int(m);
}
void ol_eat_the_point(int x, int y)
{
OL_eval(&ol,
new_string(&ol, "eat-the-point"),
make_integer(x),
make_integer(y),
0);
}
void ol_blinky_move(int x, int y)
{
OL_eval(&ol,
new_string(&ol, "blinky-move"),
make_integer(x),
make_integer(y),
0);
}
int ol_get_level(int x, int y)
{
uintptr_t m = OL_eval(&ol,
new_string(&ol, "get-level"),
make_integer(x),
make_integer(y),
0);
assert (is_number(m));
return ol2int(m);
}