From ba000c3e4589298bd62d91c7e42dbcf83c2b98e4 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 29 Oct 2021 11:09:25 +0200 Subject: Update README --- README.md | 92 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 29 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 4caf1c3..321c43d 100755 --- a/README.md +++ b/README.md @@ -4,35 +4,69 @@ 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 goals for this project are to build a programming language that can be -interpreted directly from a VM and with support for compilation to assembly -(`x86_64` and/or `ARM (thumb or aarch64)`). It could make sense to output -bytecode for LLVM to take advantage of the built in optimizations, but let's -just go one step at a time. At the time I know some ARM assembly, but I'm not so -versed in `x86_64` and know nothing of LLVM bytecode. - -I've chosen to implement a Lisp, perhaps a subset of Scheme. The syntax is not -so important for now, maybe in the future the compiler will take a different -home-brew language, but hopefully this helps setting the fundamentals for -a minimal working compiler. In principle, we could keep the internal -representation and language working as a lisp, but with a different external -syntax. - -The language should have built-in structures for dynamic arrays, hash tables, -strings (and string views). It should be suitable for use in embedded systems -and be linked seamlessly with other compiled objects. - -Accessing system resources, such as stdio or graphics could be done via function -calls to the give APIs. This should help decouple the CPU logic from hardware, -hopefully facilitating porting programs to different platforms (GBA, Rasberry -Pi, etc.). - -The current plan is to build a bootstrap interpreter in C that can be used to -generate the self-hosted version of itself. I'll try to document the process -here as best as I can. - -The bootstrap implementation should be kept simple, since we can focus on -optimization once we have a self-hosting compiler. +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 -- cgit v1.2.1