1 KiB
1 KiB
+++ title = 'Os Devlog: Lisp Compiler' date = 2024-09-08T12:00:00+02:00 categories = ["os"] tags = ["lowlevel", "lisp", "compiler"] summary = "LISP :3" draft = true +++
Introduction
In my previous article I wrote about my os. In this article I will explore the compiler I have made for the system.
Goals for the compiler
Goals are important for getting stuff done. With this compiler I want to:
- Implement a simple LISP language
- Compile to a format that my OS supports
- Functions
- Variables
- Loops
- If statements
- First-class functions
AST
For the program
(+ 1 (+
a b ))
The AST looks like this:
/ \
+ / \
1 / \
/ \ NIL
+ / \
a / \
b NIL
Compilation
My lisp-implementation is heavily stack-based, and only uses registers when using instructions that need them.
For example, a + function could compiler to this:
pop eax
pop ebx
add eax, ebx
push eax