~/bend-docscommunity

words.bend relies on unsafe/foreign

raw source on the hub · import gralha-byte-words@0.1.0.0/words.bend as Words

gralha-byte-words: bytes packed four to a U32 word, little-endian, in an Array<U32>, the layer the gralha codecs share. byte_at and le32_at read a byte or a four-byte window at any offset; Sink is a growing output buffer (put_byte, put_str, put_le32, put_zeros, reserve, skip); the effects under effs/ move packed words to and from files without a byte-per-cell detour (read, write, fill_at, append, copy_range, file_read_at, sink_write, open_out, file_size).

1 import
import Base

Types

type Gr source · line 38 · raw

Type

type Chunk source · line 218 · raw

Type

type Sink source · line 258 · raw

Type

Definitions

def b2u source · line 10 · raw

@b:Bool -> U32

def fit source · line 21 · raw

@n:Nat -> @+d:U32 -> @+need:U32 -> @ok:Bool -> U32

the smallest depth d with 2^d >= need

def depth_for source · line 30 · raw

@+need:U32 -> Nat

def gr_put source · line 41 · raw

@r:Pair(Array<U32>, U32) -> @dst:Array<U32> -> @+i:U32 -> Gr

def gr_loop source · line 45 · raw

@n:Nat -> @st:Gr -> @+i:U32 -> Gr

def gr_dst source · line 52 · raw

@st:Gr -> Array<U32>

def grow source · line 57 · raw

@out:Array<U32> -> @+cap:U32 -> Array<U32>

def ensure source · line 61 · raw

@n:Nat -> @out:Array<U32> -> @+cap:U32 -> @+need:U32 -> @ok:Bool -> Pair(Array<U32>, U32)

(out, cap) with cap >= need; ok says it already is

def room source · line 70 · raw

@out:Array<U32> -> @+cap:U32 -> @+need:U32 -> Pair(Array<U32>, U32)

def w4_hi source · line 79 · raw

@r:Pair(Array<U32>, U32) -> @+lo:U32 -> @+sh:U32 -> Pair(Array<U32>, U32)

def w4_lo source · line 83 · raw

@r:Pair(Array<U32>, U32) -> @+q:U32 -> @+sh:U32 -> Pair(Array<U32>, U32)

def le32_at source · line 88 · raw

@a:Array<U32> -> @+j:U32 -> Pair(Array<U32>, U32)

the four bytes from j, j lowest

def wb_of source · line 91 · raw

@r:Pair(Array<U32>, U32) -> @+sh:U32 -> Pair(Array<U32>, U32)

def byte_at source · line 96 · raw

@a:Array<U32> -> @+j:U32 -> Pair(Array<U32>, U32)

the byte at j

def fail source · line 139 · raw

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

def read_got source · line 143 · raw

@what:String -> @r:Result<&1, &1, Pair(U32, String), Pair(Array<U32>, U32)> -> IO(Pair(Array<U32>, U32))

def read source · line 152 · raw

@+path:String -> IO(Pair(Array<U32>, U32))

def size_got source · line 157 · raw

@what:String -> @r:Result<&1, &1, Pair(U32, String), U32> -> IO(U32)

def wr_done source · line 166 · raw

@what:String -> @r:Pair(Array<U32>, Result<&1, &1, Pair(U32, String), Unit>) -> IO(Array<U32>)

def write source · line 177 · raw

@+path:String -> @a:Array<U32> -> @+start:U32 -> @+n:U32 -> IO(Array<U32>)

n bytes of a from byte start; the words come back

def fill_at source · line 182 · raw

@+path:String -> @+file_off:U32 -> @a:Array<U32> -> @+start:U32 -> @+n:U32 -> IO(Array<U32>)

def drop source · line 187 · raw

@a:Array<U32> -> IO(Unit)

def open_got source · line 190 · raw

@what:String -> @r:Result<&1, &1, Pair(U32, String), File> -> IO(File)

def open_out source · line 199 · raw

@+path:String -> IO(File)

def size_close source · line 204 · raw

@what:String -> @r:Pair(File, Result<&1, &1, Pair(U32, String), U32>) -> IO(U32)

def file_size source · line 211 · raw

@+path:String -> IO(U32)

a member's byte count, read off its open handle

def file_read_got source · line 221 · raw

@what:String -> @r:Pair(File, Result<&1, &1, Pair(U32, String), Pair(Array<U32>, U32)>) -> IO(Chunk)

def file_write_got source · line 232 · raw

