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.
Files changed (41) hide show
  1. package/dist/cjs/BaseVisitor.js +78 -51
  2. package/dist/cjs/antlr/CircuitScriptParser.js +1059 -949
  3. package/dist/cjs/builtinMethods.js +5 -1
  4. package/dist/cjs/execute.js +43 -22
  5. package/dist/cjs/globals.js +7 -1
  6. package/dist/cjs/layout.js +50 -16
  7. package/dist/cjs/objects/ExecutionScope.js +3 -0
  8. package/dist/cjs/objects/Net.js +1 -0
  9. package/dist/cjs/objects/ParamDefinition.js +3 -0
  10. package/dist/cjs/objects/types.js +19 -10
  11. package/dist/cjs/render.js +48 -6
  12. package/dist/cjs/utils.js +16 -1
  13. package/dist/cjs/visitor.js +69 -52
  14. package/dist/esm/BaseVisitor.js +72 -45
  15. package/dist/esm/antlr/CircuitScriptParser.js +1052 -944
  16. package/dist/esm/antlr/CircuitScriptVisitor.js +4 -2
  17. package/dist/esm/builtinMethods.js +6 -2
  18. package/dist/esm/execute.js +43 -22
  19. package/dist/esm/globals.js +6 -0
  20. package/dist/esm/layout.js +53 -17
  21. package/dist/esm/objects/ExecutionScope.js +3 -0
  22. package/dist/esm/objects/Net.js +1 -0
  23. package/dist/esm/objects/ParamDefinition.js +4 -1
  24. package/dist/esm/objects/types.js +21 -15
  25. package/dist/esm/render.js +49 -7
  26. package/dist/esm/utils.js +13 -0
  27. package/dist/esm/visitor.js +57 -40
  28. package/dist/types/BaseVisitor.d.ts +2 -2
  29. package/dist/types/antlr/CircuitScriptParser.d.ts +99 -83
  30. package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -4
  31. package/dist/types/execute.d.ts +1 -0
  32. package/dist/types/globals.d.ts +5 -0
  33. package/dist/types/layout.d.ts +16 -3
  34. package/dist/types/objects/ExecutionScope.d.ts +15 -3
  35. package/dist/types/objects/Net.d.ts +1 -0
  36. package/dist/types/objects/types.d.ts +25 -18
  37. package/dist/types/utils.d.ts +3 -1
  38. package/dist/types/visitor.d.ts +3 -2
  39. package/package.json +1 -1
  40. /package/dist/libs/{lib.cst → std.cst} +0 -0
  41. /package/libs/{lib.cst → std.cst} +0 -0
@@ -7,9 +7,10 @@ const PinDefinition_js_1 = require("./objects/PinDefinition.js");
7
7
  const PinTypes_js_1 = require("./objects/PinTypes.js");
8
8
  const types_js_1 = require("./objects/types.js");
9
9
  const globals_js_1 = require("./globals.js");
10
+ const utils_js_1 = require("./utils.js");
10
11
  const draw_symbols_js_1 = require("./draw_symbols.js");
11
12
  const BaseVisitor_js_1 = require("./BaseVisitor.js");
12
- const utils_js_1 = require("./utils.js");
13
+ const utils_js_2 = require("./utils.js");
13
14
  const helpers_js_1 = require("./helpers.js");
14
15
  const Frame_js_1 = require("./objects/Frame.js");
15
16
  class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
@@ -31,7 +32,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
31
32
  value = result;
32
33
  }
33
34
  else {
34
- throw new utils_js_1.RuntimeExecutionError("Invalid value for pin", ctx);
35
+ throw new utils_js_2.RuntimeExecutionError("Invalid value for pin", ctx);
35
36
  }
36
37
  this.setResult(ctx, value);
37
38
  };
@@ -55,7 +56,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
55
56
  });
56
57
  }
