Enum brainfoamkit_lib::Instruction
source · pub enum Instruction {
IncrementPointer,
DecrementPointer,
IncrementValue,
DecrementValue,
OutputValue,
InputValue,
JumpForward,
JumpBackward,
NoOp,
}
Expand description
All possible instructions that can be understood by the interpreter
This enum is at the heart of the interpreter. This enumerates all eight instructions that a brainfuck program can be composed of in addition to a ninth No-Op instruction
§Examples
use brainfoamkit_lib::Instruction;
let incrptr = Instruction::from_char('>');
let decrptr = Instruction::from_char('<');
assert_eq!(incrptr, Instruction::IncrementPointer);
assert_eq!(decrptr, Instruction::DecrementPointer);
Variants§
IncrementPointer
Instruction to Increment the Pointer
Internal representation of the >
instruction.
DecrementPointer
Instruction to Decrement the Pointer
Internal representation of the <
instruction.
IncrementValue
Instruction to Increment the Value stored in memory location
Internal representation of the +
instruction.
DecrementValue
Instruction to Increment the Value stored in memory location
Internal representation of the -
instruction.
OutputValue
Instruction to Output the currently stored value to the external interface
Internal representation of the .
instruction.
InputValue
Instruction to Input the currently available value at the external interface
Internal representation of the ,
instruction.
JumpForward
Instruction to Start a loop if the current value is non-zero
Internal representation of the [
instruction.
JumpBackward
Instruction to Restart a loop if the current value is non-zero
Internal representation of the ]
instruction.
NoOp
Instruction to do nothing
This does not have a corresponding instruction in BrainFuck
Implementations§
source§impl Instruction
impl Instruction
sourcepub const fn from_char(c: char) -> Self
pub const fn from_char(c: char) -> Self
Convert a char to an Instruction
This method takes in a a single instruction (character and converts that into the instruction.
This ignores any instructions not in the standard alphabet
of BrainFuck
and counts them as No-Ops
The following table and associated github repository show the entire syntax.
Symbol | Effect |
---|---|
+ | Increment the value in the current memory cell |
- | Decrement the value in the current memory cell |
> | Move the memory pointer to the right |
< | Move the memory pointer to the left |
[ | Begin a loop: continue if value in memory cell is nonzero |
] | End a loop: jump back to corresponding [ if value in memory cell is nonzero |
. | Output the ASCII value in the current memory cell |
, | Read a single ASCII character and store it in the current memory cell |
_ | Everything else is a No-Up |
§Argument
c
- A single character from theBrainFuck
list of command characters.
§Examples
use brainfoamkit_lib::Instruction;
let instruction = Instruction::from_char('+');
assert_eq!(instruction, Instruction::IncrementValue)
§Returns
The appropriate variant of the Instruction
enum
§Notes
This version of Instruction
treats every character other than the
eight specific characters as NoOp
s
Trait Implementations§
source§impl Clone for Instruction
impl Clone for Instruction
source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Instruction
impl Debug for Instruction
source§impl Display for Instruction
impl Display for Instruction
Convert an instruction to a String
This method converts a given instruction to a human-readable instruction.
§Examples
use brainfoamkit_lib::{
Instruction,
Nybble,
};
let instruction = Instruction::from_char('>');
assert_eq!(instruction.to_string(), "INCPTR");
§Returns
The instruction as a string.
§See Also
from_char()
: Creates a new Instruction from a string.
source§impl PartialEq for Instruction
impl PartialEq for Instruction
source§fn eq(&self, other: &Instruction) -> bool
fn eq(&self, other: &Instruction) -> bool
self
and other
values to be equal, and is used
by ==
.impl Copy for Instruction
impl Eq for Instruction
impl StructuralPartialEq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)