2023-08-22 09:45:31 +02:00
|
|
|
# BrainRustFucked
|
|
|
|
YABI (Yet Another Brainfuck Interpretator)
|
|
|
|
This is designed to embed BrainFuck for applications.
|
|
|
|
|
|
|
|
This library provides 2 functions:
|
|
|
|
|
|
|
|
```rs
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Eval the code from a raw string returning the memory
|
|
|
|
*/
|
|
|
|
fn eval(bf_str: &&str) -> Result<[u8; 30000], String>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A more low level function to run code in custom environment
|
|
|
|
* This is useful when you want to use presetted memory & pointer
|
|
|
|
*/
|
|
|
|
fn eval_mem(bf_str: &&str, mem: &mut [u8], pointer: &mut usize) -> Result<(), String>
|
|
|
|
```
|
|
|
|
|
|
|
|
Example code:
|
|
|
|
```rs
|
|
|
|
// print "Hello world!"
|
2023-08-22 09:46:13 +02:00
|
|
|
eval(&"++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.").unwrap();
|
2023-08-22 09:45:31 +02:00
|
|
|
```
|
|
|
|
|
2023-08-22 17:09:32 +02:00
|
|
|
Also check out `examples/` directory
|
|
|
|
|
|
|
|
## Using this as command-line interpreter
|
|
|
|
There is an example `eval_file`, which you can compile to a standalone binary
|
|
|
|
|
|
|
|
```sh
|
|
|
|
cargo b --release --example=eval_file
|
|
|
|
cd target/release/examples
|
|
|
|
|
|
|
|
# those two are optional, they are needed to reduce the size of binary
|
|
|
|
# its recommended but if they fail its no big deal
|
|
|
|
strip eval_file
|
|
|
|
upx eval_file
|
|
|
|
|
|
|
|
cp eval_file /usr/bin/eval_file # or other directory that is in $PATH
|
|
|
|
hash -r # run this just in case to refresh $PATH in your terminal
|
|
|
|
|
|
|
|
eval_file file.b # 1st argument is the name of the file
|
|
|
|
```
|