1///|
2/// This package is based on the Go implementation found here:
3/// https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/crypto/sha1/sha1.go
4/// which has the copyright notice:
5/// Copyright 2009 The Go Authors. All rights reserved.
6/// Use of this source code is governed by a BSD-style
7/// license that can be found in the LICENSE file.
8
9// The size of a sha1 checksum in bytes.
10let 
Int

This package is based on the Go implementation found here: https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/crypto/sha1/sha1.go which has the copyright notice: Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

size
= 20
11 12///| 13/// The blocksize of sha1 in bytes. 14let
Int

The blocksize of sha1 in bytes.

block_size
= 64
15 16///| 17let
Int
chunk
= 64
18 19///| 20let
UInt
init0
= 0x67452301U
21 22///| 23let
UInt
init1
= 0xEFCDAB89U
24 25///| 26let
UInt
init2
= 0x98BADCFEU
27 28///| 29let
UInt
init3
= 0x10325476U
30 31///| 32let
UInt
init4
= 0xC3D2E1F0U
33 34///| 35/// `Digest` represents the partial evaluation of a checksum. 36struct Digest { 37
FixedArray[UInt]
h
:
type FixedArray[A]
FixedArray
[
UInt
UInt
] // 5
38
FixedArray[Byte]
x
:
type FixedArray[A]
FixedArray
[
Byte
Byte
] // chunk
39 mut
Int
nx
:
Int
Int
40 mut
UInt64
len
:
UInt64
UInt64
41} 42 43///| 44/// `Digest::new` returns a new, reset Digest, ready to sum. 45pub fn
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
::
() -> Digest

Digest::new returns a new, reset Digest, ready to sum.

new
() ->
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
{
46 { 47
FixedArray[UInt]
h
:
type FixedArray[A]
FixedArray
::
(array : Array[UInt]) -> FixedArray[UInt]

Creates a new fixed-size array from a dynamic array. The resulting fixed array will have the same length and elements as the input array.

Parameters:

  • array : A dynamic array containing elements of type T that will be converted to a fixed array.

Returns a new fixed array containing the same elements as the input array.

Example:

test "FixedArray::from_array" {
  let dynamic_array = [1, 2, 3, 4, 5]
  let fixed_array = FixedArray::from_array(dynamic_array)
  inspect(fixed_array, content="[1, 2, 3, 4, 5]")
}
from_array
([
UInt
init0
,
UInt
init1
,
UInt
init2
,
UInt
init3
,
UInt
init4
]),
48
FixedArray[Byte]
x
:
type FixedArray[A]
FixedArray
::
(len : Int, init : Byte) -> FixedArray[Byte]

Creates a new fixed-size array with the specified length, initializing all elements with the given value.

Parameters:

  • length : The length of the array to create. Must be non-negative.
  • initial_value : The value used to initialize all elements in the array.

Returns a new fixed-size array of type FixedArray[T] with length elements, where each element is initialized to initial_value.

Throws a panic if length is negative.

Example:

test "FixedArray::make" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[0], content="42")
  inspect(arr.length(), content="3")
}

test "panic FixedArray::make/negative_length" {
  ignore(FixedArray::make(-1, 0))
}

WARNING: A common pitfall is creating with the same initial value, for example:

test {
  let two_dimension_array = FixedArray::make(10, FixedArray::make(10, 0))
  two_dimension_array[0][5] = 10
  assert_eq(two_dimension_array[5][5], 10)
}

This is because all the cells reference to the same object (the FixedArray[Int] in this case). One should use makei() instead which creates an object for each index.

make
(
Int
chunk
, b'\x00'),
49
Int
nx
: 0,
50
UInt64
len
: 0,
51 } 52} 53 54///| 55/// `check_sum` returns the final sha1sum as a hex string. 56pub fn
(self : Digest) -> String

check_sum returns the final sha1sum as a hex string.

check_sum
(
Digest
self
:
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
) ->
String
String
{
57 let
FixedArray[Byte]
digest
=
Digest
self
.
(self : Digest) -> FixedArray[Byte]

sum returns the final sha1sum as a FixedArray[Byte].

sum
()
58 let
@buffer.T
result
=
(size_hint~ : Int) -> @buffer.T

Creates a new extensible buffer with specified initial capacity. If the initial capacity is less than 1, the buffer will be initialized with capacity 1.

Parameters:

  • size_hint : Initial capacity of the buffer in bytes. Defaults to 0.

Returns a new buffer of type T.

Example:

test "new" {
  let buf = @buffer.new(size_hint=10)
  inspect(buf.length(), content="0")
  buf.write_string("test")
  inspect(buf.length(), content="8")
}
@buffer.new
(
Int
size_hint
=2
(self : Int, other : Int) -> Int

Multiplies two 32-bit integers. This is the implementation of the * operator for Int.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns the product of the two integers. If the result overflows the range of Int, it wraps around according to two's complement arithmetic.

Example:

test "Int::op_mul" {
  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
}
*
Int

This package is based on the Go implementation found here: https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/crypto/sha1/sha1.go which has the copyright notice: Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

size
)
59 for
Byte
b
in
FixedArray[Byte]
digest
{
60
@buffer.T
result
.
(self : @buffer.T, value : Char) -> Unit

Writes a UTF-16LE encoded character into the buffer. Automatically grows the buffer if necessary.

Parameters:

  • buffer : The buffer to write to.
  • char : The character to be written.

Example:

test "write_char" {
  let buf = @buffer.new()
  buf.write_char('A')
  inspect(buf.contents(), content=
  #|b"\x41\x00"
)
}
write_char
(
(v : Int) -> Char
to_hex
((
Byte
b
.
(self : Byte) -> Int

Converts a byte value to a 32-bit signed integer. The resulting integer will have the same binary representation as the byte value, preserving the numerical value in the range [0, 255].

Parameters:

  • byte : The byte value to be converted to an integer.

Returns a 32-bit signed integer representing the same numerical value as the input byte.

Example:

test "Byte::to_int" {
  let b = b'\xFF' // byte with value 255
  inspect(b.to_int(), content="255")
  let zero = b'\x00'
  inspect(zero.to_int(), content="0")
}
to_int
()
(self : Int, other : Int) -> Int

Performs an arithmetic right shift operation on an integer value. Shifts the bits of the first operand to the right by the number of positions specified by the second operand. The sign bit is preserved and copied to the leftmost positions.

Parameters:

  • self : The integer value to be shifted.
  • shift : The number of positions to shift the bits to the right. Must be non-negative.

Returns an integer representing the result of the arithmetic right shift operation.

Example:

test "Int::op_shr" {
  let n = -16
  inspect(n >> 2, content="-4") // Sign bit is preserved during shift
  let p = 16
  inspect(p >> 2, content="4") // Regular right shift for positive numbers
}
>>
4)
(Int, Int) -> Int
&
0xf))
61
@buffer.T
result
.
(self : @buffer.T, value : Char) -> Unit

Writes a UTF-16LE encoded character into the buffer. Automatically grows the buffer if necessary.

Parameters:

  • buffer : The buffer to write to.
  • char : The character to be written.

Example:

test "write_char" {
  let buf = @buffer.new()
  buf.write_char('A')
  inspect(buf.contents(), content=
  #|b"\x41\x00"
)
}
write_char
(
(v : Int) -> Char
to_hex
(
Byte
b
.
(self : Byte) -> Int

Converts a byte value to a 32-bit signed integer. The resulting integer will have the same binary representation as the byte value, preserving the numerical value in the range [0, 255].

Parameters:

  • byte : The byte value to be converted to an integer.

Returns a 32-bit signed integer representing the same numerical value as the input byte.

Example:

test "Byte::to_int" {
  let b = b'\xFF' // byte with value 255
  inspect(b.to_int(), content="255")
  let zero = b'\x00'
  inspect(zero.to_int(), content="0")
}
to_int
()
(Int, Int) -> Int
&
0xf))
62 } 63
@buffer.T
result
.
(self : @buffer.T) -> Bytes

Returns a copy of the buffer's content as a sequence of bytes.

Parameters:

  • buffer : The buffer to read from.

Returns a Bytes object containing all bytes written to the buffer.

Example:

test "contents" {
  let buf = @buffer.new()
  buf.write_string("Test")
  inspect(
    buf.contents(),
    content=
      #|b"\x54\x00\x65\x00\x73\x00\x74\x00"
    ,
  )
}
contents
().
(self : Bytes, offset~ : Int = .., length~ : Int = ..) -> String

Return an unchecked string, containing the subsequence of self that starts at offset and has length length. Both offset and length are indexed by byte.

Note this function does not validate the encoding of the byte sequence, it simply copy the bytes into a new String.

to_unchecked_string
()
64} 65 66///| 67/// `sum` returns the final sha1sum as a `FixedArray[Byte]`. 68fn
(self : Digest) -> FixedArray[Byte]

sum returns the final sha1sum as a FixedArray[Byte].

sum
(
Digest
self
:
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
) ->
type FixedArray[A]
FixedArray
[
Byte
Byte
] {
69 // Padding. Add a 1 bit and 0 bits until 56 bytes mod 64. 70 let
FixedArray[Byte]
tmp
=
type FixedArray[A]
FixedArray
::
(len : Int, init : Byte) -> FixedArray[Byte]

Creates a new fixed-size array with the specified length, initializing all elements with the given value.

Parameters:

  • length : The length of the array to create. Must be non-negative.
  • initial_value : The value used to initialize all elements in the array.

Returns a new fixed-size array of type FixedArray[T] with length elements, where each element is initialized to initial_value.

Throws a panic if length is negative.

Example:

test "FixedArray::make" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[0], content="42")
  inspect(arr.length(), content="3")
}

test "panic FixedArray::make/negative_length" {
  ignore(FixedArray::make(-1, 0))
}

WARNING: A common pitfall is creating with the same initial value, for example:

test {
  let two_dimension_array = FixedArray::make(10, FixedArray::make(10, 0))
  two_dimension_array[0][5] = 10
  assert_eq(two_dimension_array[5][5], 10)
}

This is because all the cells reference to the same object (the FixedArray[Int] in this case). One should use makei() instead which creates an object for each index.

make
(64
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
8, b'\x00')
71
FixedArray[Byte]
tmp
[0] = b'\x80'
72 let
Int
t
= if
Digest
self
.
UInt64
len
(self : UInt64, other : UInt64) -> UInt64

Calculates the remainder of dividing one unsigned 64-bit integer by another.

Parameters:

  • self : The dividend unsigned 64-bit integer.
  • other : The divisor unsigned 64-bit integer.

Returns the remainder of the division operation.

Throws a panic if the divisor is zero.

Example:

test "UInt64::op_mod" {
  let a = 17UL
  let b = 5UL
  inspect(a % b, content="2") // 17 divided by 5 gives quotient 3 and remainder 2
  inspect(7UL % 4UL, content="3")
}

