Enum brainfuck::Instruction
[−]
[src]
pub enum Instruction { IncPtr, DecPtr, IncVal, DecVal, Output, Input, SkipForward(usize), SkipBackward(usize), }
An executable instruction in the language.
There are only 8 instructions in the brainfuck language. A pair for
incrementing and decrementing the pointer, and values on the tape.
Two instructions for reading and writing a char from STDIN
and
STDOUT
respectivly. And finally the only control flow
instructions for skipping ahead and skipping back. More information
on control flow below.
Control Flow
Control flow in brainfuck is achieved by skipping forward, and
backward. The [
instruction skips past it's matching ]
instruction, and the ]
instruction skips back to it's
matching [
instruction. Matching brackets follow the intuitive
notion, for example [+[+]+]
has to pairs of matching brackets.
Skips are conditional based on the value of the cell behind the
pointer. A forward skip only happens when the value of the cell
is 0, and the backward skip only happens when the value of the
cell is not 0. This allows for a relatively simple syntax for
decrementing iteration. For example +++[- > operate on cell 2 < ]>.
is the boilerplate for a loop that operates 3 times.
Variants
IncPtr
Increment the pointer moving it up on the tape.
DecPtr
Decrement the pointer moving it down on the tape.
IncVal
Increment the value at the pointer on the tape.
DecVal
Decrement the value at the pointer on the tape.
Output
Write the value at the pointer as a char
to STDOUT
. This
instruction can fail if writing to the underlying writer fails.
Input
Read from STDIN
as a char
to value at the pointer. This
instruction can fail if reading from the underlying reader
fails or has no more data.
SkipForward(usize)
Skip forward if the value at the pointer is 0
. For more
information see the section on control flow above.
SkipBackward(usize)
Skip backward if the value at the pointer is not 0
.
For more information see the section on control flow above.
Trait Implementations
impl Copy for Instruction
[src]
impl Clone for Instruction
[src]
fn clone(&self) -> Instruction
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for Instruction
[src]
impl PartialEq for Instruction
[src]
fn eq(&self, __arg_0: &Instruction) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Instruction) -> bool
This method tests for !=
.
impl Eq for Instruction
[src]
impl Hash for Instruction
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more