can is a stack-based programming language written in rust.
It is currently at the earliest stages of its development and basically copies the syntax of Tsoding's Porth.
- arithmetic operations
- bitwise logic operations
- dump (print number from the top of the stack)
- if-else statements
- while loops
- memory addressing
- syscalls
- C-style comments (//)
- Turing complete
While loop that prints numbers 1 to 10
10 0 while 2dup > do
1 +
dup dump
end
// prints first 10 numbers of Fibonacci sequence
mem 1 + 0 . // first
mem 2 + 1 . // second
mem 3 + 0 . // temp
// breaks after number 255 because we're using bytes :)
10 0 while 2dup > do
1 +
mem 3 + mem 1 + , mem 2 + , + . // sum two numbers and put result in temp value
mem 1 + mem 2 + , . // put second number in place of first
mem 2 + mem 3 + , . // put temp value in place of second
mem 3 + , dump // print
end
cargo run build examples/test.can && ./out
cargo run emulate examples/test.can