Lispyboi is a bytecode-based Lisp implementation written in C++. It features a virtual machine with garbage collection, tail-call optimization, and a moderate standard library.
- Lisp-2 dialect (separate namespace for functions and variables)
- Lexical scoping
- First-class functions and closures
- Macro system with quasiquotation
- Garbage collection with generational collection
- Tail-call optimization
- Package system
- Rich type system
- CLOS-like generic functions
- Comprehensive sequence operations (lists, arrays, strings)
- File I/O with streams
- String manipulation with UTF-8 support
- Network programming (TCP sockets, SSL support)
- Foreign Function Interface (FFI)
- Testing framework
- Error handling system
- HTTP server with routing and file serving
- Echo server/client network application
- Modern C++ compiler (C++17 or later)
- Make
# Build the main executable
make
# Run tests
./lispyboi lisp/test-suite.module
./lispyboi
./lispyboi script.lisp
./lispyboi lisp/httpd.lisp 8080
;; Function definition
(defun greet (name)
(format t "Hello, ~a!~%" name))
;; Macro definition
(defmacro when (test &body body)
`(if ,test (progn ,@body)))
;; Object system
(defstruct point
(x 0)
(y 0))
;; Generic functions
(defgeneric area (shape)
"Calculate area of a shape")
(defmethod area ((s circle))
(* pi (square (circle-radius s))))
(defpackage :my-package
(:use :lispyboi)
(:export :my-function))
(in-package :my-package)
(require "ffi")
(ffi-with-symbols "libc.so.6"
((c-printf "printf"))
(c-printf "Hello from C!\n"))
- Stack-based bytecode VM
- Two-stack design (parameter stack and return stack)
- Three execution modes:
- Computed gotos (fastest)
- Tailcall optimization
- Switch-based dispatch (debug mode)
- Generational garbage collector
- Mark-and-sweep collection
- Value tagging for efficient representation
- Tagged 64-bit values
- First 3 bits used for type tags
- Support for:
- Fixnums (63-bit integers)
- Cons cells
- Symbols
- Strings (UTF-8)
- Arrays
- Functions/closures
- Characters
- Packages
- Generic functions
This project is open source and available under the MIT License.
This implementation takes inspiration from various Lisp dialects and implementations, particularly:
- Common Lisp
- Scheme
- SBCL's compilation model
- Emacs Lisp's simplicity