Workshop Paper: The Layers of Larceny's FFI

Felix presented a paper on Larceny's FFI at the Scheme Workshop 2008.

The abstract:

The Foreign Function Interface (FFI) in Larceny supports interacting with dynamically loaded C libraries via glue code written in Scheme. The programmer does not need to develop any C code to interface with C libraries. The FFI is divided into layers of Larceny Scheme code; the lower layers implement kernel functionality, and the higher layers support portable glue code development.

The lower level has two main features of interest. First, the FFI supports callbacks: objects that look like simple function pointers to foreign code but invoke Scheme closures when called. This requires generating specialized machine code, and is further complicated by the potential movement of the closures during garbage collections. Second, Larceny heaps can be dumped to disk and reloaded during a fresh runtime execution. The FFI automatically relinks the foreign procedures in such heaps.

The higher level layers provide macros and procedures for extracting information from header files and dictating how values translate between Scheme and foreign code. These tools ease development of portable glue code. The upper layers have simple implementations and do not require much Larceny-specific functionality; they may be useful for the FFIs of other Scheme systems.

Presentation slides: klock-ffi-schemeworkshop-2008-slides.pdf.

The paper: klock-ffi-schemeworkshop-2008.pdf.


Felix S Klock II
Felix's homepage

Last updated 7 December 2008.

Valid XHTML 1.0!