Scheme compiler implemented in OCaml with an LLVM backend
- OCaml 90.9%
- Shell 5.5%
- Scheme 3.1%
- Makefile 0.4%
| bin | ||
| examples | ||
| lib | ||
| scheme | ||
| tests | ||
| tools | ||
| .gitignore | ||
| bonsai.opam | ||
| dune-project | ||
| Makefile | ||
| README.md | ||
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