[ proposal ] fixed size C arrays a-la Struct#3802
Conversation
| cftySpecArg : FC -> CFType -> Core Builder | ||
| cftySpecArg fc t@(CFStruct _ _) = (\x => "(& " ++ x ++ ")") <$> cftySpec fc t | ||
| cftySpecArg fc t = cftySpec fc t |
There was a problem hiding this comment.
This is actually a fix to an existing compilation bug, I should break it into a different PR.
cftySpec outputs the scheme form of the type within a struct, and cftySpecArg outputs the scheme form of the type within function arguments.
Relevant documentation:
(* ftype-name): This type allows a pointer to a foreign type (ftype) to be passed. The argument must be an ftype pointer of the type identified by ftype-name, and the actual argument is the address encapsulated in the ftype pointer.
...
(& ftype-name): This type allows a foreign type (ftype) to be passed as a value, but represented on the Scheme side as a pointer to the foreign-type data. That is, a (& ftype-name) argument is represented on the Scheme side the same as a (* ftype-name) argument, but a (& ftype-name) argument is passed to the foreign procedure as the content at the foreign pointer's address instead of as the address.
Description
We have a blessed
Structtype for passing around c structs using FFI, but I could not hack fixed size arrays. Idris seems to be okay with basic newtypes, but it complains for dependent types like:I think what's happening is that the index types (the thing left of
:right?) are being subject to the FFI restrictions of being basic types. I think a more radical fix here would be to drop the restrictions on types and only enforce them on constructors.Some notes:
CArrayin idris code to avoid clashing with the commonArraytypeSelf-check
CONTRIBUTING.mdand I've updated
CONTRIBUTORSwith my name.implementation, I have updated
CHANGELOG_NEXT.md