

A simple procedural macro that turns a Brainfuck program into Rust - steveklabnik
https://github.com/huonw/brainfuck_macro

======
eric_bullington
If you find this interesting, you should check out RustLex, which makes
writing a lexer in Rust incredibly simple through judicious use of Rust
macros:

[https://github.com/LeoTestard/rustlex](https://github.com/LeoTestard/rustlex)

------
StavrosK
Does anyone have an example? I don't have any of the toolchain, and it seems
like a lot to do to see a compiled example.

~~~
steveklabnik
Well, you'd never see the compiled example. You'd compile the example in the
README, and it'd give you a binary. It's a macro, not like CoffeeScript.

That said, you could view the expanded output if you were curious. You'd pass
`--pretty expanded` to `rustc`. The pretty printer isn't great yet, though. I
would run it for you and give you a gist, but I'm not at a computer with the
toolchain either.

~~~
ben0x539
The example in the readme: [http://ix.io/cdR](http://ix.io/cdR)

Emitted llvm ir doesn't look much more compact either:
[http://ix.io/cdS](http://ix.io/cdS)

Clearly there is still plenty of room for optimizing brainfuck compilers!

~~~
eridius
Eh, compile with -O and let LLVM optimize it.

~~~
ben0x539
Is `rustc --opt-level 3 --emit ir` not right?

~~~
eridius
The optimization level is given to LLVM. The IR itself should be the same for
all optimization levels AFAIK.

~~~
dbaupp
Almost all LLVM optimisations map IR to IR, and --emit=ir prints the final IR
just before codegen (i.e. after optimisations happen).

~~~
eridius
Oh? I was under the impression it was the IR that was given to LLVM to begin
with. Interesting.

------
Jemaclus
Amazing.

