![]() |
The femtolisp Scheme interpreter | ![]() |
TeXmacs runs its Scheme code on one of three interpreters, chosen when it is built: Guile, S7 or femtolisp. This chapter is for the developers who maintain the femtolisp one: how it is put together, what it relies on, how to change it and how to find what goes wrong.
femtolisp is a small Lisp close to Scheme, by Jeff Bezanson, with a compiler to bytecode written in Lisp and a copying garbage collector. Its sources are in the tree, with the local patches: a build with femtolisp needs nothing else. It is about a sixth of the size of S7, in lines of source, and as fast or faster once the code is loaded.
./configure --with-scheme=femtolisp
make |
With CMake the option is -DSCHEME_IMPL=femtolisp (not tested yet); for the browser version, see femtolisp in the browser. The choice defines USE_FEMTOLISP and compiles the directory
src/Scheme/Femtolisp
. In Scheme, (femtolisp-scheme?) tells that the interpreter is femtolisp, as (s7-scheme?) does for S7.
src/Scheme/Femtolisp/femtolisp/
femtolisp itself, with the local patches applied: its C sources, its library llt, its compiler and standard library (system.lsp, compiler.lsp) and the boot image made from them (flisp.boot).
src/Scheme/Femtolisp/patches/
The local patches, in order, as git format-patch writes them.
src/Scheme/Femtolisp/fl_core.c,
fl_llt.c
The two compilation units: femtolisp and its C interface for TeXmacs, and the library llt.
src/Scheme/Femtolisp/fl_tm.h
The C interface, the only header of femtolisp which the C++ code includes.
src/Scheme/Femtolisp/femtolisp_tm.hpp,
femtolisp_tm.cpp
The interface of the Scheme interpreters of TeXmacs (tmscm) on femtolisp, as S7/s7_tm.* and Guile/guile_tm.*.
src/Scheme/Femtolisp/fl_boot.h
The boot image as a C array, made by
make-boot-header.sh
.
TeXmacs/progs/init-femtolisp.scm
The first Scheme file loaded. It loads the two files below and the module of the third, then the
init-kernel.scm
and
init-texmacs.scm
of all the interpreters.
TeXmacs/progs/kernel/boot/r5rs-femtolisp.scm
R5RS and the basic functions of Guile, defined on femtolisp.
TeXmacs/progs/kernel/boot/boot-femtolisp.scm
The modules, the loading of files, the lazy function bodies and the caches of compiled code.
TeXmacs/progs/kernel/boot/compat-femtolisp.scm
The library functions of Guile (hash tables, lists, strings…), as a module.
docs/femtolisp/
The working notes: the measurements, the history of the decisions.
Scheme values held by C++ are roots of the garbage collector. The collector of femtolisp moves the objects, so a tmscm registers itself in a list which the collector updates.
The errors of femtolisp never cross C++ code. They are longjmps, which would skip the destructors.
Strings are strings of bytes, in the Cork encoding of TeXmacs, without any conversion between C++ and Scheme.
A module is a set of renamed global names. femtolisp has one global environment: the private name f of the module (a b) is the global name f@a/b.
The body of a function is expanded and compiled when it is first called, as Guile and S7 do, and the compiled code is kept in a cache between the sessions.