~/bend-docscommunity

internal/core.bend checks

raw source on the hub · import 0xfcfaebefd5553d7c2403dcd5c4130b80/internal/core.bend as Core

1 import
import Base

Types

type W64 source · line 12 · raw

Data

64-bit word represented as two native U32 halves.

Definitions

def Bits.rotr32.norm source · line 18 · raw

@+x:U32 -> @n:Nat -> U32

def Bits.rotr32 source · line 27 · raw

@+x:U32 -> @n:Nat -> U32

Rotation counts are normalized modulo the word width. This keeps the helper total and safe for reuse outside the current hash constants.

def Bits.rotl32.norm source · line 30 · raw

@+x:U32 -> @n:Nat -> U32

def Bits.rotl32 source · line 37 · raw

@+x:U32 -> @n:Nat -> U32

def Bits.add3 source · line 40 · raw

@a:U32 -> @b:U32 -> @c:U32 -> U32

def Bits.add4 source · line 43 · raw

@a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> U32

def Bits.add5 source · line 46 · raw

@a:U32 -> @b:U32 -> @c:U32 -> @d:U32 -> @e:U32 -> U32

def W64.zero source · line 52 · raw

W64

def W64.from_nat source · line 57 · raw

@+n:Nat -> W64

Exact conversion for Bend Nat values that fit in 64 bits. Bend's current native runtime limit is below this, so every representable list length fits.

def W64.shl3 source · line 66 · raw

@x:W64 -> W64

Convert a byte count to a 64-bit bit count without first multiplying in Nat. This matters near Bend's native Nat ceiling: n may be representable while n*8 is not, even though the 64-bit result is perfectly valid.

def W64.bits_from_bytes source · line 74 · raw

@n:Nat -> W64

def W64.xor source · line 77 · raw

@+a:W64 -> @+b:W64 -> W64

def W64.and source · line 82 · raw

@+a:W64 -> @+b:W64 -> W64

def W64.or source · line 87 · raw

@+a:W64 -> @+b:W64 -> W64

def W64.not source · line 92 · raw

@a:W64 -> W64

def W64.add source · line 97 · raw

@+a:W64 -> @+b:W64 -> W64

def W64.add3 source · line 104 · raw

@a:W64 -> @b:W64 -> @c:W64 -> W64

def W64.add4 source · line 107 · raw

@a:W64 -> @b:W64 -> @c:W64 -> @d:W64 -> W64

def W64.add5 source · line 110 · raw

@a:W64 -> @b:W64 -> @c:W64 -> @d:W64 -> @e:W64 -> W64

def W64.swap source · line 114 · raw

@x:W64 -> W64

def W64.shr32 source · line 119 · raw

@x:W64 -> W64

def W64.shr.gt32 source · line 124 · raw

@x:W64 -> @n:Nat -> W64

def W64.rotr.lt32 source · line 129 · raw

@+x:W64 -> @+n:Nat -> W64

def W64.rotr.gt32 source · line 138 · raw

@+x:W64 -> @+n:Nat -> W64

def W64.rotr.ge32 source · line 148 · raw

@+x:W64 -> @+n:Nat -> @eq32:Bool -> W64

def W64.rotr.nonzero source · line 155 · raw

@+x:W64 -> @+n:Nat -> @lt:Bool -> W64

def W64.rotr.norm source · line 162 · raw

@+x:W64 -> @n:Nat -> W64

def W64.rotr source · line 169 · raw

@+x:W64 -> @n:Nat -> W64

def W64.rotl.norm source · line 172 · raw

@+x:W64 -> @n:Nat -> W64

def W64.rotl source · line 179 · raw

@+x:W64 -> @n:Nat -> W64

def W64.shr.lt32 source · line 182 · raw

@+x:W64 -> @+n:Nat -> W64

def W64.shr.mid source · line 190 · raw

@+x:W64 -> @+n:Nat -> @eq32:Bool -> W64

def W64.shr.ge32 source · line 197 · raw

@+x:W64 -> @+n:Nat -> @ge64:Bool -> W64

def W64.shr.nonzero source · line 204 · raw

@+x:W64 -> @+n:Nat -> @lt32:Bool -> W64

def W64.shr source · line 211 · raw

@+x:W64 -> @n:Nat -> W64

def Bytes.byte source · line 221 · raw

@x:U32 -> U32

def Bytes.length_nat.go source · line 224 · raw

@xs:List<&2, U32> -> @acc:Nat -> Nat

def Bytes.length_nat source · line 233 · raw

@xs:List<&2, U32> -> Nat

Tail-recursive length avoids linear call-stack growth on the JavaScript backend, where Base.List.length is structurally recursive on return.

def Bytes.utf8.three source · line 240 · raw

@+cp:U32 -> @tail:List<&2, U32> -> List<&2, U32>

Correct UTF-8 encoding. Invalid scalar values become U+FFFD in the raw scalar helper. Public text(...) receives Bend String values; a backend may reject an invalid Char before this library sees it.

def Bytes.utf8.four source · line 246 · raw

@+cp:U32 -> @tail:List<&2, U32> -> List<&2, U32>

def Bytes.utf8.bmp source · line 253 · raw

@+cp:U32 -> @tail:List<&2, U32> -> @surrogate:Bool -> List<&2, U32>

