(defn range (from to)
(if (eq? from to)
(list from)
(cons from
(range (fxadd1 from) to))))
(defn fizzbuzz (n)
(cond
((eq? (fxrem n 15) 0) (puts "FizzBuzz"))
((eq? (fxrem n 3) 0) (puts "Fizz"))
((eq? (fxrem n 5) 0) (puts "Buzz"))
(else (inspect n))))
(for-each fizzbuzz (range 1 100))
- Use chicken-scheme to build the compiler & the stdlib
- Compile some program to LLVM-IR
- Combine it w/ the stdlib files
- Run it
make bootstrap
./compiler < programs/fizzbuzz.csm > fizzbuzz-body.ll
cat stdlib-ll/*.ll stdlib.ll fizzbuzz-body.ll > fizzbuzz.ll
lli fizzbuzz.ll
- 64bit only
- Tagged Pointers for values, 3bit tag, 61bit value
- 000: Integer
- 001: Symbol
- 010: Char
- 100: Closure
- 101: String
- 110: Pair
- 111: Hardcoded primitives, #t, #f, '()
- Symbols are limited to 31 chars
- Not compliant to any standart
- No GC => compiling itself uses ~1GB of RAM
compiler.scm
Main compiler logichelper.scm
Helper functions that are not part of the stdlibllvm.scm
Helper functions for outputting LLVM-IR codereader.scm
Recursive descent parser for the input languagesyntax.scm
Defines the syntax of the input language- `preprocessing/
desugar.scm
Convertcond
toif
etc.alpha-convert.scm
Rename variables to prevent naming collisionsclosure-convert.scm
Convertfn
s to closures & lambdas w/o free variables
compatibility.scm
Some macros & functions to make chicken scheme understand the compiler source codestdlib-ll/
Collection of low-level stdlib functions written directly in LLVM-IR
~>
Thread-first macro like in clojure~>>
Thread-last macro like in clojure