Idris2Doc : Data.C.Array8

Data.C.Array8

(source)

Reexports

import public Data.Fin
import public Data.Linear.Token
import public Data.Array.Index

Definitions

prim__setbits8 : AnyPtr -> Integer -> Bits8 -> PrimIO ()
prim__getbits8 : AnyPtr -> Integer -> Bits8
record CIArray8 : Nat -> Type
Totality: total
Visibility: export
Constructor: 
IA : AnyPtr -> CIArray8 n

Projection: 
.ptr : CIArray8 n -> AnyPtr
at : CIArray8 n -> Fin n -> Bits8
Totality: total
Visibility: export
ix : CIArray8 n -> (0 m : Nat) -> Ix (S m) n => Bits8
Totality: total
Visibility: export
atNat : CIArray8 n -> (m : Nat) -> {auto 0 _ : LT m n} -> Bits8
Totality: total
Visibility: export
toVect : CIArray8 n -> Vect n Bits8
  Reads the values from a C pointer into a vector.

Totality: total
Visibility: export
foldrKV : (Fin n -> Bits8 -> b -> b) -> b -> CIArray8 n -> b
  Right fold over the values of an array plus their indices.

Totality: total
Visibility: export
foldr : (Bits8 -> b -> b) -> b -> CIArray8 n -> b
  Right fold over the values of an array

Totality: total
Visibility: export
foldlKV : (Fin n -> b -> Bits8 -> b) -> b -> CIArray8 n -> b
  Left fold over the values of an array plus their indices.

Totality: total
Visibility: export
foldl : (b -> Bits8 -> b) -> b -> CIArray8 n -> b
  Left fold over the values of an array

Totality: total
Visibility: export
record PrimCArray8 : Type -> Bool -> Nat -> Type
  A wrapped pointer to a C-array holding `n` unsigned 8-bit
values (C-primitive).

Reading from and writing to such an array is O(1) and runs in `IO`.

See `CArray8` for a pure version of mutable C arrays using linear types.
See `CArray8S` for a pure versoin of mutable C arrays using linear types (overwritting/scrubbing before freeing).
See `CArray8IO` for a version of mutable C arrays usable in IO.
See `CArray8IOS` for a version of the mutable C arrays usuable in IO (overwritting/scrubbing before freeing)

Note : In typical use cases, the memory allocated for a C array must
be manually released with a call to `free` unless it is part
of a larger structure `Struct` or managed by an external library.

Totality: total
Visibility: export
Constructor: 
PCA8 : AnyPtr -> PrimCArray8 s b n

Projection: 
.ptr : PrimCArray8 s b n -> AnyPtr
0 CArray8 : Type -> Nat -> Type
  Convenience alias for `PrimCArray8 s False n a`

Totality: total
Visibility: public export
0 CArray8S : Type -> Nat -> Type
  Convenience alias for `PrimCArray8 s True n a`

Totality: total
Visibility: public export
0 CArray8IO : Nat -> Type
  Convenience alias for `PrimCArray8 World False n a`

Totality: total
Visibility: public export
0 CArray8IOS : Nat -> Type
  Convenience alias for `PrimCArray8 World True n a`

Totality: total
Visibility: public export
unsafeUnwrap : CArray8 s n -> AnyPtr
Totality: total
Visibility: export
unsafeWrap : AnyPtr -> CArray8 s n
Totality: total
Visibility: export
malloc1 : (n : Nat) -> F1 s (PrimCArray8 s b n)
  Allocates a new C-pointer of `sizeof a * n` bytes.

Totality: total
Visibility: export
calloc1 : (n : Nat) -> F1 s (PrimCArray8 s b n)
  Like `malloc1` but resets all allocated bytes to zero.

Totality: total
Visibility: export
free1 : CArray8 s n -> F1' s
  Frees the memory allocated for a C array without
overwriting its contents.

Totality: total
Visibility: export
frees1 : CArray8S s n -> F1' s
  Overwrites the contents of a C array before freeing
the underlying memory.

