Skip to content

Commit

Permalink
fix connect
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 1, 2023
1 parent 7eba58f commit 007f7c6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/lang/connect/connect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { checkPortSigns } from "../check/checkPortSigns"
import { edgeEqual } from "../edge/edgeEqual"
import { Net } from "../net"
import { findPortEntry } from "../net/findPortEntry"
import { findPortRecordOrFail } from "../net/findPortRecordOrFail"
Expand Down Expand Up @@ -48,7 +49,11 @@ export function connect(net: Net, first: Port, second: Port): void {
const secondPortRecord = findPortRecordOrFail(net, second.node)
secondPortRecord[second.name].connection = { port: first }

if (first.isPrincipal && second.isPrincipal) {
if (
first.isPrincipal &&
second.isPrincipal &&
!net.activeEdges.find((edge) => edgeEqual(edge, { first, second }))
) {
net.activeEdges.push(edge)
}
}
9 changes: 9 additions & 0 deletions src/lang/edge/edgeEqual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { portEqual } from "../port/portEqual"
import { Edge } from "./Edge"

export function edgeEqual(x: Edge, y: Edge): boolean {
return (
(portEqual(x.first, y.first) && portEqual(x.second, y.second)) ||
(portEqual(x.first, y.second) && portEqual(x.second, y.first))
)
}
5 changes: 5 additions & 0 deletions src/lang/node/nodeEqual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Node } from "./Node"

export function nodeEqual(x: Node, y: Node): boolean {
return x.name === y.name && x.id === y.id
}
6 changes: 6 additions & 0 deletions src/lang/port/portEqual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { nodeEqual } from "../node/nodeEqual"
import { Port } from "./Port"

export function portEqual(x: Port, y: Port): boolean {
return nodeEqual(x.node, y.node) && x.name === y.name
}
2 changes: 1 addition & 1 deletion tests/statement/define-without-claim.error.i.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[lookupDefinitionOrFail] I meet undefined name.
[findDefinitionOrFail] I meet undefined name.

name: swapswap

Expand Down
2 changes: 1 addition & 1 deletion tests/statement/rule-before-node.error.i.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[lookupDefinitionOrFail] I meet undefined name.
[findDefinitionOrFail] I meet undefined name.

name: add

Expand Down

0 comments on commit 007f7c6

Please sign in to comment.