Scheme compiler implemented in OCaml with an LLVM backend
  • OCaml 90.9%
  • Shell 5.5%
  • Scheme 3.1%
  • Makefile 0.4%
Find a file
2019-11-11 12:35:00 +00:00
bin rebuild bonsai as a scheme ocaml compiler 2026-09-03 04:18:07 +00:00
examples rebuild bonsai as a scheme ocaml compiler 2026-09-03 04:18:07 +00:00
lib support datum comments 2019-11-11 12:35:00 +00:00
scheme rebuild bonsai as a scheme ocaml compiler 2026-09-03 04:18:07 +00:00
tests support datum comments 2019-11-11 12:35:00 +00:00
tools initial 2026-09-02 18:06:12 +00:00
.gitignore rebuild bonsai as a scheme ocaml compiler 2026-09-03 04:18:07 +00:00
bonsai.opam add structural equality 2019-06-18 14:05:00 +00:00
dune-project rebuild bonsai as a scheme ocaml compiler 2026-09-03 04:18:07 +00:00
Makefile rebuild bonsai as a scheme ocaml compiler 2026-09-03 04:18:07 +00:00
README.md rebuild bonsai as a scheme ocaml compiler 2026-09-03 04:18:07 +00:00

scheme compiler and runtime. the implementation turns symbolic programs into typed and analysable llvm representations

the intended pipeline is:

S-expressions -> desugared core -> ANF -> CPS -> closure conversion -> LLVM IR

the runtime has proper lists and quotation. it has integers and booleans as well as it strings and symbols. procedures are first-class and closures are lexical

scheme

programs are multi form scheme source:

(define (factorial n)
	(if (= n 0)
			1
			(* n (factorial (- n 1)))))

(factorial 10) ; => 3628800

lexical state is represented by captured mutable cells

(define (make-counter seed)
	(let ((value seed))
		(lambda (step)
			(set! value (+ value step))
			value)))

(define counter (make-counter 40))
(counter 1) ; => 41
(counter 1) ; => 42

higher order procedures compose into list transformations:

(define (map f values)
	(if (null? values)
			'()
			(cons (f (car values)) (map f (cdr values)))))

(define (double value) (* value 2))
(map double '(1 2 3 4)) ; => (2 4 6 8)

recursive evaluation remains direct and compositional:

(define (fib n)
	(if (< n 2)
			n
			(+ (fib (- n 1)) (fib (- n 2)))))

(fib 20) ; => 6765

the bundled scheme prelude builds map and filter and also includes folds and list utilities