circuitscript 0.1.4 → 0.1.7
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 +149 -80
- package/dist/cjs/SemanticTokenVisitor.js +19 -13
- package/dist/cjs/antlr/CircuitScriptParser.js +711 -671
- package/dist/cjs/builtinMethods.js +48 -22
- package/dist/cjs/draw_symbols.js +4 -1
- package/dist/cjs/environment.js +118 -0
- package/dist/cjs/execute.js +98 -46
- package/dist/cjs/geometry.js +1 -0
- package/dist/cjs/globals.js +14 -7
- package/dist/cjs/helpers.js +142 -150
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/layout.js +39 -14
- package/dist/cjs/main.js +34 -21
- package/dist/cjs/objects/ClassComponent.js +4 -1
- package/dist/cjs/objects/ExecutionScope.js +40 -2
- package/dist/cjs/objects/ParamDefinition.js +15 -15
- package/dist/cjs/parser.js +27 -21
- package/dist/cjs/regenerate-tests.js +9 -6
- package/dist/cjs/render.js +3 -1
- package/dist/cjs/sizing.js +10 -60
- package/dist/cjs/utils.js +148 -17
- package/dist/cjs/validate/SymbolTable.js +96 -0
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +14 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +170 -0
- package/dist/cjs/validate.js +52 -44
- package/dist/cjs/visitor.js +149 -31
- package/dist/esm/{BaseVisitor.mjs → BaseVisitor.js} +124 -56
- package/dist/esm/{SemanticTokenVisitor.mjs → SemanticTokenVisitor.js} +17 -11
- package/dist/esm/antlr/{CircuitScriptParser.mjs → CircuitScriptParser.js} +711 -671
- package/dist/esm/{builtinMethods.mjs → builtinMethods.js} +40 -14
- package/dist/esm/{draw_symbols.mjs → draw_symbols.js} +11 -8
- package/dist/esm/environment.js +110 -0
- package/dist/esm/{execute.mjs → execute.js} +111 -58
- package/dist/esm/{export.mjs → export.js} +2 -2
- package/dist/esm/{geometry.mjs → geometry.js} +6 -5
- package/dist/esm/{globals.mjs → globals.js} +9 -2
- package/dist/esm/helpers.js +377 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/{layout.mjs → layout.js} +44 -22
- package/dist/esm/{lexer.mjs → lexer.js} +2 -2
- package/dist/esm/{main.mjs → main.js} +36 -23
- package/dist/esm/objects/{ClassComponent.mjs → ClassComponent.js} +9 -5
- package/dist/esm/objects/{ExecutionScope.mjs → ExecutionScope.js} +40 -2
- package/dist/esm/objects/{Frame.mjs → Frame.js} +1 -1
- package/dist/esm/objects/{ParamDefinition.mjs → ParamDefinition.js} +1 -1
- package/dist/esm/objects/{PinDefinition.mjs → PinDefinition.js} +1 -1
- package/dist/esm/parser.js +71 -0
- package/dist/esm/{regenerate-tests.mjs → regenerate-tests.js} +10 -7
- package/dist/esm/{render.mjs → render.js} +11 -9
- package/dist/esm/{sizing.mjs → sizing.js} +11 -36
- package/dist/esm/utils.js +286 -0
- package/dist/esm/validate/SymbolTable.js +90 -0
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +10 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +163 -0
- package/dist/esm/validate.js +86 -0
- package/dist/esm/{visitor.mjs → visitor.js} +160 -42
- package/dist/fonts/Arial.ttf +0 -0
- package/dist/fonts/Inter-Bold.ttf +0 -0
- package/dist/fonts/Inter-Regular.ttf +0 -0
- package/dist/fonts/OpenSans-Regular.ttf +0 -0
- package/dist/fonts/Roboto-Regular.ttf +0 -0
- package/dist/libs/lib.cst +423 -0
- package/dist/types/BaseVisitor.d.ts +36 -22
- package/dist/types/SemanticTokenVisitor.d.ts +6 -5
- package/dist/types/antlr/CircuitScriptParser.d.ts +4 -2
- package/dist/types/builtinMethods.d.ts +3 -2
- package/dist/types/draw_symbols.d.ts +2 -6
- package/dist/types/environment.d.ts +31 -0
- package/dist/types/execute.d.ts +2 -3
- package/dist/types/globals.d.ts +7 -2
- package/dist/types/helpers.d.ts +12 -14
- package/dist/types/index.d.ts +5 -0
- package/dist/types/objects/ClassComponent.d.ts +2 -3
- package/dist/types/objects/ExecutionScope.d.ts +20 -6
- package/dist/types/objects/types.d.ts +6 -1
- package/dist/types/parser.d.ts +7 -11
- package/dist/types/sizing.d.ts +0 -3
- package/dist/types/utils.d.ts +33 -4
- package/dist/types/validate/SymbolTable.d.ts +40 -0
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +7 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +32 -0
- package/dist/types/validate.d.ts +1 -1
- package/libs/lib.cst +12 -22
- package/package.json +14 -13
- package/dist/cjs/SymbolValidatorVisitor.js +0 -233
- package/dist/esm/SymbolValidatorVisitor.mjs +0 -222
- package/dist/esm/helpers.mjs +0 -380
- package/dist/esm/index.mjs +0 -15
- package/dist/esm/parser.mjs +0 -64
- package/dist/esm/utils.mjs +0 -169
- package/dist/esm/validate.mjs +0 -74
- package/dist/types/SymbolValidatorVisitor.d.ts +0 -61
- package/dist/types/layout.d.ts +0 -148
- /package/dist/esm/antlr/{CircuitScriptLexer.mjs → CircuitScriptLexer.js} +0 -0
- /package/dist/esm/antlr/{CircuitScriptVisitor.mjs → CircuitScriptVisitor.js} +0 -0
- /package/dist/esm/{fonts.mjs → fonts.js} +0 -0
- /package/dist/esm/{logger.mjs → logger.js} +0 -0
- /package/dist/esm/objects/{Net.mjs → Net.js} +0 -0
- /package/dist/esm/objects/{PinTypes.mjs → PinTypes.js} +0 -0
- /package/dist/esm/objects/{Wire.mjs → Wire.js} +0 -0
- /package/dist/esm/objects/{types.mjs → types.js} +0 -0
- /package/dist/esm/{server.mjs → server.js} +0 -0
|
@@ -3,10 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.linkBuiltInMethods = void 0;
|
|
6
|
+
exports.linkBuiltInMethods = exports.buildInMethodNamesList = void 0;
|
|
7
7
|
const big_js_1 = __importDefault(require("big.js"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
9
|
+
const utils_js_1 = require("./utils.js");
|
|
10
|
+
const builtInMethods = [
|
|
11
|
+
['enumerate', enumerate],
|
|
12
|
+
['toMils', toMils],
|
|
13
|
+
['range', range],
|
|
14
|
+
['len', objectLength],
|
|
15
|
+
['arrayPush', arrayPush],
|
|
16
|
+
['arrayGet', arrayGet],
|
|
17
|
+
['print', null],
|
|
18
|
+
];
|
|
19
|
+
exports.buildInMethodNamesList = builtInMethods.map(item => item[0]);
|
|
10
20
|
function linkBuiltInMethods(context, visitor) {
|
|
11
21
|
context.createFunction('print', (params) => {
|
|
12
22
|
const args = getPositionParams(params);
|
|
@@ -18,24 +28,20 @@ function linkBuiltInMethods(context, visitor) {
|
|
|
18
28
|
visitor.printStream.push(printedValue);
|
|
19
29
|
return [visitor, printedValue];
|
|
20
30
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const args = getPositionParams(params);
|
|
30
|
-
const functionReturn = functionImpl(...args);
|
|
31
|
-
return [visitor, functionReturn];
|
|
32
|
-
});
|
|
31
|
+
builtInMethods.forEach(([functionName, functionImpl]) => {
|
|
32
|
+
if (functionImpl !== null) {
|
|
33
|
+
context.createFunction(functionName, params => {
|
|
34
|
+
const args = getPositionParams(params);
|
|
35
|
+
const functionReturn = functionImpl(...args);
|
|
36
|
+
return [visitor, functionReturn];
|
|
37
|
+
});
|
|
38
|
+
}
|
|
33
39
|
});
|
|
34
40
|
}
|
|
35
41
|
exports.linkBuiltInMethods = linkBuiltInMethods;
|
|
36
42
|
function range(...args) {
|
|
37
|
-
let startValue = (0,
|
|
38
|
-
let endValue = (0,
|
|
43
|
+
let startValue = (0, ParamDefinition_js_1.numeric)(0);
|
|
44
|
+
let endValue = (0, ParamDefinition_js_1.numeric)(0);
|
|
39
45
|
if (args.length === 1) {
|
|
40
46
|
endValue = args[0];
|
|
41
47
|
}
|
|
@@ -62,7 +68,7 @@ function enumerate(array) {
|
|
|
62
68
|
}
|
|
63
69
|
function toMils(value) {
|
|
64
70
|
let bigValue;
|
|
65
|
-
if (value instanceof
|
|
71
|
+
if (value instanceof ParamDefinition_js_1.NumericValue) {
|
|
66
72
|
bigValue = value.toBigNumber();
|
|
67
73
|
}
|
|
68
74
|
else {
|
|
@@ -72,21 +78,41 @@ function toMils(value) {
|
|
|
72
78
|
bigValue = new big_js_1.default(value);
|
|
73
79
|
}
|
|
74
80
|
bigValue = bigValue.div(new big_js_1.default(25.4 / 1000));
|
|
75
|
-
return (0,
|
|
81
|
+
return (0, utils_js_1.resolveToNumericValue)(bigValue);
|
|
76
82
|
}
|
|
77
83
|
function objectLength(obj) {
|
|
78
84
|
if (Array.isArray(obj)) {
|
|
79
|
-
return (0,
|
|
85
|
+
return (0, ParamDefinition_js_1.numeric)(obj.length);
|
|
80
86
|
}
|
|
81
87
|
else {
|
|
82
88
|
if (obj.length) {
|
|
83
|
-
return (0,
|
|
89
|
+
return (0, ParamDefinition_js_1.numeric)(obj.length);
|
|
84
90
|
}
|
|
85
91
|
else {
|
|
86
92
|
throw "Could not get length of object: " + obj;
|
|
87
93
|
}
|
|
88
94
|
}
|
|
89
95
|
}
|
|
96
|
+
function arrayPush(arrayObject, valueToPush) {
|
|
97
|
+
if (!Array.isArray(arrayObject)) {
|
|
98
|
+
throw "Invalid array object to push";
|
|
99
|
+
}
|
|
100
|
+
arrayObject.push(valueToPush);
|
|
101
|
+
return arrayObject;
|
|
102
|
+
}
|
|
103
|
+
function arrayGet(arrayObject, index) {
|
|
104
|
+
if (!Array.isArray(arrayObject)) {
|
|
105
|
+
throw "Invalid array object to get";
|
|
106
|
+
}
|
|
107
|
+
let useValue;
|
|
108
|
+
if (index instanceof ParamDefinition_js_1.NumericValue) {
|
|
109
|
+
useValue = index.toNumber();
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
useValue = index;
|
|
113
|
+
}
|
|
114
|
+
return arrayObject[useValue];
|
|
115
|
+
}
|
|
90
116
|
function getPositionParams(params) {
|
|
91
117
|
return params.map(([, , value]) => value);
|
|
92
118
|
}
|
|
@@ -101,7 +127,7 @@ function toString(obj) {
|
|
|
101
127
|
const inner = obj.map(item => toString(item)).join(", ");
|
|
102
128
|
return "[" + inner + "]";
|
|
103
129
|
}
|
|
104
|
-
else if (obj instanceof
|
|
130
|
+
else if (obj instanceof ParamDefinition_js_1.NumericValue) {
|
|
105
131
|
return obj.toBigNumber().toString();
|
|
106
132
|
}
|
|
107
133
|
else {
|
package/dist/cjs/draw_symbols.js
CHANGED
|
@@ -792,7 +792,10 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
792
792
|
calculateSize() {
|
|
793
793
|
const tmpPinSpacing = this.pinSpacing.toNumber();
|
|
794
794
|
const tmpPinLength = this.pinLength.toNumber();
|
|
795
|
-
const
|
|
795
|
+
const maxTopPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Top);
|
|
796
|
+
const maxBottomPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Bottom);
|
|
797
|
+
const maxLeftPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Left);
|
|
798
|
+
const maxRightPins = this.pinMaxPositions.get(globals_js_1.SymbolPinSide.Right);
|
|
796
799
|
const bodyWidthFromPins = (0, ParamDefinition_js_1.numeric)((1 + Math.max(maxTopPins, maxBottomPins)) * tmpPinSpacing);
|
|
797
800
|
const bodyWidth = Math.max(bodyWidthFromPins.toNumber(), this.bodyWidth.toNumber());
|
|
798
801
|
let tmpBodyHeight = 0;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NodeScriptEnvironment = void 0;
|
|
7
|
+
const svg_js_1 = require("@svgdotjs/svg.js");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const globals_js_1 = require("./globals.js");
|
|
11
|
+
const utils_js_1 = require("./utils.js");
|
|
12
|
+
class NodeScriptEnvironment {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.useModuleDirectoryPath = null;
|
|
15
|
+
this.useDefaultLibsPath = null;
|
|
16
|
+
this.globalCreateSVGWindow = null;
|
|
17
|
+
this.supportedFonts = {
|
|
18
|
+
'Arial': 'Arial.ttf',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
static setInstance(instance) {
|
|
22
|
+
NodeScriptEnvironment._instance = instance;
|
|
23
|
+
}
|
|
24
|
+
static getInstance() {
|
|
25
|
+
return NodeScriptEnvironment._instance;
|
|
26
|
+
}
|
|
27
|
+
setModuleDirectory(path) {
|
|
28
|
+
this.useModuleDirectoryPath = path;
|
|
29
|
+
}
|
|
30
|
+
setDefaultLibsPath(path) {
|
|
31
|
+
this.useDefaultLibsPath = path;
|
|
32
|
+
}
|
|
33
|
+
getPackageVersion() {
|
|
34
|
+
return globals_js_1.TOOL_VERSION;
|
|
35
|
+
}
|
|
36
|
+
getModuleDirectory() {
|
|
37
|
+
if (this.useModuleDirectoryPath !== null) {
|
|
38
|
+
return this.useModuleDirectoryPath;
|
|
39
|
+
}
|
|
40
|
+
if (typeof __dirname !== 'undefined') {
|
|
41
|
+
return __dirname;
|
|
42
|
+
}
|
|
43
|
+
const stackLine = new Error().stack?.split('\n')[1];
|
|
44
|
+
if (stackLine) {
|
|
45
|
+
const fileMatch = stackLine.match(/\((.+)\:[\d]+\:[\d]+\)/);
|
|
46
|
+
if (fileMatch) {
|
|
47
|
+
const filePath = fileMatch[1].replace('file://', '');
|
|
48
|
+
return path_1.default.dirname(filePath);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw new utils_js_1.RuntimeExecutionError("Failed to get current module directory");
|
|
52
|
+
}
|
|
53
|
+
getRelativeToModule(filePath) {
|
|
54
|
+
return path_1.default.join(this.getModuleDirectory(), filePath);
|
|
55
|
+
}
|
|
56
|
+
getRelativeToDefaultLibs(filePath) {
|
|
57
|
+
return path_1.default.join(this.getDefaultLibsPath(), filePath);
|
|
58
|
+
}
|
|
59
|
+
getToolsPath() {
|
|
60
|
+
return path_1.default.normalize(this.getModuleDirectory() + '/../');
|
|
61
|
+
}
|
|
62
|
+
getFontsPath() {
|
|
63
|
+
return path_1.default.normalize(this.getToolsPath() + "fonts");
|
|
64
|
+
}
|
|
65
|
+
getDefaultLibsPath() {
|
|
66
|
+
if (this.useDefaultLibsPath !== null) {
|
|
67
|
+
return this.useDefaultLibsPath;
|
|
68
|
+
}
|
|
69
|
+
return path_1.default.normalize(this.getToolsPath() + "libs");
|
|
70
|
+
}
|
|
71
|
+
async prepareSVGEnvironmentInternal(fontsPath) {
|
|
72
|
+
try {
|
|
73
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
74
|
+
const { config, createSVGWindow } = await dynamicImport('svgdom');
|
|
75
|
+
this.globalCreateSVGWindow = createSVGWindow;
|
|
76
|
+
if (fontsPath !== null) {
|
|
77
|
+
await config.setFontDir(fontsPath)
|
|
78
|
+
.setFontFamilyMappings(this.supportedFonts)
|
|
79
|
+
.preloadFonts();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new Error(`Failed to load svgdom ESM module: ${error}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
createSVGWindow() {
|
|
87
|
+
if (this.globalCreateSVGWindow === null) {
|
|
88
|
+
throw new Error("SVG environment is not set up yet. Call prepareSVGEnvironment() first.");
|
|
89
|
+
}
|
|
90
|
+
return this.globalCreateSVGWindow();
|
|
91
|
+
}
|
|
92
|
+
getCanvasWindow() {
|
|
93
|
+
if (this.textMeasurementCanvas === undefined) {
|
|
94
|
+
const window = this.createSVGWindow();
|
|
95
|
+
const { document } = window;
|
|
96
|
+
(0, svg_js_1.registerWindow)(window, document);
|
|
97
|
+
this.textMeasurementCanvas = (0, svg_js_1.SVG)(document.documentElement);
|
|
98
|
+
}
|
|
99
|
+
return this.textMeasurementCanvas;
|
|
100
|
+
}
|
|
101
|
+
prepareSVGEnvironment() {
|
|
102
|
+
return this.prepareSVGEnvironmentInternal(this.getFontsPath());
|
|
103
|
+
}
|
|
104
|
+
async readFile(path, options) {
|
|
105
|
+
return fs_1.default.promises.readFile(path, options);
|
|
106
|
+
}
|
|
107
|
+
async exists(path) {
|
|
108
|
+
try {
|
|
109
|
+
fs_1.default.promises.access(path, fs_1.default.constants.F_OK);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.NodeScriptEnvironment = NodeScriptEnvironment;
|
|
118
|
+
NodeScriptEnvironment._instance = null;
|
package/dist/cjs/execute.js
CHANGED
|
@@ -13,6 +13,7 @@ const Frame_js_1 = require("./objects/Frame.js");
|
|
|
13
13
|
const layout_js_1 = require("./layout.js");
|
|
14
14
|
const helpers_js_1 = require("./helpers.js");
|
|
15
15
|
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
16
|
+
const utils_js_1 = require("./utils.js");
|
|
16
17
|
class ExecutionContext {
|
|
17
18
|
constructor(name, namespace, netNamespace, executionLevel = 0, indentLevel = 0, silent = false, logger, parent) {
|
|
18
19
|
this.tmpPointId = 0;
|
|
@@ -30,13 +31,6 @@ class ExecutionContext {
|
|
|
30
31
|
this.scope = ExecutionScope_js_1.ExecutionScope.create();
|
|
31
32
|
this.scope.indentLevel = indentLevel;
|
|
32
33
|
this.setupRoot();
|
|
33
|
-
if (name === '__') {
|
|
34
|
-
this.scope.sequence.push([
|
|
35
|
-
ExecutionScope_js_1.SequenceAction.At,
|
|
36
|
-
this.scope.componentRoot,
|
|
37
|
-
this.scope.currentPin
|
|
38
|
-
]);
|
|
39
|
-
}
|
|
40
34
|
this.silent = silent;
|
|
41
35
|
this.log('create new execution context', this.namespace, this.name, this.scope.indentLevel);
|
|
42
36
|
this.parentContext = parent;
|
|
@@ -62,12 +56,12 @@ class ExecutionContext {
|
|
|
62
56
|
this.scope.componentRoot = componentRoot;
|
|
63
57
|
}
|
|
64
58
|
getUniqueInstanceName() {
|
|
65
|
-
const tmpName =
|
|
59
|
+
const tmpName = `COMP${globals_js_1.Delimiter1}${this.scope.unnamedCounter}`;
|
|
66
60
|
this.scope.unnamedCounter += 1;
|
|
67
61
|
return tmpName;
|
|
68
62
|
}
|
|
69
63
|
getUniqueNetName() {
|
|
70
|
-
const tmpName =
|
|
64
|
+
const tmpName = `NET${globals_js_1.Delimiter1}${this.scope.netCounter}`;
|
|
71
65
|
this.scope.netCounter++;
|
|
72
66
|
return tmpName;
|
|
73
67
|
}
|
|
@@ -77,7 +71,7 @@ class ExecutionContext {
|
|
|
77
71
|
linkComponentPinNet(component1, component1Pin, component2, component2Pin) {
|
|
78
72
|
const net1 = this.scope.getNet(component1, component1Pin);
|
|
79
73
|
const net2 = this.scope.getNet(component2, component2Pin);
|
|
80
|
-
this.log('link nets', component1, component1Pin, net1, 'to', component2, component2Pin, net2);
|
|
74
|
+
this.log('link nets', component1, component1Pin, net1, 'priority:' + net1?.priority, 'to', component2, component2Pin, net2, 'priority:' + net2?.priority);
|
|
81
75
|
let returnNet;
|
|
82
76
|
if (net1 === null && net2 === null) {
|
|
83
77
|
const tmpNet = new Net_js_1.Net(this.netNamespace, this.getUniqueNetName());
|
|
@@ -101,7 +95,7 @@ class ExecutionContext {
|
|
|
101
95
|
returnNet = net1;
|
|
102
96
|
}
|
|
103
97
|
}
|
|
104
|
-
this.log('final net after link: ', returnNet);
|
|
98
|
+
this.log('final net after link: ', returnNet, returnNet.priority);
|
|
105
99
|
return returnNet;
|
|
106
100
|
}
|
|
107
101
|
mergeNets(net1, net2) {
|
|
@@ -162,8 +156,9 @@ class ExecutionContext {
|
|
|
162
156
|
tmpNet = new Net_js_1.Net(this.netNamespace, netName, priority);
|
|
163
157
|
this.log('net not found, added net instance', tmpNet.namespace, tmpNet.name);
|
|
164
158
|
}
|
|
165
|
-
|
|
166
|
-
this.
|
|
159
|
+
const defaultPin = 1;
|
|
160
|
+
this.scope.setNet(component, defaultPin, tmpNet);
|
|
161
|
+
this.log('set net', netName, 'component', component, defaultPin);
|
|
167
162
|
}
|
|
168
163
|
const { pins: pinSides, maxPositions } = getPortSide(component.pins, component.arrangeProps);
|
|
169
164
|
component.pinsMaxPositions = maxPositions;
|
|
@@ -205,14 +200,13 @@ class ExecutionContext {
|
|
|
205
200
|
this.atComponent(component, nextPin, {
|
|
206
201
|
addSequence: true
|
|
207
202
|
});
|
|
208
|
-
this.printPoint();
|
|
209
203
|
return this.getCurrentPoint();
|
|
210
204
|
}
|
|
211
205
|
toComponent(component, pinId, options) {
|
|
212
206
|
this.log('to component');
|
|
213
207
|
const { addSequence = false } = options ?? {};
|
|
214
208
|
if (!(component instanceof ClassComponent_js_1.ClassComponent)) {
|
|
215
|
-
throw "Not a valid component!";
|
|
209
|
+
throw new utils_js_1.RuntimeExecutionError("Not a valid component!");
|
|
216
210
|
}
|
|
217
211
|
if (pinId === null) {
|
|
218
212
|
pinId = component.getDefaultPin();
|
|
@@ -223,7 +217,7 @@ class ExecutionContext {
|
|
|
223
217
|
}
|
|
224
218
|
else {
|
|
225
219
|
console.trace();
|
|
226
|
-
throw ('Invalid pin number ' +
|
|
220
|
+
throw new utils_js_1.RuntimeExecutionError('Invalid pin number ' +
|
|
227
221
|
pinId +
|
|
228
222
|
' in ' +
|
|
229
223
|
component.instanceName);
|
|
@@ -279,6 +273,7 @@ class ExecutionContext {
|
|
|
279
273
|
return this.getCurrentPoint();
|
|
280
274
|
}
|
|
281
275
|
copyComponent(component) {
|
|
276
|
+
this.log('create clone of net component:', component);
|
|
282
277
|
let componentCopy = null;
|
|
283
278
|
if (!this.scope.copyIDs.has(component.instanceName)) {
|
|
284
279
|
this.scope.copyIDs.set(component.instanceName, 0);
|
|
@@ -291,14 +286,24 @@ class ExecutionContext {
|
|
|
291
286
|
const cloneInstanceName = component.instanceName + ':' + idNum;
|
|
292
287
|
this.scope.instances.set(cloneInstanceName, componentCopy);
|
|
293
288
|
componentCopy.instanceName = cloneInstanceName;
|
|
294
|
-
|
|
289
|
+
const defaultPin = 1;
|
|
290
|
+
if (this.scope.getNet(component, defaultPin) === null) {
|
|
291
|
+
const foundNet = this.resolveComponentPinNet(component, defaultPin);
|
|
292
|
+
if (foundNet !== null) {
|
|
293
|
+
this.log('found net in upper scopes', foundNet);
|
|
294
|
+
this.scope.setNet(component, defaultPin, foundNet);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
this.linkComponentPinNet(component, defaultPin, componentCopy, defaultPin);
|
|
295
298
|
this.log('created clone of net component:', cloneInstanceName);
|
|
296
299
|
return componentCopy;
|
|
297
300
|
}
|
|
298
301
|
enterBlocks(blockType) {
|
|
299
|
-
if (blockType === globals_js_1.BlockTypes.Point
|
|
300
|
-
|
|
301
|
-
|
|
302
|
+
if (blockType === globals_js_1.BlockTypes.Point
|
|
303
|
+
|| blockType === globals_js_1.BlockTypes.Parallel
|
|
304
|
+
|| blockType === globals_js_1.BlockTypes.Branch) {
|
|
305
|
+
const key = (0, utils_js_1.getBlockTypeString)(blockType);
|
|
306
|
+
this.addPoint(`${globals_js_1.Delimiter1}${key}.${this.name}.${this.tmpPointId}`, false);
|
|
302
307
|
this.tmpPointId += 1;
|
|
303
308
|
}
|
|
304
309
|
this.scope.blockStack.set(this.scope.indentLevel, {
|
|
@@ -337,6 +342,7 @@ class ExecutionContext {
|
|
|
337
342
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
338
343
|
stackRef['block_index'] = blockIndex;
|
|
339
344
|
const { type: blockType } = stackRef;
|
|
345
|
+
const blockTypeName = (0, utils_js_1.getBlockTypeString)(blockType);
|
|
340
346
|
stackRef['inner_blocks'].set(blockIndex, {
|
|
341
347
|
last_net: null,
|
|
342
348
|
ignore_last_net: false,
|
|
@@ -349,7 +355,7 @@ class ExecutionContext {
|
|
|
349
355
|
const { entered_at: [component, pin,] } = stackRef;
|
|
350
356
|
this.atComponent(component, pin, { addSequence: true });
|
|
351
357
|
}
|
|
352
|
-
this.log(`enter inner block of type (${
|
|
358
|
+
this.log(`enter inner block of type (${blockTypeName}) >>>`);
|
|
353
359
|
this.scope.indentLevel += 1;
|
|
354
360
|
}
|
|
355
361
|
exitBlock(blockIndex) {
|
|
@@ -373,7 +379,7 @@ class ExecutionContext {
|
|
|
373
379
|
}
|
|
374
380
|
else if (blockType === globals_js_1.BlockTypes.Join || blockType === globals_js_1.BlockTypes.Parallel) {
|
|
375
381
|
if (blockIndex === 0) {
|
|
376
|
-
const pointIdName = (
|
|
382
|
+
const pointIdName = `${globals_js_1.Delimiter1}${(0, utils_js_1.getBlockTypeString)(blockType)}`;
|
|
377
383
|
this.addPoint(`${pointIdName}.${this.name}.${this.tmpPointId}`, false);
|
|
378
384
|
this.tmpPointId += 1;
|
|
379
385
|
stackRef['final_point'] = [
|
|
@@ -407,7 +413,7 @@ class ExecutionContext {
|
|
|
407
413
|
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
408
414
|
const { entered_at } = stackRef;
|
|
409
415
|
const component = entered_at[0];
|
|
410
|
-
if (component.instanceName.startsWith(
|
|
416
|
+
if (component.instanceName.startsWith(`${globals_js_1.Delimiter1}point.`)) {
|
|
411
417
|
return entered_at;
|
|
412
418
|
}
|
|
413
419
|
}
|
|
@@ -522,14 +528,12 @@ class ExecutionContext {
|
|
|
522
528
|
const currentComponent = this.scope.currentComponent;
|
|
523
529
|
const currentPin = this.scope.currentPin;
|
|
524
530
|
const currentWireId = this.scope.currentWireId;
|
|
525
|
-
const gndCopyIdOffset = 0;
|
|
526
531
|
const tmpInstances = childScope.instances;
|
|
527
532
|
const tmpNets = childScope.getNets();
|
|
528
533
|
for (const [instanceName, component] of tmpInstances) {
|
|
529
534
|
const newInstanceName = `${namespace}.${instanceName}`;
|
|
530
535
|
component.instanceName = newInstanceName;
|
|
531
|
-
if (component === childScope.
|
|
532
|
-
component === childScope.componentRoot) {
|
|
536
|
+
if (component === childScope.componentRoot) {
|
|
533
537
|
continue;
|
|
534
538
|
}
|
|
535
539
|
if (!this.scope.instances.has(newInstanceName)) {
|
|
@@ -539,6 +543,16 @@ class ExecutionContext {
|
|
|
539
543
|
throw "Invalid instance name to merge into parent scope!";
|
|
540
544
|
}
|
|
541
545
|
}
|
|
546
|
+
const childScopeUniqueNets = new Set(tmpNets.map(([, , net]) => net));
|
|
547
|
+
childScopeUniqueNets.forEach(net => {
|
|
548
|
+
if (net.priority === 0
|
|
549
|
+
&& this.scope.getNetWithNamespacePath(net.namespace, net.name) !== null) {
|
|
550
|
+
this.log('net namespace and name already used in parent scope', net);
|
|
551
|
+
const newNetName = this.getUniqueNetName();
|
|
552
|
+
net.name = newNetName;
|
|
553
|
+
this.log('assigned new name: ', net);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
542
556
|
tmpNets.forEach(([component, pin, net]) => {
|
|
543
557
|
this.scope.setNet(component, pin, net);
|
|
544
558
|
});
|
|
@@ -553,7 +567,6 @@ class ExecutionContext {
|
|
|
553
567
|
this.scope.setNet(currentComponent, currentPin, netConnectedToRoot);
|
|
554
568
|
currentNet = tmpNet;
|
|
555
569
|
}
|
|
556
|
-
netConnectedToRoot.priority = currentNet.priority - 1;
|
|
557
570
|
this.toComponent(tmpRoot, 1);
|
|
558
571
|
}
|
|
559
572
|
}
|
|
@@ -642,25 +655,65 @@ class ExecutionContext {
|
|
|
642
655
|
this.log('Warning: ' + pointId + ' is being redefined');
|
|
643
656
|
}
|
|
644
657
|
const useName = userDefined ? 'point.' + pointId : pointId;
|
|
645
|
-
const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1
|
|
646
|
-
componentPoint.displayProp = this.getPointSymbol();
|
|
658
|
+
const componentPoint = ClassComponent_js_1.ClassComponent.simple(useName, 1);
|
|
659
|
+
componentPoint.displayProp = this.getPointSymbol(useName);
|
|
647
660
|
componentPoint.typeProp = globals_js_1.ComponentTypes.net;
|
|
661
|
+
let usePointLinkComponent = null;
|
|
662
|
+
if (this.scope.currentComponent._pointLinkComponent) {
|
|
663
|
+
usePointLinkComponent = this.scope.currentComponent._pointLinkComponent;
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
usePointLinkComponent = this.scope.currentComponent;
|
|
667
|
+
}
|
|
668
|
+
componentPoint._pointLinkComponent = usePointLinkComponent;
|
|
648
669
|
this.scope.instances.set(pointId, componentPoint);
|
|
649
670
|
this.toComponent(componentPoint, 1, { addSequence: true });
|
|
650
671
|
return this.getCurrentPoint();
|
|
651
672
|
}
|
|
652
|
-
getPointSymbol() {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
[
|
|
656
|
-
|
|
657
|
-
|
|
673
|
+
getPointSymbol(name = "") {
|
|
674
|
+
const commands = [
|
|
675
|
+
[draw_symbols_js_1.PlaceHolderCommands.pin,
|
|
676
|
+
[(0, ParamDefinition_js_1.numeric)(1), (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0),
|
|
677
|
+
(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0)],
|
|
678
|
+
new Map([
|
|
679
|
+
["display_pin_id", false]
|
|
680
|
+
]),
|
|
681
|
+
null
|
|
682
|
+
]
|
|
683
|
+
];
|
|
684
|
+
if (false) {
|
|
685
|
+
commands.push(...[
|
|
686
|
+
[draw_symbols_js_1.PlaceHolderCommands.lineColor,
|
|
687
|
+
["red"],
|
|
688
|
+
new Map(), null
|
|
689
|
+
],
|
|
690
|
+
[draw_symbols_js_1.PlaceHolderCommands.hline,
|
|
691
|
+
[(0, ParamDefinition_js_1.numeric)(-25), (0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(50)],
|
|
692
|
+
new Map(),
|
|
693
|
+
null
|
|
694
|
+
],
|
|
695
|
+
[draw_symbols_js_1.PlaceHolderCommands.vline,
|
|
696
|
+
[(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(-25), (0, ParamDefinition_js_1.numeric)(50)],
|
|
697
|
+
new Map(),
|
|
698
|
+
null
|
|
699
|
+
],
|
|
700
|
+
[draw_symbols_js_1.PlaceHolderCommands.hline,
|
|
701
|
+
[(0, ParamDefinition_js_1.numeric)(0), (0, ParamDefinition_js_1.numeric)(0),
|
|
702
|
+
(0, ParamDefinition_js_1.numeric)(10)],
|
|
703
|
+
new Map([]), null
|
|
704
|
+
],
|
|
705
|
+
[draw_symbols_js_1.PlaceHolderCommands.text,
|
|
706
|
+
[],
|
|
658
707
|
new Map([
|
|
659
|
-
["
|
|
708
|
+
["content", name],
|
|
709
|
+
["fontSize", (0, ParamDefinition_js_1.numeric)(10)],
|
|
660
710
|
]),
|
|
661
711
|
null
|
|
662
712
|
]
|
|
663
|
-
];
|
|
713
|
+
]);
|
|
714
|
+
}
|
|
715
|
+
return new draw_symbols_js_1.SymbolDrawingCommands(() => {
|
|
716
|
+
return commands;
|
|
664
717
|
});
|
|
665
718
|
}
|
|
666
719
|
setProperty(nameWithProp, value) {
|
|
@@ -797,12 +850,11 @@ function isWireSegmentsEndAuto(segments) {
|
|
|
797
850
|
}
|
|
798
851
|
function getPortSide(pins, arrangeProps) {
|
|
799
852
|
const result = [];
|
|
800
|
-
const maxPositions =
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
};
|
|
853
|
+
const maxPositions = new Map();
|
|
854
|
+
maxPositions.set(globals_js_1.SymbolPinSide.Left, 0);
|
|
855
|
+
maxPositions.set(globals_js_1.SymbolPinSide.Right, 0);
|
|
856
|
+
maxPositions.set(globals_js_1.SymbolPinSide.Top, 0);
|
|
857
|
+
maxPositions.set(globals_js_1.SymbolPinSide.Bottom, 0);
|
|
806
858
|
if (arrangeProps === null) {
|
|
807
859
|
let counter = 0;
|
|
808
860
|
for (const [pinId] of pins) {
|
|
@@ -820,8 +872,8 @@ function getPortSide(pins, arrangeProps) {
|
|
|
820
872
|
const rightSideItems = result.filter(item => {
|
|
821
873
|
return item.side === PinDefinition_js_1.PortSide.EAST;
|
|
822
874
|
});
|
|
823
|
-
maxPositions
|
|
824
|
-
maxPositions
|
|
875
|
+
maxPositions.set(globals_js_1.SymbolPinSide.Left, leftSideItems.length);
|
|
876
|
+
maxPositions.set(globals_js_1.SymbolPinSide.Right, rightSideItems.length);
|
|
825
877
|
}
|
|
826
878
|
else {
|
|
827
879
|
let counter = pins.size;
|
|
@@ -868,7 +920,7 @@ function getPortSide(pins, arrangeProps) {
|
|
|
868
920
|
}
|
|
869
921
|
}
|
|
870
922
|
});
|
|
871
|
-
maxPositions
|
|
923
|
+
maxPositions.set(key, position);
|
|
872
924
|
}
|
|
873
925
|
}
|
|
874
926
|
return {
|
package/dist/cjs/geometry.js
CHANGED
package/dist/cjs/globals.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.SymbolValidatorContext = exports.RenderFlags = exports.GlobalDocumentName = exports.ModuleContainsKeyword = exports.FrameType = exports.BlockTypes = exports.ReferenceTypes = exports.ComponentTypes = exports.ColorScheme = exports.PortPaddingVertical = exports.PortPaddingHorizontal = exports.PortArrowSize = exports.junctionSize = exports.defaultFontSize = exports.defaultFontBold = exports.defaultFont = exports.displayUnits = exports.defaultFrameTitleTextSize = exports.CustomSymbolParamTextSize = exports.CustomSymbolRefDesSize = exports.CustomSymbolPinIdSize = exports.CustomSymbolPinTextSize = exports.defaultPageSpacingMM = exports.defaultPageMarginMM = exports.defaultPinIdTextSize = exports.defaultPinNameTextSize = exports.defaultWireLineWidth = exports.defaultSymbolLineWidth = exports.fontDisplayScale = exports.defaultZoomScale = exports.defaultGridSizeUnits = exports.portHeight = exports.portWidth = exports.PxToMM = exports.MMToPt = exports.MMToPx = exports.MilsToMM = exports.WireAutoDirection = exports.LengthUnit = exports.ValidPinSides = exports.SymbolPinSide = exports.LayoutDirection = exports.ParamKeys = exports.NoNetText = exports.GlobalNames = exports.DoubleDelimiter1 = exports.Delimiter1 = exports.TOOL_VERSION = void 0;
|
|
4
|
+
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
5
|
+
exports.TOOL_VERSION = '0.1.5';
|
|
6
|
+
exports.Delimiter1 = '-';
|
|
7
|
+
exports.DoubleDelimiter1 = `${exports.Delimiter1}${exports.Delimiter1}`;
|
|
5
8
|
var GlobalNames;
|
|
6
9
|
(function (GlobalNames) {
|
|
7
|
-
GlobalNames["__root"] = "
|
|
10
|
+
GlobalNames["__root"] = "--root";
|
|
8
11
|
GlobalNames["symbol"] = "symbol";
|
|
9
12
|
})(GlobalNames || (exports.GlobalNames = GlobalNames = {}));
|
|
10
13
|
exports.NoNetText = 'NO_NET';
|
|
@@ -29,6 +32,9 @@ var SymbolPinSide;
|
|
|
29
32
|
SymbolPinSide["Top"] = "top";
|
|
30
33
|
SymbolPinSide["Bottom"] = "bottom";
|
|
31
34
|
})(SymbolPinSide || (exports.SymbolPinSide = SymbolPinSide = {}));
|
|
35
|
+
exports.ValidPinSides = [
|
|
36
|
+
SymbolPinSide.Left, SymbolPinSide.Right, SymbolPinSide.Top, SymbolPinSide.Bottom
|
|
37
|
+
];
|
|
32
38
|
var LengthUnit;
|
|
33
39
|
(function (LengthUnit) {
|
|
34
40
|
LengthUnit["mm"] = "mm";
|
|
@@ -46,11 +52,11 @@ exports.MMToPt = 2.8346456693;
|
|
|
46
52
|
exports.PxToMM = 0.2645833;
|
|
47
53
|
exports.portWidth = 20;
|
|
48
54
|
exports.portHeight = 2;
|
|
49
|
-
exports.defaultGridSizeUnits = (0,
|
|
55
|
+
exports.defaultGridSizeUnits = (0, ParamDefinition_js_1.numeric)(exports.MilsToMM).mul(100).toNumber();
|
|
50
56
|
exports.defaultZoomScale = 2.5;
|
|
51
57
|
exports.fontDisplayScale = 0.032;
|
|
52
|
-
exports.defaultSymbolLineWidth = (0,
|
|
53
|
-
exports.defaultWireLineWidth = (0,
|
|
58
|
+
exports.defaultSymbolLineWidth = (0, ParamDefinition_js_1.numeric)(exports.MilsToMM).mul(6).toNumber();
|
|
59
|
+
exports.defaultWireLineWidth = (0, ParamDefinition_js_1.numeric)(exports.MilsToMM).mul(6).toNumber();
|
|
54
60
|
exports.defaultPinNameTextSize = 40;
|
|
55
61
|
exports.defaultPinIdTextSize = 30;
|
|
56
62
|
exports.defaultPageMarginMM = 10;
|
|
@@ -64,7 +70,7 @@ exports.displayUnits = LengthUnit.mils;
|
|
|
64
70
|
exports.defaultFont = 'Arial';
|
|
65
71
|
exports.defaultFontBold = 'Arial';
|
|
66
72
|
exports.defaultFontSize = 10;
|
|
67
|
-
exports.junctionSize = (0,
|
|
73
|
+
exports.junctionSize = (0, ParamDefinition_js_1.numeric)(exports.MilsToMM).mul(20);
|
|
68
74
|
exports.PortArrowSize = exports.MilsToMM * 50;
|
|
69
75
|
exports.PortPaddingHorizontal = exports.MilsToMM * 10;
|
|
70
76
|
exports.PortPaddingVertical = exports.MilsToMM * 10;
|
|
@@ -111,3 +117,4 @@ exports.RenderFlags = {
|
|
|
111
117
|
ShowLabelBoxBounds: false,
|
|
112
118
|
ShowLabelOrigin: false,
|
|
113
119
|
};
|
|
120
|
+
exports.SymbolValidatorContext = '_sym';
|