1/// This package is based on the Go implementation found here:
2/// https://cs.opensource.google/go/go/+/master:src/encoding/base64/base64.go
3/// which has the copyright notice:
4/// Copyright 2009 The Go Authors. All rights reserved.
5/// Use of this source code is governed by a BSD-style
6/// license that can be found in the LICENSE file.
7
8///|
9/// `std_encode2bytes` base64-encodes the provided bytes using Standard encoding.
10/// Setting `no_padding=true` is used for raw encoding.
11///
12/// Note that standard encoding uses `+` and `/` characters whereas URL encoding uses `-` and `_`.
13///
14/// Examples:
15/// ```
16/// let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍"
17/// inspect!(std_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==")
18/// inspect!(std_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ")
19/// ```
20pub fn 
(src : FixedArray[Byte], no_padding~ : Bool = ..) -> Bytes

std_encode2bytes base64-encodes the provided bytes using Standard encoding. Setting no_padding=true is used for raw encoding.

Note that standard encoding uses + and / characters whereas URL encoding uses - and _.

Examples:

let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍"
inspect!(std_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==")
inspect!(std_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ")
std_encode2bytes
(
21
FixedArray[Byte]
src
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
22
Bool
no_padding
~ :
Bool
Bool
= false
23) ->
Bytes
Bytes
{
24 if
FixedArray[Byte]
src
.
(self : FixedArray[Byte]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

test "FixedArray::length" {
  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
}
length
()
(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")
}
==
0 {
25 return
(Array[Byte]) -> Bytes
Bytes::
(arr : Array[Byte]) -> Bytes

Creates a new bytes sequence from a byte array.

Parameters:

  • array : An array of bytes to be converted.

Returns a new bytes sequence containing the same bytes as the input array.

Example:

test "Bytes::from_array" {
  let arr = [b'h', b'i']
  let bytes = @bytes.from_array(arr)
  inspect(bytes, content=
    #|b"\x68\x69"
  )
}
from_array
([])
26 } 27 let
FixedArray[Byte]
buf
=
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
(
(n : Int, no_padding : Bool) -> Int
encoded_len
(
FixedArray[Byte]
src
.
(self : FixedArray[Byte]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

test "FixedArray::length" {
  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
}
length
(),
Bool
no_padding
), b'\x00')
28
(encode : FixedArray[Byte], dst : FixedArray[Byte], src : FixedArray[Byte], no_padding : Bool) -> Unit
encode_buf
(
FixedArray[Byte]
std_encoding
,
FixedArray[Byte]
buf
,
FixedArray[Byte]
src
,
Bool
no_padding
)
29
(Iter[Byte]) -> Bytes
Bytes::
(iter : Iter[Byte]) -> Bytes

Creates a new bytes sequence from an iterator of bytes.

Parameters:

  • iterator : An iterator that yields bytes.

Returns a new bytes sequence containing all the bytes from the iterator.

Example:

test "from_iter" {
  let iter = Iter::singleton(b'h')
  let bytes = @bytes.from_iter(iter)
  inspect(bytes, content=
    #|b"\x68"
  )
}
from_iter
(
FixedArray[Byte]
buf
.
(self : FixedArray[Byte]) -> Iter[Byte]

Creates an iterator over the elements of a fixed-size array, providing sequential access to each element.

Parameters:

  • array : The fixed-size array to iterate over.

Returns an iterator that yields each element of the array in order from first to last.

Example:

test "FixedArray::iter" {
  let arr = FixedArray::make(3, 42)
  let mut sum = 0
  arr.iter().each(fn(x) { sum = sum + x })
  inspect(sum, content="126")
}
iter
())
30} 31 32///| 33/// `std_encode2str` base64-encodes the provided bytes using Standard encoding and returns a String. 34/// Setting `no_padding=true` is used for raw encoding. 35/// 36/// Note that standard encoding uses `+` and `/` characters whereas URL encoding uses `-` and `_`. 37/// 38/// Examples: 39/// ``` 40/// let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍" 41/// inspect!(std_encode2str(b.to_fixedarray()), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==") 42/// inspect!(std_encode2str(b.to_fixedarray(), no_padding=true), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ") 43/// ``` 44pub fn
(src : FixedArray[Byte], no_padding~ : Bool = ..) -> String

std_encode2str base64-encodes the provided bytes using Standard encoding and returns a String. Setting no_padding=true is used for raw encoding.

Note that standard encoding uses + and / characters whereas URL encoding uses - and _.

Examples:

let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍"
inspect!(std_encode2str(b.to_fixedarray()), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==")
inspect!(std_encode2str(b.to_fixedarray(), no_padding=true), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ")
std_encode2str
(
45
FixedArray[Byte]
src
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
46
Bool
no_padding
~ :
Bool
Bool
= false
47) ->
String
String
{
48
(b : Bytes) -> String

bytes2str decodes a UTF-8 Bytes to a UTF-16 String.

Examples:

inspect!(bytes2str("+/ Hello, δΈ–η•Œ! 🌍"), content="+/ Hello, δΈ–η•Œ! 🌍")
bytes2str
(
(src : FixedArray[Byte], no_padding~ : Bool) -> Bytes

std_encode2bytes base64-encodes the provided bytes using Standard encoding. Setting no_padding=true is used for raw encoding.

Note that standard encoding uses + and / characters whereas URL encoding uses - and _.

Examples:

let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍"
inspect!(std_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ==")
inspect!(std_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J+MjQ")
std_encode2bytes
(
FixedArray[Byte]
src
,
Bool
no_padding
~))
49} 50 51///| 52/// `url_encode2bytes` base64-encodes the provided bytes using URL encoding. 53/// Setting `no_padding=true` is used for raw encoding. 54/// 55/// Note that standard encoding uses `+` and `/` characters whereas URL encoding uses `-` and `_`. 56/// 57/// Examples: 58/// ``` 59/// let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍" 60/// inspect!(url_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==") 61/// inspect!(url_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ") 62/// ``` 63pub fn
(src : FixedArray[Byte], no_padding~ : Bool = ..) -> Bytes

url_encode2bytes base64-encodes the provided bytes using URL encoding. Setting no_padding=true is used for raw encoding.

Note that standard encoding uses + and / characters whereas URL encoding uses - and _.

Examples:

let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍"
inspect!(url_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==")
inspect!(url_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ")
url_encode2bytes
(
64
FixedArray[Byte]
src
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
65
Bool
no_padding
~ :
Bool
Bool
= false
66) ->
Bytes
Bytes
{
67 if
FixedArray[Byte]
src
.
(self : FixedArray[Byte]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

test "FixedArray::length" {
  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
}
length
()
(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")
}
==
0 {
68 return
(Array[Byte]) -> Bytes
Bytes::
(arr : Array[Byte]) -> Bytes

Creates a new bytes sequence from a byte array.

Parameters:

  • array : An array of bytes to be converted.

Returns a new bytes sequence containing the same bytes as the input array.

Example:

test "Bytes::from_array" {
  let arr = [b'h', b'i']
  let bytes = @bytes.from_array(arr)
  inspect(bytes, content=
    #|b"\x68\x69"
  )
}
from_array
([])
69 } 70 let
FixedArray[Byte]
buf
=
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
(
(n : Int, no_padding : Bool) -> Int
encoded_len
(
FixedArray[Byte]
src
.
(self : FixedArray[Byte]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

test "FixedArray::length" {
  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
}
length
(),
Bool
no_padding
), b'\x00')
71
(encode : FixedArray[Byte], dst : FixedArray[Byte], src : FixedArray[Byte], no_padding : Bool) -> Unit
encode_buf
(
FixedArray[Byte]
url_encoding
,
FixedArray[Byte]
buf
,
FixedArray[Byte]
src
,
Bool
no_padding
)
72
(Iter[Byte]) -> Bytes
Bytes::
(iter : Iter[Byte]) -> Bytes

Creates a new bytes sequence from an iterator of bytes.

Parameters:

  • iterator : An iterator that yields bytes.

Returns a new bytes sequence containing all the bytes from the iterator.

Example:

test "from_iter" {
  let iter = Iter::singleton(b'h')
  let bytes = @bytes.from_iter(iter)
  inspect(bytes, content=
    #|b"\x68"
  )
}
from_iter
(
FixedArray[Byte]
buf
.
(self : FixedArray[Byte]) -> Iter[Byte]

Creates an iterator over the elements of a fixed-size array, providing sequential access to each element.

Parameters:

  • array : The fixed-size array to iterate over.

Returns an iterator that yields each element of the array in order from first to last.

Example:

test "FixedArray::iter" {
  let arr = FixedArray::make(3, 42)
  let mut sum = 0
  arr.iter().each(fn(x) { sum = sum + x })
  inspect(sum, content="126")
}
iter
())
73} 74 75///| 76/// `url_encode2str` base64-encodes the provided bytes using URL encoding and returns a String. 77/// Setting `no_padding=true` is used for raw encoding. 78/// 79/// Note that standard encoding uses `+` and `/` characters whereas URL encoding uses `-` and `_`. 80/// 81/// Examples: 82/// ``` 83/// let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍" 84/// inspect!(url_encode2str(b.to_fixedarray()), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==") 85/// inspect!(url_encode2str(b.to_fixedarray(), no_padding=true), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ") 86/// ``` 87pub fn
(src : FixedArray[Byte], no_padding~ : Bool = ..) -> String

url_encode2str base64-encodes the provided bytes using URL encoding and returns a String. Setting no_padding=true is used for raw encoding.

Note that standard encoding uses + and / characters whereas URL encoding uses - and _.

Examples:

let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍"
inspect!(url_encode2str(b.to_fixedarray()), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==")
inspect!(url_encode2str(b.to_fixedarray(), no_padding=true), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ")
url_encode2str
(
88
FixedArray[Byte]
src
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
89
Bool
no_padding
~ :
Bool
Bool
= false
90) ->
String
String
{
91
(b : Bytes) -> String

bytes2str decodes a UTF-8 Bytes to a UTF-16 String.

Examples:

inspect!(bytes2str("+/ Hello, δΈ–η•Œ! 🌍"), content="+/ Hello, δΈ–η•Œ! 🌍")
bytes2str
(
(src : FixedArray[Byte], no_padding~ : Bool) -> Bytes

url_encode2bytes base64-encodes the provided bytes using URL encoding. Setting no_padding=true is used for raw encoding.

Note that standard encoding uses + and / characters whereas URL encoding uses - and _.

Examples:

let b : Bytes = "+/ Hello, δΈ–η•Œ! 🌍"
inspect!(url_encode2bytes(b.to_fixedarray()) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ==")
inspect!(url_encode2bytes(b.to_fixedarray(), no_padding=true) |> bytes2str(), content="Ky8gSGVsbG8sIOS4lueVjCEg8J-MjQ")
url_encode2bytes
(
FixedArray[Byte]
src
,
Bool
no_padding
~))
92} 93 94///| 95fn
(encode : FixedArray[Byte], dst : FixedArray[Byte], src : FixedArray[Byte], no_padding : Bool) -> Unit
encode_buf
(
96
FixedArray[Byte]
encode
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
97
FixedArray[Byte]
dst
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
98
FixedArray[Byte]
src
:
type FixedArray[A]
FixedArray
[
Byte
Byte
],
99
Bool
no_padding
:
Bool
Bool
100) ->
Unit
Unit
{
101 let mut
Int
di
= 0
102 let mut
Int
si
= 0
103 let
Int
n
=
FixedArray[Byte]
src
.
(self : FixedArray[Byte]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

test "FixedArray::length" {
  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
}
length
()
(self : Int, other : Int) -> Int

Performs integer division between two 32-bit integers. The result is truncated towards zero (rounds down for positive numbers and up for negative numbers).

Parameters:

  • dividend : The first integer operand to be divided.
  • divisor : The second integer operand that divides the dividend.

Returns the quotient of the division operation.

Throws a panic if divisor is zero.

Example:

test "Int::op_div" {
  inspect(10 / 3, content="3") // truncates towards zero
  inspect(-10 / 3, content="-3")
  inspect(10 / -3, content="-3")
}

test "panic Int::op_div/division_by_zero" {
  ignore(42 / 0) // Panics with division by zero
}
/
3
(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
}
*
3
104 while
Int
si
(self_ : Int, other : Int) -> Bool
<
Int
n
{
105 // Convert 3x 8bit source bytes into 4 bytes 106 let
UInt
val
= (
FixedArray[Byte]
src
(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
}
[
si
(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
}
+
0].
(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
|
107 (
FixedArray[Byte]
src
(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
}
[
si
(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
}
<<
8)
(UInt, UInt) -> UInt
|
108
FixedArray[Byte]
src
(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
}
[
si
(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
()
109
FixedArray[Byte]
dst
(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
}
[
di
(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
}
+
0] =
FixedArray[Byte]
encode
[((
UInt
val
(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
}
>>
18)
(UInt, UInt) -> UInt
&
0x3F).
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()]
110
FixedArray[Byte]
dst
(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
}
[
di
(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] =
FixedArray[Byte]
encode
[((
UInt
val
(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
}
>>
12)
(UInt, UInt) -> UInt
&
0x3F).
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()]
111
FixedArray[Byte]
dst
(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
}
[
di
(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] =
FixedArray[Byte]
encode
[((
UInt
val
(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
}
>>
6)
(UInt, UInt) -> UInt
&
0x3F).
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()]
112
FixedArray[Byte]
dst
(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
}
[
di
(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] =
FixedArray[Byte]
encode
[(
UInt
val
(UInt, UInt) -> UInt
&
0x3F).
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()]
113
Int
si
(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
114
Int
di
(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
115 } 116 let
Int
remain
=
FixedArray[Byte]
src
.
(self : FixedArray[Byte]) -> Int

Returns the number of elements in a fixed-size array.

Parameters:

  • array : The fixed-size array whose length is to be determined.

Returns an integer representing the number of elements in the array.

Example:

test "FixedArray::length" {
  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
}
length
()
(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
si
117 if
Int
remain
(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")
}
==
0 {
118 return 119 } 120 // Add the remaining small block 121 let mut
UInt
val
=
FixedArray[Byte]
src
(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
}
[
si
(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
}
+
0].
(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
122 if
Int
remain
(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")
}
==
2 {
123
UInt
val
=
UInt
val
(UInt, UInt) -> UInt
|
(
FixedArray[Byte]
src
(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
}
[
si
(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
}
<<
8)
124 } 125
FixedArray[Byte]
dst
(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
}
[
di
(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
}
+
0] =
FixedArray[Byte]
encode
[((
UInt
val
(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
}
>>
18)
(UInt, UInt) -> UInt
&
0x3F).
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()]
126
FixedArray[Byte]
dst
(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
}
[
di
(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] =
FixedArray[Byte]
encode
[((
UInt
val
(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
}
>>
12)
(UInt, UInt) -> UInt
&
0x3F).
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()]
127 match
Int
remain
{
128 2 => { 129
FixedArray[Byte]
dst
(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
}
[
di
(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] =
FixedArray[Byte]
encode
[((
UInt
val
(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
}
>>
6)
(UInt, UInt) -> UInt
&
0x3F).
(self : UInt) -> Int

reinterpret the unsigned int as signed int For number within the range of 0..=2^31-1, the value is the same. For number within the range of 2^31..=2^32-1, the value is negative

reinterpret_as_int
()]
130 if
(x : Bool) -> Bool

Performs logical negation on a boolean value.

Parameters:

  • value : The boolean value to negate.

Returns the logical NOT of the input value: true if the input is false, and false if the input is true.

Example:

test "not" {
  inspect(not(true), content="false")
  inspect(not(false), content="true")
}
not
(
Bool
no_padding
) {
131
FixedArray[Byte]
dst
(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
}
[
di
(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] =
Byte
pad_char
132 } 133 } 134 1 => 135 if
(x : Bool) -> Bool

Performs logical negation on a boolean value.

Parameters:

  • value : The boolean value to negate.

Returns the logical NOT of the input value: true if the input is false, and false if the input is true.

Example:

test "not" {
  inspect(not(true), content="false")
  inspect(not(false), content="true")
}
not
(
Bool
no_padding
) {
136
FixedArray[Byte]
dst
(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
}
[
di
(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] =
Byte
pad_char
137
FixedArray[Byte]
dst
(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
}
[
di
(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] =
Byte
pad_char
138 } 139 _ => () 140 } 141} 142 143///| 144fn
(n : Int, no_padding : Bool) -> Int
encoded_len
(
Int
n
:
Int
Int
,
Bool
no_padding
:
Bool
Bool
) ->
Int
Int
{
145 if
Bool
no_padding
{
146
Int
n
(self : Int, other : Int) -> Int

Performs integer division between two 32-bit integers. The result is truncated towards zero (rounds down for positive numbers and up for negative numbers).

Parameters:

  • dividend : The first integer operand to be divided.
  • divisor : The second integer operand that divides the dividend.

Returns the quotient of the division operation.

Throws a panic if divisor is zero.

Example:

test "Int::op_div" {
  inspect(10 / 3, content="3") // truncates towards zero
  inspect(-10 / 3, content="-3")
  inspect(10 / -3, content="-3")
}

test "panic Int::op_div/division_by_zero" {
  ignore(42 / 0) // Panics with division by zero
}
/
3
(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
(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
}
+
(
Int
n
(self : Int, other : Int) -> Int

Calculates the remainder of dividing one integer by another. The result follows the formula dividend - (dividend / divisor) * divisor, maintaining the same sign as the dividend.

Parameters:

  • self : The dividend (the number being divided).
  • other : The divisor (the number to divide by).

Returns the remainder of the division. If other is 0, the behavior is undefined.

Example:

test "Int::op_mod" {
  inspect(7 % 3, content="1")
  inspect(-7 % 3, content="-1")
  inspect(7 % -3, content="1")
}

test "panic Int::op_mod/division_by_zero" {
  ignore(7 % 0) // Panics with division by zero
}
%
3
(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
}
*
8
(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
}
+
5)
(self : Int, other : Int) -> Int

Performs integer division between two 32-bit integers. The result is truncated towards zero (rounds down for positive numbers and up for negative numbers).

Parameters:

  • dividend : The first integer operand to be divided.
  • divisor : The second integer operand that divides the dividend.

Returns the quotient of the division operation.

Throws a panic if divisor is zero.

Example:

test "Int::op_div" {
  inspect(10 / 3, content="3") // truncates towards zero
  inspect(-10 / 3, content="-3")
  inspect(10 / -3, content="-3")
}

test "panic Int::op_div/division_by_zero" {
  ignore(42 / 0) // Panics with division by zero
}
/
6 // minimum # chars at 6 bits per char
147 } else { 148 (
Int
n
(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 : Int, other : Int) -> Int

Performs integer division between two 32-bit integers. The result is truncated towards zero (rounds down for positive numbers and up for negative numbers).

Parameters:

  • dividend : The first integer operand to be divided.
  • divisor : The second integer operand that divides the dividend.

Returns the quotient of the division operation.

Throws a panic if divisor is zero.

Example:

test "Int::op_div" {
  inspect(10 / 3, content="3") // truncates towards zero
  inspect(-10 / 3, content="-3")
  inspect(10 / -3, content="-3")
}

test "panic Int::op_div/division_by_zero" {
  ignore(42 / 0) // Panics with division by zero
}
/
3
(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 // minimum # 4-char quanta, 3 bytes each
149 } 150} 151 152///| 153let
FixedArray[Byte]
std_encoding
:
type FixedArray[A]
FixedArray
[
Byte
Byte
] =
type FixedArray[A]
FixedArray
::
(array : Array[Byte]) -> FixedArray[Byte]

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
(
154 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" 155 .
(self : String) -> Array[Char]

Converts the String into an array of Chars.

to_array
()
156 .
(self : Array[Char], f : (Char) -> Byte) -> Array[Byte]

Maps a function over the elements of the array.

Example

let v = [3, 4, 5]
let v2 = v.map(fn (x) {x + 1})
assert_eq(v2, [4, 5, 6])
map
(fn(
Char
c
) {
Char
c
.
(self : Char) -> Int

Converts a character to its Unicode code point value as an integer.

Parameters:

  • self : The character to be converted.

Returns an integer representing the Unicode code point value of the character.

Example:

test "Char::to_int" {
  inspect('A'.to_int(), content="65") // ASCII value of 'A'
  inspect('あ'.to_int(), content="12354") // Unicode code point of 'あ'
}
to_int
().
(self : Int) -> Byte

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

Parameters:

  • value : The 32-bit signed 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 "Int::to_byte" {
  let n = 258 // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let neg = -1 // In binary: all 1's
  inspect(neg.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
() }),
157) 158 159///| 160let
FixedArray[Byte]
url_encoding
:
type FixedArray[A]
FixedArray
[
Byte
Byte
] =
type FixedArray[A]
FixedArray
::
(array : Array[Byte]) -> FixedArray[Byte]

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
(
161 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" 162 .
(self : String) -> Array[Char]

Converts the String into an array of Chars.

to_array
()
163 .
(self : Array[Char], f : (Char) -> Byte) -> Array[Byte]

Maps a function over the elements of the array.

Example

let v = [3, 4, 5]
let v2 = v.map(fn (x) {x + 1})
assert_eq(v2, [4, 5, 6])
map
(fn(
Char
c
) {
Char
c
.
(self : Char) -> Int

Converts a character to its Unicode code point value as an integer.

Parameters:

  • self : The character to be converted.

Returns an integer representing the Unicode code point value of the character.

Example:

test "Char::to_int" {
  inspect('A'.to_int(), content="65") // ASCII value of 'A'
  inspect('あ'.to_int(), content="12354") // Unicode code point of 'あ'
}
to_int
().
(self : Int) -> Byte

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

Parameters:

  • value : The 32-bit signed 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 "Int::to_byte" {
  let n = 258 // In binary: 100000010
  inspect(n.to_byte(), content="b'\\x02'") // Only keeps 00000010
  let neg = -1 // In binary: all 1's
  inspect(neg.to_byte(), content="b'\\xFF'") // Only keeps 11111111
}
to_byte
() }),
164) 165 166///| 167let
Byte
pad_char
= b'='
168