-
Notifications
You must be signed in to change notification settings - Fork 76
Dynamically resolved c functions #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
e9150d4 to
5ddee61
Compare
|
@roastpiece This is very interesting as an experiment. However, I don't consider it to be part of the Umka interpreter, for the following reasons:
I would be happy to see Umka FFI as a separate project (UMI?), but not Umka itself. |
|
Thank you for your quick response.
Yes, my implementation was more of an exercise for me, to implement the SYSTEM V calling convention. I switched to using libffi, which adds a dependency, but implements almost every ABI imaginable.
I thought about this. Is there a way to check the signature at runtime, without the header files? If not, i think the only way would be to generate the umka prototypes during build time. But that would goes against the dynamic nature of ffi.
Yes i saw that in the code while implementing this. It can be changed of course. Wasn't sure what to call it. I was thinking of |
|
@roastpiece FYI, there is a related project being discussed on Discord: https://discord.com/channels/846663478873030666/1441947520468127916
|
78f2ea3 to
eeeb0d7
Compare
Use umka `Storage` for allocating types Cache ffi_type structs for reuse
044a046 to
d9483e9
Compare
|
@roastpiece I think to get rid of the keyword you can look it up in the symbol table as last resort if function's prototype wasn't resolved. This happens with UMI functions already as far as I'm aware. |
|
@ske2004 These new external functions are not compatible with the conventional |
Oh right, I didn't consider this. Would it be possible to simply forbid taking reference of them? |
|
At the moment the keyword is needed to differnetiate how to call the function. One way i think i can get rid of the keyword, is by loading the dll/so directly as a seperate module. then if the fn is found in a umi, it gets called the same way as it is now, otherwise it looks in the dll, and calls it directly. |

In response to @rexim's video on umka-lang, i am trying to implement dynamically resolving c functions, without requiring explicit bindings from c.
I managed the following POC working. An example can be found at (https://github.com/roastpiece/umka-ffi-example).
It takes the mentioned approach, by searching the running executable for matching symbolsdlopen(NULL, ...).It now loads the symbols from a
mod.umifile (eg:raylib_linux.umifor araylib.um).I added a new keyword
externffito mark prototype fn declarations to be dynamically resolved.So one could do:
There are some problems atm:
No type checking is done on the C side at the moment. (I'm actually not sure if this would be possible).
I'm opening this as a Draft atm to get some feedback and to see, if I'm on the right track and I should continue spending time on this.