pub struct BitvectorArray<const I: u32, const L: u32> { /* private fields */ }
Expand description

Power-of-two array of bitvectors without signedness information.

The exponent of array size is specified in the first generic parameter I. Element length is specified in the second generic parameter L.

The array is indexed by bitvectors of length I, so no out-of-bound access can occur.

Implementations§

source§

impl<const I: u32, const L: u32> BitvectorArray<I, L>

source

pub fn new_filled(element: Bitvector<L>) -> Self

Creates a new array filled with the given element.

Examples found in repository?
examples/simple_risc.rs (line 140)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
fn main() {
    let toy_program = [
        // (0) set r0 to zero
        Bitvector::new(0b0100_0000_0000),
        // (1) set r1 to one
        Bitvector::new(0b0101_0000_0001),
        // (2) set r2 to zero
        Bitvector::new(0b0110_0000_0000),
        // --- main loop ---
        // (3) store r1 content to data location 0
        Bitvector::new(0b1100_0000_0000),
        // (4) store r2 content to data location 1
        Bitvector::new(0b1100_0000_0001),
        // (5) read input location 0 to r3
        Bitvector::new(0b0011_0100_0000),
        // (6) jump to (3) if r3 bit 0 is set
        Bitvector::new(0b0011_1000_0011),
        // (7) increment r2
        Bitvector::new(0b0010_0000_1001),
        // (8) store r2 content to data location 1
        Bitvector::new(0b1110_0000_0001),
        // (9) jump to (3)
        Bitvector::new(0b0001_1000_0011),
    ];

    // load toy program to program memory, filling unused locations with 0
    let mut progmem = BitvectorArray::new_filled(Bitvector::new(0));
    for (index, instruction) in toy_program.into_iter().enumerate() {
        progmem[Bitvector::new(index as u64)] = instruction;
    }
    let system = machine_module::System { progmem };
    machine_check::run(system);
}
source

pub fn from_slice(slice: &[Bitvector<L>]) -> Self

Creates the bitvector array from a correctly sized slice of bitvectors.

Panics if the bitvector slice length is not equal to 2L.

Cannot be used within the machine_description macro.

Trait Implementations§

source§

impl<const I: u32, const L: u32> Clone for BitvectorArray<I, L>

source§

fn clone(&self) -> BitvectorArray<I, L>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const I: u32, const L: u32> Debug for BitvectorArray<I, L>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const I: u32, const L: u32> Hash for BitvectorArray<I, L>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<const I: u32, const L: u32> Index<Bitvector<I>> for BitvectorArray<I, L>

§

type Output = Bitvector<L>

The returned type after indexing.
source§

fn index(&self, index: Bitvector<I>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<const I: u32, const L: u32> IndexMut<Bitvector<I>> for BitvectorArray<I, L>

source§

fn index_mut(&mut self, index: Bitvector<I>) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<const I: u32, const L: u32> IntoMck for BitvectorArray<I, L>

§

type Type = Array<I, L>

source§

fn into_mck(self) -> Self::Type

source§

impl<const I: u32, const L: u32> PartialEq for BitvectorArray<I, L>

source§

fn eq(&self, other: &BitvectorArray<I, L>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const I: u32, const L: u32> Eq for BitvectorArray<I, L>

source§

impl<const I: u32, const L: u32> StructuralPartialEq for BitvectorArray<I, L>

Auto Trait Implementations§

§

impl<const I: u32, const L: u32> RefUnwindSafe for BitvectorArray<I, L>

§

impl<const I: u32, const L: u32> Send for BitvectorArray<I, L>

§

impl<const I: u32, const L: u32> Sync for BitvectorArray<I, L>

§

impl<const I: u32, const L: u32> Unpin for BitvectorArray<I, L>

§

impl<const I: u32, const L: u32> UnwindSafe for BitvectorArray<I, L>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.