test "panic UInt64::op_mod/division_by_zero" {
  let a = 42UL
  ignore(a % 0UL) // Panics: division by zero
}
%
64
(self_ : UInt64, other : UInt64) -> Bool
<
56 {
73 (56UL
(self : UInt64, other : UInt64) -> UInt64

Performs subtraction between two unsigned 64-bit integers. When the result would be negative, the function wraps around using modular arithmetic (2^64).

Parameters:

  • self : The first unsigned 64-bit integer (minuend).
  • other : The second unsigned 64-bit integer to subtract from the first (subtrahend).

Returns the difference between the two numbers, wrapped around if necessary.

Example:

test "UInt64::op_sub" {
  let a = 5UL
  let b = 3UL
  inspect(a - b, content="2")
  let c = 3UL
  let d = 5UL
  inspect(c - d, content="18446744073709551614") // wraps around to 2^64 - 2
}
-
Digest
self
.
UInt64
len
(self : UInt64, other : UInt64) -> UInt64

Calculates the remainder of dividing one unsigned 64-bit integer by another.

Parameters:

  • self : The dividend unsigned 64-bit integer.
  • other : The divisor unsigned 64-bit integer.

Returns the remainder of the division operation.

Throws a panic if the divisor is zero.

Example:

test "UInt64::op_mod" {
  let a = 17UL
  let b = 5UL
  inspect(a % b, content="2") // 17 divided by 5 gives quotient 3 and remainder 2
  inspect(7UL % 4UL, content="3")
}

test "panic UInt64::op_mod/division_by_zero" {
  let a = 42UL
  ignore(a % 0UL) // Panics: division by zero
}
%
64).
(self : UInt64) -> Int

Converts an unsigned 64-bit integer to a 32-bit signed integer. The conversion truncates the value to fit within the 32-bit range, possibly losing information if the input value is too large.

Parameters:

  • self : The unsigned 64-bit integer to be converted.

Returns a 32-bit signed integer representing the lower 32 bits of the input value. If the input value is larger than the maximum value of a 32-bit signed integer (2147483647), the result will be the truncated value interpreted as a signed integer.

Example:

test "UInt64::to_int" {
  let a = 42UL
  inspect(a.to_int(), content="42")
  let b = 18446744073709551615UL // max value of UInt64
  inspect(b.to_int(), content="-1") // truncated to 32 bits
}
to_int
()
74 } else { 75 (64UL
(self : UInt64, other : UInt64) -> UInt64

Adds two 64-bit unsigned integers. This is the implementation of the + operator for UInt64.

Parameters:

  • self : The first unsigned 64-bit integer operand.
  • other : The second unsigned 64-bit integer operand.

Returns the sum of the two unsigned 64-bit integers. If the result overflows, it wraps around modulo 2^64.

Example:

test "UInt64::op_add" {
  let a = 42UL
  let b = 100UL
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 18446744073709551615UL
  inspect(max + 1UL, content="0")
}
+
56UL
(self : UInt64, other : UInt64) -> UInt64

Performs subtraction between two unsigned 64-bit integers. When the result would be negative, the function wraps around using modular arithmetic (2^64).

Parameters:

  • self : The first unsigned 64-bit integer (minuend).
  • other : The second unsigned 64-bit integer to subtract from the first (subtrahend).

Returns the difference between the two numbers, wrapped around if necessary.

Example:

test "UInt64::op_sub" {
  let a = 5UL
  let b = 3UL
  inspect(a - b, content="2")
  let c = 3UL
  let d = 5UL
  inspect(c - d, content="18446744073709551614") // wraps around to 2^64 - 2
}
-
Digest
self
.
UInt64
len
(self : UInt64, other : UInt64) -> UInt64

Calculates the remainder of dividing one unsigned 64-bit integer by another.

Parameters:

  • self : The dividend unsigned 64-bit integer.
  • other : The divisor unsigned 64-bit integer.

Returns the remainder of the division operation.

Throws a panic if the divisor is zero.

Example:

test "UInt64::op_mod" {
  let a = 17UL
  let b = 5UL
  inspect(a % b, content="2") // 17 divided by 5 gives quotient 3 and remainder 2
  inspect(7UL % 4UL, content="3")
}

test "panic UInt64::op_mod/division_by_zero" {
  let a = 42UL
  ignore(a % 0UL) // Panics: division by zero
}
%
64).
(self : UInt64) -> Int

Converts an unsigned 64-bit integer to a 32-bit signed integer. The conversion truncates the value to fit within the 32-bit range, possibly losing information if the input value is too large.

Parameters:

  • self : The unsigned 64-bit integer to be converted.

Returns a 32-bit signed integer representing the lower 32 bits of the input value. If the input value is larger than the maximum value of a 32-bit signed integer (2147483647), the result will be the truncated value interpreted as a signed integer.

Example:

test "UInt64::to_int" {
  let a = 42UL
  inspect(a.to_int(), content="42")
  let b = 18446744073709551615UL // max value of UInt64
  inspect(b.to_int(), content="-1") // truncated to 32 bits
}
to_int
()
76 } 77 78 // Length in bits. 79 let
UInt64
len
=
Digest
self
.
UInt64
len
(self : UInt64, shift : Int) -> UInt64

Performs a bitwise left shift operation on an unsigned 64-bit integer.

Parameters:

  • self : The unsigned 64-bit integer to be shifted.
  • shift : The number of positions to shift the bits to the left. Must be between 0 and 63 inclusive, values outside this range will be masked with & 63.

Returns the result of shifting self left by shift positions. For each position shifted, the rightmost bit is filled with 0, and the leftmost bit is discarded.

Example:

test "UInt64::op_shl" {
  let x = 1UL
  inspect(x << 3, content="8") // 1 shifted left by 3 positions becomes 8
  inspect(x << 63, content="9223372036854775808") // 1 shifted left by 63 positions
}
<<
3
80
(b : FixedArray[Byte], offset : Int, value : UInt64) -> Unit
be_put_uint64
(
FixedArray[Byte]
tmp
,
Int
t
,
UInt64
len
) // append length in bits
81 for
Int
i
= 0;
Int
i
(self_ : Int, other : Int) -> Bool
<
Int
t
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
8;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1 {
82 guard
Digest
self
.
(self : Digest, b : Byte) -> @io.IOError?

write_byte writes a byte to the digest.

write_byte
(
FixedArray[Byte]
tmp
(FixedArray[Byte], Int) -> Byte

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i]) is
@io.IOError?
None
83 } 84 85 // The previous write ensures that a whole number of 86 // blocks (i.e. a multiple of 64 bytes) have been hashed. 87 if
Digest
self
.
Int
nx
(x : Int, y : Int) -> Bool
!=
0 {
88
() -> Unit
panic
()
89 } 90 91 // Generate digest 92 let
FixedArray[Byte]
digest
=
type FixedArray[A]
FixedArray
::
(len : Int, init : Byte) -> FixedArray[Byte]

Creates a new fixed-size array with the specified length, initializing all elements with the given value.

Parameters:

  • length : The length of the array to create. Must be non-negative.
  • initial_value : The value used to initialize all elements in the array.

Returns a new fixed-size array of type FixedArray[T] with length elements, where each element is initialized to initial_value.

Throws a panic if length is negative.

Example:

test "FixedArray::make" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[0], content="42")
  inspect(arr.length(), content="3")
}

test "panic FixedArray::make/negative_length" {
  ignore(FixedArray::make(-1, 0))
}

WARNING: A common pitfall is creating with the same initial value, for example:

test {
  let two_dimension_array = FixedArray::make(10, FixedArray::make(10, 0))
  two_dimension_array[0][5] = 10
  assert_eq(two_dimension_array[5][5], 10)
}

