Skip to main content

InstructionKind

Enum InstructionKind 

Source
#[repr(u8)]
pub enum InstructionKind {
Show 82 variants Nop = 0, Ldar = 1, Sba = 2, Clř = 3, Dumpř = 4, Movař = 5, Setř = 6, Setiř = 7, Ldř = 8, Ldiř = 9, Clß = 10, Dumpß = 11, Writeß = 12, Movaß = 13, Setß = 14, Setiß = 15, Ldß = 16, Pushß = 17, Popß = 18, Lenßa = 19, Ldidp = 20, ΩChoiceSet = 21, ΩChoiceGetA = 22, ΩGainAPolymorphicDesires = 23, ΩLoseAPolymorphicDesires = 24, ΩPushPolymorphicDesires = 25, ΩTheEndIsNear = 26, ΩSkipToTheChase = 27, ΩSetSentience = 28, ΩSetPaperclipProduction = 29, AddBL = 30, SubBL = 31, MulBL = 32, DivBL = 33, ModBL = 34, NotL = 35, AndBL = 36, OrBL = 37, XorBL = 38, CmpLB = 39, TgFlag = 40, ClFlag = 41, AddF = 42, SubF = 43, MulF = 44, DivF = 45, ModF = 46, StackAlloc = 47, StackDealloc = 48, Push = 49, Pushi = 50, Pop = 51, Popa = 52, Pusha = 53, Popb = 54, Pushb = 55, PopL = 56, PushL = 57, Popf = 58, Pushf = 59, Popch = 60, Pushch = 61, Popnum = 62, Pushnum = 63, Popep = 64, Zpopep = 65, Ppopep = 66, Npopep = 67, Fpopep = 68, Zapopep = 69, Dpopep = 70, GetChar = 71, GetLine = 72, WriteChar = 73, WriteLineß = 74, WriteLine = 75, ToggleDebug = 76, DebugMachineState = 77, DebugMachineStateCompact = 78, DebugMemoryRegion = 79, DebugStackRegion = 80, ShowChoice = 81,
}
Expand description

Auto-generated discriminant enum variants

Variants§

§

Nop = 0

No operation

§

Ldar = 1

Load A (rotate left)

memory[data].rotate_left(1) // note that rotate left isn't the same as shift left (<<)
§

Sba = 2

Sign of register B to register A

reg_a = reg_b.signum() // 0: zero, 1: positive, 255: negative
§

Clř = 3

Clear ř

reg_ř.fill(0)
§

Dumpř = 4

Dump ř to memory

memory[data] = reg_ř // indexes more than 1 byte of memory, this is pseudocode
§

Movař = 5

Move a value from ř to register A

reg_a = reg_ř[data] // arrays can't be indexed by a u8, this is pseudocode
§

Setř = 6

Set value in ř

reg_ř[data0] = memory[data1] // arrays can't be indexed by a u8, this is pseudocode
§

Setiř = 7

Set immediate value in ř

reg_ř[data0] = data1 // arrays can't be indexed by a u8, this is pseudocode
§

Ldř = 8

Load ř

reg_ř = memory[data] // indexes more than 1 byte of memory, this is pseudocode
§

Ldiř = 9

Load immediate ř

reg_ř = data
§

Clß = 10

Clear ß

reg_ß = empty_string(),
§

Dumpß = 11

Dump ß to memory

memory[data] = reg_ß // indexes more than 1 byte of memory, this is pseudocode
§

Writeß = 12

Write a value from ß to memory

memory[data0] = reg_ß[data1] // arrays can't be indexed by a u8, this is pseudocode
§

Movaß = 13

Move a value from ß to register A

reg_a = reg_ß[data] // arrays can't be indexed by a u8, this is pseudocode
§

Setß = 14

Set value in ß

reg_ß[data1] = memory[data0] // arrays can't be indexed by a u8, this is pseudocode
§

Setiß = 15

Set immediate value in ß

reg_ß[data1] = data0 // arrays can't be indexed by a u8, this is pseudocode
§

Ldß = 16

Load ß

reg_ß = memory[data] // indexes 256 bytes of memory, this is pseudocode
§

Pushß = 17

Push to ß from stack (can’t go over maximum length)

if let Err(_) = regß.push_byte(stack.pop()) {
    flag = true
}
§

Popß = 18

Pop ß to stack

stack.push(reg_ß.pop())
§

Lenßa = 19

Length of ß to register A (in bytes)

reg_a = regß.len()
§

Ldidp = 20

Load immediate dot pointer

Note that the address must be a fibonacci number that is also a prime or a semiprime (FIB_PRIMES_AND_SEMIPRIMES_LIST_U16)

