aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-02-01 19:50:32 -0330
committerSam Anthony <sam@samanthony.xyz>2023-02-01 19:50:32 -0330
commit6e6e7581b4c8575dd379f20a786108ce4edcd9c8 (patch)
tree5b1ecf5b07d62e25648a23dd1a2d43260b2ff365 /src/lib.rs
parentdfbaad1f881be6ca3e93e09da360652ba5023b7d (diff)
downloadpfc-6e6e7581b4c8575dd379f20a786108ce4edcd9c8.zip
refactor
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e08796d..79210fc 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,40 @@
+mod input;
pub mod ui;
+#[derive(Default)]
+pub struct Calculator {
+ stack: Vec<f64>,
+ input_buffer: String,
+}
+
+impl Calculator {
+ fn push_buffer_to_stack(&mut self) {
+ self.stack.push(self.input_buffer.parse::<f64>().unwrap());
+ self.input_buffer = String::new();
+ }
+
+ fn perform_operation(&mut self, op: Operator) {
+ let rhs = match self.stack.pop() {
+ Some(f) => f,
+ None => {
+ return;
+ }
+ };
+ let lhs = match self.stack.pop() {
+ Some(f) => f,
+ None => {
+ return;
+ }
+ };
+ match op {
+ Operator::Add => self.stack.push(lhs + rhs),
+ Operator::Sub => self.stack.push(lhs - rhs),
+ Operator::Mul => self.stack.push(lhs * rhs),
+ Operator::Div => self.stack.push(lhs / rhs),
+ }
+ }
+}
+
pub enum Operator {
Add,
Sub,
@@ -20,3 +55,8 @@ impl Operator {
}
pub struct ParseOperatorError(char);
+
+pub enum Signal {
+ None,
+ Exit,
+}