Helper for comparisons
(op1: Constant, op2: Constant)
| 460 | // Or potentially define an ordering based on keys? Simpler to return None. |
| 461 | } |
| 462 | |
| 463 | for key in f1_keys { |
| 464 | let val1 = f1.get(key).unwrap(); // Key must exist based on checks |
| 465 | let val2 = f2.get(key).unwrap(); |
| 466 | // Recursively call compare_constants! |
| 467 | match compare_constants(val1.clone(), val2.clone())? { |
| 468 | std::cmp::Ordering::Equal => continue, // Check next field |
| 469 | other_ordering => return Some(other_ordering), // Found difference |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | // If all params and fields are equal |
| 474 | Some(std::cmp::Ordering::Equal) |
| 475 | } |
| 476 | |
| 477 | _ => None, // Incompatible types for comparison |
| 478 | } |
| 479 | } |
| 480 | |
| 481 | // Internal equality check, handling recursion carefully |
| 482 | fn eq_constants_internal(op1: Constant, op2: Constant) -> Option<bool> { |
| 483 | match compare_constants(op1, op2) { |
| 484 | // No clone needed here if compare_constants handles it |
| 485 | Some(std::cmp::Ordering::Equal) => Some(true), |
| 486 | Some(_) => Some(false), // Comparable but not equal |
| 487 | None => None, // Not comparable |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | pub fn eq_constants(op1: Constant, op2: Constant) -> Option<bool> { |
| 492 | eq_constants_internal(op1.clone(), op2.clone()) |
| 493 | } |
| 494 | |
| 495 | pub fn gt_constants(op1: Constant, op2: Constant) -> Option<bool> { |
| 496 | compare_constants(op1.clone(), op2.clone()).map(|ord| ord == std::cmp::Ordering::Greater) |
| 497 | } |
| 498 | |
| 499 | pub fn lt_constants(op1: Constant, op2: Constant) -> Option<bool> { |
| 500 | compare_constants(op1, op2).map(|ord| ord == std::cmp::Ordering::Less) |
| 501 | } |
| 502 | |
| 503 | pub fn ge_constants(op1: Constant, op2: Constant) -> Option<bool> { |
| 504 | compare_constants(op1, op2).map(|ord| ord != std::cmp::Ordering::Less) |
| 505 | } |
| 506 | |
| 507 | pub fn le_constants(op1: Constant, op2: Constant) -> Option<bool> { |
| 508 | compare_constants(op1, op2).map(|ord| ord != std::cmp::Ordering::Greater) |
| 509 | } |
| 510 | |
| 511 | fn do_bitwise_op<F>(op1: Constant, op2: Constant, func: F) -> Option<Constant> |
| 512 | where |
| 513 | F: FnOnce(BigInt, BigInt) -> Result<BigInt, InterpretError>, // Assume BigInt for bitwise |
| 514 | { |
| 515 | // Promote both to BigInt if possible, otherwise fallback to primitives |
| 516 | if let (Ok(bi1), Ok(bi2)) = ( |
| 517 | parse_constant_to_bigint(&op1), |
| 518 | parse_constant_to_bigint(&op2), |
| 519 | ) { |
no test coverage detected