57
58
  catch (err) {
58
- throw new utils_js_1.RuntimeExecutionError(err.message, ctx);
59
+ throw new utils_js_2.RuntimeExecutionError(err.message, ctx);
59
60
  }
60
61
  });
61
62
  return this.getExecutor().getCurrentPoint();
@@ -87,39 +88,55 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
87
88
  }
88
89
  this.setResult(ctx, componentPin);
89
90
  };
90
- this.visitPath_blocks = (ctx) => {
91
- const blocks = ctx.path_block_inner();
92
- let blockIndex = 0;
91
+ this.visitPath_block = (ctx) => {
93
92
  let blockType = globals_js_1.BlockTypes.Branch;
94
- let prevBlockType = null;
95
- blocks.forEach((block, index) => {
96
- if (block.Branch()) {
97
- blockType = globals_js_1.BlockTypes.Branch;
98
- }
99
- else if (block.Join()) {
100
- blockType = globals_js_1.BlockTypes.Join;
101
- }
102
- else if (block.Parallel()) {
103
- blockType = globals_js_1.BlockTypes.Parallel;
104
- }
105
- else if (block.Point()) {
106
- blockType = globals_js_1.BlockTypes.Point;
93
+ if (ctx.Branch()) {
94
+ blockType = globals_js_1.BlockTypes.Branch;
95
+ }
96
+ else if (ctx.Join()) {
97
+ blockType = globals_js_1.BlockTypes.Join;
98
+ }
99
+ else if (ctx.Parallel()) {
100
+ blockType = globals_js_1.BlockTypes.Parallel;
101
+ }
102
+ else if (ctx.Point()) {
103
+ blockType = globals_js_1.BlockTypes.Point;
104
+ }
105
+ const scope = this.getScope();
106
+ const executor = this.getExecutor();
107
+ const indentLevel = scope.indentLevel;
108
+ if (scope.blockStack.has(indentLevel)) {
109
+ const blockStackEntry = scope.blockStack.get(indentLevel);
110
+ if (blockStackEntry.type !== blockType) {
111
+ executor.exitBlocks();
107
112
  }
108
- if (prevBlockType !== blockType) {
109
- if (index > 0) {
110
- this.getExecutor().exitBlocks();
111
- }
112
- this.getExecutor().enterBlocks(blockType);
113
- blockIndex = 0;
113
+ }
114
+ if (!scope.blockStack.has(indentLevel)) {
115
+ executor.enterBlocks(blockType);
116
+ }
117
+ const blockStackEntry = scope.blockStack.get(indentLevel);
118
+ const { current_index } = blockStackEntry;
119
+ executor.enterBlock(current_index);
120
+ this.visit(ctx.expressions_block());
121
+ executor.exitBlock(current_index);
122
+ blockStackEntry.current_index++;
123
+ };
124
+ this.visitGraph_expressions = (ctx) => {
125
+ if (ctx.path_block() === null) {
126
+ const scope = this.getScope();
127
+ const indentLevel = scope.indentLevel;
128
+ if (scope.blockStack.has(indentLevel)) {
129
+ this.getExecutor().exitBlocks();
114
130
  }
115
- this.getExecutor().enterBlock(blockIndex);
116
- this.visit(block);
117
- this.getExecutor().exitBlock(blockIndex);
118
- blockIndex += 1;
119
- prevBlockType = blockType;
120
- });
121
- this.getExecutor().exitBlocks();
122
- return this.getExecutor().getCurrentPoint();
131
+ }
132
+ const ctxPathBlock = ctx.path_block();
133
+ const ctxNotPathBlock = ctx.graph_linear_expression();
134
+ if (ctxPathBlock) {
135
+ this.visit(ctxPathBlock);
136
+ }
137
+ if (ctxNotPathBlock) {
138
+ this.visit(ctxNotPathBlock);
139
+ }
123
140
  };
124
141
  this.visitCreate_component_expr = (ctx) => {
125
142
  const scope = this.getScope();
@@ -155,13 +172,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
155
172
  break;
156
173
  case 'display':
157
174
  if (didDefineArrangeProp) {
158
- throw new utils_js_1.RuntimeExecutionError("arrange property has already been defined", ctx);
175
+ throw new utils_js_2.RuntimeExecutionError("arrange property has already been defined", ctx);
159
176
  }
160
177
  didDefineDisplayProp = true;
161
178
  break;
162
179
  case 'arrange':
163
180
  if (didDefineDisplayProp) {
164
- throw new utils_js_1.RuntimeExecutionError("display property already defined", ctx);
181
+ throw new utils_js_2.RuntimeExecutionError("display property already defined", ctx);
165
182
  }
166
183
  didDefineArrangeProp = true;
167
184
  break;
@@ -182,7 +199,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
182
199
  this.validateBoolean(value, ctx);
183
200
  }
184
201
  else {
185
- throw new utils_js_1.RuntimeExecutionError("Invalid value for 'copy' property", ctx);
202
+ throw new utils_js_2.RuntimeExecutionError("Invalid value for 'copy' property", ctx);
186
203
  }
187
204
  break;
188
205
  }
@@ -192,7 +209,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
192
209
  if (keyName === 'arrange') {
193
210
  const [sideKeyCtx, sideKeyName] = path[1];
194
211
  if (globals_js_1.ValidPinSides.indexOf(sideKeyName) === -1) {
195
- throw new utils_js_1.RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx);
212
+ throw new utils_js_2.RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx);
196
213
  }
197
214
  else {
198
215
  if (path.length === 2 && value instanceof ParamDefinition_js_1.NumericValue) {
@@ -203,12 +220,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
203
220
  const goodBlank = value.length === 1 &&
204
221
  value[0] instanceof ParamDefinition_js_1.NumericValue;
205
222
  if (!goodBlank) {
206
- throw new utils_js_1.RuntimeExecutionError(`Invalid blank specifier`, ctx);
223
+ throw new utils_js_2.RuntimeExecutionError(`Invalid blank specifier`, ctx);
207
224
  }
208
225
  }
209
226
  else {
210
227
  if (!(value instanceof ParamDefinition_js_1.NumericValue)) {
211
- throw new utils_js_1.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
228
+ throw new utils_js_2.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
212
229
  }
213
230
  else {
214
231
  checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
@@ -237,7 +254,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
237
254
  if (value.length === 2) {
238
255
  const [pinType,] = value;
239
256
  if (pinType instanceof types_js_1.UndeclaredReference) {
240
- throw new utils_js_1.RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx);
257
+ throw new utils_js_2.RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx);
241
258
  }
242
259
  }
243
260
  }
@@ -298,7 +315,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
298
315
  if (ctxId !== null) {
299
316
  const varName = ctxId.getText();
300
317
  paramIds.push(varName);
301
- this.getScope().variables.set(varName, {});
318
+ this.getScope().setVariable(varName, {});
302
319
  }
303
320
  const executor = this.getExecutor();
304
321
  const stack = [...this.executionStack];
@@ -308,7 +325,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
308
325
  variables.forEach((value, key) => {
309
326
  obj[key] = value;
310
327
  });
311
- executor.scope.variables.set(paramIds[0], obj);
328
+ executor.scope.setVariable(paramIds[0], obj);
312
329
  }
313
330
  const currentStack = this.executionStack.splice(0);
314
331
  this.executionStack.push(...stack);
@@ -389,7 +406,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
389
406
  };
390
407
  this.visitGraphicForExpr = (ctx) => {
391
408
  const forVariableNames = ctx.ID().map(item => item.getText());
392
- const listItems = this.visitResult(ctx.data_expr());
409
+ const listItems = (0, utils_js_1.prepareValue)(this.visitResult(ctx.data_expr()));
393
410
  let keepLooping = true;
394
411
  let counter = 0;
395
412
  let allCommands = [];
@@ -400,7 +417,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
400
417
  useValueArray = [useValueArray];
401
418
  }
402
419
  useValueArray.forEach((value, index) => {
403
- this.getScope().variables.set(forVariableNames[index], value);
420
+ this.getScope().setVariable(forVariableNames[index], value);
404
421
  });
405
422
  const commands = this.visitResult(ctx.graphic_expressions_block());
406
423
  allCommands = allCommands.concat(commands);
@@ -531,6 +548,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
531
548
  const ctxAssignmentExpr = ctx.assignment_expr();
532
549
  if (ctxDataExpr) {
533
550
  component = this.visitResult(ctxDataExpr);
551
+ component = (0, utils_js_1.prepareValue)(component);
534
552
  componentCtx = ctxDataExpr;
535
553
  if (component === null || component === undefined) {
536
554
  this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
@@ -822,15 +840,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
822
840
  const executor = this.getExecutor();
823
841
  executor.log('entering at block');
824
842
  this.visit(ctx.at_component_expr());
825
- const currentComponent = executor.scope.currentComponent;
826
- const currentPin = executor.scope.currentPin;
843
+ const [currentComponent, currentPin] = executor.getCurrentPoint();
827
844
  executor.scope.indentLevel += 1;
828
845
  ctx.at_block_expressions().forEach(expression => {
829
846
  this.visit(expression);
830
847
  });
831
848
  executor.scope.indentLevel -= 1;
832
- executor.scope.currentComponent = currentComponent;
833
- executor.scope.currentPin = currentPin;
849
+ executor.scope.setCurrent(currentComponent, currentPin);
834
850
  executor.log('leaving at block');
835
851
  };
836
852
  this.visitAt_block_pin_expression_simple = (ctx) => {
@@ -893,7 +909,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
893
909
  pointValue = resultValue;
894
910
  }
895
911
  else {
896
- throw new utils_js_1.RuntimeExecutionError('Invalid value for point');
912
+ throw new utils_js_2.RuntimeExecutionError('Invalid value for point');
897
913
  }
898
914
  }
