mirror of
https://github.com/mre/mos6502.git
synced 2024-11-28 22:51:26 +00:00
Merge pull request #35 from typelist/master
Reintroduce CheckedAddressDiff now that multidispatch works
This commit is contained in:
commit
bd30f8c6cc
@ -25,6 +25,8 @@
|
|||||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
// POSSIBILITY OF SUCH DAMAGE.
|
// POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
use std::num::Int;
|
||||||
|
|
||||||
// The idea here is that it doesn't make sense to add two addresses, but it
|
// The idea here is that it doesn't make sense to add two addresses, but it
|
||||||
// does make sense to add an address and an "address-difference". (If this
|
// does make sense to add an address and an "address-difference". (If this
|
||||||
// is too annoying to work with we should let it go.)
|
// is too annoying to work with we should let it go.)
|
||||||
@ -50,30 +52,20 @@ impl Add<AddressDiff, AddressDiff> for AddressDiff {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rustc doesn't seem to like having multiple implementations of Add for
|
#[deriving(Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
// Address. I believe this is a Rust bug (possibly resolved by "associated
|
|
||||||
// types" RFC?). Or I wrote it wrong. Anyway, here's some living dead code:
|
|
||||||
/*
|
|
||||||
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub struct CheckedAddressDiff(u16);
|
pub struct CheckedAddressDiff(u16);
|
||||||
|
|
||||||
impl Add<CheckedAddressDiff, Address> for Address {
|
impl Add<CheckedAddressDiff, Address> for Address {
|
||||||
fn add(&self, &CheckedAddressDiff(rhs): &CheckedAddressDiff) -> Address {
|
fn add(self, CheckedAddressDiff(rhs): CheckedAddressDiff) -> Address {
|
||||||
let &Address(lhs) = self;
|
let Address(lhs) = self;
|
||||||
|
|
||||||
// We probably don't want to overflow when doing arithmetic in our own
|
// We probably don't want to overflow when doing arithmetic in our own
|
||||||
// code.
|
// code.
|
||||||
debug_assert!({
|
debug_assert!(lhs.checked_add(rhs).is_some());
|
||||||
match lhs.checked_add(&rhs) {
|
|
||||||
None => false,
|
|
||||||
_ => true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Address(lhs + rhs)
|
Address(lhs + rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
impl Address {
|
impl Address {
|
||||||
pub fn to_u16(&self) -> u16 {
|
pub fn to_u16(&self) -> u16 {
|
||||||
|
Loading…
Reference in New Issue
Block a user