@@ -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 ) ]
5356pub 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
7274impl 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