conlang: Single-expression functions
This commit is contained in:
@@ -146,7 +146,7 @@ pub struct Function {
|
||||
pub name: Sym,
|
||||
pub sign: TyFn,
|
||||
pub bind: Vec<Param>,
|
||||
pub body: Option<Block>,
|
||||
pub body: Option<Expr>,
|
||||
}
|
||||
|
||||
/// A single parameter for a [Function]
|
||||
|
||||
@@ -107,7 +107,7 @@ pub trait Fold {
|
||||
name: self.fold_sym(name),
|
||||
sign: self.fold_ty_fn(sign),
|
||||
bind: bind.into_iter().map(|p| self.fold_param(p)).collect(),
|
||||
body: body.map(|b| self.fold_block(b)),
|
||||
body: body.map(|b| self.fold_expr(b)),
|
||||
}
|
||||
}
|
||||
fn fold_param(&mut self, p: Param) -> Param {
|
||||
|
||||
@@ -85,7 +85,7 @@ pub trait Visit<'a>: Sized {
|
||||
self.visit_ty_fn(sign);
|
||||
bind.iter().for_each(|p| self.visit_param(p));
|
||||
if let Some(b) = body {
|
||||
self.visit_block(b)
|
||||
self.visit_expr(b)
|
||||
}
|
||||
}
|
||||
fn visit_param(&mut self, p: &'a Param) {
|
||||
|
||||
@@ -71,7 +71,7 @@ impl<'a> Visit<'a> for CollectUpvars<'_> {
|
||||
self.bind_name(name);
|
||||
}
|
||||
if let Some(body) = body {
|
||||
self.visit_block(body);
|
||||
self.visit_expr(body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -459,12 +459,11 @@ impl Parse<'_> for Function {
|
||||
sign,
|
||||
bind,
|
||||
body: match p.peek_kind(P)? {
|
||||
TokenKind::LCurly => Some(Block::parse(p)?),
|
||||
TokenKind::Semi => {
|
||||
p.consume_peeked();
|
||||
None
|
||||
}
|
||||
t => Err(p.error(Unexpected(t), P))?,
|
||||
_ => Some(Expr::parse(p)?),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
|
||||
self.visit_ty_fn(sign);
|
||||
bind.iter().for_each(|p| self.visit_param(p));
|
||||
if let Some(b) = body {
|
||||
self.visit_block(b)
|
||||
self.visit_expr(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user