def Bytes.utf8.u21 source · line 260 · raw

@+cp:U32 -> @tail:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.u16 source · line 267 · raw

@+cp:U32 -> @tail:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.u11 source · line 278 · raw

@+cp:U32 -> @tail:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.u7 source · line 287 · raw

@+cp:U32 -> @tail:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.code source · line 294 · raw

@+cp:U32 -> @tail:List<&2, U32> -> List<&2, U32>

def Bytes.utf8.rev.three source · line 300 · raw

@+cp:U32 -> @acc:List<&2, U32> -> List<&2, U32>

Reverse-order encoder used by the tail-recursive String traversal. Each scalar is prepended in reverse byte order; one final List.reverse restores the complete UTF-8 byte stream.

def Bytes.utf8.rev.four source · line 306 · raw

@+cp:U32 -> @acc:List<&2, U32> -> List<&2, U32>

def Bytes.utf8.rev.bmp source · line 313 · raw

@+cp:U32 -> @acc:List<&2, U32> -> @surrogate:Bool -> List<&2, U32>

def Bytes.utf8.rev.u21 source · line 320 · raw

@+cp:U32 -> @acc:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.rev.u16 source · line 327 · raw

@+cp:U32 -> @acc:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.rev.u11 source · line 338 · raw

@+cp:U32 -> @acc:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.rev.u7 source · line 347 · raw

@+cp:U32 -> @acc:List<&2, U32> -> @le:Bool -> List<&2, U32>

def Bytes.utf8.rev.code source · line 354 · raw

@+cp:U32 -> @acc:List<&2, U32> -> List<&2, U32>

def Bytes.utf8.go source · line 357 · raw

@s:String -> @acc:List<&2, U32> -> List<&2, U32>

def Bytes.utf8 source · line 364 · raw

@s:String -> List<&2, U32>

def Hex.nibble.if source · line 368 · raw

@x:U32 -> @low:Bool -> Char

Lower-case hexadecimal.

def Hex.nibble source · line 375 · raw

@+x:U32 -> Char

def Hex.bytes.go source · line 378 · raw

@xs:List<&2, U32> -> @acc:String -> String

def Hex.bytes source · line 393 · raw

@xs:List<&2, U32> -> String

def Bytes.u32be source · line 397 · raw

@+x:U32 -> @tail:List<&2, U32> -> List<&2, U32>

Prefix a U32 to a byte list in either endian order.

def Bytes.u32le source · line 404 · raw

@+x:U32 -> @tail:List<&2, U32> -> List<&2, U32>

def Bytes.u64be source · line 411 · raw

@x:W64 -> @tail:List<&2, U32> -> List<&2, U32>

def Bytes.u64le source · line 416 · raw

@x:W64 -> @tail:List<&2, U32> -> List<&2, U32>

def Bytes.at source · line 423 · raw

@+xs:List<&2, U32> -> @n:Nat -> U32

Random-access byte/word reads. Indexes outside the list read as zero. Hash algorithms only use fixed, in-range offsets on complete padded blocks.

def Bytes.u32be_at source · line 426 · raw

@+xs:List<&2, U32> -> @+n:Nat -> U32

def Bytes.u32le_at source · line 431 · raw

@+xs:List<&2, U32> -> @+n:Nat -> U32

def Bytes.u64be_at source · line 436 · raw

@+xs:List<&2, U32> -> @+n:Nat -> W64

def Bytes.u64le_at source · line 439 · raw

@+xs:List<&2, U32> -> @+n:Nat -> W64

def Words32.block_be.go source · line 442 · raw

@+xs:List<&2, U32> -> @n:Nat -> @+i:Nat -> @acc:List<&2, U32> -> List<&2, U32>

def Words32.block_be source · line 449 · raw

@xs:List<&2, U32> -> @n:Nat -> List<&2, U32>

def Words32.block_le.go source · line 452 · raw

@+xs:List<&2, U32> -> @n:Nat -> @+i:Nat -> @acc:List<&2, U32> -> List<&2, U32>

def Words32.block_le source · line 459 · raw

@xs:List<&2, U32> -> @n:Nat -> List<&2, U32>

def Words64.block_be.go source · line 462 · raw

@+xs:List<&2, U32> -> @n:Nat -> @+i:Nat -> @acc:List<&2, W64> -> List<&2, W64>

def Words64.block_be source · line 469 · raw

@xs:List<&2, U32> -> @n:Nat -> List<&2, W64>

def Words64.block_le.go source · line 472 · raw

@+xs:List<&2, U32> -> @n:Nat -> @+i:Nat -> @acc:List<&2, W64> -> List<&2, W64>

def Words64.block_le source · line 479 · raw

@xs:List<&2, U32> -> @n:Nat -> List<&2, W64>

def Bytes.zeros source · line 483 · raw

@n:U32 -> List<&2, U32>

Fixed-size zero lists used only for padding; n is always small.

def Words32.get source · line 488 · raw

@+xs:List<&2, U32> -> @n:Nat -> U32

Extract a reusable list element with a defined zero default. Internal callers only use in-range fixed indexes; the default prevents partial functions.

def Words64.get source · line 491 · raw

@+xs:List<&2, W64> -> @n:Nat -> W64