-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add uint16/32/64 * allow [0][0]
- Loading branch information
Showing
2 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use std::bits; | ||
use std::comparator; | ||
|
||
// u8 | ||
struct Uint8 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint8.new(val: Field) -> Uint8 { | ||
let bit_len = 8; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
|
||
return Uint8 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// u16 | ||
struct Uint16 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint16.new(val: Field) -> Uint16 { | ||
let bit_len = 16; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
|
||
return Uint16 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// u32 | ||
struct Uint32 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint32.new(val: Field) -> Uint32 { | ||
let bit_len = 32; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
|
||
return Uint32 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// u64 | ||
struct Uint64 { | ||
inner: Field, | ||
bit_len: Field, | ||
} | ||
|
||
fn Uint64.new(val: Field) -> Uint64 { | ||
let bit_len = 64; | ||
|
||
// range check | ||
let ignore_ = bits::to_bits(bit_len, val); | ||
|
||
return Uint64 { | ||
inner: val, | ||
bit_len: bit_len | ||
}; | ||
} | ||
|
||
// implement comparator | ||
|
||
fn Uint8.less_than(self, rhs: Uint8) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint8.less_eq_than(self, rhs: Uint8) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint16.less_than(self, rhs: Uint16) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint16.less_eq_than(self, rhs: Uint16) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint32.less_than(self, rhs: Uint32) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint32.less_eq_than(self, rhs: Uint32) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint64.less_than(self, rhs: Uint64) -> Bool { | ||
return comparator::less_than(self.bit_len, self.inner, rhs.inner); | ||
} | ||
|
||
fn Uint64.less_eq_than(self, rhs: Uint64) -> Bool { | ||
return comparator::less_eq_than(self.bit_len, self.inner, rhs.inner); | ||
} |