aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-29 11:09:25 +0200
committerBad Diode <bd@badd10de.dev>2021-10-29 11:09:25 +0200
commitba000c3e4589298bd62d91c7e42dbcf83c2b98e4 (patch)
treeae47e9f275f3187040074977db36fe7154da60fe /README.md
parentc934ceda5e5a8f9d706b1f4e31f343e293e24f6d (diff)
downloadbdl-ba000c3e4589298bd62d91c7e42dbcf83c2b98e4.tar.gz
bdl-ba000c3e4589298bd62d91c7e42dbcf83c2b98e4.zip
Update README
Diffstat (limited to 'README.md')
-rwxr-xr-xREADME.md92
1 files changed, 63 insertions, 29 deletions
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
4language theory. And so I found myself again delving into a rabbit hole of 4language theory. And so I found myself again delving into a rabbit hole of
5wheel-reinvention for the purpose of fun and learning. 5wheel-reinvention for the purpose of fun and learning.
6 6
7The goals for this project are to build a programming language that can be 7The language, `bdl` is inspired by `Scheme`, but it doesn't aim to be compatible
8interpreted directly from a VM and with support for compilation to assembly 8with it grammatically or in terms of behaviour. Instead, the core language is
9(`x86_64` and/or `ARM (thumb or aarch64)`). It could make sense to output 9much smaller and we will grow it organically as needed. As such, it is heavily
10bytecode for LLVM to take advantage of the built in optimizations, but let's 10in flux and not ready for any kind of production usage.
11just go one step at a time. At the time I know some ARM assembly, but I'm not so 11
12versed in `x86_64` and know nothing of LLVM bytecode. 12Currently `bdl` conforms with the grammar described below. It is a dynamically
13 13typed language, garbage collected and supports lambdas, lexical scopes and
14I've chosen to implement a Lisp, perhaps a subset of Scheme. The syntax is not 14closures.
15so important for now, maybe in the future the compiler will take a different 15
16home-brew language, but hopefully this helps setting the fundamentals for 16Up to [v0.7][v0.7] we were building a fully functional tree-walking interpreter.
17a minimal working compiler. In principle, we could keep the internal 17A writeup for the different building blocks can be found in [a series of
18representation and language working as a lisp, but with a different external 18articles][bdl-series] that go into great detail about the implementation and
19syntax. 19basic concepts behind the language.
20 20
21The language should have built-in structures for dynamic arrays, hash tables, 21From [v0.7][v0.7] to [v0.8][v0.8], we created a second interpreter
22strings (and string views). It should be suitable for use in embedded systems 22implementation. It was built by following along the second part of the [Crafting
23and be linked seamlessly with other compiled objects. 23Interpreters][crafting-interpreters] book. This reimagining of the project uses
24 24a single-pass compiler to generate bytecode for an custom abstract virtual
25Accessing system resources, such as stdio or graphics could be done via function 25machine. This interpreter is much faster than the tree-walking version and still
26calls to the give APIs. This should help decouple the CPU logic from hardware, 26supports closures, but it has no garbage collector and leaks memory. It was
27hopefully facilitating porting programs to different platforms (GBA, Rasberry 27a good learning exercise but the VM is too abstracted for my taste and I don't
28Pi, etc.). 28wish to maintain a half-baked implementation.
29 29
30The current plan is to build a bootstrap interpreter in C that can be used to 30Current development focuses on building from the fundamentals of previous
31generate the self-hosted version of itself. I'll try to document the process 31iterations to create a native compiler that could be used with multiple backends
32here as best as I can. 32for code generation (e.g. `LLVM`, `x86_64`/`aarch64` assembly, `uxn` bytecode,
33 33etc.). One of the goals of this part is to have trivial `C` interop when
34The bootstrap implementation should be kept simple, since we can focus on 34compiled natively, meaning it should be possible to call `bdl` code from `C` and
35optimization once we have a self-hosting compiler. 35`C` functions from `bdl` (though some wrappers may be necessary).
36
37[bdl-series]: https://git.badd10de.dev/bdl/tag/?h=v0.7
38[v0.7]: https://git.badd10de.dev/bdl/tag/?h=v0.7
39[v0.8]: https://git.badd10de.dev/bdl/tag/?h=v0.8
40
41# Grammar
42
43```
44program : <statement>* EOF
45
46<statement> : <definition> | <expression>
47
48<definition> : ( def <symbol> <expression> )
49 | ( fun ( <symbol>* ) <body> )
50 ;
51
52<expression> : <constant>
53 | ( lambda ( <symbol>* ) <body> )
54 | ( if <expression> <expression> <expression> )
55 | ( if <expression> <expression> )
56 | ( set! <symbol> <expression> )
57 | ( <expression> <expression>* )
58 ;
59
60<body> : <statement>*
61
62<constant> : <bool> | <number> | <string> | <symbol>
63
64<bool> : true | false
65<number> : -?<digit>+
66<string> : " <character>+ "
67<digit> : 0 | 1 | ... | 9
68<symbol> : <character>+
69```
36 70
37# Resources 71# Resources
38 72