Totality: total
Visibility: export
get : PrimCArray8 s b n -> Fin n -> F1 s Bits8
  Reads a value from a C-pointer at the given position.

Totality: total
Visibility: export
getIx : PrimCArray8 s b n -> (0 m : Nat) -> Ix (S m) n => F1 s Bits8
  Reads a value from a C-pointer at the given position.

Totality: total
Visibility: export
getNat : PrimCArray8 s b n -> (m : Nat) -> {auto 0 _ : LT m n} -> F1 s Bits8
  Reads a value from a C-pointer at the given position.

Totality: total
Visibility: export
set : PrimCArray8 s b n -> Fin n -> Bits8 -> F1' s
  Writes a value to a C pointer at the given position.

Totality: total
Visibility: export
setIx : PrimCArray8 s b n -> (0 m : Nat) -> Ix (S m) n => Bits8 -> F1' s
  Writes a value to a C pointer at the given position.

Totality: total
Visibility: export
setNat : PrimCArray8 s b n -> (m : Nat) -> {auto 0 _ : LT m n} -> Bits8 -> F1' s
  Writes a value to a C pointer at the given position.

Totality: total
Visibility: export
writeVect : PrimCArray8 s b n -> Vect n Bits8 -> F1' s
  Writes the values from a vector to a C pointer

Totality: total
Visibility: export
withIArray : PrimCArray8 s b n -> (CIArray8 n -> c) -> F1 s c
  Temporarily wraps the mutable array in an immutable wrapper and
run a computation with that.

This is safe, because the pure function cannot possibly share the
immutable array by storing it in a mutable reference. It is
referentially transparent, because we call it from a linear context.

Totality: total
Visibility: export
writeList : (as : List Bits8) -> PrimCArray8 s b (length as) -> F1' s
  Writes the values from a list to a C pointer

Totality: total
Visibility: export
withPrimCArray8 : (n : Nat) -> (PrimCArray8 s b n -> F1' s) -> (PrimCArray8 s b n -> F1 s c) -> c
  Allocates a C array, runs a computation, and releases
the array using the supplied cleanup operation.

The Boolean index is erased because cleanup behavior
is supplied explicitly rather than selected by inspecting b.

Totality: total
Visibility: export
withCArray : (n : Nat) -> (CArray8 s n -> F1 s b) -> b
  Allocates a C array, runs a computation, and frees
the underlying memory afterward.

Totality: total
Visibility: export
withCArrayS : (n : Nat) -> (CArray8S s n -> F1 s b) -> b
  Allocates a C array, runs a computation, and securely
scrubs the underlying memory before freeing it.

Totality: total
Visibility: export
malloc : Lift1 s f => (n : Nat) -> f (PrimCArray8 s b n)
  Allocates a new C-pointer of `sizeof a * n` bytes.

Totality: total
Visibility: export
calloc : Lift1 s f => (n : Nat) -> f (PrimCArray8 s b n)
  Like `malloc` but resets all allocated bytes to zero.

Totality: total
Visibility: export
free : Lift1 s f => CArray8 s n -> f ()
  Frees a C array without scrubbing its contents.

Note: Only call this if the C array is no longer used and has been
allocated via a call to `malloc` or `alloc` (either in C land
or in Idris). Afterwards, it is no longer safe to use the array
for reading or writing, nor is it safe to call `free` on it again.

For safe resource management, use the linear version of
C arrays if possible. Otherwise, consider using a safer monad
than `IO` if possible.

Totality: total
Visibility: export
frees : Lift1 s f => CArray8S s n -> f ()
  Scrubs and frees a C array.

Note: Only call this if the C array is no longer used and has been
allocated via a call to `malloc` or `alloc` (either in C land
or in Idris). Afterwards, it is no longer safe to use the array
for reading or writing, nor is it safe to call `free` on it again.

For safe resource management, use the linear version of
C arrays if possible. Otherwise, consider using a safer monad
than `IO` if possible.

Totality: total
Visibility: export
fromList : Lift1 s f => (as : List Bits8) -> f (PrimCArray8 s b (length as))
Totality: total
Visibility: export