cl-interpret: Give the interpreter a little love

And stop copying strings around.
This commit is contained in:
2024-04-19 10:49:25 -05:00
parent 90a3818ca0
commit 9dc0cc7841
5 changed files with 139 additions and 65 deletions

View File

@@ -6,7 +6,10 @@ use super::{
temp_type_impl::ConValue,
BuiltIn, Callable,
};
use std::io::{stdout, Write};
use std::{
io::{stdout, Write},
rc::Rc,
};
builtins! {
const MISC;
@@ -65,7 +68,7 @@ builtins! {
Ok(match (lhs, rhs) {
(ConValue::Empty, ConValue::Empty) => ConValue::Empty,
(ConValue::Int(a), ConValue::Int(b)) => ConValue::Int(a + b),
(ConValue::String(a), ConValue::String(b)) => ConValue::String(a.to_string() + b),
(ConValue::String(a), ConValue::String(b)) => (a.to_string() + b).into(),
_ => Err(Error::TypeError)?
})
}
@@ -184,6 +187,12 @@ builtins! {
_ => Err(Error::TypeError)?,
})
}
pub fn deref(tail) -> IResult<ConValue> {
Ok(match tail {
ConValue::Ref(v) => Rc::as_ref(v).clone(),
_ => tail.clone(),
})
}
}
/// Turns an argument slice into an array with the (inferred) correct number of elements