Skip to content

Instantly share code, notes, and snippets.

@bigs
Last active August 19, 2020 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigs/80c78ff926e949c1f7ff673b25440f5a to your computer and use it in GitHub Desktop.
Save bigs/80c78ff926e949c1f7ff673b25440f5a to your computer and use it in GitHub Desktop.
2/5: Building Libgit.FFI (src/Libgit/FFI.idr)
src/Libgit/FFI.idr:30:24--35:11:Can't marshal type for foreign call (Libgit.FFI.case block in byteLengthToType Libgit.FFI.prim_int_size_bytes) at:
30 byteLengthToType len = case len of
31 1 => Bits8
32 2 => Bits16
33 4 => Bits32
34 8 => Bits64
35 _ => Int
module FFIExample
import System.FFI
-- System info helpers
export
%foreign "C:int_size_bytes,shim"
prim_int_size_bytes : Int
export
%foreign "C:size_t_size_bytes,shim"
prim_size_t_size_bytes : Int
-- I don't love this, but without providers I don't have a mechanism to fail at
-- compile time, so I'll default to Int which doesn't seem so harmful. Famous
-- last words?
byteLengthToType : Bits8 -> Type
byteLengthToType len = case len of
1 => Bits8
2 => Bits16
4 => Bits32
8 => Bits64
_ => Int
CUInt : Num a => (a : Type)
CUInt = byteLengthToType prim_int_size_bytes
CSizeT : Num a => (a : Type)
CSizeT = byteLengthToType prim_size_t_size_bytes
uint8_t int_size_bytes() {
return sizeof(int);
}
uint8_t size_t_size_bytes() {
return sizeof(size_t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment