2 releases
0.1.1 | Nov 6, 2020 |
---|---|
0.1.0 | Nov 5, 2020 |
#769 in Procedural macros
5KB
BrainFuck Compiler
BrainFuck compiler in Rust procedural macro metaprogramming.
Usage
The BrainFuck code from https://fatiherikli.github.io/brainfuck-visualizer/, see it how to work.
The BrainFuck compiler generates the below code to "Hello World!" at compiler time(metaprogramming), and printing it at run time.
Implementing in Rust procedural macro way.
extern crate brain_fuck;
use brain_fuck::brain_fuck;
fn main() {
println!("{}", brain_fuck!(
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.
>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
));
}
emit asm code:
brain_fuck::main::h3aaadb2fa73e0763:
...
pushq %rbp
movq %rsp, %rbp
subq $64, %rsp
leaq l___unnamed_2(%rip), %rax
movq %rax, -16(%rbp)
leaq _$LT$$RF$T$u20$as$u20$core..fmt..Display$GT$::fmt::h45c22d68a23dc67a(%rip), %rax
...
l___unnamed_6:
.ascii "Hello World!\__int128"
.section __DATA,__const
.p2align 3
l___unnamed_2:
.quad l___unnamed_6
.asciz "\r\000\000\000\000\000\000"