Skip to content

Commit

Permalink
placeholder -- rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Aug 17, 2023
1 parent b240035 commit b977a05
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/lang/check/checkRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { refreshNode } from "../freshen/refreshNode"
import { Mod } from "../mod"
import { lookupDefinitionOrFail } from "../mod/lookupDefinitionOrFail"
import { createNodeFromDefinition } from "../node/createNodeFromDefinition"
import { connectNodeWithPlaceholderPorts } from "../placeholder/connectNodeWithPlaceholderPorts"
import { connectPlaceholderPorts } from "../placeholder/connectPlaceholderPorts"
import { Word } from "../word"

export function checkRule(
Expand All @@ -32,8 +32,8 @@ export function checkRule(

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

connectNodeWithPlaceholderPorts(mod, env.net, first)
connectNodeWithPlaceholderPorts(mod, env.net, second)
connectPlaceholderPorts(mod, env.net, first)
connectPlaceholderPorts(mod, env.net, second)

for (const word of words) {
compose(mod, env, word, {
Expand Down
4 changes: 2 additions & 2 deletions src/lang/check/checkWords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { compose } from "../compose/compose"
import { createEnv } from "../env/createEnv"
import { freshenType } from "../freshen/freshenType"
import { Mod } from "../mod"
import { addPlaceholderOutputPortFromType } from "../placeholder/addPlaceholderOutputPortFromType"
import { createPlaceholderOutputPortForType } from "../placeholder/createPlaceholderOutputPortForType"
import { unifyTypes } from "../unify/unifyTypes"
import { formatValue } from "../value/formatValue"
import { Word } from "../word"
Expand All @@ -25,7 +25,7 @@ export function checkWords(

const placeholderOutputPorts = inputValues
.reverse()
.map((t) => addPlaceholderOutputPortFromType(env.net, mod, t))
.map((t) => createPlaceholderOutputPortForType(env.net, mod, t))

env.stack.push(...placeholderOutputPorts)

Expand Down
28 changes: 0 additions & 28 deletions src/lang/placeholder/connectNodeWithPlaceholderPorts.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { connect } from "../connect/connect"
import { Mod } from "../mod"
import { Net } from "../net"
import { addNode } from "../net/addNode"
import { findInputPorts } from "../net/findInputPorts"
import { Port } from "../port"

export function addPlaceholderInputPortForPort(
export function connectPlaceholderInputPort(
net: Net,
mod: Mod,
port: Port,
Expand All @@ -26,5 +27,9 @@ export function addPlaceholderInputPortForPort(
[],
)

return findInputPorts(net, node)[0]
const placeholderPort = findInputPorts(net, node)[0]

connect(net, port, placeholderPort)

return placeholderPort
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { connect } from "../connect/connect"
import { Mod } from "../mod"
import { Net } from "../net"
import { addNode } from "../net/addNode"
import { findOutputPorts } from "../net/findOutputPorts"
import { Port } from "../port"

export function addPlaceholderOutputPortForPort(
export function connectPlaceholderOutputPort(
net: Net,
mod: Mod,
port: Port,
Expand All @@ -26,5 +27,9 @@ export function addPlaceholderOutputPortForPort(
],
)

return findOutputPorts(net, node)[0]
const placeholderPort = findOutputPorts(net, node)[0]

connect(net, port, placeholderPort)

return placeholderPort
}
21 changes: 21 additions & 0 deletions src/lang/placeholder/connectPlaceholderPorts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Mod } from "../mod"
import { Net } from "../net"
import { findInputPorts } from "../net/findInputPorts"
import { findOutputPorts } from "../net/findOutputPorts"
import { Node } from "../node"
import { connectPlaceholderInputPort } from "./connectPlaceholderInputPort"
import { connectPlaceholderOutputPort } from "./connectPlaceholderOutputPort"

export function connectPlaceholderPorts(mod: Mod, net: Net, node: Node): void {
for (const port of findInputPorts(net, node)) {
if (!port.isPrincipal) {
connectPlaceholderOutputPort(net, mod, port)
}
}

for (const port of findOutputPorts(net, node)) {
if (!port.isPrincipal) {
connectPlaceholderInputPort(net, mod, port)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { findOutputPorts } from "../net/findOutputPorts"
import { Port } from "../port"
import { Value } from "../value"

export function addPlaceholderOutputPortFromType(
export function createPlaceholderOutputPortForType(
net: Net,
mod: Mod,
t: Value,
Expand Down
16 changes: 16 additions & 0 deletions src/lang/run/closeFreePorts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ export function closeFreePorts(env: Env): Node | undefined {
return undefined
}

// const temporaryPorts: Array<Port> = []
// for (const nodeEntry of env.net.nodeEntries) {
// for (const port of nodeEntry.ports) {
// if (port.connection === undefined) {
// switch (port.sign) {
// case 1: {
// addPlaceholderInputPortForPort(env.mod, env.net, port)
// }
// case -1: {
// addPlaceholderOutputPortForPort(env.mod, env.net, port)
// }
// }
// }
// }
// }

const ports = env.stack
.filter((value): value is Port => value["@kind"] === "Port")
.map<PortExp>((port) => ({
Expand Down

0 comments on commit b977a05

Please sign in to comment.