src/sys.bend relies on unsafe/foreign
raw source on the hub · import ezsys@0.1.0.0/src/sys.bend as Sys
ezsys/src/sys: the effects. Every decision these make is src/step.bend's, src/clock.bend's or src/dir.bend's; this module runs the effects in order and acts on the answers (SYS-TRUST-4). The three effects of its own are foreign code, a C file and its JS twin each: a flush-and-rename (SYS-TRUST-1), the wall clock (SYS-TRUST-2) and a directory's names (SYS-TRUST-5).
4 imports
import Base import ./step.bend as Step import ./clock.bend as Clock import ./dir.bend as Dir
Definitions
def sys.read.fuel source · line 33 · raw
Nat
reads one file.read makes at most
def sys.read.end source · line 37 · raw
@file:File -> @answer:Result<&1, &1, Pair(U32, String), String> -> IO(Result<&1, &1, Pair(U32, String), String>)
close the file, then answer
def sys.read.next source · line 45 · raw
@file:File -> @step:0x8abe7473e8854cc69c687ee77b7d72e3/src/step.Read -> @rest:(@_:File -> @_:String -> IO(Result<&1, &1, Pair(U32, String), String>)) -> IO(Result<&1, &1, Pair(U32, String), String>)
act on one read's step: read on, or close and answer
def sys.read.un source · line 57 · raw
@got:String -> @rest:(@_:File -> @_:String -> IO(Result<&1, &1, Pair(U32, String), String>)) -> @pair:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(Result<&1, &1, Pair(U32, String), String>)
unpack a read's file and answer
def sys.read.go source · line 66 · raw
@fuel:Nat -> @file:File -> @got:String -> @+chunk:U32 -> IO(Result<&1, &1, Pair(U32, String), String>)
read chunks until an empty one; fuel first, so the call is a decreasing one
def sys.read.sized source · line 82 · raw
@pair:Pair(File, Result<&1, &1, Pair(U32, String), U32>) -> IO(Result<&1, &1, Pair(U32, String), String>)
the file's size decides the chunk; a failed size is the answer
def sys.read.opened source · line 93 · raw
@res:Result<&1, &1, Pair(U32, String), File> -> IO(Result<&1, &1, Pair(U32, String), String>)
an opened file is sized and read; a failed open is the answer
def sys.read source · line 104 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), String>)
a whole file's text
def sys.write.done source · line 110 · raw
@pair:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Result<&1, &1, Pair(U32, String), Unit>)
close the file, then answer the write's result
def sys.write.opened source · line 118 · raw
@text:String -> @res:Result<&1, &1, Pair(U32, String), File> -> IO(Result<&1, &1, Pair(U32, String), Unit>)
write to an opened file; a failed open is the answer
def sys.write source · line 131 · raw
@path:String -> @text:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
a file's whole text replaced (created when missing)
def sys.save.next source · line 140 · raw
@+path:String -> @step:0x8abe7473e8854cc69c687ee77b7d72e3/src/step.Save -> IO(Result<&1, &1, Pair(U32, String), Unit>)
rename the written temporary file, or answer the write's failure
def sys.save source · line 151 · raw
@+path:String -> @text:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
write <path>.tmp, then rename it over path
def sys.env source · line 160 · raw
@name:String -> @fallback:String -> IO(String)
an environment variable, or the fallback when it is unset
def sys.now_iso source · line 165 · raw
IO(String)
the wall clock's ISO 8601 UTC text
def sys.list source · line 170 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), List<&2, String>>)
a directory's names, less "." and "..", sorted; a failed read is the answer
Effects (foreign code)
effect ezsys.rename source · line 13 · raw
@from:String -> @to:String -> IO(Result<&1, &1, Pair(U32, String), Unit>)
flush from to disk, then rename it over to
foreign: src/effs/rename.c, src/effs/rename.js
effect ezsys.clock source · line 21 · raw
IO(Pair(U32, U32))
whole seconds since 1970-01-01T00:00:00Z and the milliseconds past them
foreign: src/effs/clock.c, src/effs/clock.js
effect ezsys.list source · line 26 · raw
@path:String -> IO(Result<&1, &1, Pair(U32, String), List<&2, String>>)
the names in a directory as the host lists them, in its order
foreign: src/effs/dir.c, src/effs/dir.js