Added post
Some checks are pending
/ build (push) Waiting to run

This commit is contained in:
vanten-s 2024-12-18 08:55:12 +01:00
parent d60a20abe7
commit c32d5edd56
Signed by: vanten-s
GPG key ID: DE3060396884D3F2

View file

@ -0,0 +1,52 @@
+++
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
```