a compiler for the bonk programming language. compiles to arm64 assembly on macos.
bonk is a lisp-ish language that compiles to native code. it's got variables, loops, maths and nothing else.
cd bonk_compiler
cargo build --release./target/release/bonk_compiler yourfile.bonkthis creates an executable in the bin/ directory with the same name (minus the .bonk extension).
- math ops:
add,sub,mul,div,mod - comparisons:
eq,lt,gt,lte,gte - variables:
(let x 10) - loops:
(while condition body...) - conditionals:
(if condition then else) - blocks:
(block expr1 expr2 ...)- runs multiple expressions - input:
(input)- reads first command line arg as number - output:
(print expr)- prints a number
everything is s-expressions (lisp style with parens):
# fibonacci
main =
(block
(let n (input))
(let a 0)
(let b 1)
(let i 0)
(while (lt i n)
(block
(let temp b)
(let b (add a b))
(let a temp)
(let i (add i 1))))
(print a))
check out the bonk/ directory for examples:
fib.bonk- fibonacci numbersprime.bonk- prime checkercollatz.bonk- collatz conjecture
# compile
./target/release/bonk_compiler bonk/fib.bonk
# run
./bin/fib 10is_prime is comparable with optimised C (benchmark.sh n)
dunno