#![allow(clippy::type_complexity, dead_code)] #![recursion_limit = "256"] use mpstthree::binary::close::close; use mpstthree::binary::fork::fork_with_thread_id; use mpstthree::binary::recv::recv; use mpstthree::binary::send::send; use mpstthree::binary::struct_trait::{end::End, recv::Recv, send::Send, session::Session}; use mpstthree::{choose, offer}; use rand::{thread_rng, Rng}; use std::error::Error; use std::thread::spawn; //////////////////////////// type EndpointCInit = Recv<(), EndpointC0>; type EndpointC0 = Recv; type EndpointSInit = ::Dual; type EndpointS0 = ::Dual; enum Branching0fromCtoS { Continue(Recv<(), EndpointC1>), Quit(Recv<(), End>), } type EndpointC1 = Recv; type EndpointS1 = ::Dual; enum Branching1fromCtoS { Continue(Recv<(), EndpointC2>), Loop(Recv<(), EndpointC1>), } type EndpointC2 = Recv; type EndpointS2 = ::Dual; enum Branching2fromCtoS { Continue(Recv<(), EndpointC3>), Quit(Recv<(), End>), } type EndpointC3 = Recv; type EndpointS3 = ::Dual; enum Branching3fromCtoS { Continue(Recv<(), EndpointC4>), Quit(Recv<(), End>), } type EndpointC4 = Recv; type EndpointS4 = ::Dual; enum Branching4fromCtoS { Continue(Recv<(), EndpointC5>), Loop(Recv<(), EndpointC4>), } type EndpointC5 = Recv; type EndpointS5 = ::Dual; enum Branching5fromCtoS { Continue(Recv<(), EndpointC6>), Quit(Recv<(), End>), } type EndpointC6 = Recv; type EndpointS6 = ::Dual; enum Branching6fromCtoS { Continue(Recv<(), EndpointC7>), Loop(Recv<(), EndpointC6>), } type EndpointC7 = Recv; type EndpointS7 = ::Dual; enum Branching7fromCtoS { Continue(Recv<(), EndpointC8>), Quit(Recv<(), End>), } type EndpointC8 = Recv; type EndpointS8 = ::Dual; enum Branching8fromCtoS { Continue(Recv<(), EndpointC9>), Loop(Recv<(), EndpointC7>), } type EndpointC9 = Recv; type EndpointS9 = ::Dual; enum Branching9fromCtoS { Continue(Recv<(), Recv<(), Recv<(), Recv<(), EndpointC10>>>>), Loop(Recv<(), Recv<(), EndpointC9>>), } type EndpointC10 = Recv; type EndpointS10 = ::Dual; enum Branching10fromCtoS { Data(Recv<(), Recv<(), EndpointC10>>), Subject(Recv<(), Recv<(), EndpointC10>>), End(Recv<(), Recv<(), EndpointC7>>), } /////////////////////////// fn binary_s_quit_0(s: EndpointSInit) -> Result<(), Box> { let s = send((), s); let s = choose!(Branching0fromCtoS::Quit, s); let s = send((), s); close(s) } fn binary_s_x_0(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Loop, s); let s = send((), s); Ok(s) } fn binary_s_quit_2(s: EndpointSInit) -> Result<(), Box> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Quit, s); let s = send((), s); close(s) } fn binary_s_quit_3(s: EndpointSInit) -> Result<(), Box> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Quit, s); let s = send((), s); close(s) } fn binary_s_x_4(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Loop, s); let s = send((), s); Ok(s) } fn binary_s_quit_5(s: EndpointSInit) -> Result<(), Box> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Quit, s); let s = send((), s); close(s) } fn binary_s_x_6(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Loop, s); let s = send((), s); Ok(s) } fn binary_s_quit_7(s: EndpointSInit) -> Result<(), Box> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Quit, s); let s = send((), s); close(s) } fn binary_s_x_8(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching8fromCtoS::Loop, s); let s = send((), s); Ok(s) } fn binary_s_x_9(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching8fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching9fromCtoS::Loop, s); let s = send((), s); let s = send((), s); Ok(s) } fn binary_s_end_10(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching8fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching9fromCtoS::Continue, s); let s = send((), s); let s = send((), s); let s = send((), s); let s: Send = send((), s); let s = choose!(Branching10fromCtoS::End, s); let s = send((), s); let s = send((), s); Ok(s) } fn binary_s_data_10(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching8fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching9fromCtoS::Continue, s); let s = send((), s); let s = send((), s); let s = send((), s); let s: Send = send((), s); let s = choose!(Branching10fromCtoS::Data, s); let s = send((), s); let s = send((), s); Ok(s) } fn binary_s_subject_10(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching8fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching9fromCtoS::Continue, s); let s = send((), s); let s = send((), s); let s = send((), s); let s: Send = send((), s); let s = choose!(Branching10fromCtoS::Subject, s); let s = send((), s); let s = send((), s); Ok(s) } fn binary_s_init(s: EndpointSInit) -> Result> { let s = send((), s); let s = choose!(Branching0fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching1fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching2fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching3fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching4fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching5fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching6fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching8fromCtoS::Continue, s); let s: Send = send((), s); let s = choose!(Branching9fromCtoS::Continue, s); let s = send((), s); let s = send((), s); let s = send((), s); let s = send((), s); Ok(s) } fn recurs_data_s_10(s: EndpointS10) -> Result> { let s = choose!(Branching10fromCtoS::Data, s); let s = send((), s); let s = send((), s); Ok(s) } fn recurs_subject_s_10(s: EndpointS10) -> Result> { let s = choose!(Branching10fromCtoS::Subject, s); let s = send((), s); let s = send((), s); Ok(s) } fn close_s_10(s: EndpointS10) -> Result<(), Box> { let s = choose!(Branching10fromCtoS::End, s); let s = send((), s); let s: Send = send((), s); let s = choose!(Branching7fromCtoS::Quit, s); let s = send((), s); close(s) } //////////////////////////// fn endpoint_c_init(s: EndpointCInit) -> Result<(), Box> { let (_, s) = recv(s)?; endpoint_c_0(s) } fn endpoint_c_0(s: EndpointC0) -> Result<(), Box> { offer!(s, { Branching0fromCtoS::Quit(s) => { let (_, s) = recv(s)?; close(s) }, Branching0fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_1(s) }, }) } fn endpoint_c_1(s: EndpointC1) -> Result<(), Box> { offer!(s, { Branching1fromCtoS::Loop(s) => { let (_, s) = recv(s)?; endpoint_c_1(s) }, Branching1fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_2(s) }, }) } fn endpoint_c_2(s: EndpointC2) -> Result<(), Box> { offer!(s, { Branching2fromCtoS::Quit(s) => { let (_, s) = recv(s)?; close(s) }, Branching2fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_3(s) }, }) } fn endpoint_c_3(s: EndpointC3) -> Result<(), Box> { offer!(s, { Branching3fromCtoS::Quit(s) => { let (_, s) = recv(s)?; close(s) }, Branching3fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_4(s) }, }) } fn endpoint_c_4(s: EndpointC4) -> Result<(), Box> { offer!(s, { Branching4fromCtoS::Loop(s) => { let (_, s) = recv(s)?; endpoint_c_4(s) }, Branching4fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_5(s) }, }) } fn endpoint_c_5(s: EndpointC5) -> Result<(), Box> { offer!(s, { Branching5fromCtoS::Quit(s) => { let (_, s) = recv(s)?; close(s) }, Branching5fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_6(s) }, }) } fn endpoint_c_6(s: EndpointC6) -> Result<(), Box> { offer!(s, { Branching6fromCtoS::Loop(s) => { let (_, s) = recv(s)?; endpoint_c_6(s) }, Branching6fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_7(s) }, }) } fn endpoint_c_7(s: EndpointC7) -> Result<(), Box> { offer!(s, { Branching7fromCtoS::Quit(s) => { let (_, s) = recv(s)?; close(s) }, Branching7fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_8(s) }, }) } fn endpoint_c_8(s: EndpointC8) -> Result<(), Box> { offer!(s, { Branching8fromCtoS::Loop(s) => { let (_, s) = recv(s)?; endpoint_c_7(s) }, Branching8fromCtoS::Continue(s) => { let (_, s) = recv(s)?; endpoint_c_9(s) }, }) } fn endpoint_c_9(s: EndpointC9) -> Result<(), Box> { offer!(s, { Branching9fromCtoS::Loop(s) => { let (_, s) = recv(s)?; let (_, s) = recv(s)?; endpoint_c_9(s) }, Branching9fromCtoS::Continue(s) => { let (_, s) = recv(s)?; let (_, s) = recv(s)?; let (_, s) = recv(s)?; let (_, s) = recv(s)?; endpoint_c_10(s) }, }) } fn endpoint_c_10(s: EndpointC10) -> Result<(), Box> { offer!(s, { Branching10fromCtoS::Data(s) => { let (_, s) = recv(s)?; let (_, s) = recv(s)?; endpoint_c_10(s) }, Branching10fromCtoS::Subject(s) => { let (_, s) = recv(s)?; let (_, s) = recv(s)?; endpoint_c_10(s) }, Branching10fromCtoS::End(s) => { let (_, s) = recv(s)?; let (_, s) = recv(s)?; endpoint_c_7(s) }, }) } //////////////////////////// fn main() { let mut threads = Vec::new(); let mut sessions = Vec::new(); let (thread, session) = fork_with_thread_id(endpoint_c_init); let session = binary_s_init(session).unwrap(); threads.push(thread); sessions.push(session); let main = spawn(move || { for _ in 0..LOOPS { let choice = thread_rng().gen_range(1..=2); if choice != 1 { sessions = sessions .into_iter() .map(|s| recurs_data_s_10(s).unwrap()) .collect::>(); } else { sessions = sessions .into_iter() .map(|s| recurs_subject_s_10(s).unwrap()) .collect::>(); } } sessions.into_iter().for_each(|s| close_s_10(s).unwrap()); threads.into_iter().for_each(|elt| elt.join().unwrap()); }); main.join().unwrap(); } static LOOPS: i32 = 100;