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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Document</title>
<script src="/lib/util.js"></script>
<script src="/lib/chips2.js"></script>
<link href="/lib/chips.css" rel="stylesheet"></link>
<style>
table {
background: #333;
color: white;
}
table * {
border: solid #888 1px;
}
table th {
background: #222;
}
table td {
font-family: sans-serif;
}
</style>
</head>
<body>
<script>
function test() {
for (const el of document.body.children)
if (el.tagName != 'SCRIPT')
el.remove();
const tbl = document.createElement('table');
tbl.innerHTML = '<thead><tr id="head"><th>Type</th></tr></thead><tbody id="body"></tbody>';
document.body.prepend(tbl);
console.log("Testing type parsing...")
console.log(new Type("int"))
console.log(new Type("List<int>"))
console.log(new Type("(int, T1)", ["T1"]))
console.log(new Type("List<(T,int)>", ["T"]))
console.log(new Type("(int|float|Vector3)"))
console.log(new Type("List<(int|float|Vector3)>"))
console.log(new Type("(List<List<(int|float|Vector3)>>|List<any>)"))
console.log("Done!")
console.log("Testing type intersections");
const tistart = performance.now();
const types = [
//standard
new Type("int"),
new Type("bool"),
//template
new Type("List<int>"),
new Type("List<float>"),
new Type("List<List<int>>"),
new Type("List<List<any>>"),
new Type("List<(int|float)>"),
new Type("List<(float|Vector3)>"),
new Type("List<any>"),
//union
new Type("(int|float|bool)"),
new Type("(List<any>|bool)"),
//any
new Type("any"),
//dumb shit
new Type("List<(List<(int|float)>|Vector3)>"),
];
const head = document.getElementById("head");
const body = document.getElementById("body");
for (const t of types) {
const headel = document.createElement("th");
headel.innerText = t;
head.appendChild(headel);
const row = document.createElement("tr");
body.appendChild(row);
const title = document.createElement("th");
title.innerText = t;
row.appendChild(title);
for (const t2 of types) {
const sect = document.createElement("td");
sect.innerText = intersect(t,t2);
row.appendChild(sect);
}
}
console.log(`Done in ${performance.now() - tistart}ms!`)
console.log("Testing chip class...")
const nf = {"ReadonlyPaletteName": "foo","ReadonlyChipName": "foo","Description": "","IsBetaChip": false,"DeprecationStage": "Active","PaletteNameSource": "FirstNodeDesc","ChipNameSource": "FirstNodeDesc","NodeDescs": [{"Name": "foo","ReadonlyTypeParams": {"T": "(int|float|bool|string)","U": "(Vector3 | Quaternion)"},"Inputs": [{"Name": "Input0","ReadonlyType": "T","Description": ""},{"Name": "Input1","ReadonlyType": "List<U>","Description": ""}],"Outputs": [{"Name": "Output0","ReadonlyType": "T","Description": ""},{"Name": "Output1","ReadonlyType": "List<U>","Description": ""}]}]};
const nb = {"ReadonlyPaletteName": "bar","ReadonlyChipName": "bar","Description": "","IsBetaChip": false,"DeprecationStage": "Active","PaletteNameSource": "FirstNodeDesc","ChipNameSource": "FirstNodeDesc","NodeDescs": [{"Name": "bar","ReadonlyTypeParams": {"T": "(int|float)"},"Inputs": [{"Name": "Input0","ReadonlyType": "T","Description": ""},{"Name": "Input1","ReadonlyType": "List<Quaternion>","Description": ""}],"Outputs": [{"Name": "Output0","ReadonlyType": "T","Description": ""},{"Name": "Output1","ReadonlyType": "List<Quaternion>","Description": ""}]}]};
const nu = {"ReadonlyPaletteName": "buzz","ReadonlyChipName": "buzz","Description": "","IsBetaChip": false,"DeprecationStage": "Active","PaletteNameSource": "FirstNodeDesc","ChipNameSource": "FirstNodeDesc","NodeDescs": [{"Name": "buzz","ReadonlyTypeParams": {},"Inputs": [{"Name": "Input0","ReadonlyType": "int","Description": ""}],"Outputs": [{"Name": "Output0","ReadonlyType": "int","Description": ""}]}]};
const na = {"ReadonlyPaletteName": "bazz","ReadonlyChipName": "bazz","Description": "","IsBetaChip": false,"DeprecationStage": "Active","PaletteNameSource": "FirstNodeDesc","ChipNameSource": "FirstNodeDesc","NodeDescs": [{"Name": "bazz","ReadonlyTypeParams": {},"Inputs": [{"Name": "Input0","ReadonlyType": "int","Description": ""}],"Outputs": [{"Name": "Output0","ReadonlyType": "int","Description": ""}]}]};
const chstart = performance.now();
const foo = newEl('div', '');
const nodefoo = new Chip(nf, nf.NodeDescs[0], foo);
const bar = newEl('div', '');
const nodebar = new Chip(nb, nb.NodeDescs[0], bar);
const buzz = newEl('div', '');
const nodebuzz = new Chip(nu, nu.NodeDescs[0], buzz);
const bazz = newEl('div', '');
const nodebazz = new Chip(na, na.NodeDescs[0], bazz);
wireData(nodefoo.ins[0], nodebar.outs[0]);
wireData(nodebar.ins[0], nodebuzz.outs[0]);
document.body.append(foo,bar,buzz,bazz);
console.log(`Done in ${performance.now() - chstart}ms!`)
}
const start = performance.now();
const tests = 100;
for (let i = 0; i < tests; i++)
test();
const time = performance.now() - start;
console.log(`Avg time: ${time / tests}ms`);
</script>
</body>
</html>
|