brain_fuck

Crates.iobrain_fuck
lib.rsbrain_fuck
version0.1.1
sourcesrc
created_at2020-11-05 16:48:25.566402
updated_at2020-11-06 12:53:01.190722
descriptionBrainFuck compiler in Rust procedural macro metaprogramming
homepagehttps://netcan.github.io/
repositoryhttps://github.com/netcan/recipes/tree/master/rust/BrainFuck
max_upload_size
id308964
size4,876
Netcan (netcan)

documentation

README

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"
Commit count: 0

cargo fmt