Skip to content
Snippets Groups Projects
Commit 35523276 authored by Per Lindgren's avatar Per Lindgren
Browse files

wip (before array)

parent a0c37e9d
No related branches found
No related tags found
No related merge requests found
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "fixedbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
[[package]]
name = "indexmap"
version = "1.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "petgraph"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]] [[package]]
name = "rsim" name = "rsim"
version = "0.1.0" version = "0.1.0"
dependencies = [
"petgraph",
]
...@@ -7,3 +7,4 @@ edition = "2018" ...@@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
petgraph = "0.5.1"
mod signal; mod signal;
pub use signal::*; pub use signal::*;
pub struct Component {
pub inputs: Vec<Signal>,
pub outputs: Vec<(Signal, Box<Component>)>,
}
pub trait Eval {
fn eval(&mut self) -> ();
}
use rsim::*; use rsim::*;
fn main() { // fn main() {
let b: Signal = 12345u32.into(); // let b: Signal = 12345u32.into();
let c: Signal = 1245u32.into(); // let c: Signal = 1245u32.into();
let s: Signal = Signal::new_zeroed(5); // let s: Signal = Signal::new_zeroed(5);
let b8: Signal = 0b0000_1010u8.into(); // let b8: Signal = 0b0000_1010u8.into();
for i in 0..8 { // for i in 0..8 {
println!("b8[{}] {}", i, b8[i]); // println!("b8[{}] {}", i, b8[i]);
} // }
println!("b8 {:b}", b8); // println!("b8 {:b}", b8);
println!("s {:b}", s); // println!("s {:b}", s);
println!("{:?}", s); // println!("{:?}", s);
if b == c { // if b == c {
println!("eq"); // println!("eq");
} // }
// println!("b {:?}", b);
// let i: u32 = b.into();
// println!("i {:?}", i);
// let a: Signal = 0b1001_0101u8.into();
// let b: Signal = 0b1111_0000u8.into();
// let c: Signal = &a & &b;
// println!("{:?}", a);
// println!("{:?}", b);
// println!("{:?}", c);
println!("b {:?}", b); // let r: u8 = (&a & &b).into();
// }
let i: u32 = b.into(); // use petgraph::{
println!("i {:?}", i); // graph::{DiGraph, Node},
// Directed,
// };
let a: Signal = 0b1001_0101u8.into(); // use petgraph::dot::{Config, Dot};
let b: Signal = 0b1111_0000u8.into(); // use std::fs::File;
let c: Signal = &a & &b; // use std::io::prelude::*;
println!("{:?}", a); // fn main() {
println!("{:?}", b); // let mut deps = DiGraph::<&str, &str>::new();
println!("{:?}", c); // let pg = deps.add_node("petgraph");
// let fb = deps.add_node("fixedbitset");
// let qc = deps.add_node("quickcheck");
// let rand = deps.add_node("rand");
// let libc = deps.add_node("libc");
// deps.extend_with_edges(&[(pg, fb), (pg, qc), (qc, rand), (rand, libc), (qc, libc)]);
// println!("{:?}", Dot::with_config(&deps, &[Config::EdgeNoLabel]));
let r: u8 = (&a & &b).into(); // let out: String = Dot::with_config(&deps, &[Config::EdgeNoLabel]).to_string();
// let mut file = File::create("foo.dot").unwrap();
// file.write_all(out.as_bytes()).unwrap();
// }
use std::cell::Cell;
#[derive(Debug)]
struct CSignal(Cell<Signal>);
#[derive(Debug)]
struct MuxIn<'a> {
a: &'a CSignal,
b: &'a CSignal,
sel: &'a CSignal,
} }
fn main() {}
// #[derive(Debug)]
// struct Mux<'a> {
// inputs: MuxIn<'a>,
// output: CSignal,
// }
// impl<'a> Eval for Mux<'a> {
// fn eval(&mut self) {
// self.output = match self.inputs.sel[0] {
// false => self.inputs.a.get(),
// true => self.inputs.b,
// }
// .clone()
// }
// }
// #[derive(Debug)]
// struct AndIn<'a> {
// a: &'a Signal,
// b: &'a Signal,
// }
// #[derive(Debug)]
// struct And<'a> {
// inputs: AndIn<'a>,
// output: Signal,
// }
// impl<'a> Eval for And<'a> {
// fn eval(&mut self) {
// self.output = (self.inputs.a & self.inputs.b).clone()
// }
// }
// fn main() {
// let a: Signal = 1u8.into();
// let b: Signal = 2u8.into();
// let mut and = And {
// inputs: AndIn { a: &a, b: &b },
// output: Signal::new(),
// };
// let mut m = Mux {
// inputs: MuxIn {
// a: &a,
// b: &b,
// sel: &and.output,
// },
// output: Signal::new(),
// };
// and.eval();
// //println!("m {:?}", m);
// m.eval();
// // println!("m {:?}", m);
// }
...@@ -3,7 +3,7 @@ use std::fmt; ...@@ -3,7 +3,7 @@ use std::fmt;
use std::ops::{BitAnd, Index}; use std::ops::{BitAnd, Index};
use std::string::String; use std::string::String;
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Copy, Clone)]
pub struct Signal(Vec<bool>); pub struct Signal(Vec<bool>);
impl Signal { impl Signal {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment