Implemented Functio to Aboolean

This commit is contained in:
Erin 2021-12-07 21:57:37 +01:00 committed by ondra05
parent 1a78eaf8c3
commit 07d021f610

View file

@ -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::<usize>() * 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