michaeljklein / CPlug

Hot plug C into Haskell, with automatic binding generation and recompilable instances (eventually)
http://michaeljklein.github.io/CPlug/
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Need to make "standard" C template #2

Open michaeljklein opened 8 years ago

michaeljklein commented 8 years ago

Suppose we have the following C code:

int add(int a, int b){ return a + b; }

Then, on the Haskell end we'll have something like:

cAdd :: Fix CInt -> Fix CInt -> (CInt -> CInt -> CInt) cAddTemplate CInt "add" [("int", "a"), ("int", "b")] "return a + b;"

But this is not enough to compile/run/call from Haskell. We need something like:

int main(){ int (*add_ptr)(int, int) = add; send_to_haskell( fun_ptr ); pause_indefinately(); ...

Thus this issue will be solved when an interface generator for C to Haskell is written.

michaeljklein commented 8 years ago

Since pipes are no longer being used (except maybe for compilation alone), I'm not sure how relevant this is.

For one, the Haskell FFI supports returning a function pointer and the (non-recompiled) C code is well-integrated into Haskell.

See Parse.Templates for the current template, which, at the moment, is:

data CFunctionTemplate = CFunTempl {returnType :: T.Text, functionName :: T.Text, inputVars :: [(T.Text, T.Text)], functionBody :: T.Text } deriving (Eq, Ord, Show)