A compiler written in Rust.
This is just a (small?) project I'm working on. I don't have a clear goal at this point. I'll try to update this repo on a weekly basis.
Well it all started with this:
"There are two kinds of programmers — those who have written compilers and those who haven't."
-Terry A. Davis
No, actually...
I am learning compiler design at college this semester so I thought this might be a good time to try building a compiler from scratch. It took me 4 days to write a simple comiler that can convert...
return 70;
...this, to...
global _start
_start:
mov rax, 60
mov rdi, 70
syscall
...this.
Because I don't know Rust and I felt this might be a good chance to learn the language 🤷♂️
I like love coffee ♥
- To begin with, you must have a
*.cb
file (actually, any plaintext file will do, but the extension makes it look awesome, for the time being). Write a C-like return statement:return 20;
- Pass this file as an argument.
cargo run <file.cb>
- It will create an
out.asm
file. In order to create the binary, run this command (you might need to installnasm
andld
packages first):nasm -felf64 out.asm && ld out.o -o out
- Now run the binary
./out
- It won't print anything as it calls only the
exit
syscall with a return value (20 in this case). To check the return value, run:It should print 20.echo $?