-
Notifications
You must be signed in to change notification settings - Fork 0
/
iuv_c.c
49 lines (37 loc) · 891 Bytes
/
iuv_c.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
#include <stddef.h>
#include <stdlib.h>
#include <uv.h>
#include <idris_rts.h>
#include "iuv_c.h"
#include "build/IUV.h"
VM* vm;
uv_loop_t *loop;
double c_uptime() {
double v;
int result = uv_uptime(&v);
return v;
}
void close_cb(uv_handle_t* handle) {
free(handle);
}
void c_setTimeout_cb(uv_timer_t* timer, int status) {
uv_timer_stop(timer);
idris_setTimeout_cb(vm, timer->data);
uv_close((uv_handle_t*)timer, &close_cb);
}
void c_setTimeout(int ms, void* cb) {
uv_timer_t* timer = malloc(sizeof(uv_loop_t));
timer->data = cb;
uv_timer_init(loop, timer);
uv_timer_start(timer, (uv_timer_cb) &c_setTimeout_cb, ms, ms);
}
void main() {
vm = idris_vm();
loop = malloc(sizeof(uv_loop_t));
uv_loop_init(loop);
idris_main(vm);
uv_run(loop, UV_RUN_DEFAULT);
uv_loop_close(loop);
free(loop);
close_vm(vm);
}