1 # src/stop: a Stop done (Args.out's decision to print and exit): a text on 2 # its stream, then the exit code. Pure but for the IO it returns, and apart 3 # from main.bend, so its laws (the root LAWS.bend) reach no foreign code. 4 import Base 5 import ./args.bend as Args 6 7 # a text on its stream 8 def say(to: Args.Stream, text: String) -> IO(Unit): 9 match to: 10 case Args.Line{}: 11 IO.print(text) 12 case Args.Page{}: 13 IO.write(text) 14 case Args.Err{}: 15 IO.print_err(text) 16 17 def leave.at(zero: Bool, code: U32) -> IO(Unit): 18 match zero: 19 case True{}: 20 IO.pure(Unit, Unit{}) 21 case False{}: 22 IO.die(Unit, code, "") 23 24 # exit with a code: 0 falls through, any other ends the run with it 25 def leave(+code: U32) -> IO(Unit): 26 leave.at(U32.is_eq(code, 0), code)