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
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -25,7 +25,6 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
25
25
|
this.acceptedDirections = [types_js_1.Direction.Up, types_js_1.Direction.Down,
|
|
26
26
|
types_js_1.Direction.Right, types_js_1.Direction.Left];
|
|
27
27
|
this.resultData = new Map;
|
|
28
|
-
this.paramData = new Map;
|
|
29
28
|
this.pinTypesList = [
|
|
30
29
|
PinTypes_js_1.PinTypes.Any,
|
|
31
30
|
PinTypes_js_1.PinTypes.Input,
|
|
@@ -49,22 +48,22 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
49
48
|
}
|
|
50
49
|
const result = this.runExpressions(this.getExecutor(), ctx.expression());
|
|
51
50
|
this.setResult(ctx, result);
|
|
52
|
-
this.getExecutor().
|
|
51
|
+
this.getExecutor().closeOpenPathBlocks();
|
|
53
52
|
this.log('===', 'end', '===');
|
|
54
53
|
};
|
|
55
54
|
this.visitAssignment_expr = (ctx) => {
|
|
56
55
|
const ctxAtom = ctx.atom_expr();
|
|
57
|
-
const
|
|
56
|
+
const ctxFuncCallRef = ctx.function_call_expr();
|
|
58
57
|
let leftSideReference;
|
|
59
58
|
if (ctxAtom) {
|
|
60
59
|
leftSideReference = this.getReference(ctx.atom_expr());
|
|
61
60
|
}
|
|
62
|
-
else if (
|
|
63
|
-
|
|
61
|
+
else if (ctxFuncCallRef) {
|
|
62
|
+
this.setResult(ctxFuncCallRef, { keepReference: true });
|
|
63
|
+
leftSideReference = this.visitResult(ctxFuncCallRef);
|
|
64
64
|
}
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const rhsValue = (0, utils_js_1.prepareValue)(dataValue);
|
|
65
|
+
const rhsCtxResult = this.visitResult(ctx.data_expr());
|
|
66
|
+
const rhsValue = (0, utils_js_1.unwrapValue)(rhsCtxResult);
|
|
68
67
|
const trailers = leftSideReference.trailers ?? [];
|
|
69
68
|
const sequenceParts = [];
|
|
70
69
|
if (trailers.length === 0) {
|
|
@@ -107,9 +106,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
107
106
|
};
|
|
108
107
|
this.visitOperator_assignment_expr = (ctx) => {
|
|
109
108
|
const reference = this.getReference(ctx.atom_expr());
|
|
110
|
-
const
|
|
111
|
-
this.visit(ctxDataExpr);
|
|
112
|
-
const value = this.getResult(ctxDataExpr);
|
|
109
|
+
const value = this.visitResult(ctx.data_expr());
|
|
113
110
|
if (!reference.found) {
|
|
114
111
|
this.throwWithContext(ctx, 'Undefined reference: ' + reference.name);
|
|
115
112
|
}
|
|
@@ -201,55 +198,13 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
201
198
|
this.setResult(ctx, result);
|
|
202
199
|
};
|
|
203
200
|
this.visitFunction_call_expr = (ctx) => {
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
-
passedNetNamespace = this.getResult(netNameSpaceExpr);
|
|
211
|
-
}
|
|
212
|
-
let currentReference = executor.resolveVariable(this.executionStack, atomId);
|
|
213
|
-
if (ctx.trailer_expr().length > 0) {
|
|
214
|
-
if (!currentReference.found) {
|
|
215
|
-
this.throwWithContext(ctx, "Unknown function name: " + atomId);
|
|
216
|
-
}
|
|
217
|
-
currentReference.trailers = [];
|
|
218
|
-
ctx.trailer_expr().forEach(item => {
|
|
219
|
-
const itemValue = item.getText();
|
|
220
|
-
if (item.OPEN_PAREN() && item.CLOSE_PAREN()) {
|
|
221
|
-
let parameters = [];
|
|
222
|
-
const ctxParameters = item.parameters();
|
|
223
|
-
if (ctxParameters) {
|
|
224
|
-
this.visit(ctxParameters);
|
|
225
|
-
parameters = this.getResult(ctxParameters);
|
|
226
|
-
}
|
|
227
|
-
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
228
|
-
try {
|
|
229
|
-
const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
|
|
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
|
-
}
|
|
242
|
-
}
|
|
243
|
-
catch (err) {
|
|
244
|
-
this.throwWithContext(ctx, err);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
currentReference.trailers.push(itemValue);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
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);
|
|
251
207
|
}
|
|
252
|
-
this.setResult(ctx, currentReference);
|
|
253
208
|
};
|
|
254
209
|
this.visitValue_expr = (ctx) => {
|
|
255
210
|
const sign = ctx.Minus() ? -1 : 1;
|
|
@@ -299,12 +254,10 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
299
254
|
const ctxValueExpr = ctx.value_expr();
|
|
300
255
|
const ctxAtomExpr = ctx.atom_expr();
|
|
301
256
|
if (ctxValueExpr) {
|
|
302
|
-
this.
|
|
303
|
-
value = this.getResult(ctxValueExpr);
|
|
257
|
+
value = this.visitResult(ctxValueExpr);
|
|
304
258
|
}
|
|
305
259
|
else if (ctxAtomExpr) {
|
|
306
|
-
this.
|
|
307
|
-
const reference = this.getResult(ctxAtomExpr);
|
|
260
|
+
const reference = this.visitResult(ctxAtomExpr);
|
|
308
261
|
if (!reference.found) {
|
|
309
262
|
value = new types_js_1.UndeclaredReference(reference);
|
|
310
263
|
}
|
|
@@ -369,33 +322,34 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
369
322
|
executor.returnValue = returnValue;
|
|
370
323
|
this.setResult(ctx, returnValue);
|
|
371
324
|
};
|
|
372
|
-
this.
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
+
}
|
|
388
344
|
};
|
|
389
345
|
this.visitArray_expr = (ctx) => {
|
|
390
346
|
const array = ctx.data_expr().map(item => {
|
|
391
|
-
this.
|
|
392
|
-
return this.getResult(item);
|
|
347
|
+
return this.visitResult(item);
|
|
393
348
|
});
|
|
394
349
|
this.setResult(ctx, array);
|
|
395
350
|
};
|
|
396
351
|
this.visitArrayExpr = (ctx) => {
|
|
397
|
-
this.
|
|
398
|
-
this.setResult(ctx, this.getResult(ctx.array_expr()));
|
|
352
|
+
this.setResult(ctx, this.visitResult(ctx.array_expr()));
|
|
399
353
|
};
|
|
400
354
|
this.visitRoundedBracketsExpr = (ctx) => {
|
|
401
355
|
const ctxDataExpr = ctx.data_expr();
|
|
@@ -495,6 +449,57 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
495
449
|
}
|
|
496
450
|
return reference;
|
|
497
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
|
+
}
|
|
498
503
|
setResult(ctx, value) {
|
|
499
504
|
this.resultData.set(ctx, value);
|
|
500
505
|
}
|
|
@@ -581,7 +586,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
581
586
|
const tmpFuncArg = funcDefinedParameters[i];
|
|
582
587
|
if (i < passedInParameters.length) {
|
|
583
588
|
const tmpPassedInArgs = passedInParameters[i];
|
|
584
|
-
const argValue = (0, utils_js_1.
|
|
589
|
+
const argValue = (0, utils_js_1.unwrapValue)(tmpPassedInArgs[2]);
|
|
585
590
|
if (tmpPassedInArgs[0] === 'position') {
|
|
586
591
|
const variableName = tmpFuncArg[0];
|
|
587
592
|
executor.log('set variable in scope, var name: ', variableName);
|
|
@@ -664,7 +669,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
664
669
|
const executionLevel = currentExecutionContext.executionLevel;
|
|
665
670
|
const executionContextNamespace = currentExecutionContext.namespace
|
|
666
671
|
+ executionContextName + ".";
|
|
667
|
-
const newExecutor = new execute_js_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.
|
|
672
|
+
const newExecutor = new execute_js_1.ExecutionContext(executionContextName, executionContextNamespace, netNamespace, executionLevel + 1, this.getExecutor().scope.scopeLevel + 1, currentExecutionContext.silent, currentExecutionContext.logger, currentExecutionContext.warnings, parentContext);
|
|
668
673
|
executionStack.push(newExecutor);
|
|
669
674
|
this.setupDefinedParameters(funcDefinedParameters, passedInParameters, newExecutor);
|
|
670
675
|
return newExecutor;
|