circuitscript 0.0.29 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +6 -1
- package/dist/cjs/antlr/CircuitScriptLexer.js +204 -200
- package/dist/cjs/antlr/CircuitScriptParser.js +1066 -1173
- package/dist/cjs/draw_symbols.js +330 -87
- package/dist/cjs/execute.js +39 -14
- package/dist/cjs/geometry.js +79 -18
- package/dist/cjs/globals.js +36 -6
- package/dist/cjs/helpers.js +40 -2
- package/dist/cjs/layout.js +72 -39
- package/dist/cjs/main.js +10 -4
- package/dist/cjs/objects/ClassComponent.js +2 -0
- package/dist/cjs/objects/ExecutionScope.js +1 -1
- package/dist/cjs/objects/Net.js +3 -2
- package/dist/cjs/objects/PinTypes.js +7 -1
- package/dist/cjs/objects/types.js +11 -1
- package/dist/cjs/regenerate-tests.js +64 -3
- package/dist/cjs/render.js +20 -14
- package/dist/cjs/sizing.js +4 -6
- package/dist/cjs/utils.js +29 -5
- package/dist/cjs/visitor.js +176 -10
- package/dist/esm/BaseVisitor.mjs +6 -1
- package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
- package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
- package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
- package/dist/esm/draw_symbols.mjs +324 -85
- package/dist/esm/execute.mjs +40 -15
- package/dist/esm/geometry.mjs +79 -17
- package/dist/esm/globals.mjs +35 -5
- package/dist/esm/helpers.mjs +38 -1
- package/dist/esm/layout.mjs +75 -42
- package/dist/esm/main.mjs +11 -5
- package/dist/esm/objects/ClassComponent.mjs +6 -0
- package/dist/esm/objects/ExecutionScope.mjs +1 -1
- package/dist/esm/objects/Net.mjs +3 -2
- package/dist/esm/objects/PinTypes.mjs +6 -0
- package/dist/esm/objects/types.mjs +14 -0
- package/dist/esm/regenerate-tests.mjs +64 -3
- package/dist/esm/render.mjs +21 -15
- package/dist/esm/sizing.mjs +3 -4
- package/dist/esm/utils.mjs +26 -4
- package/dist/esm/visitor.mjs +179 -13
- package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
- package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
- package/dist/types/draw_symbols.d.ts +15 -2
- package/dist/types/execute.d.ts +5 -4
- package/dist/types/geometry.d.ts +4 -3
- package/dist/types/globals.d.ts +31 -3
- package/dist/types/helpers.d.ts +12 -0
- package/dist/types/layout.d.ts +2 -1
- package/dist/types/objects/ClassComponent.d.ts +8 -0
- package/dist/types/objects/PinTypes.d.ts +1 -0
- package/dist/types/objects/Wire.d.ts +4 -2
- package/dist/types/objects/types.d.ts +8 -0
- package/dist/types/sizing.d.ts +0 -4
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -1
- package/fonts/Arial.ttf +0 -0
- package/libs/lib.cst +58 -41
- package/package.json +1 -1
package/dist/cjs/main.js
CHANGED
|
@@ -52,16 +52,22 @@ async function main() {
|
|
|
52
52
|
let scriptData;
|
|
53
53
|
if (args.length > 0 && args[0]) {
|
|
54
54
|
inputFilePath = args[0];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
currentDirectory
|
|
55
|
+
if ((0, fs_1.existsSync)(inputFilePath)) {
|
|
56
|
+
scriptData = (0, fs_1.readFileSync)(inputFilePath, { encoding: 'utf-8' });
|
|
57
|
+
if (currentDirectory === null) {
|
|
58
|
+
currentDirectory = path_1.default.dirname(inputFilePath);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.error("Error: File could not be found");
|
|
63
|
+
return;
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
else if (options.input) {
|
|
61
67
|
scriptData = options.input;
|
|
62
68
|
}
|
|
63
69
|
else {
|
|
64
|
-
console.
|
|
70
|
+
console.error("Error: No input provided");
|
|
65
71
|
return;
|
|
66
72
|
}
|
|
67
73
|
const scriptOptions = {
|
|
@@ -21,8 +21,10 @@ class ClassComponent {
|
|
|
21
21
|
this.followWireOrientationProp = true;
|
|
22
22
|
this.wireOrientationAngle = 0;
|
|
23
23
|
this.useWireOrientationAngle = true;
|
|
24
|
+
this.didSetWireOrientationAngle = false;
|
|
24
25
|
this.styles = {};
|
|
25
26
|
this.assignedRefDes = null;
|
|
27
|
+
this.moduleCounter = 0;
|
|
26
28
|
this.instanceName = instanceName;
|
|
27
29
|
this.numPins = numPins;
|
|
28
30
|
this.className = className;
|
package/dist/cjs/objects/Net.js
CHANGED
|
@@ -16,10 +16,11 @@ class Net {
|
|
|
16
16
|
this.baseName = name;
|
|
17
17
|
}
|
|
18
18
|
toString() {
|
|
19
|
-
return this.name;
|
|
19
|
+
return this.namespace + this.name;
|
|
20
20
|
}
|
|
21
21
|
static isSame(netA, netB) {
|
|
22
|
-
return netA.
|
|
22
|
+
return netA.namespace === netB.namespace &&
|
|
23
|
+
netA.name === netB.name &&
|
|
23
24
|
netA.baseName === netB.baseName &&
|
|
24
25
|
netA.priority === netB.priority &&
|
|
25
26
|
netA.type === netB.type;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PinTypes = void 0;
|
|
3
|
+
exports.AllPinTypes = exports.PinTypes = void 0;
|
|
4
4
|
var PinTypes;
|
|
5
5
|
(function (PinTypes) {
|
|
6
6
|
PinTypes["Any"] = "any";
|
|
@@ -9,3 +9,9 @@ var PinTypes;
|
|
|
9
9
|
PinTypes["IO"] = "io";
|
|
10
10
|
PinTypes["Power"] = "power";
|
|
11
11
|
})(PinTypes || (exports.PinTypes = PinTypes = {}));
|
|
12
|
+
exports.AllPinTypes = [
|
|
13
|
+
PinTypes.Any,
|
|
14
|
+
PinTypes.Input,
|
|
15
|
+
PinTypes.Output,
|
|
16
|
+
PinTypes.IO,
|
|
17
|
+
];
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Direction = exports.ParseSymbolType = exports.UndeclaredReference = void 0;
|
|
3
|
+
exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = void 0;
|
|
4
4
|
class UndeclaredReference {
|
|
5
5
|
constructor(reference) {
|
|
6
6
|
this.reference = reference;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
exports.UndeclaredReference = UndeclaredReference;
|
|
10
|
+
class DeclaredReference {
|
|
11
|
+
constructor(refType) {
|
|
12
|
+
this.found = refType.found;
|
|
13
|
+
this.name = refType.name;
|
|
14
|
+
this.trailers = refType.trailers;
|
|
15
|
+
this.type = refType.type;
|
|
16
|
+
this.value = refType.value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DeclaredReference = DeclaredReference;
|
|
10
20
|
var ParseSymbolType;
|
|
11
21
|
(function (ParseSymbolType) {
|
|
12
22
|
ParseSymbolType["Variable"] = "variable";
|
|
@@ -9,7 +9,7 @@ const sizing_js_1 = require("./sizing.js");
|
|
|
9
9
|
const mainDir = './__tests__/renderData/';
|
|
10
10
|
const fontsPath = (0, helpers_js_1.getFontsPath)();
|
|
11
11
|
const defaultLibsPath = (0, helpers_js_1.getDefaultLibsPath)();
|
|
12
|
-
async function regenerateTests() {
|
|
12
|
+
async function regenerateTests(extra = "") {
|
|
13
13
|
await (0, sizing_js_1.prepareSVGEnvironment)(fontsPath);
|
|
14
14
|
const cstFiles = [];
|
|
15
15
|
const files = fs_1.default.readdirSync(mainDir);
|
|
@@ -21,12 +21,73 @@ async function regenerateTests() {
|
|
|
21
21
|
cstFiles.forEach(file => {
|
|
22
22
|
const inputPath = mainDir + file;
|
|
23
23
|
const scriptData = fs_1.default.readFileSync(inputPath, { encoding: 'utf-8' });
|
|
24
|
-
const outputPath =
|
|
24
|
+
const outputPath = mainDir + 'svgs/' + file + extra + '.svg';
|
|
25
25
|
(0, helpers_js_1.renderScript)(scriptData, outputPath, {
|
|
26
26
|
currentDirectory: mainDir,
|
|
27
27
|
defaultLibsPath,
|
|
28
28
|
});
|
|
29
29
|
console.log('generated ', outputPath);
|
|
30
30
|
});
|
|
31
|
+
return cstFiles;
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
+
(async () => {
|
|
34
|
+
const generateDiff = false;
|
|
35
|
+
const nextExtra = generateDiff ? '.next' : '';
|
|
36
|
+
const cstFiles = await regenerateTests(nextExtra);
|
|
37
|
+
const allFiles = [];
|
|
38
|
+
if (generateDiff) {
|
|
39
|
+
cstFiles.forEach(file => {
|
|
40
|
+
const svg1 = 'svgs/' + file + '.svg';
|
|
41
|
+
const svg2 = 'svgs/' + file + '.next.svg';
|
|
42
|
+
const cleanedName = file.replace('script', '').replace('.cst', '');
|
|
43
|
+
allFiles.push([file, svg1, svg2, cleanedName]);
|
|
44
|
+
});
|
|
45
|
+
const sortedFiles = allFiles.sort((a, b) => {
|
|
46
|
+
const nameA = a[3];
|
|
47
|
+
const nameB = b[3];
|
|
48
|
+
const indexA = Number(nameA);
|
|
49
|
+
const indexB = Number(nameB);
|
|
50
|
+
if (indexA > indexB) {
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
else if (indexA < indexB) {
|
|
54
|
+
return -1;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const output = [];
|
|
61
|
+
sortedFiles.forEach(group => {
|
|
62
|
+
const [file, svg1, svg2] = group;
|
|
63
|
+
output.push(`<div class='group'>
|
|
64
|
+
<h3>${file}</h3>
|
|
65
|
+
<div class='items'>
|
|
66
|
+
<div style='margin-right: 10px'>
|
|
67
|
+
<h4>${svg1}</h4>
|
|
68
|
+
<img src='${svg1}'/>
|
|
69
|
+
</div>
|
|
70
|
+
<div>
|
|
71
|
+
<h4>${svg2}</h4>
|
|
72
|
+
<img src='${svg2}'/>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>`);
|
|
76
|
+
});
|
|
77
|
+
const result = `
|
|
78
|
+
<html>
|
|
79
|
+
<header>
|
|
80
|
+
<title>SVG compare</title>
|
|
81
|
+
<style>
|
|
82
|
+
img { border: solid thin #ccc; }
|
|
83
|
+
.items { display: flex; }
|
|
84
|
+
body { font-family: Arial; }
|
|
85
|
+
</style>
|
|
86
|
+
</header>
|
|
87
|
+
<body>
|
|
88
|
+
${output.join('')}
|
|
89
|
+
</body>
|
|
90
|
+
</html>`;
|
|
91
|
+
fs_1.default.writeFileSync(mainDir + "compiled.html", result);
|
|
92
|
+
}
|
|
93
|
+
})();
|
package/dist/cjs/render.js
CHANGED
|
@@ -7,6 +7,7 @@ const sizing_js_1 = require("./sizing.js");
|
|
|
7
7
|
const globals_js_1 = require("./globals.js");
|
|
8
8
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
9
9
|
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const helpers_js_1 = require("./helpers.js");
|
|
10
11
|
function generateSVG2(graph) {
|
|
11
12
|
const window = (0, sizing_js_1.getCreateSVGWindow)()();
|
|
12
13
|
const document = window.document;
|
|
@@ -15,10 +16,10 @@ function generateSVG2(graph) {
|
|
|
15
16
|
(0, sizing_js_1.applyFontsToSVG)(canvas);
|
|
16
17
|
generateSVGChild(canvas, graph.components, graph.wires, graph.junctions, graph.mergedWires, graph.frameObjects, graph.textObjects);
|
|
17
18
|
const { x, y, width, height } = canvas.bbox();
|
|
18
|
-
const margin =
|
|
19
|
+
const margin = (0, helpers_js_1.milsToMM)(10);
|
|
19
20
|
const widthAndMargin = width + margin * 2;
|
|
20
21
|
const heightAndMargin = height + margin * 2;
|
|
21
|
-
const scale =
|
|
22
|
+
const scale = globals_js_1.MMToPx * globals_js_1.defaultZoomScale;
|
|
22
23
|
canvas.size(widthAndMargin * scale, heightAndMargin * scale);
|
|
23
24
|
canvas.viewbox(x - margin, y - margin, widthAndMargin, heightAndMargin);
|
|
24
25
|
return canvas.svg();
|
|
@@ -83,8 +84,11 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
83
84
|
const pt1 = segment[0];
|
|
84
85
|
const pt2 = segment[1];
|
|
85
86
|
mergedWireGroup.line([pt1, pt2])
|
|
86
|
-
.stroke({
|
|
87
|
-
|
|
87
|
+
.stroke({
|
|
88
|
+
width: globals_js_1.defaultWireLineWidth,
|
|
89
|
+
color: globals_js_1.ColorScheme.WireColor,
|
|
90
|
+
linecap: 'square'
|
|
91
|
+
})
|
|
88
92
|
.fill('none');
|
|
89
93
|
});
|
|
90
94
|
intersectPoints.forEach(point => {
|
|
@@ -113,7 +117,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
113
117
|
}
|
|
114
118
|
const tmpRect = frameGroup.rect(width, height)
|
|
115
119
|
.fill('none')
|
|
116
|
-
.stroke({ width: borderWidth, color: strokeColor });
|
|
120
|
+
.stroke({ width: (0, helpers_js_1.milsToMM)(borderWidth), color: strokeColor });
|
|
117
121
|
tmpRect.translate(item.x, item.y);
|
|
118
122
|
}
|
|
119
123
|
});
|
|
@@ -124,13 +128,14 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
124
128
|
symbol.draw(innerGroup);
|
|
125
129
|
});
|
|
126
130
|
const drawOrigin = false;
|
|
131
|
+
const originSize = (0, helpers_js_1.milsToMM)(10);
|
|
127
132
|
drawOrigin && canvas.group().translate(0, 0)
|
|
128
|
-
.circle(
|
|
129
|
-
.translate(-
|
|
133
|
+
.circle(originSize)
|
|
134
|
+
.translate(-originSize / 2, -originSize / 2)
|
|
130
135
|
.stroke('none').fill('red');
|
|
131
136
|
}
|
|
132
137
|
function drawGrid(group, canvasSize) {
|
|
133
|
-
const gridSize =
|
|
138
|
+
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
134
139
|
const { x, y, x2, y2 } = canvasSize;
|
|
135
140
|
const gridStartX = (Math.floor(x / gridSize) - 1) * gridSize;
|
|
136
141
|
const gridStartY = (Math.floor(y / gridSize) - 1) * gridSize;
|
|
@@ -138,19 +143,20 @@ function drawGrid(group, canvasSize) {
|
|
|
138
143
|
const gridEndY = (Math.ceil(y2 / gridSize) + 1) * gridSize;
|
|
139
144
|
const numCols = Math.ceil((gridEndX - gridStartX) / gridSize);
|
|
140
145
|
const lines = [];
|
|
146
|
+
const smallOffset = (0, helpers_js_1.milsToMM)(3);
|
|
147
|
+
const startY = gridStartY - smallOffset / 2;
|
|
148
|
+
const endY = gridEndY + smallOffset;
|
|
141
149
|
for (let i = 0; i <= numCols; i++) {
|
|
142
150
|
const startX = gridStartX + i * gridSize;
|
|
143
|
-
const startY = gridStartY - 0.5;
|
|
144
|
-
const endY = gridEndY;
|
|
145
151
|
lines.push(`M ${startX} ${startY} L ${startX} ${endY}`);
|
|
146
152
|
}
|
|
153
|
+
const strokeSize = (0, helpers_js_1.milsToMM)(3);
|
|
147
154
|
group.path(lines.join(" "))
|
|
148
|
-
.fill('none')
|
|
149
155
|
.attr({
|
|
150
|
-
'stroke-dasharray':
|
|
156
|
+
'stroke-dasharray': `${strokeSize},${gridSize - strokeSize}`,
|
|
151
157
|
})
|
|
152
158
|
.stroke({
|
|
153
|
-
width:
|
|
154
|
-
color: '#
|
|
159
|
+
width: strokeSize,
|
|
160
|
+
color: '#000'
|
|
155
161
|
});
|
|
156
162
|
}
|
package/dist/cjs/sizing.js
CHANGED
|
@@ -23,13 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.measureTextSize2 = exports.
|
|
26
|
+
exports.measureTextSize2 = exports.applyFontsToSVG = exports.getCreateSVGWindow = exports.prepareSVGEnvironment = void 0;
|
|
27
27
|
const svg_js_1 = require("@svgdotjs/svg.js");
|
|
28
28
|
const geometry_js_1 = require("./geometry.js");
|
|
29
29
|
const globals_js_1 = require("./globals.js");
|
|
30
30
|
const helpers_js_1 = require("./helpers.js");
|
|
31
31
|
let MainCanvas = null;
|
|
32
|
-
const supportedFonts = {
|
|
32
|
+
const supportedFonts = {
|
|
33
|
+
'Arial': 'Arial.ttf',
|
|
34
|
+
};
|
|
33
35
|
let globalCreateSVGWindow;
|
|
34
36
|
async function prepareSVGEnvironment(fontsPath) {
|
|
35
37
|
const moduleType = (0, helpers_js_1.detectJSModuleType)();
|
|
@@ -54,10 +56,6 @@ exports.getCreateSVGWindow = getCreateSVGWindow;
|
|
|
54
56
|
function applyFontsToSVG(canvas) {
|
|
55
57
|
}
|
|
56
58
|
exports.applyFontsToSVG = applyFontsToSVG;
|
|
57
|
-
async function measureTextSize(text, fontFamily, fontSize) {
|
|
58
|
-
return measureTextSize2(text, fontFamily, fontSize);
|
|
59
|
-
}
|
|
60
|
-
exports.measureTextSize = measureTextSize;
|
|
61
59
|
const measureTextSizeCache = {};
|
|
62
60
|
const measureTextSizeCacheHits = {};
|
|
63
61
|
function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom) {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
3
|
+
exports.roundValue = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
4
4
|
class SimpleStopwatch {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.startTime = new Date();
|
|
@@ -28,11 +28,17 @@ function printBounds(bounds) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
exports.printBounds = printBounds;
|
|
31
|
+
function hasRemainder(value, value2) {
|
|
32
|
+
const tmpValue = Math.abs(value) / value2;
|
|
33
|
+
const flooredValue = Math.floor(tmpValue);
|
|
34
|
+
const diff = tmpValue - flooredValue;
|
|
35
|
+
return diff;
|
|
36
|
+
}
|
|
31
37
|
function resizeToNearestGrid(bounds, gridSize = 20) {
|
|
32
|
-
const addXMin = (bounds.xmin
|
|
33
|
-
const addYMin = (bounds.ymin
|
|
34
|
-
const addXMax = (bounds.xmax
|
|
35
|
-
const addYMax = (bounds.ymax
|
|
38
|
+
const addXMin = hasRemainder(bounds.xmin, gridSize) === 0 ? -1 : 0;
|
|
39
|
+
const addYMin = hasRemainder(bounds.ymin, gridSize) === 0 ? -1 : 0;
|
|
40
|
+
const addXMax = hasRemainder(bounds.xmax, gridSize) === 0 ? 1 : 0;
|
|
41
|
+
const addYMax = hasRemainder(bounds.ymax, gridSize) === 0 ? 1 : 0;
|
|
36
42
|
return {
|
|
37
43
|
xmin: Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize,
|
|
38
44
|
ymin: Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize,
|
|
@@ -52,3 +58,21 @@ function getBoundsSize(bounds) {
|
|
|
52
58
|
};
|
|
53
59
|
}
|
|
54
60
|
exports.getBoundsSize = getBoundsSize;
|
|
61
|
+
function getPortType(component) {
|
|
62
|
+
const drawingCommands = component.displayProp;
|
|
63
|
+
let foundPinType = null;
|
|
64
|
+
const commands = drawingCommands.getCommands();
|
|
65
|
+
commands.some(item => {
|
|
66
|
+
if (item[0] === 'label' && item[2].has('portType')) {
|
|
67
|
+
foundPinType = item[2].get('portType');
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
});
|
|
72
|
+
return foundPinType;
|
|
73
|
+
}
|
|
74
|
+
exports.getPortType = getPortType;
|
|
75
|
+
function roundValue(value) {
|
|
76
|
+
return +value.toFixed(7);
|
|
77
|
+
}
|
|
78
|
+
exports.roundValue = roundValue;
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -9,6 +9,8 @@ const types_js_1 = require("./objects/types.js");
|
|
|
9
9
|
const globals_js_1 = require("./globals.js");
|
|
10
10
|
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
11
11
|
const BaseVisitor_js_1 = require("./BaseVisitor.js");
|
|
12
|
+
const utils_js_1 = require("./utils.js");
|
|
13
|
+
const helpers_js_1 = require("./helpers.js");
|
|
12
14
|
class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
13
15
|
constructor() {
|
|
14
16
|
super(...arguments);
|
|
@@ -150,7 +152,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
150
152
|
arrange, display, type, width, copy,
|
|
151
153
|
angle, followWireOrientation
|
|
152
154
|
};
|
|
153
|
-
|
|
155
|
+
const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
|
|
156
|
+
this.setResult(ctx, createdComponent);
|
|
154
157
|
};
|
|
155
158
|
this.visitCreate_graphic_expr = (ctx) => {
|
|
156
159
|
const commands = ctx.graphic_expr().reduce((accum, item) => {
|
|
@@ -196,8 +199,82 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
196
199
|
this.visit(ctxParameters);
|
|
197
200
|
parameters = this.getResult(ctxParameters);
|
|
198
201
|
}
|
|
202
|
+
if (commandName === 'label') {
|
|
203
|
+
parameters.forEach(item => {
|
|
204
|
+
if (item[0] == 'keyword' && item[1] === 'portType') {
|
|
205
|
+
if (item[2] === 'in') {
|
|
206
|
+
item[2] = 'input';
|
|
207
|
+
}
|
|
208
|
+
else if (item[2] === 'out') {
|
|
209
|
+
item[2] = 'output';
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
199
214
|
this.setResult(ctx, [commandName, parameters]);
|
|
200
215
|
};
|
|
216
|
+
this.visitCreate_module_expr = (ctx) => {
|
|
217
|
+
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
218
|
+
const { left: leftPorts, right: rightPorts } = this.parseCreateModulePorts(properties.get('ports'));
|
|
219
|
+
const allPorts = [...leftPorts, ...rightPorts].filter(item => {
|
|
220
|
+
return !(item instanceof ParamDefinition_js_1.PinBlankValue);
|
|
221
|
+
});
|
|
222
|
+
const nameToPinId = new Map();
|
|
223
|
+
const tmpPorts = allPorts.map((portName, index) => {
|
|
224
|
+
nameToPinId.set(portName, index + 1);
|
|
225
|
+
return new PinDefinition_js_1.PinDefinition(index + 1, PinDefinition_js_1.PinIdType.Int, portName, PinTypes_js_1.PinTypes.Any);
|
|
226
|
+
});
|
|
227
|
+
const arrangeLeftItems = leftPorts.map(item => {
|
|
228
|
+
if (item instanceof ParamDefinition_js_1.PinBlankValue) {
|
|
229
|
+
return item;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return nameToPinId.get(item);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
const arrangeRightItems = rightPorts.map(item => {
|
|
236
|
+
if (item instanceof ParamDefinition_js_1.PinBlankValue) {
|
|
237
|
+
return item;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return nameToPinId.get(item);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
const arrange = new Map();
|
|
244
|
+
if (arrangeLeftItems.length > 0) {
|
|
245
|
+
arrange.set('left', arrangeLeftItems);
|
|
246
|
+
}
|
|
247
|
+
if (arrangeRightItems.length > 0) {
|
|
248
|
+
arrange.set('right', arrangeRightItems);
|
|
249
|
+
}
|
|
250
|
+
const width = properties.has('width') ?
|
|
251
|
+
properties.get('width') : null;
|
|
252
|
+
const blankParams = [];
|
|
253
|
+
const props = {
|
|
254
|
+
arrange, width
|
|
255
|
+
};
|
|
256
|
+
const moduleInstanceName = this.getExecutor().getUniqueInstanceName('');
|
|
257
|
+
const createdComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props);
|
|
258
|
+
createdComponent.typeProp = 'module';
|
|
259
|
+
const ctxPropertyBlock = ctx.property_block_expr();
|
|
260
|
+
if (ctxPropertyBlock) {
|
|
261
|
+
const [firstBlock] = ctxPropertyBlock;
|
|
262
|
+
this.visit(firstBlock);
|
|
263
|
+
const [keyName, expressionsBlock] = this.getResult(firstBlock);
|
|
264
|
+
if (keyName === 'contains') {
|
|
265
|
+
createdComponent.moduleContainsExpressions = expressionsBlock;
|
|
266
|
+
this.expandModuleContains(createdComponent, this.getExecutor().netNamespace);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
this.setResult(ctx, createdComponent);
|
|
270
|
+
};
|
|
271
|
+
this.visitProperty_block_expr = (ctx) => {
|
|
272
|
+
const tmpCtx = ctx.property_key_expr();
|
|
273
|
+
this.visit(tmpCtx);
|
|
274
|
+
const keyName = this.getResult(tmpCtx);
|
|
275
|
+
const expressionsBlock = ctx.expressions_block();
|
|
276
|
+
this.setResult(ctx, [keyName, expressionsBlock]);
|
|
277
|
+
};
|
|
201
278
|
this.visitProperty_expr = (ctx) => {
|
|
202
279
|
const ctxPropertyKeyExpr = ctx.property_key_expr();
|
|
203
280
|
const ctxPropertyValueExpr = ctx.property_value_expr();
|
|
@@ -275,6 +352,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
275
352
|
&& component.copyProp) {
|
|
276
353
|
component = this.getExecutor().copyComponent(component);
|
|
277
354
|
}
|
|
355
|
+
if (component instanceof types_js_1.DeclaredReference
|
|
356
|
+
&& component.found
|
|
357
|
+
&& component.trailers
|
|
358
|
+
&& component.trailers.length > 0
|
|
359
|
+
&& component.trailers[0] === 'contains') {
|
|
360
|
+
component = component.value;
|
|
361
|
+
this.placeModuleContains(component);
|
|
362
|
+
}
|
|
278
363
|
if (component && component instanceof ClassComponent_js_1.ClassComponent) {
|
|
279
364
|
const modifiers = ctx.component_modifier_expr();
|
|
280
365
|
modifiers.forEach(modifier => {
|
|
@@ -333,7 +418,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
333
418
|
pinValue = this.getResult(ctxPinSelectExpr);
|
|
334
419
|
}
|
|
335
420
|
else {
|
|
336
|
-
|
|
421
|
+
if (component instanceof ClassComponent_js_1.ClassComponent) {
|
|
422
|
+
pinValue = component.getDefaultPin();
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
const undeclaredRef = component;
|
|
426
|
+
throw 'Invalid component: ' + undeclaredRef.reference.name;
|
|
427
|
+
}
|
|
337
428
|
}
|
|
338
429
|
this.setResult(ctx, [component, pinValue]);
|
|
339
430
|
};
|
|
@@ -365,6 +456,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
365
456
|
let value;
|
|
366
457
|
const ctxCreateComponentExpr = ctx.create_component_expr();
|
|
367
458
|
const ctxCreateGraphicExpr = ctx.create_graphic_expr();
|
|
459
|
+
const ctxCreateModuleExpr = ctx.create_module_expr();
|
|
368
460
|
if (ctxCreateComponentExpr) {
|
|
369
461
|
this.visit(ctxCreateComponentExpr);
|
|
370
462
|
value = this.getResult(ctxCreateComponentExpr);
|
|
@@ -373,6 +465,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
373
465
|
this.visit(ctxCreateGraphicExpr);
|
|
374
466
|
value = this.getResult(ctxCreateGraphicExpr);
|
|
375
467
|
}
|
|
468
|
+
else if (ctxCreateModuleExpr) {
|
|
469
|
+
this.visit(ctxCreateModuleExpr);
|
|
470
|
+
value = this.getResult(ctxCreateModuleExpr);
|
|
471
|
+
}
|
|
376
472
|
else {
|
|
377
473
|
throw "Invalid data expression";
|
|
378
474
|
}
|
|
@@ -541,13 +637,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
541
637
|
}
|
|
542
638
|
};
|
|
543
639
|
this.visitAt_block_pin_expression_complex = (ctx) => {
|
|
544
|
-
ctx.
|
|
545
|
-
this.visit(item);
|
|
546
|
-
});
|
|
640
|
+
this.visit(ctx.expressions_block());
|
|
547
641
|
};
|
|
548
642
|
this.visitWire_expr_direction_only = (ctx) => {
|
|
549
643
|
const value = ctx.ID().getText();
|
|
550
|
-
if (value ===
|
|
644
|
+
if (value === globals_js_1.WireAutoDirection.Auto || value === globals_js_1.WireAutoDirection.Auto_) {
|
|
551
645
|
this.setResult(ctx, [value]);
|
|
552
646
|
}
|
|
553
647
|
else {
|
|
@@ -568,7 +662,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
568
662
|
useValue = this.getResult(ctxDataExpr);
|
|
569
663
|
}
|
|
570
664
|
if (useValue !== null) {
|
|
571
|
-
this.setResult(ctx, [direction, useValue]);
|
|
665
|
+
this.setResult(ctx, [direction, new helpers_js_1.UnitDimension(useValue)]);
|
|
572
666
|
return;
|
|
573
667
|
}
|
|
574
668
|
}
|
|
@@ -602,9 +696,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
602
696
|
const propertyName = ctx.ID().getText();
|
|
603
697
|
this.getExecutor().setProperty('..' + propertyName, result);
|
|
604
698
|
};
|
|
699
|
+
this.visitExpressions_block = (ctx) => {
|
|
700
|
+
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
701
|
+
};
|
|
605
702
|
this.visitFrame_expr = (ctx) => {
|
|
606
703
|
const frameId = this.getExecutor().enterFrame();
|
|
607
|
-
this.
|
|
704
|
+
this.visit(ctx.expressions_block());
|
|
608
705
|
this.getExecutor().exitFrame(frameId);
|
|
609
706
|
};
|
|
610
707
|
this.visitNet_namespace_expr = (ctx) => {
|
|
@@ -635,7 +732,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
635
732
|
this.visit(ctxDataExpr);
|
|
636
733
|
const result = this.getResult(ctxDataExpr);
|
|
637
734
|
if (result) {
|
|
638
|
-
this.
|
|
735
|
+
this.visit(ctx.expressions_block());
|
|
639
736
|
}
|
|
640
737
|
else {
|
|
641
738
|
const ctxInnerIfExprs = ctx.if_inner_expr();
|
|
@@ -662,7 +759,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
662
759
|
this.visit(ctxDataExpr);
|
|
663
760
|
const result = this.getResult(ctxDataExpr);
|
|
664
761
|
if (result) {
|
|
665
|
-
this.
|
|
762
|
+
this.visit(ctx.expressions_block());
|
|
666
763
|
}
|
|
667
764
|
this.setResult(ctx, result);
|
|
668
765
|
};
|
|
@@ -674,6 +771,55 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
674
771
|
PinTypes_js_1.PinTypes.Power,
|
|
675
772
|
];
|
|
676
773
|
}
|
|
774
|
+
expandModuleContains(component, netNamespace) {
|
|
775
|
+
this.getExecutor().log('expanding module `contains`');
|
|
776
|
+
const executionStack = this.executionStack;
|
|
777
|
+
const resolveNet = this.createNetResolver(executionStack);
|
|
778
|
+
const executionContextName = this.getExecutor().namespace + "_"
|
|
779
|
+
+ component.instanceName
|
|
780
|
+
+ '_' + component.moduleCounter;
|
|
781
|
+
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + "_" + component.moduleCounter);
|
|
782
|
+
const newExecutor = this.enterNewChildContext(executionStack, this.getExecutor(), executionContextName, { netNamespace: tmpNamespace }, [], []);
|
|
783
|
+
component.moduleCounter += 1;
|
|
784
|
+
newExecutor.resolveNet = resolveNet;
|
|
785
|
+
this.visit(component.moduleContainsExpressions);
|
|
786
|
+
const executionContext = executionStack.pop();
|
|
787
|
+
component.moduleExecutionContext = executionContext;
|
|
788
|
+
component.moduleExecutionContextName = executionContextName;
|
|
789
|
+
this.linkModuleSymbolWithContains(component, executionContext);
|
|
790
|
+
}
|
|
791
|
+
linkModuleSymbolWithContains(moduleComponent, executionContext) {
|
|
792
|
+
this.log('link module symbol');
|
|
793
|
+
const modulePinMapping = new Map();
|
|
794
|
+
moduleComponent.pins.forEach(pin => {
|
|
795
|
+
const pinName = pin.name;
|
|
796
|
+
modulePinMapping.set(pinName, pin.id);
|
|
797
|
+
});
|
|
798
|
+
const pinIdToPortMap = new Map();
|
|
799
|
+
moduleComponent.modulePinIdToPortMap = pinIdToPortMap;
|
|
800
|
+
for (const [key, component] of executionContext.scope.instances) {
|
|
801
|
+
if (component._copyID !== null && component.typeProp === 'port') {
|
|
802
|
+
const portName = component.parameters.get('net_name');
|
|
803
|
+
const modulePinId = modulePinMapping.get(portName);
|
|
804
|
+
pinIdToPortMap.set(modulePinId, component);
|
|
805
|
+
const portType = (0, utils_js_1.getPortType)(component);
|
|
806
|
+
const tmpPin = moduleComponent.pins.get(modulePinId);
|
|
807
|
+
tmpPin.pinType = portType;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
placeModuleContains(moduleComponent) {
|
|
812
|
+
if (moduleComponent.typeProp === 'module'
|
|
813
|
+
&& moduleComponent.moduleContainsExpressions) {
|
|
814
|
+
this.log('place module `contains`');
|
|
815
|
+
this.getExecutor().mergeScope(moduleComponent.moduleExecutionContext.scope, moduleComponent.moduleExecutionContextName);
|
|
816
|
+
this.log('connect module ports');
|
|
817
|
+
for (const [pinId, portComponent] of moduleComponent.modulePinIdToPortMap) {
|
|
818
|
+
this.getExecutor().atComponent(moduleComponent, pinId);
|
|
819
|
+
this.getExecutor().toComponent(portComponent, 1);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
677
823
|
parseCreateComponentPins(pinData) {
|
|
678
824
|
const pins = [];
|
|
679
825
|
if (typeof pinData === 'number') {
|
|
@@ -718,6 +864,26 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
718
864
|
}
|
|
719
865
|
return pins;
|
|
720
866
|
}
|
|
867
|
+
parseCreateModulePorts(portsDefinition) {
|
|
868
|
+
let leftItems = [];
|
|
869
|
+
let rightItems = [];
|
|
870
|
+
if (portsDefinition.has('left')) {
|
|
871
|
+
leftItems = portsDefinition.get('left');
|
|
872
|
+
if (!Array.isArray(leftItems)) {
|
|
873
|
+
leftItems = [leftItems];
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if (portsDefinition.has('right')) {
|
|
877
|
+
rightItems = portsDefinition.get('right');
|
|
878
|
+
if (!Array.isArray(rightItems)) {
|
|
879
|
+
rightItems = [rightItems];
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return {
|
|
883
|
+
left: leftItems,
|
|
884
|
+
right: rightItems
|
|
885
|
+
};
|
|
886
|
+
}
|
|
721
887
|
parseCreateComponentParams(params) {
|
|
722
888
|
const result = [];
|
|
723
889
|
if (params) {
|
package/dist/esm/BaseVisitor.mjs
CHANGED
|
@@ -282,7 +282,12 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
282
282
|
value = reference;
|
|
283
283
|
}
|
|
284
284
|
else {
|
|
285
|
-
|
|
285
|
+
if (reference.trailers && reference.trailers.length > 0) {
|
|
286
|
+
value = reference;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
value = reference.value;
|
|
290
|
+
}
|
|
286
291
|
}
|
|
287
292
|
}
|
|
288
293
|
}
|