impl.bend relies on unsafe/foreign
raw source on the hub · import bend-stdio-pipes@0.2.0.0/impl.bend as Impl
Pipes to a started program, and this program's stdin, as Files of UTF-8 lines. A POLYFILL: Bend has no pipes to a started program, no way to kill one, and no stdin handle yet. Delete this module when Base has them, and call Base instead. A line has at most max bytes with its LF or CRLF: a longer one fails with E2BIG (7).
1 import
import Base
Definitions
def read_line.peeked source · line 34 · raw
@next:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> @text:String -> Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>)
A line with no LF that ends the input is the last line; one that does not is too long.
def read_line.unended source · line 48 · raw
@+piece:String -> String
The line of a piece that ends with its LF: the piece without the LF, and the CR before it, if any.
def read_line.if source · line 57 · raw
@file:File -> @ended:Bool -> @piece:String -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>))
def read_line.got source · line 73 · raw
@got:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>))
def read_line source · line 86 · raw
@file:File -> @max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Maybe<&1, String>>))
The next line of file, as it comes, without its LF or CRLF; None at the end of the file.
def write_lines.text source · line 94 · raw
@lines:List<&1, String> -> String
def write_lines source · line 102 · raw
@file:File -> @lines:List<&1, String> -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Unit>))
Writes each line to file, with its LF.
Effects (foreign code)
effect stdin source · line 11 · raw
IO(File)
This program's stdin. A File owns its descriptor: ask for it once.
foreign: std.c, std.js
effect open source · line 19 · raw
@program:String -> @args:List<&1, String> -> IO(Result<&1, &1, Pair(U32, String), Pair(U32, Pair(File, File))>)
Start a program, with its stdin and stdout as pipes: its process id, the File that writes its stdin, and the File that reads its stdout. Its stderr is ours. Closing the stdin File gives it EOF; nothing waits for it to exit. On JS, it runs on Bun on Linux and macOS only; elsewhere it fails with ENOSYS.
foreign: open.c, open.js
effect kill source · line 29 · raw
@pid:U32 -> IO(Result<&1, &1, Pair(U32, String), Unit>)
Kills the program that open started with pid, unless it has ended: then it fails with ESRCH (3). It never kills a program that open did not start, though the system gives an ended program's pid to another one.
foreign: open.c, open.js