Skip to content

Commit

Permalink
rename Action to ActiveEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 29, 2023
1 parent 8563f72 commit f111373
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 31 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
quit using `Action`
[graph] extract `interact`

`Action` should be type instead of class
quit using `ActiveEdge`

`ActiveEdge` should be type instead of class

use new syntax

Expand Down
28 changes: 12 additions & 16 deletions docs/mimors/interaction-nets.mimor
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
<metadata theme-color="white" />
<metadata theme-color="indigo" />

<front-cover>
Notes about the 1990 "Interaction Nets" paper, by Yves Lafont.
Notes about the 1990 "Interaction Nets" paper by Yves Lafont
</front-cover>

<cloze>
Interaction net (INet) is a computation model
based on <blank>(indirected) graph</blank>.
</cloze>

<question>
What is interaction net (inet)?
What is computation?

<answer>
Interaction net is a linear computation model
based (indirected) graph.
Computation is directed changes.
</answer>
</question>

<question>
What is a computation model?

<answer>
Computation is directed changes.

A computation model is a group of rules about how to change.

An initial state is a program,
let it start changing by the rules,
is computation.
</answer>
</question>

<question>
What does "linear" mean in "linear computation model"?
What is a program?

<answer>
Linear means when a variable is used,
the value in the variable is taken out,
to use the variable again,
a new value must be put in.
A program is an initial state of a computation model,
ready to change.
</answer>
</question>
4 changes: 2 additions & 2 deletions src/lang/graph/Action.ts → src/lang/graph/ActiveEdge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { netConnect } from "./netConnect"
import { netRemoveEdge } from "./netRemoveEdge"
import { netRemoveNode } from "./netRemoveNode"

export class Action {
export class ActiveEdge {
constructor(
public start: Port,
public end: Port,
public rule: Rule,
) {}

act(mod: Mod, net: Net): void {
interact(mod: Mod, net: Net): void {
// NOTE The state of action.
const input: Array<Port> = []
const output: Array<Port> = []
Expand Down
4 changes: 2 additions & 2 deletions src/lang/graph/Net.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Action, Edge, Node, Port } from "../graph"
import { ActiveEdge, Edge, Node, Port } from "../graph"
import { Mod } from "../mod"

export type Net = {
mod: Mod
nodes: Array<Node>
edges: Array<Edge>
actions: Array<Action>
activeEdges: Array<ActiveEdge>
portStack: Array<Port>
// for named local variables.
portStore: Map<string, Port>
Expand Down
2 changes: 1 addition & 1 deletion src/lang/graph/createNet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function createNet(mod: Mod): Net {
mod,
nodes: [],
edges: [],
actions: [],
activeEdges: [],
portStack: [],
portStore: new Map(),
wires: [],
Expand Down
2 changes: 1 addition & 1 deletion src/lang/graph/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./Action"
export * from "./ActiveEdge"
export * from "./Edge"
export * from "./Net"
export * from "./Node"
Expand Down
4 changes: 2 additions & 2 deletions src/lang/graph/netConnect.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Action, Net, Port, createEdge } from "../graph"
import { ActiveEdge, Net, Port, createEdge } from "../graph"
import { lookupRuleByPorts } from "../mod/lookupRuleByPorts"

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

if (rule) {
net.actions.push(new Action(start, end, rule))
net.activeEdges.push(new ActiveEdge(start, end, rule))
} else {
net.edges.push(createEdge(start, end))
}
Expand Down
8 changes: 4 additions & 4 deletions src/lang/graph/netRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { netReleaseFreePorts } from "./netReleaseFreePorts"
export function netRun(net: Net): void {
const closer = netCloseFreePorts(net)

while (net.actions.length > 0) {
while (net.activeEdges.length > 0) {
netStep(net)
}

Expand All @@ -20,10 +20,10 @@ function netStep(net: Net): void {
throw new InternalError("I can not handle free port during stepping.")
}

const action = net.actions.pop()
if (action === undefined) {
const activeEdge = net.activeEdges.pop()
if (activeEdge === undefined) {
return
} else {
action.act(net.mod, net)
activeEdge.interact(net.mod, net)
}
}
2 changes: 1 addition & 1 deletion src/renderers/NetRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class NetRenderer {
lines.push(`${end}`)
}

for (const edge of net.actions) {
for (const edge of net.activeEdges) {
const start = formatNode(edge.start.node)
const end = formatNode(edge.end.node)
const indexes = `${edge.end.index}-${edge.start.index}`
Expand Down

0 comments on commit f111373

Please sign in to comment.