This is because all the cells reference to the same object (the FixedArray[Int] in this case). One should use makei() instead which creates an object for each index.

make
(
Int

This package is based on the Go implementation found here: https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/crypto/sha1/sha1.go which has the copyright notice: Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

size
, b'\x00')
93
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
digest
, 0,
Digest
self
.
FixedArray[UInt]
h
[0])
94
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
digest
, 4,
Digest
self
.
FixedArray[UInt]
h
[1])
95
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
digest
, 8,
Digest
self
.
FixedArray[UInt]
h
[2])
96
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
digest
, 12,
Digest
self
.
FixedArray[UInt]
h
[3])
97
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
digest
, 16,
Digest
self
.
FixedArray[UInt]
h
[4])
98
FixedArray[Byte]
digest
99} 100 101///| 102/// `reset` resets a digest for re-use. 103pub fn
(self : Digest) -> Unit

reset resets a digest for re-use.

reset
(
Digest
self
:
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
) ->
Unit
Unit
{
104
Digest
self
.
FixedArray[UInt]
h
[0] =
UInt
init0
105
Digest
self
.
FixedArray[UInt]
h
[1] =
UInt
init1
106
Digest
self
.
FixedArray[UInt]
h
[2] =
UInt
init2
107
Digest
self
.
FixedArray[UInt]
h
[3] =
UInt
init3
108
Digest
self
.
FixedArray[UInt]
h
[4] =
UInt
init4
109
Digest
self
.
Int
nx
= 0
110
Digest
self
.
UInt64
len
= 0
111} 112 113///| 114let
&@io.Writer
_trait
: &
trait @io.Writer {
  write(Self, @io.Slice[Byte]) -> (Int, @io.IOError?)
}

Writer is the interface that wraps the basic Write method.

Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-None error if it returns n < len(p). Write must not modify the slice data, even temporarily.

Implementations must not retain p.

@io.Writer
=
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
::
() -> Digest

Digest::new returns a new, reset Digest, ready to sum.

new
()
115 116///| 117/// `write` writes a slice of bytes to the digest. 118pub impl
trait @io.Writer {
  write(Self, @io.Slice[Byte]) -> (Int, @io.IOError?)
}

Writer is the interface that wraps the basic Write method.

Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-None error if it returns n < len(p). Write must not modify the slice data, even temporarily.

Implementations must not retain p.

@io.Writer
for
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
with
(self : Digest, buf : @io.Slice[Byte]) -> (Int, @io.IOError?)

write writes a slice of bytes to the digest.

write
(
Digest
self
,
@io.Slice[Byte]
buf
) {
119 let mut
Int
count
= 0
120 for
Byte
b
in
@io.Slice[Byte]
buf
{
121 guard
Digest
self
.
(self : Digest, b : Byte) -> @io.IOError?

write_byte writes a byte to the digest.

write_byte
(
Byte
b
) is
@io.IOError?
None
else { break }
122
Int
count
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+=
1
123 } 124 (
Int
count
,
@io.IOError?
None
)
125} 126 127///| 128/// `write_byte` writes a byte to the digest. 129pub impl
trait @io.ByteWriter {
  write_byte(Self, Byte) -> @io.IOError?
}

ByteWriter is the interface that wraps the write_byte method.

@io.ByteWriter
for
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
with
(self : Digest, b : Byte) -> @io.IOError?

write_byte writes a byte to the digest.

write_byte
(
Digest
self
,
Byte
b
) {
130
Digest
self
.
UInt64
len
(self : UInt64, other : UInt64) -> UInt64

Adds two 64-bit unsigned integers. This is the implementation of the + operator for UInt64.

Parameters:

  • self : The first unsigned 64-bit integer operand.
  • other : The second unsigned 64-bit integer operand.

Returns the sum of the two unsigned 64-bit integers. If the result overflows, it wraps around modulo 2^64.

Example:

test "UInt64::op_add" {
  let a = 42UL
  let b = 100UL
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 18446744073709551615UL
  inspect(max + 1UL, content="0")
}
+=
1
131
Digest
self
.
FixedArray[Byte]
x
(FixedArray[Byte], Int, Byte) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
self.
Int
nx
] =
Byte
b
132
Digest
self
.
Int
nx
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+=
1
133 if
Digest
self
.
Int
nx
(self : Int, other : Int) -> Bool

Compares two integers for equality.

Parameters:

  • self : The first integer to compare.
  • other : The second integer to compare.

Returns true if both integers have the same value, false otherwise.

Example:

test "Int::op_equal" {
  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
}
==
Int

The blocksize of sha1 in bytes.

block_size
{
134
Digest
self
.
(self : Digest) -> Unit
block_generic
()
135
Digest
self
.
Int
nx
= 0
136 } 137
@io.IOError?
None
138} 139 140///| 141let
UInt
_K0
= 0x5A827999U
142 143///| 144let
UInt
_K1
= 0x6ED9EBA1U
145 146///| 147let
UInt
_K2
= 0x8F1BBCDCU
148 149///| 150let
UInt
_K3
= 0xCA62C1D6U
151 152///| 153fn
(self : Digest) -> Unit
block_generic
(
Digest
self
:
struct Digest {
  h: FixedArray[UInt]
  x: FixedArray[Byte]
  mut nx: Int
  mut len: UInt64
}

Digest represents the partial evaluation of a checksum.

Digest
) ->
Unit
Unit
{
154 let
FixedArray[UInt]
w
=
type FixedArray[A]
FixedArray
::
(len : Int, init : UInt) -> FixedArray[UInt]

Creates a new fixed-size array with the specified length, initializing all elements with the given value.

Parameters:

  • length : The length of the array to create. Must be non-negative.
  • initial_value : The value used to initialize all elements in the array.

Returns a new fixed-size array of type FixedArray[T] with length elements, where each element is initialized to initial_value.

Throws a panic if length is negative.

Example:

test "FixedArray::make" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[0], content="42")
  inspect(arr.length(), content="3")
}

test "panic FixedArray::make/negative_length" {
  ignore(FixedArray::make(-1, 0))
}

WARNING: A common pitfall is creating with the same initial value, for example:

test {
  let two_dimension_array = FixedArray::make(10, FixedArray::make(10, 0))
  two_dimension_array[0][5] = 10
  assert_eq(two_dimension_array[5][5], 10)
}

