forked from AbleScript/ablescript
Function division
This commit is contained in:
parent
3c98caf2d6
commit
0b703173f8
|
@ -107,9 +107,7 @@ impl Value {
|
|||
instructions,
|
||||
tape_len,
|
||||
} => (instructions.len() + tape_len) as _,
|
||||
Functio::Able { params, body } => {
|
||||
(params.len() + format!("{:?}", body).len()) as _
|
||||
}
|
||||
Functio::Able { params, body } => (params.len() + format!("{:?}", body).len()) as _,
|
||||
Functio::Eval(s) => s.len() as _,
|
||||
},
|
||||
Value::Int(i) => i,
|
||||
|
@ -456,7 +454,38 @@ impl ops::Div for Value {
|
|||
})),
|
||||
Value::Bool(b) => Value::Bool(!b || rhs.into_bool()),
|
||||
Value::Abool(_) => !self + rhs,
|
||||
Value::Functio(_) => todo!(),
|
||||
Value::Functio(f) => {
|
||||
let fraction = 1.0 / rhs.into_i32() as f64;
|
||||
Value::Functio(match f {
|
||||
Functio::Bf {
|
||||
instructions,
|
||||
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::Eval(s) => {
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue