My Master's degree was in programming languages, where I did research in foreign function interfaces (FFI). In my thesis, I designed and implemented an FFI for the Pallene programming language. Later on, we published a paper of the same title in the Brazilian Symposium on Programming Languages (SBLP), which won the Best Non-Student Paper Award.
Abstract
Pallene is a statically typed subset of the Lua programming language, designed to act as a system-language counterpart to Lua’s scripting, and used to write lower-level libraries and extension modules for Lua. In this sense, Pallene is a companion language, always intended to be used side-by-side with Lua, sharing its runtime.
Pallene, both as a system-language counterpart to Lua and as a bridge between Lua and foreign languages, must provide a mechanism to interact with libraries and system services written in a low-level language like C. To this end, we present a Foreign Function Interface (FFI) design and implementation for Pallene, which allows for calling external functions that follow C calling conventions and manipulating C data representations directly.
Our design balances flexibility and safety following an empirical approach, wherein we prefer to sacrifice hypothetical flexibility unless we see a real use case that forces us to compromise on safety. Furthermore, our implementation aims to be as portable as Pallene, as well as performant and simple. Since Pallene’s implementation already depends on a C compiler, we avail ourselves of the assistance of this compiler to gain a rudimentary understanding of C. This enables the FFI to verify the correctness of function bindings and to use C macro definitions.