Skip to content

ms0g/tinysexp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tinysexp

tinysexp is a minimalist Lisp compiler that targets the x86-64 architecture. It takes Lisp source code written in a simple s-expression syntax and compiles it down to NASM-compatible x86 assembly code.

Features

A subset of Lisp, including:

Operators: +,-,*,/,=, /=,>,<,>=,<= and,or,not

Conditionals: if,when,cond

Loop: dotimes,loop

Functions: defun

Variables: let,setq,defvar,defconstant

Usage

~ tinysexp -h
OVERVIEW: Lisp compiler for x86-64 architecture

USAGE: tinysexp [options] file

OPTIONS:
  -o, --output          The output file name
  -h, --help            Display available options
  -v, --version         Display the version of this program

Example

Input

(defun add (a b)
  (+ a b))

(add 1 2)

Output

[bits 64]
section .text
    global _start
_start:
    push rbp
    mov rbp, rsp
    sub rsp, 16
    mov rdi, 1
    mov rsi, 2
    call add
    add rsp, 16
    pop rbp
    mov rax, 0x2000001
    xor rdi, rdi
    syscall

add:
    push rbp
    mov rbp, rsp
    sub rsp, 16
    mov qword [rbp - 8], rdi
    mov qword [rbp - 16], rsi
    mov rax, qword [rbp - 8]
    mov r10, qword [rbp - 16]
    add rax, r10
    pop rbp
    add rsp, 16
    ret

License

This project is licensed under the GPL-2.0 License. See the LICENSE file for details.

Releases

No releases published

Packages

No packages published

Languages