Experimental - Proof of concept
Cpppp introduces "Quoted Initialisers" to C. Quoted initialisers are C initialisers that are executed before C compilation and the results substituted (similar to macros). For example:
intx=4; inty=2; intz= @|c_hs|"(+) %d %d"|x, y|;Here we use the c_hs transformer to call Haskell's (+) function to add two C integers. Cpppp expands this initialiser out into a C foreign function interface call and a Haskell foreign function export.
This is not limited to FFI code generation, you can add your own code transformers! Simply implement the following data type:
dataTransform=foralla.Transform{_init::IOa , _trns::a->String-> [Id] ->SrcLoc->IO (a, Initializer) , _fin::a->IO()}Using this, we can type check and perform code generate for SQL expressions, regex expressions, Auto Layout strings, etc. in C. Anything you might of used quasi-quotation for in Haskell.
language-c-quote can not ingest macros yet, so it will not work for anything serious yet.
The following repos and branches are required to be cabal install-ed:
git@github.com:maxpow4h/language-c-quote.gitbranch:quoted-init