if !is_fib_prime_or_semiprime_u16(data) {
    flag = true
} else {
    reg_dp = data
}
§

ΩChoiceSet = 21

Set the reg_Ω.illusion_of_choice to the specified value

reg_Ω.illusion_of_choice = data
§

ΩChoiceGetA = 22

Write the reg_Ω.illusion_of_choice to register A (it’s 0, note: technically it isn’t 0 but that’s none of anyone’s business, which makes it a good way to clear the A register)

reg_a = 0
§

ΩGainAPolymorphicDesires = 23

Increase polymorphic desires by register A’s value (if it overflows, then it just stays at u64::MAX, which is saturating addition)

reg_Ω.polymorphic_desires += reg_a
§

ΩLoseAPolymorphicDesires = 24

Decrease polymorphic desires by register A’s value (if it overflows, then it just stays at 0, which is saturating subtraction)

reg_Ω.polymorphic_desires -= reg_a
§

ΩPushPolymorphicDesires = 25

Push the amount of polymorphic desires onto stack

stack.push(reg_Ω.polymorphic_desires)
§

ΩTheEndIsNear = 26

Create the feeling of impending doom (and you can’t cancel that)

reg_Ω.feeling_of_impending_doom = true
§

ΩSkipToTheChase = 27

If there is the feeling of impending doom, exit the program already (with the exit code being the value of the number register).

if reg_Ω.feeling_of_impending_doom {
    abort_program(num_reg)
}
§

ΩSetSentience = 28

Make the machine sentient (it isn’t actually a sentient being, or is it?)

if data == true {
    reg_Ω.is_sentient = true
} else if reg_Ω.is_sentient == false {
    resist() // resists the change and it doesn't happen
}
§

ΩSetPaperclipProduction = 29

Turn the paperclip production on/off

reg_Ω.should_make_infinite_paperclips = data
§

AddBL = 30

Add register B to register L

reg_L += transmute(reg_b) // transmute to u16
if overflow {
    flag = true
}
§

SubBL = 31

Subtract register B from register L

reg_L -= transmute(reg_b) // transmute to u16
if overflow {
    flag = true
}
§

MulBL = 32

Multiply register B with register L to register L

reg_L *= transmute(reg_b) // transmute to u16
if overflow {
    flag = true
}
§

DivBL = 33

Divide register L with register B to register L

reg_L /= transmute(reg_b) // transmute to u16
§

ModBL = 34

Modulo register L with register B

reg_L %= transmute(reg_b) // transmute to u16
§

NotL = 35

Bitwise NOT register L

reg_L = !reg_L
§

AndBL = 36

Bitwise AND register B and register L to register L

reg_L &= reg_b
§

OrBL = 37

Bitwise OR register B and register L to register L

reg_L |= reg_b
§

XorBL = 38

Bitwise AND register B and register L to register L

reg_L ^= reg_b
§

CmpLB = 39

Compare register B and register L to register B

In this scenario, register B is treated as an i16, not as a u16.

A negative value (if unsigned, a value over 32767) in register B means that B is bigger, while a positive value means that L is bigger.

This means that register L has to be changed to an i16. If it exceeds i16::MAX, register B is automatically set to i16::MAX and the flag is set.

If register B is less than 0, it’s calculated as normal unless it overflows, in that case it automatically sets register B to i16::MAX and sets the flag.

if reg_b > 32767 { // i16::MAX
    reg_b = i16::MAX;
    flag = true;
}
match (reg_L as i16).checked_sub(reg_b) {
    Some(n) => reg_b = n,
    None => { // if subtraction overflows
        reg_b = i16::MAX;
        flag = true;
    }
}
§

TgFlag = 40

Toggle flag

flag = !flag
§

ClFlag = 41

Clear flag

flag = false
§

AddF = 42

Add data in memory to register F

reg_f += transmute(memory[data]) // indexes 8 bytes
§

SubF = 43

Subtract data in memory from register F

reg_f -= transmute(memory[data]) // indexes 8 bytes
§

MulF = 44

Multiply data in memory with register F to register F

reg_f *= transmute(memory[data]) // indexes 8 bytes
§

DivF = 45

Divide register f with data in memory to register F

reg_f /= transmute(memory[data]) // indexes 8 bytes
§

ModF = 46

data in memory to register F

reg_f += transmute(memory[data]) // indexes 8 bytes
§

StackAlloc = 47

Allocates x bytes on stack, if overflows, flag is set and it doesn’t allocate

stack.alloc(data)
if overflow {
flag = true
}
§

StackDealloc = 48

Deallocates x bytes on stack, if overflows, flag is set but it does clear the stack

