# Bad Diode's Lisp For some time I've been meaning to learn more about compilers and programming language theory. And so I found myself again delving into a rabbit hole of wheel-reinvention for the purpose of fun and learning. The language, `bdl` is inspired by `Scheme`, but it doesn't aim to be compatible with it grammatically or in terms of behaviour. Instead, the core language is much smaller and we will grow it organically as needed. As such, it is heavily in flux and not ready for any kind of production usage. Currently `bdl` conforms with the grammar described below. It is a dynamically typed language, garbage collected and supports lambdas, lexical scopes and closures. Up to [v0.7][v0.7] we were building a fully functional tree-walking interpreter. A writeup for the different building blocks can be found in [a series of articles][bdl-series] that go into great detail about the implementation and basic concepts behind the language. From [v0.7][v0.7] to [v0.8][v0.8], we created a second interpreter implementation. It was built by following along the second part of the [Crafting Interpreters][crafting-interpreters] book. This reimagining of the project uses a single-pass compiler to generate bytecode for an custom abstract virtual machine. This interpreter is much faster than the tree-walking version and still supports closures, but it has no garbage collector and leaks memory. It was a good learning exercise but the VM is too abstracted for my taste and I don't wish to maintain a half-baked implementation. Current development focuses on building from the fundamentals of previous iterations to create a native compiler that could be used with multiple backends for code generation (e.g. `LLVM`, `x86_64`/`aarch64` assembly, `uxn` bytecode, etc.). One of the goals of this part is to have trivial `C` interop when compiled natively, meaning it should be possible to call `bdl` code from `C` and `C` functions from `bdl` (though some wrappers may be necessary). [bdl-series]: https://git.badd10de.dev/bdl/tag/?h=v0.7 [v0.7]: https://git.badd10de.dev/bdl/tag/?h=v0.7 [v0.8]: https://git.badd10de.dev/bdl/tag/?h=v0.8 # Grammar ``` program : * EOF : | : ( def ) | ( fun ( * ) ) : | ( lambda ( * ) ) | ( if ) | ( if ) | ( set! ) | ( * ) : * : | | | : true | false : -?+ : " + " : 0 | 1 | ... | 9 : + ``` # Resources - [Structure and Interpretation of Computer Programs][sicp] - [Crafting Interpreters][crafting-interpreters] - [Building a Scheme from scratch][scheme-from-scratch] - [Compiling a Lisp][compiling-a-lisp] - [An Incremental Approach to Compiler Construction][ghuloum11] - [Make-A-Lisp Guide][mal] - [An Introduction to Scheme and its Implementation][intro-to-scheme-and-imp] - [Scheme to C][scheme-to-c] [sicp]: https://mitpress.mit.edu/sites/default/files/sicp/index.html [crafting-interpreters]: https://craftinginterpreters.com/ [scheme-from-scratch]: http://peter.michaux.ca/articles/scheme-from-scratch-introduction [compiling-a-lisp]: https://bernsteinbear.com/blog/compiling-a-lisp-0/ [ghuloum11]: http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf [mal]: https://github.com/kanaka/mal/blob/master/process/guide.md [intro-to-scheme-and-imp]: https://www.cs.utexas.edu/ftp/garbage/cs345/schintro-v14/schintro_toc.html#SEC271 [scheme-to-c]: https://github.com/akeep/scheme-to-c