type alias for Context
This commit is contained in:
parent
6ba05f31e6
commit
525ca2c8cb
14
src/vm.rs
14
src/vm.rs
|
@ -41,6 +41,8 @@ pub struct LudusError {
|
|||
// }
|
||||
// }
|
||||
|
||||
type Context<'src> = Vec<(String, Value<'src>)>;
|
||||
|
||||
pub fn match_eq<T, U>(x: T, y: T, z: U) -> Option<U>
|
||||
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<MatchClause>,
|
||||
ctx: &mut Vec<(String, Value<'src>)>,
|
||||
clauses: &'src [MatchClause],
|
||||
ctx: &mut Context<'src>,
|
||||
) -> Result<Value<'src>, 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<Value<'src>, 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<Value<'src>, LudusError> {
|
||||
match ast {
|
||||
Ast::Nil => Ok(Value::Nil),
|
||||
|
|
Loading…
Reference in New Issue
Block a user