justinethier / cyclone

:cyclone: A brand-new compiler that allows practical application development using R7RS Scheme. We provide modern features and a stable system capable of generating fast native binaries.
http://justinethier.github.io/cyclone/
MIT License
823 stars 42 forks source link

Allow (cyclone foreign) to define top-level C functions #461

Open justinethier opened 3 years ago

justinethier commented 3 years ago

EG: perhaps c-code could be used to define C functions, rather than merely inserting code into a generated lambda function.

Alternatively we could add a new construct if there are implementation details that prevent c-code from working in this capacity.

arthurmaciel commented 2 years ago

Hi @justinethier. It would be awesome! Also the possibility to introduce C macros directly would be great.

I was wondering about the name of a new construct and thought of c-verbatim or c-raw. Anyway, I am not sure if the actual c-code functionality would even be required/used, so we could just change its behavior. Just random ideas on the subject.

PS: I missed this functionality, especially of directly insertion of C macros, while implementing winds Levenshtein distance (to be finished soon).

justinethier commented 2 years ago

Hi @arthurmaciel!

Thanks for the feedback. Agree c-code is rather limiting since it only allows inserting code within a Scheme function. It probably makes sense to either rename it or allow insertions at the top-level too and compile those differently.

Regarding the top-level it is possible to use include-c-header to include arbitrary top-level code. This is kind of a hack though. See: https://github.com/cyclone-scheme/simple-http-server/blob/master/http-server.sld#L8

Looking forward to your update! Sorry if the tooling is slowing you down / getting in your way. Please let me know if there are any other improvements that could help.

arthurmaciel commented 2 years ago

@justinethier, the code was already done using exactly the strategy you mentioned (include-c-header) and the tooling was not slowing me down in anyway.

About c-code, if I can be of any help, please let me know.