From f5e4be4d67d90254caf25b58ac7dde85cb10f646 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 7 Dec 2021 21:57:37 +0100 Subject: [PATCH] Implemented Functio to Aboolean --- 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 2cce2b5..1a7af9e 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -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::() * 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