Skip to content

Commit

Permalink
Node as value
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Sep 13, 2023
1 parent cc87a83 commit 91075d0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
`Node` as word
`Ports` as builtin
remove syntax of rearrange
update docs about using `@ports` to do rearrange

`(cons)` -- unconnected node as value -- redesign syntax of rearrange

```
Expand Down
8 changes: 7 additions & 1 deletion src/lang/net/addNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ export function addNode(
): Node {
const id = createNodeId(mod, name)

const node: Node = { id, url: mod.url, name }
const node: Node = {
"@type": "Value",
"@kind": "Node",
id,
url: mod.url,
name,
}

const ports: PortRecord = {}
net.nodeEntries.set(nodeKey(node), { id, url: mod.url, name, ports })
Expand Down
2 changes: 2 additions & 0 deletions src/lang/net/createNodeFromNodeEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { NodeEntry } from "./Net"

export function createNodeFromNodeEntry(nodeEntry: NodeEntry): Node {
return {
"@type": "Value",
"@kind": "Node",
id: nodeEntry.id,
name: nodeEntry.name,
url: nodeEntry.url,
Expand Down
2 changes: 2 additions & 0 deletions src/lang/node/Node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type Node = {
"@type": "Value"
"@kind": "Node"
id: string
url: URL
name: string
Expand Down
3 changes: 2 additions & 1 deletion src/lang/value/Value.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Node } from "../node"
import { Port } from "../port"

export type Value = Port | Type | Symbol | TypeTerm | Labeled
export type Value = Port | Node | Type | Symbol | TypeTerm | Labeled

export type Type = {
"@type": "Value"
Expand Down
4 changes: 4 additions & 0 deletions src/lang/value/formatValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function formatValue(value: Value): string {
}
}

case "Node": {
return `(${formatNode(value)})`
}

case "Type": {
return "Type"
}
Expand Down

0 comments on commit 91075d0

Please sign in to comment.