diff --git a/TODO.md b/TODO.md index 58b23257..1e7057aa 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,5 @@ +[mod] extract `modBuildNet` + `NodeDefinition` should not have `rules` -- use `RuleDefinition` `Node` should not have `definition` -- which is used to `getRule` diff --git a/src/lang/definitions/NodeDefinition.ts b/src/lang/definitions/NodeDefinition.ts index c8688fdc..217ae2e0 100644 --- a/src/lang/definitions/NodeDefinition.ts +++ b/src/lang/definitions/NodeDefinition.ts @@ -28,7 +28,7 @@ export class NodeDefinition extends Definition { this.rules.set(end.fullName, rule) } - getRule(end: NodeDefinition): Rule | undefined { + lookupRule(end: NodeDefinition): Rule | undefined { return this.rules.get(end.fullName) } diff --git a/src/lang/graph/netConnect.ts b/src/lang/graph/netConnect.ts index 71d8f335..4ac9b849 100644 --- a/src/lang/graph/netConnect.ts +++ b/src/lang/graph/netConnect.ts @@ -1,7 +1,7 @@ import { Action, Net, Port, createEdge } from "../graph" export function netConnect(net: Net, start: Port, end: Port): void { - const rule = net.mod.getRuleByPorts(start, end) + const rule = net.mod.lookupRuleByPorts(start, end) if (rule) { net.actions.push(new Action(start, end, rule)) diff --git a/src/lang/mod/Mod.ts b/src/lang/mod/Mod.ts index ea0e99ce..3e65e827 100644 --- a/src/lang/mod/Mod.ts +++ b/src/lang/mod/Mod.ts @@ -13,7 +13,7 @@ export class Mod { defineBuiltInOperators(this) } - getDefinitionOrFail(name: string): Definition { + lookupDefinitionOrFail(name: string): Definition { const definition = this.definitions.get(name) if (definition === undefined) { throw new Error(`Undefined name: ${name}`) @@ -22,8 +22,8 @@ export class Mod { return definition } - getNodeDefinitionOrFail(name: string): Definitions.NodeDefinition { - const definition = this.getDefinitionOrFail(name) + lookupNodeDefinitionOrFail(name: string): Definitions.NodeDefinition { + const definition = this.lookupDefinitionOrFail(name) if (!(definition instanceof Definitions.NodeDefinition)) { throw new Error( `I expect a node definition, but ${name} is ${definition.constructor.name}`, @@ -33,8 +33,8 @@ export class Mod { return definition } - private getNetDefinitionOrFail(name: string): Definitions.NetDefinition { - const definition = this.getDefinitionOrFail(name) + private lookupNetDefinitionOrFail(name: string): Definitions.NetDefinition { + const definition = this.lookupDefinitionOrFail(name) if (!(definition instanceof Definitions.NetDefinition)) { throw new Error( `I expect a net definition, but ${name} is ${definition.constructor.name}`, @@ -44,15 +44,15 @@ export class Mod { return definition } - getRuleByPorts(start: Port, end: Port): Rule | undefined { + lookupRuleByPorts(start: Port, end: Port): Rule | undefined { if (start.isPrincipal && end.isPrincipal) { - return start.node.definition.getRule(end.node.definition) + return start.node.definition.lookupRule(end.node.definition) } } buildNet(name: string): Net { const net = createNet(this) - this.getNetDefinitionOrFail(name).meaning(net) + this.lookupNetDefinitionOrFail(name).meaning(net) netCleanUpWires(net) return net } diff --git a/src/lang/stmts/DefruleStmt.ts b/src/lang/stmts/DefruleStmt.ts index 4c1dd112..ae25942d 100644 --- a/src/lang/stmts/DefruleStmt.ts +++ b/src/lang/stmts/DefruleStmt.ts @@ -15,8 +15,8 @@ export class DefruleStmt extends Stmt { } async execute(mod: Mod): Promise { - const startNodeDefinition = mod.getNodeDefinitionOrFail(this.start) - const endNodeDefinition = mod.getNodeDefinitionOrFail(this.end) + const startNodeDefinition = mod.lookupNodeDefinitionOrFail(this.start) + const endNodeDefinition = mod.lookupNodeDefinitionOrFail(this.end) startNodeDefinition.defineRule( endNodeDefinition, diff --git a/src/lang/words/Call.ts b/src/lang/words/Call.ts index df71cfb5..21ccacb7 100644 --- a/src/lang/words/Call.ts +++ b/src/lang/words/Call.ts @@ -17,7 +17,7 @@ export class Call extends Word { net.portStore.delete(this.name) net.portStack.push(found) } else { - mod.getDefinitionOrFail(this.name).meaning(net) + mod.lookupDefinitionOrFail(this.name).meaning(net) } } }