-
Notifications
You must be signed in to change notification settings - Fork 1
/
format.js
104 lines (81 loc) · 1.51 KB
/
format.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"use strict";
const ambtype = 1;
const wiretype = 0;
let nwires, nambs, typelist, infmt;
function getlist(pax)
{
const list = pax.map(gettree);
if (list.length)
return "(" + list.join(", ") + ")";
else
return "";
}
function gettree(agent)
{
const type = agent.type;
let human;
if (wiretype == type) {
human = agent.human;
if (!human) {
++nwires;
human = "w" + nwires;
agent.human = human;
}
agent.twin.human = human;
} else if (ambtype == type) {
const need = agent.need ? "!" : "\\";
let index = agent.index;
let list = "";
if (!index || (nambs < index)) {
++nambs;
index = nambs;
agent.twin.index = nambs;
list = getlist([
agent.main,
agent.aux
]);
}
human = need + "amb#" + index + list;
} else {
const need = agent.need ? "!" : "\\";
let data = infmt(agent.data);
let cell;
if (void(0) == data)
data = "";
else
data = "_{" + data + "}";
cell = typelist[type] + data;
human = need + cell + getlist(agent.pax);
}
return human;
}
function geteqn(pair)
{
const left = gettree(pair.left);
const right = gettree(pair.right);
return left + " = " + right + ";";
}
function getconf(queue)
{
nambs = 0;
return queue.map(geteqn).join("\n");
}
function nofmt(data)
{
return data;
}
function reset(fmt, types)
{
if (fmt)
infmt = fmt;
else
infmt = nofmt;
nwires = 0;
nambs = 0;
typelist = [];
for (const type in types)
typelist[types[type]] = type;
}
exports.reset = reset;
exports.geteqn = geteqn;
exports.getconf = getconf;