added some conversions
This commit is contained in:
parent
f23266f63c
commit
3496fec48e
|
@ -6,6 +6,7 @@ pub use function::Function;
|
|||
pub use pair::DotPair;
|
||||
pub use string::Str;
|
||||
|
||||
use crate::syntax::ast::{Expr, Spanned};
|
||||
use std::{collections::BTreeMap, rc::Rc};
|
||||
|
||||
pub type OrderedF64 = ordered_float::OrderedFloat<f64>;
|
||||
|
@ -23,3 +24,27 @@ pub enum Value<'s> {
|
|||
Macro(Function),
|
||||
Nil,
|
||||
}
|
||||
|
||||
impl<'s> From<Spanned<Expr<'s>>> for Value<'s> {
|
||||
fn from(e: Spanned<Expr<'s>>) -> Self {
|
||||
e.item.into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> From<Expr<'s>> for Value<'s> {
|
||||
fn from(e: Expr<'s>) -> Self {
|
||||
match e {
|
||||
Expr::List(_) => todo!(),
|
||||
Expr::Vector(v) => Self::Vector(Rc::new(v.into_iter().map(Into::into).collect())),
|
||||
Expr::Pair((l, r)) => Self::DotPair(Rc::new(DotPair((*l).into(), (*r).into()))),
|
||||
Expr::Quote(e) => Self::DotPair(Rc::new(DotPair(
|
||||
Self::Symbol("quote".into()),
|
||||
Self::DotPair(Rc::new(DotPair((*e).into(), Self::Nil))),
|
||||
))),
|
||||
Expr::Symbol(s) => Self::Symbol(s.into()),
|
||||
Expr::Keyword(s) => Self::Keyword(s.into()),
|
||||
Expr::Number(n) => Self::Number(n),
|
||||
Expr::String(s) => Self::String(s.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue