Module("system/posix/process-abstractions",[Imports([Import("system/posix/process"),Import("system/posix/signal"),Import("util/log")]),Strategies([SDef("fork",[DefaultVarDec("child")],Call(SVar("fork"),[CallNoArgs(SVar("child")),Id])),SDef("fork",[DefaultVarDec("child"),DefaultVarDec("parent")],Seq(Match(Var("t")),Seq(CallNoArgs(SVar("fork")),Seq(Match(Var("pid")),GuardedLChoice(Match(NoAnnoList(Int("0"))),BA(CallNoArgs(SVar("child")),Var("t")),BA(CallNoArgs(SVar("parent")),NoAnnoList(Tuple([Var("pid"),Var("t")])))))))),SDef("fork-and-wait",[DefaultVarDec("child")],Call(SVar("fork"),[CallNoArgs(SVar("child")),Seq(Match(NoAnnoList(Tuple([RootApp(CallNoArgs(SVar("waitpid"))),Var("t")]))),Seq(CallNoArgs(SVar("warn-ifsignaled")),Seq(Match(NoAnnoList(Op("WaitStatus",[NoAnnoList(Int("0")),Wld,Wld]))),Build(Var("t")))))]))]),Strategies([SDefNoArgs("call",Call(SVar("call"),[Id])),SDef("call",[DefaultVarDec("init-child")],Seq(Match(NoAnnoList(Tuple([Var("prog"),Var("args")]))),Call(SVar("fork-and-wait"),[Seq(CallNoArgs(SVar("init-child")),Seq(BA(CallNoArgs(SVar("execvp")),NoAnnoList(Tuple([Var("prog"),Var("args")]))),BA(CallNoArgs(SVar("exit")),NoAnnoList(Int("1")))))]))),SDefNoArgs("call-noisy",Seq(Match(NoAnnoList(Tuple([Var("prog"),Var("args")]))),Call(SVar("fork-and-wait"),[BA(Seq(CallNoArgs(SVar("debug")),CallNoArgs(SVar("execvp"))),NoAnnoList(Tuple([Var("prog"),Var("args")])))])))]),Strategies([SDefNoArgs("exited",Seq(Match(NoAnnoList(Op("WaitStatus",[Var("s"),Wld,Wld]))),Seq(Where(BA(Not(CallNoArgs(SVar("eq"))),NoAnnoList(Tuple([Var("s"),NoAnnoList(Int("-1"))])))),Call(SVar("if-verbose3"),[Call(SVar("debug"),[Build(NoAnnoList(Str("\"the process exited: \"")))])])))),SDefNoArgs("signaled",Seq(Match(NoAnnoList(Op("WaitStatus",[Wld,Var("s"),Wld]))),Seq(Where(BA(Not(CallNoArgs(SVar("eq"))),NoAnnoList(Tuple([Var("s"),NoAnnoList(Int("-1"))])))),Call(SVar("if-verbose2"),[Call(SVar("debug"),[Build(NoAnnoList(Str("\"the process was signaled\"")))])])))),SDefNoArgs("stopped",Seq(Match(NoAnnoList(Op("WaitStatus",[Wld,Wld,Var("s")]))),Seq(Where(BA(Not(CallNoArgs(SVar("eq"))),NoAnnoList(Tuple([Var("s"),NoAnnoList(Int("-1"))])))),Call(SVar("if-verbose3"),[Call(SVar("debug"),[Build(NoAnnoList(Str("\"the process stopped\"")))])])))),SDefNoArgs("warn-ifsignaled",Where(Call(SVar("try"),[Seq(Match(NoAnnoList(Op("WaitStatus",[Wld,RootApp(Id),Wld]))),Seq(Not(Match(NoAnnoList(Int("-1")))),Seq(CallNoArgs(SVar("signal-from-number")),Seq(CallNoArgs(SVar("signal-to-descr")),CallT(SVar("log"),[],[NoAnnoList(Op("Warning",[])),App(CallNoArgs(SVar("concat-strings")),NoAnnoList(List([NoAnnoList(Str("\"process signaled: \"")),RootApp(Id)])))])))))]))),SDefT("call",[],[DefaultVarDec("opt-fdin"),DefaultVarDec("opt-fdout"),DefaultVarDec("opt-fderr")],Seq(Match(NoAnnoList(Tuple([Var("prog"),Var("args")]))),Seq(Call(SVar("fork-and-wait"),[Seq(BA(Call(SVar("option"),[BA(CallNoArgs(SVar("dup2")),NoAnnoList(Tuple([RootApp(Id),RootApp(CallNoArgs(SVar("STDIN_FILENO")))])))]),Var("opt-fdin")),Seq(BA(Call(SVar("option"),[BA(CallNoArgs(SVar("dup2")),NoAnnoList(Tuple([RootApp(Id),RootApp(CallNoArgs(SVar("STDOUT_FILENO")))])))]),Var("opt-fdout")),Seq(BA(Call(SVar("option"),[BA(CallNoArgs(SVar("dup2")),NoAnnoList(Tuple([RootApp(Id),RootApp(CallNoArgs(SVar("STDERR_FILENO")))])))]),Var("opt-fderr")),Seq(BA(CallNoArgs(SVar("execvp")),NoAnnoList(Tuple([Var("prog"),Var("args")]))),BA(CallNoArgs(SVar("exit")),NoAnnoList(Int("1")))))))]),Build(NoAnnoList(Tuple([]))))))])])
