Implemented Functio to Aboolean

pull/1/head
ondra05 2021-12-07 21:57:37 +01:00
parent 9e41f8de07
commit bc3f16ba40
1 changed files with 23 additions and 1 deletions

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