1///|
2fn args_sizes_get_ffi(argc : 
Int
Int
, size :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "args_sizes_get"
3 4///| Return command-line argument data sizes. 5/// 6/// @return Returns the number of arguments and the size of the argument string data, or an error. 7pub fn
() -> (Int, Int) raise Errno

Return command-line argument data sizes.

@return Returns the number of arguments and the size of the argument string data, or an error.

args_sizes_get
() -> (
Int
Int
,
Int
Int
) raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
8 let
Int
argc_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
9 let
Int
size_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
10 let
UInt
ret
=
(argc : Int, size : Int) -> UInt
args_sizes_get_ffi
(
Int
argc_ptr
,
Int
size_ptr
)
11 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
12 let
Int
argc
=
(offset : Int) -> Int
@ffi.load32
(
Int
argc_ptr
)
13
(position : Int) -> Unit
@ffi.free
(
Int
argc_ptr
)
14 let
Int
size
=
(offset : Int) -> Int
@ffi.load32
(
Int
size_ptr
)
15
(position : Int) -> Unit
@ffi.free
(
Int
size_ptr
)
16 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
17 raise
Errno
ret
18 } 19 (
Int
argc
,
Int
size
)
20} 21 22///| 23fn args_get_ffi(argv :
Int
Int
, argv_buf :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "args_get"
24 25///| Read command-line argument data. 26/// 27/// The size of the array should match that returned by `args_sizes_get`. 28/// 29/// Each argument is **not** `\0` terminated. 30/// 31/// The first argument should be a string containing the "name" of the 32/// program. This need not be a usable filesystem path or even file name, 33/// and may even be a fixed string. Subsequent arguments are the arguments 34/// passed to the program by the user. 35pub fn
() -> Array[String] raise Errno

Read command-line argument data.

The size of the array should match that returned by args_sizes_get.

Each argument is not \0 terminated.

The first argument should be a string containing the "name" of the program. This need not be a usable filesystem path or even file name, and may even be a fixed string. Subsequent arguments are the arguments passed to the program by the user.

args_get
() ->
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
String
String
] raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
36 let (
Int
argc
,
Int
size
) =
() -> (Int, Int) raise Errno

Return command-line argument data sizes.

@return Returns the number of arguments and the size of the argument string data, or an error.

args_sizes_get
()
37 if
Int
argc
(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:

  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
==
0 {
38 return [] 39 } 40 let
Int
arg_ptr_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
argc
(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:

  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)
41 let
Bytes
arg_buf
=
(Int, Byte) -> Bytes
Bytes::
(len : Int, init : Byte) -> Bytes

Creates a new byte sequence of the specified length, where each byte is initialized to the given value. Returns an empty byte sequence if the length is negative.

Parameters:

  • length : The length of the byte sequence to create. Must be non-negative.
  • initial_value : The byte value used to initialize each position in the sequence.

Example:

  let bytes = Bytes::make(3, b'\xFF')
  inspect(bytes, content=
  #|b"\xff\xff\xff"
)
  let empty = Bytes::make(0, b'\x00')
  inspect(empty, content="b\"\"")
make
(
Int
size
, b'\x00')
42 let
Int
arg_buf_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
arg_buf
)
43 let
UInt
ret
=
(argv : Int, argv_buf : Int) -> UInt
args_get_ffi
(
Int
arg_ptr_ptr
,
Int
arg_buf_ptr
)
44 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
45 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
46
(position : Int) -> Unit
@ffi.free
(
Int
arg_ptr_ptr
)
47
(position : Int) -> Unit
@ffi.free
(
Int
arg_buf_ptr
)
48 raise
Errno
ret
49 } 50 let
Array[String]
args
= []
51 for
Int
i
in
Int
0
..<
Int
argc
{
52 let
Int
arg_start
=
(offset : Int) -> Int
@ffi.load32
(
Int
arg_ptr_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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

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:

  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
arg_buf_ptr
53 let
Int
arg_end
= if
Int
i
(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:

  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
==
Int
argc
(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:

  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
-
1 {
54
Int
size
55 } else { 56
(offset : Int) -> Int
@ffi.load32
(
Int
arg_ptr_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
(
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
1)
(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:

  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

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:

  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
arg_buf_ptr
57 } 58 let
Int
len
=
Int
arg_end
(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:

  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
arg_start
(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:

  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
-
1 // remove trailing zero
59
Array[String]
args
.
(self : Array[String], value : String) -> Unit

Adds an element to the end of the array.

If the array is at capacity, it will be reallocated.

Example

  let v = []
  v.push(3)
push
(
60
Bytes
arg_buf
[
Int
arg_start
:
Int
arg_start
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
Int
len
]
61 |>
(input : @bytes.View, encoding~ : @encoding.Encoding) -> String
@encoding.decode_lossy
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
),
62 ) 63 } 64
(position : Int) -> Unit
@ffi.free
(
Int
arg_ptr_ptr
)
65
(position : Int) -> Unit
@ffi.free
(
Int
arg_buf_ptr
)
66
Array[String]
args
67} 68 69///| 70fn environ_sizes_get_ffi(argc :
Int
Int
, size :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "environ_sizes_get"
71 72///| Return environment variable data sizes. 73/// 74/// @return Returns the number of environment variables arguments and the size of the environment variable data. 75pub fn
() -> (Int, Int) raise Errno

Return environment variable data sizes.

@return Returns the number of environment variables arguments and the size of the environment variable data.

environ_sizes_get
() -> (
Int
Int
,
Int
Int
) raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
76 let
Int
argc_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
77 let
Int
size_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
78 let
UInt
ret
=
(argc : Int, size : Int) -> UInt
environ_sizes_get_ffi
(
Int
argc_ptr
,
Int
size_ptr
)
79 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
80 let
Int
argc
=
(offset : Int) -> Int
@ffi.load32
(
Int
argc_ptr
)
81 let
Int
size
=
(offset : Int) -> Int
@ffi.load32
(
Int
size_ptr
)
82
(position : Int) -> Unit
@ffi.free
(
Int
argc_ptr
)
83
(position : Int) -> Unit
@ffi.free
(
Int
size_ptr
)
84 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
85 raise
Errno
ret
86 } 87 (
Int
argc
,
Int
size
)
88} 89 90///| 91fn environ_get_ffi(environ :
Int
Int
, environ_buf :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "environ_get"
92 93///| Read environment variable data. 94/// 95/// The size of the array should match that returned by `environ_sizes_get`. 96pub fn
() -> Array[(String, String)] raise Errno

Read environment variable data.

The size of the array should match that returned by environ_sizes_get.

environ_get
() ->
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[(
String
String
,
String
String
)] raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
97 let (
Int
argc
,
Int
size
) =
() -> (Int, Int) raise Errno

Return environment variable data sizes.

@return Returns the number of environment variables arguments and the size of the environment variable data.

environ_sizes_get
()
98 if
Int
argc
(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:

  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
==
0 {
99 return [] 100 } 101 let
Int
environ_ptr_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
argc
(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:

  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)
102 let
Bytes
environ_buf
=
(Int, Byte) -> Bytes
Bytes::
(len : Int, init : Byte) -> Bytes

Creates a new byte sequence of the specified length, where each byte is initialized to the given value. Returns an empty byte sequence if the length is negative.

Parameters:

  • length : The length of the byte sequence to create. Must be non-negative.
  • initial_value : The byte value used to initialize each position in the sequence.

Example:

  let bytes = Bytes::make(3, b'\xFF')
  inspect(bytes, content=
  #|b"\xff\xff\xff"
)
  let empty = Bytes::make(0, b'\x00')
  inspect(empty, content="b\"\"")
make
(
Int
size
, b'\x00')
103 let
Int
environ_buf_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
environ_buf
)
104 let
UInt
ret
=
(environ : Int, environ_buf : Int) -> UInt
environ_get_ffi
(
Int
environ_ptr_ptr
,
Int
environ_buf_ptr
)
105 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
106 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
107
(position : Int) -> Unit
@ffi.free
(
Int
environ_ptr_ptr
)
108
(position : Int) -> Unit
@ffi.free
(
Int
environ_buf_ptr
)
109 raise
Errno
ret
110 } 111 let
Array[(String, String)]
envs
= []
112 for
Int
i
in
Int
0
..<
Int
argc
{
113 let
Int
env_start
=
(offset : Int) -> Int
@ffi.load32
(
Int
environ_ptr_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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

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:

  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
environ_buf_ptr
114 let
Int
env_end
= if
Int
i
(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:

  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
==
Int
argc
(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:

  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
-
1 {
115
Int
size
116 } else { 117
(offset : Int) -> Int
@ffi.load32
(
Int
environ_ptr_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
(
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
1)
(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:

  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

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:

  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
environ_buf_ptr
118 } 119 let
Int
len
=
Int
env_end
(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:

  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
env_start
(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:

  let a = 42
  let b = 10
  inspect(a - b, content="32")
  let max = 2147483647 // Int maximum value
  inspect(max - -1, content="-2147483648") // Overflow case
-
1 // remove trailing zero
120 let
String
str
=
Bytes
environ_buf
[
Int
env_start
:
Int
env_start
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
Int
len
]
121 |>
(input : @bytes.View, encoding~ : @encoding.Encoding) -> String
@encoding.decode_lossy
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
122 guard
String
str
.
(self : String, sep : @string.StringView) -> Iter[@string.StringView]

Splits the string into all substrings separated by the given separator.

If the string does not contain the separator and the separator is not empty, the returned iterator will contain only one element, which is the original string.

If the separator is empty, the returned iterator will contain all the characters in the string as single elements.

split
("=").
(self : Iter[@string.StringView]) -> Array[@string.StringView]

Collects the elements of the iterator into an array.

collect
() is
Array[@string.StringView]
[
@string.StringView
key
Array[@string.StringView]
, .. value]
123
Array[(String, String)]
envs
.
(self : Array[(String, String)], value : (String, String)) -> Unit

Adds an element to the end of the array.

If the array is at capacity, it will be reallocated.

Example

  let v = []
  v.push(3)
push
(
124 (
@string.StringView
key
.
(self : @string.StringView) -> String

Returns a new String containing a copy of the characters in this view.

Examples

  let str = "Hello World"
  let view = str.charcodes(start = str.offset_of_nth_char(0).unwrap(),end   = str.offset_of_nth_char(5).unwrap()) // "Hello"
  inspect(view.to_string(), content="Hello")
to_string
(),
ArrayView[@string.StringView]
value
.
(self : ArrayView[@string.StringView]) -> Iter[@string.StringView]

Returns an iterator that yields each element of the array view in sequence from start to end.

Parameters:

  • array_view : The array view to iterate over.

Returns an iterator that yields elements of type A from the array view.

Example:

  let arr = [1, 2, 3]
  let view = arr[1:]
  let mut sum = 0
  view.iter().each(fn(x) { sum = sum + x })
  inspect(sum, content="5")
iter
().
(self : Iter[@string.StringView], f : (@string.StringView) -> String) -> Iter[String]

Transforms the elements of the iterator using a mapping function.

Type Parameters

  • T: The type of the elements in the iterator.
  • R: The type of the transformed elements.

Arguments

  • self - The input iterator.
  • f - The mapping function that transforms each element of the iterator.

Returns

A new iterator that contains the transformed elements.

map
(
type @string.StringView

A @string.View represents a view of a String that maintains proper Unicode character boundaries. It allows safe access to a substring while handling multi-byte characters correctly.

@string.View
(@string.StringView) -> String

Returns a new String containing a copy of the characters in this view.

Examples

  let str = "Hello World"
  let view = str.charcodes(start = str.offset_of_nth_char(0).unwrap(),end   = str.offset_of_nth_char(5).unwrap()) // "Hello"
  inspect(view.to_string(), content="Hello")
::to_string
).
(self : Iter[String], sep : String) -> String

Collects the elements of the iterator into a string.

join
("=")),
125 ) 126 } 127
(position : Int) -> Unit
@ffi.free
(
Int
environ_ptr_ptr
)
128
(position : Int) -> Unit
@ffi.free
(
Int
environ_buf_ptr
)
129
Array[(String, String)]
envs
130} 131 132///| 133fn clock_res_get_ffi(clock_id :
UInt
UInt
, resolution :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "clock_res_get"
134 135///| Return the resolution of a clock. 136/// 137/// Implementations are required to provide a non-zero value for supported clocks. 138/// For unsupported clocks, return `errno::inval`. 139/// 140/// Note: This is similar to `clock_getres` in POSIX. 141/// 142/// @param `self` The clock for which to return the resolution. 143/// @return The resolution of the clock, or an error if one happened. 144pub fn
(self : ClockId) -> TimeStamp raise Errno

Return the resolution of a clock.

Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return errno::inval.

Note: This is similar to clock_getres in POSIX.

@param self The clock for which to return the resolution.
@return The resolution of the clock, or an error if one happened.

clock_res_get
(
ClockId
self
:
enum ClockId {
  RealTime
  Monotonic
  ProcessCPUTimeId
  ThreadCPUTimeId
}

Identifiers for clocks.

  • Realtime: The clock measuring real time. Time value zero corresponds with 1970-01-01T00:00:00Z.
  • Monotonic: The store-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be adjusted and which cannot have negative clock jumps. The epoch of this clock is undefined. The absolute time value of this clock therefore has no meaning.
  • ProcessCPUTimeId: The CPU-time clock associated with the current process.
  • ThreadCPUTimeId: The CPU-time clock associated with the current thread.
ClockId
) ->
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
145 let
Int
resolution_ptr
=
(size : Int) -> Int
@ffi.malloc
(8)
146 let
UInt
ret
=
(clock_id : UInt, resolution : Int) -> UInt
clock_res_get_ffi
(
ClockId
self
.
(self : ClockId) -> UInt
value
(),
Int
resolution_ptr
)
147 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
148 let
UInt64
resolution
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
resolution_ptr
)
149
(position : Int) -> Unit
@ffi.free
(
Int
resolution_ptr
)
150 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
151 raise
Errno
ret
152 } 153
UInt64
resolution
154} 155 156///| 157fn clock_time_get_ffi(clock_id :
UInt
UInt
, precision :
UInt64
UInt64
, time :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "clock_time_get"
158 159///| Return the time value of a clock 160/// 161/// Note: This is similar to `clock_gettime` in POSIX. 162/// 163/// @param `self` The clodk for which to return the time. 164/// @param `precision` The maximum lag (exclusive) that the returned time value may have, compared to its actual value. 165/// @return The time value of the clock. 166pub fn
(self : ClockId, precision : TimeStamp) -> TimeStamp raise Errno

Return the time value of a clock

Note: This is similar to clock_gettime in POSIX.

@param self The clodk for which to return the time.
@param precision The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
@return The time value of the clock.

clock_time_get
(
167
ClockId
self
:
enum ClockId {
  RealTime
  Monotonic
  ProcessCPUTimeId
  ThreadCPUTimeId
}

Identifiers for clocks.

  • Realtime: The clock measuring real time. Time value zero corresponds with 1970-01-01T00:00:00Z.
  • Monotonic: The store-wide monotonic clock, which is defined as a clock measuring real time, whose value cannot be adjusted and which cannot have negative clock jumps. The epoch of this clock is undefined. The absolute time value of this clock therefore has no meaning.
  • ProcessCPUTimeId: The CPU-time clock associated with the current process.
  • ThreadCPUTimeId: The CPU-time clock associated with the current thread.
ClockId
,
168
TimeStamp
precision
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
169) ->
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
170 let
Int
time_ptr
=
(size : Int) -> Int
@ffi.malloc
(8)
171 let
UInt
ret
=
(clock_id : UInt, precision : UInt64, time : Int) -> UInt
clock_time_get_ffi
(
ClockId
self
.
(self : ClockId) -> UInt
value
(),
TimeStamp
precision
.
(self : TimeStamp) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
time_ptr
)
172 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
173 let
UInt64
time
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
time_ptr
)
174
(position : Int) -> Unit
@ffi.free
(
Int
time_ptr
)
175 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
176 raise
Errno
ret
177 } 178
UInt64
time
179} 180 181///| 182fn fd_advise_ffi( 183 fd :
Int
Int
,
184 offset :
UInt64
UInt64
,
185 len :
UInt64
UInt64
,
186 advice :
UInt
UInt
187) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_advise"
188 189///| Provide file advisory information on a file ddescriptor 190/// 191/// Note: This is similar to `posix_fadvise` in POSIX. 192/// 193/// @param `offset` The offset within the file to which the advisory applies. 194/// @param `len` The length of the region to which the advisory applies. 195/// @param `advice` The advice. 196pub fn
(self : Fd, offset : FileSize, len : FileSize, advice : Advice) -> Unit raise Errno

Provide file advisory information on a file ddescriptor

Note: This is similar to posix_fadvise in POSIX.

@param offset The offset within the file to which the advisory applies.
@param len The length of the region to which the advisory applies.
@param advice The advice.

fd_advise
(
197
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
198
FileSize
offset
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
,
199
FileSize
len
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
,
200
Advice
advice
:
enum Advice {
  Normal
  Sequential
  Random
  Willneed
  Dontneed
  Noreuse
}

File or memory access pattern advisory information.

  • Normal: The application has no advice to give on its behavior with respect to the specified data.
  • Sequential: The application expects to access the specified data sequentially from lower offsets to higher offsets.
  • Random: The application expects to access the specified data in a random order.
  • Willneed: The application expects to access the specified data in the near future.
  • Dontneed: The application expects that it will not access the specified data in the near future.
  • Noreuse: The application expects to access the specified data once and then not reuse it afterwards.
Advice
201) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
202 let
UInt
ret
=
(fd : Int, offset : UInt64, len : UInt64, advice : UInt) -> UInt
fd_advise_ffi
(
203
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
204
FileSize
offset
.
(self : FileSize) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
205
FileSize
len
.
(self : FileSize) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
206
Advice
advice
.
(self : Advice) -> UInt
value
(),
207 ) 208 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
209 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
210 raise
Errno
ret
211 } 212} 213 214///| 215fn fd_allocate_ffi(fd :
Int
Int
, offset :
UInt64
UInt64
, len :
UInt64
UInt64
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_allocate"
216 217///| Force the allocaiton of space in a file. 218/// 219/// Note: This is similar to `posix_fallocate` in POSIX. 220/// 221/// @param `offset` The offset at which to start allocating. 222/// @param `len` The length of the area that is allocated. 223/// @return The error code. 224pub fn
(self : Fd, offset : FileSize, len : FileSize) -> Unit raise Errno

