z

Building a C compiler along with Rui Ueyama's 9cc ([book][9cc-book], [repo][9cc]).

prereqs

Crystal.

build/install

git clone https://github.com/jethrodaniel/z && cd z && make

usage

$ ./bin/z
Usage: z [command] [arguments]
    lex                              Lex input, output tokens
    parse                            Parse input, output AST
    dot                              Parse input, output graphviz dot
    compile                          Compile input, output assembly
    run                              Compile and run input
    obj                              Analyze object files
    -i                               Get input from stdin
    -c                               Get input from string
    -v, --version                    Show the version
    -h, --help                       Show this help

example

See the specs in the spec/compiler directory.

$ pushd spec/compiler/
$ ../../bin/z run hi.c
hi!
$ ../../bin/z run main.c
fib(0)  = 0
fib(1)  = 1
fib(2)  = 1
fib(3)  = 2
fib(4)  = 3
fib(5)  = 5
fib(6)  = 8
fib(7)  = 13
fib(8)  = 21
fib(9)  = 34
fib(10) = 55
fib(11) = 89
fib(12) = 144
$ z run -c 'p(c){putchar(c);}main(){p(65);p(10);}'
A

license

MIT

references

If I have seen further, it is by standing upon the shoulders of giants.

Sir Isaac Newton, 1675

Thanks, y'all.