diff options
Diffstat (limited to 'src/stack.rs')
-rw-r--r-- | src/stack.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/stack.rs b/src/stack.rs index 14e1799..2862b72 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -50,3 +50,39 @@ impl Stack { self.sp = 0; } } + +use std::ops::Not; + +impl Stack { + pub fn inc_u8(&mut self) { + let sp = self.sp.wrapping_sub(1) as usize; + self.mem[sp] = self.mem[sp].wrapping_add(1); + } + + pub fn dec_u8(&mut self) { + let sp = self.sp.wrapping_sub(1) as usize; + self.mem[sp] = self.mem[sp].wrapping_sub(1); + } + + pub fn not_u8(&mut self) { + let sp = self.sp.wrapping_sub(1) as usize; + self.mem[sp] = self.mem[sp].not(); + } + + pub fn not_u16(&mut self) { + let sp = self.sp.wrapping_sub(1) as usize; + self.mem[sp] = self.mem[sp].not(); + let sp = self.sp.wrapping_sub(2) as usize; + self.mem[sp] = self.mem[sp].not(); + } + + pub fn tal_u8(&mut self) { + let sp = self.sp.wrapping_sub(1) as usize; + self.mem[sp] = self.mem[sp].count_ones() as u8; + } + + pub fn rev_u8(&mut self) { + let sp = self.sp.wrapping_sub(1) as usize; + self.mem[sp] = self.mem[sp].reverse_bits(); + } +} |