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