Crate mindjuice [−] [src]
mindjuice
Mindjuice is a simple and easy-to-use brainfuck interpreter!
Usage
Mindjuice parses and runs brainfuck programs in two stages. First, it converts an input string into a Vec<Instruction>
, then it can run that instruction vector to produce output.
You can pass anything which implements Iterator<char>
to the parse function.
For example, parsing and executing static string:
extern crate mindjuice; use std::io; // parse_instructions will return Err() if there are any unmatched left or right brackets. // However, since we know that this program doesn't have any, using `.unwrap()` is fine. let instructions = mindjuice::parse_instructions("++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.".chars()).unwrap(); let mut buffer = Vec::new(); // First parameter is instructions, second is output buffer, third parameter is something to // provide input, fourth parameter is maximum iterations to take before returning. // Since this hello world program doesn't use the `,` command at all, we can just use // io::empty() as the input. Note that if we do this in a program which takes input, it will // loop indefinitely waiting to get input. mindjuice::execute_brainfuck(instructions, &mut buffer, io::empty(), 30000000u64).unwrap(); assert_eq!(&buffer[..], b"Hello World!\n");
Enums
Error | |
ExecutionTerminationCondition | |
Instruction |
Functions
execute_brainfuck | |
parse_instructions |