Created
October 21, 2018 10:47
-
-
Save keigoi/196416841674a8e5517ac7f389bc02a1 to your computer and use it in GitHub Desktop.
Channel vector generation from Scribble protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
module fase16.adder.Adder; | |
type <ocaml> "int" from "stdlib" as Int; | |
global protocol Adder(role C, role S) | |
{ | |
choice at C | |
{ | |
Add(Int, Int) from C to S; | |
Res(Int) from S to C; | |
do Adder(C, S); | |
} | |
or | |
{ | |
Bye() from C to S; | |
Bye() from S to C; | |
} | |
} | |
*) | |
type 'a ex = Ex : ('v LwtChannel.t * ('v -> 'a)) -> 'a ex | |
(* | |
unit -> | |
< c : < s : < add : (int * int) LwtChannel.t * | |
[> `S of [> `res of int * 'a ] ] ex list; | |
bye : unit LwtChannel.t * | |
[> `S of [> `bye of unit * close sess ] ] ex list > > | |
lazy_t as 'a; | |
s : [> `C of | |
[> `add of | |
(int * int) * < c : < res : int LwtChannel.t * 'b > > lazy_t | |
| `bye of | |
unit * | |
< c : < bye : unit LwtChannel.t * close sess > > lazy_t ] ] | |
ex list as 'b > | |
*) | |
let gen () = | |
let open LwtChannel in | |
let open Lwt in | |
let kCS_Add : (int * int) LwtChannel.t = create () in | |
let kCS_Bye : unit LwtChannel.t = create () in | |
let kSC_Bye : unit LwtChannel.t = create () in | |
let kSC_Res : int LwtChannel.t = create () in | |
let rec adderC_1 = (lazy (object | |
method s = object | |
method add = kCS_Add, adderC_4 | |
method bye = kCS_Bye, adderC_6 | |
end | |
end)) | |
and adderS_2 = [ | |
Ex (kCS_Add, (fun x -> `C (`add(x, adderS_3)))); | |
Ex (kCS_Bye, (fun x -> `C (`bye(x, adderS_5)))); | |
] | |
and adderS_3 = (lazy (object | |
method c = object | |
method res = kSC_Res, adderS_2 | |
end | |
end)) | |
and adderC_4 = [ | |
Ex (kSC_Res, (fun x -> `S (`res(x, adderC_1)))); | |
] | |
and adderS_5 = (lazy (object | |
method c = object | |
method bye = kSC_Bye, adderS_7 | |
end | |
end)) | |
and adderC_6 = [ | |
Ex (kSC_Bye, (fun x -> `S (`bye(x, adderC_8)))); | |
] | |
and adderC_8 = Close | |
and adderS_7 = Close | |
in | |
let vector = object | |
method c = adderC_1 | |
method s = adderS_2 | |
end in | |
vector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
module Simple; | |
type <java> "java.lang.String" from "rt.jar" as String; | |
type <java> "java.lang.Integer" from "rt.jar" as Int; | |
global protocol Simple(role A, role B, role C) | |
{ | |
msg(String) from C to A; | |
choice at A { | |
left(String) from A to B; | |
right(Int) from B to C; | |
msg(String) from B to A; | |
} or { | |
right(String) from A to B; | |
msg(String) from B to A; | |
left(Int) from B to C; | |
msg(String) from C to A; | |
} | |
} | |
*) | |
type 'a ex = Ex : ('v LwtChannel.t * ('v -> 'a)) -> 'a ex | |
(* | |
unit -> | |
< a : [> `C of | |
[> `msg of | |
string * | |
< b : < left : string LwtChannel.t * | |
[> `B of [> `msg of int * close sess ] ] ex | |
list; | |
right : string LwtChannel.t * | |
[> `B of | |
[> `msg of | |
string * | |
[> `C of | |
[> `msg of string * close sess ] ] | |
ex list ] ] | |
ex list > > | |
lazy_t ] ] | |
ex list; | |
b : [> `A of | |
[> `left of | |
string * | |
< c : < right : int LwtChannel.t * | |
< a : < msg : int LwtChannel.t * close sess > > | |
lazy_t > > | |
lazy_t | |
| `right of | |
string * | |
< a : < msg : string LwtChannel.t * | |
< c : < left : int LwtChannel.t * close sess > > | |
lazy_t > > | |
lazy_t ] ] | |
ex list; | |
c : < a : < msg : string LwtChannel.t * | |
[> `B of | |
[> `left of | |
int * | |
< a : < msg : string LwtChannel.t * close sess > > | |
lazy_t | |
| `right of int * close sess ] ] | |
ex list > > | |
lazy_t > | |
*) | |
let gen () = | |
let open LwtChannel in | |
let open Lwt in | |
let kAB_left : string LwtChannel.t = create () in | |
let kAB_right : string LwtChannel.t = create () in | |
let kBA_msg : int LwtChannel.t = create () in | |
let kBA_msg1 : string LwtChannel.t = create () in | |
let kBC_left : int LwtChannel.t = create () in | |
let kBC_right : int LwtChannel.t = create () in | |
let kCA_msg : string LwtChannel.t = create () in | |
let kCA_msg1 : string LwtChannel.t = create () in | |
let rec simpleC_1 = (lazy (object | |
method a = object | |
method msg = kCA_msg, simpleC_6 | |
end | |
end)) | |
and simpleA_2 = [ | |
Ex (kCA_msg, (fun x -> `C (`msg(x, simpleA_3)))); | |
] | |
and simpleA_3 = (lazy (object | |
method b = object | |
method left = kAB_left, simpleA_8 | |
method right = kAB_right, simpleA_10 | |
end | |
end)) | |
and simpleB_4 = [ | |
Ex (kAB_left, (fun x -> `A (`left(x, simpleB_5)))); | |
Ex (kAB_right, (fun x -> `A (`right(x, simpleB_9)))); | |
] | |
and simpleB_5 = (lazy (object | |
method c = object | |
method right = kBC_right, simpleB_7 | |
end | |
end)) | |
and simpleC_6 = [ | |
Ex (kBC_right, (fun x -> `B (`right(x, simpleC_14)))); | |
Ex (kBC_left, (fun x -> `B (`left(x, simpleC_12)))); | |
] | |
and simpleB_7 = (lazy (object | |
method a = object | |
method msg = kBA_msg, simpleB_15 | |
end | |
end)) | |
and simpleA_8 = [ | |
Ex (kBA_msg, (fun x -> `B (`msg(x, simpleA_16)))); | |
] | |
and simpleB_9 = (lazy (object | |
method a = object | |
method msg = kBA_msg1, simpleB_11 | |
end | |
end)) | |
and simpleA_10 = [ | |
Ex (kBA_msg1, (fun x -> `B (`msg(x, simpleA_13)))); | |
] | |
and simpleB_11 = (lazy (object | |
method c = object | |
method left = kBC_left, simpleB_15 | |
end | |
end)) | |
and simpleC_12 = (lazy (object | |
method a = object | |
method msg = kCA_msg1, simpleC_14 | |
end | |
end)) | |
and simpleA_13 = [ | |
Ex (kCA_msg1, (fun x -> `C (`msg(x, simpleA_16)))); | |
] | |
and simpleB_15 = Close | |
and simpleC_14 = Close | |
and simpleA_16 = Close | |
in | |
let vector = object | |
method b = simpleB_4 | |
method c = simpleC_1 | |
method a = simpleA_2 | |
end in | |
vector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment