cl-ast: Unify break, return, and unary expressions

This commit is contained in:
2024-07-30 20:16:07 -05:00
parent 0e545077c6
commit adb0fd229c
8 changed files with 15 additions and 123 deletions

View File

@@ -154,8 +154,6 @@ impl Interpret for ExprKind {
ExprKind::While(v) => v.interpret(env),
ExprKind::If(v) => v.interpret(env),
ExprKind::For(v) => v.interpret(env),
ExprKind::Break(v) => v.interpret(env),
ExprKind::Return(v) => v.interpret(env),
ExprKind::Continue => Err(Error::Continue),
}
}
@@ -330,6 +328,8 @@ impl Interpret for Unary {
e => e?,
};
},
UnaryKind::Break => Err(Error::Break(tail.interpret(env)?)),
UnaryKind::Return => Err(Error::Return(tail.interpret(env)?)),
UnaryKind::Deref => {
let operand = tail.interpret(env)?;
env.call("deref".into(), &[operand])
@@ -579,23 +579,3 @@ impl Interpret for Else {
}
}
}
impl Interpret for Return {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
let Self { body } = self;
Err(Error::Return(
body.as_ref()
.map(|body| body.interpret(env))
.unwrap_or(Ok(ConValue::Empty))?,
))
}
}
impl Interpret for Break {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
let Self { body } = self;
Err(Error::Break(
body.as_ref()
.map(|body| body.interpret(env))
.unwrap_or(Ok(ConValue::Empty))?,
))
}
}