+++ 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](https://forgejo.vanten-s.com/vanten-s/os). In this article I will explore the [compiler I have made for the system](https://forgejo.vanten-s.com/vanten-s/lisp-8bit). ## 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 ```lisp (+ 1 (+ a b )) ``` The AST looks like this: ```text / \ + / \ 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: ```asm pop eax pop ebx add eax, ebx push eax ```