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 and while-loops
- Memory addressing
- Syscalls
- Macros
- C-style comments (//)
- Turing complete
While loop that prints numbers 1 to 10
include "./std/std.can" // for dump
10 0 while 2dup > do
1 +
dup dump
end
// prints first 10 numbers of Fibonacci sequence
include "./std/std.can"
// include offset (hack as we don't have proper memory allocation)
macro offset mem 64 + ;
macro BYTE 8 ;
macro first offset ;
macro second offset BYTE + ;
macro temp offset BYTE BYTE + + ;
first 0 !64 // first
second 1 !64 // second
temp 0 !64 // temp
20 0 while 2dup > do
1 +
temp first @64 second @64 + !64 // sum two numbers and put result in temp value
first second @64 !64 // put second number in place of first
second temp @64 !64 // put temp value in place of second
temp @64 dump // print
end
cargo run -- build examples/test.can && ./out
cargo run -- emulate examples/test.can