Used body length for AbleFunctio to i32 instead of AST length

pull/2/head
ondra05 2021-08-29 00:28:45 +02:00
parent 7ca05ccda6
commit 0f283c1da8
1 changed files with 2 additions and 27 deletions

View File

@ -97,7 +97,7 @@ impl Value {
instructions,
tape_len,
} => (instructions.len() + tape_len) as _,
Functio::AbleFunctio { params, body } => (params.len() + body.len()) as _,
Functio::AbleFunctio { params, body } => (params.len() + format!("{:?}", body).len()) as _,
Functio::Eval(s) => s.len() as _,
},
Value::Int(i) => i,
@ -361,32 +361,7 @@ impl PartialOrd for Value {
Value::Int(i) => Some(i.cmp(&other.into_i32())),
Value::Bool(b) => Some(b.cmp(&other.into_bool())),
Value::Abool(a) => a.partial_cmp(&other.into_abool()),
Value::Functio(f) => {
// Compares lengths of functions:
// BfFunctio - Sum of lengths of instructions and length of tape
// AbleFunctio - Sum of argument count and body length
// Eval - Length of input code
let selfl = match f {
Functio::BfFunctio {
instructions,
tape_len,
} => instructions.len() + tape_len,
Functio::AbleFunctio { params, body } => params.len() + body.len(),
Functio::Eval(s) => s.len(),
};
let otherl = match other.into_functio() {
Functio::BfFunctio {
instructions,
tape_len,
} => instructions.len() + tape_len,
Functio::AbleFunctio { params, body } => params.len() + body.len(),
Functio::Eval(s) => s.len(),
};
Some(selfl.cmp(&otherl))
}
Value::Functio(_) => self.clone().into_i32().partial_cmp(&other.into_i32()),
Value::Cart(c) => Some(c.len().cmp(&other.into_cart().len())),
}
}