Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant committed Dec 27, 2024
1 parent e6dfe23 commit 78f9761
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/ast/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Expression {
Self::Begin(body) => body.tail_eval(env, cont).await,
Self::Var(var) => Ok(ValuesOrPreparedCall::Values(vec![var
.fetch(env)
.map_err(|ident| RuntimeError::undefined_variable(ident))?])),
.map_err(RuntimeError::undefined_variable)?])),
}
})
}
Expand Down Expand Up @@ -336,7 +336,7 @@ impl SyntaxCase {
Expression::parse(transformed, &expansion_env, cont)
.await
.expect("fixme")
.eval(&env, cont)
.eval(env, cont)
.await
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl AstNode {
Ok(None)
}
Some([Syntax::Identifier { ident, span, .. }, ..]) if ident.name == "define-syntax" => {
return Err(parse::ParseAstError::BadForm(span.clone()));
Err(parse::ParseAstError::BadForm(span.clone()))
}
Some(syn @ [Syntax::Identifier { ident, span, .. }, ..]) if ident.name == "define" => {
Ok(Some(Self::Definition(
Expand Down
18 changes: 9 additions & 9 deletions src/ast/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Definition {
second: span.clone(),
});
}
new_env.def_local_var(&ident, Gc::new(Value::Undefined));
new_env.def_local_var(ident, Gc::new(Value::Undefined));
bound.insert(ident.clone(), span.clone());
fixed.push(ident.clone());
}
Expand All @@ -106,7 +106,7 @@ impl Definition {
});
}
let remaining = ident.clone();
new_env.def_local_var(&ident, Gc::new(Value::Undefined));
new_env.def_local_var(ident, Gc::new(Value::Undefined));
bound.insert(remaining.clone(), span.clone());
Formals::VarArgs {
fixed: fixed.into_iter().collect(),
Expand Down Expand Up @@ -214,7 +214,7 @@ where
'a: 'b,
{
Box::pin(async move {
if body.len() == 0 {
if body.is_empty() {
return Err(ParseAstError::EmptyBody(span.clone()));
}

Expand Down Expand Up @@ -302,7 +302,7 @@ impl Expression {
let FullyExpanded {
expanded,
expansion_ctxs: expansion_envs,
} = syn.expand(&env, cont).await?;
} = syn.expand(env, cont).await?;
let expansion_env = env.push_expansion_env(expansion_envs);
Self::parse_expanded(expanded, &expansion_env, cont).await
}
Expand Down Expand Up @@ -403,7 +403,7 @@ impl Expression {
[Syntax::Identifier { ident, span, .. }, .., Syntax::Null { .. }]
if ident.name == "define" =>
{
return Err(ParseAstError::DefInExprContext(span.clone()));
Err(ParseAstError::DefInExprContext(span.clone()))
}

// Regular old function call:
Expand All @@ -413,7 +413,7 @@ impl Expression {
.map(Expression::Call)
}

_ => return Err(ParseAstError::BadForm(span.clone())),
_ => Err(ParseAstError::BadForm(span.clone())),
},
}
})
Expand Down Expand Up @@ -488,7 +488,7 @@ async fn parse_lambda(
second: span.clone(),
});
}
new_contour.def_local_var(&ident, Gc::new(Value::Undefined));
new_contour.def_local_var(ident, Gc::new(Value::Undefined));
bound.insert(ident.clone(), span.clone());
fixed.push(ident.clone());
}
Expand All @@ -508,7 +508,7 @@ async fn parse_lambda(
second: span.clone(),
});
}
new_contour.def_local_var(&ident, Gc::new(Value::Undefined));
new_contour.def_local_var(ident, Gc::new(Value::Undefined));
let remaining = ident.clone();
Formals::VarArgs {
fixed: fixed.into_iter().collect(),
Expand Down Expand Up @@ -727,7 +727,7 @@ impl Set {
impl Quote {
async fn parse(exprs: &[Syntax], span: &Span) -> Result<Self, ParseAstError> {
match exprs {
[] => Err(dbg!(ParseAstError::ExpectedArgument(span.clone()))),
[] => Err(ParseAstError::ExpectedArgument(span.clone())),
[Syntax::Null { .. }] => Ok(Quote { val: Value::Null }),
[expr, Syntax::Null { .. }] => Ok(Quote {
val: Value::from_syntax(expr),
Expand Down
11 changes: 4 additions & 7 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ impl Env {
|| {
self.up
.as_ref()
.map(|up| up.read().fetch_var_ref(ident).map(VarRef::inc_depth))
.flatten()
.and_then(|up| up.read().fetch_var_ref(ident).map(VarRef::inc_depth))
},
|offset| Some(VarRef { depth: 0, offset }),
)
Expand Down Expand Up @@ -286,9 +285,7 @@ impl GlobalRef {
};

let top = top.read();
let Some(var) = top.fetch_var_ref(&self.name) else {
return None;
};
let var = top.fetch_var_ref(&self.name)?;
Some(top.fetch_var(var))
}

Expand Down Expand Up @@ -377,15 +374,15 @@ impl ExpansionEnv<'_> {
!matches!(self.fetch_var_ref(ident), Ref::Global(_))
}

pub fn push_expansion_env<'a>(&'a self, ctxs: Vec<ExpansionCtx>) -> ExpansionEnv<'a> {
pub fn push_expansion_env(&self, ctxs: Vec<ExpansionCtx>) -> ExpansionEnv<'_> {
ExpansionEnv {
lexical_contour: self.lexical_contour.clone(),
up: Some(self),
expansion_ctxs: ctxs,
}
}

pub fn push_lexical_contour<'a>(&'a self, gc: Gc<Env>) -> ExpansionEnv<'a> {
pub fn push_lexical_contour(&self, gc: Gc<Env>) -> ExpansionEnv<'_> {
ExpansionEnv {
up: Some(self),
expansion_ctxs: Vec::new(),
Expand Down
3 changes: 0 additions & 3 deletions tests/r6rs.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use std::sync::Arc;

use scheme_rs::{
ast::AstNode,
builtin,
continuation::Continuation,
env::Env,
error::RuntimeError,
gc::Gc,
lex::Token,
syntax::ParsedSyntax,
value::{eqv, Value},
};

Expand Down

0 comments on commit 78f9761

Please sign in to comment.