sasagawa888 / eisl

ISLisp interpreter/compiler
Other
267 stars 22 forks source link

clang has no local function, but blocks #288

Closed informatimago closed 10 months ago

informatimago commented 1 year ago
In file included from library/tcltk0.c:40:
library/tcltk2.c:69:32: error: function definition is not allowed here
res = ({int res;int ITER(int X){

I don't see exactly where in library/tcltk.lsp this comes from, and probably it's from FFI generator elsewhere. The point is that local functions don't exist in clang. Instead, we may use blocks. Blocks are like pointers, but using ^ instead of * for the function pointer. We may initialize those blocks with anonymous functions (kind of lambda). Also variables that are written from inside the block need to be declared with __block. So something like this should be generated for clang:

res=({__block int res; int (^)(int X) ITER = int(int X){ ... res=...; return (int)res; }; ... return res;});
sasagawa888 commented 1 year ago

Thank you for your comment. The Easy-ISLisp compiler relies on GCC extensions. It is mainly designed for use on Linux. I think Clang might have GCC-compatible options. The options for MacOS are specified in compiler.lsp. Modifying this part to be GCC-compatible might make it work. see library/compiler.lsp line235

informatimago commented 1 year ago

I see. Thanks for the hint on compiler.lsp; I may have a look at it later.