~/bend-docscommunity

run.bend relies on unsafe/foreign

raw source on the hub · import cli@0.3.0.0/run.bend as Run

Purpose: the public IO shell: probes the host, runs Cli.eval, writes its output, calls act and exits (§7). The host effects live in sys.c and sys.js; no law imports this file (F1). Expected output: SOME PROOFS FAIL, listing only the defs that rely on sys.c and sys.js (F1, G2). Run: bend run.bend --check-only

2 imports
import Base
import ./cli.bend as Cli

Definitions

def exit_when source · line 26 · raw

@zero:Bool -> @code:U32 -> IO(Unit)

def exit source · line 33 · raw

@+code:U32 -> IO(Unit)

0 returns, so work started with IO.fork can finish; any other code flushes stdout and ends the process at once.

def chomp_end source · line 36 · raw

@newline:Bool -> @c:Char -> String

def chomp_from source · line 42 · raw

@t:String -> @+c:Char -> String

c then t, less one final "\n".

def chomp source · line 48 · raw

@s:String -> String

s less one final "\n": IO.print_err adds it back.

def write_out source · line 53 · raw

@empty:Bool -> @out:String -> IO(Unit)

def write_err source · line 58 · raw

@empty:Bool -> @err:String -> IO(Unit)

def finish source · line 64 · raw

@code:U32 -> @+out:String -> @+err:String -> IO(Unit)

§7.2 step 4: out to stdout and err to stderr, each if not empty, then exit.

def var_found source · line 70 · raw

@name:String -> @got:Result<&1, &1, Pair(U32, String), String> -> List<&2, 0xb33f58fff370c320dce638f3937c166b/cli.Var>

def var_read source · line 76 · raw

@set:Bool -> @+name:String -> IO(List<&2, 0xb33f58fff370c320dce638f3937c166b/cli.Var>)

def read_vars source · line 86 · raw

@names:List<&2, String> -> IO(List<&2, 0xb33f58fff370c320dce638f3937c166b/cli.Var>)

Each set variable among names, in order. Sys.has_env tests first, since IO.get_env's failure on an unset name costs about 6 ms under Bun.

def host source · line 98 · raw

@c:0xb33f58fff370c320dce638f3937c166b/cli.Cmd -> IO(0xb33f58fff370c320dce638f3937c166b/cli.Host)

§7.3: the variables c reads, whether stdout and stderr are TTYs, and their columns; Cli.probe decides the rest.

def argv_list source · line 108 · raw

@args:List<&1, List<&2, U32>> -> List<&2, String>

def argv_of source · line 115 · raw

@args:List<&1, List<&2, U32>> -> List<&2, String>

IO.args_bytes without its head, the program as invoked, each argument decoded by Cli.arg_text, so Cli.arg_bytes gives back its bytes.

def ended source · line 121 · raw

@r:Pair(U32, String) -> IO(Unit)

§7.2 step 5: act's code, mapped by Cli.act_exit.

def wrote source · line 142 · raw

@r:0xb33f58fff370c320dce638f3937c166b/cli.Ran -> IO(Unit)

Templates

template stepped source · line 125 · raw

@-A:Type -> @-act:(@+t:0xb33f58fff370c320dce638f3937c166b/cli.Term -> @_:A -> IO(U32)) -> @s:0xb33f58fff370c320dce638f3937c166b/cli.Step<A> -> IO(Unit)

template main source · line 135 · raw

@-A:Type -> @-decode:(@+m:0xb33f58fff370c320dce638f3937c166b/cli.Matches -> 0xb33f58fff370c320dce638f3937c166b/cli.Dec(A)) -> @-act:(@+t:0xb33f58fff370c320dce638f3937c166b/cli.Term -> @_:A -> IO(U32)) -> @+c:0xb33f58fff370c320dce638f3937c166b/cli.Cmd -> IO(Unit)

§7.2: an app's whole main.

template planned source · line 149 · raw

@-A:Type -> @-decode:(@+m:0xb33f58fff370c320dce638f3937c166b/cli.Matches -> 0xb33f58fff370c320dce638f3937c166b/cli.Dec(A)) -> @-plan:(@+t:0xb33f58fff370c320dce638f3937c166b/cli.Term -> @_:A -> 0xb33f58fff370c320dce638f3937c166b/cli.Ran) -> @+c:0xb33f58fff370c320dce638f3937c166b/cli.Cmd -> IO(Unit)

§7.2: the whole main of an app whose action is a pure plan: Cli.invoke's run on the host and argv, written out, so a law on Cli.invoke states what the app prints and exits with.

Effects (foreign code)

effect Sys.isatty source · line 12 · raw

@fd:U32 -> IO(U32)

1 if fd is a terminal, else 0.

foreign: sys.c, sys.js

effect Sys.columns source · line 17 · raw

@fd:U32 -> IO(U32)

fd's terminal width in columns, or 0 if it has none.

foreign: sys.c, sys.js

effect Sys.has_env source · line 22 · raw

@name:String -> IO(U32)

1 if the variable name is set, else 0.

foreign: sys.c, sys.js