bivoje/ziggerish
Brainfuck compiler with minimum compile dependency, written in zig.
Brainfuck compiler written in Zig.
This project is tested with zig-linux-x86_64-0.10.0-dev.479+5e60ee412
.
Compatibility with other versions of zig is not known.
Download and install zig compiler then
zig build
will create the executable in zig-out/bin/ziggerish
.
Simple hello world program copied from wikipedia page
zig build run -- samples/hello.bf : ?target=linux_x86_64 ?alloc=7 : ll : main
life automaton simulator written by Linus Akesson found at here.
ziggerish samples/hello.bf : ?target=linux_x86_64 ?alloc=-1000 : as : hello
shorted brainfuck interpreter written in brainfuck found at here.
ziggerish samples/dbfi.bf : ?target=linux_x86 : gcc +inlined -libc : dbfi
(cat samples/hello.bf; echo -n '!') | ./dbfi
ziggerish <source> : <general_options> : <method> <method_options> : <dest>
ziggerish
gets compile options from commandline arguments in unconventional, structured way.
4 fields being colon (:
) separated are required where each can be left omitted for default value.
Note that you can't omit space between colons and give ziggerish a.bf ::: a.out
,
as parameters are tokenized by whitespaces in current implimentation.
Simply specify source path and destination path.
In current implementation, when multiple paths are given, only the last one is recognized.
Unlike other unix programs, options have the form ?<key>=<value>
.
If the value is boolean you can use syntactic sugar +<key>
for true
or -<key>
for false
.
The possible options are:
,
instruction do when EOF encountered. there are no consensus for behavior on EOF,
so each bf code assumes one of the options listed above.
selecting the wrong option may result in unexpected behavior of compiled program.<method>
selects which backends to use while compiling.
<method_options>
has same format as <general_options>
while supported keys are method specific.
Currently suppoted methods are
gcc
to produce an executable..
and ,
are effected, and >
and <
are inlined regardlessly.as
and ld
to produce an executable.as
clang
to produce an execuable.[ ] impliment streamed input/output
[ ] --help option?
[ ] better, detailed error message. use enum-either rather than error set
[ ] support intel assembly syntax?
[ ] organize tests
[ ] add tests
[ ] optimizaion use ir (add 4 etc..) <- need to ge/le rather than ne for boundary check
[ ] remove unnecessary -q instr, it inflates machine code size
[ ] boundary check when accessing the value rather than moving the pointer
[ ] writer monad, funcionize code snippet generation parameterize registers in compile_as
[ ] what if compilation takes too long? < like kernel compile? memory management use other than arena
[ ] windows binary support
[ ] resolve TODOs and FIXMEs
[ ] impliment inotifywait in build.zig
inotifywait src
is too noisy, as vim never just writes to the file
vim creates and writes to filename~ file stead of the file itself
and then deletes original and moves the file
with auto saves and temp files, this behavior makes watch-test run multiple times
[ ] enable compiling with debugging infos
[ ] verbos compiling (dump option only if)
[ ] compile pipeline design
[ ] option for how to handle temp files?
[ ] immediate executable generation
[ ] inline asm. it inflates exe size but may have better performance as there's less jumps.
[ ] alloc=dynamic in c-nostdlib/llvm using alloca().