From d81fb1f45d25235cd26263bc5203946f6fd8ebc0 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Fri, 30 Apr 2021 00:26:42 -0400 Subject: [PATCH] Code cleanup --- src/calc.rs | 30 +++++------------------------- src/calc/operations.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/calc.rs b/src/calc.rs index cc18c30..61acf75 100644 --- a/src/calc.rs +++ b/src/calc.rs @@ -8,7 +8,7 @@ use constants::{ CalculatorState, RegisterState, }; use errors::{CalculatorError, CalculatorResult}; -use operations::{CalculatorOperation, MacroState}; +use operations::{CalculatorOperation, CalculatorStateChange, MacroState, OpArgs}; use std::collections::{HashSet, VecDeque}; #[derive(PartialEq, Debug)] @@ -17,20 +17,6 @@ enum HistoryMode { Macro, } -#[derive(PartialEq, Debug)] -enum OpArgs { - Macro(MacroState), - Unary(f64), - Binary([f64; 2]), - None, -} - -#[derive(PartialEq, Debug)] -struct CalculatorStateChange { - pop: OpArgs, - push: OpArgs, -} - impl CalculatorStateChange { pub fn is_noop(&self) -> bool { self.push == OpArgs::None && self.pop == OpArgs::None @@ -316,6 +302,9 @@ impl<'a> Calculator<'a> { pub fn get_registers_iter(&self) -> CalculatorRegistersIter { self.registers.iter() } + pub fn get_stack(&self) -> &VecDeque { + &self.stack + } pub fn flush_l(&mut self) -> CalculatorResult { if self.l.is_empty() { @@ -330,6 +319,7 @@ impl<'a> Calculator<'a> { fn within_macro(&self) -> bool { !self.active_macros.is_empty() } + fn push(&mut self, f: f64) -> CalculatorResult<()> { self.direct_state_change(CalculatorStateChange { pop: OpArgs::None, @@ -344,9 +334,6 @@ impl<'a> Calculator<'a> { })?; Ok(f) } - pub fn get_stack(&self) -> &VecDeque { - &self.stack - } pub fn op(&mut self, op: CalculatorOperation) -> CalculatorResult<()> { // Dup is special -- don't actually run it if l needs to be flushed if self.flush_l()? { @@ -529,13 +516,6 @@ impl<'a> Calculator<'a> { OpArgs::Binary([a, b]) => { self.stack_eq(0, *a)?; self.stack_eq(1, *b)?; - // if forward { - // self.stack_eq(0, *a)?; - // self.stack_eq(1, *b)?; - // } else { - // self.stack_eq(0, *a)?; - // self.stack_eq(1, *b)?; - // } self.stack.pop_front(); self.stack.pop_front(); } diff --git a/src/calc/operations.rs b/src/calc/operations.rs index c00d922..0f71cc1 100644 --- a/src/calc/operations.rs +++ b/src/calc/operations.rs @@ -35,3 +35,17 @@ pub enum CalculatorOperation { E, Macro(MacroState), } + +#[derive(PartialEq, Debug)] +pub enum OpArgs { + Macro(MacroState), + Unary(f64), + Binary([f64; 2]), + None, +} + +#[derive(PartialEq, Debug)] +pub struct CalculatorStateChange { + pub pop: OpArgs, + pub push: OpArgs, +}