From 20b14081790b678672e22b1bea6b196e5128da5d Mon Sep 17 00:00:00 2001 From: Alex Bethel Date: Tue, 14 Dec 2021 16:16:28 -0600 Subject: [PATCH] Implement function chain division --- ablescript/src/variables.rs | 65 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 90d00b6..5d42a19 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -617,39 +617,48 @@ impl ops::Div for Value { })), Value::Bool(b) => Value::Bool(!b || rhs.into_bool()), Value::Abool(_) => !self + rhs, - Value::Functio(f) => { - let fraction = 1.0 / rhs.into_i32() as f64; - Value::Functio(match f { + Value::Functio(f) => Value::Functio(match f { + Functio::Bf { + instructions, + tape_len, + } => { + let fraction = 1.0 / rhs.into_i32() as f64; + let len = instructions.len(); Functio::Bf { - instructions, + instructions: instructions + .into_iter() + .take((len as f64 * fraction) as usize) + .collect(), tape_len, - } => { - let len = instructions.len(); - Functio::Bf { - instructions: instructions - .into_iter() - .take((len as f64 * fraction) as usize) - .collect(), - tape_len, - } } - Functio::Able { params, body } => { - let len = body.len(); - Functio::Able { - params, - body: body - .into_iter() - .take((len as f64 * fraction) as usize) - .collect(), - } + } + Functio::Able { params, body } => { + let fraction = 1.0 / rhs.into_i32() as f64; + let len = body.len(); + Functio::Able { + params, + body: body + .into_iter() + .take((len as f64 * fraction) as usize) + .collect(), } - Functio::Chain { .. } => todo!(":P"), - Functio::Eval(s) => { - let len = s.len(); - Functio::Eval(s.chars().take((len as f64 * fraction) as usize).collect()) + } + Functio::Chain { functios, kind } => { + let functios = *functios; + Functio::Chain { + functios: Box::new(( + (Value::Functio(functios.0) / rhs.clone()).into_functio(), + (Value::Functio(functios.1) / rhs).into_functio(), + )), + kind, } - }) - } + } + Functio::Eval(s) => { + let fraction = 1.0 / rhs.into_i32() as f64; + let len = s.len(); + Functio::Eval(s.chars().take((len as f64 * fraction) as usize).collect()) + } + }), Value::Cart(c) => { let cart_len = c.len(); let chunk_len = rhs.into_i32() as usize;