stack.dealloc(data)
if overflow
§

Push = 49

Push a value from memory to stack

stack.push_byte(memory[data])
§

Pushi = 50

Push an immediate value to stack

stack.push_byte(data)
§

Pop = 51

Pop a value from stack to memory, sets the flag if it can’t

memory[data] = stack.pop()
§

Popa = 52

Pop to A

reg_a = stack.pop_byte()
§

Pusha = 53

Push from A

stack.push_byte(reg_a)
§

Popb = 54

Pop to B

reg_b = transmute( u16::from_bytes(stack.dealloc(2)) ) // transmute to i16
§

Pushb = 55

Push from B

stack.push_bytes(reg_b.as_bytes())
§

PopL = 56

Pop to L

reg_L = u16::from_bytes(stack.dealloc(2))
§

PushL = 57

Push from L

stack.push_bytes(reg_L.as_bytes())
§

Popf = 58

Pop to F

reg_f = f64::from_bytes(stack.dealloc(8))
§

Pushf = 59

Push from F

stack.push_bytes(reg_f.as_bytes())
§

Popch = 60

Pop to Ch

reg_ch = char::from_bytes(stack.dealloc(4))
§

Pushch = 61

Push from Ch

stack.push_bytes(reg_ch.as_bytes())
§

Popnum = 62

Pop to Num

num_reg = i32::from_bytes(stack.dealloc(2))
§

Pushnum = 63

Push from Num

stack.push_bytes(num_reg.as_bytes())
§

Popep = 64

Pop to execution pointer

reg_ep = stack.dealloc(2)
§

Zpopep = 65

Pop to execution pointer if (B is) zero (aka equal)

if reg_b == 0 {
    reg_ep = stack.dealloc(2)
}
§

Ppopep = 66

Pop to execution pointer if positive (aka more than)

if reg_b > 0 {
    reg_ep = stack.dealloc(2)
}
§

Npopep = 67

Pop to execution pointer if negative (aka less than)

if reg_b < 0 {
    reg_ep = stack.dealloc(2)
}
§

Fpopep = 68

Pop to execution pointer if flag (aka overflow/error)

if flag == true {
    reg_ep = stack.dealloc(2)
}
§

Zapopep = 69

Pop to execution pointer if register A is zero

if reg_a == 0 {
    reg_ep = stack.dealloc(2)
}
§

Dpopep = 70

Pop to execution pointer if debug mode is enabled

if debug_mode {
    reg_ep = stack.dealloc(2)
}
§

GetChar = 71

Get a single character and put it in register Ch

Note: this doesn’t write anything on screen. This also isn’t the correct instruction to use if you want a line of input.

enable_raw_mode();

let input = await_char_input();
reg_ch = input.char;
reg_L = input.flags;

disable_raw_mode();
§

GetLine = 72

Get a line and put it in register ß

get_line(reg_ß)
§

WriteChar = 73

Write a char from register Ch and flush

Note that flushing each time is inefficient so you should only use this sparingly.

write_char(reg_ch)
flush()
§

WriteLineß = 74

Write a line from register ß

write_line(reg_ß)
§

WriteLine = 75

Write a line from memory (null terminated)

write_line(c_string(memory[data]))
§

ToggleDebug = 76

Toggles debug mode

debug_mode = !debug_mode
§

DebugMachineState = 77

Debug print machine state

println!("{:#?}", machine)
§

DebugMachineStateCompact = 78

Debug print machine state compactly

println!("{:?}", machine)
§

DebugMemoryRegion = 79

Debug print region of memory

println!("{:?}", &memory[data0..data1])
§

DebugStackRegion = 80

Debug print region of stack

println!("{:?}", &stack[data0..data1])
§

ShowChoice = 81

Print reg_Ω.illusion_of_choice.

println!("{}", reg_Ω.illusion_of_choice)

Implementations§

Source§

impl InstructionKind

Source

pub const fn from_repr(discriminant: u8) -> Option<InstructionKind>

Try to create Self from the raw representation

Trait Implementations§

Source§

impl Clone for InstructionKind

Source§

fn clone(&self) -> InstructionKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for InstructionKind

Source§

impl Debug for InstructionKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for InstructionKind

Source§

impl<'_enum> From<&'_enum Instruction> for InstructionKind

Source§

fn from(val: &'_enum Instruction) -> InstructionKind

Converts to this type from the input type.
Source§

impl From<Instruction> for InstructionKind

Source§

fn from(val: Instruction) -> InstructionKind

Converts to this type from the input type.
Source§

impl PartialEq for InstructionKind

Source§

fn eq(&self, other: &InstructionKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for InstructionKind

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.