diff options
author | Camil Staps | 2016-01-31 16:08:18 +0100 |
---|---|---|
committer | Camil Staps | 2016-01-31 16:11:06 +0100 |
commit | 017b43b182c598063633e382affb3b40b82efecb (patch) | |
tree | f7c301c6ebc2331fecf6715191d2e05cce6359ff | |
parent | Documentation (diff) |
Readme
-rw-r--r-- | README.md | 52 |
1 files changed, 51 insertions, 1 deletions
@@ -1,2 +1,52 @@ -# CleanC +# CleanC 0.1 Improved C interface for Clean + +Vanilla Clean requires the programmer to write a separate interface for every C function that is ever going to be called from Clean, directly using the ABC instruction `ccall`. This library removes the need for ABC instructions *entirely*, and allows the programmer to call C functions given their name as a `String`. + +Copyright © 2016 Camil Staps. Licensed under MIT, see LICENSE for more details. + +### Installation & Usage + +To install, simply run: + + make + +To use CleanC, you will need to do the following: + + - Add `import CleanC` to your Clean program. + - Link the C object file you want to call code from. + - Link `CleanC.o`, `libelf` and `libffi` (may need to install the latter two). + - Disable linker optimisation and stripping of the application. + - Add the Generics library to the search path. + +This gives a clm command line of: + + clm -I "$CLEAN_HOME/lib/Generics" -ns -no-opt-link -l CleanC.o -l myfile.o -l -libelf -l -libffi mymodule + +This assumes you have set `$CLEAN_HOME` to the path to your Clean installation. + +### Example + +See `test.icl`. + +### Warning +This is Bad Code. To be able to call a C function by its name, we need to look through `/proc/self/exe` using libelf. + +Since we need `/proc/self/exe`, this is probably linux-specific. Also check the [libffi][libffi] list of supported platforms. + +### Acknowledgements +Code to look up a function pointer by its name was provided by [Falaina on Stack Overflow](http://stackoverflow.com/a/1118808/1544337). Calling a function pointer with extra arguments is possible using [libffi][libffi], as suggested by [FUZxxl](http://stackoverflow.com/a/35088746/1544337). + +### Todo + + - Call functions from shared libraries + - Improved interface to call Clean from C + - Look into Darwin support + +### Changelog + + - **0.1** (2016-01-31) + - Initial version + +[libffi]: https://sourceware.org/libffi/ + |