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,
|
NotEnoughStackEntries,
|
||||||
/// Requested type does not match target type
|
/// Requested type does not match target type
|
||||||
TypeMismatch,
|
TypeMismatch,
|
||||||
|
/// Dimensions must match
|
||||||
|
DimensionMismatch,
|
||||||
/// Thrown when an undo or redo cannot be performed
|
/// Thrown when an undo or redo cannot be performed
|
||||||
CorruptStateChange(String),
|
CorruptStateChange(String),
|
||||||
/// Cannot undo or redo
|
/// Cannot undo or redo
|
||||||
@ -47,6 +49,7 @@ impl fmt::Display for CalculatorError {
|
|||||||
Self::ArithmeticError => write!(f, "Arithmetic Error"),
|
Self::ArithmeticError => write!(f, "Arithmetic Error"),
|
||||||
Self::NotEnoughStackEntries => write!(f, "Not enough items in the stack"),
|
Self::NotEnoughStackEntries => write!(f, "Not enough items in the stack"),
|
||||||
Self::TypeMismatch => write!(f, "Type mismatch"),
|
Self::TypeMismatch => write!(f, "Type mismatch"),
|
||||||
|
Self::DimensionMismatch => write!(f, "Dimension mismatch"),
|
||||||
Self::CorruptStateChange(msg) => {
|
Self::CorruptStateChange(msg) => {
|
||||||
write!(f, "Corrupt state change: {}", msg)
|
write!(f, "Corrupt state change: {}", msg)
|
||||||
}
|
}
|
||||||
|
@ -3,64 +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),
|
||||||
BuildVector,
|
BuildVector,
|
||||||
Undo,
|
Undo,
|
||||||
Redo,
|
Redo,
|
||||||
Drop,
|
Drop,
|
||||||
Dup,
|
Dup,
|
||||||
Swap,
|
Swap,
|
||||||
Macro(MacroState),
|
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]),
|
||||||
/// Some variable number of changes
|
/// Some variable number of changes
|
||||||
Variable(Vec<Entry>),
|
Variable(Vec<Entry>),
|
||||||
/// Operation takes no arguments, ex: push
|
/// Operation takes no arguments, ex: push
|
||||||
None,
|
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,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user