fpco / inline-c

284 stars 51 forks source link

How to pass a data type from haskell into `inline-c` #138

Closed zhfnjust closed 2 years ago

zhfnjust commented 2 years ago

How to pass a data type from haskell into inline-c for processing.

now I need to pass an array of OpCode from haskell into inline-c.

data OpCode
  = -- Constants: OP_0-16 is also represented by OP_N, but needed for inline asm
    OP_N Integer
  | OP_PUSHDATA0 Word8 [Word8]
  | OP_PUSHDATA1 Word8 [Word8]
  | OP_PUSHDATA2 [Word8] [Word8]
  | OP_PUSHDATA4 [Word8] [Word8]
  ...
  deriving (Eq, Data, Generic, ToJSON, Read, Ord)
bitonic commented 2 years ago

There is no generic way -- you need to tell inline-c how to marshal Haskell types into C types. In this case you'll probably want to marshal the different parts into different corresponding C types. See readme for more info (e.g. how it works for vectors).

zhfnjust commented 2 years ago

more example about marshal ?