diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 96d89d2..545f2d4 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -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::() * tape_len as i32, + Functio::Able { params, body } => { + params + .into_iter() + .map(|x| x.bytes().map(|x| x as i32).sum::()) + .sum::() + + 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),