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>
|
pub fn match_eq<T, U>(x: T, y: T, z: U) -> Option<U>
|
||||||
where
|
where
|
||||||
T: PartialEq,
|
T: PartialEq,
|
||||||
|
@ -55,8 +57,8 @@ where
|
||||||
pub fn match_pattern<'src, 'a>(
|
pub fn match_pattern<'src, 'a>(
|
||||||
patt: &Pattern,
|
patt: &Pattern,
|
||||||
val: &Value<'src>,
|
val: &Value<'src>,
|
||||||
ctx: &'a mut Vec<(String, Value<'src>)>,
|
ctx: &'a mut Context<'src>,
|
||||||
) -> Option<&'a mut Vec<(String, Value<'src>)>> {
|
) -> Option<&'a mut Context<'src>> {
|
||||||
match (patt, val) {
|
match (patt, val) {
|
||||||
(Pattern::Nil, Value::Nil) => Some(ctx),
|
(Pattern::Nil, Value::Nil) => Some(ctx),
|
||||||
(Pattern::Placeholder, _) => Some(ctx),
|
(Pattern::Placeholder, _) => Some(ctx),
|
||||||
|
@ -197,8 +199,8 @@ pub fn match_pattern<'src, 'a>(
|
||||||
|
|
||||||
pub fn match_clauses<'src>(
|
pub fn match_clauses<'src>(
|
||||||
value: &Value<'src>,
|
value: &Value<'src>,
|
||||||
clauses: &'src Vec<MatchClause>,
|
clauses: &'src [MatchClause],
|
||||||
ctx: &mut Vec<(String, Value<'src>)>,
|
ctx: &mut Context<'src>,
|
||||||
) -> Result<Value<'src>, LudusError> {
|
) -> Result<Value<'src>, LudusError> {
|
||||||
let to = ctx.len();
|
let to = ctx.len();
|
||||||
for MatchClause { patt, body, guard } in clauses.iter() {
|
for MatchClause { patt, body, guard } in clauses.iter() {
|
||||||
|
@ -234,7 +236,7 @@ pub fn match_clauses<'src>(
|
||||||
pub fn apply<'src>(
|
pub fn apply<'src>(
|
||||||
callee: Value<'src>,
|
callee: Value<'src>,
|
||||||
caller: Value<'src>,
|
caller: Value<'src>,
|
||||||
ctx: &mut Vec<(String, Value<'src>)>,
|
ctx: &mut Context<'src>,
|
||||||
) -> Result<Value<'src>, LudusError> {
|
) -> Result<Value<'src>, LudusError> {
|
||||||
match (callee, caller) {
|
match (callee, caller) {
|
||||||
(Value::Keyword(kw), Value::Dict(dict)) => {
|
(Value::Keyword(kw), Value::Dict(dict)) => {
|
||||||
|
@ -304,7 +306,7 @@ pub fn apply<'src>(
|
||||||
|
|
||||||
pub fn eval<'src, 'a>(
|
pub fn eval<'src, 'a>(
|
||||||
ast: &'src Ast,
|
ast: &'src Ast,
|
||||||
ctx: &'a mut Vec<(String, Value<'src>)>,
|
ctx: &'a mut Context<'src>,
|
||||||
) -> Result<Value<'src>, LudusError> {
|
) -> Result<Value<'src>, LudusError> {
|
||||||
match ast {
|
match ast {
|
||||||
Ast::Nil => Ok(Value::Nil),
|
Ast::Nil => Ok(Value::Nil),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user