Skip to content

Commit

Permalink
NetRenderer -- format to simple text
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Jul 28, 2023
1 parent db5e66a commit 50c7846
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 22 deletions.
22 changes: 21 additions & 1 deletion docs/tests/diff-list.inet.one-two-soles.finial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#8" -- "sole#7" [label="1-0"]; "sole#7"; "cons#8"; "cons#8" -- "cons#6" [label="0-2"]; "cons#6"; "cons#8"; "diff#13" -- "cons#8" [label="1-2"]; "cons#8"; "diff#13"; "cons#6" -- "cons#2" [label="0-0"]; "cons#2"; "cons#6"; "diff#13" -- "cons#2" [label="0-2"]; "cons#2"; "diff#13"; "diff#13(2)" -- "diff#13"; "diff#13"; "diff#13(2)"; }
cons#2 -- sole#1 [label="1-0"]
sole#1
cons#2
cons#6 -- sole#5 [label="1-0"]
sole#5
cons#6
cons#8 -- sole#7 [label="1-0"]
sole#7
cons#8
cons#8 -- cons#6 [label="0-2"]
cons#6
cons#8
diff#13 -- cons#8 [label="1-2"]
cons#8
diff#13
cons#6 -- cons#2 [label="0-0"]
cons#2
cons#6
diff#13 -- cons#2 [label="0-2"]
cons#2
diff#13
31 changes: 30 additions & 1 deletion docs/tests/diff-list.inet.one-two-soles.initial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "diff#3" -- "cons#2" [label="1-2"]; "cons#2"; "diff#3"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#8" -- "sole#7" [label="1-0"]; "sole#7"; "cons#8"; "cons#8" -- "cons#6" [label="0-2"]; "cons#6"; "cons#8"; "diff#9" -- "cons#8" [label="1-2"]; "cons#8"; "diff#9"; "diff-append#10" -- "diff#3" [label="0-2"]; "diff#3"; "diff-append#10"; "cons#2" -- "diff#3" [label="0-0"]; "diff#3"; "cons#2"; "cons#6" -- "diff#9" [label="0-0"]; "diff#9"; "cons#6"; "diff-append#10" -- "diff#9" [label="1-2" color=red]; "diff#9"; "diff-append#10"; "diff-append#10(2)" -- "diff-append#10"; "diff-append#10"; "diff-append#10(2)"; }
cons#2 -- sole#1 [label="1-0"]
sole#1
cons#2
diff#3 -- cons#2 [label="1-2"]
cons#2
diff#3
cons#6 -- sole#5 [label="1-0"]
sole#5
cons#6
cons#8 -- sole#7 [label="1-0"]
sole#7
cons#8
cons#8 -- cons#6 [label="0-2"]
cons#6
cons#8
diff#9 -- cons#8 [label="1-2"]
cons#8
diff#9
diff-append#10 -- diff#3 [label="0-2"]
diff#3
diff-append#10
cons#2 -- diff#3 [label="0-0"]
diff#3
cons#2
cons#6 -- diff#9 [label="0-0"]
diff#9
cons#6
diff-append#10 -- diff#9 [label="1-2" color=red]
diff#9
diff-append#10
28 changes: 27 additions & 1 deletion docs/tests/diff-list.inet.two-two-soles.finial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
graph { "cons#16" -- "sole#15" [label="1-0"]; "sole#15"; "cons#16"; "cons#18" -- "sole#17" [label="1-0"]; "sole#17"; "cons#18"; "cons#18" -- "cons#16" [label="0-2"]; "cons#16"; "cons#18"; "cons#22" -- "sole#21" [label="1-0"]; "sole#21"; "cons#22"; "cons#24" -- "sole#23" [label="1-0"]; "sole#23"; "cons#24"; "cons#24" -- "cons#22" [label="0-2"]; "cons#22"; "cons#24"; "diff#29" -- "cons#24" [label="1-2"]; "cons#24"; "diff#29"; "cons#22" -- "cons#16" [label="0-0"]; "cons#16"; "cons#22"; "diff#29" -- "cons#18" [label="0-2"]; "cons#18"; "diff#29"; "diff#29(2)" -- "diff#29"; "diff#29"; "diff#29(2)"; }
cons#16 -- sole#15 [label="1-0"]
sole#15
cons#16
cons#18 -- sole#17 [label="1-0"]
sole#17
cons#18
cons#18 -- cons#16 [label="0-2"]
cons#16
cons#18
cons#22 -- sole#21 [label="1-0"]
sole#21
cons#22
cons#24 -- sole#23 [label="1-0"]
sole#23
cons#24
cons#24 -- cons#22 [label="0-2"]
cons#22
cons#24
diff#29 -- cons#24 [label="1-2"]
cons#24
diff#29
cons#22 -- cons#16 [label="0-0"]
cons#16
cons#22
diff#29 -- cons#18 [label="0-2"]
cons#18
diff#29
37 changes: 36 additions & 1 deletion docs/tests/diff-list.inet.two-two-soles.initial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
graph { "cons#16" -- "sole#15" [label="1-0"]; "sole#15"; "cons#16"; "cons#18" -- "sole#17" [label="1-0"]; "sole#17"; "cons#18"; "cons#18" -- "cons#16" [label="0-2"]; "cons#16"; "cons#18"; "diff#19" -- "cons#18" [label="1-2"]; "cons#18"; "diff#19"; "cons#22" -- "sole#21" [label="1-0"]; "sole#21"; "cons#22"; "cons#24" -- "sole#23" [label="1-0"]; "sole#23"; "cons#24"; "cons#24" -- "cons#22" [label="0-2"]; "cons#22"; "cons#24"; "diff#25" -- "cons#24" [label="1-2"]; "cons#24"; "diff#25"; "diff-append#26" -- "diff#19" [label="0-2"]; "diff#19"; "diff-append#26"; "cons#16" -- "diff#19" [label="0-0"]; "diff#19"; "cons#16"; "cons#22" -- "diff#25" [label="0-0"]; "diff#25"; "cons#22"; "diff-append#26" -- "diff#25" [label="1-2" color=red]; "diff#25"; "diff-append#26"; "diff-append#26(2)" -- "diff-append#26"; "diff-append#26"; "diff-append#26(2)"; }
cons#16 -- sole#15 [label="1-0"]
sole#15
cons#16
cons#18 -- sole#17 [label="1-0"]
sole#17
cons#18
cons#18 -- cons#16 [label="0-2"]
cons#16
cons#18
diff#19 -- cons#18 [label="1-2"]
cons#18
diff#19
cons#22 -- sole#21 [label="1-0"]
sole#21
cons#22
cons#24 -- sole#23 [label="1-0"]
sole#23
cons#24
cons#24 -- cons#22 [label="0-2"]
cons#22
cons#24
diff#25 -- cons#24 [label="1-2"]
cons#24
diff#25
diff-append#26 -- diff#19 [label="0-2"]
diff#19
diff-append#26
cons#16 -- diff#19 [label="0-0"]
diff#19
cons#16
cons#22 -- diff#25 [label="0-0"]
diff#25
cons#22
diff-append#26 -- diff#25 [label="1-2" color=red]
diff#25
diff-append#26
37 changes: 36 additions & 1 deletion docs/tests/list.inet.six-soles.finial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "cons#2" -- "null#0" [label="0-0"]; "null#0"; "cons#2"; "cons#4" -- "sole#3" [label="1-0"]; "sole#3"; "cons#4"; "cons#4" -- "cons#2" [label="0-2"]; "cons#2"; "cons#4"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#6" -- "cons#4" [label="0-2"]; "cons#4"; "cons#6"; "cons#17" -- "sole#12" [label="1-0"]; "sole#12"; "cons#17"; "cons#19" -- "sole#10" [label="1-0"]; "sole#10"; "cons#19"; "cons#17" -- "cons#19" [label="0-2"]; "cons#19"; "cons#17"; "cons#21" -- "sole#8" [label="1-0"]; "sole#8"; "cons#21"; "cons#19" -- "cons#21" [label="0-2"]; "cons#21"; "cons#19"; "cons#21" -- "cons#6" [label="0-2"]; "cons#6"; "cons#21"; "cons#17(2)" -- "cons#17"; "cons#17"; "cons#17(2)"; }
cons#2 -- sole#1 [label="1-0"]
sole#1
cons#2
cons#2 -- null#0 [label="0-0"]
null#0
cons#2
cons#4 -- sole#3 [label="1-0"]
sole#3
cons#4
cons#4 -- cons#2 [label="0-2"]
cons#2
cons#4
cons#6 -- sole#5 [label="1-0"]
sole#5
cons#6
cons#6 -- cons#4 [label="0-2"]
cons#4
cons#6
cons#17 -- sole#12 [label="1-0"]
sole#12
cons#17
cons#19 -- sole#10 [label="1-0"]
sole#10
cons#19
cons#17 -- cons#19 [label="0-2"]
cons#19
cons#17
cons#21 -- sole#8 [label="1-0"]
sole#8
cons#21
cons#19 -- cons#21 [label="0-2"]
cons#21
cons#19
cons#21 -- cons#6 [label="0-2"]
cons#6
cons#21
43 changes: 42 additions & 1 deletion docs/tests/list.inet.six-soles.initial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
graph { "cons#2" -- "sole#1" [label="1-0"]; "sole#1"; "cons#2"; "cons#2" -- "null#0" [label="0-0"]; "null#0"; "cons#2"; "cons#4" -- "sole#3" [label="1-0"]; "sole#3"; "cons#4"; "cons#4" -- "cons#2" [label="0-2"]; "cons#2"; "cons#4"; "cons#6" -- "sole#5" [label="1-0"]; "sole#5"; "cons#6"; "cons#6" -- "cons#4" [label="0-2"]; "cons#4"; "cons#6"; "cons#9" -- "sole#8" [label="1-0"]; "sole#8"; "cons#9"; "cons#9" -- "null#7" [label="0-0"]; "null#7"; "cons#9"; "cons#11" -- "sole#10" [label="1-0"]; "sole#10"; "cons#11"; "cons#11" -- "cons#9" [label="0-2"]; "cons#9"; "cons#11"; "cons#13" -- "sole#12" [label="1-0"]; "sole#12"; "cons#13"; "cons#13" -- "cons#11" [label="0-2"]; "cons#11"; "cons#13"; "append#14" -- "cons#6" [label="0-2"]; "cons#6"; "append#14"; "append#14" -- "cons#13" [label="1-2" color=red]; "cons#13"; "append#14"; "append#14(2)" -- "append#14"; "append#14"; "append#14(2)"; }
cons#2 -- sole#1 [label="1-0"]
sole#1
cons#2
cons#2 -- null#0 [label="0-0"]
null#0
cons#2
cons#4 -- sole#3 [label="1-0"]
sole#3
cons#4
cons#4 -- cons#2 [label="0-2"]
cons#2
cons#4
cons#6 -- sole#5 [label="1-0"]
sole#5
cons#6
cons#6 -- cons#4 [label="0-2"]
cons#4
cons#6
cons#9 -- sole#8 [label="1-0"]
sole#8
cons#9
cons#9 -- null#7 [label="0-0"]
null#7
cons#9
cons#11 -- sole#10 [label="1-0"]
sole#10
cons#11
cons#11 -- cons#9 [label="0-2"]
cons#9
cons#11
cons#13 -- sole#12 [label="1-0"]
sole#12
cons#13
cons#13 -- cons#11 [label="0-2"]
cons#11
cons#13
append#14 -- cons#6 [label="0-2"]
cons#6
append#14
append#14 -- cons#13 [label="1-2" color=red]
cons#13
append#14
13 changes: 12 additions & 1 deletion docs/tests/nat.inet.four.finial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
graph { "add1#9" -- "zero#8" [label="0-0"]; "zero#8"; "add1#9"; "add1#23" -- "add1#25" [label="0-1"]; "add1#25"; "add1#23"; "add1#25" -- "add1#27" [label="0-1"]; "add1#27"; "add1#25"; "add1#27" -- "add1#9" [label="0-1"]; "add1#9"; "add1#27"; "add1#23(1)" -- "add1#23"; "add1#23"; "add1#23(1)"; }
add1#9 -- zero#8 [label="0-0"]
zero#8
add1#9
add1#23 -- add1#25 [label="0-1"]
add1#25
add1#23
add1#25 -- add1#27 [label="0-1"]
add1#27
add1#25
add1#27 -- add1#9 [label="0-1"]
add1#9
add1#27
31 changes: 30 additions & 1 deletion docs/tests/nat.inet.four.initial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
graph { "add1#9" -- "zero#8" [label="0-0"]; "zero#8"; "add1#9"; "add1#11" -- "zero#10" [label="0-0"]; "zero#10"; "add1#11"; "add#12" -- "add1#9" [label="0-1"]; "add1#9"; "add#12"; "add1#14" -- "zero#13" [label="0-0"]; "zero#13"; "add1#14"; "add1#16" -- "zero#15" [label="0-0"]; "zero#15"; "add1#16"; "add#17" -- "add1#14" [label="0-1"]; "add1#14"; "add#17"; "add#18" -- "add#17" [label="1-2"]; "add#17"; "add#18"; "add#18" -- "add#12" [label="0-2"]; "add#12"; "add#18"; "add#12" -- "add1#11" [label="1-1" color=red]; "add1#11"; "add#12"; "add#17" -- "add1#16" [label="1-1" color=red]; "add1#16"; "add#17"; "add#18(2)" -- "add#18"; "add#18"; "add#18(2)"; }
add1#9 -- zero#8 [label="0-0"]
zero#8
add1#9
add1#11 -- zero#10 [label="0-0"]
zero#10
add1#11
add#12 -- add1#9 [label="0-1"]
add1#9
add#12
add1#14 -- zero#13 [label="0-0"]
zero#13
add1#14
add1#16 -- zero#15 [label="0-0"]
zero#15
add1#16
add#17 -- add1#14 [label="0-1"]
add1#14
add#17
add#18 -- add#17 [label="1-2"]
add#17
add#18
add#18 -- add#12 [label="0-2"]
add#12
add#18
add#12 -- add1#11 [label="1-1" color=red]
add1#11
add#12
add#17 -- add1#16 [label="1-1" color=red]
add1#16
add#17
7 changes: 6 additions & 1 deletion docs/tests/nat.inet.two.finial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
graph { "add1#1" -- "zero#0" [label="0-0"]; "zero#0"; "add1#1"; "add1#7" -- "add1#1" [label="0-1"]; "add1#1"; "add1#7"; "add1#7(1)" -- "add1#7"; "add1#7"; "add1#7(1)"; }
add1#1 -- zero#0 [label="0-0"]
zero#0
add1#1
add1#7 -- add1#1 [label="0-1"]
add1#1
add1#7
13 changes: 12 additions & 1 deletion docs/tests/nat.inet.two.initial.txt
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
graph { "add1#1" -- "zero#0" [label="0-0"]; "zero#0"; "add1#1"; "add1#3" -- "zero#2" [label="0-0"]; "zero#2"; "add1#3"; "add#4" -- "add1#1" [label="0-1"]; "add1#1"; "add#4"; "add#4" -- "add1#3" [label="1-1" color=red]; "add1#3"; "add#4"; "add#4(2)" -- "add#4"; "add#4"; "add#4(2)"; }
add1#1 -- zero#0 [label="0-0"]
zero#0
add1#1
add1#3 -- zero#2 [label="0-0"]
zero#2
add1#3
add#4 -- add1#1 [label="0-1"]
add1#1
add#4
add#4 -- add1#3 [label="1-1" color=red]
add1#3
add#4
22 changes: 10 additions & 12 deletions src/renderers/NetRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,28 @@ export class NetRenderer {
const start = formatNode(edge.start.node)
const end = formatNode(edge.end.node)
const indexes = `${edge.end.index}-${edge.start.index}`
lines.push(`"${end}" -- "${start}" [label="${indexes}"];`)
lines.push(`"${start}";`)
lines.push(`"${end}";`)
lines.push(`${end} -- ${start} [label="${indexes}"]`)
lines.push(`${start}`)
lines.push(`${end}`)
}

for (const edge of net.actions) {
const start = formatNode(edge.start.node)
const end = formatNode(edge.end.node)
const indexes = `${edge.end.index}-${edge.start.index}`
lines.push(`"${end}" -- "${start}" [label="${indexes}" color=red];`)
lines.push(`"${start}";`)
lines.push(`"${end}";`)
lines.push(`${end} -- ${start} [label="${indexes}" color=red]`)
lines.push(`${start}`)
lines.push(`${end}`)
}

for (const port of net.portStack) {
const start = formatNode(port.node)
const end = `${formatNode(port.node)}(${port.index})`
lines.push(`"${end}" -- "${start}";`)
lines.push(`"${start}";`)
lines.push(`"${end}";`)
lines.push(`${end} -- ${start}`)
lines.push(`${start}`)
lines.push(`${end}`)
}

const body = lines.join(" ")

return `graph { ${body} }`
return lines.join("\n")
}
}

0 comments on commit 50c7846

Please sign in to comment.