Wisp: Small-but-featureful embeddable Lisp interpreter written in Haskell
github.com
github.com
> wisp lives in the ST (optionally IO) monad. separate
> interpreters with completely segregated environments can be
> run concurrently. wisp has a few IO facilities, but they're
> completely sandboxed and can't accidentally affect the host
> program or environment.
This is wonderful. There's already an embedded R5RS Scheme for Haskell (http://hackage.haskell.org/package/husk-scheme) but it runs everything in the IO monad. That makes it fairly annoying for sandboxed embeddings.I also recently found Matt Might's Compilers class [3] via a submission here on HN. It has a lot of language-agnostic resources.
[1]: http://www.reddit.com/r/compilers
The main problem is that it doesn't have a ternary operator, making conditional expression problematic to represent (you have to wrap an if statement in a lambda called on the fly).
For something more fully featured, see [0], it is written in MoonScript (which itself compiles to Lua), and the parser depends on LPeg, but writing a S-expression parser is rather easy.
Edit: There's also lcl [1], which is implemented in C. Written by lhf, one of the Lua authors. From the test files, it looks very basic.
--
[0] https://github.com/leafo/moonlisp/tree/master/lisp
[1] http://www.drdobbs.com/open-source/lua-an-extensible-embedde...
((if foo + -) 4 6)
Can be compiled to (function()
if foo then return plus
else return minus
end
end)()(4, 6)
It is far too verbose to be used in manually crafted Lua, but acceptable if you treat it as a compiler target (with the caveat that the lambda creation will prevent LuaJIT from JITting that piece of code)."A object-oriented, unicode-enabled lisp that compiles to and runs as fast as Lua. Equipped with macros and compile-time compiler manipulation. Comes with all built-in Lua functions."
I have a question regarding your implementation: why do you use `goto`s rather than `elseif` to compile `(cond)` blocks? For nested blocks?
The author's own Maru (http://piumarta.com/software/maru/) might be better suited for this, but I'm not sure..
Some links
1. Andy Wingo (main Guile implemetor)'s "buyer's guide" to Scheme implementations - http://wingolog.org/archives/2013/01/07/an-opinionated-guide...
2. Chibi Scheme homepage - http://synthcode.com/scheme/chibi/
While maybe not as tiny as Lua, it is designed to be embeddable out of the box.
The FFI is very simple.