This is because all the cells reference to the same object (the FixedArray[Int] in this case). One should use makei() instead which creates an object for each index.

make
(16, 0U)
155 156 // 157 let
FixedArray[Byte]
p
=
Digest
self
.
FixedArray[Byte]
x
158 for
Int
i
= 0;
Int
i
(self_ : Int, other : Int) -> Bool
<
16;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1 {
159 let
Int
j
=
Int
i
(self : Int, other : Int) -> Int

Multiplies two 32-bit integers. This is the implementation of the * operator for Int.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns the product of the two integers. If the result overflows the range of Int, it wraps around according to two's complement arithmetic.

Example:

test "Int::op_mul" {
  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
}
*
4
160
FixedArray[UInt]
w
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
i] = (
FixedArray[Byte]
p
(FixedArray[Byte], Int) -> Byte

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
j].
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
(self : UInt, shift : Int) -> UInt

Performs a left shift operation on an unsigned 32-bit integer. Each bit in the integer is shifted left by the specified number of positions, and zeros are filled in from the right.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift. Only the least significant 5 bits are used, effectively making the shift count always between 0 and 31.

Returns a new unsigned 32-bit integer that is the result of shifting self left by shift positions.

Example:

test "UInt::op_shl" {
  let x = 1U
  inspect(x << 3, content="8") // Binary: 1 -> 1000
  let y = 0xFFFFFFFFU
  inspect(y << 16, content="4294901760") // All bits after position 16 are discarded
}
<<
24)
(UInt, UInt) -> UInt
|
161 (
FixedArray[Byte]
p
(FixedArray[Byte], Int) -> Byte

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
j
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1].
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
(self : UInt, shift : Int) -> UInt

Performs a left shift operation on an unsigned 32-bit integer. Each bit in the integer is shifted left by the specified number of positions, and zeros are filled in from the right.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift. Only the least significant 5 bits are used, effectively making the shift count always between 0 and 31.

Returns a new unsigned 32-bit integer that is the result of shifting self left by shift positions.

Example:

test "UInt::op_shl" {
  let x = 1U
  inspect(x << 3, content="8") // Binary: 1 -> 1000
  let y = 0xFFFFFFFFU
  inspect(y << 16, content="4294901760") // All bits after position 16 are discarded
}
<<
16)
(UInt, UInt) -> UInt
|
162 (
FixedArray[Byte]
p
(FixedArray[Byte], Int) -> Byte

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
j
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
2].
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
(self : UInt, shift : Int) -> UInt

Performs a left shift operation on an unsigned 32-bit integer. Each bit in the integer is shifted left by the specified number of positions, and zeros are filled in from the right.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift. Only the least significant 5 bits are used, effectively making the shift count always between 0 and 31.

Returns a new unsigned 32-bit integer that is the result of shifting self left by shift positions.

Example:

test "UInt::op_shl" {
  let x = 1U
  inspect(x << 3, content="8") // Binary: 1 -> 1000
  let y = 0xFFFFFFFFU
  inspect(y << 16, content="4294901760") // All bits after position 16 are discarded
}
<<
8)
(UInt, UInt) -> UInt
|
163
FixedArray[Byte]
p
(FixedArray[Byte], Int) -> Byte

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
j
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
3].
(self : Byte) -> UInt

Converts a Byte to a UInt.

Parameters:

  • byte : The Byte value to be converted.

Returns the UInt representation of the Byte.

