Crates.io | brain_fuck |
lib.rs | brain_fuck |
version | 0.1.1 |
source | src |
created_at | 2020-11-05 16:48:25.566402 |
updated_at | 2020-11-06 12:53:01.190722 |
description | BrainFuck compiler in Rust procedural macro metaprogramming |
homepage | https://netcan.github.io/ |
repository | https://github.com/netcan/recipes/tree/master/rust/BrainFuck |
max_upload_size | |
id | 308964 |
size | 4,876 |
BrainFuck compiler in Rust procedural macro metaprogramming.
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"