diff --git a/TODO.md b/TODO.md index 451feccd..ae20468b 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,3 @@ -extract `netConnect` - extract `netCleanUpWires` extract `netStep` extract `netRun` diff --git a/src/lang/defs/NodeDef.ts b/src/lang/defs/NodeDef.ts index 4949b25e..6015431f 100644 --- a/src/lang/defs/NodeDef.ts +++ b/src/lang/defs/NodeDef.ts @@ -1,5 +1,6 @@ import { Def } from "../def" import { Net, Node, createNode } from "../graph" +import { netConnect } from "../graph/netConnect" import { Mod } from "../mod" import { Rule } from "../rule" import { Type } from "../type" @@ -42,7 +43,7 @@ export class NodeDef extends Def { throw new Error(`I expect a port on top of the stack`) } - net.connect(top, port) + netConnect(net, top, port) } net.portStack.push(...node.output) diff --git a/src/lang/graph/Action.ts b/src/lang/graph/Action.ts index f93ea9bd..3b155f36 100644 --- a/src/lang/graph/Action.ts +++ b/src/lang/graph/Action.ts @@ -2,6 +2,7 @@ import { InternalError } from "../errors" import { Net, Node, Port } from "../graph" import { Mod } from "../mod" import { Rule } from "../rule" +import { netConnect } from "./netConnect" import { netRemoveEdge } from "./netRemoveEdge" import { netRemoveNode } from "./netRemoveNode" @@ -94,6 +95,6 @@ function reconnectOutput(net: Net, output: Array): void { while (net.portStack.length > 0) { const start = net.portStack.pop() as Port const end = output.pop() as Port - net.connect(start, end) + netConnect(net, start, end) } } diff --git a/src/lang/graph/Net.ts b/src/lang/graph/Net.ts index 43718ceb..6fac56a2 100644 --- a/src/lang/graph/Net.ts +++ b/src/lang/graph/Net.ts @@ -1,7 +1,8 @@ import { InternalError } from "../errors" -import { Action, Edge, Node, Port, createEdge } from "../graph" +import { Action, Edge, Node, Port } from "../graph" import { Mod } from "../mod" import { netCloseFreePorts } from "./netCloseFreePorts" +import { netConnect } from "./netConnect" import { netReleaseFreePorts } from "./netReleaseFreePorts" import { netRemoveEdge } from "./netRemoveEdge" import { netRemoveNode } from "./netRemoveNode" @@ -36,7 +37,7 @@ export class Net { netRemoveNode(this, wire.start.node) netRemoveNode(this, wire.end.node) - this.connect(wire.start.connection.port, wire.end.connection.port) + netConnect(this, wire.start.connection.port, wire.end.connection.port) } } @@ -52,14 +53,4 @@ export class Net { if (action === undefined) return else action.act(this.mod, this) } - - connect(start: Port, end: Port): void { - const rule = this.mod.getRuleByPorts(start, end) - - if (rule) { - this.actions.push(new Action(start, end, rule)) - } else { - this.edges.push(createEdge(start, end)) - } - } } diff --git a/src/lang/graph/netConnect.ts b/src/lang/graph/netConnect.ts new file mode 100644 index 00000000..71d8f335 --- /dev/null +++ b/src/lang/graph/netConnect.ts @@ -0,0 +1,11 @@ +import { Action, Net, Port, createEdge } from "../graph" + +export function netConnect(net: Net, start: Port, end: Port): void { + const rule = net.mod.getRuleByPorts(start, end) + + if (rule) { + net.actions.push(new Action(start, end, rule)) + } else { + net.edges.push(createEdge(start, end)) + } +} diff --git a/src/lang/mod/builtInOperators.ts b/src/lang/mod/builtInOperators.ts index 5e3f7bec..86b1b300 100644 --- a/src/lang/mod/builtInOperators.ts +++ b/src/lang/mod/builtInOperators.ts @@ -1,6 +1,7 @@ import { Mod } from "." import * as Defs from "../defs" import { Port } from "../graph" +import { netConnect } from "../graph/netConnect" import { buildTypes } from "../types" export function builtInOperators(mod: Mod): void { @@ -20,7 +21,7 @@ export function builtInOperators(mod: Mod): void { mod.defineOperator("connect", (net) => { const start = net.portStack.pop() as Port const end = net.portStack.pop() as Port - net.connect(start, end) + netConnect(net, start, end) }) mod.defineOperator("wire", (net) => {