Force the allocaiton of space in a file.

Note: This is similar to posix_fallocate in POSIX.

@param offset The offset at which to start allocating.
@param len The length of the area that is allocated.
@return The error code.

fd_allocate
(
225
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
226
FileSize
offset
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
,
227
FileSize
len
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
228) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
229 let
UInt
ret
=
(fd : Int, offset : UInt64, len : UInt64) -> UInt
fd_allocate_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
FileSize
offset
.
(self : FileSize) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
FileSize
len
.
(self : FileSize) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
())
230 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
231 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
232 raise
Errno
ret
233 } 234} 235 236///| 237fn fd_close_ffi(fd :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_close"
238 239///| Close a file descriptor. 240/// 241/// Note: This is similar to `close` in POSIX. 242pub fn
(self : Fd) -> Unit raise Errno

Close a file descriptor.

Note: This is similar to close in POSIX.

fd_close
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
243 let
UInt
ret
=
(fd : Int) -> UInt
fd_close_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
())
244 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
245 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
246 raise
Errno
ret
247 } 248} 249 250///| 251fn fd_datasync_ffi(fd :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_datasync"
252 253///| Synchronize the data of a file to disk. 254/// 255/// Note: This is similar to `fdatasync` in POSIX. 256pub fn
(self : Fd) -> Unit raise Errno

Synchronize the data of a file to disk.

Note: This is similar to fdatasync in POSIX.

fd_datasync
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
257 let
UInt
ret
=
(fd : Int) -> UInt
fd_datasync_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
())
258 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
259 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
260 raise
Errno
ret
261 } 262} 263 264///| 265fn fd_fdstat_get_ffi(fd :
Int
Int
, buf :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_fdstat_get"
266 267///| Get the attributes of a file descriptor. 268/// 269/// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX, as well as additional fields. 270pub fn
(self : Fd) -> FdStat raise Errno

Get the attributes of a file descriptor.

Note: This returns similar flags to fcntl(fd, F_GETFL) in POSIX, as well as additional fields.

fd_fdstat_get
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
struct FdStat {
  fs_filetype: FileType
  fs_flags: FdFlags
  fs_rights_base: Rights
  fs_rights_inheriting: Rights
}

File descriptor attributes.

  • fs_filetype: File type.
  • fs_flags: File descriptor flags.
  • fs_rights_base: Rights that apply to this file descriptor.
  • fs_rights_inheriting: Maximum set of rights that may be installed on new file descriptors that are created through this file descriptor, e.g., through path_open.
FdStat
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
271 let
Int
buf_ptr
=
(size : Int) -> Int
@ffi.malloc
(24)
272 let
UInt
ret
=
(fd : Int, buf : Int) -> UInt
fd_fdstat_get_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
buf_ptr
)
273 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
274 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
275
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
276 raise
Errno
ret
277 } 278 let
FileType
fs_filetype
:
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
=
(offset : Int) -> Int
@ffi.load8_u
(
Int
buf_ptr
)
279 |>
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
(Int) -> FileType?
::from_value
280 |>
enum Option[A] {
  None
  Some(A)
}
Option
(FileType?) -> FileType

Extract the value in Some.

If the value is None, it throws a panic.

::unwrap
281 let
FdFlags
fs_flags
:
type FdFlags UInt

File descriptor flag.

FdFlags
=
(offset : Int) -> UInt
@ffi.load16_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
2)
282 let
Rights
fs_rights_base
:
type Rights UInt64

File descriptor rights, determining which actions may be performed.

Rights
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8)
283 let
Rights
fs_rights_inheriting
:
type Rights UInt64

File descriptor rights, determining which actions may be performed.

Rights
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
16)
284 let
FdStat
buf
=
struct FdStat {
  fs_filetype: FileType
  fs_flags: FdFlags
  fs_rights_base: Rights
  fs_rights_inheriting: Rights
}

File descriptor attributes.

  • fs_filetype: File type.
  • fs_flags: File descriptor flags.
  • fs_rights_base: Rights that apply to this file descriptor.
  • fs_rights_inheriting: Maximum set of rights that may be installed on new file descriptors that are created through this file descriptor, e.g., through path_open.
FdStat
::{
285
FileType
fs_filetype
,
286
FdFlags
fs_flags
,
287
Rights
fs_rights_base
,
288
Rights
fs_rights_inheriting
,
289 } 290
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
291
FdStat
buf
292} 293 294///| 295fn fd_fdstat_set_flags_ffi(fd :
Int
Int
, flags :
UInt
UInt
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_fdstat_set_flags"
296 297///| Adjust the flags associated with a file descriptor. 298/// 299/// Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. 300/// 301/// @param `flags` The desired values of the file descriptor flags. 302pub fn
(self : Fd, flags : FdFlags) -> Unit raise Errno

Adjust the flags associated with a file descriptor.

Note: This is similar to fcntl(fd, F_SETFL, flags) in POSIX.

@param flags The desired values of the file descriptor flags.

fd_fdstat_set_flags
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
FdFlags
flags
:
type FdFlags UInt

File descriptor flag.

FdFlags
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
303 let
UInt
ret
=
(fd : Int, flags : UInt) -> UInt
fd_fdstat_set_flags_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
FdFlags
flags
.
(self : FdFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
())
304 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
305 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
306 raise
Errno
ret
307 } 308} 309 310///| 311fn fd_fdstat_set_rights_ffi( 312 fd :
Int
Int
,
313 fs_rights_base :
UInt64
UInt64
,
314 fs_rights_inheriting :
UInt64
UInt64
315) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_fdstat_set_rights"
316 317///| Adjust the rights associated with a file descriptor. 318/// 319/// This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights. 320/// 321/// @param `fs_rights_base` The desired rights of the file descriptor. 322pub fn
(self : Fd, fs_rights_base : Rights, fs_rights_inheriting : Rights) -> Unit raise Errno

Adjust the rights associated with a file descriptor.

This can only be used to remove rights, and returns errno::notcapable if called in a way that would attempt to add rights.

@param fs_rights_base The desired rights of the file descriptor.

fd_fdstat_set_rights
(
323
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
324
Rights
fs_rights_base
:
type Rights UInt64

File descriptor rights, determining which actions may be performed.

Rights
,
325
Rights
fs_rights_inheriting
:
type Rights UInt64

File descriptor rights, determining which actions may be performed.

Rights
326) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
327 let
UInt
ret
=
(fd : Int, fs_rights_base : UInt64, fs_rights_inheriting : UInt64) -> UInt
fd_fdstat_set_rights_ffi
(
328
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
329
Rights
fs_rights_base
.
(self : Rights) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
330
Rights
fs_rights_inheriting
.
(self : Rights) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
331 ) 332 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
333 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
334 raise
Errno
ret
335 } 336} 337 338///| 339fn fd_filestat_get_ffi(fd :
Int
Int
, buf :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_filestat_get"
340 341///| Return the attributes of an open file 342pub fn
(self : Fd) -> FileStat raise Errno

Return the attributes of an open file

fd_filestat_get
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
struct FileStat {
  dev: Device
  ino: Inode
  filetype: FileType
  nlink: LinkCount
  size: FileSize
  atim: TimeStamp
  mtim: TimeStamp
  ctim: TimeStamp
}

File attributes.

  • dev: Device ID of device containing the file.
  • ino: File serial number.
  • filetype: File type.
  • nlink: Number of hard links to the file.
  • size: For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
  • atim: Last data access timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • mtim: Last data modification timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • ctim: Last file status change timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
FileStat
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
343 let
Int
buf_ptr
=
(size : Int) -> Int
@ffi.malloc
(24)
344 let
UInt
ret
=
(fd : Int, buf : Int) -> UInt
fd_filestat_get_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
buf_ptr
)
345 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
346 let
Device
dev
:
type Device UInt64

Identifier for a device containing a file system. Can be used in combination with inode to uniquely identify a file or directory in the filesystem.

Device
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
)
347 let
Inode
ino
:
type Inode UInt64

File serial number that is unique within its file system.

Inode
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8)
348 let
FileType
filetype
:
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
=
(offset : Int) -> Int
@ffi.load8_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
16)
349 |>
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
(Int) -> FileType?
::from_value
350 |>
enum Option[A] {
  None
  Some(A)
}
Option
(FileType?) -> FileType

Extract the value in Some.

If the value is None, it throws a panic.

::unwrap
351 let
LinkCount
nlink
:
type LinkCount UInt64

Number of hard links to an inode.

