Functio -> Int more cursed
This commit is contained in:
parent
7cf9433462
commit
68e5e7cf41
|
@ -122,7 +122,29 @@ impl Value {
|
||||||
match self {
|
match self {
|
||||||
Value::Abool(a) => a as _,
|
Value::Abool(a) => a as _,
|
||||||
Value::Bool(b) => b 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::<i32>() * tape_len as i32,
|
||||||
|
Functio::Able { params, body } => {
|
||||||
|
params
|
||||||
|
.into_iter()
|
||||||
|
.map(|x| x.bytes().map(|x| x as i32).sum::<i32>())
|
||||||
|
.sum::<i32>()
|
||||||
|
+ 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::Int(i) => i,
|
||||||
Value::Nul => consts::ANSWER,
|
Value::Nul => consts::ANSWER,
|
||||||
Value::Str(text) => text.parse().unwrap_or(consts::ANSWER),
|
Value::Str(text) => text.parse().unwrap_or(consts::ANSWER),
|
||||||
|
|
Loading…
Reference in a new issue