Skip to content

jerseyjosh/bonk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bonk

a compiler for the bonk programming language. compiles to arm64 assembly on macos.

what is this

bonk is a lisp-ish language that compiles to native code. it's got variables, loops, maths and nothing else.

building the compiler

cd bonk_compiler
cargo build --release

compiling bonk programs

./target/release/bonk_compiler yourfile.bonk

this creates an executable in the bin/ directory with the same name (minus the .bonk extension).

language features

  • 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

syntax

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))

examples

check out the bonk/ directory for examples:

  • fib.bonk - fibonacci numbers
  • prime.bonk - prime checker
  • collatz.bonk - collatz conjecture

running programs

# compile
./target/release/bonk_compiler bonk/fib.bonk

# run
./bin/fib 10

performance

is_prime is comparable with optimised C (benchmark.sh n)

why tho

dunno

About

bonk programming language compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors