circuitscript 0.1.28 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BaseVisitor.js +155 -17
- package/dist/cjs/SemanticTokenVisitor.js +6 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +241 -236
- package/dist/cjs/antlr/CircuitScriptParser.js +568 -431
- package/dist/cjs/builtinMethods.js +6 -2
- package/dist/cjs/environment.js +21 -0
- package/dist/cjs/execute.js +90 -59
- package/dist/cjs/globals.js +4 -1
- package/dist/cjs/helpers.js +9 -4
- package/dist/cjs/objects/ExecutionScope.js +9 -0
- package/dist/cjs/objects/types.js +21 -2
- package/dist/cjs/parser.js +6 -2
- package/dist/cjs/validate/SymbolTable.js +7 -1
- package/dist/cjs/validate/SymbolValidatorVisitor.js +54 -7
- package/dist/cjs/visitor.js +15 -47
- package/dist/esm/BaseVisitor.js +157 -19
- package/dist/esm/SemanticTokenVisitor.js +6 -0
- package/dist/esm/antlr/CircuitScriptLexer.js +241 -236
- package/dist/esm/antlr/CircuitScriptParser.js +567 -429
- package/dist/esm/antlr/CircuitScriptVisitor.js +3 -1
- package/dist/esm/builtinMethods.js +7 -3
- package/dist/esm/environment.js +21 -0
- package/dist/esm/execute.js +91 -60
- package/dist/esm/globals.js +2 -0
- package/dist/esm/helpers.js +9 -4
- package/dist/esm/objects/ExecutionScope.js +9 -0
- package/dist/esm/objects/types.js +27 -1
- package/dist/esm/parser.js +6 -2
- package/dist/esm/validate/SymbolTable.js +5 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +53 -6
- package/dist/esm/visitor.js +16 -45
- package/dist/types/BaseVisitor.d.ts +12 -5
- package/dist/types/SemanticTokenVisitor.d.ts +2 -1
- package/dist/types/antlr/CircuitScriptLexer.d.ts +43 -42
- package/dist/types/antlr/CircuitScriptParser.d.ts +71 -45
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -2
- package/dist/types/environment.d.ts +7 -0
- package/dist/types/execute.d.ts +2 -2
- package/dist/types/globals.d.ts +2 -0
- package/dist/types/objects/ExecutionScope.d.ts +3 -1
- package/dist/types/objects/types.d.ts +22 -1
- package/dist/types/validate/SymbolTable.d.ts +1 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +6 -2
- package/dist/types/visitor.d.ts +3 -1
- package/package.json +4 -1
package/dist/cjs/visitor.js
CHANGED
|
@@ -16,8 +16,8 @@ const Frame_js_1 = require("./objects/Frame.js");
|
|
|
16
16
|
const ComponentAnnotater_js_1 = require("./ComponentAnnotater.js");
|
|
17
17
|
const ComponentMatchConditions_js_1 = require("./ComponentMatchConditions.js");
|
|
18
18
|
class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
19
|
-
constructor() {
|
|
20
|
-
super(
|
|
19
|
+
constructor(silent = false, onErrorHandler = null, environment) {
|
|
20
|
+
super(silent, onErrorHandler, environment);
|
|
21
21
|
this.componentCreationIndex = 0;
|
|
22
22
|
this.creationCtx = new Map();
|
|
23
23
|
this.visitKeyword_assignment_expr = (ctx) => {
|
|
@@ -841,7 +841,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
841
841
|
this.visitFunction_def_expr = (ctx) => {
|
|
842
842
|
const functionName = ctx.ID().getText();
|
|
843
843
|
const uniqueFunctionID = '__._' + ctx.start.line + '_'
|
|
844
|
-
+ ctx.start.column + '_' + functionName + '_' + ctx.getText();
|
|
844
|
+
+ ctx.start.column + '_' + functionName + '_' + this.environment.hashStringSHA256(ctx.getText());
|
|
845
845
|
let funcDefinedParameters = [];
|
|
846
846
|
const ctxFunctionArgsExpr = ctx.function_args_expr();
|
|
847
847
|
if (ctxFunctionArgsExpr) {
|
|
@@ -853,54 +853,17 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
853
853
|
const resolveComponentPinNet = this.createComponentPinNetResolver(this.executionStack);
|
|
854
854
|
const __runFunc = (passedInParameters, options) => {
|
|
855
855
|
const executor = this.getExecutor();
|
|
856
|
-
const parentBreakContext = executor.getParentBreakContext();
|
|
857
|
-
executor.addBreakContext(ctx);
|
|
858
|
-
let useIndex = -1;
|
|
859
|
-
if (parentBreakContext === null) {
|
|
860
|
-
useIndex = options.functionCallIndex;
|
|
861
|
-
}
|
|
862
|
-
else {
|
|
863
|
-
const parentEntry = executor.indexedStack.get(parentBreakContext);
|
|
864
|
-
const { funcCallIndex } = parentEntry;
|
|
865
|
-
if (!funcCallIndex.has(ctx)) {
|
|
866
|
-
funcCallIndex.set(ctx, 0);
|
|
867
|
-
useIndex = 0;
|
|
868
|
-
}
|
|
869
|
-
else {
|
|
870
|
-
useIndex = funcCallIndex.get(ctx) + 1;
|
|
871
|
-
funcCallIndex.set(ctx, useIndex);
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
executor.setBreakContextIndex(useIndex);
|
|
875
856
|
const functionCounterIndex = functionCounter['counter'];
|
|
876
|
-
const executionContextName = `${functionName}-${functionCounterIndex}`;
|
|
877
|
-
const newExecutor = this.enterNewChildContext(executionStack, this.getExecutor(), executionContextName, options, funcDefinedParameters, passedInParameters);
|
|
878
857
|
functionCounter['counter'] += 1;
|
|
858
|
+
const executionContextName = `${functionName}-${functionCounterIndex}`;
|
|
859
|
+
const newExecutor = this.handleEnterContext(executor, executionStack, executionContextName, ctx, options, funcDefinedParameters, passedInParameters);
|
|
879
860
|
newExecutor.resolveNet = resolveNet;
|
|
880
861
|
newExecutor.resolveComponentPinNet = resolveComponentPinNet;
|
|
881
862
|
const returnValue = this.runExpressions(newExecutor, ctx.function_expr());
|
|
882
|
-
const lastExecution =
|
|
883
|
-
const nextLastExecution = executionStack[executionStack.length - 1];
|
|
884
|
-
const mergedComponents = nextLastExecution.mergeScope(lastExecution.scope, executionContextName);
|
|
885
|
-
const scope = this.getScope();
|
|
886
|
-
const indexedStack = [];
|
|
887
|
-
if (scope.breakStack.length > 0) {
|
|
888
|
-
const executor = this.getExecutor();
|
|
889
|
-
scope.breakStack.forEach(stackCtx => {
|
|
890
|
-
const entry = executor.indexedStack.get(stackCtx);
|
|
891
|
-
const { index } = entry;
|
|
892
|
-
indexedStack.push([stackCtx, index]);
|
|
893
|
-
});
|
|
894
|
-
mergedComponents.forEach(component => {
|
|
895
|
-
component.ctxReferences.forEach(ref => {
|
|
896
|
-
ref.indexedStack = [...indexedStack, ...ref.indexedStack];
|
|
897
|
-
});
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
executor.popBreakContext();
|
|
863
|
+
const lastExecution = this.handlePopContext(executor, executionStack, executionContextName);
|
|
901
864
|
return [lastExecution, returnValue];
|
|
902
865
|
};
|
|
903
|
-
this.getExecutor().createFunction(functionName, __runFunc, ctx, uniqueFunctionID);
|
|
866
|
+
this.getExecutor().createFunction(this.getExecutor().namespace, functionName, __runFunc, ctx, uniqueFunctionID);
|
|
904
867
|
};
|
|
905
868
|
this.visitPin_select_expr2 = (ctx) => {
|
|
906
869
|
const ctxStringValue = ctx.STRING_VALUE();
|
|
@@ -1322,6 +1285,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1322
1285
|
PinTypes_js_1.PinTypes.Output,
|
|
1323
1286
|
PinTypes_js_1.PinTypes.Power,
|
|
1324
1287
|
];
|
|
1288
|
+
if (environment) {
|
|
1289
|
+
this.log('-- Environment --');
|
|
1290
|
+
this.log('Module directory: ' + environment.getModuleDirectory());
|
|
1291
|
+
this.log('Default libs path: ' + environment.getDefaultLibsPath());
|
|
1292
|
+
this.log('Current file: ' + environment.getCurrentFile());
|
|
1293
|
+
this.log('-----------------');
|
|
1294
|
+
}
|
|
1325
1295
|
}
|
|
1326
1296
|
expandModuleContains(component, netNamespace) {
|
|
1327
1297
|
this.getExecutor().log('expanding module `contains`');
|
|
@@ -1331,10 +1301,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1331
1301
|
+ component.instanceName
|
|
1332
1302
|
+ globals_js_1.Delimiter1 + component.moduleCounter;
|
|
1333
1303
|
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + globals_js_1.Delimiter1 + component.moduleCounter);
|
|
1334
|
-
|
|
1304
|
+
this.enterNewChildContext(executionStack, executor, executionContextName, { netNamespace: tmpNamespace }, [], []);
|
|
1335
1305
|
component.moduleCounter += 1;
|
|
1336
|
-
newExecutor.resolveNet = this.createNetResolver(executionStack);
|
|
1337
|
-
newExecutor.resolveComponentPinNet = this.createComponentPinNetResolver(executionStack);
|
|
1338
1306
|
this.visit(component.moduleContainsExpressions);
|
|
1339
1307
|
const executionContext = executionStack.pop();
|
|
1340
1308
|
component.moduleExecutionContext = executionContext;
|
package/dist/esm/BaseVisitor.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { Big } from 'big.js';
|
|
2
|
+
import { Import_specificContext } from "./antlr/CircuitScriptParser.js";
|
|
2
3
|
import { CircuitScriptVisitor } from "./antlr/CircuitScriptVisitor.js";
|
|
3
4
|
import { ExecutionContext } from "./execute.js";
|
|
4
5
|
import { Logger } from "./logger.js";
|
|
5
6
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
6
7
|
import { NumberOperator, NumericValue, PercentageValue } from "./objects/ParamDefinition.js";
|
|
7
8
|
import { PinTypes } from "./objects/PinTypes.js";
|
|
8
|
-
import { Direction, AnyReference, UndeclaredReference } from "./objects/types.js";
|
|
9
|
-
import { ComponentTypes, DoubleDelimiter1, GlobalDocumentName, ReferenceTypes, TrailerArrayIndex } from './globals.js';
|
|
9
|
+
import { Direction, AnyReference, UndeclaredReference, ImportedModule, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
|
|
10
|
+
import { BaseNamespace, ComponentTypes, DoubleDelimiter1, GlobalDocumentName, ReferenceTypes, TrailerArrayIndex } from './globals.js';
|
|
10
11
|
import { isReference, unwrapValue as unwrapValue } from "./utils.js";
|
|
11
12
|
import { linkBuiltInMethods } from './builtinMethods.js';
|
|
12
13
|
import { resolveToNumericValue, RuntimeExecutionError, throwWithContext } from './utils.js';
|
|
13
14
|
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
14
15
|
import { PinId } from './objects/PinDefinition.js';
|
|
15
16
|
export class BaseVisitor extends CircuitScriptVisitor {
|
|
16
|
-
indentLevel = 0;
|
|
17
17
|
startingContext;
|
|
18
18
|
executionStack;
|
|
19
19
|
silent = false;
|
|
20
20
|
logger;
|
|
21
21
|
printStream = [];
|
|
22
22
|
printToConsole = true;
|
|
23
|
+
allowParseImports = false;
|
|
23
24
|
acceptedDirections = [Direction.Up, Direction.Down,
|
|
24
25
|
Direction.Right, Direction.Left];
|
|
25
26
|
resultData = new Map;
|
|
@@ -40,10 +41,11 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
40
41
|
};
|
|
41
42
|
constructor(silent = false, onErrorHandler = null, environment) {
|
|
42
43
|
super();
|
|
44
|
+
this.silent = silent;
|
|
43
45
|
this.logger = new Logger();
|
|
44
46
|
this.onErrorHandler = onErrorHandler;
|
|
45
47
|
this.environment = environment;
|
|
46
|
-
this.startingContext = new ExecutionContext(DoubleDelimiter1,
|
|
48
|
+
this.startingContext = new ExecutionContext(DoubleDelimiter1, BaseNamespace, '/', 0, 0, silent, this.logger, this.warnings, null);
|
|
47
49
|
const scope = this.startingContext.scope;
|
|
48
50
|
scope.sequence.push([
|
|
49
51
|
SequenceAction.At, scope.componentRoot, scope.currentPin
|
|
@@ -105,8 +107,9 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
105
107
|
};
|
|
106
108
|
}
|
|
107
109
|
log(...params) {
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
+
const indentLevel = this.getScope().scopeLevel;
|
|
111
|
+
const indentOutput = ''.padStart(indentLevel * 4, ' ');
|
|
112
|
+
const indentLevelText = indentLevel.toString().padStart(3, ' ');
|
|
110
113
|
const args = ['[' + indentLevelText + ']', indentOutput, ...params];
|
|
111
114
|
this.logger.add(args.join(' '));
|
|
112
115
|
if (!this.silent) {
|
|
@@ -122,17 +125,36 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
122
125
|
}
|
|
123
126
|
visitScript = async (ctx) => {
|
|
124
127
|
this.log('===', 'start', '===');
|
|
125
|
-
|
|
126
|
-
for (
|
|
127
|
-
|
|
128
|
-
const ID = ctxImport.ID().toString();
|
|
129
|
-
await this.handleImportFile(ID, true, ctxImport);
|
|
128
|
+
this.allowParseImports = true;
|
|
129
|
+
for (const ctxImport of ctx.import_expr()) {
|
|
130
|
+
await this.visit(ctxImport);
|
|
130
131
|
}
|
|
132
|
+
this.allowParseImports = false;
|
|
131
133
|
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
132
134
|
this.setResult(ctx, result);
|
|
133
135
|
this.getExecutor().closeOpenPathBlocks();
|
|
134
136
|
this.log('===', 'end', '===');
|
|
135
137
|
};
|
|
138
|
+
async importCommon(ctx, handling) {
|
|
139
|
+
const specificImports = [];
|
|
140
|
+
if (ctx instanceof Import_specificContext) {
|
|
141
|
+
const tmpSpecificImports = ctx._funcNames.map(item => {
|
|
142
|
+
return item.text;
|
|
143
|
+
});
|
|
144
|
+
specificImports.push(...tmpSpecificImports);
|
|
145
|
+
}
|
|
146
|
+
const id = ctx._moduleName.text;
|
|
147
|
+
await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
148
|
+
}
|
|
149
|
+
visitImport_simple = async (ctx) => {
|
|
150
|
+
await this.importCommon(ctx, ImportFunctionHandling.AllWithNamespace);
|
|
151
|
+
};
|
|
152
|
+
visitImport_all_simple = async (ctx) => {
|
|
153
|
+
await this.importCommon(ctx, ImportFunctionHandling.AllMergeIntoNamespace);
|
|
154
|
+
};
|
|
155
|
+
visitImport_specific = async (ctx) => {
|
|
156
|
+
await this.importCommon(ctx, ImportFunctionHandling.SpecificMergeIntoNamespace);
|
|
157
|
+
};
|
|
136
158
|
visitAssignment_expr = (ctx) => {
|
|
137
159
|
const ctxAtom = ctx.atom_expr();
|
|
138
160
|
const ctxFuncCallRef = ctx.function_call_expr();
|
|
@@ -364,7 +386,8 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
364
386
|
let currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
365
387
|
if (ctx.trailer_expr().length > 0) {
|
|
366
388
|
if (!currentReference.found) {
|
|
367
|
-
this.
|
|
389
|
+
this.log(`could not resolve function: ${atomId}`);
|
|
390
|
+
this.throwWithContext(ctx, "could not resolve function: " + atomId);
|
|
368
391
|
}
|
|
369
392
|
currentReference.trailers = [];
|
|
370
393
|
ctx.trailer_expr().forEach(item => {
|
|
@@ -381,7 +404,24 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
381
404
|
}
|
|
382
405
|
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
383
406
|
try {
|
|
384
|
-
const
|
|
407
|
+
const isModuleFunction = currentReference.rootValue
|
|
408
|
+
&& currentReference.rootValue instanceof ImportedModule;
|
|
409
|
+
if (isModuleFunction) {
|
|
410
|
+
this.log('create new module context');
|
|
411
|
+
const importedModule = currentReference.rootValue;
|
|
412
|
+
const importedModuleContext = importedModule.context;
|
|
413
|
+
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedModuleContext.name, ctx, {
|
|
414
|
+
netNamespace: executor.netNamespace,
|
|
415
|
+
namespace: importedModule.moduleNamespace
|
|
416
|
+
}, [], [], false);
|
|
417
|
+
this.log('copy module context scope');
|
|
418
|
+
importedModuleContext.scope.copyTo(newExecutor.scope);
|
|
419
|
+
}
|
|
420
|
+
const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
|
|
421
|
+
if (isModuleFunction) {
|
|
422
|
+
this.log('pop module context scope');
|
|
423
|
+
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
424
|
+
}
|
|
385
425
|
if (isReference(functionResult)) {
|
|
386
426
|
currentReference = functionResult;
|
|
387
427
|
}
|
|
@@ -408,6 +448,54 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
408
448
|
}
|
|
409
449
|
this.setResult(ctx, currentReference);
|
|
410
450
|
}
|
|
451
|
+
handleEnterContext(executor, executionStack, contextName, ctx, options, funcDefinedParameters, passedInParameters, isBreakContext = true) {
|
|
452
|
+
if (isBreakContext) {
|
|
453
|
+
const parentBreakContext = executor.getParentBreakContext();
|
|
454
|
+
executor.addBreakContext(ctx);
|
|
455
|
+
let useIndex = -1;
|
|
456
|
+
if (parentBreakContext === null) {
|
|
457
|
+
useIndex = options.functionCallIndex;
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
const parentEntry = executor.indexedStack.get(parentBreakContext);
|
|
461
|
+
const { funcCallIndex } = parentEntry;
|
|
462
|
+
if (!funcCallIndex.has(ctx)) {
|
|
463
|
+
funcCallIndex.set(ctx, 0);
|
|
464
|
+
useIndex = 0;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
useIndex = funcCallIndex.get(ctx) + 1;
|
|
468
|
+
funcCallIndex.set(ctx, useIndex);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
executor.setBreakContextIndex(useIndex);
|
|
472
|
+
}
|
|
473
|
+
return this.enterNewChildContext(executionStack, executor, contextName, options, funcDefinedParameters, passedInParameters);
|
|
474
|
+
}
|
|
475
|
+
handlePopContext(executor, executionStack, namespaceExtension, isBreakContext = true) {
|
|
476
|
+
const poppedContext = executionStack.pop();
|
|
477
|
+
const nextLastExecution = executionStack[executionStack.length - 1];
|
|
478
|
+
const mergedComponents = nextLastExecution.mergeScope(poppedContext.scope, namespaceExtension);
|
|
479
|
+
if (isBreakContext) {
|
|
480
|
+
const scope = this.getScope();
|
|
481
|
+
const indexedStack = [];
|
|
482
|
+
if (scope.breakStack.length > 0) {
|
|
483
|
+
const executor = this.getExecutor();
|
|
484
|
+
scope.breakStack.forEach(stackCtx => {
|
|
485
|
+
const entry = executor.indexedStack.get(stackCtx);
|
|
486
|
+
const { index } = entry;
|
|
487
|
+
indexedStack.push([stackCtx, index]);
|
|
488
|
+
});
|
|
489
|
+
mergedComponents.forEach(component => {
|
|
490
|
+
component.ctxReferences.forEach(ref => {
|
|
491
|
+
ref.indexedStack = [...indexedStack, ...ref.indexedStack];
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
executor.popBreakContext();
|
|
496
|
+
}
|
|
497
|
+
return poppedContext;
|
|
498
|
+
}
|
|
411
499
|
visitValue_expr = (ctx) => {
|
|
412
500
|
const sign = ctx.Minus() ? -1 : 1;
|
|
413
501
|
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
@@ -602,18 +690,40 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
602
690
|
this.visit(ctx);
|
|
603
691
|
return this.getResult(ctx);
|
|
604
692
|
}
|
|
605
|
-
async handleImportFile(name, throwErrors = true, ctx = null) {
|
|
693
|
+
async handleImportFile(name, importHandling, throwErrors = true, ctx = null, specificImports = []) {
|
|
606
694
|
name = name.trim();
|
|
607
695
|
const importAlready = this.importedFiles.find(item => {
|
|
608
696
|
return item.id === name;
|
|
609
697
|
});
|
|
610
698
|
if (importAlready) {
|
|
699
|
+
const tmpImportedModule = importAlready.importedModule;
|
|
700
|
+
const alreadyImportedFlag = tmpImportedModule.importHandlingFlag;
|
|
701
|
+
const isMergedNamespace = alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace
|
|
702
|
+
|| alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace;
|
|
703
|
+
const invalidImportCondition1 = alreadyImportedFlag === ImportFunctionHandling.AllWithNamespace &&
|
|
704
|
+
importHandling !== ImportFunctionHandling.AllWithNamespace;
|
|
705
|
+
const invalidImportCondition2 = alreadyImportedFlag !== ImportFunctionHandling.AllWithNamespace &&
|
|
706
|
+
importHandling === ImportFunctionHandling.AllWithNamespace;
|
|
707
|
+
if (invalidImportCondition1 || invalidImportCondition2) {
|
|
708
|
+
throw new RuntimeExecutionError(`Namespace import and wildcard/specific imports cannot be mixed: ${name}`, ctx);
|
|
709
|
+
}
|
|
710
|
+
if (isMergedNamespace) {
|
|
711
|
+
if (alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
712
|
+
}
|
|
713
|
+
else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
714
|
+
tmpImportedModule.specifiedImports = [];
|
|
715
|
+
tmpImportedModule.importHandlingFlag = ImportFunctionHandling.AllMergeIntoNamespace;
|
|
716
|
+
}
|
|
717
|
+
else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.SpecificMergeIntoNamespace) {
|
|
718
|
+
tmpImportedModule.specifiedImports.push(...specificImports);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
611
721
|
return importAlready;
|
|
612
722
|
}
|
|
613
723
|
let hasError = false;
|
|
614
724
|
let hasParseError = false;
|
|
615
725
|
let pathExists = false;
|
|
616
|
-
const tmpFilePath = this.environment.
|
|
726
|
+
const tmpFilePath = this.environment.getRelativeToCurrentFolder(name + ".cst");
|
|
617
727
|
this.log('importing path:', tmpFilePath);
|
|
618
728
|
let fileData = null;
|
|
619
729
|
let filePathUsed = null;
|
|
@@ -623,30 +733,54 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
623
733
|
pathExists = true;
|
|
624
734
|
}
|
|
625
735
|
catch (err) {
|
|
736
|
+
this.log('failed to read file');
|
|
626
737
|
pathExists = false;
|
|
627
738
|
}
|
|
739
|
+
let importedModule;
|
|
628
740
|
if (!pathExists) {
|
|
629
741
|
try {
|
|
630
742
|
const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
|
|
743
|
+
this.log('checking default libs: ' + tmpFilePath2);
|
|
631
744
|
filePathUsed = tmpFilePath2;
|
|
632
745
|
fileData = await this.environment.readFile(tmpFilePath2, { encoding: 'utf8' });
|
|
633
746
|
pathExists = true;
|
|
634
747
|
}
|
|
635
748
|
catch (err) {
|
|
749
|
+
this.log('failed to read file');
|
|
636
750
|
pathExists = false;
|
|
637
751
|
}
|
|
638
752
|
}
|
|
639
753
|
try {
|
|
640
|
-
if (pathExists) {
|
|
754
|
+
if (pathExists && filePathUsed) {
|
|
641
755
|
this.log('done reading imported file data');
|
|
756
|
+
const executionStack = this.executionStack;
|
|
757
|
+
const executor = this.getExecutor();
|
|
758
|
+
const executionContextName = name;
|
|
759
|
+
const netNamespace = executor.netNamespace;
|
|
760
|
+
const moduleNamespace = `${BaseNamespace}${name}.`;
|
|
761
|
+
this.enterNewChildContext(executionStack, executor, executionContextName, {
|
|
762
|
+
netNamespace,
|
|
763
|
+
namespace: moduleNamespace,
|
|
764
|
+
}, [], []);
|
|
642
765
|
const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
|
|
643
766
|
hasError = importResult.hasError;
|
|
644
767
|
hasParseError = importResult.hasParseError;
|
|
768
|
+
const importContext = executionStack.pop();
|
|
769
|
+
this.log(`import handling flag: ${importHandling}`);
|
|
770
|
+
importedModule = new ImportedModule(name, moduleNamespace, filePathUsed, importContext, importHandling, specificImports);
|
|
771
|
+
if (specificImports.length > 0) {
|
|
772
|
+
this.log('specific import: ' + specificImports.join(', '));
|
|
773
|
+
}
|
|
774
|
+
const scope = this.getScope();
|
|
775
|
+
scope.modules.set(name, importedModule);
|
|
776
|
+
importedModule.context.scope.modules.forEach((module, key) => {
|
|
777
|
+
scope.modules.set(key, module);
|
|
778
|
+
});
|
|
645
779
|
}
|
|
646
780
|
}
|
|
647
781
|
catch (err) {
|
|
648
782
|
if (ctx != null) {
|
|
649
|
-
throw
|
|
783
|
+
throw err;
|
|
650
784
|
}
|
|
651
785
|
else {
|
|
652
786
|
this.log('An error occurred while importing file:', err.message);
|
|
@@ -669,6 +803,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
669
803
|
hasError,
|
|
670
804
|
hasParseError,
|
|
671
805
|
pathExists,
|
|
806
|
+
importedModule: importedModule
|
|
672
807
|
};
|
|
673
808
|
this.importedFiles.push(newImportedFile);
|
|
674
809
|
return newImportedFile;
|
|
@@ -762,14 +897,17 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
762
897
|
return object.getParam(paramName);
|
|
763
898
|
}
|
|
764
899
|
enterNewChildContext(executionStack, parentContext, executionContextName, options, funcDefinedParameters, passedInParameters) {
|
|
765
|
-
const { netNamespace = "" } = options;
|
|
900
|
+
const { netNamespace = "", namespace = null, } = options;
|
|
766
901
|
const currentExecutionContext = executionStack[executionStack.length - 1];
|
|
767
902
|
const executionLevel = currentExecutionContext.executionLevel;
|
|
768
|
-
const executionContextNamespace = currentExecutionContext.namespace
|
|
903
|
+
const executionContextNamespace = namespace ?? currentExecutionContext.namespace
|
|
769
904
|
+ executionContextName + ".";
|
|
770
905
|
const newExecutor = new ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.scopeLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, currentExecutionContext.warnings, parentContext);
|
|
771
906
|
executionStack.push(newExecutor);
|
|
772
907
|
this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
|
|
908
|
+
newExecutor.resolveNet = this.createNetResolver(executionStack);
|
|
909
|
+
newExecutor.resolveComponentPinNet =
|
|
910
|
+
this.createComponentPinNetResolver(executionStack);
|
|
773
911
|
return newExecutor;
|
|
774
912
|
}
|
|
775
913
|
prepareStringValue(value) {
|
|
@@ -109,6 +109,10 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
109
109
|
this.addSemanticToken(ctx.ID(0), [], 'variable');
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
+
visitOperator_assignment_expr = (ctx) => {
|
|
113
|
+
this.visit(ctx.atom_expr());
|
|
114
|
+
this.visit(ctx.data_expr());
|
|
115
|
+
};
|
|
112
116
|
visitImport_expr = (ctx) => {
|
|
113
117
|
this.addSemanticToken(ctx.ID(), [], 'namespace');
|
|
114
118
|
};
|
|
@@ -116,6 +120,8 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
116
120
|
ctx.ID().forEach(item => {
|
|
117
121
|
this.addSemanticToken(item, [], 'variable');
|
|
118
122
|
});
|
|
123
|
+
this.visit(ctx.data_expr());
|
|
124
|
+
this.visit(ctx.expressions_block());
|
|
119
125
|
};
|
|
120
126
|
visitAnnotation_comment_expr = (ctx) => {
|
|
121
127
|
this.addSemanticToken(ctx.ANNOTATION_START(), [], 'comment');
|