899
915
  else if (ID) {
@@ -1012,7 +1028,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1012
1028
  this.visitFor_expr = (ctx) => {
1013
1029
  this.log('in for loop');
1014
1030
  const forVariableNames = ctx.ID().map(item => item.getText());
1015
- const listItems = this.visitResult(ctx.data_expr());
1031
+ let listItems = this.visitResult(ctx.data_expr());
1032
+ listItems = (0, utils_js_1.prepareValue)(listItems);
1016
1033
  this.getExecutor().addBreakContext(ctx);
1017
1034
  let keepLooping = true;
1018
1035
  let counter = 0;
@@ -1023,7 +1040,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1023
1040
  useValueArray = [useValueArray];
1024
1041
  }
1025
1042
  useValueArray.forEach((value, index) => {
1026
- this.getScope().variables.set(forVariableNames[index], value);
1043
+ this.getScope().setVariable(forVariableNames[index], value);
1027
1044
  });
1028
1045
  this.visit(ctx.expressions_block());
1029
1046
  keepLooping = true;
@@ -1088,7 +1105,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1088
1105
  const portName = component.parameters.get(globals_js_1.ParamKeys.net_name);
1089
1106
  const modulePinId = modulePinMapping.get(portName);
1090
1107
  pinIdToPortMap.set(modulePinId, component);
1091
- const portType = (0, utils_js_1.getPortType)(component);
1108
+ const portType = (0, utils_js_2.getPortType)(component);
1092
1109
  const tmpPin = moduleComponent.pins.get(modulePinId);
1093
1110
  tmpPin.pinType = portType;
1094
1111
  }
@@ -6,8 +6,9 @@ import { Logger } from "./logger.js";
6
6
  import { ClassComponent } from "./objects/ClassComponent.js";
7
7
  import { NumberOperator, NumericValue, PercentageValue } from "./objects/ParamDefinition.js";
8
8
  import { PinTypes } from "./objects/PinTypes.js";
9
- import { Direction, UndeclaredReference } from "./objects/types.js";
10
- import { DoubleDelimiter1, GlobalDocumentName, ReferenceTypes } from './globals.js';
9
+ import { Direction, AnyReference, UndeclaredReference } from "./objects/types.js";
10
+ import { ComponentTypes, DoubleDelimiter1, GlobalDocumentName, ReferenceTypes } from './globals.js';
11
+ import { isReference, prepareValue } 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';
@@ -47,7 +48,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
47
48
  scope.sequence.push([
48
49
  SequenceAction.At, scope.componentRoot, scope.currentPin
49
50
  ]);
50
- scope.variables.set(GlobalDocumentName, {});
51
+ scope.setVariable(GlobalDocumentName, {});
51
52
  this.setupBuiltInFunctions(this.startingContext);
52
53
  this.executionStack = [this.startingContext];
53
54
  this.startingContext.resolveNet =
@@ -127,37 +128,61 @@ export class BaseVisitor extends CircuitScriptVisitor {
127
128
  }
128
129
  const result = this.runExpressions(this.getExecutor(), ctx.expression());
129
130
  this.setResult(ctx, result);
131
+ this.getExecutor().closeAllBlocks();
130
132
  this.log('===', 'end', '===');
131
133
  };
132
134
  visitAssignment_expr = (ctx) => {
133
- const reference = this.getReference(ctx.atom_expr());
135
+ const ctxAtom = ctx.atom_expr();
136
+ const ctxFuncCall = ctx.function_call_expr();
137
+ let leftSideReference;
138
+ if (ctxAtom) {
139
+ leftSideReference = this.getReference(ctx.atom_expr());
140
+ }
141
+ else if (ctxFuncCall) {
142
+ leftSideReference = this.visitResult(ctxFuncCall);
143
+ }
134
144
  const ctxDataExpr = ctx.data_expr();
135
- this.visit(ctxDataExpr);
136
- const value = this.getResult(ctxDataExpr);
137
- const trailers = reference.trailers ?? [];
145
+ const dataValue = this.visitResult(ctxDataExpr);
146
+ const rhsValue = prepareValue(dataValue);
147
+ const trailers = leftSideReference.trailers ?? [];
148
+ const sequenceParts = [];
138
149
  if (trailers.length === 0) {
139
- if (value instanceof ClassComponent) {
140
- const variables = this.getExecutor().scope.variables;
141
- variables.set(reference.name, value);
142
- this.getExecutor().scope.sequence.push([SequenceAction.Assign, reference.name, value]);
143
- this.log2(`assigned '${reference.name}' to ClassComponent`);
150
+ if (rhsValue instanceof ClassComponent) {
151
+ this.getScope().setVariable(leftSideReference.name, rhsValue);
152
+ sequenceParts.push(...['instance', leftSideReference.name, rhsValue]);
153
+ this.log2(`assigned '${leftSideReference.name}' to ClassComponent`);
144
154
  }
145
155
  else {
146
- this.getExecutor().scope.variables.set(reference.name, value);
147
- this.log2(`assigned variable ${reference.name} to ${value}`);
156
+ this.getScope().setVariable(leftSideReference.name, rhsValue);
157
+ this.log2(`assigned variable ${leftSideReference.name} to ${rhsValue}`);
158
+ sequenceParts.push(...['variable', leftSideReference.name, rhsValue]);
148
159
  }
149
160
  }
150
161
  else {
151
- if (reference.parentValue instanceof ClassComponent) {
152
- this.setInstanceParam(reference.parentValue, trailers, value);
153
- this.log2(`assigned component param ${reference.parentValue} trailers: ${trailers} value: ${value}`);
162
+ if (leftSideReference.parentValue instanceof ClassComponent) {
163
+ this.setInstanceParam(leftSideReference.parentValue, trailers, rhsValue);
164
+ this.log2(`assigned component param ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
165
+ sequenceParts.push(...['instance', [leftSideReference.parentValue, trailers], rhsValue]);
166
+ if (leftSideReference.parentValue.typeProp === ComponentTypes.net) {
167
+ const net = this.getScope().getNet(leftSideReference.parentValue, 1);
168
+ if (net) {
169
+ const trailerValue = trailers.join(".");
170
+ net.params.set(trailerValue, rhsValue);
171
+ }
172
+ }
154
173
  }
155
- else if (reference.parentValue instanceof Object) {
156
- reference.parentValue[trailers.join('.')] = value;
157
- this.log2(`assigned object ${reference.parentValue} trailers: ${trailers} value: ${value}`);
174
+ else if (leftSideReference.parentValue instanceof Object) {
175
+ leftSideReference.parentValue[trailers.join('.')] = rhsValue;
176
+ this.log2(`assigned object ${leftSideReference.parentValue} trailers: ${trailers} value: ${rhsValue}`);
177
+ sequenceParts.push(...['variable', [leftSideReference.parentValue, trailers], rhsValue]);
158
178
  }
159
179
  }
160
- this.setResult(ctx, value);
180
+ if (sequenceParts.length > 0) {
181
+ this.getScope().sequence.push([
182
+ SequenceAction.Assign, ...sequenceParts
183
+ ]);
184
+ }
185
+ this.setResult(ctx, rhsValue);
161
186
  };
162
187
  visitOperator_assignment_expr = (ctx) => {
163
188
  const reference = this.getReference(ctx.atom_expr());
@@ -204,7 +229,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
204
229
  this.throwWithContext(ctx, 'Operator assignment failed: could not perform operator');
205
230
  }
206
231
  if (trailers.length === 0) {
207
- this.getExecutor().scope.variables.set(reference.name, newValue);
232
+ this.getExecutor().scope.setVariable(reference.name, newValue);
208
233
  }
209
234
  else {
210
235
  if (reference.value instanceof ClassComponent) {
@@ -221,8 +246,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
221
246
  if (atomStr.indexOf('(') !== -1 || atomStr.indexOf(')') !== -1) {
222
247
  this.throwWithContext(ctx, "Invalid assignment expression!");
223
248
  }
224
- this.visit(ctx);
225
- const reference = this.getResult(ctx);
249
+ const reference = this.visitResult(ctx);
226
250
  const { trailers = [] } = reference;
227
251
  const undefinedParentWithTrailers = trailers.length > 0
228
252
  && reference.parentValue === undefined;
@@ -245,11 +269,11 @@ export class BaseVisitor extends CircuitScriptVisitor {
245
269
  }
246
270
  }
247
271
  if (this.pinTypesList.indexOf(atomId) !== -1) {
248
- currentReference = {
272
+ currentReference = new AnyReference({
249
273
  found: true,
250
274
  value: atomId,
251
275
  type: ReferenceTypes.pinType,
252
- };
276
+ });
253
277
  }
254
278
  else {
255
279
  currentReference = executor.resolveVariable(this.executionStack, atomId, idTrailers);
@@ -266,9 +290,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
266
290
  this.setResult(ctx, currentReference);
267
291
  };
268
292
  visitFunctionCallExpr = (ctx) => {
269
- const tmpCtx = ctx.function_call_expr();
270
- this.visit(tmpCtx);
271
- const result = this.getResult(tmpCtx);
293
+ const result = this.visitResult(ctx.function_call_expr());
272
294
  this.setResult(ctx, result);
273
295
  };
274
296
  visitFunction_call_expr = (ctx) => {
@@ -298,12 +320,18 @@ export class BaseVisitor extends CircuitScriptVisitor {
298
320
  const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
299
321
  try {
300
322
  const [, functionResult] = executor.callFunction(currentReference.name, parameters, this.executionStack, useNetNamespace);
301
- currentReference = {
302
- found: true,
303
- value: functionResult,
304
- type: (functionResult instanceof ClassComponent) ?
305
- 'instance' : 'value',
306
- };
323
+ if (isReference(functionResult)) {
324
+ currentReference = functionResult;
325
+ }
326
+ else {
327
+ currentReference = new AnyReference({
328
+ found: true,
329
+ value: functionResult,
330
+ trailers: [],
331
+ type: (functionResult instanceof ClassComponent) ?
332
+ ReferenceTypes.instance : ReferenceTypes.value,
333
+ });
334
+ }
307
335
  }
308
336
  catch (err) {
309
337
  this.throwWithContext(ctx, err);
@@ -314,7 +342,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
314
342
  }
315
343
  });
316
344
  }
317
- this.setResult(ctx, currentReference.value);
345
+ this.setResult(ctx, currentReference);
318
346
  };
319
347
  visitValue_expr = (ctx) => {
320
348
  const sign = ctx.Minus() ? -1 : 1;
@@ -412,13 +440,11 @@ export class BaseVisitor extends CircuitScriptVisitor {
412
440
  const keywordAssignmentExpressions = ctx.keyword_assignment_expr();
413
441
  const returnList = [];
414
442
  dataExpressions.forEach((item, index) => {
415
- this.visit(item);
416
- const value = this.getResult(item);
443
+ const value = this.visitResult(item);
417
444
  returnList.push(['position', index, value]);
418
445
  });
419
446
  keywordAssignmentExpressions.forEach((item) => {
420
- this.visit(item);
421
- const [key, value] = this.getResult(item);
447
+ const [key, value] = this.visitResult(item);
422
448
  returnList.push(['keyword', key, value]);
423
449
  });
424
450
  this.setResult(ctx, returnList);
@@ -556,12 +582,13 @@ export class BaseVisitor extends CircuitScriptVisitor {
556
582
  const tmpFuncArg = funcDefinedParameters[i];
557
583
  if (i < passedInParameters.length) {
558
584
  const tmpPassedInArgs = passedInParameters[i];
585
+ const argValue = prepareValue(tmpPassedInArgs[2]);
559
586
  if (tmpPassedInArgs[0] === 'position') {
560
587
  const variableName = tmpFuncArg[0];
561
588
  executor.log('set variable in scope, var name: ', variableName);
562
- executor.scope.variables.set(variableName, tmpPassedInArgs[2]);
563
- if (tmpPassedInArgs[2] instanceof ClassComponent) {
564
- const component = tmpPassedInArgs[2];
589
+ executor.scope.setVariable(variableName, argValue);
590
+ if (argValue instanceof ClassComponent) {
591
+ const component = argValue;
565
592
  for (const [pinNumber, net] of component.pinNets) {
566
593
  executor.scope.setNet(component, pinNumber, net);
567
594
  }
@@ -570,14 +597,14 @@ export class BaseVisitor extends CircuitScriptVisitor {
570
597
  else if (tmpPassedInArgs[0] === 'keyword') {
571
598
  const variableName = tmpPassedInArgs[1];
572
599
  executor.log('set variable in scope, var name: ', variableName);
573
- executor.scope.variables.set(variableName, tmpPassedInArgs[2]);
600
+ executor.scope.setVariable(variableName, argValue);
574
601
  }
575
602
  }
576
603
  else if (tmpFuncArg.length === 3) {
577
604
  const variableName = tmpFuncArg[0];
578
605
  const defaultValue = tmpFuncArg[2];
579
606
  executor.log('set variable in scope, var name: ', variableName);
580
- executor.scope.variables.set(variableName, defaultValue);
607
+ executor.scope.setVariable(variableName, defaultValue);
581
608
  }
582
609
  else {
583
610
  throw `Invalid arguments got: ` + passedInParameters;