cl-interpret: remove Loc from error type

This allows removal of intermediate expression metadata from the AST
This commit is contained in:
John 2024-04-13 02:54:02 -05:00
parent 21c9909f0c
commit 3b0190b389
2 changed files with 10 additions and 11 deletions

View File

@ -141,7 +141,7 @@ impl Interpret for Assign {
let head = match &head.kind { let head = match &head.kind {
ExprKind::Path(Path { parts, .. }) if parts.len() == 1 => { ExprKind::Path(Path { parts, .. }) if parts.len() == 1 => {
match parts.last().expect("parts should not be empty") { match parts.last().expect("parts should not be empty") {
PathPart::SuperKw => Err(Error::NotAssignable(head.extents.head))?, PathPart::SuperKw => Err(Error::NotAssignable)?,
PathPart::SelfKw => todo!("Assignment to `self`"), PathPart::SelfKw => todo!("Assignment to `self`"),
PathPart::Ident(Identifier(s)) => s, PathPart::Ident(Identifier(s)) => s,
} }
@ -153,7 +153,7 @@ impl Interpret for Assign {
ExprKind::Empty | ExprKind::Group(_) | ExprKind::Tuple(_) => { ExprKind::Empty | ExprKind::Group(_) | ExprKind::Tuple(_) => {
todo!("Pattern Destructuring?") todo!("Pattern Destructuring?")
} }
_ => Err(Error::NotAssignable(head.extents.head))?, _ => Err(Error::NotAssignable)?,
}; };
// Get the initializer and the tail // Get the initializer and the tail
let init = tail.interpret(env)?; let init = tail.interpret(env)?;

View File

@ -522,7 +522,6 @@ pub mod error {
//! The [Error] type represents any error thrown by the [Environment](super::Environment) //! The [Error] type represents any error thrown by the [Environment](super::Environment)
use super::temp_type_impl::ConValue; use super::temp_type_impl::ConValue;
use cl_structures::span::Loc;
pub type IResult<T> = Result<T, Error>; pub type IResult<T> = Result<T, Error>;
@ -546,12 +545,12 @@ pub mod error {
TypeError, TypeError,
/// In clause of For loop didn't yield a Range /// In clause of For loop didn't yield a Range
NotIterable, NotIterable,
/// A value at this [location](struct@Loc) can't be indexed /// A value could not be indexed
NotIndexable(Loc), NotIndexable,
/// An array index went out of bounds /// An array index went out of bounds
OobIndex(usize, usize), OobIndex(usize, usize),
/// An expression at this [location](struct@Loc)ation is not assignable /// An expression is not assignable
NotAssignable(Loc), NotAssignable,
/// A name was not defined in scope before being used /// A name was not defined in scope before being used
NotDefined(String), NotDefined(String),
/// A name was defined but not initialized /// A name was defined but not initialized
@ -578,14 +577,14 @@ pub mod error {
Error::ScopeExit => "Exited the last scope. This is a logic bug.".fmt(f), Error::ScopeExit => "Exited the last scope. This is a logic bug.".fmt(f),
Error::TypeError => "Incompatible types".fmt(f), Error::TypeError => "Incompatible types".fmt(f),
Error::NotIterable => "`in` clause of `for` loop did not yield an iterable".fmt(f), Error::NotIterable => "`in` clause of `for` loop did not yield an iterable".fmt(f),
Error::NotIndexable(location) => { Error::NotIndexable => {
write!(f, "{location} expression cannot be indexed") write!(f, "expression cannot be indexed")
} }
Error::OobIndex(idx, len) => { Error::OobIndex(idx, len) => {
write!(f, "Index out of bounds: index was {idx}. but len is {len}") write!(f, "Index out of bounds: index was {idx}. but len is {len}")
} }
Error::NotAssignable(location) => { Error::NotAssignable => {
write!(f, "{location} expression is not assignable") write!(f, "expression is not assignable")
} }
Error::NotDefined(value) => { Error::NotDefined(value) => {
write!(f, "{value} not bound. Did you mean `let {value};`?") write!(f, "{value} not bound. Did you mean `let {value};`?")