fecs: a lisp interpreter running in wasm
15 Sep 2024fecs is a lisp interpreter in the style of PicoLisp running in wasm.
Fecs was made as an exploration of the PicoLisp system and as an attempt to make a programming language that runs on WebAssembly (wasm). It is implemented in C, and compiled to wasm with clang/LLVM. WebAssembly can run on many platforms, including browsers. A nice advantage of running wasm in the browser is the availability of the wasm memory inspector. Because PicoLisp is an interpreter (instead of a code compiler) any running system was therefore easily inspectable and debugable during development.
The name 'fecs' stands for 'FExprs', 'cells' and 'symbols', which refer to the building blocks of the PicoLisp system. 'FExprs' are functions that get passed the unevaluated arguments, and are an alternative to Lisp macros. The 'cell' in PicoLisp is the only datastructure as a cons cell of 2 pointers (fecs uses 4 bytes per pointer). And 'symbols' are dynamically bound, rather than the more common lexical binding and scoping, which makes symbols represent an actual place in memory. These and other choices make PicoLisp a nice and small system.
The main example to make the interpreter work is the code from the 'Functional Geometry by P. Henderson' paper. By composing functions, a picture is drawn from a single fish into mesh of interleaved fish, as can be seen on the canvas example page. In PicoLisp and thus fecs functions are only data, without a closure binding context. Therefore the function composition is done by putting the datastructure of a function within the data of another function.
More information on fecs is available on the API page, which has a repl running in the browser.
- API & repl
- canvas example to render an Escher picture
- test cases running in a web page