LinkCount
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24)
352 let
FileSize
size
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
32)
353 let
TimeStamp
atim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
40)
354 let
TimeStamp
mtim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
48)
355 let
TimeStamp
ctim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
56)
356 let
FileStat
buf
=
struct FileStat {
  dev: Device
  ino: Inode
  filetype: FileType
  nlink: LinkCount
  size: FileSize
  atim: TimeStamp
  mtim: TimeStamp
  ctim: TimeStamp
}

File attributes.

  • dev: Device ID of device containing the file.
  • ino: File serial number.
  • filetype: File type.
  • nlink: Number of hard links to the file.
  • size: For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
  • atim: Last data access timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • mtim: Last data modification timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • ctim: Last file status change timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
FileStat
::{
Device
dev
,
Inode
ino
,
FileType
filetype
,
LinkCount
nlink
,
FileSize
size
,
TimeStamp
atim
,
TimeStamp
mtim
,
TimeStamp
ctim
}
357
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
358 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
359 raise
Errno
ret
360 } 361
FileStat
buf
362} 363 364///| 365fn fd_filestat_set_size_ffi(ffi :
Int
Int
, size :
UInt64
UInt64
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_filestat_set_size"
366 367///| Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. 368/// 369/// Note: This is similar to `ftruncate` in POSIX. 370/// 371/// @param `size` The desired file size. 372pub fn
(self : Fd, size : FileSize) -> Unit raise Errno

Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.

Note: This is similar to ftruncate in POSIX.

@param size The desired file size.

fd_filestat_set_size
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
FileSize
size
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
373 let
UInt
ret
=
(ffi : Int, size : UInt64) -> UInt
fd_filestat_set_size_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
FileSize
size
.
(self : FileSize) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
())
374 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
375 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
376 raise
Errno
ret
377 } 378} 379 380///| 381fn fd_filestat_set_times_ffi( 382 fd :
Int
Int
,
383 atim :
UInt64
UInt64
,
384 mtim :
UInt64
UInt64
,
385 fst_flags :
UInt
UInt
386) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_filestat_set_times"
387 388///| Adjust the timestamps of an open file or directory. 389/// 390/// Note: This is similar to `futimens` in POSIX. 391/// 392/// @param `atim` The desired value of the data access timestamp. 393/// @param `mtim` The desired value of the data modification timestamp. 394/// @param `fst_flags` A bitmask indicating which timestamps to adjust. 395pub fn
(self : Fd, atim : TimeStamp, mtim : TimeStamp, fst_flags : FstFlags) -> Unit raise Errno

Adjust the timestamps of an open file or directory.

Note: This is similar to futimens in POSIX.

@param atim The desired value of the data access timestamp.
@param mtim The desired value of the data modification timestamp.
@param fst_flags A bitmask indicating which timestamps to adjust.

fd_filestat_set_times
(
396
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
397
TimeStamp
atim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
,
398
TimeStamp
mtim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
,
399
FstFlags
fst_flags
:
type FstFlags UInt

Which file time attributes to adjust

FstFlags
400) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
401 let
UInt
ret
=
(fd : Int, atim : UInt64, mtim : UInt64, fst_flags : UInt) -> UInt
fd_filestat_set_times_ffi
(
402
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
403
TimeStamp
atim
.
(self : TimeStamp) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
404
TimeStamp
mtim
.
(self : TimeStamp) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
405
FstFlags
fst_flags
.
(self : FstFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
406 ) 407 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
408 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
409 raise
Errno
ret
410 } 411} 412 413///| 414fn fd_pread_ffi( 415 fd :
Int
Int
,
416 iovs :
Int
Int
,
417 iovs_len :
Int
Int
,
418 offset :
UInt64
UInt64
,
419 nread :
Int
Int
420) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_pread"
421 422///| Read from a file descriptor, without using and updating the file descriptor's offset. 423/// 424/// Note: This is similar to `preadv` in Linux (and other Unix-es). 425pub fn
(self : Fd, iovs : Array[FixedArray[Byte]], offset : FileSize) -> Size raise Errno

Read from a file descriptor, without using and updating the file descriptor's offset.

Note: This is similar to preadv in Linux (and other Unix-es).

fd_pread
(
426
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
427
Array[FixedArray[Byte]]
iovs
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
type FixedArray[A]
FixedArray
[
Byte
Byte
]],
428
FileSize
offset
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
429) ->
type Size UInt
Size
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
430 let
Int
iovs_len
=
Array[FixedArray[Byte]]
iovs
.
(self : Array[FixedArray[Byte]]) -> Int

Returns the number of elements in the array.

Parameters:

  • array : The array whose length is to be determined.

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

Example:

  let arr = [1, 2, 3]
  inspect(arr.length(), content="3")
  let empty : Array[Int] = []
  inspect(empty.length(), content="0")
length
()
431 let
Int
iovs_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
iovs_len
(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:

  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)
432 for
Int
i
,
FixedArray[Byte]
byte
in
Array[FixedArray[Byte]]
iovs
{
433 let
Int
ptr
=
(bytes : FixedArray[Byte]) -> Int
@ffi.byte_array2ptr
(
FixedArray[Byte]
byte
)
434
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
iovs_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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,
Int
ptr
)
435
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
iovs_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
4,
FixedArray[Byte]
byte
.
(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:

  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
length
())
436
(position : Int) -> Unit
@ffi.free
(
Int
ptr
)
437 } 438 let
Int
nread_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
439 let
UInt
ret
=
(fd : Int, iovs : Int, iovs_len : Int, offset : UInt64, nread : Int) -> UInt
fd_pread_ffi
(
440
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
441
Int
iovs_ptr
,
442
Int
iovs_len
,
443
FileSize
offset
.
(self : FileSize) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
444
Int
nread_ptr
,
445 ) 446 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
447 let
UInt
nread
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
nread_ptr
)
448
(position : Int) -> Unit
@ffi.free
(
Int
nread_ptr
)
449
(position : Int) -> Unit
@ffi.free
(
Int
iovs_ptr
)
450 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
451 raise
Errno
ret
452 } 453
(t : Array[FixedArray[Byte]]) -> Unit

Evaluates an expression and discards its result. This is useful when you want to execute an expression for its side effects but don't care about its return value, or when you want to explicitly indicate that a value is intentionally unused.

Parameters:

  • value : The value to be ignored. Can be of any type.

Example:

  let x = 42
  ignore(x) // Explicitly ignore the value
  let mut sum = 0
  ignore([1, 2, 3].iter().each(fn(x) { sum = sum + x })) // Ignore the Unit return value of each()
ignore
(
Array[FixedArray[Byte]]
iovs
)
454
UInt
nread
455} 456 457///| 458fn fd_prestat_get_ffi(fd :
Int
Int
, buf :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_prestat_get"
459 460///| Return a description of the given preopened file descriptor. 461/// 462/// Note: consider using `fd_prestat_dir_name` directly. 463pub fn
(self : Fd) -> PreStat raise Errno

Return a description of the given preopened file descriptor.

Note: consider using fd_prestat_dir_name directly.

fd_prestat_get
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
enum PreStat {
  Dir(PreStat_dir)
}

Information about a pre-opened capability.

PreStat
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
464 let
Int
buf_ptr
=
(size : Int) -> Int
@ffi.malloc
(8)
465 let
UInt
ret
=
(fd : Int, buf : Int) -> UInt
fd_prestat_get_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
buf_ptr
)
466 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
467 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
468
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
469 raise
Errno
ret
470 } 471 // There's no other possibility of tag... 472 guard
(offset : Int) -> Int
@ffi.load8_u
(
Int
buf_ptr
) is 0
473 let
Size
size
:
type Size UInt
Size
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
4)
474 let
PreStat
buf
= PreStat::
(PreStat_dir) -> PreStat
Dir
(
struct PreStat_dir {
  pr_name_len: Size
}

The content of a prestat when type is preopentype::dir.

  • pr_name_len: The length of the directory name for use with fd_prestat_dir_name.
PreStat_dir
::{
Size
pr_name_len
:
Size
size
})
475
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
476
PreStat
buf
477} 478 479///| 480fn fd_prestat_dir_name_ffi(fd :
Int
Int
, path :
Int
Int
, path_len :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_prestat_dir_name"
481 482///| Return a description of the given preopened file descriptor. 483pub fn
(self : Fd) -> String raise Errno

Return a description of the given preopened file descriptor.

fd_prestat_dir_name
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
String
String
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
484 let
PreStat
prestat
=
Fd
self
.
(self : Fd) -> PreStat raise Errno

Return a description of the given preopened file descriptor.

Note: consider using fd_prestat_dir_name directly.

fd_prestat_get
()
485 guard
PreStat
prestat
is
(PreStat_dir) -> PreStat
Dir
({
Size
pr_name_len
:
(UInt) -> Size
Size
(
UInt
size
) })
486 let
Bytes
buffer
=
(Int, Byte) -> Bytes
Bytes::
(len : Int, init : Byte) -> Bytes

Creates a new byte sequence of the specified length, where each byte is initialized to the given value. Returns an empty byte sequence if the length is negative.

Parameters:

  • length : The length of the byte sequence to create. Must be non-negative.
  • initial_value : The byte value used to initialize each position in the sequence.

Example:

  let bytes = Bytes::make(3, b'\xFF')
  inspect(bytes, content=
  #|b"\xff\xff\xff"
)
  let empty = Bytes::make(0, b'\x00')
  inspect(empty, content="b\"\"")
make
(
UInt
size
.
(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
(), b'\x00')
487 let
Int
buf_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
buffer
)
488 let
UInt
ret
=
(fd : Int, path : Int, path_len : Int) -> UInt
fd_prestat_dir_name_ffi
(
489
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
490
Int
buf_ptr
,
491
UInt
size
.
(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
(),
492 ) 493 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
494
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
495 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
496 raise
Errno
ret
497 } 498
Bytes
buffer
|>
(input : @bytes.View, encoding~ : @encoding.Encoding) -> String
@encoding.decode_lossy
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
499} 500 501///| 502fn fd_read_ffi(fd :
Int
Int
, iovs :
Int
Int
, iovs_len :
Int
Int
, nread :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_read"
503 504///| Read from a file descriptor. 505/// 506/// Note: This is similar to `readv` in POSIX. 507pub fn
(self : Fd, iovs : Array[FixedArray[Byte]]) -> Size raise Errno

Read from a file descriptor.

Note: This is similar to readv in POSIX.

fd_read
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
Array[FixedArray[Byte]]
iovs
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
type FixedArray[A]
FixedArray
[
Byte
Byte
]]) ->
type Size UInt
Size
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
508 let
Int
iovs_len
=
Array[FixedArray[Byte]]
iovs
.
(self : Array[FixedArray[Byte]]) -> Int

Returns the number of elements in the array.

Parameters:

  • array : The array whose length is to be determined.

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

Example:

  let arr = [1, 2, 3]
  inspect(arr.length(), content="3")
  let empty : Array[Int] = []
  inspect(empty.length(), content="0")
length
()
509 let
Int
iovs_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
iovs_len
(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:

  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)
510 for
Int
i
,
FixedArray[Byte]
byte
in
Array[FixedArray[Byte]]
iovs
{
511 let
Int
ptr
=
(bytes : FixedArray[Byte]) -> Int
@ffi.byte_array2ptr
(
FixedArray[Byte]
byte
)
512
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
iovs_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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,
Int
ptr
)
513
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
iovs_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
4,
FixedArray[Byte]
byte
.
(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:

  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
length
())
514
(position : Int) -> Unit
@ffi.free
(
Int
ptr
)
515 } 516 let
Int
nread_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
517 let
UInt
ret
=
(fd : Int, iovs : Int, iovs_len : Int, nread : Int) -> UInt
fd_read_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
iovs_ptr
,
Int
iovs_len
,
Int
nread_ptr
)
518 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
519 let
UInt
nread
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
nread_ptr
)
520
(position : Int) -> Unit
@ffi.free
(
Int
nread_ptr
)
521
(position : Int) -> Unit
@ffi.free
(
Int
iovs_ptr
)
522 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
523 raise
Errno
ret
524 } 525
(t : Array[FixedArray[Byte]]) -> Unit

Evaluates an expression and discards its result. This is useful when you want to execute an expression for its side effects but don't care about its return value, or when you want to explicitly indicate that a value is intentionally unused.

Parameters:

  • value : The value to be ignored. Can be of any type.

Example:

  let x = 42
  ignore(x) // Explicitly ignore the value
  let mut sum = 0
  ignore([1, 2, 3].iter().each(fn(x) { sum = sum + x })) // Ignore the Unit return value of each()
ignore
(
Array[FixedArray[Byte]]
iovs
)
526
UInt
nread
527} 528 529///| 530fn fd_readdir_ffi( 531 fd :
Int
Int
,
532 buf :
Int
Int
,
533 buf_len :
Int
Int
,
534 cookie :
UInt64
UInt64
,
535 buf_used :
Int
Int
536) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_readdir"
537 538///| Read directory entries from a directory. 539/// When successful, the contents of the output buffer consist of a sequence of 540/// directory entries. Each directory entry consists of a `dirent` object, 541/// followed by `dirent::d_namlen` bytes holding the name of the directory 542/// entry. 543/// 544/// This function fills the output buffer as much as possible, potentially 545/// truncating the last directory entry. This allows the caller to grow its 546/// read buffer size in case it's too small to fit a single large directory 547/// entry, or skip the oversized directory entry. 548/// 549/// Entries for the special `.` and `..` directory entries are included in the 550/// sequence. 551/// 552/// @param `cookie`: The location within the directory to start reading. 553/// @param `size`: The buffer used to read. 554/// @return The entries untruncated and whether there's still other entries. 555pub fn
(self : Fd, cookie~ : DirCookie = .., buffer~ : Bytes = ..) -> (Array[(String, DirEnt)], Bool) raise Errno

