From 6f5b96b26b97e80e083ab8ce36444549b67e8ec1 Mon Sep 17 00:00:00 2001 From: Erin Date: Sat, 22 Jan 2022 21:02:10 +0100 Subject: [PATCH] Functio -> Int more cursed --- ablescript/src/variables.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 96d89d20..545f2d45 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),