circuitscript 0.1.11 → 0.1.12
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 +78 -51
- package/dist/cjs/antlr/CircuitScriptParser.js +1059 -949
- package/dist/cjs/builtinMethods.js +5 -1
- package/dist/cjs/execute.js +43 -22
- package/dist/cjs/globals.js +7 -1
- package/dist/cjs/layout.js +50 -16
- package/dist/cjs/objects/ExecutionScope.js +3 -0
- package/dist/cjs/objects/Net.js +1 -0
- package/dist/cjs/objects/ParamDefinition.js +3 -0
- package/dist/cjs/objects/types.js +19 -10
- package/dist/cjs/render.js +48 -6
- package/dist/cjs/utils.js +16 -1
- package/dist/cjs/visitor.js +69 -52
- package/dist/esm/BaseVisitor.js +72 -45
- package/dist/esm/antlr/CircuitScriptParser.js +1052 -944
- package/dist/esm/antlr/CircuitScriptVisitor.js +4 -2
- package/dist/esm/builtinMethods.js +6 -2
- package/dist/esm/execute.js +43 -22
- package/dist/esm/globals.js +6 -0
- package/dist/esm/layout.js +53 -17
- package/dist/esm/objects/ExecutionScope.js +3 -0
- package/dist/esm/objects/Net.js +1 -0
- package/dist/esm/objects/ParamDefinition.js +4 -1
- package/dist/esm/objects/types.js +21 -15
- package/dist/esm/render.js +49 -7
- package/dist/esm/utils.js +13 -0
- package/dist/esm/visitor.js +57 -40
- package/dist/types/BaseVisitor.d.ts +2 -2
- package/dist/types/antlr/CircuitScriptParser.d.ts +99 -83
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -4
- package/dist/types/execute.d.ts +1 -0
- package/dist/types/globals.d.ts +5 -0
- package/dist/types/layout.d.ts +16 -3
- package/dist/types/objects/ExecutionScope.d.ts +15 -3
- package/dist/types/objects/Net.d.ts +1 -0
- package/dist/types/objects/types.d.ts +25 -18
- package/dist/types/utils.d.ts +3 -1
- package/dist/types/visitor.d.ts +3 -2
- package/package.json +1 -1
- /package/dist/libs/{lib.cst → std.cst} +0 -0
- /package/libs/{lib.cst → std.cst} +0 -0
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -11,8 +11,9 @@ const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
|
11
11
|
const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
12
12
|
const types_js_1 = require("./objects/types.js");
|
|
13
13
|
const globals_js_1 = require("./globals.js");
|
|
14
|
-
const builtinMethods_js_1 = require("./builtinMethods.js");
|
|
15
14
|
const utils_js_1 = require("./utils.js");
|
|
15
|
+
const builtinMethods_js_1 = require("./builtinMethods.js");
|
|
16
|
+
const utils_js_2 = require("./utils.js");
|
|
16
17
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
17
18
|
class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
18
19
|
constructor(silent = false, onErrorHandler = null, environment) {
|
|
@@ -48,37 +49,61 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
48
49
|
}
|
|
49
50
|
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
50
51
|
this.setResult(ctx, result);
|
|
52
|
+
this.getExecutor().closeAllBlocks();
|
|
51
53
|
this.log('===', 'end', '===');
|
|
52
54
|
};
|
|
53
55
|
this.visitAssignment_expr = (ctx) => {
|
|
54
|
-
const
|
|
56
|
+
const ctxAtom = ctx.atom_expr();
|
|
57
|
+
const ctxFuncCall = ctx.function_call_expr();
|
|
58
|
+
let leftSideReference;
|
|
59
|
+
if (ctxAtom) {
|
|
60
|
+
leftSideReference = this.getReference(ctx.atom_expr());
|
|
61
|
+
}
|
|
62
|
+
else if (ctxFuncCall) {
|
|
63
|
+
leftSideReference = this.visitResult(ctxFuncCall);
|
|
64
|
+
}
|
|
55
65
|
const ctxDataExpr = ctx.data_expr();
|
|
56
|
-
this.
|
|
57
|
-
const
|
|
58
|
-
const trailers =
|
|
66
|
+
const dataValue = this.visitResult(ctxDataExpr);
|
|
67
|
+
const rhsValue = (0, utils_js_1.prepareValue)(dataValue);
|
|
68
|
+
const trailers = leftSideReference.trailers ?? [];
|
|
69
|
+
const sequenceParts = [];
|
|
59
70
|
if (trailers.length === 0) {
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.
|
|
64
|
-
this.log2(`assigned '${reference.name}' to ClassComponent`);
|
|
71
|
+
if (rhsValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
72
|
+
this.getScope().setVariable(leftSideReference.name, rhsValue);
|
|
73
|
+
sequenceParts.push(...['instance', leftSideReference.name, rhsValue]);
|
|
74
|
+
this.log2(`assigned '${leftSideReference.name}' to ClassComponent`);
|
|
65
75
|
}
|
|
66
76
|
else {
|
|
67
|
-
this.
|
|
68
|
-
this.log2(`assigned variable ${
|
|
77
|
+
this.getScope().setVariable(leftSideReference.name, rhsValue);
|
|
78
|
+
this.log2(`assigned variable ${leftSideReference.name} to ${rhsValue}`);
|
|
79
|
+
sequenceParts.push(...['variable', leftSideReference.name, rhsValue]);
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
else {
|
|
72
|
-
if (
|
|
73
|
-
this.setInstanceParam(
|
|
74
|
-
this.log2(`assigned component param ${
|
|
83
|
+
if (leftSideReference.parentValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
84
|
+
this.setInstanceParam(leftSideReference.parentValue, trailers, rhsValue);
|
|
85
|
+
this.log2(`assigned component param ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
86
|
+
sequenceParts.push(...['instance', [leftSideReference.parentValue, trailers], rhsValue]);
|
|
87
|
+
if (leftSideReference.parentValue.typeProp === globals_js_1.ComponentTypes.net) {
|
|
88
|
+
const net = this.getScope().getNet(leftSideReference.parentValue, 1);
|
|
89
|
+
if (net) {
|
|
90
|
+
const trailerValue = trailers.join(".");
|
|
91
|
+
net.params.set(trailerValue, rhsValue);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
75
94
|
}
|
|
76
|
-
else if (
|
|
77
|
-
|
|
78
|
-
this.log2(`assigned object ${
|
|
95
|
+
else if (leftSideReference.parentValue instanceof Object) {
|
|
96
|
+
leftSideReference.parentValue[trailers.join('.')] = rhsValue;
|
|
97
|
+
this.log2(`assigned object ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
98
|
+
sequenceParts.push(...['variable', [leftSideReference.parentValue, trailers], rhsValue]);
|
|
79
99
|
}
|
|
80
100
|
}
|
|
81
|
-
|
|
101
|
+
if (sequenceParts.length > 0) {
|
|
102
|
+
this.getScope().sequence.push([
|
|
103
|
+
ExecutionScope_js_1.SequenceAction.Assign, ...sequenceParts
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
this.setResult(ctx, rhsValue);
|
|
82
107
|
};
|
|
83
108
|
this.visitOperator_assignment_expr = (ctx) => {
|
|
84
109
|
const reference = this.getReference(ctx.atom_expr());
|
|
@@ -125,7 +150,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
125
150
|
this.throwWithContext(ctx, 'Operator assignment failed: could not perform operator');
|
|
126
151
|
}
|
|
127
152
|
if (trailers.length === 0) {
|
|
128
|
-
this.getExecutor().scope.
|
|
153
|
+
this.getExecutor().scope.setVariable(reference.name, newValue);
|
|
129
154
|
}
|
|
130
155
|
else {
|
|
131
156
|
if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
|
|
@@ -151,11 +176,11 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
151
176
|
}
|
|
152
177
|
}
|
|
153
178
|
if (this.pinTypesList.indexOf(atomId) !== -1) {
|
|
154
|
-
currentReference = {
|
|
179
|
+
currentReference = new types_js_1.AnyReference({
|
|
155
180
|
found: true,
|
|
156
181
|
value: atomId,
|
|
157
182
|
type: globals_js_1.ReferenceTypes.pinType,
|
|
158
|
-
};
|
|
183
|
+
});
|
|
159
184
|
}
|
|
160
185
|
else {
|
|
161
186
|
currentReference = executor.resolveVariable(this.executionStack, atomId, idTrailers);
|
|
@@ -172,9 +197,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
172
197
|
this.setResult(ctx, currentReference);
|
|
173
198
|
};
|
|
174
199
|
this.visitFunctionCallExpr = (ctx) => {
|
|
175
|
-
const
|
|
176
|
-
this.visit(tmpCtx);
|
|
177
|
-
const result = this.getResult(tmpCtx);
|
|
200
|
+
const result = this.visitResult(ctx.function_call_expr());
|
|
178
201
|
this.setResult(ctx, result);
|
|
179
202
|
};
|
|
180
203
|
this.visitFunction_call_expr = (ctx) => {
|
|
@@ -204,12 +227,18 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
204
227
|
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
205
228
|
try {
|
|
206
229
|
const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
230
|
+
if ((0, utils_js_1.isReference)(functionResult)) {
|
|
231
|
+
currentReference = functionResult;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
currentReference = new types_js_1.AnyReference({
|
|
235
|
+
found: true,
|
|
236
|
+
value: functionResult,
|
|
237
|
+
trailers: [],
|
|
238
|
+
type: (functionResult instanceof ClassComponent_js_1.ClassComponent) ?
|
|
239
|
+
globals_js_1.ReferenceTypes.instance : globals_js_1.ReferenceTypes.value,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
213
242
|
}
|
|
214
243
|
catch (err) {
|
|
215
244
|
this.throwWithContext(ctx, err);
|
|
@@ -220,7 +249,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
220
249
|
}
|
|
221
250
|
});
|
|
222
251
|
}
|
|
223
|
-
this.setResult(ctx, currentReference
|
|
252
|
+
this.setResult(ctx, currentReference);
|
|
224
253
|
};
|
|
225
254
|
this.visitValue_expr = (ctx) => {
|
|
226
255
|
const sign = ctx.Minus() ? -1 : 1;
|
|
@@ -233,10 +262,10 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
233
262
|
let result = null;
|
|
234
263
|
if (ctxIntegerValue || ctxDecimalValue || ctxNumericValue) {
|
|
235
264
|
if (ctxIntegerValue) {
|
|
236
|
-
result = (0,
|
|
265
|
+
result = (0, utils_js_2.resolveToNumericValue)((new big_js_1.Big(ctxIntegerValue.getText())).mul(new big_js_1.Big(sign)));
|
|
237
266
|
}
|
|
238
267
|
else if (ctxDecimalValue) {
|
|
239
|
-
result = (0,
|
|
268
|
+
result = (0, utils_js_2.resolveToNumericValue)((new big_js_1.Big(ctxDecimalValue.getText())).mul(new big_js_1.Big(sign)));
|
|
240
269
|
}
|
|
241
270
|
else if (ctxNumericValue) {
|
|
242
271
|
const textExtra = ctx.Minus() ? '-' : '';
|
|
@@ -318,19 +347,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
318
347
|
const keywordAssignmentExpressions = ctx.keyword_assignment_expr();
|
|
319
348
|
const returnList = [];
|
|
320
349
|
dataExpressions.forEach((item, index) => {
|
|
321
|
-
this.
|
|
322
|
-
const value = this.getResult(item);
|
|
350
|
+
const value = this.visitResult(item);
|
|
323
351
|
returnList.push(['position', index, value]);
|
|
324
352
|
});
|
|
325
353
|
keywordAssignmentExpressions.forEach((item) => {
|
|
326
|
-
this.
|
|
327
|
-
const [key, value] = this.getResult(item);
|
|
354
|
+
const [key, value] = this.visitResult(item);
|
|
328
355
|
returnList.push(['keyword', key, value]);
|
|
329
356
|
});
|
|
330
357
|
this.setResult(ctx, returnList);
|
|
331
358
|
};
|
|
332
359
|
this.visitImport_expr = (ctx) => {
|
|
333
|
-
throw new
|
|
360
|
+
throw new utils_js_2.RuntimeExecutionError("Cannot parse imports here", ctx);
|
|
334
361
|
};
|
|
335
362
|
this.visitFunction_return_expr = (ctx) => {
|
|
336
363
|
const executor = this.getExecutor();
|
|
@@ -384,7 +411,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
384
411
|
scope.sequence.push([
|
|
385
412
|
ExecutionScope_js_1.SequenceAction.At, scope.componentRoot, scope.currentPin
|
|
386
413
|
]);
|
|
387
|
-
scope.
|
|
414
|
+
scope.setVariable(globals_js_1.GlobalDocumentName, {});
|
|
388
415
|
this.setupBuiltInFunctions(this.startingContext);
|
|
389
416
|
this.executionStack = [this.startingContext];
|
|
390
417
|
this.startingContext.resolveNet =
|
|
@@ -459,8 +486,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
459
486
|
if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
|
|
460
487
|
this.throwWithContext(ctx, "Invalid assignment expression!");
|
|
461
488
|
}
|
|
462
|
-
this.
|
|
463
|
-
const reference = this.getResult(ctx);
|
|
489
|
+
const reference = this.visitResult(ctx);
|
|
464
490
|
const { trailers = [] } = reference;
|
|
465
491
|
const undefinedParentWithTrailers = trailers.length > 0
|
|
466
492
|
&& reference.parentValue === undefined;
|
|
@@ -523,7 +549,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
523
549
|
}
|
|
524
550
|
catch (err) {
|
|
525
551
|
if (ctx != null) {
|
|
526
|
-
throw new
|
|
552
|
+
throw new utils_js_2.RuntimeExecutionError("An error occurred while importing file", ctx);
|
|
527
553
|
}
|
|
528
554
|
else {
|
|
529
555
|
this.log('An error occurred while importing file:', err.message);
|
|
@@ -539,7 +565,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
539
565
|
}
|
|
540
566
|
}
|
|
541
567
|
if (errorMessage !== null && ctx) {
|
|
542
|
-
throw new
|
|
568
|
+
throw new utils_js_2.RuntimeExecutionError(errorMessage, ctx);
|
|
543
569
|
}
|
|
544
570
|
const newImportedFile = {
|
|
545
571
|
id: name.trim(),
|
|
@@ -555,12 +581,13 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
555
581
|
const tmpFuncArg = funcDefinedParameters[i];
|
|
556
582
|
if (i < passedInParameters.length) {
|
|
557
583
|
const tmpPassedInArgs = passedInParameters[i];
|
|
584
|
+
const argValue = (0, utils_js_1.prepareValue)(tmpPassedInArgs[2]);
|
|
558
585
|
if (tmpPassedInArgs[0] === 'position') {
|
|
559
586
|
const variableName = tmpFuncArg[0];
|
|
560
587
|
executor.log('set variable in scope, var name: ', variableName);
|
|
561
|
-
executor.scope.
|
|
562
|
-
if (
|
|
563
|
-
const component =
|
|
588
|
+
executor.scope.setVariable(variableName, argValue);
|
|
589
|
+
if (argValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
590
|
+
const component = argValue;
|
|
564
591
|
for (const [pinNumber, net] of component.pinNets) {
|
|
565
592
|
executor.scope.setNet(component, pinNumber, net);
|
|
566
593
|
}
|
|
@@ -569,14 +596,14 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
569
596
|
else if (tmpPassedInArgs[0] === 'keyword') {
|
|
570
597
|
const variableName = tmpPassedInArgs[1];
|
|
571
598
|
executor.log('set variable in scope, var name: ', variableName);
|
|
572
|
-
executor.scope.
|
|
599
|
+
executor.scope.setVariable(variableName, argValue);
|
|
573
600
|
}
|
|
574
601
|
}
|
|
575
602
|
else if (tmpFuncArg.length === 3) {
|
|
576
603
|
const variableName = tmpFuncArg[0];
|
|
577
604
|
const defaultValue = tmpFuncArg[2];
|
|
578
605
|
executor.log('set variable in scope, var name: ', variableName);
|
|
579
|
-
executor.scope.
|
|
606
|
+
executor.scope.setVariable(variableName, defaultValue);
|
|
580
607
|
}
|
|
581
608
|
else {
|
|
582
609
|
throw `Invalid arguments got: ` + passedInParameters;
|
|
@@ -646,7 +673,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
646
673
|
return value.slice(1, value.length - 1);
|
|
647
674
|
}
|
|
648
675
|
throwWithContext(context, messageOrError) {
|
|
649
|
-
(0,
|
|
676
|
+
(0, utils_js_2.throwWithContext)(context, messageOrError);
|
|
650
677
|
}
|
|
651
678
|
validateType(value, context, validateFunction, expectedType) {
|
|
652
679
|
if (value === undefined) {
|
|
@@ -654,7 +681,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
654
681
|
}
|
|
655
682
|
const result = validateFunction(value);
|
|
656
683
|
if (!result) {
|
|
657
|
-
throw new
|
|
684
|
+
throw new utils_js_2.RuntimeExecutionError(`Invalid ${expectedType}`, context);
|
|
658
685
|
}
|
|
659
686
|
return result;
|
|
660
687
|
}
|