Change EvaluatedValue::String to Rc<str>

master
Nick Krichevsky 2024-05-21 22:21:28 -04:00
parent 0b4d4d6d21
commit 32f6628328
2 changed files with 7 additions and 7 deletions

View File

@ -1,5 +1,6 @@
use std::{
fmt::{self, Display, Formatter},
rc::Rc,
string::ParseError,
};
@ -24,7 +25,7 @@ impl From<&LiteralValue> for EvaluatedValue {
LiteralValue::False => EvaluatedValue::Boolean(false),
LiteralValue::Nil => EvaluatedValue::Nil,
LiteralValue::Number(number) => EvaluatedValue::Number(*number),
LiteralValue::String(string) => EvaluatedValue::String(string.clone()),
LiteralValue::String(string) => EvaluatedValue::String(string.clone().into()),
}
}
}
@ -178,7 +179,6 @@ impl ExprVisitor<Result<EvaluatedValue, ScriptError>> for InterpreterRunner<'_>
location: String::new(),
line: name.line(),
})
// TODO: AAAAA this cloning sucks
.cloned()
}
}
@ -241,7 +241,8 @@ fn evaluate_addition(
}
(EvaluatedValue::String(left_value), EvaluatedValue::String(right_value)) => {
Ok(EvaluatedValue::String(left_value + right_value.as_ref()))
let concatted = left_value.to_string() + right_value.as_ref();
Ok(EvaluatedValue::String(concatted.into()))
}
// TODO: we could improve this error (and others) to include the types

View File

@ -1,10 +1,9 @@
use thiserror::Error;
use std::rc::Rc;
#[derive(Debug, Clone, PartialEq)]
pub enum EvaluatedValue {
Number(f64),
String(String),
String(Rc<str>),
Boolean(bool),
Nil,
}
@ -35,7 +34,7 @@ impl_value_try_from!(
);
impl_value_try_from!(
String,
Rc<str>,
EvaluatedValue::String(s) => s,
"value is not of type string"
);