forked from AbleScript/ablescript
Implement custom PartialEq
for Value
This commit is contained in:
parent
8b57cbe5a5
commit
4c74e3bef3
|
@ -7,7 +7,7 @@ use rand::Rng;
|
||||||
|
|
||||||
use crate::{ast::Stmt, consts};
|
use crate::{ast::Stmt, consts};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||||
pub enum Abool {
|
pub enum Abool {
|
||||||
Never = -1,
|
Never = -1,
|
||||||
Sometimes = 0,
|
Sometimes = 0,
|
||||||
|
@ -357,12 +357,37 @@ impl PartialOrd for Value {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::Str(_) => todo!(),
|
Value::Str(s) => Some(s.cmp(&other.to_string())),
|
||||||
Value::Int(_) => todo!(),
|
Value::Int(i) => Some(i.cmp(&other.into_i32())),
|
||||||
Value::Bool(_) => todo!(),
|
Value::Bool(b) => Some(b.cmp(&other.into_bool())),
|
||||||
Value::Abool(_) => todo!(),
|
Value::Abool(a) => a.partial_cmp(&other.into_abool()),
|
||||||
Value::Functio(_) => todo!(),
|
Value::Functio(f) => {
|
||||||
Value::Cart(_) => todo!(),
|
// 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::Cart(c) => Some(c.len().cmp(&other.into_cart().len())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue