Skip to content

Commit

Permalink
[mod] drop mod prefix of lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 29, 2023
1 parent 5abd727 commit 1c3d96f
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 22 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[mod] drop mod prefix of lookup

`NodeDefinition.fullName`

`Node` should not have `definition` -- which is used to `lookupRule`
Expand Down
4 changes: 2 additions & 2 deletions src/lang/graph/netConnect.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Action, Net, Port, createEdge } from "../graph"
import { modLookupRuleByPorts } from "../mod/modLookupRuleByPorts"
import { lookupRuleByPorts } from "../mod/lookupRuleByPorts"

export function netConnect(net: Net, start: Port, end: Port): void {
const rule = modLookupRuleByPorts(net.mod, start, end)
const rule = lookupRuleByPorts(net.mod, start, end)

if (rule) {
net.actions.push(new Action(start, end, rule))
Expand Down
6 changes: 3 additions & 3 deletions src/lang/mod/defineRule.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Rule } from "../rule"
import { Word } from "../word"
import { Mod } from "./Mod"
import { modLookupNodeDefinitionOrFail } from "./modLookupNodeDefinitionOrFail"
import { lookupNodeDefinitionOrFail } from "./lookupNodeDefinitionOrFail"

export function defineRule(
mod: Mod,
Expand All @@ -13,8 +13,8 @@ export function defineRule(
`${start} ${end}`,
new Rule(
mod,
modLookupNodeDefinitionOrFail(mod, start),
modLookupNodeDefinitionOrFail(mod, end),
lookupNodeDefinitionOrFail(mod, start),
lookupNodeDefinitionOrFail(mod, end),
words,
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Definition } from "../definition"
import { Mod } from "./Mod"

export function modLookupDefinitionOrFail(mod: Mod, name: string): Definition {
export function lookupDefinitionOrFail(mod: Mod, name: string): Definition {
const definition = mod.definitions.get(name)
if (definition === undefined) {
throw new Error(`Undefined name: ${name}`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Definitions from "../definitions"
import { Mod } from "./Mod"
import { modLookupDefinitionOrFail } from "./modLookupDefinitionOrFail"
import { lookupDefinitionOrFail } from "./lookupDefinitionOrFail"

export function modLookupNetDefinitionOrFail(
export function lookupNetDefinitionOrFail(
mod: Mod,
name: string,
): Definitions.NetDefinition {
const definition = modLookupDefinitionOrFail(mod, name)
const definition = lookupDefinitionOrFail(mod, name)
if (!(definition instanceof Definitions.NetDefinition)) {
throw new Error(
`I expect a net definition, but ${name} is ${definition.constructor.name}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Definitions from "../definitions"
import { Mod } from "./Mod"
import { modLookupDefinitionOrFail } from "./modLookupDefinitionOrFail"
import { lookupDefinitionOrFail } from "./lookupDefinitionOrFail"

export function modLookupNodeDefinitionOrFail(
export function lookupNodeDefinitionOrFail(
mod: Mod,
name: string,
): Definitions.NodeDefinition {
const definition = modLookupDefinitionOrFail(mod, name)
const definition = lookupDefinitionOrFail(mod, name)
if (!(definition instanceof Definitions.NodeDefinition)) {
throw new Error(
`I expect a node definition, but ${name} is ${definition.constructor.name}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Rule } from "../rule"
import { Mod } from "./Mod"

export function modLookupRule(
export function lookupRule(
mod: Mod,
start: string,
end: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Port } from "../graph"
import { Rule } from "../rule"
import { Mod } from "./Mod"
import { modLookupRule } from "./modLookupRule"
import { lookupRule } from "./lookupRule"

export function modLookupRuleByPorts(
export function lookupRuleByPorts(
mod: Mod,
start: Port,
end: Port,
): Rule | undefined {
if (start.isPrincipal && end.isPrincipal) {
return modLookupRule(mod, start.node.name, end.node.name)
return lookupRule(mod, start.node.name, end.node.name)
}
}
4 changes: 2 additions & 2 deletions src/lang/mod/modBuildNet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Net } from "../graph"
import { createNet } from "../graph/createNet"
import { netCleanUpWires } from "../graph/netCleanUpWires"
import { Mod } from "./Mod"
import { modLookupNetDefinitionOrFail } from "./modLookupNetDefinitionOrFail"
import { lookupNetDefinitionOrFail } from "./lookupNetDefinitionOrFail"

export function modBuildNet(mod: Mod, name: string): Net {
const net = createNet(mod)
modLookupNetDefinitionOrFail(mod, name).meaning(net)
lookupNetDefinitionOrFail(mod, name).meaning(net)
netCleanUpWires(net)
return net
}
4 changes: 2 additions & 2 deletions src/lang/words/Call.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Net } from "../graph"
import { Mod } from "../mod"
import { modLookupDefinitionOrFail } from "../mod/modLookupDefinitionOrFail"
import { lookupDefinitionOrFail } from "../mod/lookupDefinitionOrFail"
import { Span } from "../span"
import { Word } from "../word"

Expand All @@ -16,7 +16,7 @@ export class Call implements Word {
net.portStore.delete(this.name)
net.portStack.push(found)
} else {
modLookupDefinitionOrFail(mod, this.name).meaning(net)
lookupDefinitionOrFail(mod, this.name).meaning(net)
}
}
}

0 comments on commit 1c3d96f

Please sign in to comment.