diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 2cce2b56..1a7af9e7 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -165,7 +165,29 @@ impl Value { } } Value::Abool(a) => a, - Value::Functio(_) => todo!(), + Value::Functio(f) => match f { + Functio::BfFunctio { + instructions, + tape_len, + } => Value::Int( + (instructions.iter().map(|x| *x as usize).sum::() * tape_len) as _, + ) + .into_abool(), + Functio::AbleFunctio { params, body } => { + let str_to_i32 = + |x: String| -> i32 { x.as_bytes().into_iter().map(|x| *x as i32).sum() }; + + let params: i32 = params.into_iter().map(str_to_i32).sum(); + let body: i32 = body + .into_iter() + .map(|x| format!("{:?}", x)) + .map(str_to_i32) + .sum(); + + Value::Int((params + body) % 3 - 1).into_abool() + } + Functio::Eval(code) => Value::Str(code).into_abool(), + }, Value::Cart(c) => { if c.is_empty() { Abool::Never