Functio -> Int more cursed

pull/2/head
ondra05 2022-01-22 21:02:10 +01:00
parent f4f7b102eb
commit 4386e31ea5
1 changed files with 23 additions and 1 deletions

View File

@ -122,7 +122,29 @@ impl Value {
match self {
Value::Abool(a) => a as _,
Value::Bool(b) => b as _,
Value::Functio(_) => self.len(),
Value::Functio(f) => match f {
Functio::Bf {
instructions,
tape_len,
} => instructions.into_iter().map(|x| x as i32).sum::<i32>() * tape_len as i32,
Functio::Able { params, body } => {
params
.into_iter()
.map(|x| x.bytes().map(|x| x as i32).sum::<i32>())
.sum::<i32>()
+ body.len() as i32
}
Functio::Chain { functios, kind } => {
let (lf, rf) = *functios;
Value::Functio(lf).into_i32()
+ Value::Functio(rf).into_i32()
* match kind {
FunctioChainKind::Equal => -1,
FunctioChainKind::ByArity => 1,
}
}
Functio::Eval(code) => code.bytes().map(|x| x as i32).sum(),
},
Value::Int(i) => i,
Value::Nul => consts::ANSWER,
Value::Str(text) => text.parse().unwrap_or(consts::ANSWER),