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
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseVisitor = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
4
|
const big_js_1 = require("big.js");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
|
|
6
|
+
const CircuitScriptVisitor_js_1 = require("./antlr/CircuitScriptVisitor.js");
|
|
7
|
+
const execute_js_1 = require("./execute.js");
|
|
8
|
+
const logger_js_1 = require("./logger.js");
|
|
9
|
+
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
10
|
+
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
11
|
+
const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
12
|
+
const types_js_1 = require("./objects/types.js");
|
|
13
|
+
const globals_js_1 = require("./globals.js");
|
|
14
|
+
const builtinMethods_js_1 = require("./builtinMethods.js");
|
|
15
|
+
const utils_js_1 = require("./utils.js");
|
|
16
|
+
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
17
|
+
class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
18
|
+
constructor(silent = false, onErrorHandler = null, environment) {
|
|
20
19
|
super();
|
|
21
20
|
this.indentLevel = 0;
|
|
22
21
|
this.silent = false;
|
|
23
22
|
this.printStream = [];
|
|
24
23
|
this.printToConsole = true;
|
|
25
|
-
this.acceptedDirections = [
|
|
26
|
-
|
|
24
|
+
this.acceptedDirections = [types_js_1.Direction.Up, types_js_1.Direction.Down,
|
|
25
|
+
types_js_1.Direction.Right, types_js_1.Direction.Left];
|
|
27
26
|
this.resultData = new Map;
|
|
28
27
|
this.paramData = new Map;
|
|
29
28
|
this.pinTypesList = [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
PinTypes_js_1.PinTypes.Any,
|
|
30
|
+
PinTypes_js_1.PinTypes.Input,
|
|
31
|
+
PinTypes_js_1.PinTypes.Output,
|
|
32
|
+
PinTypes_js_1.PinTypes.IO,
|
|
33
|
+
PinTypes_js_1.PinTypes.Power,
|
|
35
34
|
];
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
35
|
+
this.onErrorHandler = null;
|
|
36
|
+
this.importedFiles = [];
|
|
37
|
+
this.onImportFile = async (visitor, filePath, fileData, onErrorHandler) => {
|
|
38
38
|
throw "Import file not implemented";
|
|
39
39
|
};
|
|
40
|
-
this.visitScript = (ctx) => {
|
|
40
|
+
this.visitScript = async (ctx) => {
|
|
41
41
|
this.log('===', 'start', '===');
|
|
42
|
-
const
|
|
42
|
+
const imports = ctx.import_expr();
|
|
43
|
+
for (let i = 0; i < imports.length; i++) {
|
|
44
|
+
const ctxImport = imports[i];
|
|
45
|
+
const ID = ctxImport.ID().toString();
|
|
46
|
+
await this.handleImportFile(ID, true, ctxImport);
|
|
47
|
+
}
|
|
48
|
+
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
49
|
+
this.setResult(ctx, result);
|
|
43
50
|
this.log('===', 'end', '===');
|
|
44
|
-
return result;
|
|
45
51
|
};
|
|
46
52
|
this.visitAssignment_expr = (ctx) => {
|
|
47
53
|
const reference = this.getReference(ctx.atom_expr());
|
|
@@ -50,13 +56,10 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
50
56
|
const value = this.getResult(ctxDataExpr);
|
|
51
57
|
const trailers = reference.trailers ?? [];
|
|
52
58
|
if (trailers.length === 0) {
|
|
53
|
-
if (value instanceof
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
tmpComponent.instanceName = reference.name;
|
|
58
|
-
instances.delete(oldName);
|
|
59
|
-
instances.set(reference.name, tmpComponent);
|
|
59
|
+
if (value instanceof ClassComponent_js_1.ClassComponent) {
|
|
60
|
+
const variables = this.getExecutor().scope.variables;
|
|
61
|
+
variables.set(reference.name, value);
|
|
62
|
+
this.getExecutor().scope.sequence.push([ExecutionScope_js_1.SequenceAction.Assign, reference.name, value]);
|
|
60
63
|
this.log2(`assigned '${reference.name}' to ClassComponent`);
|
|
61
64
|
}
|
|
62
65
|
else {
|
|
@@ -65,7 +68,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
else {
|
|
68
|
-
if (reference.parentValue instanceof
|
|
71
|
+
if (reference.parentValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
69
72
|
this.setInstanceParam(reference.parentValue, trailers, value);
|
|
70
73
|
this.log2(`assigned component param ${reference.parentValue} trailers: ${trailers} value: ${value}`);
|
|
71
74
|
}
|
|
@@ -90,7 +93,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
90
93
|
currentValue = this.getExecutor().scope.variables.get(reference.name);
|
|
91
94
|
}
|
|
92
95
|
else {
|
|
93
|
-
if (reference.value instanceof
|
|
96
|
+
if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
|
|
94
97
|
currentValue = this.getInstanceParam(reference.value, trailers);
|
|
95
98
|
}
|
|
96
99
|
else if (reference.value instanceof Object) {
|
|
@@ -101,7 +104,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
101
104
|
this.throwWithContext(ctx, 'Operator assignment failed: could not get value');
|
|
102
105
|
}
|
|
103
106
|
let newValue = 0;
|
|
104
|
-
const operator = new
|
|
107
|
+
const operator = new ParamDefinition_js_1.NumberOperator();
|
|
105
108
|
if (ctx.AdditionAssign()) {
|
|
106
109
|
newValue = operator.addition(currentValue, value);
|
|
107
110
|
}
|
|
@@ -124,7 +127,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
124
127
|
this.getExecutor().scope.variables.set(reference.name, newValue);
|
|
125
128
|
}
|
|
126
129
|
else {
|
|
127
|
-
if (reference.value instanceof
|
|
130
|
+
if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
|
|
128
131
|
this.setInstanceParam(reference.value, trailers, newValue);
|
|
129
132
|
}
|
|
130
133
|
else if (reference.value instanceof Object) {
|
|
@@ -150,7 +153,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
150
153
|
currentReference = {
|
|
151
154
|
found: true,
|
|
152
155
|
value: atomId,
|
|
153
|
-
type:
|
|
156
|
+
type: globals_js_1.ReferenceTypes.pinType,
|
|
154
157
|
};
|
|
155
158
|
}
|
|
156
159
|
else {
|
|
@@ -162,8 +165,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
162
165
|
executor.scope.setNet(tmpComponent, pinId, net);
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
|
-
|
|
166
|
-
if (ctx.parent instanceof CircuitScriptParser_1.ExpressionContext && !currentReference.found) {
|
|
168
|
+
if (ctx.parent instanceof CircuitScriptParser_js_1.ExpressionContext && !currentReference.found) {
|
|
167
169
|
this.throwWithContext(ctx, "Unknown symbol: " + atomId);
|
|
168
170
|
}
|
|
169
171
|
this.setResult(ctx, currentReference);
|
|
@@ -204,7 +206,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
204
206
|
currentReference = {
|
|
205
207
|
found: true,
|
|
206
208
|
value: functionResult,
|
|
207
|
-
type: (functionResult instanceof
|
|
209
|
+
type: (functionResult instanceof ClassComponent_js_1.ClassComponent) ?
|
|
208
210
|
'instance' : 'value',
|
|
209
211
|
};
|
|
210
212
|
}
|
|
@@ -230,14 +232,14 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
230
232
|
let result = null;
|
|
231
233
|
if (ctxIntegerValue || ctxDecimalValue || ctxNumericValue) {
|
|
232
234
|
if (ctxIntegerValue) {
|
|
233
|
-
result = (0,
|
|
235
|
+
result = (0, utils_js_1.resolveToNumericValue)((new big_js_1.Big(ctxIntegerValue.getText())).mul(new big_js_1.Big(sign)));
|
|
234
236
|
}
|
|
235
237
|
else if (ctxDecimalValue) {
|
|
236
|
-
result = (0,
|
|
238
|
+
result = (0, utils_js_1.resolveToNumericValue)((new big_js_1.Big(ctxDecimalValue.getText())).mul(new big_js_1.Big(sign)));
|
|
237
239
|
}
|
|
238
240
|
else if (ctxNumericValue) {
|
|
239
241
|
const textExtra = ctx.Minus() ? '-' : '';
|
|
240
|
-
result = new
|
|
242
|
+
result = new ParamDefinition_js_1.NumericValue(textExtra + ctxNumericValue.getText());
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
245
|
else {
|
|
@@ -258,7 +260,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
258
260
|
result = this.prepareStringValue(ctxStringValue.getText());
|
|
259
261
|
}
|
|
260
262
|
else if (ctxPercentageValue) {
|
|
261
|
-
result = new
|
|
263
|
+
result = new ParamDefinition_js_1.PercentageValue(ctxPercentageValue.getText());
|
|
262
264
|
}
|
|
263
265
|
this.setResult(ctx, result);
|
|
264
266
|
};
|
|
@@ -274,10 +276,10 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
274
276
|
this.visit(ctxAtomExpr);
|
|
275
277
|
const reference = this.getResult(ctxAtomExpr);
|
|
276
278
|
if (!reference.found) {
|
|
277
|
-
value = new
|
|
279
|
+
value = new types_js_1.UndeclaredReference(reference);
|
|
278
280
|
}
|
|
279
281
|
else {
|
|
280
|
-
if (reference.type && reference.type ===
|
|
282
|
+
if (reference.type && reference.type === globals_js_1.ReferenceTypes.pinType) {
|
|
281
283
|
value = reference;
|
|
282
284
|
}
|
|
283
285
|
else {
|
|
@@ -302,10 +304,10 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
302
304
|
const tmpCtx = defaultValuesProvided[index - boundary];
|
|
303
305
|
this.visit(tmpCtx);
|
|
304
306
|
const defaultValue = this.getResult(tmpCtx);
|
|
305
|
-
return [idText, defaultValue];
|
|
307
|
+
return [idText, tmpCtx.start, defaultValue];
|
|
306
308
|
}
|
|
307
309
|
else {
|
|
308
|
-
return [idText];
|
|
310
|
+
return [idText, id.getSymbol()];
|
|
309
311
|
}
|
|
310
312
|
});
|
|
311
313
|
this.setResult(ctx, result);
|
|
@@ -327,10 +329,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
327
329
|
this.setResult(ctx, returnList);
|
|
328
330
|
};
|
|
329
331
|
this.visitImport_expr = (ctx) => {
|
|
330
|
-
|
|
331
|
-
this.log('import', ID);
|
|
332
|
-
this.handleImportFile(ID, true, ctx);
|
|
333
|
-
this.log('done import', ID);
|
|
332
|
+
throw new utils_js_1.RuntimeExecutionError("Cannot parse imports here", ctx.start, ctx.stop);
|
|
334
333
|
};
|
|
335
334
|
this.visitFunction_return_expr = (ctx) => {
|
|
336
335
|
const executor = this.getExecutor();
|
|
@@ -376,23 +375,34 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
376
375
|
const innerResult = this.getResult(ctxDataExpr);
|
|
377
376
|
this.setResult(ctx, innerResult);
|
|
378
377
|
};
|
|
379
|
-
this.logger = new
|
|
380
|
-
this.
|
|
381
|
-
this.
|
|
382
|
-
this.startingContext.
|
|
383
|
-
this.
|
|
378
|
+
this.logger = new logger_js_1.Logger();
|
|
379
|
+
this.onErrorHandler = onErrorHandler;
|
|
380
|
+
this.environment = environment;
|
|
381
|
+
this.startingContext = new execute_js_1.ExecutionContext(globals_js_1.DoubleDelimiter1, `${globals_js_1.DoubleDelimiter1}.`, '/', 0, 0, silent, this.logger, null);
|
|
382
|
+
const scope = this.startingContext.scope;
|
|
383
|
+
scope.sequence.push([
|
|
384
|
+
ExecutionScope_js_1.SequenceAction.At, scope.componentRoot, scope.currentPin
|
|
385
|
+
]);
|
|
386
|
+
scope.variables.set(globals_js_1.GlobalDocumentName, {});
|
|
387
|
+
this.setupBuiltInFunctions(this.startingContext);
|
|
384
388
|
this.executionStack = [this.startingContext];
|
|
385
389
|
this.startingContext.resolveNet =
|
|
386
390
|
this.createNetResolver(this.executionStack);
|
|
391
|
+
this.startingContext.resolveComponentPinNet =
|
|
392
|
+
this.createComponentPinNetResolver(this.executionStack);
|
|
387
393
|
this.silent = silent;
|
|
388
|
-
this.currentDirectory = currentDirectory;
|
|
389
|
-
this.defaultLibsPath = defaultLibsPath;
|
|
390
394
|
}
|
|
391
395
|
getExecutor() {
|
|
392
396
|
return this.executionStack[this.executionStack.length - 1];
|
|
393
397
|
}
|
|
394
|
-
|
|
395
|
-
|
|
398
|
+
getScope() {
|
|
399
|
+
return this.getExecutor().scope;
|
|
400
|
+
}
|
|
401
|
+
getRootExecutor() {
|
|
402
|
+
return this.executionStack[0];
|
|
403
|
+
}
|
|
404
|
+
setupBuiltInFunctions(context) {
|
|
405
|
+
(0, builtinMethods_js_1.linkBuiltInMethods)(context, this);
|
|
396
406
|
}
|
|
397
407
|
createNetResolver(executionStack) {
|
|
398
408
|
const resolveNet = (netName, netNamespace) => {
|
|
@@ -414,6 +424,19 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
414
424
|
};
|
|
415
425
|
return resolveNet;
|
|
416
426
|
}
|
|
427
|
+
createComponentPinNetResolver(executionStack) {
|
|
428
|
+
return (component, pin) => {
|
|
429
|
+
const reversed = [...executionStack].reverse();
|
|
430
|
+
for (let i = 0; i < reversed.length; i++) {
|
|
431
|
+
const context = reversed[i];
|
|
432
|
+
const net = context.scope.getNet(component, pin);
|
|
433
|
+
if (net !== null) {
|
|
434
|
+
return net;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
return null;
|
|
438
|
+
};
|
|
439
|
+
}
|
|
417
440
|
log(...params) {
|
|
418
441
|
const indentOutput = ''.padStart(this.indentLevel * 4, ' ');
|
|
419
442
|
const indentLevelText = this.indentLevel.toString().padStart(3, ' ');
|
|
@@ -426,6 +449,10 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
426
449
|
log2(message) {
|
|
427
450
|
this.getExecutor().log(message);
|
|
428
451
|
}
|
|
452
|
+
async visitAsync(ctx) {
|
|
453
|
+
const result = await ctx.accept(this);
|
|
454
|
+
return result;
|
|
455
|
+
}
|
|
429
456
|
getReference(ctx) {
|
|
430
457
|
const atomStr = ctx.getText();
|
|
431
458
|
if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
|
|
@@ -451,15 +478,24 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
451
478
|
this.visit(ctx);
|
|
452
479
|
return this.getResult(ctx);
|
|
453
480
|
}
|
|
454
|
-
handleImportFile(name, throwErrors = true, ctx = null) {
|
|
481
|
+
async handleImportFile(name, throwErrors = true, ctx = null) {
|
|
482
|
+
name = name.trim();
|
|
483
|
+
const importAlready = this.importedFiles.find(item => {
|
|
484
|
+
return item.id === name;
|
|
485
|
+
});
|
|
486
|
+
if (importAlready) {
|
|
487
|
+
return importAlready;
|
|
488
|
+
}
|
|
455
489
|
let hasError = false;
|
|
456
490
|
let hasParseError = false;
|
|
457
491
|
let pathExists = false;
|
|
458
|
-
const tmpFilePath =
|
|
492
|
+
const tmpFilePath = this.environment.getRelativeToModule(name + ".cst");
|
|
459
493
|
this.log('importing path:', tmpFilePath);
|
|
460
494
|
let fileData = null;
|
|
495
|
+
let filePathUsed = null;
|
|
461
496
|
try {
|
|
462
|
-
|
|
497
|
+
filePathUsed = tmpFilePath;
|
|
498
|
+
fileData = await this.environment.readFile(tmpFilePath, { encoding: 'utf8' });
|
|
463
499
|
pathExists = true;
|
|
464
500
|
}
|
|
465
501
|
catch (err) {
|
|
@@ -467,8 +503,9 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
467
503
|
}
|
|
468
504
|
if (!pathExists) {
|
|
469
505
|
try {
|
|
470
|
-
const tmpFilePath2 =
|
|
471
|
-
|
|
506
|
+
const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
|
|
507
|
+
filePathUsed = tmpFilePath2;
|
|
508
|
+
fileData = await this.environment.readFile(tmpFilePath2, { encoding: 'utf8' });
|
|
472
509
|
pathExists = true;
|
|
473
510
|
}
|
|
474
511
|
catch (err) {
|
|
@@ -478,31 +515,39 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
478
515
|
try {
|
|
479
516
|
if (pathExists) {
|
|
480
517
|
this.log('done reading imported file data');
|
|
481
|
-
const importResult = this.onImportFile(this, fileData, this.
|
|
518
|
+
const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
|
|
482
519
|
hasError = importResult.hasError;
|
|
483
520
|
hasParseError = importResult.hasParseError;
|
|
484
521
|
}
|
|
485
522
|
}
|
|
486
523
|
catch (err) {
|
|
487
|
-
|
|
524
|
+
if (ctx != null) {
|
|
525
|
+
throw new utils_js_1.RuntimeExecutionError("An error occurred while importing file", ctx.start, ctx.stop);
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
this.log('An error occurred while importing file:', err.message);
|
|
529
|
+
}
|
|
488
530
|
}
|
|
489
531
|
let errorMessage = null;
|
|
490
532
|
if (throwErrors && (hasError || hasParseError || !pathExists)) {
|
|
491
533
|
if (!pathExists) {
|
|
492
|
-
errorMessage = `File does not exist: ${name}`;
|
|
534
|
+
errorMessage = `File does not exist: ${name} (${filePathUsed})`;
|
|
493
535
|
}
|
|
494
536
|
else {
|
|
495
537
|
errorMessage = `Failed to import: ${name}`;
|
|
496
538
|
}
|
|
497
539
|
}
|
|
498
540
|
if (errorMessage !== null && ctx) {
|
|
499
|
-
|
|
541
|
+
throw new utils_js_1.RuntimeExecutionError(errorMessage, ctx.start, ctx.end);
|
|
500
542
|
}
|
|
501
|
-
|
|
543
|
+
const newImportedFile = {
|
|
544
|
+
id: name.trim(),
|
|
502
545
|
hasError,
|
|
503
546
|
hasParseError,
|
|
504
547
|
pathExists,
|
|
505
548
|
};
|
|
549
|
+
this.importedFiles.push(newImportedFile);
|
|
550
|
+
return newImportedFile;
|
|
506
551
|
}
|
|
507
552
|
setupDefinedParameters(funcDefinedParameters, passedInParameters, executor) {
|
|
508
553
|
for (let i = 0; i < funcDefinedParameters.length; i++) {
|
|
@@ -513,7 +558,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
513
558
|
const variableName = tmpFuncArg[0];
|
|
514
559
|
executor.log('set variable in scope, var name: ', variableName);
|
|
515
560
|
executor.scope.variables.set(variableName, tmpPassedInArgs[2]);
|
|
516
|
-
if (tmpPassedInArgs[2] instanceof
|
|
561
|
+
if (tmpPassedInArgs[2] instanceof ClassComponent_js_1.ClassComponent) {
|
|
517
562
|
const component = tmpPassedInArgs[2];
|
|
518
563
|
for (const [pinNumber, net] of component.pinNets) {
|
|
519
564
|
executor.scope.setNet(component, pinNumber, net);
|
|
@@ -526,9 +571,9 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
526
571
|
executor.scope.variables.set(variableName, tmpPassedInArgs[2]);
|
|
527
572
|
}
|
|
528
573
|
}
|
|
529
|
-
else if (tmpFuncArg.length ===
|
|
574
|
+
else if (tmpFuncArg.length === 3) {
|
|
530
575
|
const variableName = tmpFuncArg[0];
|
|
531
|
-
const defaultValue = tmpFuncArg[
|
|
576
|
+
const defaultValue = tmpFuncArg[2];
|
|
532
577
|
executor.log('set variable in scope, var name: ', variableName);
|
|
533
578
|
executor.scope.variables.set(variableName, defaultValue);
|
|
534
579
|
}
|
|
@@ -591,8 +636,7 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
591
636
|
const executionLevel = currentExecutionContext.executionLevel;
|
|
592
637
|
const executionContextNamespace = currentExecutionContext.namespace
|
|
593
638
|
+ executionContextName + ".";
|
|
594
|
-
const newExecutor = new
|
|
595
|
-
this.setupPrintFunction(newExecutor);
|
|
639
|
+
const newExecutor = new execute_js_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.indentLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, parentContext);
|
|
596
640
|
executionStack.push(newExecutor);
|
|
597
641
|
this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
|
|
598
642
|
return newExecutor;
|
|
@@ -600,8 +644,33 @@ class BaseVisitor extends CircuitScriptVisitor_1.CircuitScriptVisitor {
|
|
|
600
644
|
prepareStringValue(value) {
|
|
601
645
|
return value.slice(1, value.length - 1);
|
|
602
646
|
}
|
|
603
|
-
throwWithContext(context,
|
|
604
|
-
(0,
|
|
647
|
+
throwWithContext(context, messageOrError) {
|
|
648
|
+
(0, utils_js_1.throwWithContext)(context, messageOrError);
|
|
649
|
+
}
|
|
650
|
+
validateType(value, context, validateFunction, expectedType) {
|
|
651
|
+
if (value === undefined) {
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
const result = validateFunction(value);
|
|
655
|
+
if (!result) {
|
|
656
|
+
throw new utils_js_1.RuntimeExecutionError(`Invalid ${expectedType}`, context.start, context.stop);
|
|
657
|
+
}
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
validateString(value, context) {
|
|
661
|
+
this.validateType(value, context, (val) => {
|
|
662
|
+
return typeof val === 'string';
|
|
663
|
+
}, 'string');
|
|
664
|
+
}
|
|
665
|
+
validateBoolean(value, context) {
|
|
666
|
+
this.validateType(value, context, (val) => {
|
|
667
|
+
return typeof val === 'boolean';
|
|
668
|
+
}, 'boolean');
|
|
669
|
+
}
|
|
670
|
+
validateNumeric(value, context) {
|
|
671
|
+
this.validateType(value, context, (val) => {
|
|
672
|
+
return (val instanceof ParamDefinition_js_1.NumericValue);
|
|
673
|
+
}, 'numeric value');
|
|
605
674
|
}
|
|
606
675
|
}
|
|
607
676
|
exports.BaseVisitor = BaseVisitor;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prepareTokens = exports.SemanticTokensVisitor = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
|
|
5
|
+
const BaseVisitor_js_1 = require("./BaseVisitor.js");
|
|
6
|
+
const builtinMethods_js_1 = require("./builtinMethods.js");
|
|
7
|
+
const globals_js_1 = require("./globals.js");
|
|
8
|
+
class SemanticTokensVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
9
|
+
constructor(silent = false, onErrorHandler = null, environment, lexer, script) {
|
|
10
|
+
super(silent, onErrorHandler, environment);
|
|
9
11
|
this.parsedTokens = [];
|
|
10
12
|
this.semanticTokens = new Map();
|
|
11
13
|
this.visitFunction_args_expr = (ctx) => {
|
|
@@ -15,7 +17,11 @@ class SemanticTokensVisitor extends BaseVisitor_1.BaseVisitor {
|
|
|
15
17
|
});
|
|
16
18
|
};
|
|
17
19
|
this.visitFunction_call_expr = (ctx) => {
|
|
18
|
-
|
|
20
|
+
const modifiers = [];
|
|
21
|
+
if (builtinMethods_js_1.buildInMethodNamesList.indexOf(ctx.ID().getText()) !== -1) {
|
|
22
|
+
modifiers.push('defaultLibrary');
|
|
23
|
+
}
|
|
24
|
+
this.addSemanticToken(ctx.ID(), modifiers, 'function');
|
|
19
25
|
};
|
|
20
26
|
this.visitFunction_def_expr = (ctx) => {
|
|
21
27
|
const functionName = ctx.ID().getText();
|
|
@@ -24,7 +30,7 @@ class SemanticTokensVisitor extends BaseVisitor_1.BaseVisitor {
|
|
|
24
30
|
if (ctxFunctionArgsExpr) {
|
|
25
31
|
this.visit(ctxFunctionArgsExpr);
|
|
26
32
|
}
|
|
27
|
-
const executionContextName = functionName +
|
|
33
|
+
const executionContextName = functionName + globals_js_1.SymbolValidatorContext;
|
|
28
34
|
const newExecutor = this.enterNewChildContext(this.executionStack, this.getExecutor(), executionContextName, { netNamespace: "" }, [], []);
|
|
29
35
|
this.runExpressions(newExecutor, ctx.function_expr());
|
|
30
36
|
this.executionStack.pop();
|
|
@@ -37,9 +43,8 @@ class SemanticTokensVisitor extends BaseVisitor_1.BaseVisitor {
|
|
|
37
43
|
};
|
|
38
44
|
this.visitCreate_graphic_expr = (ctx) => {
|
|
39
45
|
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
40
|
-
ctx.
|
|
41
|
-
|
|
42
|
-
});
|
|
46
|
+
const graphicsExpressionsCtx = ctx.graphic_expressions_block();
|
|
47
|
+
this.visitResult(graphicsExpressionsCtx);
|
|
43
48
|
};
|
|
44
49
|
this.visitProperty_key_expr = (ctx) => {
|
|
45
50
|
let useValue = null;
|
|
@@ -59,7 +64,7 @@ class SemanticTokensVisitor extends BaseVisitor_1.BaseVisitor {
|
|
|
59
64
|
this.addSemanticToken(useValue, [], 'property');
|
|
60
65
|
}
|
|
61
66
|
};
|
|
62
|
-
this.
|
|
67
|
+
this.visitGraphicCommandExpr = (ctx) => {
|
|
63
68
|
let useValue = null;
|
|
64
69
|
const ctxId = ctx.ID();
|
|
65
70
|
const ctxPin = ctx.Pin();
|
|
@@ -88,7 +93,7 @@ class SemanticTokensVisitor extends BaseVisitor_1.BaseVisitor {
|
|
|
88
93
|
this.visit(ctx.data_expr());
|
|
89
94
|
};
|
|
90
95
|
this.visitAtom_expr = (ctx) => {
|
|
91
|
-
if (ctx.parent instanceof
|
|
96
|
+
if (ctx.parent instanceof CircuitScriptParser_js_1.Assignment_exprContext && ctx.ID(0)) {
|
|
92
97
|
this.addSemanticToken(ctx.ID(0), [], 'variable');
|
|
93
98
|
}
|
|
94
99
|
};
|
|
@@ -182,7 +187,7 @@ const languageKeywords = [
|
|
|
182
187
|
'break', 'branch', 'create', 'component',
|
|
183
188
|
'graphic', 'wire', 'pin', 'add', 'at', 'to',
|
|
184
189
|
'point', 'join', 'parallel', 'return', 'def', 'import',
|
|
185
|
-
'true', 'false', 'nc', 'frame',
|
|
190
|
+
'true', 'false', 'nc', 'sheet', 'frame', 'if', 'for',
|
|
186
191
|
];
|
|
187
192
|
const operatorKeywords = [
|
|
188
193
|
'at', 'to', 'wire', 'add', 'frame', 'join', 'parallel', 'point'
|
|
@@ -206,6 +211,7 @@ function resolveTokenType(tokenType) {
|
|
|
206
211
|
case 'ID':
|
|
207
212
|
return 'variable';
|
|
208
213
|
case 'Define':
|
|
214
|
+
case 'BOOLEAN_VALUE':
|
|
209
215
|
return 'keyword';
|
|
210
216
|
case 'COMMENT':
|
|
211
217
|
return 'comment';
|