Read directory entries from a directory. When successful, the contents of the output buffer consist of a sequence of directory entries. Each directory entry consists of a dirent object, followed by dirent::d_namlen bytes holding the name of the directory entry.

This function fills the output buffer as much as possible, potentially truncating the last directory entry. This allows the caller to grow its read buffer size in case it's too small to fit a single large directory entry, or skip the oversized directory entry.

Entries for the special . and .. directory entries are included in the sequence.

@param cookie: The location within the directory to start reading.
@param size: The buffer used to read.
@return The entries untruncated and whether there's still other entries.

fd_readdir
(
556
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
557
DirCookie
cookie
~ :
type DirCookie UInt64

A reference to the offset of a directory entry.

The value 0 signifies the start of the directory.

DirCookie
=
(UInt64) -> DirCookie

A reference to the offset of a directory entry.

The value 0 signifies the start of the directory.

DirCookie
(0),
558
Bytes
buffer
~ :
Bytes
Bytes
=
(Int, Byte) -> Bytes
Bytes::
(len : Int, init : Byte) -> Bytes

Creates a new byte sequence of the specified length, where each byte is initialized to the given value. Returns an empty byte sequence if the length is negative.

Parameters:

  • length : The length of the byte sequence to create. Must be non-negative.
  • initial_value : The byte value used to initialize each position in the sequence.

Example:

  let bytes = Bytes::make(3, b'\xFF')
  inspect(bytes, content=
  #|b"\xff\xff\xff"
)
  let empty = Bytes::make(0, b'\x00')
  inspect(empty, content="b\"\"")
make
(4096, 0)
559) -> (
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[(
String
String
,
struct DirEnt {
  d_next: DirCookie
  d_ino: Inode
  d_namlen: DirNamlen
  d_type: FileType
}

A directory entry.

  • d_next: The offset of the next directory entry stored in the buffer.
  • d_ino: The serial number of the file referred to by this directory entry.
  • d_namlen: The length of the name of the directory entry.
  • d_type: The type of the file referred to by this directory entry.
DirEnt
)],
Bool
Bool
) raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
560 let
Int
buf_len
=
Bytes
buffer
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
561 let
Int
buf_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
buffer
)
562 let
Int
buf_used_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
563 let
UInt
ret
=
(fd : Int, buf : Int, buf_len : Int, cookie : UInt64, buf_used : Int) -> UInt
fd_readdir_ffi
(
564
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
565
Int
buf_ptr
,
566
Int
buf_len
,
567
DirCookie
cookie
.
(self : DirCookie) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
568
Int
buf_used_ptr
,
569 ) 570 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
571 let
Int
buf_used
=
(offset : Int) -> Int
@ffi.load32
(
Int
buf_used_ptr
)
572
(position : Int) -> Unit
@ffi.free
(
Int
buf_used_ptr
)
573
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
574 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
575 raise
Errno
ret
576 } 577 let
Array[(String, DirEnt)]
entries
= []
578 for
Int
i
= 0;
Int
i
(self_ : Int, other : Int) -> Bool
<
Int
buf_used
; {
579 if
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24
(self_ : Int, other : Int) -> Bool
>
Int
buf_used
{
580 // truncated 581 break (
Array[(String, DirEnt)]
entries
, true)
582 } 583 let
DirCookie
d_next
:
type DirCookie UInt64

A reference to the offset of a directory entry.

The value 0 signifies the start of the directory.

DirCookie
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
Int
i
)
584 let
Inode
d_ino
:
type Inode UInt64

File serial number that is unique within its file system.

Inode
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8)
585 let
Int
namlen
=
(offset : Int) -> Int
@ffi.load32
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
16)
586 let
DirNamlen
d_namlen
:
type DirNamlen UInt

The type for the dirent::d_namlen field of dirent struct.

DirNamlen
=
Int
namlen
.
(self : Int) -> UInt

reinterpret the signed int as unsigned int, when the value is non-negative, i.e, 0..=2^31-1, the value is the same. When the value is negative, it turns into a large number, for example, -1 turns into 2^32-1

reinterpret_as_uint
()
587 let
FileType
d_type
:
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
=
(offset : Int) -> Int
@ffi.load8_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
20)
588 |>
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
(Int) -> FileType?
::from_value
589 |>
enum Option[A] {
  None
  Some(A)
}
Option
(FileType?) -> FileType

Extract the value in Some.

If the value is None, it throws a panic.

::unwrap
590 if
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
Int
namlen
(self_ : Int, other : Int) -> Bool
>
Int
buf_used
{
591 // truncated 592 break (
Array[(String, DirEnt)]
entries
, true)
593 } 594
Array[(String, DirEnt)]
entries
.
(self : Array[(String, DirEnt)], value : (String, DirEnt)) -> Unit

Adds an element to the end of the array.

If the array is at capacity, it will be reallocated.

Example

  let v = []
  v.push(3)
push
(
595 ( 596
Bytes
buffer
[
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24:
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
Int
namlen
] |>
(input : @bytes.View, encoding~ : @encoding.Encoding) -> String
@encoding.decode_lossy
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
),
597
struct DirEnt {
  d_next: DirCookie
  d_ino: Inode
  d_namlen: DirNamlen
  d_type: FileType
}

A directory entry.

  • d_next: The offset of the next directory entry stored in the buffer.
  • d_ino: The serial number of the file referred to by this directory entry.
  • d_namlen: The length of the name of the directory entry.
  • d_type: The type of the file referred to by this directory entry.
DirEnt
::{
DirCookie
d_next
,
Inode
d_ino
,
DirNamlen
d_namlen
,
FileType
d_type
},
598 ), 599 ) 600 continue
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
Int
namlen
601 } else { 602 (
Array[(String, DirEnt)]
entries
,
Int
buf_used
(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:

  inspect(42 == 42, content="true")
  inspect(42 == -42, content="false")
==
Int
buf_len
)
603 } 604} 605 606///| 607fn fd_renumber_ffi(fd :
Int
Int
, to :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_renumber"
608 609///| Atomically replace a file descriptor by renumbering another file descriptor. 610/// 611/// Due to the strong focus on thread safety, this environment does not provide 612/// a mechanism to duplicate or renumber a file descriptor to an arbitrary 613/// number, like `dup2()`. This would be prone to race conditions, as an actual 614/// file descriptor with the same number could be allocated by a different 615/// thread at the same time. 616/// 617/// This function provides a way to atomically renumber file descriptors, which 618/// would disappear if `dup2()` were to be removed entirely. 619pub fn
(self : Fd, to : Fd) -> Unit raise Errno

Atomically replace a file descriptor by renumbering another file descriptor.

Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber a file descriptor to an arbitrary number, like dup2(). This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time.

This function provides a way to atomically renumber file descriptors, which would disappear if dup2() were to be removed entirely.

fd_renumber
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
Fd
to
:
type Fd Int

A file descriptor handle

Fd
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
620 let
UInt
ret
=
(fd : Int, to : Int) -> UInt
fd_renumber_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Fd
to
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
())
621 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
622 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
623 raise
Errno
ret
624 } 625} 626 627///| 628fn fd_seek_ffi( 629 fd :
Int
Int
,
630 offset :
Int64
Int64
,
631 whence :
UInt
UInt
,
632 newoffset :
Int
Int
633) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_seek"
634 635///| Move the offset of a file descriptor. 636/// 637/// Note: This is similar to `lseek` in POSIX. 638/// 639/// @param `offset` The number of bytes to move. 640/// @param `whence` The base from which the offset is calculated. 641/// @return The new offset of the file descriptor, relative to the start of the file. 642pub fn
(self : Fd, offset : FileDelta, whence : Whence) -> FileSize raise Errno

Move the offset of a file descriptor.

Note: This is similar to lseek in POSIX.

@param offset The number of bytes to move.
@param whence The base from which the offset is calculated.
@return The new offset of the file descriptor, relative to the start of the file.

fd_seek
(
643
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
644
FileDelta
offset
:
type FileDelta Int64

Relative offset within a file.

FileDelta
,
645
Whence
whence
:
enum Whence {
  Set
  Cur
  End
}

The position relative to which to set the offset of the file descriptor

Whence
646) ->
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
647 let
Int
newoffset_ptr
=
(size : Int) -> Int
@ffi.malloc
(8)
648 let
UInt
ret
=
(fd : Int, offset : Int64, whence : UInt, newoffset : Int) -> UInt
fd_seek_ffi
(
649
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
650
FileDelta
offset
.
(self : FileDelta) -> Int64

Convert newtype to its underlying type, automatically derived.

inner
(),
651
Whence
whence
.
(self : Whence) -> UInt
value
(),
652
Int
newoffset_ptr
,
653 ) 654 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
655 let
UInt64
newoffset
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
newoffset_ptr
)
656
(position : Int) -> Unit
@ffi.free
(
Int
newoffset_ptr
)
657 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
658 raise
Errno
ret
659 } 660
UInt64
newoffset
661} 662 663///| 664fn fd_sync_ffi(fd :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_sync"
665 666///| Synchronize the data and metadata of a file to disk. 667/// 668/// Note: This is similar to `fsync` in POSIX. 669pub fn
(self : Fd) -> Unit raise Errno

Synchronize the data and metadata of a file to disk.

Note: This is similar to fsync in POSIX.

fd_sync
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
670 let
UInt
ret
=
(fd : Int) -> UInt
fd_sync_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
())
671 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
672 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
673 raise
Errno
ret
674 } 675} 676 677///| 678fn fd_tell_ffi(fd :
Int
Int
, newoffset :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_tell"
679 680///| Return the current offset of a file descriptor. 681/// 682/// Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. 683/// 684/// @return The current offset of the file descriptor, relative to the start of the file. 685pub fn
(self : Fd) -> FileSize raise Errno

Return the current offset of a file descriptor.

Note: This is similar to lseek(fd, 0, SEEK_CUR) in POSIX.

@return The current offset of the file descriptor, relative to the start of the file.

fd_tell
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
) ->
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
686 let
Int
newoffset_ptr
=
(size : Int) -> Int
@ffi.malloc
(8)
687 let
UInt
ret
=
(fd : Int, newoffset : Int) -> UInt
fd_tell_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
newoffset_ptr
)
688 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
689 let
UInt64
newoffset
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
newoffset_ptr
)
690
(position : Int) -> Unit
@ffi.free
(
Int
newoffset_ptr
)
691 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
692 raise
Errno
ret
693 } 694
UInt64
newoffset
695} 696 697///| 698fn fd_write_ffi(fd :
Int
Int
, iovs :
Int
Int
, iovs_len :
Int
Int
, nwritten :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "fd_write"
699 700///| Write to a file descriptor. 701/// 702/// Note: This is similar to `writev` in POSIX. 703/// 704/// Like POSIX, any calls of `write` (and other functions to read or write) 705/// for a regular file by other threads in the WASI process should not be 706/// interleaved while `write` is executed. 707/// 708/// Note: it may write less than demanded. 709pub fn
(self : Fd, contents : Array[@bytes.View]) -> Size raise Errno

Write to a file descriptor.

Note: This is similar to writev in POSIX.

Like POSIX, any calls of write (and other functions to read or write) for a regular file by other threads in the WASI process should not be interleaved while write is executed.

Note: it may write less than demanded.

fd_write
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
Array[@bytes.View]
contents
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
type @bytes.View

A @bytes.View represents a view into a section of a Bytes without copying the data.

Example

  let bs = b"\x00\x01\x02\x03\x04\x05"
  let bv = bs[1:4]
  assert_eq(bv.length(), 3)
  assert_eq(bv[0], b'\x01')
  assert_eq(bv[1], b'\x02')
  assert_eq(bv[2], b'\x03')
@bytes.View
]) ->
type Size UInt
Size
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
710 let
Int
iovs_len
=
Array[@bytes.View]
contents
.
(self : Array[@bytes.View]) -> Int

Returns the number of elements in the array.

Parameters:

  • array : The array whose length is to be determined.

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

Example:

  let arr = [1, 2, 3]
  inspect(arr.length(), content="3")
  let empty : Array[Int] = []
  inspect(empty.length(), content="0")
length
()
711 let
Int
iovs_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
iovs_len
(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:

  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)
712 for
Int
i
,
@bytes.View
byte
in
Array[@bytes.View]
contents
{
713 let
Int
ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
@bytes.View
byte
.
(self : @bytes.View) -> Bytes

Retrieves the underlying Bytes from a View.

data
())
714
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
iovs_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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,
Int
ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
@bytes.View
byte
.
(self : @bytes.View) -> Int

Retrieves the start index of the view.

start_offset
())
715
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
iovs_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
4,
@bytes.View
byte
.
(self : @bytes.View) -> Int

Returns the number of bytes in the view.

Parameters:

  • bytes_view : The view of a byte sequence.

Returns an integer representing the length of the view.

Example:

  let bytes = b"\x00\x01\x02\x03\x04"
  let view = bytes[2:4]
  inspect(view.length(), content="2")
length
())
716
(position : Int) -> Unit
@ffi.free
(
Int
ptr
)
717 } 718 let
Int
nwritten_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
719 let
UInt
ret
=
(fd : Int, iovs : Int, iovs_len : Int, nwritten : Int) -> UInt
fd_write_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
iovs_ptr
,
Int
iovs_len
,
Int
nwritten_ptr
)
720 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
721 let
UInt
nwritten
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
nwritten_ptr
)
722
(position : Int) -> Unit
@ffi.free
(
Int
nwritten_ptr
)
723
(position : Int) -> Unit
@ffi.free
(
Int
iovs_ptr
)
724
(t : Array[@bytes.View]) -> Unit

Evaluates an expression and discards its result. This is useful when you want to execute an expression for its side effects but don't care about its return value, or when you want to explicitly indicate that a value is intentionally unused.

Parameters:

  • value : The value to be ignored. Can be of any type.

Example:

  let x = 42
  ignore(x) // Explicitly ignore the value
  let mut sum = 0
  ignore([1, 2, 3].iter().each(fn(x) { sum = sum + x })) // Ignore the Unit return value of each()
ignore
(
Array[@bytes.View]
contents
)
725 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
726 raise
Errno
ret
727 } 728
UInt
nwritten
729} 730 731///| 732fn path_create_directory_ffi(fd :
Int
Int
, path :
Int
Int
, path_len :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_create_directory"
733 734///| Create a directory. 735/// 736/// Note: This is similar to `mkdirat` in POSIX. 737/// 738/// @param `path` The path at which to create the directory. 739pub fn
(self : Fd, path : String) -> Unit raise Errno

Create a directory.

Note: This is similar to mkdirat in POSIX.

@param path The path at which to create the directory.

path_create_directory
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
String
path
:
String
String
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
740 let
Bytes
path_bytes
=
String
path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
741 let
Int
path_len
=
Bytes
path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
742 let
Int
path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
path_bytes
)
743 let
UInt
ret
=
(fd : Int, path : Int, path_len : Int) -> UInt
path_create_directory_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
path_ptr
,
Int
path_len
)
744 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
745
(position : Int) -> Unit
@ffi.free
(
Int
path_ptr
)
746 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
747 raise
Errno
ret
748 } 749} 750 751///| 752fn path_filestat_get_ffi( 753 fd :
Int
Int
,
754 flags :
UInt
UInt
,
755 path :
Int
Int
,
756 path_len :
Int
Int
,
757 buf :
Int
Int
758) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_filestat_get"
759 760///| Return the attributes of a file or directory. 761/// 762/// Note: This is similar to `stat` in POSIX. 763/// 764/// @param `flags` Flags determining the method of how the path is resolved. 765/// @param `path` The path of the file or directory to inspect. 766pub fn
(self : Fd, flags : LookupFlags, path : String) -> FileStat raise Errno

Return the attributes of a file or directory.

Note: This is similar to stat in POSIX.

@param flags Flags determining the method of how the path is resolved.
@param path The path of the file or directory to inspect.

path_filestat_get
(
767
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
768
LookupFlags
flags
:
type LookupFlags UInt

Flags dermining the method of how paths are resolved.

LookupFlags
,
769
String
path
:
String
String
770) ->
struct FileStat {
  dev: Device
  ino: Inode
  filetype: FileType
  nlink: LinkCount
  size: FileSize
  atim: TimeStamp
  mtim: TimeStamp
  ctim: TimeStamp
}

File attributes.

  • dev: Device ID of device containing the file.
  • ino: File serial number.
  • filetype: File type.
  • nlink: Number of hard links to the file.
  • size: For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
  • atim: Last data access timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • mtim: Last data modification timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • ctim: Last file status change timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
FileStat
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
771 let
Bytes
path_bytes
=
String
path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
772 let
Int
path_len
=
Bytes
path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
773 let
Int
path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
path_bytes
)
774 let
Int
buf_ptr
=
(size : Int) -> Int
@ffi.malloc
(24)
775 let
UInt
ret
=
(fd : Int, flags : UInt, path : Int, path_len : Int, buf : Int) -> UInt
path_filestat_get_ffi
(
776
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
777
LookupFlags
flags
.
(self : LookupFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
778
Int
path_ptr
,
779
Int
path_len
,
780
Int
buf_ptr
,
781 ) 782 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
783
(position : Int) -> Unit
@ffi.free
(
Int
path_ptr
)
784 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
785
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
786 raise
Errno
ret
787 } 788 let
Device
dev
:
type Device UInt64

Identifier for a device containing a file system. Can be used in combination with inode to uniquely identify a file or directory in the filesystem.

Device
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
)
789 let
Inode
ino
:
type Inode UInt64

File serial number that is unique within its file system.

Inode
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8)
790 let
FileType
filetype
:
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
=
(offset : Int) -> Int
@ffi.load8_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
16)
791 |>
enum FileType {
  Unknown
  Block_device
  Character_device
  Directory
  Regular_file
  Socket_dgram
  Socket_stream
  Symbolic_link
}

The type of a file descriptor or file.

  • Unknown: The type of the file descriptor or file is unknown or is different from any of the other types specified.
  • Block_device: The file descriptor or file refers to a block device inode.
  • Character_device: The file descriptor or file refers to a character device inode.
  • Directory: The file descriptor or file refers to a directory inode.
  • Regular_file: The file descriptor or file refers to a regular file inode.
  • Socket_dgram: The file descriptor or file refers to a datagram socket.
  • Socket_stream: The file descriptor or file refers to a byte-stream socket.
  • Symbolic_link: The file refers to a symbolic link inode.
FileType
(Int) -> FileType?
::from_value
792 |>
enum Option[A] {
  None
  Some(A)
}
Option
(FileType?) -> FileType

Extract the value in Some.

If the value is None, it throws a panic.

::unwrap
793 let
LinkCount
nlink
:
type LinkCount UInt64

Number of hard links to an inode.

LinkCount
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24)
794 let
FileSize
size
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
32)
795 let
TimeStamp
atim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
40)
796 let
TimeStamp
mtim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
48)
797 let
TimeStamp
ctim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
buf_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
56)
798 let
FileStat
buf
=
struct FileStat {
  dev: Device
  ino: Inode
  filetype: FileType
  nlink: LinkCount
  size: FileSize
  atim: TimeStamp
  mtim: TimeStamp
  ctim: TimeStamp
}

File attributes.

  • dev: Device ID of device containing the file.
  • ino: File serial number.
  • filetype: File type.
  • nlink: Number of hard links to the file.
  • size: For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
  • atim: Last data access timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • mtim: Last data modification timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
  • ctim: Last file status change timestamp. This can be 0 if the underlying platform doesn't provide suitable timestamp for this file.
FileStat
::{
Device
dev
,
Inode
ino
,
FileType
filetype
,
LinkCount
nlink
,
FileSize
size
,
TimeStamp
atim
,
TimeStamp
mtim
,
TimeStamp
ctim
}
799
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
800
FileStat
buf
801} 802 803///| 804fn path_filestat_set_times_ffi( 805 fd :
Int
Int
,
806 flags :
UInt
UInt
,
807 path :
Int
Int
,
808 path_len :
Int
Int
,
809 atim :
UInt64
UInt64
,
810 mtim :
UInt64
UInt64
,
811 fst_flags :
UInt
UInt
812) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_filestat_set_times"
813 814///| Adjust the timestamps of a file or directory. 815/// 816/// Note: This is similar to `utimensat` in POSIX. 817/// 818/// @param `flag` Flags determining the method of how the path is resolved. 819/// @param `path` The path of the file or directory to operate on. 820/// @param `atim` The desired values of the data access timestamp. 821/// @param `mtim` The desired values of the data modification timestamp. 822/// @param `fst_flags` A bitmask indicating which timestamps to adjust. 823pub fn
(self : Fd, flags : LookupFlags, path : String, atim : TimeStamp, mtim : TimeStamp, fst_flags : FstFlags) -> Unit raise Errno

Adjust the timestamps of a file or directory.

Note: This is similar to utimensat in POSIX.

@param flag Flags determining the method of how the path is resolved.
@param path The path of the file or directory to operate on.
@param atim The desired values of the data access timestamp.
@param mtim The desired values of the data modification timestamp.
@param fst_flags A bitmask indicating which timestamps to adjust.

path_filestat_set_times
(
824
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
825
LookupFlags
flags
:
type LookupFlags UInt

Flags dermining the method of how paths are resolved.

LookupFlags
,
826
String
path
:
String
String
,
827
TimeStamp
atim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
,
828
TimeStamp
mtim
:
type TimeStamp UInt64

Timestamp in nanoseconds.

TimeStamp
,
829
FstFlags
fst_flags
:
type FstFlags UInt

Which file time attributes to adjust

FstFlags
830) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
831 let
Bytes
path_bytes
=
String
path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
832 let
Int
path_len
=
Bytes
path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
833 let
Int
path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
path_bytes
)
834 let
UInt
ret
=
(fd : Int, flags : UInt, path : Int, path_len : Int, atim : UInt64, mtim : UInt64, fst_flags : UInt) -> UInt
path_filestat_set_times_ffi
(
835
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
836
LookupFlags
flags
.
(self : LookupFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
837
Int
path_ptr
,
838
Int
path_len
,
839
TimeStamp
atim
.
(self : TimeStamp) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
840
TimeStamp
mtim
.
(self : TimeStamp) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
841
FstFlags
fst_flags
.
(self : FstFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
842 ) 843 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
844
(position : Int) -> Unit
@ffi.free
(
Int
path_ptr
)
845 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
846 raise
Errno
ret
847 } 848} 849 850///| 851fn path_link_ffi( 852 old_fd :
Int
Int
,
853 old_flags :
UInt
UInt
,
854 old_path :
Int
Int
,
855 old_path_len :
Int
Int
,
856 new_fd :
Int
Int
,
857 new_path :
Int
Int
,
858 new_path_len :
Int
Int
859) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_link"
860 861///| Create a hard link. 862/// 863/// Note: This is similar to `linkat` in POSIX. 864/// 865/// @param `old_flags` Flags determining the method of how the path is resolved. 866/// @param `old_path` The source path from which to link. 867/// @param `new_fd` The wroking directory at which the resolution of the new path starts. 868/// @param `new_path` The destination path at which to create the hard link. 869pub fn
(self : Fd, old_flags : LookupFlags, old_path : String, new_fd : Fd, new_path : String) -> Unit raise Errno

Create a hard link.

Note: This is similar to linkat in POSIX.

@param old_flags Flags determining the method of how the path is resolved.
@param old_path The source path from which to link.
@param new_fd The wroking directory at which the resolution of the new path starts.
@param new_path The destination path at which to create the hard link.

path_link
(
870
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
871
LookupFlags
old_flags
:
type LookupFlags UInt

Flags dermining the method of how paths are resolved.

LookupFlags
,
872
String
old_path
:
String
String
,
873
Fd
new_fd
:
type Fd Int

A file descriptor handle

Fd
,
874
String
new_path
:
String
String
875) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
876 let
Bytes
old_path_bytes
=
String
old_path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
877 let
Int
old_path_len
=
Bytes
old_path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
878 let
Int
old_path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
old_path_bytes
)
879 let
Bytes
new_path_bytes
=
String
new_path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
880 let
Int
new_path_len
=
Bytes
new_path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
881 let
Int
new_path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
new_path_bytes
)
882 let
UInt
ret
=
(old_fd : Int, old_flags : UInt, old_path : Int, old_path_len : Int, new_fd : Int, new_path : Int, new_path_len : Int) -> UInt
path_link_ffi
(
883
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
884
LookupFlags
old_flags
.
(self : LookupFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
885
Int
old_path_ptr
,
886
Int
old_path_len
,
887
Fd
new_fd
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
888
Int
new_path_ptr
,
889
Int
new_path_len
,
890 ) 891 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
892
(position : Int) -> Unit
@ffi.free
(
Int
old_path_ptr
)
893
(position : Int) -> Unit
@ffi.free
(
Int
new_path_ptr
)
894 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
895 raise
Errno
ret
896 } 897} 898 899///| 900fn path_open_ffi( 901 dirfd :
Int
Int
,
902 dirflags :
UInt
UInt
,
903 path :
Int
Int
,
904 path_len :
Int
Int
,
905 oflags :
UInt
UInt
,
906 fs_rights_base :
UInt64
UInt64
,
907 fs_rights_inheriting :
UInt64
UInt64
,
908 fs_flags :
UInt
UInt
,
909 fd :
Int
Int
910) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_open"
911 912///| Open a file or directory. 913/// 914/// The returned file descriptor is not guaranteed to be the lowest-numbered 915/// file descriptor not currently open; it is randomized to prevent 916/// applications from depending on making assumptions about indexes, since this 917/// is error-prone in multi-threaded contexts. The returned file descriptor is 918/// guaranteed to be less than 2^31. 919/// 920/// Note: This is similar to `openat` in POSIX. 921/// 922/// @param `dirflags` Flags determining the method of how the path is resolved. 923/// @param `path` The path of the file or directory to open. 924/// @param `oflags` The method by which to open the file. 925/// @param `fs_rights_base` The initial rights of the newly created file descriptor. The 926/// implementation is allowed to return a file descriptor with fewer rights 927/// than specified, if and only if those rights do not apply to the type of 928/// file being opened. The *base* rights are rights that will apply to operations 929/// using the file descriptor itself. 930/// @param `fs_rights_inheriting` The initial rights of the newly created file descriptor. The 931/// implementation is allowed to return a file descriptor with fewer rights 932/// than specified, if and only if those rights do not apply to the type of 933/// file being opened. The *inheriting* rights are rights that apply to 934/// file descriptors derived from it. 935/// @return The file descriptor of the file that has been opened. 936pub fn
(self : Fd, dirflags : LookupFlags, path : String, oflags : OpenFlags, fs_rights_base : Rights, fs_rights_inheriting : Rights, fs_flags : FdFlags) -> Fd raise Errno

Open a file or directory.

The returned file descriptor is not guaranteed to be the lowest-numbered file descriptor not currently open; it is randomized to prevent applications from depending on making assumptions about indexes, since this is error-prone in multi-threaded contexts. The returned file descriptor is guaranteed to be less than 2^31.

Note: This is similar to openat in POSIX.

@param dirflags Flags determining the method of how the path is resolved.
@param path The path of the file or directory to open.
@param oflags The method by which to open the file.
@param fs_rights_base The initial rights of the newly created file descriptor. The implementation is allowed to return a file descriptor with fewer rights than specified, if and only if those rights do not apply to the type of file being opened. The base rights are rights that will apply to operations using the file descriptor itself.
@param fs_rights_inheriting The initial rights of the newly created file descriptor. The implementation is allowed to return a file descriptor with fewer rights than specified, if and only if those rights do not apply to the type of file being opened. The inheriting rights are rights that apply to file descriptors derived from it.
@return The file descriptor of the file that has been opened.

path_open
(
937
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
938
LookupFlags
dirflags
:
type LookupFlags UInt

Flags dermining the method of how paths are resolved.

LookupFlags
,
939
String
path
:
String
String
,
940
OpenFlags
oflags
:
type OpenFlags UInt

Open flags used by path_open.

OpenFlags
,
941
Rights
fs_rights_base
:
type Rights UInt64

File descriptor rights, determining which actions may be performed.

Rights
,
942
Rights
fs_rights_inheriting
:
type Rights UInt64

File descriptor rights, determining which actions may be performed.

Rights
,
943
FdFlags
fs_flags
:
type FdFlags UInt

File descriptor flag.

FdFlags
944) ->
type Fd Int

A file descriptor handle

Fd
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
945 let
Bytes
path_bytes
=
String
path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
946 let
Int
path_len
=
Bytes
path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
947 let
Int
path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
path_bytes
)
948 let
Int
fd_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
949 let
UInt
ret
=
(dirfd : Int, dirflags : UInt, path : Int, path_len : Int, oflags : UInt, fs_rights_base : UInt64, fs_rights_inheriting : UInt64, fs_flags : UInt, fd : Int) -> UInt
path_open_ffi
(
950
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
951
LookupFlags
dirflags
.
(self : LookupFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
952
Int
path_ptr
,
953
Int
path_len
,
954
OpenFlags
oflags
.
(self : OpenFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
955
Rights
fs_rights_base
.
(self : Rights) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
956
Rights
fs_rights_inheriting
.
(self : Rights) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
(),
957
FdFlags
fs_flags
.
(self : FdFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
958
Int
fd_ptr
,
959 ) 960 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
961
(position : Int) -> Unit
@ffi.free
(
Int
path_ptr
)
962 let
Int
fd
=
(offset : Int) -> Int
@ffi.load32
(
Int
fd_ptr
)
963
(position : Int) -> Unit
@ffi.free
(
Int
fd_ptr
)
964 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
965 raise
Errno
ret
966 } 967
(Int) -> Fd

A file descriptor handle

Fd
(
Int
fd
)
968} 969 970///| 971fn path_readlink_ffi( 972 fd :
Int
Int
,
973 path :
Int
Int
,
974 path_len :
Int
Int
,
975 buf :
Int
Int
,
976 buf_len :
Int
Int
,
977 buf_used :
Int
Int
978) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_readlink"
979 980///| Read the contents of a symbolic link. 981/// 982/// Note: This is similar to `readlinkat` in POSIX. If `buf` is not large 983/// enough to store the contents of the link, the first `buf_len` bytes will be 984/// written `buf`. 985pub fn
(self : Fd, path : String, buffer~ : FixedArray[Byte] = ..) -> Size raise Errno

Read the contents of a symbolic link.

Note: This is similar to readlinkat in POSIX. If buf is not large enough to store the contents of the link, the first buf_len bytes will be written buf.

path_readlink
(
986
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
987
String
path
:
String
String
,
988
FixedArray[Byte]
buffer
~ :
type FixedArray[A]
FixedArray
[
Byte
Byte
] =
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:

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

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

  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
(4096, 0)
989) ->
type Size UInt
Size
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
990 let
Bytes
path_bytes
=
String
path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
991 let
Int
path_len
=
Bytes
path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
992 let
Int
path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
path_bytes
)
993 let
Int
buf_len
=
FixedArray[Byte]
buffer
.
(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:

  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
length
()
994 let
Int
buf_ptr
=
(bytes : FixedArray[Byte]) -> Int
@ffi.byte_array2ptr
(
FixedArray[Byte]
buffer
)
995 let
Int
buf_used_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
996 let
UInt
ret
=
(fd : Int, path : Int, path_len : Int, buf : Int, buf_len : Int, buf_used : Int) -> UInt
path_readlink_ffi
(
997
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
998
Int
path_ptr
,
999
Int
path_len
,
1000
Int
buf_ptr
,
1001
Int
buf_len
,
1002
Int
buf_used_ptr
,
1003 ) 1004 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1005 let
UInt
buf_used
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
buf_used_ptr
)
1006
(position : Int) -> Unit
@ffi.free
(
Int
buf_used_ptr
)
1007
(position : Int) -> Unit
@ffi.free
(
Int
path_ptr
)
1008
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
1009 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1010 raise
Errno
ret
1011 } 1012
UInt
buf_used
1013} 1014 1015///| 1016fn path_remove_directory_ffi(fd :
Int
Int
, path :
Int
Int
, path_len :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_remove_directory"
1017 1018///| Remove a directory. 1019/// 1020/// Return `errno::notempty` if the directory is not empty. 1021/// 1022/// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. 1023pub fn
(self : Fd, path : String) -> Unit raise Errno

Remove a directory.

Return errno::notempty if the directory is not empty.

Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.

path_remove_directory
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
String
path
:
String
String
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1024 let
Bytes
path_bytes
=
String
path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
1025 let
Int
path_len
=
Bytes
path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
1026 let
Int
path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
path_bytes
)
1027 let
UInt
ret
=
(fd : Int, path : Int, path_len : Int) -> UInt
path_remove_directory_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
path_ptr
,
Int
path_len
)
1028 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1029
(position : Int) -> Unit
@ffi.free
(
Int
path_ptr
)
1030 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1031 raise
Errno
ret
1032 } 1033} 1034 1035///| 1036fn path_rename_ffi( 1037 old_fd :
Int
Int
,
1038 old_path :
Int
Int
,
1039 old_path_len :
Int
Int
,
1040 new_fd :
Int
Int
,
1041 new_path :
Int
Int
,
1042 new_path_len :
Int
Int
1043) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_rename"
1044 1045///| Rename a file or directory. 1046/// 1047/// Note: This is similar to `renameat` in POSIX. 1048/// 1049/// @param `old_path` The source path of the file or directory to rename. 1050/// @param `new_fd` The working directory at which the resolution of the new path starts. 1051/// @param `new_path` The destination path of the file or directory to rename. 1052pub fn
(self : Fd, old_path : String, new_fd : Fd, new_path : String) -> Unit raise Errno

Rename a file or directory.

Note: This is similar to renameat in POSIX.

@param old_path The source path of the file or directory to rename.
@param new_fd The working directory at which the resolution of the new path starts.
@param new_path The destination path of the file or directory to rename.

path_rename
(
1053
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
1054
String
old_path
:
String
String
,
1055
Fd
new_fd
:
type Fd Int

A file descriptor handle

Fd
,
1056
String
new_path
:
String
String
1057) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1058 let
Bytes
old_path_bytes
=
String
old_path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
1059 let
Int
old_path_len
=
Bytes
old_path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
1060 let
Int
old_path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
old_path_bytes
)
1061 let
Bytes
new_path_bytes
=
String
new_path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
1062 let
Int
new_path_len
=
Bytes
new_path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
1063 let
Int
new_path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
new_path_bytes
)
1064 let
UInt
ret
=
(old_fd : Int, old_path : Int, old_path_len : Int, new_fd : Int, new_path : Int, new_path_len : Int) -> UInt
path_rename_ffi
(
1065
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
1066
Int
old_path_ptr
,
1067
Int
old_path_len
,
1068
Fd
new_fd
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
1069
Int
new_path_ptr
,
1070
Int
new_path_len
,
1071 ) 1072 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1073
(position : Int) -> Unit
@ffi.free
(
Int
old_path_ptr
)
1074
(position : Int) -> Unit
@ffi.free
(
Int
new_path_ptr
)
1075 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1076 raise
Errno
ret
1077 } 1078} 1079 1080///| 1081fn path_symlink_ffi( 1082 old_path :
Int
Int
,
1083 old_path_len :
Int
Int
,
1084 fd :
Int
Int
,
1085 new_path :
Int
Int
,
1086 new_path_len :
Int
Int
1087) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_symlink"
1088 1089///| Create a symbolic link. 1090/// 1091/// Note: This is similar to `symlinkat` in POSIX. 1092pub fn
(old_path : String, fd : Fd, new_path : String) -> Unit raise Errno

Create a symbolic link.

Note: This is similar to symlinkat in POSIX.

path_symlink
(
1093
String
old_path
:
String
String
,
1094
Fd
fd
:
type Fd Int

A file descriptor handle

Fd
,
1095
String
new_path
:
String
String
1096) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1097 let
Bytes
old_path_bytes
=
String
old_path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
1098 let
Int
old_path_len
=
Bytes
old_path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
1099 let
Int
old_path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
old_path_bytes
)
1100 let
Bytes
new_path_bytes
=
String
new_path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
1101 let
Int
new_path_len
=
Bytes
new_path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
1102 let
Int
new_path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
new_path_bytes
)
1103 let
UInt
ret
=
(old_path : Int, old_path_len : Int, fd : Int, new_path : Int, new_path_len : Int) -> UInt
path_symlink_ffi
(
1104
Int
old_path_ptr
,
1105
Int
old_path_len
,
1106
Fd
fd
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
1107
Int
new_path_ptr
,
1108
Int
new_path_len
,
1109 ) 1110 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1111
(position : Int) -> Unit
@ffi.free
(
Int
old_path_ptr
)
1112
(position : Int) -> Unit
@ffi.free
(
Int
new_path_ptr
)
1113 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1114 raise
Errno
ret
1115 } 1116} 1117 1118///| 1119fn path_unlink_file_ffi(fd :
Int
Int
, path :
Int
Int
, path_len :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "path_unlink_file"
1120 1121///| Unlink a file. 1122/// 1123/// Return `errno::isdir` if the path refers to a directory. 1124/// 1125/// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. 1126pub fn
(self : Fd, path : String) -> Unit raise Errno

Unlink a file.

Return errno::isdir if the path refers to a directory.

Note: This is similar to unlinkat(fd, path, 0) in POSIX.

path_unlink_file
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
String
path
:
String
String
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1127 let
Bytes
path_bytes
=
String
path
|>
(string : String, encoding~ : @encoding.Encoding) -> Bytes

Encode a given string to the specified character encoding and returns the resulting bytes.

Parameters

  • encoding : The target encoding format.
  • src: The input string to be encoded.

Returns

A bytes representing the encoded string in the selected format.

Examples

let src = "Hello, World!"
inspect(encode(encoding=UTF8, src), content=
  #|b"\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21"
)
@encoding.encode
(
@encoding.Encoding
encoding
=
@encoding.Encoding
UTF8
)
1128 let
Int
path_len
=
Bytes
path_bytes
.
(self : Bytes) -> Int

Returns the number of bytes in a byte sequence.

Parameters:

  • bytes : The byte sequence whose length is to be determined.

Returns an integer representing the length (number of bytes) of the sequence.

Example:

  let bytes = b"\x01\x02\x03"
  inspect(bytes.length(), content="3")
  let empty = b""
  inspect(empty.length(), content="0")
length
()
1129 let
Int
path_ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
Bytes
path_bytes
)
1130 let
UInt
ret
=
(fd : Int, path : Int, path_len : Int) -> UInt
path_unlink_file_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
path_ptr
,
Int
path_len
)
1131 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1132
(position : Int) -> Unit
@ffi.free
(
Int
path_ptr
)
1133 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1134 raise
Errno
ret
1135 } 1136} 1137 1138///| 1139fn poll_oneoff_ffi( 1140 in_ :
Int
Int
,
1141 out :
Int
Int
,
1142 nsubscriptions :
Int
Int
,
1143 nevents :
Int
Int
1144) ->
UInt
UInt
= "wasi_snapshot_preview1" "poll_oneoff"
1145 1146///| Concurrently poll for the occurrence of a set of events. 1147/// 1148/// If `nsubscriptions` is 0, returns `errno::inval`. 1149/// 1150/// @param `in_` The events to which to subscribe. 1151/// @return The events that have occurred. 1152pub fn
(in_ : Array[Subscription]) -> Array[Event] raise Errno

Concurrently poll for the occurrence of a set of events.

If nsubscriptions is 0, returns errno::inval.

@param in_ The events to which to subscribe.
@return The events that have occurred.

poll_oneoff
(
Array[Subscription]
in_
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
struct Subscription {
  userdata: Userdata
  u: Subscription_u
}

Subscription to an event.

  • userdata: User-provided value that is attached to the subscription in the implementaiton and returned through event::userdata.
  • u: The type of the event to which to subscribe, and its contents.
Subscription
]) ->
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
struct Event {
  userdata: Userdata
  error: Errno
  type_: EventType
  fd_readwrite: Event_fd_readwrite
}

