Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 28, 2023
1 parent 66cb956 commit 66144aa
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[mod] extract `modBuildNet`

`NodeDefinition` should not have `rules` -- use `RuleDefinition`

`Node` should not have `definition` -- which is used to `getRule`
Expand Down
2 changes: 1 addition & 1 deletion src/lang/definitions/NodeDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/lang/graph/netConnect.ts
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
16 changes: 8 additions & 8 deletions src/lang/mod/Mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand All @@ -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}`,
Expand All @@ -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}`,
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/lang/stmts/DefruleStmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class DefruleStmt extends Stmt {
}

async execute(mod: Mod): Promise<void> {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/lang/words/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 66144aa

Please sign in to comment.