From 525ca2c8cb41fca31841d690a04686fc9d83e69b Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 8 Dec 2024 00:02:01 -0500 Subject: [PATCH] type alias for Context --- src/vm.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/vm.rs b/src/vm.rs index 207e688..fcdedc6 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -41,6 +41,8 @@ pub struct LudusError { // } // } +type Context<'src> = Vec<(String, Value<'src>)>; + pub fn match_eq(x: T, y: T, z: U) -> Option where T: PartialEq, @@ -55,8 +57,8 @@ where pub fn match_pattern<'src, 'a>( patt: &Pattern, val: &Value<'src>, - ctx: &'a mut Vec<(String, Value<'src>)>, -) -> Option<&'a mut Vec<(String, Value<'src>)>> { + ctx: &'a mut Context<'src>, +) -> Option<&'a mut Context<'src>> { match (patt, val) { (Pattern::Nil, Value::Nil) => Some(ctx), (Pattern::Placeholder, _) => Some(ctx), @@ -197,8 +199,8 @@ pub fn match_pattern<'src, 'a>( pub fn match_clauses<'src>( value: &Value<'src>, - clauses: &'src Vec, - ctx: &mut Vec<(String, Value<'src>)>, + clauses: &'src [MatchClause], + ctx: &mut Context<'src>, ) -> Result, LudusError> { let to = ctx.len(); for MatchClause { patt, body, guard } in clauses.iter() { @@ -234,7 +236,7 @@ pub fn match_clauses<'src>( pub fn apply<'src>( callee: Value<'src>, caller: Value<'src>, - ctx: &mut Vec<(String, Value<'src>)>, + ctx: &mut Context<'src>, ) -> Result, LudusError> { match (callee, caller) { (Value::Keyword(kw), Value::Dict(dict)) => { @@ -304,7 +306,7 @@ pub fn apply<'src>( pub fn eval<'src, 'a>( ast: &'src Ast, - ctx: &'a mut Vec<(String, Value<'src>)>, + ctx: &'a mut Context<'src>, ) -> Result, LudusError> { match ast { Ast::Nil => Ok(Value::Nil),