An event that occurred.

  • userdata: User-provided value that got attched to subscription::userdata.
  • error: If non-zero, an error that occurred while processing the subscription request.
  • type_: The type of the event that occurred.
  • fd_readwrite: The contents of the event, if it is an eventtype::fd_read or eventtype::fd_write. eventtype::clock events ignore this field.
Event
] raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1153 let
Int
nsubscriptions
=
Array[Subscription]
in_
.
(self : Array[Subscription]) -> Int

Returns the number of elements in the array.

Parameters:

  • array : The array whose length is to be determined.

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

Example:

  let arr = [1, 2, 3]
  inspect(arr.length(), content="3")
  let empty : Array[Int] = []
  inspect(empty.length(), content="0")
length
()
1154 let
Int
in_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
nsubscriptions
(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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48)
1155 let
Int
out_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
nsubscriptions
(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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
32)
1156 for
Int
i
,
Subscription
sub
in
Array[Subscription]
in_
{
1157
(offset : Int, value : UInt64) -> Unit
@ffi.store64_u
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48,
Subscription
sub
.
Userdata
userdata
.
(self : Userdata) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
())
1158 match
Subscription
sub
.
Subscription_u
u
{
1159
(Subscription_clock) -> Subscription_u
Clock
({
ClockId
id
,
TimeStamp
timeout
,
TimeStamp
precision
,
SubclockFlags
flags
}) => {
1160
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8, 0)
1161
(offset : Int, value : UInt) -> Unit
@ffi.store32_u
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
0,
ClockId
id
.
(self : ClockId) -> UInt
value
())
1162
(offset : Int, value : UInt64) -> Unit
@ffi.store64_u
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8,
TimeStamp
timeout
.
(self : TimeStamp) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
())
1163
(offset : Int, value : UInt64) -> Unit
@ffi.store64_u
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
16,
TimeStamp
precision
.
(self : TimeStamp) -> UInt64

Convert newtype to its underlying type, automatically derived.

inner
())
1164
(offset : Int, value : UInt) -> Unit
@ffi.store32_u
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
24,
SubclockFlags
flags
.
(self : SubclockFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
())
1165 } 1166
(Subscription_fd_readwrite) -> Subscription_u
Fd_read
({
Fd
file_descriptor
}) => {
1167
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8, 1)
1168
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
12,
Fd
file_descriptor
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
())
1169 } 1170
(Subscription_fd_readwrite) -> Subscription_u
Fd_write
({
Fd
file_descriptor
}) => {
1171
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8, 2)
1172
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
in_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
48
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
12,
Fd
file_descriptor
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
())
1173 } 1174 } 1175 } 1176 let
Int
nevents_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
1177 let
UInt
ret
=
(in_ : Int, out : Int, nsubscriptions : Int, nevents : Int) -> UInt
poll_oneoff_ffi
(
Int
in_ptr
,
Int
out_ptr
,
Int
nsubscriptions
,
Int
nevents_ptr
)
1178 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1179 let
Int
nevents
=
(offset : Int) -> Int
@ffi.load32
(
Int
nevents_ptr
)
1180
(position : Int) -> Unit
@ffi.free
(
Int
nevents_ptr
)
1181
(position : Int) -> Unit
@ffi.free
(
Int
in_ptr
)
1182 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1183
(position : Int) -> Unit
@ffi.free
(
Int
out_ptr
)
1184 raise
Errno
ret
1185 } 1186 let
Array[Event]
events
= []
1187 for
Int
i
in
Int
0
..<
Int
nevents
{
1188 let
Userdata
userdata
:
type Userdata UInt64

User-provided value that may be attached to objects that is retained when extracted from the implementation.

Userdata
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
out_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
32)
1189 let
Errno
errno
:
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
=
(offset : Int) -> UInt
@ffi.load16_u
(
Int
out_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
32
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8)
1190 |>
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
(UInt) -> Errno?
::from_value
1191 |>
enum Option[A] {
  None
  Some(A)
}
Option
(Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

::unwrap
1192 let
EventType
type_
:
enum EventType {
  Clock
  Fd_read
  Fd_write
}

Type of a subscription to an event or its occurrence.

  • Clock: The time value of clock subscription_clock::id has reached timestamp subscription_clock::timeout.
  • Fd_read: File descriptor subscription_fd_readwrite::file_descriptor has data available for reading. This event always triggers for regular files.
  • Fd_write: File descriptor subscription_fd_readwrite::file_descriptor has capacity available for writing. This event always triggers for regular files.
EventType
=
(offset : Int) -> UInt
@ffi.load16_u
(
Int
out_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
32
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
10)
1193 |>
enum EventType {
  Clock
  Fd_read
  Fd_write
}

Type of a subscription to an event or its occurrence.

  • Clock: The time value of clock subscription_clock::id has reached timestamp subscription_clock::timeout.
  • Fd_read: File descriptor subscription_fd_readwrite::file_descriptor has data available for reading. This event always triggers for regular files.
  • Fd_write: File descriptor subscription_fd_readwrite::file_descriptor has capacity available for writing. This event always triggers for regular files.
EventType
(UInt) -> EventType?
::from_value
1194 |>
enum Option[A] {
  None
  Some(A)
}
Option
(EventType?) -> EventType

Extract the value in Some.

If the value is None, it throws a panic.

::unwrap
1195 let
FileSize
nbytes
:
type FileSize UInt64

Non-negative file size or length of a region within a file.

FileSize
=
(offset : Int) -> UInt64
@ffi.load64_u
(
Int
out_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
32
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
16)
1196 let
EventRWFlags
flags
:
type EventRWFlags UInt

The state of the file descriptor subscribed to with eventtype::fd_read or eventtype::fd_write.

EventRWFlags
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
out_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  inspect(42 * 2, content="84")
  inspect(-10 * 3, content="-30")
  let max = 2147483647 // Int.max_value
  inspect(max * 2, content="-2") // Overflow wraps around
*
32
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
16
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
8)
1197 let
Event_fd_readwrite
fd_readwrite
:
struct Event_fd_readwrite {
  nbytes: FileSize
  flags: EventRWFlags
}

The contents of an event when type is eventtype::fd_read or eventtype::fd_write.

  • nbytes: Number of bytes available for reading or writing.
  • flags: The state of the file descriptor.
Event_fd_readwrite
= {
FileSize
nbytes
,
EventRWFlags
flags
}
1198
Array[Event]
events
.
(self : Array[Event], value : Event) -> Unit

Adds an element to the end of the array.

If the array is at capacity, it will be reallocated.

Example

  let v = []
  v.push(3)
push
(
struct Event {
  userdata: Userdata
  error: Errno
  type_: EventType
  fd_readwrite: Event_fd_readwrite
}

An event that occurred.

  • userdata: User-provided value that got attched to subscription::userdata.
  • error: If non-zero, an error that occurred while processing the subscription request.
  • type_: The type of the event that occurred.
  • fd_readwrite: The contents of the event, if it is an eventtype::fd_read or eventtype::fd_write. eventtype::clock events ignore this field.
Event
::{
Userdata
userdata
,
Errno
error
:
Errno
errno
,
EventType
type_
,
Event_fd_readwrite
fd_readwrite
})
1199 } 1200
(position : Int) -> Unit
@ffi.free
(
Int
out_ptr
)
1201
Array[Event]
events
1202} 1203 1204///| 1205fn proc_exit_ffi(rval :
UInt
UInt
) = "wasi_snapshot_preview1" "proc_exit"
1206 1207///| Terminate the process normally. An exit code of 0 indicates successful 1208/// termination of the program. The meanings of other values is dependent on 1209/// the environment. 1210/// 1211/// Note: the accepted range may depend on the runtime, meaning that it may 1212/// become an error to return a value outside the accepted range of exit codes, 1213/// making the actual error code environment-dependent. 1214pub fn
(rval : UInt) -> Unit

Terminate the process normally. An exit code of 0 indicates successful termination of the program. The meanings of other values is dependent on the environment.

Note: the accepted range may depend on the runtime, meaning that it may become an error to return a value outside the accepted range of exit codes, making the actual error code environment-dependent.

proc_exit
(
UInt
rval
:
UInt
UInt
) ->
Unit
Unit
{
1215
(rval : UInt) -> Unit
proc_exit_ffi
(
UInt
rval
)
1216} 1217 1218///| 1219fn proc_raise_ffi(sig :
UInt
UInt
) ->
UInt
UInt
= "wasi_snapshot_preview1" "proc_raise"
1220 1221///| Send a signal to the process of the calling thread. 1222/// 1223/// Note: This is similar to `raise` in POSIX. 1224/// 1225/// @param `sig` The signal condition to trigger. 1226pub fn
(sig : Signal) -> Unit raise Errno

Send a signal to the process of the calling thread.

Note: This is similar to raise in POSIX.

@param sig The signal condition to trigger.

proc_raise
(
Signal
sig
:
enum Signal {
  None
  Hup
  Inte
  Quit
  Ill
  Trap
  Abrt
  Bus
  Fpe
  Kill
  Usr1
  Segv
  Usr2
  Pipe
  Alrm
  Term
  Chld
  Cont
  Stop
  Tstp
  Ttin
  Ttou
  Urg
  Xcpu
  Xfsz
  Vtalrm
  Prof
  Winch
  Poll
  Pwr
  Sys
}

Signal condition.

  • None: No signal. Note that POSIX has special semantics for kill(pid, 0), so this value is reserved.
  • Hup: Hangup. Action: Terminates the process.
  • Inte: Terminate interrupt signal. Action: Terminates the process.
  • Quit: Terminal quit signal. Action: Terminates the process.
  • Ill: Illegal instruction. Action: Terminates the process.
  • Trap: Trace/breakpoint trap. Action: Terminates the process.
  • Abrt: Process abort signal. Action: Terminates the process.
  • Bus: Access to an undefined portion of a memory object. Action: Terminates the process.
  • Fpe: Erroneous arithmetic operation. Action: Terminates the process.
  • Kill: Kill. Action: Terminates the process.
  • Usr1: User-defined signal 1. Action: Terminates the process.
  • Segv: Invalid memory reference. Action: Terminates the process.
  • Usr2: User-defined signal 2. Action: Terminates the process.
  • Pipe: Write on a pipe with no one to read it. Action: Ignored.
  • Alrm: Alarm clock. Action: Terminates the process.
  • Chld: Child process terminated, stopped, or continued. Action: Ignored.
  • Cont: Continue executing, if stopped. Action: Continues the process.
  • Stop: Stop executing. Action: Stops the process.
  • Tstp: Terminal stop signal. Action: Stops the process.
  • Ttin: Background process attempting read. Action: Stops the process.
  • Ttou: Background process attempting write. Action: Stops the process.
  • Urg: High bandwidth data is available at a socket. Action: Ignored.
  • Xcpu: CPU time limit exceeded. Action: Terminates the process.
  • Xfsz: File size limit exceeded. Action: Terminates the process.
  • Vtalrm: Virtual timer expired. Action: Terminates the process.
  • Prof: Profiling timer expired. Action: Terminates the process.
  • Winch: Window changed. Action: Ignored.
  • Poll: I/O possible. Action: Terminates the process.
  • Pwr: Power failure. Action: Terminates the process.
  • Sys: Bad system call. Action: Terminates the process.
Signal
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1227 let
UInt
ret
=
(sig : UInt) -> UInt
proc_raise_ffi
(
Signal
sig
.
(self : Signal) -> UInt
value
())
1228 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1229 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1230 raise
Errno
ret
1231 } 1232} 1233 1234///| 1235fn sched_yield_ffi() ->
UInt
UInt
= "wasi_snapshot_preview1" "sched_yield"
1236 1237///| Temporarily yield execution of the calling thread. 1238/// 1239/// Note: This is similar to `sched_yield` in POSIX. 1240pub fn
() -> Unit raise Errno

Temporarily yield execution of the calling thread.

Note: This is similar to sched_yield in POSIX.

sched_yield
() ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1241 let
UInt
ret
=
() -> UInt
sched_yield_ffi
()
1242 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1243 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1244 raise
Errno
ret
1245 } 1246} 1247 1248///| 1249fn random_get_ffi(buf :
Int
Int
, buf_len :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "random_get"
1250 1251///| Write high-quality random data into a buffer. 1252/// 1253/// This function blocks when the implementaiton is unable to immediately 1254/// provide sufficient high-quality random data. 1255/// 1256/// This function may execute slowly, so when larget mounts of random data are 1257/// required, it's advisable to use this function to seed a pseudo-random 1258/// number generator, rather than to provide the random data directly. 1259pub fn
(buf : FixedArray[Byte]) -> Unit raise Errno

Write high-quality random data into a buffer.

This function blocks when the implementaiton is unable to immediately provide sufficient high-quality random data.

This function may execute slowly, so when larget mounts of random data are required, it's advisable to use this function to seed a pseudo-random number generator, rather than to provide the random data directly.

random_get
(
FixedArray[Byte]
buf
:
type FixedArray[A]
FixedArray
[
Byte
Byte
]) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1260 let
Int
buf_len
=
FixedArray[Byte]
buf
.
(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:

  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
length
()
1261 let
Int
buf_ptr
=
(bytes : FixedArray[Byte]) -> Int
@ffi.byte_array2ptr
(
FixedArray[Byte]
buf
)
1262 let
UInt
ret
=
(buf : Int, buf_len : Int) -> UInt
random_get_ffi
(
Int
buf_ptr
,
Int
buf_len
)
1263 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1264
(position : Int) -> Unit
@ffi.free
(
Int
buf_ptr
)
1265 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1266 raise
Errno
ret
1267 } 1268} 1269 1270///| 1271fn sock_accept_ffi(sock :
Int
Int
, flags :
UInt
UInt
, fd :
Int
Int
) ->
UInt
UInt
= "wasi_snapshot_preview1" "sock_accept"
1272 1273///| Accept a new incoming connection on a socket. 1274/// 1275/// Note: This is similar to `accept` in POSIX. 1276/// 1277/// @param `self` The listening socket. 1278/// @param `flags` The desired values of the file descriptor flags. 1279/// @return New socket connection. 1280pub fn
(self : Fd, flags : FdFlags) -> Fd raise Errno

