circuitscript 0.1.12 → 0.1.14
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 +90 -85
- package/dist/cjs/antlr/CircuitScriptParser.js +761 -854
- package/dist/cjs/builtinMethods.js +5 -3
- package/dist/cjs/execute.js +61 -45
- package/dist/cjs/helpers.js +11 -8
- package/dist/cjs/objects/ExecutionScope.js +1 -1
- package/dist/cjs/parser.js +3 -1
- package/dist/cjs/utils.js +3 -3
- package/dist/cjs/visitor.js +14 -16
- package/dist/esm/BaseVisitor.js +50 -45
- package/dist/esm/antlr/CircuitScriptParser.js +759 -850
- package/dist/esm/antlr/CircuitScriptVisitor.js +0 -2
- package/dist/esm/builtinMethods.js +6 -4
- package/dist/esm/execute.js +62 -46
- package/dist/esm/helpers.js +11 -8
- package/dist/esm/objects/ExecutionScope.js +1 -1
- package/dist/esm/parser.js +3 -1
- package/dist/esm/utils.js +1 -1
- package/dist/esm/visitor.js +15 -17
- package/dist/types/BaseVisitor.d.ts +3 -4
- package/dist/types/antlr/CircuitScriptParser.d.ts +42 -58
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +0 -4
- package/dist/types/execute.d.ts +6 -5
- package/dist/types/objects/ExecutionScope.d.ts +1 -1
- package/dist/types/parser.d.ts +1 -0
- package/dist/types/utils.d.ts +1 -1
- package/package.json +1 -1
|
@@ -25,8 +25,6 @@ export class CircuitScriptVisitor extends AbstractParseTreeVisitor {
|
|
|
25
25
|
visitAt_block_pin_expr;
|
|
26
26
|
visitAt_block_pin_expression_simple;
|
|
27
27
|
visitAt_block_pin_expression_complex;
|
|
28
|
-
visitBreak_keyword;
|
|
29
|
-
visitContinue_keyword;
|
|
30
28
|
visitAssignment_expr;
|
|
31
29
|
visitOperator_assignment_expr;
|
|
32
30
|
visitKeyword_assignment_expr;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { numeric, NumericValue } from "./objects/ParamDefinition.js";
|
|
3
|
-
import {
|
|
3
|
+
import { unwrapValue, resolveToNumericValue, RuntimeExecutionError } from "./utils.js";
|
|
4
4
|
const builtInMethods = [
|
|
5
5
|
['enumerate', enumerate],
|
|
6
6
|
['toMils', toMils],
|
|
@@ -16,8 +16,7 @@ export function linkBuiltInMethods(context, visitor) {
|
|
|
16
16
|
context.createFunction('print', (params) => {
|
|
17
17
|
const args = getPositionParams(params);
|
|
18
18
|
const items = args.map(item => {
|
|
19
|
-
|
|
20
|
-
return toString(value);
|
|
19
|
+
return toString(unwrapValue(item));
|
|
21
20
|
});
|
|
22
21
|
if (visitor.printToConsole) {
|
|
23
22
|
console.log('::', ...items);
|
|
@@ -78,7 +77,7 @@ function toMils(value) {
|
|
|
78
77
|
return resolveToNumericValue(bigValue);
|
|
79
78
|
}
|
|
80
79
|
function objectLength(obj) {
|
|
81
|
-
obj =
|
|
80
|
+
obj = unwrapValue(obj);
|
|
82
81
|
if (Array.isArray(obj)) {
|
|
83
82
|
return numeric(obj.length);
|
|
84
83
|
}
|
|
@@ -109,6 +108,9 @@ function arrayGet(arrayObject, index) {
|
|
|
109
108
|
else {
|
|
110
109
|
useValue = index;
|
|
111
110
|
}
|
|
111
|
+
if (isNaN(useValue)) {
|
|
112
|
+
throw new RuntimeExecutionError("Invalid index for arrayGet");
|
|
113
|
+
}
|
|
112
114
|
return arrayObject[useValue];
|
|
113
115
|
}
|
|
114
116
|
function arraySet(arrayObject, index, setValue) {
|
package/dist/esm/execute.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './obj
|
|
|
4
4
|
import { Net } from './objects/Net.js';
|
|
5
5
|
import { numeric, NumericValue } from './objects/ParamDefinition.js';
|
|
6
6
|
import { PortSide } from './objects/PinDefinition.js';
|
|
7
|
-
import { DeclaredReference, Direction } from './objects/types.js';
|
|
7
|
+
import { AnyReference, DeclaredReference, Direction } from './objects/types.js';
|
|
8
8
|
import { Wire } from './objects/Wire.js';
|
|
9
9
|
import { Frame } from './objects/Frame.js';
|
|
10
10
|
import { CalculatePinPositions } from './layout.js';
|
|
@@ -28,17 +28,17 @@ export class ExecutionContext {
|
|
|
28
28
|
parentContext;
|
|
29
29
|
componentAngleFollowsWire = true;
|
|
30
30
|
warnings = [];
|
|
31
|
-
constructor(name, namespace, netNamespace, executionLevel = 0,
|
|
31
|
+
constructor(name, namespace, netNamespace, executionLevel = 0, scopeLevel = 0, silent = false, logger, warnings, parent) {
|
|
32
32
|
this.name = name;
|
|
33
33
|
this.namespace = namespace;
|
|
34
34
|
this.netNamespace = netNamespace;
|
|
35
35
|
this.executionLevel = executionLevel;
|
|
36
36
|
this.logger = logger;
|
|
37
37
|
this.scope = ExecutionScope.create();
|
|
38
|
-
this.scope.
|
|
38
|
+
this.scope.scopeLevel = scopeLevel;
|
|
39
39
|
this.setupRoot();
|
|
40
40
|
this.silent = silent;
|
|
41
|
-
this.log('create new execution context', this.namespace, this.name, this.scope.
|
|
41
|
+
this.log('create new execution context', this.namespace, this.name, this.scope.scopeLevel);
|
|
42
42
|
this.parentContext = parent;
|
|
43
43
|
this.warnings = warnings;
|
|
44
44
|
}
|
|
@@ -50,8 +50,8 @@ export class ExecutionContext {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
log(...params) {
|
|
53
|
-
const indentOutput = ''.padStart(this.scope.
|
|
54
|
-
const indentLevelText = this.scope.
|
|
53
|
+
const indentOutput = ''.padStart(this.scope.scopeLevel * 4, ' ');
|
|
54
|
+
const indentLevelText = this.scope.scopeLevel
|
|
55
55
|
.toString()
|
|
56
56
|
.padStart(3, ' ');
|
|
57
57
|
const args = ['[' + indentLevelText + ']', indentOutput, ...params];
|
|
@@ -403,7 +403,7 @@ export class ExecutionContext {
|
|
|
403
403
|
this.addPoint(`${Delimiter1}${key}.${this.name}.${this.tmpPointId}`, false);
|
|
404
404
|
this.tmpPointId += 1;
|
|
405
405
|
}
|
|
406
|
-
this.scope.blockStack.set(this.scope.
|
|
406
|
+
this.scope.blockStack.set(this.scope.scopeLevel, {
|
|
407
407
|
start_point: [
|
|
408
408
|
this.scope.currentComponent,
|
|
409
409
|
this.scope.currentPin,
|
|
@@ -416,8 +416,11 @@ export class ExecutionContext {
|
|
|
416
416
|
});
|
|
417
417
|
this.log('enter blocks');
|
|
418
418
|
}
|
|
419
|
-
exitBlocks() {
|
|
420
|
-
|
|
419
|
+
exitBlocks(scopeLevel = null) {
|
|
420
|
+
if (scopeLevel === null) {
|
|
421
|
+
scopeLevel = this.scope.scopeLevel;
|
|
422
|
+
}
|
|
423
|
+
const stackRef = this.scope.blockStack.get(scopeLevel);
|
|
421
424
|
const { type: blockType } = stackRef;
|
|
422
425
|
if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
|
|
423
426
|
const { end_point: finalPoint } = stackRef;
|
|
@@ -434,16 +437,18 @@ export class ExecutionContext {
|
|
|
434
437
|
const { start_point: [component, pin,] } = stackRef;
|
|
435
438
|
this.atComponent(component, pin, { addSequence: true });
|
|
436
439
|
}
|
|
437
|
-
this.scope.blockStack.delete(
|
|
440
|
+
this.scope.blockStack.delete(scopeLevel);
|
|
438
441
|
this.log('exit blocks');
|
|
439
442
|
}
|
|
440
|
-
|
|
441
|
-
|
|
443
|
+
closeOpenPathBlocks() {
|
|
444
|
+
const scope = this.scope;
|
|
445
|
+
const scopeLevel = scope.scopeLevel;
|
|
446
|
+
if (scope.blockStack.has(scopeLevel)) {
|
|
442
447
|
this.exitBlocks();
|
|
443
448
|
}
|
|
444
449
|
}
|
|
445
450
|
enterBlock(blockIndex) {
|
|
446
|
-
const stackRef = this.scope.blockStack.get(this.scope.
|
|
451
|
+
const stackRef = this.scope.blockStack.get(this.scope.scopeLevel);
|
|
447
452
|
const { type: blockType } = stackRef;
|
|
448
453
|
const blockTypeName = getBlockTypeString(blockType);
|
|
449
454
|
stackRef.inner_blocks.set(blockIndex, {
|
|
@@ -459,10 +464,10 @@ export class ExecutionContext {
|
|
|
459
464
|
this.atComponent(component, pin, { addSequence: true });
|
|
460
465
|
}
|
|
461
466
|
this.log(`enter inner block of type (${blockTypeName}) >>>`);
|
|
462
|
-
this.scope.
|
|
467
|
+
this.scope.scopeLevel += 1;
|
|
463
468
|
}
|
|
464
469
|
exitBlock(blockIndex) {
|
|
465
|
-
const stackRef = this.scope.blockStack.get(this.scope.
|
|
470
|
+
const stackRef = this.scope.blockStack.get(this.scope.scopeLevel - 1);
|
|
466
471
|
const { type: blockType } = stackRef;
|
|
467
472
|
const blockIndexRef = stackRef.inner_blocks.get(blockIndex);
|
|
468
473
|
blockIndexRef.last_net = [
|
|
@@ -470,7 +475,7 @@ export class ExecutionContext {
|
|
|
470
475
|
this.scope.currentPin,
|
|
471
476
|
this.scope.currentWireId
|
|
472
477
|
];
|
|
473
|
-
this.scope.
|
|
478
|
+
this.scope.scopeLevel -= 1;
|
|
474
479
|
this.log('exit inner block <<<');
|
|
475
480
|
if (blockType === BlockTypes.Branch) {
|
|
476
481
|
const { start_point: [component, pin, wireId] } = stackRef;
|
|
@@ -511,8 +516,8 @@ export class ExecutionContext {
|
|
|
511
516
|
}
|
|
512
517
|
getPointBlockLocation() {
|
|
513
518
|
this.log('get block point');
|
|
514
|
-
for (let i = 0; i < this.scope.
|
|
515
|
-
const stackRef = this.scope.blockStack.get(this.scope.
|
|
519
|
+
for (let i = 0; i < this.scope.scopeLevel; i++) {
|
|
520
|
+
const stackRef = this.scope.blockStack.get(this.scope.scopeLevel - 1 - i);
|
|
516
521
|
const { start_point } = stackRef;
|
|
517
522
|
const component = start_point[0];
|
|
518
523
|
if (component.instanceName.startsWith(`${Delimiter1}point.`)) {
|
|
@@ -562,38 +567,18 @@ export class ExecutionContext {
|
|
|
562
567
|
if (isVariable || isComponentInstance) {
|
|
563
568
|
const scopeList = isVariable ? context.scope.variables
|
|
564
569
|
: context.scope.instances;
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const trailersPath = trailers.join(".");
|
|
570
|
-
if (!isComponentInstance && (parentValue instanceof ClassComponent)) {
|
|
571
|
-
isComponentInstance = true;
|
|
572
|
-
isVariable = false;
|
|
573
|
-
}
|
|
574
|
-
if (isVariable) {
|
|
575
|
-
useValue = parentValue[trailersPath];
|
|
576
|
-
}
|
|
577
|
-
else if (isComponentInstance) {
|
|
578
|
-
const tmpComponent = parentValue;
|
|
579
|
-
if (tmpComponent.typeProp === ComponentTypes.net) {
|
|
580
|
-
const usedNet = this.scope.getNet(tmpComponent, 1);
|
|
581
|
-
if (usedNet) {
|
|
582
|
-
const trailerValue = trailers.join(".");
|
|
583
|
-
useValue = usedNet.params.get(trailerValue) ?? null;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
useValue = parentValue.parameters.get(trailersPath);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
570
|
+
const useValue = scopeList.get(idName);
|
|
571
|
+
if (!isComponentInstance && (useValue instanceof ClassComponent)) {
|
|
572
|
+
isComponentInstance = true;
|
|
573
|
+
isVariable = false;
|
|
590
574
|
}
|
|
575
|
+
const tmpReference = this.resolveTrailers(isVariable ? ReferenceTypes.variable : ReferenceTypes.instance, useValue, trailers);
|
|
591
576
|
return new DeclaredReference({
|
|
592
577
|
type: isVariable ? ReferenceTypes.variable
|
|
593
578
|
: ReferenceTypes.instance,
|
|
594
|
-
found: (
|
|
595
|
-
parentValue,
|
|
596
|
-
value:
|
|
579
|
+
found: (tmpReference.value !== undefined),
|
|
580
|
+
parentValue: tmpReference.parentValue,
|
|
581
|
+
value: tmpReference.value,
|
|
597
582
|
name: idName,
|
|
598
583
|
trailers,
|
|
599
584
|
});
|
|
@@ -605,6 +590,37 @@ export class ExecutionContext {
|
|
|
605
590
|
name: idName,
|
|
606
591
|
});
|
|
607
592
|
}
|
|
593
|
+
resolveTrailers(type, item, trailers = []) {
|
|
594
|
+
let parentValue;
|
|
595
|
+
let useValue = item;
|
|
596
|
+
if (trailers.length > 0) {
|
|
597
|
+
parentValue = useValue;
|
|
598
|
+
const trailersPath = trailers.join(".");
|
|
599
|
+
if (type === ReferenceTypes.variable) {
|
|
600
|
+
useValue = parentValue[trailersPath];
|
|
601
|
+
}
|
|
602
|
+
else if (type === ReferenceTypes.instance) {
|
|
603
|
+
const tmpComponent = parentValue;
|
|
604
|
+
if (tmpComponent.typeProp === ComponentTypes.net) {
|
|
605
|
+
const usedNet = this.scope.getNet(tmpComponent, 1);
|
|
606
|
+
if (usedNet) {
|
|
607
|
+
const trailerValue = trailers.join(".");
|
|
608
|
+
useValue = usedNet.params.get(trailerValue) ?? null;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
useValue = parentValue.parameters.get(trailersPath);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return new AnyReference({
|
|
617
|
+
found: true,
|
|
618
|
+
type: type,
|
|
619
|
+
parentValue,
|
|
620
|
+
trailers,
|
|
621
|
+
value: useValue,
|
|
622
|
+
});
|
|
623
|
+
}
|
|
608
624
|
callFunction(functionName, functionParams, executionStack, netNamespace) {
|
|
609
625
|
let __runFunc = null;
|
|
610
626
|
if (this.__functionCache[functionName] === undefined) {
|
package/dist/esm/helpers.js
CHANGED
|
@@ -184,14 +184,6 @@ export async function renderScript(scriptData, outputPath, options) {
|
|
|
184
184
|
};
|
|
185
185
|
visitor.log('reading file');
|
|
186
186
|
visitor.log('done reading file');
|
|
187
|
-
const { tree, parser, parserTimeTaken, lexerTimeTaken } = await parseFileWithVisitor(visitor, scriptData);
|
|
188
|
-
printWarnings(visitor.getWarnings());
|
|
189
|
-
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
190
|
-
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
191
|
-
if (dumpNets) {
|
|
192
|
-
const nets = visitor.dumpNets();
|
|
193
|
-
nets.forEach(item => console.log(item.join(" | ")));
|
|
194
|
-
}
|
|
195
187
|
const dumpDirectory = environment.getRelativeToModule('/dump/');
|
|
196
188
|
if (dumpData) {
|
|
197
189
|
console.log('Dump data to:', dumpDirectory);
|
|
@@ -199,8 +191,19 @@ export async function renderScript(scriptData, outputPath, options) {
|
|
|
199
191
|
mkdirSync(dumpDirectory);
|
|
200
192
|
}
|
|
201
193
|
}
|
|
194
|
+
const { tree, parser, parserTimeTaken, lexerTimeTaken, throwError } = await parseFileWithVisitor(visitor, scriptData);
|
|
195
|
+
printWarnings(visitor.getWarnings());
|
|
196
|
+
showStats && console.log('Lexing took:', lexerTimeTaken);
|
|
197
|
+
showStats && console.log('Parsing took:', parserTimeTaken);
|
|
198
|
+
if (dumpNets) {
|
|
199
|
+
const nets = visitor.dumpNets();
|
|
200
|
+
nets.forEach(item => console.log(item.join(" | ")));
|
|
201
|
+
}
|
|
202
202
|
dumpData && writeFileSync(dumpDirectory + 'tree.lisp', tree.toStringTree(null, parser));
|
|
203
203
|
dumpData && writeFileSync(dumpDirectory + 'raw-parser.txt', visitor.logger.dump());
|
|
204
|
+
if (throwError) {
|
|
205
|
+
throw throwError;
|
|
206
|
+
}
|
|
204
207
|
let svgOutput = "";
|
|
205
208
|
if (errors.length === 0) {
|
|
206
209
|
const { frameComponent } = visitor.applySheetFrameComponent();
|
package/dist/esm/parser.js
CHANGED
|
@@ -18,6 +18,7 @@ export async function parseFileWithVisitor(visitor, data) {
|
|
|
18
18
|
parser.removeErrorListeners();
|
|
19
19
|
parser.addErrorListener(parserErrorListener);
|
|
20
20
|
const tree = parser.script();
|
|
21
|
+
let throwError;
|
|
21
22
|
try {
|
|
22
23
|
await visitor.visitAsync(tree);
|
|
23
24
|
}
|
|
@@ -27,7 +28,7 @@ export async function parseFileWithVisitor(visitor, data) {
|
|
|
27
28
|
visitor.onErrorHandler(error.message, null, error);
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
|
|
31
|
+
throwError = error;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -38,6 +39,7 @@ export async function parseFileWithVisitor(visitor, data) {
|
|
|
38
39
|
hasError: false,
|
|
39
40
|
parserTimeTaken,
|
|
40
41
|
lexerTimeTaken,
|
|
42
|
+
throwError
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
export class CircuitscriptParserErrorListener {
|
package/dist/esm/utils.js
CHANGED
package/dist/esm/visitor.js
CHANGED
|
@@ -4,7 +4,7 @@ import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
|
|
|
4
4
|
import { PinTypes } from './objects/PinTypes.js';
|
|
5
5
|
import { DeclaredReference, UndeclaredReference } from './objects/types.js';
|
|
6
6
|
import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
|
|
7
|
-
import {
|
|
7
|
+
import { unwrapValue } from "./utils.js";
|
|
8
8
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
|
|
9
9
|
import { BaseVisitor } from './BaseVisitor.js';
|
|
10
10
|
import { getPortType, RuntimeExecutionError } from './utils.js';
|
|
@@ -99,17 +99,17 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
99
99
|
}
|
|
100
100
|
const scope = this.getScope();
|
|
101
101
|
const executor = this.getExecutor();
|
|
102
|
-
const
|
|
103
|
-
if (scope.blockStack.has(
|
|
104
|
-
const blockStackEntry = scope.blockStack.get(
|
|
102
|
+
const scopeLevel = scope.scopeLevel;
|
|
103
|
+
if (scope.blockStack.has(scopeLevel)) {
|
|
104
|
+
const blockStackEntry = scope.blockStack.get(scopeLevel);
|
|
105
105
|
if (blockStackEntry.type !== blockType) {
|
|
106
106
|
executor.exitBlocks();
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
if (!scope.blockStack.has(
|
|
109
|
+
if (!scope.blockStack.has(scopeLevel)) {
|
|
110
110
|
executor.enterBlocks(blockType);
|
|
111
111
|
}
|
|
112
|
-
const blockStackEntry = scope.blockStack.get(
|
|
112
|
+
const blockStackEntry = scope.blockStack.get(scopeLevel);
|
|
113
113
|
const { current_index } = blockStackEntry;
|
|
114
114
|
executor.enterBlock(current_index);
|
|
115
115
|
this.visit(ctx.expressions_block());
|
|
@@ -117,12 +117,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
117
117
|
blockStackEntry.current_index++;
|
|
118
118
|
};
|
|
119
119
|
visitGraph_expressions = (ctx) => {
|
|
120
|
+
this.getExecutor().log('graph expressions', this.getScope().scopeLevel);
|
|
120
121
|
if (ctx.path_block() === null) {
|
|
121
|
-
|
|
122
|
-
const indentLevel = scope.indentLevel;
|
|
123
|
-
if (scope.blockStack.has(indentLevel)) {
|
|
124
|
-
this.getExecutor().exitBlocks();
|
|
125
|
-
}
|
|
122
|
+
this.getExecutor().closeOpenPathBlocks();
|
|
126
123
|
}
|
|
127
124
|
const ctxPathBlock = ctx.path_block();
|
|
128
125
|
const ctxNotPathBlock = ctx.graph_linear_expression();
|
|
@@ -401,7 +398,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
401
398
|
};
|
|
402
399
|
visitGraphicForExpr = (ctx) => {
|
|
403
400
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
404
|
-
const listItems =
|
|
401
|
+
const listItems = unwrapValue(this.visitResult(ctx.data_expr()));
|
|
405
402
|
let keepLooping = true;
|
|
406
403
|
let counter = 0;
|
|
407
404
|
let allCommands = [];
|
|
@@ -543,7 +540,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
543
540
|
const ctxAssignmentExpr = ctx.assignment_expr();
|
|
544
541
|
if (ctxDataExpr) {
|
|
545
542
|
component = this.visitResult(ctxDataExpr);
|
|
546
|
-
component =
|
|
543
|
+
component = unwrapValue(component);
|
|
547
544
|
componentCtx = ctxDataExpr;
|
|
548
545
|
if (component === null || component === undefined) {
|
|
549
546
|
this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
|
|
@@ -863,9 +860,10 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
863
860
|
this.setResult(ctx, result);
|
|
864
861
|
};
|
|
865
862
|
visitAt_block_pin_expr = (ctx) => {
|
|
866
|
-
const atPin = this.visitResult(ctx.pin_select_expr2());
|
|
867
863
|
const executor = this.getExecutor();
|
|
868
864
|
const [currentComponent, currentPin] = executor.getCurrentPoint();
|
|
865
|
+
executor.closeOpenPathBlocks();
|
|
866
|
+
const atPin = this.visitResult(ctx.pin_select_expr2());
|
|
869
867
|
executor.atComponent(currentComponent, atPin, {
|
|
870
868
|
addSequence: true
|
|
871
869
|
});
|
|
@@ -886,11 +884,11 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
886
884
|
executor.log('entering at block');
|
|
887
885
|
this.visit(ctx.at_component_expr());
|
|
888
886
|
const [currentComponent, currentPin] = executor.getCurrentPoint();
|
|
889
|
-
executor.scope.
|
|
887
|
+
executor.scope.scopeLevel += 1;
|
|
890
888
|
ctx.at_block_expressions().forEach(expression => {
|
|
891
889
|
this.visit(expression);
|
|
892
890
|
});
|
|
893
|
-
executor.scope.
|
|
891
|
+
executor.scope.scopeLevel -= 1;
|
|
894
892
|
executor.scope.setCurrent(currentComponent, currentPin);
|
|
895
893
|
executor.log('leaving at block');
|
|
896
894
|
};
|
|
@@ -1074,7 +1072,7 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1074
1072
|
this.log('in for loop');
|
|
1075
1073
|
const forVariableNames = ctx.ID().map(item => item.getText());
|
|
1076
1074
|
let listItems = this.visitResult(ctx.data_expr());
|
|
1077
|
-
listItems =
|
|
1075
|
+
listItems = unwrapValue(listItems);
|
|
1078
1076
|
this.getExecutor().addBreakContext(ctx);
|
|
1079
1077
|
let keepLooping = true;
|
|
1080
1078
|
let counter = 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array_exprContext, ArrayExprContext, Assignment_exprContext, Atom_exprContext,
|
|
1
|
+
import { Array_exprContext, ArrayExprContext, Assignment_exprContext, Atom_exprContext, ExpressionContext, Flow_expressionsContext, Function_args_exprContext, Function_call_exprContext, Function_exprContext, Function_return_exprContext, FunctionCallExprContext, Import_exprContext, Operator_assignment_exprContext, ParametersContext, RoundedBracketsExprContext, ScriptContext, Value_exprContext, ValueAtomExprContext } from "./antlr/CircuitScriptParser.js";
|
|
2
2
|
import { CircuitScriptVisitor } from "./antlr/CircuitScriptVisitor.js";
|
|
3
3
|
import { ExecutionContext } from "./execute.js";
|
|
4
4
|
import { Logger } from "./logger.js";
|
|
@@ -20,7 +20,6 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
20
20
|
printToConsole: boolean;
|
|
21
21
|
acceptedDirections: Direction[];
|
|
22
22
|
protected resultData: Map<ParserRuleContext, any>;
|
|
23
|
-
protected paramData: Map<ParserRuleContext, any>;
|
|
24
23
|
pinTypesList: string[];
|
|
25
24
|
onErrorHandler: OnErrorHandler | null;
|
|
26
25
|
environment: NodeScriptEnvironment;
|
|
@@ -50,14 +49,14 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
|
|
|
50
49
|
visitAtom_expr: (ctx: Atom_exprContext) => void;
|
|
51
50
|
visitFunctionCallExpr: (ctx: FunctionCallExprContext) => void;
|
|
52
51
|
visitFunction_call_expr: (ctx: Function_call_exprContext) => void;
|
|
52
|
+
private handleFunctionCall;
|
|
53
53
|
visitValue_expr: (ctx: Value_exprContext) => void;
|
|
54
54
|
visitValueAtomExpr: (ctx: ValueAtomExprContext) => void;
|
|
55
55
|
visitFunction_args_expr: (ctx: Function_args_exprContext) => void;
|
|
56
56
|
visitParameters: (ctx: ParametersContext) => void;
|
|
57
57
|
visitImport_expr: (ctx: Import_exprContext) => void;
|
|
58
58
|
visitFunction_return_expr: (ctx: Function_return_exprContext) => void;
|
|
59
|
-
|
|
60
|
-
visitContinue_keyword: (ctx: Continue_keywordContext) => void;
|
|
59
|
+
visitFlow_expressions: (ctx: Flow_expressionsContext) => void;
|
|
61
60
|
visitArray_expr: (ctx: Array_exprContext) => void;
|
|
62
61
|
visitArrayExpr: (ctx: ArrayExprContext) => void;
|
|
63
62
|
protected setResult(ctx: ParserRuleContext, value: any): void;
|
|
@@ -94,47 +94,45 @@ export declare class CircuitScriptParser extends antlr.Parser {
|
|
|
94
94
|
static readonly RULE_at_block_pin_expr = 22;
|
|
95
95
|
static readonly RULE_at_block_pin_expression_simple = 23;
|
|
96
96
|
static readonly RULE_at_block_pin_expression_complex = 24;
|
|
97
|
-
static readonly
|
|
98
|
-
static readonly
|
|
99
|
-
static readonly
|
|
100
|
-
static readonly
|
|
101
|
-
static readonly
|
|
102
|
-
static readonly
|
|
103
|
-
static readonly
|
|
104
|
-
static readonly
|
|
105
|
-
static readonly
|
|
106
|
-
static readonly
|
|
107
|
-
static readonly
|
|
108
|
-
static readonly
|
|
109
|
-
static readonly
|
|
110
|
-
static readonly
|
|
111
|
-
static readonly
|
|
112
|
-
static readonly
|
|
113
|
-
static readonly
|
|
114
|
-
static readonly
|
|
115
|
-
static readonly
|
|
116
|
-
static readonly
|
|
117
|
-
static readonly
|
|
118
|
-
static readonly
|
|
119
|
-
static readonly
|
|
120
|
-
static readonly
|
|
121
|
-
static readonly
|
|
122
|
-
static readonly
|
|
123
|
-
static readonly
|
|
124
|
-
static readonly
|
|
125
|
-
static readonly
|
|
126
|
-
static readonly
|
|
127
|
-
static readonly
|
|
128
|
-
static readonly
|
|
129
|
-
static readonly
|
|
130
|
-
static readonly
|
|
131
|
-
static readonly
|
|
132
|
-
static readonly
|
|
133
|
-
static readonly
|
|
134
|
-
static readonly
|
|
135
|
-
static readonly
|
|
136
|
-
static readonly RULE_while_expr = 64;
|
|
137
|
-
static readonly RULE_for_expr = 65;
|
|
97
|
+
static readonly RULE_assignment_expr = 25;
|
|
98
|
+
static readonly RULE_operator_assignment_expr = 26;
|
|
99
|
+
static readonly RULE_keyword_assignment_expr = 27;
|
|
100
|
+
static readonly RULE_parameters = 28;
|
|
101
|
+
static readonly RULE_property_set_expr = 29;
|
|
102
|
+
static readonly RULE_double_dot_property_set_expr = 30;
|
|
103
|
+
static readonly RULE_data_expr = 31;
|
|
104
|
+
static readonly RULE_binary_operator = 32;
|
|
105
|
+
static readonly RULE_unary_operator = 33;
|
|
106
|
+
static readonly RULE_value_expr = 34;
|
|
107
|
+
static readonly RULE_function_def_expr = 35;
|
|
108
|
+
static readonly RULE_function_expr = 36;
|
|
109
|
+
static readonly RULE_function_args_expr = 37;
|
|
110
|
+
static readonly RULE_atom_expr = 38;
|
|
111
|
+
static readonly RULE_trailer_expr = 39;
|
|
112
|
+
static readonly RULE_function_call_expr = 40;
|
|
113
|
+
static readonly RULE_net_namespace_expr = 41;
|
|
114
|
+
static readonly RULE_function_return_expr = 42;
|
|
115
|
+
static readonly RULE_property_block_expr = 43;
|
|
116
|
+
static readonly RULE_create_component_expr = 44;
|
|
117
|
+
static readonly RULE_graphic_expressions_block = 45;
|
|
118
|
+
static readonly RULE_create_graphic_expr = 46;
|
|
119
|
+
static readonly RULE_create_module_expr = 47;
|
|
120
|
+
static readonly RULE_nested_properties_inner = 48;
|
|
121
|
+
static readonly RULE_graphic_expr = 49;
|
|
122
|
+
static readonly RULE_property_expr = 50;
|
|
123
|
+
static readonly RULE_property_key_expr = 51;
|
|
124
|
+
static readonly RULE_property_value_expr = 52;
|
|
125
|
+
static readonly RULE_wire_atom_expr = 53;
|
|
126
|
+
static readonly RULE_wire_expr = 54;
|
|
127
|
+
static readonly RULE_array_expr = 55;
|
|
128
|
+
static readonly RULE_point_expr = 56;
|
|
129
|
+
static readonly RULE_import_expr = 57;
|
|
130
|
+
static readonly RULE_frame_expr = 58;
|
|
131
|
+
static readonly RULE_if_expr = 59;
|
|
132
|
+
static readonly RULE_if_inner_expr = 60;
|
|
133
|
+
static readonly RULE_else_expr = 61;
|
|
134
|
+
static readonly RULE_while_expr = 62;
|
|
135
|
+
static readonly RULE_for_expr = 63;
|
|
138
136
|
static readonly literalNames: (string | null)[];
|
|
139
137
|
static readonly symbolicNames: (string | null)[];
|
|
140
138
|
static readonly ruleNames: string[];
|
|
@@ -170,8 +168,6 @@ export declare class CircuitScriptParser extends antlr.Parser {
|
|
|
170
168
|
at_block_pin_expr(): At_block_pin_exprContext;
|
|
171
169
|
at_block_pin_expression_simple(): At_block_pin_expression_simpleContext;
|
|
172
170
|
at_block_pin_expression_complex(): At_block_pin_expression_complexContext;
|
|
173
|
-
break_keyword(): Break_keywordContext;
|
|
174
|
-
continue_keyword(): Continue_keywordContext;
|
|
175
171
|
assignment_expr(): Assignment_exprContext;
|
|
176
172
|
operator_assignment_expr(): Operator_assignment_exprContext;
|
|
177
173
|
keyword_assignment_expr(): Keyword_assignment_exprContext;
|
|
@@ -236,7 +232,6 @@ export declare class ScriptContext extends antlr.ParserRuleContext {
|
|
|
236
232
|
export declare class ExpressionContext extends antlr.ParserRuleContext {
|
|
237
233
|
constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
|
|
238
234
|
graph_expressions(): Graph_expressionsContext | null;
|
|
239
|
-
flow_expressions(): Flow_expressionsContext | null;
|
|
240
235
|
assignment_expr(): Assignment_exprContext | null;
|
|
241
236
|
operator_assignment_expr(): Operator_assignment_exprContext | null;
|
|
242
237
|
property_set_expr(): Property_set_exprContext | null;
|
|
@@ -247,6 +242,7 @@ export declare class ExpressionContext extends antlr.ParserRuleContext {
|
|
|
247
242
|
import_expr(): Import_exprContext | null;
|
|
248
243
|
atom_expr(): Atom_exprContext | null;
|
|
249
244
|
frame_expr(): Frame_exprContext | null;
|
|
245
|
+
flow_expressions(): Flow_expressionsContext | null;
|
|
250
246
|
get ruleIndex(): number;
|
|
251
247
|
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
252
248
|
}
|
|
@@ -255,8 +251,8 @@ export declare class Flow_expressionsContext extends antlr.ParserRuleContext {
|
|
|
255
251
|
if_expr(): If_exprContext | null;
|
|
256
252
|
while_expr(): While_exprContext | null;
|
|
257
253
|
for_expr(): For_exprContext | null;
|
|
258
|
-
|
|
259
|
-
|
|
254
|
+
Break(): antlr.TerminalNode | null;
|
|
255
|
+
Continue(): antlr.TerminalNode | null;
|
|
260
256
|
get ruleIndex(): number;
|
|
261
257
|
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
262
258
|
}
|
|
@@ -451,18 +447,6 @@ export declare class At_block_pin_expression_complexContext extends antlr.Parser
|
|
|
451
447
|
get ruleIndex(): number;
|
|
452
448
|
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
453
449
|
}
|
|
454
|
-
export declare class Break_keywordContext extends antlr.ParserRuleContext {
|
|
455
|
-
constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
|
|
456
|
-
Break(): antlr.TerminalNode;
|
|
457
|
-
get ruleIndex(): number;
|
|
458
|
-
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
459
|
-
}
|
|
460
|
-
export declare class Continue_keywordContext extends antlr.ParserRuleContext {
|
|
461
|
-
constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
|
|
462
|
-
Continue(): antlr.TerminalNode;
|
|
463
|
-
get ruleIndex(): number;
|
|
464
|
-
accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
|
|
465
|
-
}
|
|
466
450
|
export declare class Assignment_exprContext extends antlr.ParserRuleContext {
|
|
467
451
|
constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
|
|
468
452
|
data_expr(): Data_exprContext;
|
|
@@ -24,8 +24,6 @@ import { At_block_expressionsContext } from "./CircuitScriptParser.js";
|
|
|
24
24
|
import { At_block_pin_exprContext } from "./CircuitScriptParser.js";
|
|
25
25
|
import { At_block_pin_expression_simpleContext } from "./CircuitScriptParser.js";
|
|
26
26
|
import { At_block_pin_expression_complexContext } from "./CircuitScriptParser.js";
|
|
27
|
-
import { Break_keywordContext } from "./CircuitScriptParser.js";
|
|
28
|
-
import { Continue_keywordContext } from "./CircuitScriptParser.js";
|
|
29
27
|
import { Assignment_exprContext } from "./CircuitScriptParser.js";
|
|
30
28
|
import { Operator_assignment_exprContext } from "./CircuitScriptParser.js";
|
|
31
29
|
import { Keyword_assignment_exprContext } from "./CircuitScriptParser.js";
|
|
@@ -103,8 +101,6 @@ export declare class CircuitScriptVisitor<Result> extends AbstractParseTreeVisit
|
|
|
103
101
|
visitAt_block_pin_expr?: (ctx: At_block_pin_exprContext) => Result;
|
|
104
102
|
visitAt_block_pin_expression_simple?: (ctx: At_block_pin_expression_simpleContext) => Result;
|
|
105
103
|
visitAt_block_pin_expression_complex?: (ctx: At_block_pin_expression_complexContext) => Result;
|
|
106
|
-
visitBreak_keyword?: (ctx: Break_keywordContext) => Result;
|
|
107
|
-
visitContinue_keyword?: (ctx: Continue_keywordContext) => Result;
|
|
108
104
|
visitAssignment_expr?: (ctx: Assignment_exprContext) => Result;
|
|
109
105
|
visitOperator_assignment_expr?: (ctx: Operator_assignment_exprContext) => Result;
|
|
110
106
|
visitKeyword_assignment_expr?: (ctx: Keyword_assignment_exprContext) => Result;
|