File tree Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Expand file tree Collapse file tree 4 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ build/counter: examples/counter.c coroutine.h build/coroutine.o
2
2
gcc -I. -Wall -Wextra -ggdb -o build/counter examples/counter.c build/coroutine.o
3
3
4
4
.PHONY :
5
- examples : build/counter build/counter_cpp build/counter_c3 build/echo
5
+ examples : build/counter build/counter_cpp build/counter_c3 build/counter_jai build/ echo
6
6
7
7
build/echo : examples/echo.c3 coroutine.c3 build/coroutine.o
8
8
cp build/coroutine.o build/echo.coroutine.o # c3c deletes the object files for some reason, so we make a copy to preserve the original
@@ -15,6 +15,12 @@ build/counter_c3: examples/counter.c3 coroutine.c3 build/coroutine.o
15
15
cp build/coroutine.o build/counter.coroutine.o # c3c deletes the object files for some reason, so we make a copy to preserve the original
16
16
c3c compile -o build/counter_c3 examples/counter.c3 coroutine.c3 build/counter.coroutine.o
17
17
18
+ build/counter_jai : examples/counter.jai build/coroutine.so
19
+ jai-linux examples/counter.jai
20
+
21
+ build/coroutine.so : coroutine.c
22
+ gcc -Wall -Wextra -ggdb -shared -fPIC -o build/coroutine.so coroutine.c
23
+
18
24
build/coroutine.o : coroutine.c coroutine.h
19
25
mkdir -p build
20
26
gcc -Wall -Wextra -ggdb -c -o build/coroutine.o coroutine.c
Original file line number Diff line number Diff line change 1
- // coroutine bindings for C3
1
+ // coroutine bindings for C3 (see coroutine.h for the API documentation)
2
2
module coroutine;
3
3
import std::net;
4
4
Original file line number Diff line number Diff line change
1
+ .build /
Original file line number Diff line number Diff line change
1
+ #import "Basic ";
2
+
3
+ coroutine :: #library " ../build/coroutine" ;
4
+ coroutine_sleep_read :: (fd : int ) #foreign coroutine ;
5
+ coroutine_sleep_write :: (fd : int ) #foreign coroutine ;
6
+ coroutine_wake_up :: (id : int ) #foreign coroutine ;
7
+ coroutine_init :: () #foreign coroutine ;
8
+ coroutine_finish :: () #foreign coroutine ;
9
+ coroutine_yield :: () #foreign coroutine ;
10
+ coroutine_go :: (f : (* void ) #c_call , arg : * void ) #foreign coroutine ;
11
+ coroutine_id :: () -> int #foreign coroutine ;
12
+ coroutine_alive :: () -> int #foreign coroutine ;
13
+
14
+ counter :: (arg : * void ) #c_call {
15
+ push_context {
16
+ n := cast (int ) arg ;
17
+ for 0 ..n - 1 {
18
+ print (" [% ] % \n " , coroutine_id (), it );
19
+ coroutine_yield ();
20
+ }
21
+ }
22
+ }
23
+
24
+ main :: () {
25
+ coroutine_init ();
26
+ defer coroutine_finish ();
27
+ coroutine_go (counter , cast (* void ) 5 );
28
+ coroutine_go (counter , cast (* void ) 10 );
29
+ while coroutine_alive () > 1 {
30
+ coroutine_yield ();
31
+ }
32
+ }
33
+
34
+ #run {
35
+ #import "Compiler ";
36
+ set_build_options_dc (.{
37
+ output_path = " ../build/" ,
38
+ output_executable_name = " counter_jai" ,
39
+ });
40
+ }
You can’t perform that action at this time.
0 commit comments