Rhope Blog

Blog Home Downloads Documentation RSS

Foreign Function Interface

by Mike Pavone

I've gotten a basic version of the foreign function interface working in the Rhope compiler. Currently, you can only call functions that are in the C standard library or the Rhope runtime, and the types it supports is limited, but I hope to address that soon.

Here's an example of how to declare a foreign function in Rhope:
Foreign C:libc { putchar[char(Int32,Naked):result(Int32,Naked)] }
The above declares a C foreign function in the library libc named putchar with one input and one output. In this case both the input and the output is an unboxed signed 32-bit integer. After putting this declaration in the toplevel of a Rhope source file, you could call putchar is if it were a normal Rhope worker.

Adding the FFI has allowed me to write the implementation of Array mostly in Rhope with a few small helper functions in C. Once the FFI is finished, writing an initial version of the File type will be relatively straightforward. Once I have access to file I/O, I just need to implement higher order functions and a few more types (String, List and Dictionary) and I should be able to get the Rhope compiler compiling itself (with a few small modifications due to changes I've made in the language).

Username: Password:
Don't have an account? Register now!