circuitscript 0.1.33 → 0.3.0
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 +32 -32
- package/dist/cjs/BomGeneration.js +2 -3
- package/dist/cjs/ComponentMatchConditions.js +2 -2
- package/dist/cjs/SemanticTokenVisitor.js +1 -1
- package/dist/cjs/antlr/CircuitScriptParser.js +3 -3
- package/dist/cjs/builtinMethods.js +2 -2
- package/dist/cjs/environment.js +14 -6
- package/dist/cjs/execute.js +28 -24
- package/dist/cjs/globals.js +2 -1
- package/dist/cjs/graph.js +1 -1
- package/dist/cjs/helpers.js +28 -29
- package/dist/cjs/objects/ExecutionScope.js +1 -1
- package/dist/cjs/objects/types.js +7 -18
- package/dist/cjs/validate/SymbolValidatorVisitor.js +7 -7
- package/dist/cjs/visitor.js +6 -6
- package/dist/esm/BaseVisitor.js +33 -33
- package/dist/esm/BomGeneration.js +2 -3
- package/dist/esm/ComponentMatchConditions.js +2 -2
- package/dist/esm/SemanticTokenVisitor.js +1 -1
- package/dist/esm/antlr/CircuitScriptParser.js +6 -6
- package/dist/esm/builtinMethods.js +3 -3
- package/dist/esm/environment.js +10 -2
- package/dist/esm/execute.js +28 -24
- package/dist/esm/globals.js +2 -1
- package/dist/esm/graph.js +2 -2
- package/dist/esm/helpers.js +28 -29
- package/dist/esm/objects/ExecutionScope.js +1 -1
- package/dist/esm/objects/types.js +8 -19
- package/dist/esm/validate/SymbolValidatorVisitor.js +7 -7
- package/dist/esm/visitor.js +7 -7
- package/dist/types/BaseVisitor.d.ts +6 -6
- package/dist/types/BomGeneration.d.ts +2 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +3 -3
- package/dist/types/environment.d.ts +7 -4
- package/dist/types/globals.d.ts +3 -2
- package/dist/types/helpers.d.ts +2 -2
- package/dist/types/objects/ExecutionScope.d.ts +2 -2
- package/dist/types/objects/types.d.ts +5 -15
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +1 -1
- package/dist/types/visitor.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportFunctionHandling = exports.
|
|
3
|
+
exports.ImportFunctionHandling = exports.ImportedLibrary = exports.NetTypes = exports.Direction = exports.ParseSymbolType = exports.DeclaredReference = exports.UndeclaredReference = exports.AnyReference = exports.CFunctionEntry = void 0;
|
|
4
4
|
const globals_js_1 = require("../globals.js");
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
class CFunctionEntry {
|
|
@@ -111,29 +111,18 @@ var Direction;
|
|
|
111
111
|
Direction["Down"] = "down";
|
|
112
112
|
Direction["Up"] = "up";
|
|
113
113
|
})(Direction || (exports.Direction = Direction = {}));
|
|
114
|
-
var TypeProps;
|
|
115
|
-
(function (TypeProps) {
|
|
116
|
-
TypeProps["Net"] = "net";
|
|
117
|
-
TypeProps["Port"] = "port";
|
|
118
|
-
TypeProps["Graphic"] = "graphic";
|
|
119
|
-
TypeProps["Module"] = "module";
|
|
120
|
-
TypeProps["Resistor"] = "res";
|
|
121
|
-
TypeProps["Capacitor"] = "cap";
|
|
122
|
-
TypeProps["Inductor"] = "ind";
|
|
123
|
-
TypeProps["Diode"] = "diode";
|
|
124
|
-
})(TypeProps || (exports.TypeProps = TypeProps = {}));
|
|
125
114
|
var NetTypes;
|
|
126
115
|
(function (NetTypes) {
|
|
127
116
|
NetTypes["Any"] = "any";
|
|
128
117
|
NetTypes["Source"] = "source";
|
|
129
118
|
})(NetTypes || (exports.NetTypes = NetTypes = {}));
|
|
130
|
-
class
|
|
131
|
-
constructor(
|
|
119
|
+
class ImportedLibrary {
|
|
120
|
+
constructor(libraryName, libraryNamespace, libraryFilePath, tree, tokens, context, flag, specifiedImports) {
|
|
132
121
|
this.enableRefdesAnnotation = false;
|
|
133
122
|
this.enableRefdesAnnotationFile = false;
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
136
|
-
this.
|
|
123
|
+
this.libraryName = libraryName;
|
|
124
|
+
this.libraryNamespace = libraryNamespace;
|
|
125
|
+
this.libraryFilePath = libraryFilePath;
|
|
137
126
|
this.tree = tree;
|
|
138
127
|
this.tokens = tokens;
|
|
139
128
|
this.context = context;
|
|
@@ -141,7 +130,7 @@ class ImportedModule {
|
|
|
141
130
|
this.specifiedImports = specifiedImports;
|
|
142
131
|
}
|
|
143
132
|
}
|
|
144
|
-
exports.
|
|
133
|
+
exports.ImportedLibrary = ImportedLibrary;
|
|
145
134
|
var ImportFunctionHandling;
|
|
146
135
|
(function (ImportFunctionHandling) {
|
|
147
136
|
ImportFunctionHandling["AllWithNamespace"] = "all-with-namespace";
|
|
@@ -167,24 +167,24 @@ class SymbolValidatorVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
167
167
|
});
|
|
168
168
|
specifiedImports.push(...tmpImports);
|
|
169
169
|
}
|
|
170
|
-
const id = ctx.
|
|
171
|
-
const { pathExists,
|
|
170
|
+
const id = ctx._libraryName.text;
|
|
171
|
+
const { pathExists, importedLibrary } = await this.handleImportFile(id, handling, true, ctx, specifiedImports);
|
|
172
172
|
if (!pathExists) {
|
|
173
|
-
this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx.
|
|
173
|
+
this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx._libraryName);
|
|
174
174
|
}
|
|
175
175
|
else {
|
|
176
|
-
this.
|
|
176
|
+
this.applyLibraryImports(importedLibrary);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
const { importHandlingFlag: importHandling, specifiedImports } =
|
|
179
|
+
applyLibraryImports(library) {
|
|
180
|
+
const { importHandlingFlag: importHandling, specifiedImports } = library;
|
|
181
181
|
const addedSymbols = [];
|
|
182
182
|
const executor = this.getExecutor();
|
|
183
183
|
const symbolTable = this.symbolTable.getSymbols();
|
|
184
184
|
symbolTable.forEach((value, key) => {
|
|
185
185
|
if (value.type === types_js_1.ParseSymbolType.Function) {
|
|
186
186
|
const definedSymbol = value;
|
|
187
|
-
if (definedSymbol.fileName ===
|
|
187
|
+
if (definedSymbol.fileName === library.libraryFilePath) {
|
|
188
188
|
const addSymbolToNamespace = importHandling === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace
|
|
189
189
|
|| (importHandling === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace
|
|
190
190
|
&& specifiedImports.indexOf(definedSymbol.id) !== -1);
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -351,7 +351,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
351
351
|
return new PinDefinition_js_1.PinDefinition(index + 1, PinDefinition_js_1.PinIdType.Int, portName, PinTypes_js_1.PinTypes.Any);
|
|
352
352
|
});
|
|
353
353
|
const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
|
|
354
|
-
const unitProperties = this.extractComponentUnitProperties(properties,
|
|
354
|
+
const unitProperties = this.extractComponentUnitProperties(properties, globals_js_1.ComponentTypes.module);
|
|
355
355
|
const firstUnitDef = unitProperties[0][1];
|
|
356
356
|
firstUnitDef.pins = tmpPorts;
|
|
357
357
|
firstUnitDef.arrange = arrange;
|
|
@@ -362,7 +362,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
362
362
|
};
|
|
363
363
|
const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
|
|
364
364
|
const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
|
|
365
|
-
moduleComponent.typeProp =
|
|
365
|
+
moduleComponent.typeProp = globals_js_1.ComponentTypes.module;
|
|
366
366
|
const ctxPropertyBlock = ctx.property_block_expr();
|
|
367
367
|
if (ctxPropertyBlock) {
|
|
368
368
|
const [firstBlock] = ctxPropertyBlock;
|
|
@@ -1148,7 +1148,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1148
1148
|
const display = properties.get('display') ?? null;
|
|
1149
1149
|
const suffix = properties.get('suffix') ?? null;
|
|
1150
1150
|
let pins = [];
|
|
1151
|
-
if (display !== null && arrange === null && typeProp !==
|
|
1151
|
+
if (display !== null && arrange === null && typeProp !== globals_js_1.ComponentTypes.graphic) {
|
|
1152
1152
|
const drawCommands = display.getCommands();
|
|
1153
1153
|
drawCommands.forEach(command => {
|
|
1154
1154
|
const [commandValue,] = command;
|
|
@@ -1385,7 +1385,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1385
1385
|
currentComponent.forceSaveRefdesAnnotation = forceSave;
|
|
1386
1386
|
}
|
|
1387
1387
|
}
|
|
1388
|
-
async
|
|
1388
|
+
async checkLibraryHasRefdesFile(filePath) {
|
|
1389
1389
|
const dir = this.environment.dirname(filePath);
|
|
1390
1390
|
const ext = this.environment.extname(filePath);
|
|
1391
1391
|
const basename = this.environment.basename(filePath, ext);
|
|
@@ -1655,8 +1655,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1655
1655
|
const fullNetNames = Array.from(uniqueNets).map(item => item.toString());
|
|
1656
1656
|
nets.forEach(([component, pin, net]) => {
|
|
1657
1657
|
if (net.priority === 0 && seenNets.indexOf(net) === -1
|
|
1658
|
-
&& component.typeProp !==
|
|
1659
|
-
&& component.typeProp !==
|
|
1658
|
+
&& component.typeProp !== globals_js_1.ComponentTypes.module
|
|
1659
|
+
&& component.typeProp !== globals_js_1.ComponentTypes.net) {
|
|
1660
1660
|
net.name = net.baseName =
|
|
1661
1661
|
`NET-(${component.assignedRefDes}-${pin.toString()})`;
|
|
1662
1662
|
if (fullNetNames.indexOf(net.toString()) !== -1) {
|
package/dist/esm/BaseVisitor.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Logger } from "./logger.js";
|
|
|
6
6
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
7
7
|
import { NumberOperator, NumericValue, PercentageValue } from "./objects/ParamDefinition.js";
|
|
8
8
|
import { PinTypes } from "./objects/PinTypes.js";
|
|
9
|
-
import { Direction, AnyReference, UndeclaredReference,
|
|
9
|
+
import { Direction, AnyReference, UndeclaredReference, ImportedLibrary, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
|
|
10
10
|
import { BaseNamespace, ComponentTypes, DoubleDelimiter1, GlobalDocumentName, ReferenceTypes, TrailerArrayIndex } from './globals.js';
|
|
11
11
|
import { isReference, unwrapValue as unwrapValue } from "./utils.js";
|
|
12
12
|
import { linkBuiltInMethods } from './builtinMethods.js';
|
|
@@ -145,17 +145,17 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
145
145
|
});
|
|
146
146
|
specificImports.push(...tmpSpecificImports);
|
|
147
147
|
}
|
|
148
|
-
const id = ctx.
|
|
148
|
+
const id = ctx._libraryName.text;
|
|
149
149
|
const importedFile = await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
150
150
|
const ctxImportAnnotation = ctx.import_annotation_expr();
|
|
151
151
|
if (ctxImportAnnotation) {
|
|
152
152
|
const textValue = ctxImportAnnotation.getText().replace('#=', '');
|
|
153
|
-
const {
|
|
153
|
+
const { importedLibrary } = importedFile;
|
|
154
154
|
if (textValue === 'annotate') {
|
|
155
|
-
|
|
155
|
+
importedLibrary.enableRefdesAnnotation = true;
|
|
156
156
|
}
|
|
157
157
|
else if (textValue === 'annotate-external') {
|
|
158
|
-
|
|
158
|
+
importedLibrary.enableRefdesAnnotationFile = true;
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -417,23 +417,23 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
417
417
|
}
|
|
418
418
|
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
419
419
|
try {
|
|
420
|
-
const
|
|
421
|
-
&& currentReference.rootValue instanceof
|
|
422
|
-
if (
|
|
423
|
-
this.log('create new
|
|
424
|
-
const
|
|
425
|
-
const
|
|
426
|
-
this.enterFile(
|
|
427
|
-
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack,
|
|
420
|
+
const isLibraryFunction = currentReference.rootValue
|
|
421
|
+
&& currentReference.rootValue instanceof ImportedLibrary;
|
|
422
|
+
if (isLibraryFunction) {
|
|
423
|
+
this.log('create new library context');
|
|
424
|
+
const importedLibrary = currentReference.rootValue;
|
|
425
|
+
const { context: importedLibraryContext } = importedLibrary;
|
|
426
|
+
this.enterFile(importedLibrary.libraryFilePath);
|
|
427
|
+
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedLibraryContext.name, ctx, {
|
|
428
428
|
netNamespace: executor.netNamespace,
|
|
429
|
-
namespace:
|
|
429
|
+
namespace: importedLibrary.libraryNamespace
|
|
430
430
|
}, [], [], false);
|
|
431
|
-
this.log('copy
|
|
432
|
-
|
|
431
|
+
this.log('copy library context scope');
|
|
432
|
+
importedLibraryContext.scope.copyTo(newExecutor.scope);
|
|
433
433
|
}
|
|
434
434
|
const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
|
|
435
|
-
if (
|
|
436
|
-
this.log('pop
|
|
435
|
+
if (isLibraryFunction) {
|
|
436
|
+
this.log('pop library context scope');
|
|
437
437
|
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
438
438
|
this.exitFile();
|
|
439
439
|
}
|
|
@@ -712,8 +712,8 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
712
712
|
return item.id === name;
|
|
713
713
|
});
|
|
714
714
|
if (importAlready) {
|
|
715
|
-
const
|
|
716
|
-
const alreadyImportedFlag =
|
|
715
|
+
const { importedLibrary: tmpImportedLibrary } = importAlready;
|
|
716
|
+
const alreadyImportedFlag = tmpImportedLibrary.importHandlingFlag;
|
|
717
717
|
const isMergedNamespace = alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace
|
|
718
718
|
|| alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace;
|
|
719
719
|
const invalidImportCondition1 = alreadyImportedFlag === ImportFunctionHandling.AllWithNamespace &&
|
|
@@ -727,11 +727,11 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
727
727
|
if (alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
728
728
|
}
|
|
729
729
|
else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
730
|
-
|
|
731
|
-
|
|
730
|
+
tmpImportedLibrary.specifiedImports = [];
|
|
731
|
+
tmpImportedLibrary.importHandlingFlag = ImportFunctionHandling.AllMergeIntoNamespace;
|
|
732
732
|
}
|
|
733
733
|
else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.SpecificMergeIntoNamespace) {
|
|
734
|
-
|
|
734
|
+
tmpImportedLibrary.specifiedImports.push(...specificImports);
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
737
|
return importAlready;
|
|
@@ -752,7 +752,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
752
752
|
this.log('failed to read file');
|
|
753
753
|
pathExists = false;
|
|
754
754
|
}
|
|
755
|
-
let
|
|
755
|
+
let importedLibrary;
|
|
756
756
|
if (!pathExists) {
|
|
757
757
|
try {
|
|
758
758
|
const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
|
|
@@ -773,26 +773,26 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
773
773
|
const executor = this.getExecutor();
|
|
774
774
|
const executionContextName = name;
|
|
775
775
|
const netNamespace = executor.netNamespace;
|
|
776
|
-
const
|
|
776
|
+
const libraryNamespace = `${BaseNamespace}${name}.`;
|
|
777
777
|
this.enterNewChildContext(executionStack, executor, executionContextName, {
|
|
778
778
|
netNamespace,
|
|
779
|
-
namespace:
|
|
779
|
+
namespace: libraryNamespace,
|
|
780
780
|
}, [], []);
|
|
781
781
|
const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
|
|
782
782
|
hasError = importResult.hasError;
|
|
783
783
|
hasParseError = importResult.hasParseError;
|
|
784
784
|
const importContext = executionStack.pop();
|
|
785
785
|
this.log(`import handling flag: ${importHandling}`);
|
|
786
|
-
|
|
786
|
+
importedLibrary = new ImportedLibrary(name, libraryNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
|
|
787
787
|
if (specificImports.length > 0) {
|
|
788
788
|
this.log('specific import: ' + specificImports.join(', '));
|
|
789
789
|
}
|
|
790
790
|
const scope = this.getScope();
|
|
791
|
-
scope.
|
|
792
|
-
|
|
793
|
-
scope.
|
|
791
|
+
scope.libraries.set(name, importedLibrary);
|
|
792
|
+
importedLibrary.context.scope.libraries.forEach((lib, key) => {
|
|
793
|
+
scope.libraries.set(key, lib);
|
|
794
794
|
});
|
|
795
|
-
await this.
|
|
795
|
+
await this.checkLibraryHasRefdesFile(filePathUsed);
|
|
796
796
|
}
|
|
797
797
|
}
|
|
798
798
|
catch (err) {
|
|
@@ -820,12 +820,12 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
820
820
|
hasError,
|
|
821
821
|
hasParseError,
|
|
822
822
|
pathExists,
|
|
823
|
-
|
|
823
|
+
importedLibrary: importedLibrary
|
|
824
824
|
};
|
|
825
825
|
this.importedFiles.push(newImportedFile);
|
|
826
826
|
return newImportedFile;
|
|
827
827
|
}
|
|
828
|
-
async
|
|
828
|
+
async checkLibraryHasRefdesFile(filePath) {
|
|
829
829
|
return;
|
|
830
830
|
}
|
|
831
831
|
getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as csv from '@fast-csv/format';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
2
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
4
3
|
const TypeSortOrder = {
|
|
5
4
|
"res": 1,
|
|
@@ -122,9 +121,9 @@ export function generateBomCSV(bomData) {
|
|
|
122
121
|
});
|
|
123
122
|
return rows;
|
|
124
123
|
}
|
|
125
|
-
export async function saveBomOutputCsv(bomCsvOutput, filePath) {
|
|
124
|
+
export async function saveBomOutputCsv(environment, bomCsvOutput, filePath) {
|
|
126
125
|
return new Promise(resolve => {
|
|
127
|
-
const outputStream =
|
|
126
|
+
const outputStream = environment.createWriteStream(filePath);
|
|
128
127
|
const csvStream = csv.format();
|
|
129
128
|
csvStream.pipe(outputStream).on("finish", () => {
|
|
130
129
|
resolve();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ComponentTypes } from "./globals.js";
|
|
1
2
|
import { NumericValue } from "./objects/ParamDefinition.js";
|
|
2
|
-
import { TypeProps } from "./objects/types.js";
|
|
3
3
|
export function flattenConditionNodes(conditionNodes, level = 0) {
|
|
4
4
|
const conditionBranches = [];
|
|
5
5
|
conditionNodes.forEach(node => {
|
|
@@ -95,7 +95,7 @@ export function partMatchesConditions(instance, partConditions) {
|
|
|
95
95
|
}
|
|
96
96
|
export function applyPartConditions(instances, paramKeys, partConditions) {
|
|
97
97
|
instances.forEach(item => {
|
|
98
|
-
if (item.typeProp !==
|
|
98
|
+
if (item.typeProp !== ComponentTypes.graphic) {
|
|
99
99
|
const matchedResult = partMatchesConditions(item, partConditions);
|
|
100
100
|
if (matchedResult !== undefined) {
|
|
101
101
|
paramKeys.forEach((paramKey, index) => {
|
|
@@ -208,7 +208,7 @@ export function prepareTokens(tokens, lexer, script) {
|
|
|
208
208
|
const languageKeywords = [
|
|
209
209
|
'break', 'branch', 'create', 'component',
|
|
210
210
|
'graphic', 'wire', 'pin', 'add', 'at', 'to',
|
|
211
|
-
'point', 'join', 'parallel', 'return', 'def', 'import',
|
|
211
|
+
'point', 'join', 'parallel', 'return', 'def', 'from', 'import',
|
|
212
212
|
'true', 'false', 'nc', 'sheet', 'frame', 'if', 'else', 'for', 'in',
|
|
213
213
|
];
|
|
214
214
|
const operatorKeywords = [
|
|
@@ -3572,7 +3572,7 @@ export class CircuitScriptParser extends antlr.Parser {
|
|
|
3572
3572
|
this.state = 686;
|
|
3573
3573
|
this.match(CircuitScriptParser.Import);
|
|
3574
3574
|
this.state = 687;
|
|
3575
|
-
localContext.
|
|
3575
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3576
3576
|
this.state = 689;
|
|
3577
3577
|
this.errorHandler.sync(this);
|
|
3578
3578
|
switch (this.interpreter.adaptivePredict(this.tokenStream, 76, this.context)) {
|
|
@@ -3592,7 +3592,7 @@ export class CircuitScriptParser extends antlr.Parser {
|
|
|
3592
3592
|
this.state = 691;
|
|
3593
3593
|
this.match(CircuitScriptParser.From);
|
|
3594
3594
|
this.state = 692;
|
|
3595
|
-
localContext.
|
|
3595
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3596
3596
|
this.state = 693;
|
|
3597
3597
|
this.match(CircuitScriptParser.Import);
|
|
3598
3598
|
this.state = 694;
|
|
@@ -3616,7 +3616,7 @@ export class CircuitScriptParser extends antlr.Parser {
|
|
|
3616
3616
|
this.state = 698;
|
|
3617
3617
|
this.match(CircuitScriptParser.From);
|
|
3618
3618
|
this.state = 699;
|
|
3619
|
-
localContext.
|
|
3619
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3620
3620
|
this.state = 700;
|
|
3621
3621
|
this.match(CircuitScriptParser.Import);
|
|
3622
3622
|
this.state = 701;
|
|
@@ -6760,7 +6760,7 @@ export class Import_exprContext extends antlr.ParserRuleContext {
|
|
|
6760
6760
|
}
|
|
6761
6761
|
}
|
|
6762
6762
|
export class Import_specificContext extends Import_exprContext {
|
|
6763
|
-
|
|
6763
|
+
_libraryName;
|
|
6764
6764
|
_ID;
|
|
6765
6765
|
_funcNames = [];
|
|
6766
6766
|
constructor(ctx) {
|
|
@@ -6794,7 +6794,7 @@ export class Import_specificContext extends Import_exprContext {
|
|
|
6794
6794
|
}
|
|
6795
6795
|
}
|
|
6796
6796
|
export class Import_all_simpleContext extends Import_exprContext {
|
|
6797
|
-
|
|
6797
|
+
_libraryName;
|
|
6798
6798
|
constructor(ctx) {
|
|
6799
6799
|
super(ctx.parent, ctx.invokingState);
|
|
6800
6800
|
super.copyFrom(ctx);
|
|
@@ -6824,7 +6824,7 @@ export class Import_all_simpleContext extends Import_exprContext {
|
|
|
6824
6824
|
}
|
|
6825
6825
|
}
|
|
6826
6826
|
export class Import_simpleContext extends Import_exprContext {
|
|
6827
|
-
|
|
6827
|
+
_libraryName;
|
|
6828
6828
|
constructor(ctx) {
|
|
6829
6829
|
super(ctx.parent, ctx.invokingState);
|
|
6830
6830
|
super.copyFrom(ctx);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { numeric, NumericValue } from "./objects/ParamDefinition.js";
|
|
3
|
-
import { CFunctionEntry,
|
|
3
|
+
import { CFunctionEntry, ImportedLibrary } from "./objects/types.js";
|
|
4
4
|
import { unwrapValue, resolveToNumericValue, RuntimeExecutionError } from "./utils.js";
|
|
5
5
|
import { BaseNamespace } from "./globals.js";
|
|
6
6
|
const builtInMethods = [
|
|
@@ -149,8 +149,8 @@ function toString(obj) {
|
|
|
149
149
|
else if (obj instanceof CFunctionEntry) {
|
|
150
150
|
return obj.toString();
|
|
151
151
|
}
|
|
152
|
-
else if (obj instanceof
|
|
153
|
-
return `[
|
|
152
|
+
else if (obj instanceof ImportedLibrary) {
|
|
153
|
+
return `[library: ${obj.libraryName}]`;
|
|
154
154
|
}
|
|
155
155
|
else {
|
|
156
156
|
if (obj === undefined) {
|
package/dist/esm/environment.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { registerWindow, SVG } from "@svgdotjs/svg.js";
|
|
2
|
-
import { writeFileSync } from "fs";
|
|
3
2
|
import fs from 'fs';
|
|
4
3
|
import path from "path";
|
|
5
4
|
import CryptoJs from "crypto-js";
|
|
6
5
|
import { TOOL_VERSION } from "./globals.js";
|
|
7
6
|
import { RuntimeExecutionError } from "./utils.js";
|
|
8
7
|
export class NodeScriptEnvironment {
|
|
8
|
+
existsSync(pathLike) {
|
|
9
|
+
return fs.existsSync(pathLike);
|
|
10
|
+
}
|
|
11
|
+
mkdirSync(pathLike) {
|
|
12
|
+
return fs.mkdirSync(pathLike);
|
|
13
|
+
}
|
|
9
14
|
static _instance = null;
|
|
10
15
|
static setInstance(instance) {
|
|
11
16
|
NodeScriptEnvironment._instance = instance;
|
|
@@ -117,7 +122,7 @@ export class NodeScriptEnvironment {
|
|
|
117
122
|
return fs.promises.readFile(path, options);
|
|
118
123
|
}
|
|
119
124
|
writeFileSync(path, data) {
|
|
120
|
-
return writeFileSync(path, data);
|
|
125
|
+
return fs.writeFileSync(path, data);
|
|
121
126
|
}
|
|
122
127
|
getAbsolutePath(filePath) {
|
|
123
128
|
return path.resolve(filePath);
|
|
@@ -162,4 +167,7 @@ export class NodeScriptEnvironment {
|
|
|
162
167
|
relative(from, to) {
|
|
163
168
|
return path.relative(from, to);
|
|
164
169
|
}
|
|
170
|
+
createWriteStream(filePath) {
|
|
171
|
+
return fs.createWriteStream(filePath);
|
|
172
|
+
}
|
|
165
173
|
}
|
package/dist/esm/execute.js
CHANGED
|
@@ -646,19 +646,18 @@ export class ExecutionContext {
|
|
|
646
646
|
});
|
|
647
647
|
}
|
|
648
648
|
else {
|
|
649
|
-
const
|
|
650
|
-
for (
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
if (module.context.hasFunction(functionPath)) {
|
|
649
|
+
const libraries = Array.from(context.scope.libraries.values());
|
|
650
|
+
for (const library of libraries) {
|
|
651
|
+
if (library.importHandlingFlag === ImportFunctionHandling.AllMergeIntoNamespace ||
|
|
652
|
+
(library.importHandlingFlag === ImportFunctionHandling.SpecificMergeIntoNamespace
|
|
653
|
+
&& library.specifiedImports.indexOf(idName) !== -1)) {
|
|
654
|
+
const { context: libraryContext } = library;
|
|
655
|
+
const functionPath = `${libraryContext.namespace}${idName}`;
|
|
656
|
+
if (library.context.hasFunction(functionPath)) {
|
|
658
657
|
return new DeclaredReference({
|
|
659
658
|
found: true,
|
|
660
|
-
rootValue:
|
|
661
|
-
value:
|
|
659
|
+
rootValue: library,
|
|
660
|
+
value: library.context.getFunction(functionPath),
|
|
662
661
|
type: ReferenceTypes.function,
|
|
663
662
|
name: idName,
|
|
664
663
|
trailerIndex: 1,
|
|
@@ -667,24 +666,24 @@ export class ExecutionContext {
|
|
|
667
666
|
}
|
|
668
667
|
}
|
|
669
668
|
}
|
|
670
|
-
let
|
|
671
|
-
if (context.scope.
|
|
672
|
-
const
|
|
673
|
-
if (
|
|
674
|
-
|
|
669
|
+
let isLibrary = false;
|
|
670
|
+
if (context.scope.libraries.has(idName)) {
|
|
671
|
+
const library = context.scope.libraries.get(idName);
|
|
672
|
+
if (library.importHandlingFlag === ImportFunctionHandling.AllWithNamespace) {
|
|
673
|
+
isLibrary = true;
|
|
675
674
|
}
|
|
676
675
|
}
|
|
677
676
|
let isVariable = context.scope.variables.has(idName);
|
|
678
677
|
let isComponentInstance = context.scope.instances.has(idName);
|
|
679
|
-
if (
|
|
680
|
-
const scopeList =
|
|
678
|
+
if (isLibrary || isVariable || isComponentInstance) {
|
|
679
|
+
const scopeList = isLibrary ? context.scope.libraries :
|
|
681
680
|
(isVariable ? context.scope.variables : context.scope.instances);
|
|
682
681
|
const useValue = scopeList.get(idName);
|
|
683
682
|
if (!isComponentInstance && (useValue instanceof ClassComponent)) {
|
|
684
683
|
isComponentInstance = true;
|
|
685
684
|
isVariable = false;
|
|
686
685
|
}
|
|
687
|
-
const referenceType =
|
|
686
|
+
const referenceType = isLibrary ? ReferenceTypes.library :
|
|
688
687
|
(isVariable ? ReferenceTypes.variable : ReferenceTypes.instance);
|
|
689
688
|
const tmpReference = this.resolveTrailers(referenceType, useValue, trailers);
|
|
690
689
|
return new DeclaredReference({
|
|
@@ -731,12 +730,12 @@ export class ExecutionContext {
|
|
|
731
730
|
}
|
|
732
731
|
break;
|
|
733
732
|
}
|
|
734
|
-
case ReferenceTypes.
|
|
733
|
+
case ReferenceTypes.library: {
|
|
735
734
|
const funcName = trailers[0];
|
|
736
|
-
const
|
|
737
|
-
const functionPath = `${
|
|
738
|
-
if (
|
|
739
|
-
const foundFunc =
|
|
735
|
+
const library = rootValue;
|
|
736
|
+
const functionPath = `${library.libraryNamespace}${funcName}`;
|
|
737
|
+
if (library.context.hasFunction(functionPath)) {
|
|
738
|
+
const foundFunc = library.context.getFunction(functionPath);
|
|
740
739
|
return new AnyReference({
|
|
741
740
|
found: true,
|
|
742
741
|
type: ReferenceTypes.function,
|
|
@@ -1017,6 +1016,11 @@ export class ExecutionContext {
|
|
|
1017
1016
|
ParamKeys.flipY,
|
|
1018
1017
|
];
|
|
1019
1018
|
if (unitModifiers.indexOf(paramName) !== -1) {
|
|
1019
|
+
if (paramName === ParamKeys.flipX || paramName == ParamKeys.flipY) {
|
|
1020
|
+
if (typeof value === "boolean") {
|
|
1021
|
+
value = value ? numeric(1) : numeric(0);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1020
1024
|
component.getUnit().setParam(paramName, value);
|
|
1021
1025
|
}
|
|
1022
1026
|
}
|
package/dist/esm/globals.js
CHANGED
|
@@ -87,6 +87,7 @@ export var ComponentTypes;
|
|
|
87
87
|
ComponentTypes["graphic"] = "graphic";
|
|
88
88
|
ComponentTypes["port"] = "port";
|
|
89
89
|
ComponentTypes["module"] = "module";
|
|
90
|
+
ComponentTypes["resistor"] = "res";
|
|
90
91
|
})(ComponentTypes || (ComponentTypes = {}));
|
|
91
92
|
export var ReferenceTypes;
|
|
92
93
|
(function (ReferenceTypes) {
|
|
@@ -95,7 +96,7 @@ export var ReferenceTypes;
|
|
|
95
96
|
ReferenceTypes["variable"] = "variable";
|
|
96
97
|
ReferenceTypes["instance"] = "instance";
|
|
97
98
|
ReferenceTypes["pinType"] = "pinType";
|
|
98
|
-
ReferenceTypes["
|
|
99
|
+
ReferenceTypes["library"] = "library";
|
|
99
100
|
ReferenceTypes["unknown"] = "unknown";
|
|
100
101
|
})(ReferenceTypes || (ReferenceTypes = {}));
|
|
101
102
|
export var BlockTypes;
|
package/dist/esm/graph.js
CHANGED
|
@@ -6,7 +6,7 @@ import { RenderFrame, RenderComponent, applyComponentParamsToSymbol, RenderWire
|
|
|
6
6
|
import { SequenceAction, FrameAction } from "./objects/ExecutionScope.js";
|
|
7
7
|
import { Frame, FixedFrameIds, FrameParamKeys } from "./objects/Frame.js";
|
|
8
8
|
import { numeric } from "./objects/ParamDefinition.js";
|
|
9
|
-
import { NetTypes
|
|
9
|
+
import { NetTypes } from "./objects/types.js";
|
|
10
10
|
import Matrix, { solve } from "ml-matrix";
|
|
11
11
|
import { getPinDefinition, PinId } from "./objects/PinDefinition.js";
|
|
12
12
|
export class NetGraph {
|
|
@@ -232,7 +232,7 @@ export class NetGraph {
|
|
|
232
232
|
const netsLength = netsIndexed.length;
|
|
233
233
|
const conductanceMatrix = Matrix.zeros(netsLength, netsLength);
|
|
234
234
|
components.forEach(item => {
|
|
235
|
-
if (item.typeProp ===
|
|
235
|
+
if (item.typeProp === ComponentTypes.resistor) {
|
|
236
236
|
const net1 = item.pinNets.get(1);
|
|
237
237
|
const net2 = item.pinNets.get(2);
|
|
238
238
|
const net1Index = netsIndexed.indexOf(net1);
|