-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathminicoro.nelua
73 lines (73 loc) · 2.74 KB
/
minicoro.nelua
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
##[[
if not MINICORO_NO_IMPL then
cdefine 'MCO_API static'
cdefine 'MINICORO_IMPL'
end
cinclude 'minicoro.h'
]]
global mco_state: type <cimport,nodecl,using> = @enum(cint){
MCO_DEAD = 0,
MCO_NORMAL = 1,
MCO_RUNNING = 2,
MCO_SUSPENDED = 3
}
global mco_result: type <cimport,nodecl,using> = @enum(cint){
MCO_SUCCESS = 0,
MCO_GENERIC_ERROR = 1,
MCO_INVALID_POINTER = 2,
MCO_INVALID_COROUTINE = 3,
MCO_NOT_SUSPENDED = 4,
MCO_NOT_RUNNING = 5,
MCO_MAKE_CONTEXT_ERROR = 6,
MCO_SWITCH_CONTEXT_ERROR = 7,
MCO_NOT_ENOUGH_SPACE = 8,
MCO_OUT_OF_MEMORY = 9,
MCO_INVALID_ARGUMENTS = 10,
MCO_INVALID_OPERATION = 11,
MCO_STACK_OVERFLOW = 12
}
global mco_coro: type <cimport,nodecl,forwarddecl> = @record{}
mco_coro = @record{
context: pointer,
state: mco_state,
func: function(*mco_coro): void,
prev_co: *mco_coro,
user_data: pointer,
allocator_data: pointer,
free_cb: function(pointer, pointer): void,
stack_base: pointer,
stack_size: csize,
storage: *cuchar,
bytes_stored: csize,
storage_size: csize,
asan_prev_stack: pointer,
tsan_prev_fiber: pointer,
tsan_fiber: pointer,
magic_number: csize
}
global mco_desc: type <cimport,nodecl> = @record{
func: function(*mco_coro): void,
user_data: pointer,
malloc_cb: function(csize, pointer): pointer,
free_cb: function(pointer, pointer): void,
allocator_data: pointer,
storage_size: csize,
coro_size: csize,
stack_size: csize
}
global function mco_desc_init(func: function(*mco_coro): void, stack_size: csize): mco_desc <cimport,nodecl> end
global function mco_init(co: *mco_coro, desc: *mco_desc): mco_result <cimport,nodecl> end
global function mco_uninit(co: *mco_coro): mco_result <cimport,nodecl> end
global function mco_create(out_co: **mco_coro, desc: *mco_desc): mco_result <cimport,nodecl> end
global function mco_destroy(co: *mco_coro): mco_result <cimport,nodecl> end
global function mco_resume(co: *mco_coro): mco_result <cimport,nodecl> end
global function mco_yield(co: *mco_coro): mco_result <cimport,nodecl> end
global function mco_status(co: *mco_coro): mco_state <cimport,nodecl> end
global function mco_get_user_data(co: *mco_coro): pointer <cimport,nodecl> end
global function mco_push(co: *mco_coro, src: pointer, len: csize): mco_result <cimport,nodecl> end
global function mco_pop(co: *mco_coro, dest: pointer, len: csize): mco_result <cimport,nodecl> end
global function mco_peek(co: *mco_coro, dest: pointer, len: csize): mco_result <cimport,nodecl> end
global function mco_get_bytes_stored(co: *mco_coro): csize <cimport,nodecl> end
global function mco_get_storage_size(co: *mco_coro): csize <cimport,nodecl> end
global function mco_running(): *mco_coro <cimport,nodecl> end
global function mco_result_description(res: mco_result): cstring <cimport,nodecl> end