-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.dats
104 lines (86 loc) · 2.55 KB
/
test.dats
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "share/atspre_staload.hats"
staload "./libsession.sats"
staload "./set.sats"
staload "./blackboard.sats"
staload "./endpoint.sats"
staload "./msg.sats"
staload "./thread.sats"
staload _ = "./thread.dats"
staload _ = "./endpoint.dats"
staload _ = "./libsession.dats"
%{^
#include "./runtime.h"
#include "./log.h"
%}
extern fun setup (): void
implement setup () = let
val LOG_INFO = $extval(int, "LOG_INFO")
val _ = $extfcall(void, "install_handler")
val _ = $extfcall(void, "log_set_pthread")
val _ = $extfcall(void, "log_set_level", LOG_INFO)
in
end
extern fun helloworld (): void
implement helloworld () = let
stadef rs1 = emp+1
stadef rs2 = emp+2
stadef helloworld = pbmsg(1,string)::pbmsg(2,string)::pend(1)
fun client (ch: chan(rs1+rs2,rs1,helloworld)): void = let
val _ = session_bsend<string> (ch, 1, "hello")
val _ = println! (session_brecv<string> (ch, 2))
in
session_close (ch, 1)
end
fun server (ch: chan(rs1+rs2,rs2,helloworld)): void = let
val _ = println! (session_brecv<string> (ch, 1))
val _ = session_bsend (ch, 2, "world!")
in
session_wait (ch, 1)
end
val ch = session_fork (emp()+1, emp()+2, llam ch => client ch)
val _ = server ch
in
end
extern fun simplelink (): void
implement simplelink () = let
stadef rs1 = emp+1
stadef rs2 = emp+2
stadef helloworld = pbmsg(1,string)::pbmsg(2,string)::pbmsg(1,string)::pbmsg(2,string)::pend(1)
fun client (ch: chan(rs1+rs2,rs1,helloworld)): void = let
val _ = session_bsend<string> (ch, 1, "hello1")
val _ = println! (session_brecv<string> (ch, 2))
val _ = $extfcall(void, "sleep", 1)
val _ = session_bsend<string> (ch, 1, "hello2")
val _ = println! (session_brecv<string> (ch, 2))
in
session_close (ch, 1)
end
fun server (ch: chan(rs1+rs2,rs2,helloworld)): void = let
val _ = println! (session_brecv<string> (ch, 1))
val _ = session_bsend (ch, 2, "world1!")
val _ = $extfcall(void, "sleep", 1)
val _ = println! (session_brecv<string> (ch, 1))
val _ = session_bsend (ch, 2, "world2!")
in
session_wait (ch, 1)
end
val ch1 = session_fork (emp()+1, emp()+2, llam ch => client ch)
val ch2 = session_fork (emp()+2, emp()+1, llam ch => server ch)
val ch = session_link (ch1, ch2)
val _ = session_emp ch
in
end
//local (**)
//#include "./examples/ex-queue.dats"
//#include "./examples/ex-cut-residual.dats"
//#include "./examples/ex-sieve.dats"
#include "./examples/ex-cloud.dats"
//in (**)
implement main0 () = let
val _ = setup ()
val _ = test("Test Queue")
val _ = $extfcall(void, "sleep", 2)
// val _ = $extfcall(void, "g_states")
in
end
//end (**)