Get vectors working
This commit is contained in:
parent
53891274f1
commit
0405d25998
1440
src/calc.rs
1440
src/calc.rs
File diff suppressed because it is too large
Load Diff
1522
src/calc/entries.rs
1522
src/calc/entries.rs
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,8 @@ pub enum CalculatorError {
|
||||
NotEnoughStackEntries,
|
||||
/// Requested type does not match target type
|
||||
TypeMismatch,
|
||||
/// Dimensions must match
|
||||
DimensionMismatch,
|
||||
/// Thrown when an undo or redo cannot be performed
|
||||
CorruptStateChange(String),
|
||||
/// Cannot undo or redo
|
||||
@ -47,6 +49,7 @@ impl fmt::Display for CalculatorError {
|
||||
Self::ArithmeticError => write!(f, "Arithmetic Error"),
|
||||
Self::NotEnoughStackEntries => write!(f, "Not enough items in the stack"),
|
||||
Self::TypeMismatch => write!(f, "Type mismatch"),
|
||||
Self::DimensionMismatch => write!(f, "Dimension mismatch"),
|
||||
Self::CorruptStateChange(msg) => {
|
||||
write!(f, "Corrupt state change: {}", msg)
|
||||
}
|
||||
|
@ -3,64 +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),
|
||||
BuildVector,
|
||||
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]),
|
||||
/// Some variable number of changes
|
||||
Variable(Vec<Entry>),
|
||||
/// 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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user