Skip to content

Commit

Permalink
capNodeAllPorts vs capNodeNonPrinciplePorts
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 30, 2023
1 parent af1ac0c commit d2cb264
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
17 changes: 17 additions & 0 deletions src/lang/cap/capNodeAllPorts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Mod } from "../mod"
import { Net } from "../net"
import { findInputPorts } from "../net/findInputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Node } from "../node"
import { capInputPort } from "./capInputPort"
import { capOutputPort } from "./capOutputPort"

export function capNodeAllPorts(mod: Mod, net: Net, node: Node): void {
for (const port of findInputPorts(net, node)) {
capInputPort(mod, net, port)
}

for (const port of findOutputPorts(net, node)) {
capOutputPort(mod, net, port)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Node } from "../node"
import { capInputPort } from "./capInputPort"
import { capOutputPort } from "./capOutputPort"

export function capNode(mod: Mod, net: Net, node: Node): void {
export function capNodeNonPrinciplePorts(mod: Mod, net: Net, node: Node): void {
for (const port of findInputPorts(net, node)) {
if (!port.isPrincipal) {
capInputPort(mod, net, port)
Expand Down
3 changes: 2 additions & 1 deletion src/lang/cap/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./capInputPort"
export * from "./capNode"
export * from "./capNodeAllPorts"
export * from "./capNodeNonPrinciplePorts"
export * from "./capOutputPort"
export * from "./capType"
6 changes: 3 additions & 3 deletions src/lang/check/checkRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capNode } from "../cap/capNode"
import { capNodeNonPrinciplePorts } from "../cap/capNodeNonPrinciplePorts"
import { createChecking } from "../checking/createChecking"
import { compose } from "../compose/compose"
import { createEnv } from "../env/createEnv"
Expand Down Expand Up @@ -33,8 +33,8 @@ export function checkRule(

refreshNode(env.net, checking.typeVarCounters, second)

capNode(mod, env.net, first)
capNode(mod, env.net, second)
capNodeNonPrinciplePorts(mod, env.net, first)
capNodeNonPrinciplePorts(mod, env.net, second)

for (const word of words) {
compose(mod, env, word, {
Expand Down
3 changes: 2 additions & 1 deletion src/lang/present/presentNodeAsNet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ end
const net = presentNodeAsNet(mod, "add")

expect(formatNet(net)).toMatchInlineSnapshot(`
"(add₀)-addend covering-(@input_port_cap₀)
"(add₀)-target covering-(@input_port_cap₀)
(add₀)-addend covering-(@input_port_cap₁)
(add₀)-return covering-(@ouput_port_cap₀)"
`)
})
4 changes: 2 additions & 2 deletions src/lang/present/presentNodeAsNet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capNode } from "../cap"
import { capNodeAllPorts } from "../cap"
import { Mod, lookupDefinitionOrFail } from "../mod"
import { Net, createNet } from "../net"
import { createNodeFromDefinition } from "../node/createNodeFromDefinition"
Expand All @@ -8,7 +8,7 @@ export function presentNodeAsNet(mod: Mod, nodeName: string): Net {

const definition = lookupDefinitionOrFail(mod, nodeName)
const node = createNodeFromDefinition(net, definition)
capNode(mod, net, node)
capNodeAllPorts(mod, net, node)

return net
}
16 changes: 3 additions & 13 deletions src/lang/present/presentRuleAsNets.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { capNode } from "../cap"
import { capNodeNonPrinciplePorts } from "../cap"
import { compose } from "../compose/compose"
import { connect } from "../connect/connect"
import { createEnv } from "../env/createEnv"
import { Mod, lookupDefinitionOrFail } from "../mod"
import { lookupRuleByName } from "../mod/lookupRuleByName"
import { Net, copyConnectedComponent, createNet } from "../net"
import { deleteNodeEntry } from "../net/deleteNodeEntry"
import { disconnectPort } from "../net/disconnectPort"
import { findPrincipalPort } from "../net/findPrincipalPort"
import { Node } from "../node"
import { createNodeFromDefinition } from "../node/createNodeFromDefinition"
Expand Down Expand Up @@ -37,8 +36,8 @@ export function presentRuleAsNets(mod: Mod, ruleName: string): [Net, Net] {
lookupDefinitionOrFail(mod, secondName),
)

capNode(mod, env.net, first)
capNode(mod, env.net, second)
capNodeNonPrinciplePorts(mod, env.net, first)
capNodeNonPrinciplePorts(mod, env.net, second)

const initial = collectInitialNet(env.net, first, second)

Expand All @@ -63,16 +62,7 @@ function collectInitialNet(net: Net, first: Node, second: Node): Net {
copyConnectedComponent(net, initial, second)

const firstPrincipalPort = findPrincipalPort(initial, first)
const firstConnectedPort = disconnectPort(initial, firstPrincipalPort)
if (firstConnectedPort) {
deleteNodeEntry(initial, firstConnectedPort.node)
}

const secondPrincipalPort = findPrincipalPort(initial, second)
const secondConnectedPort = disconnectPort(initial, secondPrincipalPort)
if (secondConnectedPort) {
deleteNodeEntry(initial, secondConnectedPort.node)
}

connect(initial, firstPrincipalPort, secondPrincipalPort)

Expand Down

0 comments on commit d2cb264

Please sign in to comment.