Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions stack-core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ impl Engine {
}
Ok(context)
} else {
context.stack_push(Expr {
kind: ExprKind::Error(Error::new("unknown function".into())),
info: None,
})?;
context.stack_push(
ExprKind::Error(Error::new("unknown function".into())).into(),
)?;

Ok(context)
}
Expand Down
34 changes: 30 additions & 4 deletions stack-core/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ pub struct Expr {
pub info: Option<ExprInfo>,
}

impl From<ExprKind> for Expr {
fn from(value: ExprKind) -> Self {
Self {
info: None,
kind: value,
}
}
}

impl PartialEq for Expr {
#[inline]
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -108,6 +117,26 @@ impl ExprKind {
x => x,
}
}

pub fn type_of(&self) -> &str {
match self {
ExprKind::Nil => "nil",
ExprKind::Error(_) => "error",

ExprKind::Boolean(_) => "boolean",
ExprKind::Integer(_) => "integer",
ExprKind::Float(_) => "float",
ExprKind::String(_) => "string",

ExprKind::Symbol(_) => "symbol",

ExprKind::Lazy(_) => "lazy",
ExprKind::List(_) => "list",
ExprKind::Record(_) => "record",

ExprKind::Fn(_) => "function",
}
}
}

impl PartialEq for ExprKind {
Expand Down Expand Up @@ -270,10 +299,7 @@ impl fmt::Display for ExprKind {
.chain(core::iter::repeat(", "))
.zip(x.iter())
.try_for_each(|(sep, (key, value))| {
let key = Expr {
info: None,
kind: ExprKind::Symbol(*key),
};
let key: Expr = ExprKind::Symbol(*key).into();
write!(f, "{sep}{key:#}: {value:#}")
})?;

Expand Down
Loading