Sandbox: Fix incorrect assumption that wire net ignores output pegs
In fact, if a wire is connected to an output peg, it has the same net state as the output peg. The net then changes between the wire and the input peg that it connects to.
This commit is contained in:
parent
da9d0fe09b
commit
4234140165
1 changed files with 41 additions and 11 deletions
|
|
@ -168,15 +168,32 @@ impl Sandbox {
|
||||||
// wire all have the same net.
|
// wire all have the same net.
|
||||||
|
|
||||||
//TODO bubble this error
|
//TODO bubble this error
|
||||||
assert!(id == peg_a.net_id && id == peg_b.net_id);
|
assert!(
|
||||||
|
(addr_a.peg_type == PegType::Output || id == peg_b.net_id)
|
||||||
|
&& (addr_b.peg_type == PegType::Output || id == peg_a.net_id),
|
||||||
|
"{:?}\n{:?} {:?}\n{:?} {:?}",
|
||||||
|
id,
|
||||||
|
peg_a.net_id,
|
||||||
|
addr_a,
|
||||||
|
peg_b.net_id,
|
||||||
|
addr_b
|
||||||
|
);
|
||||||
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// If no net ID is given (i.e. caller is `add_wire`), then
|
// If no net ID is given (i.e. caller is `add_wire`), then:
|
||||||
// obtain one from merging the two endpoints.
|
|
||||||
|
// If one of the pegs is an output, use that peg's ID.
|
||||||
|
if addr_a.peg_type == PegType::Output {
|
||||||
|
peg_a.net_id
|
||||||
|
} else if addr_b.peg_type == PegType::Output {
|
||||||
|
peg_b.net_id
|
||||||
|
} else {
|
||||||
|
// If both pegs are inputs, obtain one net from merging the two.
|
||||||
self.merge_nets(peg_a.net_id, peg_b.net_id)
|
self.merge_nets(peg_a.net_id, peg_b.net_id)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create wire.
|
// Create wire.
|
||||||
|
|
@ -362,14 +379,27 @@ impl Sandbox {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_split(&mut self, addr_a: &PegAddress, addr_b: &PegAddress) {
|
fn check_split(&mut self, addr_a: &PegAddress, addr_b: &PegAddress) {
|
||||||
if self.get_peg(addr_a).is_none() || self.get_peg(addr_b).is_none() {
|
match (self.get_peg(addr_a), self.get_peg(addr_b)) {
|
||||||
// At least one of the pegs does not exist - nothing needs to be split.
|
(None, _) | (_, None) => {
|
||||||
|
// At least one of the pegs does not exist - nothing needs to be
|
||||||
|
// split.
|
||||||
//
|
//
|
||||||
// This can happen while a component is being removed; its pegs are
|
// This can happen while a component is being removed; its pegs
|
||||||
// also being removed and any wires connected to them, and so they
|
// are also being removed and any wires connected to them, and
|
||||||
// will not need a new net.
|
// so they will not need a new net.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
(Some(peg_a), Some(peg_b)) if peg_a.net_id != peg_b.net_id => {
|
||||||
|
// The pegs do not have the same net ID. This happens when one
|
||||||
|
// of them is an output peg (however, they cannot _both_ be output pegs.
|
||||||
|
assert!(addr_a.peg_type != addr_b.peg_type);
|
||||||
|
// In this case, nothing needs to be split.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// In any other case, we need to split.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Traverse the whole net connected to addr_a.
|
// Traverse the whole net connected to addr_a.
|
||||||
// If addr_b is in that set, then they are connected.
|
// If addr_b is in that set, then they are connected.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue