circuitscript 0.1.11 → 0.1.13
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 +147 -115
- package/dist/cjs/antlr/CircuitScriptParser.js +949 -932
- package/dist/cjs/builtinMethods.js +7 -1
- package/dist/cjs/execute.js +67 -35
- package/dist/cjs/globals.js +7 -1
- package/dist/cjs/helpers.js +11 -8
- 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/parser.js +3 -1
- 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 +113 -81
- package/dist/esm/antlr/CircuitScriptParser.js +943 -926
- package/dist/esm/antlr/CircuitScriptVisitor.js +4 -4
- package/dist/esm/builtinMethods.js +8 -2
- package/dist/esm/execute.js +68 -36
- package/dist/esm/globals.js +6 -0
- package/dist/esm/helpers.js +11 -8
- 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/parser.js +3 -1
- 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 +5 -6
- package/dist/types/antlr/CircuitScriptParser.d.ts +58 -58
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -8
- package/dist/types/execute.d.ts +4 -2
- 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/parser.d.ts +1 -0
- 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) {
|
|
@@ -24,7 +25,6 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
24
25
|
this.acceptedDirections = [types_js_1.Direction.Up, types_js_1.Direction.Down,
|
|
25
26
|
types_js_1.Direction.Right, types_js_1.Direction.Left];
|
|
26
27
|
this.resultData = new Map;
|
|
27
|
-
this.paramData = new Map;
|
|
28
28
|
this.pinTypesList = [
|
|
29
29
|
PinTypes_js_1.PinTypes.Any,
|
|
30
30
|
PinTypes_js_1.PinTypes.Input,
|
|
@@ -48,43 +48,65 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
48
48
|
}
|
|
49
49
|
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
50
50
|
this.setResult(ctx, result);
|
|
51
|
+
this.getExecutor().closeAllBlocks();
|
|
51
52
|
this.log('===', 'end', '===');
|
|
52
53
|
};
|
|
53
54
|
this.visitAssignment_expr = (ctx) => {
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
const ctxAtom = ctx.atom_expr();
|
|
56
|
+
const ctxFuncCallRef = ctx.function_call_expr();
|
|
57
|
+
let leftSideReference;
|
|
58
|
+
if (ctxAtom) {
|
|
59
|
+
leftSideReference = this.getReference(ctx.atom_expr());
|
|
60
|
+
}
|
|
61
|
+
else if (ctxFuncCallRef) {
|
|
62
|
+
this.setResult(ctxFuncCallRef, { keepReference: true });
|
|
63
|
+
leftSideReference = this.visitResult(ctxFuncCallRef);
|
|
64
|
+
}
|
|
65
|
+
const rhsCtxResult = this.visitResult(ctx.data_expr());
|
|
66
|
+
const rhsValue = (0, utils_js_1.unwrapValue)(rhsCtxResult);
|
|
67
|
+
const trailers = leftSideReference.trailers ?? [];
|
|
68
|
+
const sequenceParts = [];
|
|
59
69
|
if (trailers.length === 0) {
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.
|
|
64
|
-
this.log2(`assigned '${reference.name}' to ClassComponent`);
|
|
70
|
+
if (rhsValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
71
|
+
this.getScope().setVariable(leftSideReference.name, rhsValue);
|
|
72
|
+
sequenceParts.push(...['instance', leftSideReference.name, rhsValue]);
|
|
73
|
+
this.log2(`assigned '${leftSideReference.name}' to ClassComponent`);
|
|
65
74
|
}
|
|
66
75
|
else {
|
|
67
|
-
this.
|
|
68
|
-
this.log2(`assigned variable ${
|
|
76
|
+
this.getScope().setVariable(leftSideReference.name, rhsValue);
|
|
77
|
+
this.log2(`assigned variable ${leftSideReference.name} to ${rhsValue}`);
|
|
78
|
+
sequenceParts.push(...['variable', leftSideReference.name, rhsValue]);
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
81
|
else {
|
|
72
|
-
if (
|
|
73
|
-
this.setInstanceParam(
|
|
74
|
-
this.log2(`assigned component param ${
|
|
82
|
+
if (leftSideReference.parentValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
83
|
+
this.setInstanceParam(leftSideReference.parentValue, trailers, rhsValue);
|
|
84
|
+
this.log2(`assigned component param ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
85
|
+
sequenceParts.push(...['instance', [leftSideReference.parentValue, trailers], rhsValue]);
|
|
86
|
+
if (leftSideReference.parentValue.typeProp === globals_js_1.ComponentTypes.net) {
|
|
87
|
+
const net = this.getScope().getNet(leftSideReference.parentValue, 1);
|
|
88
|
+
if (net) {
|
|
89
|
+
const trailerValue = trailers.join(".");
|
|
90
|
+
net.params.set(trailerValue, rhsValue);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
75
93
|
}
|
|
76
|
-
else if (
|
|
77
|
-
|
|
78
|
-
this.log2(`assigned object ${
|
|
94
|
+
else if (leftSideReference.parentValue instanceof Object) {
|
|
95
|
+
leftSideReference.parentValue[trailers.join('.')] = rhsValue;
|
|
96
|
+
this.log2(`assigned object ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
|
|
97
|
+
sequenceParts.push(...['variable', [leftSideReference.parentValue, trailers], rhsValue]);
|
|
79
98
|
}
|
|
80
99
|
}
|
|
81
|
-
|
|
100
|
+
if (sequenceParts.length > 0) {
|
|
101
|
+
this.getScope().sequence.push([
|
|
102
|
+
ExecutionScope_js_1.SequenceAction.Assign, ...sequenceParts
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
this.setResult(ctx, rhsValue);
|
|
82
106
|
};
|
|
83
107
|
this.visitOperator_assignment_expr = (ctx) => {
|
|
84
108
|
const reference = this.getReference(ctx.atom_expr());
|
|
85
|
-
const
|
|
86
|
-
this.visit(ctxDataExpr);
|
|
87
|
-
const value = this.getResult(ctxDataExpr);
|
|
109
|
+
const value = this.visitResult(ctx.data_expr());
|
|
88
110
|
if (!reference.found) {
|
|
89
111
|
this.throwWithContext(ctx, 'Undefined reference: ' + reference.name);
|
|
90
112
|
}
|
|
@@ -125,7 +147,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
125
147
|
this.throwWithContext(ctx, 'Operator assignment failed: could not perform operator');
|
|
126
148
|
}
|
|
127
149
|
if (trailers.length === 0) {
|
|
128
|
-
this.getExecutor().scope.
|
|
150
|
+
this.getExecutor().scope.setVariable(reference.name, newValue);
|
|
129
151
|
}
|
|
130
152
|
else {
|
|
131
153
|
if (reference.value instanceof ClassComponent_js_1.ClassComponent) {
|
|
@@ -151,11 +173,11 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
151
173
|
}
|
|
152
174
|
}
|
|
153
175
|
if (this.pinTypesList.indexOf(atomId) !== -1) {
|
|
154
|
-
currentReference = {
|
|
176
|
+
currentReference = new types_js_1.AnyReference({
|
|
155
177
|
found: true,
|
|
156
178
|
value: atomId,
|
|
157
179
|
type: globals_js_1.ReferenceTypes.pinType,
|
|
158
|
-
};
|
|
180
|
+
});
|
|
159
181
|
}
|
|
160
182
|
else {
|
|
161
183
|
currentReference = executor.resolveVariable(this.executionStack, atomId, idTrailers);
|
|
@@ -172,55 +194,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
172
194
|
this.setResult(ctx, currentReference);
|
|
173
195
|
};
|
|
174
196
|
this.visitFunctionCallExpr = (ctx) => {
|
|
175
|
-
const
|
|
176
|
-
this.visit(tmpCtx);
|
|
177
|
-
const result = this.getResult(tmpCtx);
|
|
197
|
+
const result = this.visitResult(ctx.function_call_expr());
|
|
178
198
|
this.setResult(ctx, result);
|
|
179
199
|
};
|
|
180
200
|
this.visitFunction_call_expr = (ctx) => {
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this.
|
|
187
|
-
passedNetNamespace = this.getResult(netNameSpaceExpr);
|
|
188
|
-
}
|
|
189
|
-
let currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
190
|
-
if (ctx.trailer_expr().length > 0) {
|
|
191
|
-
if (!currentReference.found) {
|
|
192
|
-
this.throwWithContext(ctx, "Unknown function name: " + atomId);
|
|
193
|
-
}
|
|
194
|
-
currentReference.trailers = [];
|
|
195
|
-
ctx.trailer_expr().forEach(item => {
|
|
196
|
-
const itemValue = item.getText();
|
|
197
|
-
if (item.OPEN_PAREN() && item.CLOSE_PAREN()) {
|
|
198
|
-
let parameters = [];
|
|
199
|
-
const ctxParameters = item.parameters();
|
|
200
|
-
if (ctxParameters) {
|
|
201
|
-
this.visit(ctxParameters);
|
|
202
|
-
parameters = this.getResult(ctxParameters);
|
|
203
|
-
}
|
|
204
|
-
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
205
|
-
try {
|
|
206
|
-
const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
|
|
207
|
-
currentReference = {
|
|
208
|
-
found: true,
|
|
209
|
-
value: functionResult,
|
|
210
|
-
type: (functionResult instanceof ClassComponent_js_1.ClassComponent) ?
|
|
211
|
-
'instance' : 'value',
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
this.throwWithContext(ctx, err);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
currentReference.trailers.push(itemValue);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
201
|
+
const ctxParams = this.getResult(ctx);
|
|
202
|
+
const { keepReference = false } = ctxParams ?? {};
|
|
203
|
+
this.handleFunctionCall(ctx);
|
|
204
|
+
if (!keepReference) {
|
|
205
|
+
const functionResultReference = this.getResult(ctx);
|
|
206
|
+
this.setResult(ctx, functionResultReference.value);
|
|
222
207
|
}
|
|
223
|
-
this.setResult(ctx, currentReference.value);
|
|
224
208
|
};
|
|
225
209
|
this.visitValue_expr = (ctx) => {
|
|
226
210
|
const sign = ctx.Minus() ? -1 : 1;
|
|
@@ -233,10 +217,10 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
233
217
|
let result = null;
|
|
234
218
|
if (ctxIntegerValue || ctxDecimalValue || ctxNumericValue) {
|
|
235
219
|
if (ctxIntegerValue) {
|
|
236
|
-
result = (0,
|
|
220
|
+
result = (0, utils_js_2.resolveToNumericValue)((new big_js_1.Big(ctxIntegerValue.getText())).mul(new big_js_1.Big(sign)));
|
|
237
221
|
}
|
|
238
222
|
else if (ctxDecimalValue) {
|
|
239
|
-
result = (0,
|
|
223
|
+
result = (0, utils_js_2.resolveToNumericValue)((new big_js_1.Big(ctxDecimalValue.getText())).mul(new big_js_1.Big(sign)));
|
|
240
224
|
}
|
|
241
225
|
else if (ctxNumericValue) {
|
|
242
226
|
const textExtra = ctx.Minus() ? '-' : '';
|
|
@@ -270,12 +254,10 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
270
254
|
const ctxValueExpr = ctx.value_expr();
|
|
271
255
|
const ctxAtomExpr = ctx.atom_expr();
|
|
272
256
|
if (ctxValueExpr) {
|
|
273
|
-
this.
|
|
274
|
-
value = this.getResult(ctxValueExpr);
|
|
257
|
+
value = this.visitResult(ctxValueExpr);
|
|
275
258
|
}
|
|
276
259
|
else if (ctxAtomExpr) {
|
|
277
|
-
this.
|
|
278
|
-
const reference = this.getResult(ctxAtomExpr);
|
|
260
|
+
const reference = this.visitResult(ctxAtomExpr);
|
|
279
261
|
if (!reference.found) {
|
|
280
262
|
value = new types_js_1.UndeclaredReference(reference);
|
|
281
263
|
}
|
|
@@ -318,19 +300,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
318
300
|
const keywordAssignmentExpressions = ctx.keyword_assignment_expr();
|
|
319
301
|
const returnList = [];
|
|
320
302
|
dataExpressions.forEach((item, index) => {
|
|
321
|
-
this.
|
|
322
|
-
const value = this.getResult(item);
|
|
303
|
+
const value = this.visitResult(item);
|
|
323
304
|
returnList.push(['position', index, value]);
|
|
324
305
|
});
|
|
325
306
|
keywordAssignmentExpressions.forEach((item) => {
|
|
326
|
-
this.
|
|
327
|
-
const [key, value] = this.getResult(item);
|
|
307
|
+
const [key, value] = this.visitResult(item);
|
|
328
308
|
returnList.push(['keyword', key, value]);
|
|
329
309
|
});
|
|
330
310
|
this.setResult(ctx, returnList);
|
|
331
311
|
};
|
|
332
312
|
this.visitImport_expr = (ctx) => {
|
|
333
|
-
throw new
|
|
313
|
+
throw new utils_js_2.RuntimeExecutionError("Cannot parse imports here", ctx);
|
|
334
314
|
};
|
|
335
315
|
this.visitFunction_return_expr = (ctx) => {
|
|
336
316
|
const executor = this.getExecutor();
|
|
@@ -342,33 +322,34 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
342
322
|
executor.returnValue = returnValue;
|
|
343
323
|
this.setResult(ctx, returnValue);
|
|
344
324
|
};
|
|
345
|
-
this.
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
325
|
+
this.visitFlow_expressions = (ctx) => {
|
|
326
|
+
if (ctx.if_expr()) {
|
|
327
|
+
this.visit(ctx.if_expr());
|
|
328
|
+
}
|
|
329
|
+
else if (ctx.while_expr()) {
|
|
330
|
+
this.visit(ctx.while_expr());
|
|
331
|
+
}
|
|
332
|
+
else if (ctx.for_expr()) {
|
|
333
|
+
this.visit(ctx.for_expr());
|
|
334
|
+
}
|
|
335
|
+
else if (ctx.Break() || ctx.Continue()) {
|
|
336
|
+
const breakContext = this.getExecutor().getBreakContext();
|
|
337
|
+
const currentResult = this.getResult(breakContext) ?? {};
|
|
338
|
+
this.setResult(breakContext, {
|
|
339
|
+
...currentResult,
|
|
340
|
+
breakSignal: true,
|
|
341
|
+
continueSignal: ctx.Continue() ? true : false
|
|
342
|
+
});
|
|
343
|
+
}
|
|
361
344
|
};
|
|
362
345
|
this.visitArray_expr = (ctx) => {
|
|
363
346
|
const array = ctx.data_expr().map(item => {
|
|
364
|
-
this.
|
|
365
|
-
return this.getResult(item);
|
|
347
|
+
return this.visitResult(item);
|
|
366
348
|
});
|
|
367
349
|
this.setResult(ctx, array);
|
|
368
350
|
};
|
|
369
351
|
this.visitArrayExpr = (ctx) => {
|
|
370
|
-
this.
|
|
371
|
-
this.setResult(ctx, this.getResult(ctx.array_expr()));
|
|
352
|
+
this.setResult(ctx, this.visitResult(ctx.array_expr()));
|
|
372
353
|
};
|
|
373
354
|
this.visitRoundedBracketsExpr = (ctx) => {
|
|
374
355
|
const ctxDataExpr = ctx.data_expr();
|
|
@@ -384,7 +365,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
384
365
|
scope.sequence.push([
|
|
385
366
|
ExecutionScope_js_1.SequenceAction.At, scope.componentRoot, scope.currentPin
|
|
386
367
|
]);
|
|
387
|
-
scope.
|
|
368
|
+
scope.setVariable(globals_js_1.GlobalDocumentName, {});
|
|
388
369
|
this.setupBuiltInFunctions(this.startingContext);
|
|
389
370
|
this.executionStack = [this.startingContext];
|
|
390
371
|
this.startingContext.resolveNet =
|
|
@@ -459,8 +440,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
459
440
|
if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
|
|
460
441
|
this.throwWithContext(ctx, "Invalid assignment expression!");
|
|
461
442
|
}
|
|
462
|
-
this.
|
|
463
|
-
const reference = this.getResult(ctx);
|
|
443
|
+
const reference = this.visitResult(ctx);
|
|
464
444
|
const { trailers = [] } = reference;
|
|
465
445
|
const undefinedParentWithTrailers = trailers.length > 0
|
|
466
446
|
&& reference.parentValue === undefined;
|
|
@@ -469,6 +449,57 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
469
449
|
}
|
|
470
450
|
return reference;
|
|
471
451
|
}
|
|
452
|
+
handleFunctionCall(ctx) {
|
|
453
|
+
const executor = this.getExecutor();
|
|
454
|
+
const atomId = ctx.ID().getText();
|
|
455
|
+
let passedNetNamespace = null;
|
|
456
|
+
const netNameSpaceExpr = ctx.net_namespace_expr();
|
|
457
|
+
if (netNameSpaceExpr) {
|
|
458
|
+
passedNetNamespace = this.visitResult(netNameSpaceExpr);
|
|
459
|
+
}
|
|
460
|
+
let currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
461
|
+
if (ctx.trailer_expr().length > 0) {
|
|
462
|
+
if (!currentReference.found) {
|
|
463
|
+
this.throwWithContext(ctx, "Unknown function name: " + atomId);
|
|
464
|
+
}
|
|
465
|
+
currentReference.trailers = [];
|
|
466
|
+
ctx.trailer_expr().forEach(item => {
|
|
467
|
+
if (item.OPEN_PAREN() && item.CLOSE_PAREN()) {
|
|
468
|
+
let parameters = [];
|
|
469
|
+
const ctxParameters = item.parameters();
|
|
470
|
+
if (ctxParameters) {
|
|
471
|
+
parameters = this.visitResult(ctxParameters);
|
|
472
|
+
}
|
|
473
|
+
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
474
|
+
try {
|
|
475
|
+
const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
|
|
476
|
+
if ((0, utils_js_1.isReference)(functionResult)) {
|
|
477
|
+
currentReference = functionResult;
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
currentReference = new types_js_1.AnyReference({
|
|
481
|
+
found: true,
|
|
482
|
+
value: functionResult,
|
|
483
|
+
trailers: [],
|
|
484
|
+
type: (functionResult instanceof ClassComponent_js_1.ClassComponent) ?
|
|
485
|
+
globals_js_1.ReferenceTypes.instance : globals_js_1.ReferenceTypes.value,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
catch (err) {
|
|
490
|
+
this.throwWithContext(ctx, err);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
currentReference.trailers.push(item.ID().getText());
|
|
495
|
+
currentReference = this.getExecutor().resolveTrailers(currentReference.type, (currentReference.parentValue !== undefined)
|
|
496
|
+
? currentReference.parentValue
|
|
497
|
+
: currentReference.value, currentReference.trailers);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
this.setResult(ctx, currentReference);
|
|
502
|
+
}
|
|
472
503
|
setResult(ctx, value) {
|
|
473
504
|
this.resultData.set(ctx, value);
|
|
474
505
|
}
|
|
@@ -523,7 +554,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
523
554
|
}
|
|
524
555
|
catch (err) {
|
|
525
556
|
if (ctx != null) {
|
|
526
|
-
throw new
|
|
557
|
+
throw new utils_js_2.RuntimeExecutionError("An error occurred while importing file", ctx);
|
|
527
558
|
}
|
|
528
559
|
else {
|
|
529
560
|
this.log('An error occurred while importing file:', err.message);
|
|
@@ -539,7 +570,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
539
570
|
}
|
|
540
571
|
}
|
|
541
572
|
if (errorMessage !== null && ctx) {
|
|
542
|
-
throw new
|
|
573
|
+
throw new utils_js_2.RuntimeExecutionError(errorMessage, ctx);
|
|
543
574
|
}
|
|
544
575
|
const newImportedFile = {
|
|
545
576
|
id: name.trim(),
|
|
@@ -555,12 +586,13 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
555
586
|
const tmpFuncArg = funcDefinedParameters[i];
|
|
556
587
|
if (i < passedInParameters.length) {
|
|
557
588
|
const tmpPassedInArgs = passedInParameters[i];
|
|
589
|
+
const argValue = (0, utils_js_1.unwrapValue)(tmpPassedInArgs[2]);
|
|
558
590
|
if (tmpPassedInArgs[0] === 'position') {
|
|
559
591
|
const variableName = tmpFuncArg[0];
|
|
560
592
|
executor.log('set variable in scope, var name: ', variableName);
|
|
561
|
-
executor.scope.
|
|
562
|
-
if (
|
|
563
|
-
const component =
|
|
593
|
+
executor.scope.setVariable(variableName, argValue);
|
|
594
|
+
if (argValue instanceof ClassComponent_js_1.ClassComponent) {
|
|
595
|
+
const component = argValue;
|
|
564
596
|
for (const [pinNumber, net] of component.pinNets) {
|
|
565
597
|
executor.scope.setNet(component, pinNumber, net);
|
|
566
598
|
}
|
|
@@ -569,14 +601,14 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
569
601
|
else if (tmpPassedInArgs[0] === 'keyword') {
|
|
570
602
|
const variableName = tmpPassedInArgs[1];
|
|
571
603
|
executor.log('set variable in scope, var name: ', variableName);
|
|
572
|
-
executor.scope.
|
|
604
|
+
executor.scope.setVariable(variableName, argValue);
|
|
573
605
|
}
|
|
574
606
|
}
|
|
575
607
|
else if (tmpFuncArg.length === 3) {
|
|
576
608
|
const variableName = tmpFuncArg[0];
|
|
577
609
|
const defaultValue = tmpFuncArg[2];
|
|
578
610
|
executor.log('set variable in scope, var name: ', variableName);
|
|
579
|
-
executor.scope.
|
|
611
|
+
executor.scope.setVariable(variableName, defaultValue);
|
|
580
612
|
}
|
|
581
613
|
else {
|
|
582
614
|
throw `Invalid arguments got: ` + passedInParameters;
|
|
@@ -646,7 +678,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
646
678
|
return value.slice(1, value.length - 1);
|
|
647
679
|
}
|
|
648
680
|
throwWithContext(context, messageOrError) {
|
|
649
|
-
(0,
|
|
681
|
+
(0, utils_js_2.throwWithContext)(context, messageOrError);
|
|
650
682
|
}
|
|
651
683
|
validateType(value, context, validateFunction, expectedType) {
|
|
652
684
|
if (value === undefined) {
|
|
@@ -654,7 +686,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
654
686
|
}
|
|
655
687
|
const result = validateFunction(value);
|
|
656
688
|
if (!result) {
|
|
657
|
-
throw new
|
|
689
|
+
throw new utils_js_2.RuntimeExecutionError(`Invalid ${expectedType}`, context);
|
|
658
690
|
}
|
|
659
691
|
return result;
|
|
660
692
|
}
|