circuitscript 0.3.2 → 0.4.1
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 +394 -262
- package/dist/cjs/LexerDiagnosticListener.js +375 -0
- package/dist/cjs/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/cjs/annotate/DefaultPostAnnotationCallback.js +126 -0
- package/dist/cjs/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
- package/dist/cjs/annotate/utils.js +70 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +279 -286
- package/dist/cjs/antlr/CircuitScriptParser.js +1954 -3535
- package/dist/cjs/antlr/CircuitScriptParserVisitor.js +7 -0
- package/dist/cjs/cache/deserializer.js +34 -0
- package/dist/cjs/cache/hash.js +8 -0
- package/dist/cjs/cache/serializer.js +122 -0
- package/dist/cjs/cache/storage.js +45 -0
- package/dist/cjs/cache/types.js +4 -0
- package/dist/cjs/{environment.js → environment/environment.js} +18 -6
- package/dist/cjs/environment/esm-environment.js +21 -0
- package/dist/cjs/environment/helpers.js +8 -0
- package/dist/cjs/execute.js +49 -15
- package/dist/cjs/globals.js +9 -1
- package/dist/cjs/helpers.js +3 -485
- package/dist/cjs/importResolver.js +102 -0
- package/dist/cjs/index.js +12 -7
- package/dist/cjs/lexer.js +48 -12
- package/dist/cjs/main.js +14 -4
- package/dist/cjs/objects/ClassComponent.js +1 -1
- package/dist/cjs/objects/ExecutionScope.js +0 -1
- package/dist/cjs/objects/types.js +17 -1
- package/dist/cjs/parser.js +18 -4
- package/dist/cjs/pipeline.js +284 -0
- package/dist/cjs/regenerate-tests.js +4 -3
- package/dist/cjs/render/KiCadNetListOutputHandler.js +30 -0
- package/dist/cjs/render/PaperSizes.js +46 -0
- package/dist/cjs/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/cjs/{export.js → render/export.js} +2 -2
- package/dist/cjs/{geometry.js → render/geometry.js} +5 -5
- package/dist/cjs/{graph.js → render/graph.js} +7 -7
- package/dist/cjs/{layout.js → render/layout.js} +8 -8
- package/dist/cjs/{render.js → render/render.js} +9 -8
- package/dist/cjs/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/cjs/rules-check/unconnected-pins.js +1 -1
- package/dist/cjs/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/cjs/semantic-tokens/getSemanticTokens.js +55 -0
- package/dist/cjs/sizing.js +2 -2
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +6 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +34 -39
- package/dist/cjs/validate/validateScript.js +54 -0
- package/dist/cjs/validate.js +5 -4
- package/dist/cjs/visitor.js +140 -204
- package/dist/esm/BaseVisitor.js +396 -264
- package/dist/esm/LexerDiagnosticListener.js +371 -0
- package/dist/esm/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/esm/annotate/DefaultPostAnnotationCallback.js +122 -0
- package/dist/esm/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
- package/dist/esm/annotate/utils.js +66 -0
- package/dist/esm/antlr/CircuitScriptLexer.js +279 -286
- package/dist/esm/antlr/CircuitScriptParser.js +1962 -3522
- package/dist/esm/antlr/{CircuitScriptVisitor.js → CircuitScriptParserVisitor.js} +14 -35
- package/dist/esm/cache/deserializer.js +30 -0
- package/dist/esm/cache/hash.js +4 -0
- package/dist/esm/cache/serializer.js +118 -0
- package/dist/esm/cache/storage.js +39 -0
- package/dist/esm/cache/types.js +1 -0
- package/dist/esm/{environment.js → environment/environment.js} +18 -6
- package/dist/esm/environment/esm-environment.js +17 -0
- package/dist/esm/environment/helpers.js +4 -0
- package/dist/esm/execute.js +49 -15
- package/dist/esm/globals.js +8 -0
- package/dist/esm/helpers.js +5 -474
- package/dist/esm/importResolver.js +96 -0
- package/dist/esm/index.js +12 -7
- package/dist/esm/lexer.js +51 -12
- package/dist/esm/main.js +13 -3
- package/dist/esm/objects/ClassComponent.js +1 -1
- package/dist/esm/objects/ExecutionScope.js +0 -1
- package/dist/esm/objects/types.js +21 -1
- package/dist/esm/parser.js +19 -5
- package/dist/esm/pipeline.js +276 -0
- package/dist/esm/regenerate-tests.js +3 -2
- package/dist/esm/render/KiCadNetListOutputHandler.js +20 -0
- package/dist/esm/render/PaperSizes.js +41 -0
- package/dist/esm/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/esm/{export.js → render/export.js} +2 -2
- package/dist/esm/{geometry.js → render/geometry.js} +5 -5
- package/dist/esm/{graph.js → render/graph.js} +7 -7
- package/dist/esm/{layout.js → render/layout.js} +8 -8
- package/dist/esm/{render.js → render/render.js} +8 -7
- package/dist/esm/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/esm/rules-check/unconnected-pins.js +1 -1
- package/dist/esm/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/esm/semantic-tokens/getSemanticTokens.js +51 -0
- package/dist/esm/sizing.js +2 -2
- package/dist/esm/utils.js +2 -2
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +3 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +36 -41
- package/dist/esm/validate/validateScript.js +50 -0
- package/dist/esm/validate.js +4 -3
- package/dist/esm/visitor.js +142 -206
- package/dist/libs/std.cst +15 -19
- package/dist/types/BaseVisitor.d.ts +25 -18
- package/dist/types/BomGeneration.d.ts +1 -1
- package/dist/types/LexerDiagnosticListener.d.ts +85 -0
- package/dist/types/{ComponentAnnotater.d.ts → annotate/ComponentAnnotater.d.ts} +1 -1
- package/dist/types/annotate/DefaultPostAnnotationCallback.d.ts +7 -0
- package/dist/types/{RefdesAnnotationVisitor.d.ts → annotate/RefdesAnnotationVisitor.d.ts} +6 -8
- package/dist/types/annotate/utils.d.ts +6 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -70
- package/dist/types/antlr/CircuitScriptParser.d.ts +357 -515
- package/dist/types/antlr/{CircuitScriptVisitor.d.ts → CircuitScriptParserVisitor.d.ts} +27 -69
- package/dist/types/cache/deserializer.d.ts +5 -0
- package/dist/types/cache/hash.d.ts +1 -0
- package/dist/types/cache/serializer.d.ts +3 -0
- package/dist/types/cache/storage.d.ts +4 -0
- package/dist/types/cache/types.d.ts +20 -0
- package/dist/types/{environment.d.ts → environment/environment.d.ts} +5 -4
- package/dist/types/environment/esm-environment.d.ts +4 -0
- package/dist/types/environment/helpers.d.ts +2 -0
- package/dist/types/execute.d.ts +3 -2
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/helpers.d.ts +31 -36
- package/dist/types/importResolver.d.ts +4 -0
- package/dist/types/index.d.ts +12 -7
- package/dist/types/lexer.d.ts +9 -5
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +1 -4
- package/dist/types/objects/types.d.ts +16 -2
- package/dist/types/parser.d.ts +9 -2
- package/dist/types/pipeline.d.ts +9 -0
- package/dist/types/render/KiCadNetListOutputHandler.d.ts +10 -0
- package/dist/types/render/PaperSizes.d.ts +12 -0
- package/dist/types/{draw_symbols.d.ts → render/draw_symbols.d.ts} +4 -4
- package/dist/types/{export.d.ts → render/export.d.ts} +1 -1
- package/dist/types/{geometry.d.ts → render/geometry.d.ts} +2 -2
- package/dist/types/{graph.d.ts → render/graph.d.ts} +6 -6
- package/dist/types/{layout.d.ts → render/layout.d.ts} +10 -10
- package/dist/types/{render.d.ts → render/render.d.ts} +1 -1
- package/dist/types/{SemanticTokenVisitor.d.ts → semantic-tokens/SemanticTokenVisitor.d.ts} +6 -6
- package/dist/types/semantic-tokens/getSemanticTokens.d.ts +6 -0
- package/dist/types/sizing.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +3 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +8 -8
- package/dist/types/validate/validateScript.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -14
- package/libs/std.cst +15 -19
- package/package.json +3 -6
- package/dist/cjs/antlr/CircuitScriptVisitor.js +0 -7
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -3,12 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseVisitor = void 0;
|
|
4
4
|
const big_js_1 = require("big.js");
|
|
5
5
|
const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
|
|
6
|
-
const
|
|
6
|
+
const CircuitScriptParserVisitor_js_1 = require("./antlr/CircuitScriptParserVisitor.js");
|
|
7
7
|
const execute_js_1 = require("./execute.js");
|
|
8
8
|
const logger_js_1 = require("./logger.js");
|
|
9
9
|
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
10
10
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
11
|
-
const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
12
11
|
const types_js_1 = require("./objects/types.js");
|
|
13
12
|
const globals_js_1 = require("./globals.js");
|
|
14
13
|
const utils_js_1 = require("./utils.js");
|
|
@@ -16,7 +15,12 @@ const builtinMethods_js_1 = require("./builtinMethods.js");
|
|
|
16
15
|
const utils_js_2 = require("./utils.js");
|
|
17
16
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
18
17
|
const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
19
|
-
|
|
18
|
+
const hash_js_1 = require("./cache/hash.js");
|
|
19
|
+
const storage_js_1 = require("./cache/storage.js");
|
|
20
|
+
const serializer_js_1 = require("./cache/serializer.js");
|
|
21
|
+
const deserializer_js_1 = require("./cache/deserializer.js");
|
|
22
|
+
const importResolver_js_1 = require("./importResolver.js");
|
|
23
|
+
class BaseVisitor extends CircuitScriptParserVisitor_js_1.CircuitScriptParserVisitor {
|
|
20
24
|
constructor(silent = false, onErrorHandler = null, environment) {
|
|
21
25
|
super();
|
|
22
26
|
this.filePathStack = [];
|
|
@@ -28,25 +32,22 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
28
32
|
types_js_1.Direction.Right, types_js_1.Direction.Left];
|
|
29
33
|
this.resultData = new Map;
|
|
30
34
|
this.componentCtxLinks = new Map;
|
|
31
|
-
this.pinTypesList = [
|
|
32
|
-
PinTypes_js_1.PinTypes.Any,
|
|
33
|
-
PinTypes_js_1.PinTypes.Input,
|
|
34
|
-
PinTypes_js_1.PinTypes.Output,
|
|
35
|
-
PinTypes_js_1.PinTypes.IO,
|
|
36
|
-
PinTypes_js_1.PinTypes.Power,
|
|
37
|
-
];
|
|
38
35
|
this.onErrorHandler = null;
|
|
39
36
|
this.importedFiles = [];
|
|
40
37
|
this.warnings = [];
|
|
41
|
-
this.
|
|
38
|
+
this.loadedFiles = new Map();
|
|
39
|
+
this.enableCacheImports = true;
|
|
40
|
+
this.enableCachedImportsRead = false || this.enableCacheImports;
|
|
41
|
+
this.enableCachedImportsWrite = false || this.enableCacheImports;
|
|
42
|
+
this.onImportFile = (visitor, filePath, fileData, onErrorHandler, fileLineOffset) => {
|
|
42
43
|
throw "Import file not implemented";
|
|
43
44
|
};
|
|
44
45
|
this.refdesFileAnnotations = new Map();
|
|
45
|
-
this.visitScript =
|
|
46
|
+
this.visitScript = (ctx) => {
|
|
46
47
|
this.log('===', 'start', '===');
|
|
47
48
|
this.allowParseImports = true;
|
|
48
49
|
for (const ctxImport of ctx.import_expr()) {
|
|
49
|
-
|
|
50
|
+
this.visit(ctxImport);
|
|
50
51
|
}
|
|
51
52
|
this.allowParseImports = false;
|
|
52
53
|
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
@@ -54,148 +55,225 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
54
55
|
this.getExecutor().closeOpenPathBlocks();
|
|
55
56
|
this.log('===', 'end', '===');
|
|
56
57
|
};
|
|
57
|
-
this.visitImport_simple =
|
|
58
|
-
|
|
58
|
+
this.visitImport_simple = (ctx) => {
|
|
59
|
+
this.importCommon(ctx, types_js_1.ImportFunctionHandling.AllWithNamespace);
|
|
59
60
|
};
|
|
60
|
-
this.
|
|
61
|
-
|
|
61
|
+
this.visitImport_specific_or_all = (ctx) => {
|
|
62
|
+
let importType = types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace;
|
|
63
|
+
if (ctx._all) {
|
|
64
|
+
importType = types_js_1.ImportFunctionHandling.AllMergeIntoNamespace;
|
|
65
|
+
}
|
|
66
|
+
this.importCommon(ctx, importType);
|
|
62
67
|
};
|
|
63
|
-
this.
|
|
64
|
-
|
|
68
|
+
this.visitCallableExpr = (ctx) => {
|
|
69
|
+
this.passResult(ctx, ctx.callable_expr());
|
|
70
|
+
};
|
|
71
|
+
this.visitCallable_expr = (ctx) => {
|
|
72
|
+
const ctxParams = this.getResult(ctx);
|
|
73
|
+
const { keepReference = false } = ctxParams ?? {};
|
|
74
|
+
const executor = this.getExecutor();
|
|
75
|
+
let passedNetNamespace = null;
|
|
76
|
+
const netNameSpaceExpr = ctx.net_namespace_expr();
|
|
77
|
+
if (netNameSpaceExpr) {
|
|
78
|
+
passedNetNamespace = this.visitResult(netNameSpaceExpr);
|
|
79
|
+
}
|
|
80
|
+
const firstId = ctx.ID(0);
|
|
81
|
+
const atomId = firstId.getText();
|
|
82
|
+
let currentReference;
|
|
83
|
+
if (globals_js_1.PinTypesList.indexOf(atomId) !== -1 && ctx.trailer().length === 0) {
|
|
84
|
+
currentReference = new types_js_1.AnyReference({
|
|
85
|
+
found: true,
|
|
86
|
+
value: atomId,
|
|
87
|
+
type: globals_js_1.ReferenceTypes.pinType,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.log('resolve variable ctx: ' + ctx.getText(), 'atomId', atomId);
|
|
92
|
+
currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
93
|
+
this.log('reference:', currentReference.name, 'found:', currentReference.found);
|
|
94
|
+
}
|
|
95
|
+
if (currentReference !== undefined && currentReference.found) {
|
|
96
|
+
ctx.trailer().forEach(ctxTrailer => {
|
|
97
|
+
this.setResult(ctxTrailer, {
|
|
98
|
+
reference: currentReference,
|
|
99
|
+
netNamespace: passedNetNamespace
|
|
100
|
+
});
|
|
101
|
+
currentReference = this.visitResult(ctxTrailer);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
let resultValue = currentReference;
|
|
105
|
+
if (!keepReference) {
|
|
106
|
+
if (currentReference.type !== globals_js_1.ReferenceTypes.pinType) {
|
|
107
|
+
resultValue = (0, utils_js_1.unwrapValue)(resultValue);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.setResult(ctx, resultValue);
|
|
111
|
+
this.log2('atom resolved: ' + ctx.getText() + ' -> ' + currentReference);
|
|
112
|
+
};
|
|
113
|
+
this.visitTrailer = (ctx) => {
|
|
114
|
+
const { reference, netNamespace } = this.getResult(ctx);
|
|
115
|
+
const ctxLParam = ctx.LParen();
|
|
116
|
+
const ctxID = ctx.ID();
|
|
117
|
+
const ctxDataExpr = ctx.data_expr();
|
|
118
|
+
const useValue = reference.value;
|
|
119
|
+
let nextReference;
|
|
120
|
+
if (ctxID) {
|
|
121
|
+
reference.trailers.push(ctxID.getText());
|
|
122
|
+
const useRootValue = reference.rootValue ?? reference.value;
|
|
123
|
+
const useTrailerIndex = reference.trailerIndex ?? 0;
|
|
124
|
+
nextReference = this.getExecutor().resolveTrailers(reference.type, useRootValue, reference.trailers);
|
|
125
|
+
nextReference.name =
|
|
126
|
+
[reference.name,
|
|
127
|
+
...reference.trailers.slice(useTrailerIndex)].join('.');
|
|
128
|
+
}
|
|
129
|
+
else if (ctxDataExpr) {
|
|
130
|
+
const arrayIndex = this.visitResult(ctxDataExpr);
|
|
131
|
+
if (arrayIndex instanceof ParamDefinition_js_1.NumericValue) {
|
|
132
|
+
const arrayIndexValue = arrayIndex.toNumber();
|
|
133
|
+
const foundValue = useValue[arrayIndexValue];
|
|
134
|
+
const refType = foundValue instanceof ClassComponent_js_1.ClassComponent
|
|
135
|
+
? globals_js_1.ReferenceTypes.instance : globals_js_1.ReferenceTypes.variable;
|
|
136
|
+
nextReference = new types_js_1.AnyReference({
|
|
137
|
+
found: true,
|
|
138
|
+
type: refType,
|
|
139
|
+
value: foundValue,
|
|
140
|
+
trailers: [[globals_js_1.TrailerArrayIndex, arrayIndexValue]],
|
|
141
|
+
rootValue: useValue
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (ctxLParam) {
|
|
146
|
+
nextReference = this.handleFunctionCall(reference, netNamespace, ctx);
|
|
147
|
+
}
|
|
148
|
+
this.setResult(ctx, nextReference);
|
|
65
149
|
};
|
|
66
150
|
this.visitAssignment_expr = (ctx) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
else if (ctxFuncCallRef) {
|
|
76
|
-
this.setResult(ctxFuncCallRef, { keepReference: true });
|
|
77
|
-
leftSideReference = this.visitResult(ctxFuncCallRef);
|
|
78
|
-
lhsCtx = ctxFuncCallRef;
|
|
79
|
-
}
|
|
80
|
-
const rhsCtx = ctx.data_expr();
|
|
81
|
-
const rhsCtxResult = this.visitResult(rhsCtx);
|
|
82
|
-
if ((0, utils_js_1.isReference)(rhsCtxResult) && !rhsCtxResult.found) {
|
|
83
|
-
this.throwWithContext(rhsCtx, rhsCtx.getText() + ' is not defined');
|
|
84
|
-
}
|
|
85
|
-
const rhsValue = (0, utils_js_1.unwrapValue)(rhsCtxResult);
|
|
86
|
-
const trailers = leftSideReference.trailers ?? [];
|
|
87
|
-
const sequenceParts = [];
|
|
88
|
-
if (trailers.length === 0) {
|
|
89
|
-
this.getScope().setVariable(leftSideReference.name, rhsValue);
|
|
90
|
-
let itemType = '';
|
|
91
|
-
if (rhsValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
92
|
-
itemType = globals_js_1.ReferenceTypes.instance;
|
|
93
|
-
this.log2(`assigned '${leftSideReference.name}' to ClassComponent`);
|
|
151
|
+
if (ctx.Assign()) {
|
|
152
|
+
const lhsCtx = ctx.callable_expr();
|
|
153
|
+
this.setResult(lhsCtx, { keepReference: true });
|
|
154
|
+
const leftSideReference = this.visitResult(lhsCtx);
|
|
155
|
+
const rhsCtx = ctx.data_expr();
|
|
156
|
+
const rhsCtxResult = this.visitResult(rhsCtx);
|
|
157
|
+
if ((0, utils_js_1.isReference)(rhsCtxResult) && !rhsCtxResult.found) {
|
|
158
|
+
this.throwWithContext(rhsCtx, rhsCtx.getText() + ' is not defined');
|
|
94
159
|
}
|
|
95
|
-
|
|
96
|
-
|
|
160
|
+
const rhsValue = (0, utils_js_1.unwrapValue)(rhsCtxResult);
|
|
161
|
+
const { trailers = [] } = leftSideReference;
|
|
162
|
+
const sequenceParts = [];
|
|
163
|
+
if (trailers.length === 0) {
|
|
97
164
|
this.getScope().setVariable(leftSideReference.name, rhsValue);
|
|
98
|
-
|
|
165
|
+
let itemType = '';
|
|
166
|
+
if (rhsValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
167
|
+
itemType = globals_js_1.ReferenceTypes.instance;
|
|
168
|
+
this.log2(`assigned '${leftSideReference.name}' to ClassComponent`);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
itemType = globals_js_1.ReferenceTypes.variable;
|
|
172
|
+
this.getScope().setVariable(leftSideReference.name, rhsValue);
|
|
173
|
+
this.log2(`assigned variable ${leftSideReference.name} to ${rhsValue}`);
|
|
174
|
+
}
|
|
175
|
+
sequenceParts.push(...[itemType, leftSideReference.name, rhsValue]);
|
|
99
176
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
net.params.set(trailerValue, rhsValue);
|
|
177
|
+
else {
|
|
178
|
+
if (leftSideReference.rootValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
179
|
+
this.setInstanceParam(leftSideReference.rootValue, trailers, rhsValue);
|
|
180
|
+
this.log2(`assigned component param ${leftSideReference.rootValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
181
|
+
sequenceParts.push(...['instance', [leftSideReference.rootValue, trailers], rhsValue]);
|
|
182
|
+
if (leftSideReference.rootValue.typeProp === globals_js_1.ComponentTypes.net) {
|
|
183
|
+
const net = this.getScope().getNet(leftSideReference.rootValue, new PinDefinition_js_1.PinId(1));
|
|
184
|
+
if (net) {
|
|
185
|
+
const trailerValue = trailers.join(".");
|
|
186
|
+
net.params.set(trailerValue, rhsValue);
|
|
187
|
+
}
|
|
112
188
|
}
|
|
113
189
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
190
|
+
else if (leftSideReference.rootValue instanceof Object) {
|
|
191
|
+
if (Array.isArray(trailers[0]) && trailers[0][0] === globals_js_1.TrailerArrayIndex) {
|
|
192
|
+
if (Array.isArray(leftSideReference.rootValue)) {
|
|
193
|
+
const arrayIndexValue = trailers[0][1];
|
|
194
|
+
leftSideReference.rootValue[arrayIndexValue] = rhsValue;
|
|
195
|
+
this.log2(`assigned array index ${leftSideReference.rootValue} index: ${arrayIndexValue} value: ${rhsValue}`);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
this.throwWithContext(lhsCtx, "Invalid array");
|
|
199
|
+
}
|
|
121
200
|
}
|
|
122
201
|
else {
|
|
123
|
-
|
|
202
|
+
let expandedValue = leftSideReference.rootValue;
|
|
203
|
+
trailers.slice(0, -1).forEach(trailer => {
|
|
204
|
+
expandedValue = expandedValue[trailer];
|
|
205
|
+
});
|
|
206
|
+
const lastTrailer = trailers.slice(-1)[0];
|
|
207
|
+
expandedValue[lastTrailer] = rhsValue;
|
|
208
|
+
this.log2(`assigned object ${leftSideReference.rootValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
124
209
|
}
|
|
210
|
+
sequenceParts.push(...['variable', [leftSideReference.rootValue, trailers], rhsValue]);
|
|
125
211
|
}
|
|
126
|
-
else {
|
|
127
|
-
let expandedValue = leftSideReference.rootValue;
|
|
128
|
-
trailers.slice(0, -1).forEach(trailer => {
|
|
129
|
-
expandedValue = expandedValue[trailer];
|
|
130
|
-
});
|
|
131
|
-
const lastTrailer = trailers.slice(-1)[0];
|
|
132
|
-
expandedValue[lastTrailer] = rhsValue;
|
|
133
|
-
this.log2(`assigned object ${leftSideReference.rootValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
134
|
-
}
|
|
135
|
-
sequenceParts.push(...['variable', [leftSideReference.rootValue, trailers], rhsValue]);
|
|
136
212
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.setResult(ctx, rhsValue);
|
|
144
|
-
};
|
|
145
|
-
this.visitOperator_assignment_expr = (ctx) => {
|
|
146
|
-
const reference = this.getReference(ctx.atom_expr());
|
|
147
|
-
const value = this.visitResult(ctx.data_expr());
|
|
148
|
-
if (!reference.found) {
|
|
149
|
-
this.throwWithContext(ctx, 'Undefined reference: ' + reference.name);
|
|
150
|
-
}
|
|
151
|
-
const trailers = reference.trailers ?? [];
|
|
152
|
-
let currentValue = null;
|
|
153
|
-
if (trailers.length === 0) {
|
|
154
|
-
currentValue = this.getExecutor().scope.variables.get(reference.name);
|
|
213
|
+
if (sequenceParts.length > 0) {
|
|
214
|
+
this.getScope().sequence.push([
|
|
215
|
+
ExecutionScope_js_1.SequenceAction.Assign, ...sequenceParts
|
|
216
|
+
]);
|
|
217
|
+
}
|
|
218
|
+
this.setResult(ctx, rhsValue);
|
|
155
219
|
}
|
|
156
220
|
else {
|
|
157
|
-
|
|
158
|
-
|
|
221
|
+
const ctxCallable = ctx.callable_expr();
|
|
222
|
+
this.setResult(ctxCallable, { keepReference: true });
|
|
223
|
+
const reference = this.visitResult(ctx.callable_expr());
|
|
224
|
+
const value = this.visitResult(ctx.data_expr());
|
|
225
|
+
if (!reference.found) {
|
|
226
|
+
this.throwWithContext(ctx, 'Undefined reference: ' + reference.name);
|
|
159
227
|
}
|
|
160
|
-
|
|
161
|
-
|
|
228
|
+
const trailers = reference.trailers ?? [];
|
|
229
|
+
let currentValue = null;
|
|
230
|
+
if (trailers.length === 0) {
|
|
231
|
+
currentValue = this.getExecutor().scope.variables.get(reference.name);
|
|
162
232
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
newValue = operator.subtraction(currentValue, value);
|
|
174
|
-
}
|
|
175
|
-
else if (ctx.MultiplyAssign()) {
|
|
176
|
-
newValue = operator.multiply(currentValue, value);
|
|
177
|
-
}
|
|
178
|
-
else if (ctx.DivideAssign()) {
|
|
179
|
-
newValue = operator.divide(currentValue, value);
|
|
180
|
-
}
|
|
181
|
-
else if (ctx.ModulusAssign()) {
|
|
182
|
-
newValue = operator.modulus(currentValue, value);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
this.throwWithContext(ctx, 'Operator assignment failed: could not perform operator');
|
|
186
|
-
}
|
|
187
|
-
if (trailers.length === 0) {
|
|
188
|
-
this.getExecutor().scope.setVariable(reference.name, newValue);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
|
|
192
|
-
this.setInstanceParam(reference.value, trailers, newValue);
|
|
233
|
+
else {
|
|
234
|
+
if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
|
|
235
|
+
currentValue = this.getInstanceParam(reference.value, trailers);
|
|
236
|
+
}
|
|
237
|
+
else if (reference.value instanceof Object) {
|
|
238
|
+
currentValue = reference.value[trailers.join('.')];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (currentValue === null) {
|
|
242
|
+
this.throwWithContext(ctx, 'Operator assignment failed: could not get value');
|
|
193
243
|
}
|
|
194
|
-
|
|
195
|
-
|
|
244
|
+
let newValue = 0;
|
|
245
|
+
const operator = new ParamDefinition_js_1.NumberOperator();
|
|
246
|
+
if (ctx.AdditionAssign()) {
|
|
247
|
+
newValue = operator.addition(currentValue, value);
|
|
248
|
+
}
|
|
249
|
+
else if (ctx.MinusAssign()) {
|
|
250
|
+
newValue = operator.subtraction(currentValue, value);
|
|
251
|
+
}
|
|
252
|
+
else if (ctx.MultiplyAssign()) {
|
|
253
|
+
newValue = operator.multiply(currentValue, value);
|
|
254
|
+
}
|
|
255
|
+
else if (ctx.DivideAssign()) {
|
|
256
|
+
newValue = operator.divide(currentValue, value);
|
|
257
|
+
}
|
|
258
|
+
else if (ctx.ModulusAssign()) {
|
|
259
|
+
newValue = operator.modulus(currentValue, value);
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
this.throwWithContext(ctx, 'Operator assignment failed: could not perform operator');
|
|
196
263
|
}
|
|
264
|
+
if (trailers.length === 0) {
|
|
265
|
+
this.getExecutor().scope.setVariable(reference.name, newValue);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
|
|
269
|
+
this.setInstanceParam(reference.value, trailers, newValue);
|
|
270
|
+
}
|
|
271
|
+
else if (reference.value instanceof Object) {
|
|
272
|
+
reference.value[trailers.join('.')] = newValue;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
this.setResult(ctx, newValue);
|
|
197
276
|
}
|
|
198
|
-
this.setResult(ctx, newValue);
|
|
199
277
|
};
|
|
200
278
|
this.visitTrailer_expr2 = (ctx) => {
|
|
201
279
|
const reference = this.getResult(ctx);
|
|
@@ -235,7 +313,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
235
313
|
const firstId = ctx.ID(0);
|
|
236
314
|
const atomId = firstId.getText();
|
|
237
315
|
let currentReference;
|
|
238
|
-
if (
|
|
316
|
+
if (globals_js_1.PinTypesList.indexOf(atomId) !== -1) {
|
|
239
317
|
currentReference = new types_js_1.AnyReference({
|
|
240
318
|
found: true,
|
|
241
319
|
value: atomId,
|
|
@@ -256,19 +334,6 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
256
334
|
this.setResult(ctx, currentReference);
|
|
257
335
|
this.log2('atom resolved: ' + ctx.getText() + ' -> ' + currentReference);
|
|
258
336
|
};
|
|
259
|
-
this.visitFunctionCallExpr = (ctx) => {
|
|
260
|
-
const result = this.visitResult(ctx.function_call_expr());
|
|
261
|
-
this.setResult(ctx, result);
|
|
262
|
-
};
|
|
263
|
-
this.visitFunction_call_expr = (ctx) => {
|
|
264
|
-
const ctxParams = this.getResult(ctx);
|
|
265
|
-
const { keepReference = false } = ctxParams ?? {};
|
|
266
|
-
this.handleFunctionCall(ctx);
|
|
267
|
-
if (!keepReference) {
|
|
268
|
-
const functionResultReference = this.getResult(ctx);
|
|
269
|
-
this.setResult(ctx, functionResultReference.value);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
337
|
this.visitValue_expr = (ctx) => {
|
|
273
338
|
const sign = ctx.Minus() ? -1 : 1;
|
|
274
339
|
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
@@ -312,30 +377,26 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
312
377
|
}
|
|
313
378
|
this.setResult(ctx, result);
|
|
314
379
|
};
|
|
315
|
-
this.
|
|
380
|
+
this.visitValueExpr = (ctx) => {
|
|
381
|
+
this.passResult(ctx, ctx.value_expr());
|
|
382
|
+
};
|
|
383
|
+
this.visitAtomExpr = (ctx) => {
|
|
316
384
|
let value = null;
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
value = this.visitResult(ctxValueExpr);
|
|
385
|
+
const reference = this.visitResult(ctx.atom_expr());
|
|
386
|
+
if (!reference.found) {
|
|
387
|
+
value = new types_js_1.UndeclaredReference(reference);
|
|
321
388
|
}
|
|
322
|
-
else
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
value = new types_js_1.UndeclaredReference(reference);
|
|
389
|
+
else {
|
|
390
|
+
if (reference.type && reference.type === globals_js_1.ReferenceTypes.pinType) {
|
|
391
|
+
value = reference;
|
|
326
392
|
}
|
|
327
393
|
else {
|
|
328
|
-
if (reference.
|
|
394
|
+
if ((reference.trailers && reference.trailers.length > 0)
|
|
395
|
+
|| reference.type === globals_js_1.ReferenceTypes.function) {
|
|
329
396
|
value = reference;
|
|
330
397
|
}
|
|
331
398
|
else {
|
|
332
|
-
|
|
333
|
-
|| reference.type === globals_js_1.ReferenceTypes.function) {
|
|
334
|
-
value = reference;
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
value = reference.value;
|
|
338
|
-
}
|
|
399
|
+
value = reference.value;
|
|
339
400
|
}
|
|
340
401
|
}
|
|
341
402
|
}
|
|
@@ -359,6 +420,11 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
359
420
|
});
|
|
360
421
|
this.setResult(ctx, result);
|
|
361
422
|
};
|
|
423
|
+
this.visitKeyword_assignment_expr = (ctx) => {
|
|
424
|
+
const id = ctx.ID().getText();
|
|
425
|
+
const value = this.visitResult(ctx.data_expr());
|
|
426
|
+
this.setResult(ctx, [id, value]);
|
|
427
|
+
};
|
|
362
428
|
this.visitParameters = (ctx) => {
|
|
363
429
|
const dataExpressions = ctx.data_expr();
|
|
364
430
|
const keywordAssignmentExpressions = ctx.keyword_assignment_expr();
|
|
@@ -411,7 +477,10 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
411
477
|
this.setResult(ctx, array);
|
|
412
478
|
};
|
|
413
479
|
this.visitArrayExpr = (ctx) => {
|
|
414
|
-
|
|
480
|
+
const array = ctx.data_expr().map(item => {
|
|
481
|
+
return this.visitResult(item);
|
|
482
|
+
});
|
|
483
|
+
this.setResult(ctx, array);
|
|
415
484
|
};
|
|
416
485
|
this.visitArrayIndexExpr = (ctx) => {
|
|
417
486
|
const ctxArray = ctx.data_expr(0);
|
|
@@ -516,21 +585,38 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
516
585
|
log2(message) {
|
|
517
586
|
this.getExecutor().log(message);
|
|
518
587
|
}
|
|
519
|
-
async
|
|
520
|
-
|
|
521
|
-
|
|
588
|
+
async resolveImportsAndLoad(inputPath, scriptData) {
|
|
589
|
+
this.log('resolve and load imports');
|
|
590
|
+
const importedFiles = await (0, importResolver_js_1.resolveAllImportFilepaths)(inputPath, scriptData, this.environment);
|
|
591
|
+
this.log('resolved all referenced imports');
|
|
592
|
+
const loadedFiles = new Map();
|
|
593
|
+
for (const importFilePath of importedFiles) {
|
|
594
|
+
this.log(`reading file: ${importFilePath}`);
|
|
595
|
+
const importFileData = await this.environment.readFile(importFilePath);
|
|
596
|
+
loadedFiles.set(importFilePath, importFileData);
|
|
597
|
+
}
|
|
598
|
+
if (this.filePathStack.length > 0) {
|
|
599
|
+
const mainRefdesFile = this.getPathRefdesFile(this.filePathStack[0]);
|
|
600
|
+
const fileExists = await this.environment.exists(mainRefdesFile);
|
|
601
|
+
if (fileExists) {
|
|
602
|
+
this.log('.refdes.json file exists, reading it');
|
|
603
|
+
const mainRefdesFileData = await this.environment.readFile(mainRefdesFile);
|
|
604
|
+
loadedFiles.set(mainRefdesFile, mainRefdesFileData);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
this.loadedFiles = loadedFiles;
|
|
522
608
|
}
|
|
523
|
-
|
|
609
|
+
importCommon(ctx, handling) {
|
|
524
610
|
const specificImports = [];
|
|
525
|
-
if (ctx instanceof CircuitScriptParser_js_1.
|
|
611
|
+
if (ctx instanceof CircuitScriptParser_js_1.Import_specific_or_allContext) {
|
|
526
612
|
const tmpSpecificImports = ctx._funcNames.map(item => {
|
|
527
613
|
return item.text;
|
|
528
614
|
});
|
|
529
615
|
specificImports.push(...tmpSpecificImports);
|
|
530
616
|
}
|
|
531
|
-
const id = ctx._libraryName.text;
|
|
532
|
-
const importedFile =
|
|
533
|
-
const ctxImportAnnotation = ctx.
|
|
617
|
+
const id = ctx._libraryName.text.slice(1, -1);
|
|
618
|
+
const importedFile = this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
619
|
+
const ctxImportAnnotation = ctx.annotation_comment_expr();
|
|
534
620
|
if (ctxImportAnnotation) {
|
|
535
621
|
const textValue = ctxImportAnnotation.getText().replace('#=', '');
|
|
536
622
|
const { importedLibrary } = importedFile;
|
|
@@ -556,80 +642,52 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
556
642
|
}
|
|
557
643
|
return reference;
|
|
558
644
|
}
|
|
559
|
-
handleFunctionCall(ctx) {
|
|
645
|
+
handleFunctionCall(currentReference, passedNetNamespace, ctx) {
|
|
560
646
|
const executor = this.getExecutor();
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
passedNetNamespace = this.visitResult(netNameSpaceExpr);
|
|
647
|
+
let parameters = [];
|
|
648
|
+
const ctxParameters = ctx.parameters();
|
|
649
|
+
if (ctxParameters) {
|
|
650
|
+
parameters = this.visitResult(ctxParameters);
|
|
566
651
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
602
|
-
const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
|
|
603
|
-
if (isLibraryFunction) {
|
|
604
|
-
this.log('pop library context scope');
|
|
605
|
-
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
606
|
-
this.exitFile();
|
|
607
|
-
}
|
|
608
|
-
if ((0, utils_js_1.isReference)(functionResult)) {
|
|
609
|
-
currentReference = functionResult;
|
|
610
|
-
}
|
|
611
|
-
else {
|
|
612
|
-
currentReference = new types_js_1.AnyReference({
|
|
613
|
-
found: true,
|
|
614
|
-
value: functionResult,
|
|
615
|
-
trailers: [],
|
|
616
|
-
type: (functionResult instanceof ClassComponent_js_1.ClassComponent) ?
|
|
617
|
-
globals_js_1.ReferenceTypes.instance : globals_js_1.ReferenceTypes.value,
|
|
618
|
-
});
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
catch (err) {
|
|
622
|
-
this.throwWithContext(ctx, err);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
const ctxTrailer = item.trailer_expr2();
|
|
627
|
-
this.setResult(ctxTrailer, currentReference);
|
|
628
|
-
currentReference = this.visitResult(ctxTrailer);
|
|
629
|
-
}
|
|
630
|
-
});
|
|
652
|
+
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
653
|
+
try {
|
|
654
|
+
const isLibraryFunction = currentReference.rootValue
|
|
655
|
+
&& currentReference.rootValue instanceof types_js_1.ImportedLibrary;
|
|
656
|
+
if (isLibraryFunction) {
|
|
657
|
+
this.log('create new library context');
|
|
658
|
+
const importedLibrary = currentReference.rootValue;
|
|
659
|
+
const { context: importedLibraryContext } = importedLibrary;
|
|
660
|
+
this.enterFile(importedLibrary.libraryFilePath);
|
|
661
|
+
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedLibraryContext.name, ctx, {
|
|
662
|
+
netNamespace: executor.netNamespace,
|
|
663
|
+
namespace: importedLibrary.libraryNamespace
|
|
664
|
+
}, [], [], false);
|
|
665
|
+
this.log('copy library context scope');
|
|
666
|
+
importedLibraryContext.scope.copyTo(newExecutor.scope);
|
|
667
|
+
}
|
|
668
|
+
const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
|
|
669
|
+
if (isLibraryFunction) {
|
|
670
|
+
this.log('pop library context scope');
|
|
671
|
+
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
672
|
+
this.exitFile();
|
|
673
|
+
}
|
|
674
|
+
if ((0, utils_js_1.isReference)(functionResult)) {
|
|
675
|
+
currentReference = functionResult;
|
|
676
|
+
}
|
|
677
|
+
else {
|
|
678
|
+
currentReference = new types_js_1.AnyReference({
|
|
679
|
+
found: true,
|
|
680
|
+
value: functionResult,
|
|
681
|
+
trailers: [],
|
|
682
|
+
type: (functionResult instanceof ClassComponent_js_1.ClassComponent) ?
|
|
683
|
+
globals_js_1.ReferenceTypes.instance : globals_js_1.ReferenceTypes.value,
|
|
684
|
+
});
|
|
685
|
+
}
|
|
631
686
|
}
|
|
632
|
-
|
|
687
|
+
catch (err) {
|
|
688
|
+
this.throwWithContext(ctx, err);
|
|
689
|
+
}
|
|
690
|
+
return currentReference;
|
|
633
691
|
}
|
|
634
692
|
handleEnterContext(executor, executionStack, contextName, ctx, options, funcDefinedParameters, passedInParameters, isBreakContext = true) {
|
|
635
693
|
if (isBreakContext) {
|
|
@@ -711,11 +769,27 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
711
769
|
this.visit(ctx);
|
|
712
770
|
return this.getResult(ctx);
|
|
713
771
|
}
|
|
714
|
-
|
|
772
|
+
passResult(ctx, innerCtx) {
|
|
773
|
+
const params = this.getResult(ctx);
|
|
774
|
+
if (params) {
|
|
775
|
+
this.setResult(innerCtx, params);
|
|
776
|
+
}
|
|
777
|
+
this.setResult(ctx, this.visitResult(innerCtx));
|
|
778
|
+
}
|
|
779
|
+
handleImportFile(name, importHandling, throwErrors = true, ctx = null, specificImports = []) {
|
|
715
780
|
name = name.trim();
|
|
716
781
|
const importAlready = this.importedFiles.find(item => {
|
|
717
782
|
return item.id === name;
|
|
718
783
|
});
|
|
784
|
+
let importStatement;
|
|
785
|
+
if (ctx !== null) {
|
|
786
|
+
const start = ctx.start;
|
|
787
|
+
const inputStream = start.inputStream;
|
|
788
|
+
importStatement = [
|
|
789
|
+
start.line, start.column,
|
|
790
|
+
inputStream.getTextFromRange(start.start, ctx.stop.stop)
|
|
791
|
+
];
|
|
792
|
+
}
|
|
719
793
|
if (importAlready) {
|
|
720
794
|
const { importedLibrary: tmpImportedLibrary } = importAlready;
|
|
721
795
|
const alreadyImportedFlag = tmpImportedLibrary.importHandlingFlag;
|
|
@@ -744,14 +818,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
744
818
|
let hasError = false;
|
|
745
819
|
let hasParseError = false;
|
|
746
820
|
let pathExists = false;
|
|
747
|
-
const tmpFilePath = this.environment.
|
|
821
|
+
const tmpFilePath = this.environment.getAbsPathRelativeToCurrentFolder(name + ".cst");
|
|
822
|
+
const relativeFilePath = this.environment.relative(this.environment.getCurrentDirectory(), tmpFilePath);
|
|
748
823
|
this.log('importing path:', tmpFilePath);
|
|
749
824
|
let fileData = null;
|
|
750
825
|
let filePathUsed = null;
|
|
751
826
|
try {
|
|
752
|
-
filePathUsed =
|
|
753
|
-
|
|
754
|
-
|
|
827
|
+
filePathUsed = relativeFilePath;
|
|
828
|
+
if (this.loadedFiles.has(relativeFilePath)) {
|
|
829
|
+
fileData = this.loadedFiles.get(relativeFilePath);
|
|
830
|
+
pathExists = true;
|
|
831
|
+
}
|
|
755
832
|
}
|
|
756
833
|
catch (err) {
|
|
757
834
|
this.log('failed to read file');
|
|
@@ -763,8 +840,10 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
763
840
|
const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
|
|
764
841
|
this.log('checking default libs: ' + tmpFilePath2);
|
|
765
842
|
filePathUsed = tmpFilePath2;
|
|
766
|
-
|
|
767
|
-
|
|
843
|
+
if (this.loadedFiles.has(tmpFilePath2)) {
|
|
844
|
+
fileData = this.loadedFiles.get(tmpFilePath2);
|
|
845
|
+
pathExists = true;
|
|
846
|
+
}
|
|
768
847
|
}
|
|
769
848
|
catch (err) {
|
|
770
849
|
this.log('failed to read file');
|
|
@@ -779,16 +858,46 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
779
858
|
const executionContextName = name;
|
|
780
859
|
const netNamespace = executor.netNamespace;
|
|
781
860
|
const libraryNamespace = `${globals_js_1.BaseNamespace}${name}.`;
|
|
782
|
-
this.enterNewChildContext(executionStack, executor, executionContextName, {
|
|
861
|
+
const importContext = this.enterNewChildContext(executionStack, executor, executionContextName, {
|
|
783
862
|
netNamespace,
|
|
784
863
|
namespace: libraryNamespace,
|
|
785
864
|
}, [], []);
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
865
|
+
let loadedFromCache = false;
|
|
866
|
+
let contentHash = '';
|
|
867
|
+
if (this.enableCachedImportsRead) {
|
|
868
|
+
try {
|
|
869
|
+
contentHash = (0, hash_js_1.computeContentHash)(fileData);
|
|
870
|
+
const cachedIR = (0, storage_js_1.readCache)(filePathUsed, contentHash);
|
|
871
|
+
if (cachedIR !== null) {
|
|
872
|
+
this.log('cache hit for:', filePathUsed);
|
|
873
|
+
const parseAndVisit = (miniScript, lineOffset) => {
|
|
874
|
+
return this.onImportFile(this, filePathUsed, miniScript, this.onErrorHandler, lineOffset);
|
|
875
|
+
};
|
|
876
|
+
importedLibrary = (0, deserializer_js_1.deserializeLibraryScope)(cachedIR, name, libraryNamespace, filePathUsed, importHandling, specificImports, importContext, parseAndVisit, () => {
|
|
877
|
+
executionStack.push(importContext);
|
|
878
|
+
return importContext;
|
|
879
|
+
}, () => {
|
|
880
|
+
executionStack.pop();
|
|
881
|
+
}, contentHash);
|
|
882
|
+
loadedFromCache = true;
|
|
883
|
+
this.log('Done reading from import cache');
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
catch (err) {
|
|
887
|
+
this.log('Error while reading cache: ', err);
|
|
888
|
+
loadedFromCache = false;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (!loadedFromCache) {
|
|
892
|
+
const importResult = this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
|
|
893
|
+
hasError = importResult.hasError;
|
|
894
|
+
hasParseError = importResult.hasParseError;
|
|
895
|
+
this.log(`import handling flag: ${importHandling}`);
|
|
896
|
+
importedLibrary = new types_js_1.ImportedLibrary(name, libraryNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports, contentHash, importStatement);
|
|
897
|
+
importedLibrary.parseError = hasError || hasParseError;
|
|
898
|
+
importedLibrary.writeToCache = true;
|
|
899
|
+
}
|
|
900
|
+
executionStack.pop();
|
|
792
901
|
if (specificImports.length > 0) {
|
|
793
902
|
this.log('specific import: ' + specificImports.join(', '));
|
|
794
903
|
}
|
|
@@ -797,7 +906,8 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
797
906
|
importedLibrary.context.scope.libraries.forEach((lib, key) => {
|
|
798
907
|
scope.libraries.set(key, lib);
|
|
799
908
|
});
|
|
800
|
-
|
|
909
|
+
executor.mergeScope(importedLibrary.context.scope, importedLibrary.libraryNamespace);
|
|
910
|
+
this.checkLibraryInRefdesFile(filePathUsed);
|
|
801
911
|
}
|
|
802
912
|
}
|
|
803
913
|
catch (err) {
|
|
@@ -830,10 +940,32 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
830
940
|
this.importedFiles.push(newImportedFile);
|
|
831
941
|
return newImportedFile;
|
|
832
942
|
}
|
|
833
|
-
|
|
943
|
+
cacheLibraries() {
|
|
944
|
+
this.log('caching libraries');
|
|
945
|
+
const libraries = this.getScope().libraries;
|
|
946
|
+
for (const [libName, library] of libraries) {
|
|
947
|
+
this.log(`checking write flag for library ${library.libraryName}: ${library.writeToCache}`);
|
|
948
|
+
if (library.writeToCache && !library.parseError) {
|
|
949
|
+
try {
|
|
950
|
+
const { fileHash } = library;
|
|
951
|
+
const ir = (0, serializer_js_1.serializeLibraryScope)(library, fileHash);
|
|
952
|
+
(0, storage_js_1.writeCache)(library.libraryFilePath, fileHash, ir);
|
|
953
|
+
this.log(`created cache for library: ${libName}`);
|
|
954
|
+
}
|
|
955
|
+
catch (err) {
|
|
956
|
+
this.log(`failed to cache library: ${libName}`);
|
|
957
|
+
throw new utils_js_2.RuntimeExecutionError(`Failed to cache library: ${libName}`);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
checkLibraryInRefdesFile(filePath) {
|
|
834
963
|
return;
|
|
835
964
|
}
|
|
836
|
-
|
|
965
|
+
getPathRefdesFile(filePath) {
|
|
966
|
+
return '';
|
|
967
|
+
}
|
|
968
|
+
getRefdesFileAnnotationKey(filePath, startLine, startColumn, stopLine, stopColumn) {
|
|
837
969
|
return `${filePath}:${startLine}:${startColumn}:${stopLine}:${stopColumn}`;
|
|
838
970
|
}
|
|
839
971
|
setupDefinedParameters(funcDefinedParameters, passedInParameters, executor) {
|