diff --git a/src/eval.rs b/src/eval.rs index 7ae02ed..22a6963 100644 --- a/src/eval.rs +++ b/src/eval.rs @@ -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> 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 diff --git a/src/eval/value.rs b/src/eval/value.rs index 5c6a0f1..0c57de3 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -1,10 +1,9 @@ -use thiserror::Error; +use std::rc::Rc; #[derive(Debug, Clone, PartialEq)] - pub enum EvaluatedValue { Number(f64), - String(String), + String(Rc), Boolean(bool), Nil, } @@ -35,7 +34,7 @@ impl_value_try_from!( ); impl_value_try_from!( - String, + Rc, EvaluatedValue::String(s) => s, "value is not of type string" );