A Foreign Function Interface for Pallene
Resumo
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.
Palavras-chave:
Lua, Compilers, Foreign Function Interface
Publicado
03/10/2022
Como Citar
DE PAULA, Gabriel Coutinho; IERUSALIMSCHY, Roberto.
A Foreign Function Interface for Pallene. In: SIMPÓSIO BRASILEIRO DE LINGUAGENS DE PROGRAMAÇÃO (SBLP), 26. , 2022, Uberlândia.
Anais [...].
Porto Alegre: Sociedade Brasileira de Computação,
2022
.
p. 32–40.