Like how would I find the entry point in memory, and then capture the returned values. Or for instance, how would I determine the input variables locations that the compiled C code is expecting as inputs, albeit special registers or the stack?
This is an abstract conceptual question with no actual goal or project application at the moment. It would be nice to utilize Arduino libraries in FORTH by writing a function and then encapsulating the compiled binary in a FORTH Dictionary Word definition.
Obviously measures must be taken to preserve the FORTH interpreter’s pointers, stacks, and special registers. Is this ever worth the effort as opposed to sucking it up and rewriting the whole thing from scratch, delving into all the underlying mess of peripheral hardware documentation, or is there some typical way to streamline?
As a further aside, does one ever do this within a Unix like system? Like let’s say I want to only use a single python method present in llama.cpp in the source that has been compiled and cached in another directory. I want to call this method from inside a function written in my .bashrc file. I have called Python executables from bash functions many times, but never some random subroutine.
I don’t know about MicroPython or Arduino specifically, but I often call code I wrote in C or C++ using
ctypesfrom regular Python.If you have a shared library, you can
dlopen()it (see man page), and receive symbol addresses by name (might be mangled). FORTH probably has a way to call C functions, search for “FFI”. If you want to call stuff from asm, you might also want to search the web for “ELF”, “ABI”, and “calling convention”. Idk any arduino specifics.There’s not really an abstract answer. It’s all system specific. But basically you find code addresses from a linker dump or similar. I haven’t used Arduino but remember messing with that with SDCC for an STM8. Same idea most likely.
At one point a few years ago, I was following a UC Berkeley CS open course online. Nothing official, just following the lectures and posted stuff. I think it was getting into this subject with a custom version of the schema language. I stopped following along because I could not get a copy of the specific schema version and everything I tried was incompatible with what was taught in the course. Is that a better glue language for stuff like this on an operating system level?