to_uint
()
164 } 165 // 166 let mut
UInt
a
=
Digest
self
.
FixedArray[UInt]
h
[0]
167 let mut
UInt
b
=
Digest
self
.
FixedArray[UInt]
h
[1]
168 let mut
UInt
c
=
Digest
self
.
FixedArray[UInt]
h
[2]
169 let mut
UInt
d
=
Digest
self
.
FixedArray[UInt]
h
[3]
170 let mut
UInt
e
=
Digest
self
.
FixedArray[UInt]
h
[4]
171 // Each of the four 20-iteration rounds 172 // differs only in the computation of f and 173 // the choice of K (_K0, _K1, etc). 174 for
Int
i
= 0;
Int
i
(self_ : Int, other : Int) -> Bool
<
16;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1 {
175 let
UInt
f
= (
UInt
b
(UInt, UInt) -> UInt
&
UInt
c
)
(UInt, UInt) -> UInt
|
(
UInt
b
.
(self : UInt) -> UInt

Performs a bitwise NOT operation on an unsigned 32-bit integer. Flips all bits in the number (changes each 0 to 1 and each 1 to 0).

Parameters:

  • self : The unsigned 32-bit integer value on which to perform the bitwise NOT operation.

Returns a new unsigned 32-bit integer where each bit is inverted from the input value.

Example:

test "UInt::lnot" {
  let x = 0xFF00U // Binary: 1111_1111_0000_0000
  inspect(x.lnot(), content="4294902015") // Binary: ...0000_0000_1111_1111
}
lnot
()
(UInt, UInt) -> UInt
&
UInt
d
)
176 let
UInt
t
=
(x : UInt, r : Int) -> UInt
rotl
(
UInt
a
, 5)
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
f
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
e
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
_K0
177 let
(UInt, UInt, UInt, UInt, UInt)
tmp
= (
UInt
t
,
UInt
a
,
(x : UInt, r : Int) -> UInt
rotl
(
UInt
b
, 30),
UInt
c
,
UInt
d
)
178
UInt
a
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
0
179
UInt
b
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
1
180
UInt
c
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
2
181
UInt
d
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
3
182
UInt
e
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
4
183 } 184 for
Int
i
= 16;
Int
i
(self_ : Int, other : Int) -> Bool
<
20;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1 {
185 let
UInt
tmp
=
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
3)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
186
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
8)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
187
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
14)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
188
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
189
FixedArray[UInt]
w
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf] =
(x : UInt, r : Int) -> UInt
rotl
(
UInt
tmp
, 1)
190 let
UInt
f
= (
UInt
b
(UInt, UInt) -> UInt
&
UInt
c
)
(UInt, UInt) -> UInt
|
(
UInt
b
.
(self : UInt) -> UInt

Performs a bitwise NOT operation on an unsigned 32-bit integer. Flips all bits in the number (changes each 0 to 1 and each 1 to 0).

Parameters:

  • self : The unsigned 32-bit integer value on which to perform the bitwise NOT operation.

Returns a new unsigned 32-bit integer where each bit is inverted from the input value.

Example:

test "UInt::lnot" {
  let x = 0xFF00U // Binary: 1111_1111_0000_0000
  inspect(x.lnot(), content="4294902015") // Binary: ...0000_0000_1111_1111
}
lnot
()
(UInt, UInt) -> UInt
&
UInt
d
)
191 let
UInt
t
=
(x : UInt, r : Int) -> UInt
rotl
(
UInt
a
, 5)
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
f
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
e
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
_K0
192 let
(UInt, UInt, UInt, UInt, UInt)
tmp
= (
UInt
t
,
UInt
a
,
(x : UInt, r : Int) -> UInt
rotl
(
UInt
b
, 30),
UInt
c
,
UInt
d
)
193
UInt
a
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
0
194
UInt
b
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
1
195
UInt
c
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
2
196
UInt
d
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
3
197
UInt
e
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
4
198 } 199 for
Int
i
= 20;
Int
i
(self_ : Int, other : Int) -> Bool
<
40;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1 {
200 let
UInt
tmp
=
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
3)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
201
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
8)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
202
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
14)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
203
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
204
FixedArray[UInt]
w
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf] =
(x : UInt, r : Int) -> UInt
rotl
(
UInt
tmp
, 1)
205 let
UInt
f
=
UInt
b
(UInt, UInt) -> UInt
^
UInt
c
(UInt, UInt) -> UInt
^
UInt
d
206 let
UInt
t
=
(x : UInt, r : Int) -> UInt
rotl
(
UInt
a
, 5)
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
f
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
e
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
_K1
207 let
(UInt, UInt, UInt, UInt, UInt)
tmp
= (
UInt
t
,
UInt
a
,
(x : UInt, r : Int) -> UInt
rotl
(
UInt
b
, 30),
UInt
c
,
UInt
d
)
208
UInt
a
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
0
209
UInt
b
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
1
210
UInt
c
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
2
211
UInt
d
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
3
212
UInt
e
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
4
213 } 214 for
Int
i
= 40;
Int
i
(self_ : Int, other : Int) -> Bool
<
60;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1 {
215 let
UInt
tmp
=
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
3)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
216
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
8)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
217
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
14)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
218
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
219
FixedArray[UInt]
w
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf] =
(x : UInt, r : Int) -> UInt
rotl
(
UInt
tmp
, 1)
220 let
UInt
f
= ((
UInt
b
(UInt, UInt) -> UInt
|
UInt
c
)
(UInt, UInt) -> UInt
&
UInt
d
)
(UInt, UInt) -> UInt
|
(
UInt
b
(UInt, UInt) -> UInt
&
UInt
c
)
221 let
UInt
t
=
(x : UInt, r : Int) -> UInt
rotl
(
UInt
a
, 5)
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
f
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
e
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
_K2
222 let
(UInt, UInt, UInt, UInt, UInt)
tmp
= (
UInt
t
,
UInt
a
,
(x : UInt, r : Int) -> UInt
rotl
(
UInt
b
, 30),
UInt
c
,
UInt
d
)
223
UInt
a
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
0
224
UInt
b
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
1
225
UInt
c
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
2
226
UInt
d
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
3
227
UInt
e
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
4
228 } 229 for
Int
i
= 60;
Int
i
(self_ : Int, other : Int) -> Bool
<
80;
Int
i
=
Int
i
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1 {
230 let
UInt
tmp
=
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
3)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
231
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
8)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
232
FixedArray[UInt]
w
[(
Int
i
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
14)
(Int, Int) -> Int
&
0xf]
(UInt, UInt) -> UInt
^
233
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
234
FixedArray[UInt]
w
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf] =
(x : UInt, r : Int) -> UInt
rotl
(
UInt
tmp
, 1)
235 let
UInt
f
=
UInt
b
(UInt, UInt) -> UInt
^
UInt
c
(UInt, UInt) -> UInt
^
UInt
d
236 let
UInt
t
=
(x : UInt, r : Int) -> UInt
rotl
(
UInt
a
, 5)
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
f
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
e
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
FixedArray[UInt]
w
(FixedArray[UInt], Int) -> UInt

Retrieves an element at the specified index from a fixed-size array. This function implements the array indexing operator [].

Parameters:

  • array : The fixed-size array to access.
  • index : The position in the array from which to retrieve the element.

Returns the element at the specified index.

Throws a runtime error if the index is out of bounds (negative or greater than or equal to the length of the array).

Example:

test "FixedArray::op_get" {
  let arr = FixedArray::make(3, 42)
  inspect(arr[1], content="42")
}

test "panic FixedArray::op_get/out_of_bounds" {
  let arr = FixedArray::make(3, 0)
  ignore(arr[3]) // Index out of bounds
}
[
i
(Int, Int) -> Int
&
0xf]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+
UInt
_K3
237 let
(UInt, UInt, UInt, UInt, UInt)
tmp
= (
UInt
t
,
UInt
a
,
(x : UInt, r : Int) -> UInt
rotl
(
UInt
b
, 30),
UInt
c
,
UInt
d
)
238
UInt
a
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
0
239
UInt
b
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
1
240
UInt
c
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
2
241
UInt
d
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
3
242
UInt
e
=
(UInt, UInt, UInt, UInt, UInt)
tmp
.
UInt
4
243 } 244 245 // save state 246
Digest
self
.
FixedArray[UInt]
h
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
0]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+=
UInt
a
247
Digest
self
.
FixedArray[UInt]
h
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
1]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+=
UInt
b
248
Digest
self
.
FixedArray[UInt]
h
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
2]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+=
UInt
c
249
Digest
self
.
FixedArray[UInt]
h
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
3]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+=
UInt
d
250
Digest
self
.
FixedArray[UInt]
h
(FixedArray[UInt], Int, UInt) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
4]
(self : UInt, other : UInt) -> UInt

Performs addition between two unsigned 32-bit integers. If the result overflows, it wraps around according to the rules of modular arithmetic (2^32).

Parameters:

  • self : The first unsigned 32-bit integer operand.
  • other : The second unsigned 32-bit integer operand to be added.