Accept a new incoming connection on a socket.

Note: This is similar to accept in POSIX.

@param self The listening socket.
@param flags The desired values of the file descriptor flags.
@return New socket connection.

sock_accept
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
FdFlags
flags
:
type FdFlags UInt

File descriptor flag.

FdFlags
) ->
type Fd Int

A file descriptor handle

Fd
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1281 let
Int
fd_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
1282 let
UInt
ret
=
(sock : Int, flags : UInt, fd : Int) -> UInt
sock_accept_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
FdFlags
flags
.
(self : FdFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
Int
fd_ptr
)
1283 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1284 let
Int
fd
=
(offset : Int) -> Int
@ffi.load32
(
Int
fd_ptr
)
1285
(position : Int) -> Unit
@ffi.free
(
Int
fd_ptr
)
1286 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1287 raise
Errno
ret
1288 } 1289
(Int) -> Fd

A file descriptor handle

Fd
(
Int
fd
)
1290} 1291 1292///| 1293fn sock_recv_ffi( 1294 sock :
Int
Int
,
1295 ri_data :
Int
Int
,
1296 ri_data_len :
Int
Int
,
1297 ri_flags :
UInt
UInt
,
1298 size :
Int
Int
,
1299 ro_flags :
Int
Int
1300) ->
UInt
UInt
= "wasi_snapshot_preview1" "sock_recv"
1301 1302///| Receive a message from a socket. 1303/// 1304/// Note: This is similar to `recv` in POSIX, though it also supports reading 1305/// the data into multiple buffers in the manner of `readv`. 1306/// 1307/// @param `contents` List of scatter/gather vectors to which to store data. 1308/// @param `flags` Message flags. 1309/// @return Number of bytes stored in the buffers and message flags. 1310pub fn
(self : Fd, contents : Array[FixedArray[Byte]], flags : RiFlags) -> (Size, RoFlags) raise Errno

Receive a message from a socket.

Note: This is similar to recv in POSIX, though it also supports reading the data into multiple buffers in the manner of readv.

@param contents List of scatter/gather vectors to which to store data.
@param flags Message flags.
@return Number of bytes stored in the buffers and message flags.

sock_recv
(
1311
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
1312
Array[FixedArray[Byte]]
contents
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
type FixedArray[A]
FixedArray
[
Byte
Byte
]],
1313
RiFlags
flags
:
type RiFlags UInt

Flags provided to sock_recv.

RiFlags
1314) -> (
type Size UInt
Size
,
type RoFlags UInt

Flags returned by sock_recv.

RoFlags
) raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1315 let
Int
ri_data_len
=
Array[FixedArray[Byte]]
contents
.
(self : Array[FixedArray[Byte]]) -> Int

Returns the number of elements in the array.

Parameters:

  • array : The array whose length is to be determined.

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

Example:

  let arr = [1, 2, 3]
  inspect(arr.length(), content="3")
  let empty : Array[Int] = []
  inspect(empty.length(), content="0")
length
()
1316 let
Int
ri_data_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
ri_data_len
(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:

  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)
1317 for
Int
i
,
FixedArray[Byte]
byte
in
Array[FixedArray[Byte]]
contents
{
1318 let
Int
ptr
=
(bytes : FixedArray[Byte]) -> Int
@ffi.byte_array2ptr
(
FixedArray[Byte]
byte
)
1319
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
ri_data_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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,
Int
ptr
)
1320
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
ri_data_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
4,
FixedArray[Byte]
byte
.
(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:

  let arr = FixedArray::make(3, 42)
  inspect(arr.length(), content="3")
length
())
1321
(position : Int) -> Unit
@ffi.free
(
Int
ptr
)
1322 } 1323 let
Int
ro_flags_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
1324 let
Int
size_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
1325 let
UInt
ret
=
(sock : Int, ri_data : Int, ri_data_len : Int, ri_flags : UInt, size : Int, ro_flags : Int) -> UInt
sock_recv_ffi
(
1326
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
1327
Int
ri_data_ptr
,
1328
Int
ri_data_len
,
1329
RiFlags
flags
.
(self : RiFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
1330
Int
size_ptr
,
1331
Int
ro_flags_ptr
,
1332 ) 1333 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1334 let
UInt
size
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
size_ptr
)
1335 let
UInt
ro_flags
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
ro_flags_ptr
)
1336
(position : Int) -> Unit
@ffi.free
(
Int
size_ptr
)
1337
(position : Int) -> Unit
@ffi.free
(
Int
ro_flags_ptr
)
1338
(position : Int) -> Unit
@ffi.free
(
Int
ri_data_ptr
)
1339
(t : Array[FixedArray[Byte]]) -> Unit

Evaluates an expression and discards its result. This is useful when you want to execute an expression for its side effects but don't care about its return value, or when you want to explicitly indicate that a value is intentionally unused.

Parameters:

  • value : The value to be ignored. Can be of any type.

Example:

  let x = 42
  ignore(x) // Explicitly ignore the value
  let mut sum = 0
  ignore([1, 2, 3].iter().each(fn(x) { sum = sum + x })) // Ignore the Unit return value of each()
ignore
(
Array[FixedArray[Byte]]
contents
)
1340 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1341 raise
Errno
ret
1342 } 1343 (
UInt
size
,
UInt
ro_flags
)
1344} 1345 1346///| 1347fn sock_send_ffi( 1348 sock :
Int
Int
,
1349 si_data :
Int
Int
,
1350 si_data_len :
Int
Int
,
1351 si_flags :
UInt
UInt
,
1352 size :
Int
Int
1353) ->
UInt
UInt
= "wasi_snapshot_preview1" "sock_send"
1354 1355///| Send a message on a socket. 1356/// 1357/// Note: This is similar to `send` in POSIX, though it also supports writing 1358/// the data from multiple buffers in the manner of `writev`. 1359/// 1360/// @param `contents` List of scatter/gather vectors to which to retrieve the data. 1361/// @param `flags` Message flags. 1362/// @return The number of bytes transmitted. 1363pub fn
(self : Fd, contents : Array[@bytes.View], flags : SiFlags) -> Size raise Errno

Send a message on a socket.

Note: This is similar to send in POSIX, though it also supports writing the data from multiple buffers in the manner of writev.

@param contents List of scatter/gather vectors to which to retrieve the data.
@param flags Message flags.
@return The number of bytes transmitted.

sock_send
(
1364
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
1365
Array[@bytes.View]
contents
:
type Array[T]

An Array is a collection of values that supports random access and can grow in size.

Array
[
type @bytes.View

A @bytes.View represents a view into a section of a Bytes without copying the data.

Example

  let bs = b"\x00\x01\x02\x03\x04\x05"
  let bv = bs[1:4]
  assert_eq(bv.length(), 3)
  assert_eq(bv[0], b'\x01')
  assert_eq(bv[1], b'\x02')
  assert_eq(bv[2], b'\x03')
@bytes.View
],
1366
SiFlags
flags
:
type SiFlags UInt

Flags provided to sock_send. As there are currently no flags defined, it must be set to zero.

SiFlags
1367) ->
type Size UInt
Size
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1368 let
Int
si_data_len
=
Array[@bytes.View]
contents
.
(self : Array[@bytes.View]) -> Int

Returns the number of elements in the array.

Parameters:

  • array : The array whose length is to be determined.

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

Example:

  let arr = [1, 2, 3]
  inspect(arr.length(), content="3")
  let empty : Array[Int] = []
  inspect(empty.length(), content="0")
length
()
1369 let
Int
si_data_ptr
=
(size : Int) -> Int
@ffi.malloc
(
Int
si_data_len
(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:

  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)
1370 for
Int
i
,
@bytes.View
byte
in
Array[@bytes.View]
contents
{
1371 let
Int
ptr
=
(bytes : Bytes) -> Int
@ffi.bytes2ptr
(
@bytes.View
byte
.
(self : @bytes.View) -> Bytes

Retrieves the underlying Bytes from a View.

data
())
1372
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
si_data_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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,
Int
ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
@bytes.View
byte
.
(self : @bytes.View) -> Int

Retrieves the start index of the view.

start_offset
())
1373
(offset : Int, value : Int) -> Unit
@ffi.store32
(
Int
si_data_ptr
(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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
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:

  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:

  inspect(42 + 1, content="43")
  inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
+
4,
@bytes.View
byte
.
(self : @bytes.View) -> Int

Returns the number of bytes in the view.

Parameters:

  • bytes_view : The view of a byte sequence.

Returns an integer representing the length of the view.

Example:

  let bytes = b"\x00\x01\x02\x03\x04"
  let view = bytes[2:4]
  inspect(view.length(), content="2")
length
())
1374
(position : Int) -> Unit
@ffi.free
(
Int
ptr
)
1375 } 1376 let
Int
size_ptr
=
(size : Int) -> Int
@ffi.malloc
(4)
1377 let
UInt
ret
=
(sock : Int, si_data : Int, si_data_len : Int, si_flags : UInt, size : Int) -> UInt
sock_send_ffi
(
1378
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
1379
Int
si_data_ptr
,
1380
Int
si_data_len
,
1381
SiFlags
flags
.
(self : SiFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
(),
1382
Int
size_ptr
,
1383 ) 1384 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1385 let
UInt
size
=
(offset : Int) -> UInt
@ffi.load32_u
(
Int
size_ptr
)
1386
(position : Int) -> Unit
@ffi.free
(
Int
size_ptr
)
1387
(position : Int) -> Unit
@ffi.free
(
Int
si_data_ptr
)
1388
(t : Array[@bytes.View]) -> Unit

Evaluates an expression and discards its result. This is useful when you want to execute an expression for its side effects but don't care about its return value, or when you want to explicitly indicate that a value is intentionally unused.

Parameters:

  • value : The value to be ignored. Can be of any type.

Example:

  let x = 42
  ignore(x) // Explicitly ignore the value
  let mut sum = 0
  ignore([1, 2, 3].iter().each(fn(x) { sum = sum + x })) // Ignore the Unit return value of each()
ignore
(
Array[@bytes.View]
contents
)
1389 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1390 raise
Errno
ret
1391 } 1392
UInt
size
1393} 1394 1395///| 1396fn sock_shutdown_ffi(sock :
Int
Int
, how :
UInt
UInt
) ->
UInt
UInt
= "wasi_snapshot_preview1" "sock_shutdown"
1397 1398///| Shut down socket send and receive channels. 1399/// 1400/// Note: This is similar to `shutdown` in POSIX. 1401/// 1402/// @param `how` Which channels on the socket to shut down. 1403pub fn
(self : Fd, how : SdFlags) -> Unit raise Errno

Shut down socket send and receive channels.

Note: This is similar to shutdown in POSIX.

@param how Which channels on the socket to shut down.

sock_shutdown
(
Fd
self
:
type Fd Int

A file descriptor handle

Fd
,
SdFlags
how
:
type SdFlags UInt

Which channels on a socket to shut down.

SdFlags
) ->
Unit
Unit
raise
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
{
1404 let
UInt
ret
=
(sock : Int, how : UInt) -> UInt
sock_shutdown_ffi
(
Fd
self
.
(self : Fd) -> Int

Convert newtype to its underlying type, automatically derived.

inner
(),
SdFlags
how
.
(self : SdFlags) -> UInt

Convert newtype to its underlying type, automatically derived.

inner
())
1405 let
Errno
ret
=
type! Errno {
  Success
  TooBig
  Acces
  Addrinuse
  Addrnotavail
  Afnosupport
  Again
  Already
  Badf
  Badmsg
  Busy
  Canceled
  Child
  Connaborted
  Connrefused
  Connreset
  Deadlock
  Destaddrreq
  Dom
  Dquot
  Exist
  Fault
  Fbig
  Hostunreach
  Idrm
  Ilseq
  Inprogress
  Intr
  Inval
  IO
  Isconn
  Isdir
  Loop
  Mfile
  Mlink
  Msgsize
  Multihop
  Nametoolong
  Netdown
  Netreset
  Netunreach
  Nfile
  Nobufs
  Nodev
  Noent
  Noexec
  Nolck
  Nolink
  Nomem
  Nomsg
  Noprotoopt
  Nospc
  Nosys
  Notconn
  Notdir
  Notempty
  Notrecoverable
  Notsock
  Notsup
  Notty
  Nxio
  Overflow
  Ownerdead
  Perm
  Pipe
  Proto
  Protonosupport
  Prototype
  Range
  Rofs
  Spipe
  Srch
  Stale
  Timedout
  Txtbsy
  Xdev
  Notcapable
}

Error codes returned by functions. Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

See : https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-errno-variant

Errno
::
(value : UInt) -> Errno?
from_value
(
UInt
ret
).
(self : Errno?) -> Errno

Extract the value in Some.

If the value is None, it throws a panic.

unwrap
()
1406 if
Errno
ret
(x : Errno, y : Errno) -> Bool
!=
Errno
Success
{
1407 raise
Errno
ret
1408 } 1409} 1410