Get operations working with the calculator interface

This commit is contained in:
Austen Adler 2021-06-01 22:01:07 -04:00
parent e05b0726f1
commit 53891274f1
3 changed files with 1543 additions and 1427 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3,61 +3,64 @@ use serde::{Deserialize, Serialize};
#[derive(PartialEq, Debug, Serialize, Deserialize)] #[derive(PartialEq, Debug, Serialize, Deserialize)]
pub enum ArithmeticOperation { pub enum ArithmeticOperation {
Add, Add,
Subtract, Subtract,
Multiply, Multiply,
Divide, Divide,
Negate, Negate,
AbsoluteValue, AbsoluteValue,
Inverse, Inverse,
Modulo, Modulo,
IntegerDivide, IntegerDivide,
Sin, Sin,
Cos, Cos,
Tan, Tan,
ASin, ASin,
ACos, ACos,
ATan, ATan,
Sqrt, Sqrt,
Pow, Pow,
Log, Log,
Ln, Ln,
} }
/// Operations that can be sent to the calculator such as +, -, or undo /// Operations that can be sent to the calculator such as +, -, or undo
#[derive(PartialEq, Debug, Serialize, Deserialize)] #[derive(PartialEq, Debug, Serialize, Deserialize)]
pub enum CalculatorOperation { pub enum CalculatorOperation {
ArithmeticOperation(ArithmeticOperation), ArithmeticOperation(ArithmeticOperation),
Undo, BuildVector,
Redo, Undo,
Drop, Redo,
Dup, Drop,
Swap, Dup,
Macro(MacroState), Swap,
Macro(MacroState),
} }
/// Macro bundary; defined by the start or end of a macro invocation /// Macro bundary; defined by the start or end of a macro invocation
#[derive(PartialEq, Debug, Serialize, Deserialize)] #[derive(PartialEq, Debug, Serialize, Deserialize)]
pub enum MacroState { pub enum MacroState {
Start, Start,
End, End,
} }
/// Arguments for a given operation /// Arguments for a given operation
#[derive(PartialEq, Debug, Serialize, Deserialize)] #[derive(PartialEq, Debug, Serialize, Deserialize)]
pub enum OpArgs { pub enum OpArgs {
/// This is a macro start and end noop /// This is a macro start and end noop
Macro(MacroState), Macro(MacroState),
/// Operation takes 1 argument, ex: sqrt or negate /// Operation takes 1 argument, ex: sqrt or negate
Unary(Entry), Unary(Entry),
/// Operation takes 2 arguments, ex: + or - /// Operation takes 2 arguments, ex: + or -
Binary([Entry; 2]), Binary([Entry; 2]),
/// Operation takes no arguments, ex: push /// Some variable number of changes
None, Variable(Vec<Entry>),
/// Operation takes no arguments, ex: push
None,
} }
/// Record of what to pop and push. Used for undo and redo buffers /// Record of what to pop and push. Used for undo and redo buffers
#[derive(PartialEq, Debug, Serialize, Deserialize)] #[derive(PartialEq, Debug, Serialize, Deserialize)]
pub struct CalculatorStateChange { pub struct CalculatorStateChange {
pub pop: OpArgs, pub pop: OpArgs,
pub push: OpArgs, pub push: OpArgs,
} }