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.

  • Speiser0@feddit.org
    link
    fedilink
    arrow-up
    2
    ·
    1 day ago

    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.