Skip to content

Commit 8a9a8dd

Browse files
committed
Add circuit
1 parent f1c27d6 commit 8a9a8dd

4 files changed

Lines changed: 15 additions & 23 deletions

File tree

check.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# This scripts runs various CI-like checks in a convenient way.
33
set -eu
44

5-
rustup override set 1.89
6-
75
cargo check --quiet --workspace --all-targets
86
cargo check --quiet --workspace --all-features --lib --target wasm32-unknown-unknown
97
cargo fmt --all -- --check

src/app.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,6 @@ impl App {
622622
}
623623

624624
pub fn delete_instance(&mut self, id: InstanceId) {
625-
self.db.instances.remove(id);
626625
self.db.types.remove(id);
627626
self.db.gates.remove(id);
628627
self.db.powers.remove(id);

src/connection_manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl ConnectionManager {
124124
self.pin_position_cache.clear();
125125

126126
// Index all pins by their grid cell
127-
for (instance_id, _) in &db.instances {
127+
for (instance_id, _) in &db.types {
128128
for pin in db.pins_of(instance_id) {
129129
let pos = db.pin_position(pin, &self.canvas_config);
130130
let cell = GridCell::from_pos(pos);
@@ -292,7 +292,7 @@ impl ConnectionManager {
292292
pins_to_update.sort_unstable();
293293
pins_to_update.dedup();
294294

295-
if pins_to_update.len() > db.instances.len() / 4 {
295+
if pins_to_update.len() > db.types.len() / 4 {
296296
self.rebuild_spatial_index(db);
297297
} else {
298298
self.update_spatial_index_for_pins(db, &pins_to_update);

src/db.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,75 +49,70 @@ impl From<u32> for ModuleDefId {
4949
}
5050
}
5151

52+
#[derive(Default, serde::Deserialize, serde::Serialize, Debug, Clone)]
53+
pub struct Circuit {}
54+
5255
#[derive(Default, serde::Deserialize, serde::Serialize, Debug, Clone)]
5356
pub struct DB {
54-
// Primary key allocator; ensures unique keys across all instance kinds
55-
pub instances: SlotMap<InstanceId, ()>,
57+
pub circuit: Circuit,
5658
// Type registry for each instance id
57-
pub types: SecondaryMap<InstanceId, InstanceKind>,
59+
pub types: SlotMap<InstanceId, InstanceKind>,
5860
// Per-kind payloads keyed off the primary key space
5961
pub gates: SecondaryMap<InstanceId, Gate>,
6062
pub powers: SecondaryMap<InstanceId, Power>,
6163
pub wires: SecondaryMap<InstanceId, Wire>,
6264
pub lamps: SecondaryMap<InstanceId, Lamp>,
6365
pub clocks: SecondaryMap<InstanceId, Clock>,
6466
pub modules: SecondaryMap<InstanceId, Module>,
65-
// Definition of modules created by the user
66-
pub module_definitions: SlotMap<ModuleDefId, ModuleDefinition>,
6767
pub connections: HashSet<Connection>,
6868
// Labels
6969
pub labels: SlotMap<LabelId, Label>,
70+
// Definition of modules created by the user
71+
pub module_definitions: SlotMap<ModuleDefId, ModuleDefinition>,
7072
}
7173

7274
impl DB {
7375
pub fn new() -> Self {
7476
Self::default()
7577
}
7678
pub fn new_gate(&mut self, g: Gate) -> InstanceId {
77-
let k = self.instances.insert(());
79+
let k = self.types.insert(InstanceKind::Gate(g.kind));
7880
self.gates.insert(k, g);
7981
let kind = self
8082
.gates
8183
.get(k)
8284
.expect("gate must exist right after insertion")
8385
.kind;
84-
self.types.insert(k, InstanceKind::Gate(kind));
8586
k
8687
}
8788

8889
pub fn new_power(&mut self, p: Power) -> InstanceId {
89-
let k = self.instances.insert(());
90+
let k = self.types.insert(InstanceKind::Power);
9091
self.powers.insert(k, p);
91-
self.types.insert(k, InstanceKind::Power);
9292
k
9393
}
9494

9595
pub fn new_wire(&mut self, w: Wire) -> InstanceId {
96-
let k = self.instances.insert(());
96+
let k = self.types.insert(InstanceKind::Wire);
9797
self.wires.insert(k, w);
98-
self.types.insert(k, InstanceKind::Wire);
9998
k
10099
}
101100

102101
pub fn new_lamp(&mut self, l: Lamp) -> InstanceId {
103-
let k = self.instances.insert(());
102+
let k = self.types.insert(InstanceKind::Lamp);
104103
self.lamps.insert(k, l);
105-
self.types.insert(k, InstanceKind::Lamp);
106104
k
107105
}
108106

109107
pub fn new_clock(&mut self, c: Clock) -> InstanceId {
110-
let k = self.instances.insert(());
108+
let k = self.types.insert(InstanceKind::Clock);
111109
self.clocks.insert(k, c);
112-
self.types.insert(k, InstanceKind::Clock);
113110
k
114111
}
115112

116113
pub fn new_module(&mut self, c: crate::module::Module) -> InstanceId {
117-
let k = self.instances.insert(());
118-
let definition_index = c.definition_index;
114+
let k = self.types.insert(InstanceKind::Module(c.definition_index));
119115
self.modules.insert(k, c);
120-
self.types.insert(k, InstanceKind::Module(definition_index));
121116
k
122117
}
123118

0 commit comments

Comments
 (0)