@what:String -> @r:Pair(File, Pair(Array<U32>, Result<&1, &1, Pair(U32, String), Unit>)) -> IO(File)

def append source · line 246 · raw

@+path:String -> @a:Array<U32> -> @+header_n:U32 -> @+input:String -> @+pad_n:U32 -> @first:Bool -> IO(Unit)

def sink_write source · line 261 · raw

@+path:String -> @file:File -> @st:Sink -> IO(File)

def sink_new source · line 268 · raw

Sink

def ob_fit source · line 271 · raw

@r:Pair(Array<U32>, U32) -> @+pos:U32 -> Sink

def ob_room source · line 276 · raw

@a:Array<U32> -> @+cap:U32 -> @+pos:U32 -> @+need:U32 -> Sink

room for bytes up to need

def ob_or source · line 279 · raw

@r:Pair(Array<U32>, U32) -> @+cap:U32 -> @+pos:U32 -> @+b:U32 -> Sink

def ob_byte_at source · line 283 · raw

@st:Sink -> @+b:U32 -> Sink

def put_byte source · line 289 · raw

@st:Sink -> @+b:U32 -> Sink

def ow_split source · line 295 · raw

@a:Array<U32> -> @+q:U32 -> @+v:U32 -> @+sh:U32 -> @split:Bool -> Array<U32>

def ob_word_got source · line 302 · raw

@r:Pair(Array<U32>, U32) -> @+cap:U32 -> @+pos:U32 -> @+q:U32 -> @+sh:U32 -> @+v:U32 -> Sink

def put_word_at source · line 309 · raw

@st:Sink -> @+v:U32 -> Sink

Four bytes into a previously reserved output range. The destination may be unaligned; its already-written low bytes are preserved and the high spill becomes the prefix of the next word.

def reserve source · line 317 · raw

@st:Sink -> @+n:U32 -> Sink

def put_str source · line 324 · raw

@s:String -> @st:Sink -> Sink

n bytes of a string

def skip source · line 332 · raw

@st:Sink -> @+n:U32 -> Sink

n zero bytes: the room is zero already

def put_zeros source · line 337 · raw

@st:Sink -> @+n:U32 -> Sink

def put_le32 source · line 343 · raw

@ob:Sink -> @+v:U32 -> Sink

Effects (foreign code)

effect read_raw source · line 107 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), Pair(Array<U32>, U32)>)

foreign: effs/words_read.c, effs/words_read.js

effect write_raw source · line 111 · raw

@path:String -> @a:Array<U32> -> @+start:U32 -> @+n:U32 -> IO(Pair(Array<U32>, Result<&1, &1, Pair(U32, String), Unit>))

foreign: effs/words_write.c, effs/words_write.js

effect fill_at_raw source · line 115 · raw

@path:String -> @+file_off:U32 -> @a:Array<U32> -> @+start:U32 -> @+n:U32 -> IO(Pair(Array<U32>, Result<&1, &1, Pair(U32, String), Unit>))

foreign: effs/words_fill_at.c, effs/words_fill_at.js

effect append_raw source · line 119 · raw

@path:String -> @a:Array<U32> -> @+header_n:U32 -> @input:String -> @+pad_n:U32 -> @+first:U32 -> IO(Pair(Array<U32>, Result<&1, &1, Pair(U32, String), Unit>))

foreign: effs/stream_append.c, effs/stream_append.js

effect copy_range source · line 123 · raw

@src:Array<U32> -> @+src_at:U32 -> @dst:Array<U32> -> @+dst_at:U32 -> @+n:U32 -> IO(Pair(Array<U32>, Array<U32>))

foreign: effs/words_copy_range.c, effs/words_copy_range.js

effect file_write_raw source · line 127 · raw

@file:File -> @a:Array<U32> -> @+start:U32 -> @+n:U32 -> IO(Pair(File, Pair(Array<U32>, Result<&1, &1, Pair(U32, String), Unit>)))

foreign: effs/file_words_write.c, effs/file_words_write.js

effect file_read_at_raw source · line 131 · raw

@file:File -> @+offset:U32 -> @+max:U32 -> IO(Pair(File, Result<&1, &1, Pair(U32, String), Pair(Array<U32>, U32)>))

foreign: effs/file_words_read_at.c, effs/file_words_read_at.js

effect open_out_raw source · line 135 · raw

@path:String -> IO(Result<&1, &1, Pair(U32, String), File>)

foreign: effs/output_open.c, effs/output_open.js