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

This reverts commit adb0fd229c.
This commit is contained in:
2024-07-30 22:31:39 -05:00
parent 5e7ba6de24
commit 388a69948e
8 changed files with 123 additions and 15 deletions

View File

@@ -154,6 +154,8 @@ 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),
}
}
@@ -328,8 +330,6 @@ 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,3 +579,23 @@ 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))?,
))
}
}