Returns the sum of the two unsigned integers, wrapped around if necessary.

Example:

test "UInt::op_add" {
  let a = 42U
  let b = 100U
  inspect(a + b, content="142")

  // Demonstrate overflow behavior
  let max = 4294967295U // UInt::max_value
  inspect(max + 1U, content="0")
}
+=
UInt
e
251} 252 253///| 254fn
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
b
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
Int
offset
:
Int
Int
,
UInt
value
:
UInt
UInt
) ->
Unit
Unit
{
255
FixedArray[Byte]
b
(FixedArray[Byte], Int, Byte) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
offset
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
3] = (
UInt
value
(UInt, UInt) -> UInt
&
0xff).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
256
FixedArray[Byte]
b
(FixedArray[Byte], Int, Byte) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
offset
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
2] = ((
UInt
value
(self : UInt, shift : Int) -> UInt

Performs a logical right shift operation on an unsigned 32-bit integer. The operation shifts all bits to the right by a specified number of positions, filling the leftmost positions with zeros.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift right. If this value is negative, the behavior is undefined. Values larger than 31 are masked with & 31.

Returns a new unsigned 32-bit integer containing the result of the right shift operation.

Example:

test "UInt::op_shr" {
  let x = 0xFF000000U
  inspect(x >> 8, content="16711680") // 0x00FF0000
  inspect(x >> 24, content="255") // 0x000000FF
}

test "UInt::op_shr/large_shift" {
  let x = 0xFF000000U
  inspect(x >> 32, content="4278190080") // Same as x >> 0 due to masking
}
>>
8)
(UInt, UInt) -> UInt
&
0xff).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
257
FixedArray[Byte]
b
(FixedArray[Byte], Int, Byte) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
offset
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
1] = ((
UInt
value
(self : UInt, shift : Int) -> UInt

Performs a logical right shift operation on an unsigned 32-bit integer. The operation shifts all bits to the right by a specified number of positions, filling the leftmost positions with zeros.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift right. If this value is negative, the behavior is undefined. Values larger than 31 are masked with & 31.

Returns a new unsigned 32-bit integer containing the result of the right shift operation.

Example:

test "UInt::op_shr" {
  let x = 0xFF000000U
  inspect(x >> 8, content="16711680") // 0x00FF0000
  inspect(x >> 24, content="255") // 0x000000FF
}

test "UInt::op_shr/large_shift" {
  let x = 0xFF000000U
  inspect(x >> 32, content="4278190080") // Same as x >> 0 due to masking
}
>>
16)
(UInt, UInt) -> UInt
&
0xff).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
258
FixedArray[Byte]
b
(FixedArray[Byte], Int, Byte) -> Unit

Sets a value at the specified index in a fixed-size array. The original value at that index is overwritten.

Parameters:

  • array : The fixed-size array to modify.
  • index : The position in the array where the value will be set.
  • value : The new value to assign at the specified index.

Throws a runtime error if the index is out of bounds (less than 0 or greater than or equal to the length of the array).

Example:

test "FixedArray::op_set" {
  let arr = [1, 2, 3]
  arr[1] = 42
  inspect(arr, content="[1, 42, 3]")
}

test "panic FixedArray::op_set/out_of_bounds" {
  let arr = [1, 2, 3]
  arr[3] = 42 // Index out of bounds
}
[
offset] = ((
UInt
value
(self : UInt, shift : Int) -> UInt

Performs a logical right shift operation on an unsigned 32-bit integer. The operation shifts all bits to the right by a specified number of positions, filling the leftmost positions with zeros.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift right. If this value is negative, the behavior is undefined. Values larger than 31 are masked with & 31.

Returns a new unsigned 32-bit integer containing the result of the right shift operation.

Example:

test "UInt::op_shr" {
  let x = 0xFF000000U
  inspect(x >> 8, content="16711680") // 0x00FF0000
  inspect(x >> 24, content="255") // 0x000000FF
}

test "UInt::op_shr/large_shift" {
  let x = 0xFF000000U
  inspect(x >> 32, content="4278190080") // Same as x >> 0 due to masking
}
>>
24)
(UInt, UInt) -> UInt
&
0xff).
(self : UInt) -> Byte

Converts an unsigned 32-bit integer to a byte by taking its least significant 8 bits. Any bits beyond the first 8 bits are truncated.

Parameters:

  • self : The unsigned 32-bit integer to be converted. Only the least significant 8 bits will be used.

Returns a byte containing the least significant 8 bits of the input integer.

Example:

test "UInt::to_byte" {
  let n = 258U // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let big = 4294967295U // Maximum value of UInt
  inspect(big.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
()
259} 260 261///| 262fn
(b : FixedArray[Byte], offset : Int, value : UInt64) -> Unit
be_put_uint64
(
FixedArray[Byte]
b
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
Int
offset
:
Int
Int
,
UInt64
value
:
UInt64
UInt64
) ->
Unit
Unit
{
263
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
b
,
Int
offset
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
4, (
UInt64
value
(self : UInt64, other : UInt64) -> UInt64

Performs a bitwise AND operation between two unsigned 64-bit integers.

Parameters:

  • self : The first unsigned 64-bit integer operand.
  • other : The second unsigned 64-bit integer operand.

Returns the result of performing a bitwise AND operation on the two operands.

Example:

test "UInt64::land" {
  let a = 0xF0F0F0F0F0F0F0F0UL
  let b = 0xFF00FF00FF00FF00UL
  inspect(a & b, content="17294086455919964160") // 0xF000F000F000F000
}
&
0xffffffff).
(self : UInt64) -> UInt

Converts a 64-bit unsigned integer to a 32-bit unsigned integer by truncating the higher 32 bits.

Parameters:

  • self : The 64-bit unsigned integer to be converted.

Returns a 32-bit unsigned integer containing the lower 32 bits of the input value.

Example:

test "UInt64::to_uint" {
  let big = 0xFFFFFFFFFFFFFFFFUL // max value of UInt64
  inspect(big.to_uint(), content="4294967295") // 0xFFFFFFFF, max value of UInt
  let small = 42UL
  inspect(small.to_uint(), content="42")
}
to_uint
())
264
(b : FixedArray[Byte], offset : Int, value : UInt) -> Unit
be_put_uint32
(
FixedArray[Byte]
b
,
Int
offset
, ((
UInt64
value
(self : UInt64, shift : Int) -> UInt64

Performs a logical right shift operation on a 64-bit unsigned integer by a specified number of bits. All bits shifted beyond the least significant bit are discarded, and zeros are shifted in from the most significant bit.

Parameters:

  • self : The 64-bit unsigned integer to be shifted.
  • shift : The number of positions to shift right. Only the least significant 6 bits of this value are used, effectively making the shift count always between 0 and 63.

Returns a new UInt64 value representing the result of the right shift operation.

Example:

test "UInt64::op_shr" {
  let x = 0xFF00FF00FF00FF00UL
  inspect(x >> 8, content="71777214294589695") // Shifted right by 8 bits
  inspect(x >> 64, content="18374966859414961920") // Equivalent to x >> 0 due to masking
}
>>
32)
(self : UInt64, other : UInt64) -> UInt64

Performs a bitwise AND operation between two unsigned 64-bit integers.

Parameters:

  • self : The first unsigned 64-bit integer operand.
  • other : The second unsigned 64-bit integer operand.

Returns the result of performing a bitwise AND operation on the two operands.

Example:

test "UInt64::land" {
  let a = 0xF0F0F0F0F0F0F0F0UL
  let b = 0xFF00FF00FF00FF00UL
  inspect(a & b, content="17294086455919964160") // 0xF000F000F000F000
}
&
0xffffffff).
(self : UInt64) -> UInt

Converts a 64-bit unsigned integer to a 32-bit unsigned integer by truncating the higher 32 bits.

Parameters:

  • self : The 64-bit unsigned integer to be converted.

Returns a 32-bit unsigned integer containing the lower 32 bits of the input value.

Example:

test "UInt64::to_uint" {
  let big = 0xFFFFFFFFFFFFFFFFUL // max value of UInt64
  inspect(big.to_uint(), content="4294967295") // 0xFFFFFFFF, max value of UInt
  let small = 42UL
  inspect(small.to_uint(), content="42")
}
to_uint
())
265} 266 267///| 268fn
(x : UInt, r : Int) -> UInt
rotl
(
UInt
x
:
UInt
UInt
,
Int
r
:
Int
Int
) ->
UInt
UInt
{
269 (
UInt
x
(self : UInt, shift : Int) -> UInt

Performs a left shift operation on an unsigned 32-bit integer. Each bit in the integer is shifted left by the specified number of positions, and zeros are filled in from the right.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift. Only the least significant 5 bits are used, effectively making the shift count always between 0 and 31.

Returns a new unsigned 32-bit integer that is the result of shifting self left by shift positions.

Example:

test "UInt::op_shl" {
  let x = 1U
  inspect(x << 3, content="8") // Binary: 1 -> 1000
  let y = 0xFFFFFFFFU
  inspect(y << 16, content="4294901760") // All bits after position 16 are discarded
}
<<
Int
r
)
(UInt, UInt) -> UInt
|
(
UInt
x
(self : UInt, shift : Int) -> UInt

Performs a logical right shift operation on an unsigned 32-bit integer. The operation shifts all bits to the right by a specified number of positions, filling the leftmost positions with zeros.

Parameters:

  • self : The unsigned 32-bit integer to be shifted.
  • shift : The number of positions to shift right. If this value is negative, the behavior is undefined. Values larger than 31 are masked with & 31.

Returns a new unsigned 32-bit integer containing the result of the right shift operation.

Example:

test "UInt::op_shr" {
  let x = 0xFF000000U
  inspect(x >> 8, content="16711680") // 0x00FF0000
  inspect(x >> 24, content="255") // 0x000000FF
}

test "UInt::op_shr/large_shift" {
  let x = 0xFF000000U
  inspect(x >> 32, content="4278190080") // Same as x >> 0 due to masking
}
>>
(32
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
Int
r
))
270} 271 272///| 273fn
(v : Int) -> Char
to_hex
(
Int
v
:
Int
Int
) ->
Char
Char
{
274 if
Int
v
(self_ : Int, other : Int) -> Bool
<
10 {
275
(Int) -> Char
Int::
(self : Int) -> Char
unsafe_to_char
(
Int
v
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
b'0'.
(self : Byte) -> Int

Converts a byte value to a 32-bit signed integer. The resulting integer will have the same binary representation as the byte value, preserving the numerical value in the range [0, 255].

Parameters:

  • byte : The byte value to be converted to an integer.

Returns a 32-bit signed integer representing the same numerical value as the input byte.

Example:

test "Byte::to_int" {
  let b = b'\xFF' // byte with value 255
  inspect(b.to_int(), content="255")
  let zero = b'\x00'
  inspect(zero.to_int(), content="0")
}
to_int
())
276 } else { 277
(Int) -> Char
Int::
(self : Int) -> Char
unsafe_to_char
(
Int
v
(self : Int, other : Int) -> Int

Performs subtraction between two 32-bit integers, following standard two's complement arithmetic rules. When the result overflows or underflows, it wraps around within the 32-bit integer range.

Parameters:

  • self : The minuend (the number being subtracted from).
  • other : The subtrahend (the number to subtract).

Returns the difference between self and other.

Example:

test "Int::op_sub" {
  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
}
-
10
(self : Int, other : Int) -> Int

Adds two 32-bit signed integers. Performs two's complement arithmetic, which means the operation will wrap around if the result exceeds the range of a 32-bit integer.

Parameters:

  • self : The first integer operand.
  • other : The second integer operand.

Returns a new integer that is the sum of the two operands. If the mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to 2,147,483,647), the result wraps around according to two's complement rules.

Example:

test "Int::op_add" {
  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+
b'a'.
(self : Byte) -> Int

Converts a byte value to a 32-bit signed integer. The resulting integer will have the same binary representation as the byte value, preserving the numerical value in the range [0, 255].

Parameters:

  • byte : The byte value to be converted to an integer.

Returns a 32-bit signed integer representing the same numerical value as the input byte.

Example:

test "Byte::to_int" {
  let b = b'\xFF' // byte with value 255
  inspect(b.to_int(), content="255")
  let zero = b'\x00'
  inspect(zero.to_int(), content="0")
}
to_int
())
278 } 279} 280