aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2019-01-29 02:41:42 -0800
committeriximeow <me@iximeow.net>2020-01-12 16:26:39 -0800
commit5d951e6dd6b130702fffb7238e7cb5daa782ca7d (patch)
tree38408e7366cdbbcf4cd88297e735a92fe0a3cabe /src
parenta3cf49ad33fd4a967035c48ff1d04033364707fa (diff)
add some predetermined address display stuff
also add zero and one traits to Address, adjust layout
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 77d3df2..b72686a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,12 +1,25 @@
extern crate num_traits;
-use std::fmt::Debug;
+use std::fmt::{Debug, Display};
use std::ops::{Add, Sub};
-use num_traits::{Bounded, WrappingAdd};
+use num_traits::identities;
+use num_traits::{Bounded, WrappingAdd, WrappingSub, CheckedAdd, CheckedSub};
// This is pretty wonk..
-pub trait Address where Self: Debug + Copy + Clone + Sized + Ord + Add<Output=Self> + Sub<Output=Self> + From<u16> + Bounded + WrappingAdd {
+
+pub trait AddressDisplay {
+ fn stringy(&self) -> String;
+}
+
+pub trait Address where Self:
+ Debug + Display + AddressDisplay +
+ Copy + Clone + Sized +
+ Ord + Eq + PartialEq + Bounded +
+ Add<Output=Self> + Sub<Output=Self> +
+ WrappingAdd + WrappingSub +
+ CheckedAdd + CheckedSub +
+ identities::One + identities::Zero {
fn to_linear(&self) -> usize;
}
/*
@@ -15,6 +28,18 @@ impl <T> Address for T where T: Sized + Ord + Add<Output=Self> + From<u16> + Int
}
*/
+impl AddressDisplay for u32 {
+ fn stringy(&self) -> String {
+ format!("{:#x}", self)
+ }
+}
+
+impl AddressDisplay for u16 {
+ fn stringy(&self) -> String {
+ format!("{:#x}", self)
+ }
+}
+
impl Address for u16 {
fn to_linear(&self) -> usize { *self as usize }
}
@@ -30,7 +55,7 @@ pub trait Decodable where Self: Sized {
pub trait Arch {
type Address: Address + Debug;
- type Instruction: Decodable + LengthedInstruction;
+ type Instruction: Decodable + LengthedInstruction<Unit=Self::Address>;
type Operand;
}