fn compile_unsigned_cmp(
    lhs: ScoreHolder,
    rhs: ScoreHolder,
    dest: ScoreHolder,
    relation: cir::Relation,
) -> Vec<Command> {
    let mut cmds = Vec::new();

    let (invert, or_eq) = match relation {
        cir::Relation::LessThan => (false, false),
        cir::Relation::LessThanEq => (false, true),
        cir::Relation::GreaterThanEq => (true, false),
        cir::Relation::GreaterThan => (true, true),
        cir::Relation::Eq => panic!(),
    };

    // Reset the flag
    cmds.push(assign_lit(dest.clone(), invert as i32));

    let mut check1 = Execute::new();
    check1.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((0..).into()),
    });
    check1.with_if(ExecuteCondition::Score {
        target: rhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((0..).into()),
    });
    check1.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Relation {
            relation: cir::Relation::LessThan,
            source: rhs.clone().into(),
            source_obj: OBJECTIVE.to_string(),
        },
    });
    check1.with_run(assign_lit(dest.clone(), !invert as i32));
    cmds.push(check1.into());

    let mut check2 = Execute::new();
    check2.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((..=-1).into()),
    });
    check2.with_if(ExecuteCondition::Score {
        target: rhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((..=-1).into()),
    });
    check2.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Relation {
            relation: cir::Relation::LessThan,
            source: rhs.clone().into(),
            source_obj: OBJECTIVE.to_string(),
        },
    });
    check2.with_run(assign_lit(dest.clone(), !invert as i32));
    cmds.push(check2.into());

    let mut check3 = Execute::new();
    check3.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((0..).into()),
    });
    check3.with_if(ExecuteCondition::Score {
        target: rhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((..=-1).into()),
    });
    check3.with_run(assign_lit(dest.clone(), !invert as i32));
    cmds.push(check3.into());

    if or_eq {
        let mut eq_check = Execute::new();
        eq_check.with_if(ExecuteCondition::Score {
            target: lhs.into(),
            target_obj: OBJECTIVE.to_string(),
            kind: ExecuteCondKind::Relation {
                relation: cir::Relation::Eq,
                source: rhs.into(),
                source_obj: OBJECTIVE.to_string(),
            },
        });
        eq_check.with_run(assign_lit(dest, !invert as i32));
        cmds.push(eq_check.into());
    }

    cmds
}
// This whole thing could be optimized into a single command with a Predicate but... ugh
This whole thing could be optimized into a single command with a Predicate but... ugh
This whole thing could be optimized into a single command with a Predicate but ... ugh
fn compile_unsigned_cmp(
    lhs: ScoreHolder,
    rhs: ScoreHolder,
    dest: ScoreHolder,
    relation: cir::Relation,
) -> Vec<Command> {
    let mut cmds = Vec::new();
    let (invert, or_eq) = match relation {
        cir::Relation::LessThan => (false, false),
        cir::Relation::LessThanEq => (false, true),
        cir::Relation::GreaterThanEq => (true, false),
        cir::Relation::GreaterThan => (true, true),
        cir::Relation::Eq => panic!(),
    };
    // Reset the flag
    cmds.push(assign_lit(dest.clone(), invert as i32));
    let mut check1 = Execute::new();
    check1.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((0..).into()),
    });
    check1.with_if(ExecuteCondition::Score {
        target: rhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((0..).into()),
    });
    check1.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Relation {
            relation: cir::Relation::LessThan,
            source: rhs.clone().into(),
            source_obj: OBJECTIVE.to_string(),
        },
    });
    check1.with_run(assign_lit(dest.clone(), !invert as i32));
    cmds.push(check1.into());
    let mut check2 = Execute::new();
    check2.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((..=-1).into()),
    });
    check2.with_if(ExecuteCondition::Score {
        target: rhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((..=-1).into()),
    });
    check2.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Relation {
            relation: cir::Relation::LessThan,
            source: rhs.clone().into(),
            source_obj: OBJECTIVE.to_string(),
        },
    });
    check2.with_run(assign_lit(dest.clone(), !invert as i32));
    cmds.push(check2.into());
    let mut check3 = Execute::new();
    check3.with_if(ExecuteCondition::Score {
        target: lhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((0..).into()),
    });
    check3.with_if(ExecuteCondition::Score {
        target: rhs.clone().into(),
        target_obj: OBJECTIVE.to_string(),
        kind: ExecuteCondKind::Matches((..=-1).into()),
    });
    check3.with_run(assign_lit(dest.clone(), !invert as i32));
    cmds.push(check3.into());
    if or_eq {
        let mut eq_check = Execute::new();
        eq_check.with_if(ExecuteCondition::Score {
            target: lhs.into(),
            target_obj: OBJECTIVE.to_string(),
            kind: ExecuteCondKind::Relation {
                relation: cir::Relation::Eq,
                source: rhs.into(),
                source_obj: OBJECTIVE.to_string(),
            },
        });
        eq_check.with_run(assign_lit(dest, !invert as i32));
        cmds.push(eq_check.into());
    }
    cmds
}
fn compile_unsigned_cmp ( lhs : ScoreHolder , rhs : ScoreHolder , dest : ScoreHolder , relation : cir :: Relation , ) -> Vec < Command > { let mut cmds = Vec :: new ( ) ; let ( invert , or_eq ) = match relation { cir :: Relation :: LessThan => ( false , false ) , cir :: Relation :: LessThanEq => ( false , true ) , cir :: Relation :: GreaterThanEq => ( true , false ) , cir :: Relation :: GreaterThan => ( true , true ) , cir :: Relation :: Eq => panic ! ( ) , } ; // Reset the flag cmds . push ( assign_lit ( dest . clone ( ) , invert as i32 ) ) ; let mut check1 = Execute :: new ( ) ; check1 . with_if ( ExecuteCondition :: Score { target : lhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Matches ( ( 0 .. ) . into ( ) ) , } ) ; check1 . with_if ( ExecuteCondition :: Score { target : rhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Matches ( ( 0 .. ) . into ( ) ) , } ) ; check1 . with_if ( ExecuteCondition :: Score { target : lhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Relation { relation : cir :: Relation :: LessThan , source : rhs . clone ( ) . into ( ) , source_obj : OBJECTIVE . to_string ( ) , } , } ) ; check1 . with_run ( assign_lit ( dest . clone ( ) , ! invert as i32 ) ) ; cmds . push ( check1 . into ( ) ) ; let mut check2 = Execute :: new ( ) ; check2 . with_if ( ExecuteCondition :: Score { target : lhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Matches ( ( .. = - 1 ) . into ( ) ) , } ) ; check2 . with_if ( ExecuteCondition :: Score { target : rhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Matches ( ( .. = - 1 ) . into ( ) ) , } ) ; check2 . with_if ( ExecuteCondition :: Score { target : lhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Relation { relation : cir :: Relation :: LessThan , source : rhs . clone ( ) . into ( ) , source_obj : OBJECTIVE . to_string ( ) , } , } ) ; check2 . with_run ( assign_lit ( dest . clone ( ) , ! invert as i32 ) ) ; cmds . push ( check2 . into ( ) ) ; let mut check3 = Execute :: new ( ) ; check3 . with_if ( ExecuteCondition :: Score { target : lhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Matches ( ( 0 .. ) . into ( ) ) , } ) ; check3 . with_if ( ExecuteCondition :: Score { target : rhs . clone ( ) . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Matches ( ( .. = - 1 ) . into ( ) ) , } ) ; check3 . with_run ( assign_lit ( dest . clone ( ) , ! invert as i32 ) ) ; cmds . push ( check3 . into ( ) ) ; if or_eq { let mut eq_check = Execute :: new ( ) ; eq_check . with_if ( ExecuteCondition :: Score { target : lhs . into ( ) , target_obj : OBJECTIVE . to_string ( ) , kind : ExecuteCondKind :: Relation { relation : cir :: Relation :: Eq , source : rhs . into ( ) , source_obj : OBJECTIVE . to_string ( ) , } , } ) ; eq_check . with_run ( assign_lit ( dest , ! invert as i32 ) ) ; cmds . push ( eq_check . into ( ) ) ; } cmds }
This whole thing could be optimized into a single command with a Predicate but... ugh
This whole thing could be optimized into a single command with a Predicate but ... ugh
lhs
ScoreHolder
rhs
ScoreHolder
dest
ScoreHolder
relation
cir::Relation
lhs
ScoreHolder
rhs
ScoreHolder
dest
ScoreHolder
relation
cir::Relation