Skip to content

Commit

Permalink
Merge pull request #60 from paholg/fix_cmp
Browse files Browse the repository at this point in the history
Fix cmp
  • Loading branch information
paholg committed Apr 1, 2016
2 parents 10c15e3 + 6d23687 commit 9f90e7f
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 67 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This project follows semantic versioning.

### Unpublished

### 1.3.1 (2016-03-31)
- [fixed] Bug with recent nightlies.

### 1.3.0 (2016-02-07)
- [changed] Removed dependency on libstd. (Issue #53, PR #55)
- [changed] Reorganized module structure. (PR #57)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "typenum"
build = "build.rs"
version = "1.3.0"
version = "1.3.1"
authors = [
"Paho Lurie-Gregg <[email protected]>",
"Andre Bogus <[email protected]>"
Expand Down
105 changes: 45 additions & 60 deletions src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,100 +791,85 @@ impl<U: Unsigned, B: Bit> Cmp<UInt<U, B>> for UTerm {
type Output = Less;
}

impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned, Br: Bit> Cmp<UInt<Ur, Br>> for UInt<Ul, Bl>
where UInt<Ul, Bl>: PrivateCmp<UInt<Ur, Br>, Equal>
impl<Ul: Unsigned, Ur: Unsigned> Cmp<UInt<Ur, B0>> for UInt<Ul, B0>
where Ul: PrivateCmp<Ur, Equal>
{
type Output = PrivateCmpOut<UInt<Ul, Bl>, UInt<Ur, Br>, Equal>;
type Output = PrivateCmpOut<Ul, Ur, Equal>;
}

impl<Ul: Unsigned, Ur: Unsigned> Cmp<UInt<Ur, B1>> for UInt<Ul, B1>
where Ul: PrivateCmp<Ur, Equal>
{
type Output = PrivateCmpOut<Ul, Ur, Equal>;
}

impl<Ul: Unsigned, Ur: Unsigned> Cmp<UInt<Ur, B1>> for UInt<Ul, B0>
where Ul: PrivateCmp<Ur, Less>
{
type Output = PrivateCmpOut<Ul, Ur, Less>;
}

impl<Ul: Unsigned, Ur: Unsigned> Cmp<UInt<Ur, B0>> for UInt<Ul, B1>
where Ul: PrivateCmp<Ur, Greater>
{
type Output = PrivateCmpOut<Ul, Ur, Greater>;
}

/// Comparing non-terimal bits, with both having bit B0. These are the same, so we propogate `SoFar`.
impl<Ul, Bl, Ur, Br, S> PrivateCmp<UInt<UInt<Ur, Br>, B0>, S> for UInt<UInt<Ul, Bl>, B0>
impl<Ul, Ur, SoFar> PrivateCmp<UInt<Ur, B0>, SoFar> for UInt<Ul, B0>
where Ul: Unsigned,
Bl: Bit,
Ur: Unsigned,
Br: Bit,
S: Ord,
UInt<Ul, Bl>: PrivateCmp<UInt<Ur, Br>, S>
SoFar: Ord,
Ul: PrivateCmp<Ur, SoFar>
{
type Output = PrivateCmpOut<UInt<Ul, Bl>, UInt<Ur, Br>, S>;
type Output = PrivateCmpOut<Ul, Ur, SoFar>;
}

/// Comparing non-terimal bits, with both having bit B1. These are the same, so we propogate `SoFar`.
impl<Ul, Bl, Ur, Br, S> PrivateCmp<UInt<UInt<Ur, Br>, B1>, S> for UInt<UInt<Ul, Bl>, B1>
impl<Ul, Ur, SoFar> PrivateCmp<UInt<Ur, B1>, SoFar> for UInt<Ul, B1>
where Ul: Unsigned,
Bl: Bit,
Ur: Unsigned,
Br: Bit,
S: Ord,
UInt<Ul, Bl>: PrivateCmp<UInt<Ur, Br>, S>
SoFar: Ord,
Ul: PrivateCmp<Ur, SoFar>
{
type Output = PrivateCmpOut<UInt<Ul, Bl>, UInt<Ur, Br>, S>;
type Output = PrivateCmpOut<Ul, Ur, SoFar>;
}

/// Comparing non-terimal bits, with Lhs having bit B0 and Rhs having bit B1. `SoFar`, Lhs is `Less`.
impl<Ul, Bl, Ur, Br, S> PrivateCmp<UInt<UInt<Ur, Br>, B1>, S> for UInt<UInt<Ul, Bl>, B0>
impl<Ul, Ur, SoFar> PrivateCmp<UInt<Ur, B1>, SoFar> for UInt<Ul, B0>
where Ul: Unsigned,
Bl: Bit,
Ur: Unsigned,
Br: Bit,
S: Ord,
UInt<Ul, Bl>: PrivateCmp<UInt<Ur, Br>, Less>
SoFar: Ord,
Ul: PrivateCmp<Ur, Less>
{
type Output = PrivateCmpOut<UInt<Ul, Bl>, UInt<Ur, Br>, Less>;
type Output = PrivateCmpOut<Ul, Ur, Less>;
}

/// Comparing non-terimal bits, with Lhs having bit B1 and Rhs having bit B0. `SoFar`, Lhs is `Greater`.
impl<Ul, Bl, Ur, Br, S> PrivateCmp<UInt<UInt<Ur, Br>, B0>, S> for UInt<UInt<Ul, Bl>, B1>
impl<Ul, Ur, SoFar> PrivateCmp<UInt<Ur, B0>, SoFar> for UInt<Ul, B1>
where Ul: Unsigned,
Bl: Bit,
Ur: Unsigned,
Br: Bit,
S: Ord,
UInt<Ul, Bl>: PrivateCmp<UInt<Ur, Br>, Greater>
SoFar: Ord,
Ul: PrivateCmp<Ur, Greater>
{
type Output = PrivateCmpOut<UInt<Ul, Bl>, UInt<Ur, Br>, Greater>;
type Output = PrivateCmpOut<Ul, Ur, Greater>;
}

/// Comparing when Rhs has finished but Lhs has not; Lhs is `Greater`.
impl<Ul, Bl1, Bl2, Br, S> PrivateCmp<UInt<UTerm, Br>, S> for UInt<UInt<Ul, Bl2>, Bl1>
where Ul: Unsigned,
Bl1: Bit,
Bl2: Bit,
Br: Bit,
S: Ord
{
type Output = Greater;
}

/// Comparing when Lhs has finished but Rhs has not; Lhs is `Less`.
impl<Bl, Ur, Br1, Br2, S> PrivateCmp<UInt<UInt<Ur, Br2>, Br1>, S> for UInt<UTerm, Bl>
where Bl: Bit,
Ur: Unsigned,
Br1: Bit,
Br2: Bit,
S: Ord
{
/// Got to the end of just the Lhs. It's `Less`.
impl<U: Unsigned, B: Bit, SoFar: Ord> PrivateCmp<UInt<U, B>, SoFar> for UTerm {
type Output = Less;
}

/// Comparing when both are at terminal bits and both have `B0`. Go by `SoFar`.
impl<S: Ord> PrivateCmp<UInt<UTerm, B0>, S> for UInt<UTerm, B0> {
type Output = S;
/// Got to the end of just the Rhs. Lhs is `Greater`.
impl<U: Unsigned, B: Bit, SoFar: Ord> PrivateCmp<UTerm, SoFar> for UInt<U, B> {
type Output = Greater;
}

/// Comparing when both are at terminal bits and both have `B1`. Go by `SoFar`.
impl<S: Ord> PrivateCmp<UInt<UTerm, B1>, S> for UInt<UTerm, B1> {
type Output = S;
}

/// Comparing when both are at terminal bits and Lhs has `B0` while Rhs has `B1`. Lhs is `Less`.
impl<S: Ord> PrivateCmp<UInt<UTerm, B1>, S> for UInt<UTerm, B0> {
type Output = Less;
}

/// Comparing when both are at terminal bits and Lhs has `B1` while Rhs has `B0`. Lhs is `Greater`.
impl<S: Ord> PrivateCmp<UInt<UTerm, B0>, S> for UInt<UTerm, B1> {
type Output = Greater;
/// Got to the end of both! Return `SoFar`
impl<SoFar: Ord> PrivateCmp<UTerm, SoFar> for UTerm {
type Output = SoFar;
}

macro_rules! test_ord {
Expand Down
24 changes: 18 additions & 6 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,24 @@ fn test_all() {


let out_dir = env::var("OUT_DIR").unwrap();
let test_dir = Path::new(&out_dir).join("test/");
let cargo = Path::new(&out_dir).join("test/Cargo.toml");
let main = Path::new(&out_dir).join("test/src/main.rs");

Command::new("cargo").arg("new").arg("--bin").arg(&test_dir).output().unwrap();

let test_dir = Path::new(&out_dir).join("testing/");
let cargo = Path::new(&test_dir).join("Cargo.toml");
let main = Path::new(&test_dir).join("src/main.rs");

// This'll fail if the dir isn't already there. We don't really care, just need to
// make sure it isn't so we can run cargo new.
match std::fs::remove_dir_all(&test_dir) {
_ => ()
};

let cmd = Command::new("cargo").arg("new").arg("--bin").arg(&test_dir).output().unwrap();

if !cmd.status.success() {
panic!("Couldn't run cargo new. Stdout: \n{}\nStderr: {}\n",
std::str::from_utf8(&cmd.stdout).unwrap(),
std::str::from_utf8(&cmd.stderr).unwrap()
);
}
// Write cargo file
let mut cargof = File::create(&cargo).unwrap();
write!(cargof, "
Expand Down

0 comments on commit 9f90e7f

Please sign in to comment.