circuitscript 0.1.0 → 0.1.3

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 (61) hide show
  1. package/dist/cjs/BaseVisitor.js +13 -8
  2. package/dist/cjs/antlr/CircuitScriptLexer.js +80 -80
  3. package/dist/cjs/antlr/CircuitScriptParser.js +599 -657
  4. package/dist/cjs/builtinMethods.js +27 -8
  5. package/dist/cjs/draw_symbols.js +320 -197
  6. package/dist/cjs/execute.js +114 -116
  7. package/dist/cjs/export.js +2 -4
  8. package/dist/cjs/geometry.js +52 -19
  9. package/dist/cjs/globals.js +17 -12
  10. package/dist/cjs/helpers.js +16 -3
  11. package/dist/cjs/layout.js +473 -354
  12. package/dist/cjs/logger.js +8 -1
  13. package/dist/cjs/objects/ClassComponent.js +22 -22
  14. package/dist/cjs/objects/ExecutionScope.js +10 -4
  15. package/dist/cjs/objects/Frame.js +11 -2
  16. package/dist/cjs/objects/ParamDefinition.js +123 -4
  17. package/dist/cjs/objects/PinDefinition.js +1 -4
  18. package/dist/cjs/render.js +76 -138
  19. package/dist/cjs/sizing.js +33 -7
  20. package/dist/cjs/utils.js +86 -2
  21. package/dist/cjs/visitor.js +224 -255
  22. package/dist/esm/BaseVisitor.mjs +15 -10
  23. package/dist/esm/antlr/CircuitScriptLexer.mjs +80 -80
  24. package/dist/esm/antlr/CircuitScriptParser.mjs +599 -657
  25. package/dist/esm/builtinMethods.mjs +24 -8
  26. package/dist/esm/draw_symbols.mjs +322 -200
  27. package/dist/esm/execute.mjs +116 -118
  28. package/dist/esm/export.mjs +2 -4
  29. package/dist/esm/geometry.mjs +52 -19
  30. package/dist/esm/globals.mjs +17 -12
  31. package/dist/esm/helpers.mjs +17 -4
  32. package/dist/esm/layout.mjs +479 -360
  33. package/dist/esm/logger.mjs +8 -1
  34. package/dist/esm/objects/ClassComponent.mjs +21 -26
  35. package/dist/esm/objects/ExecutionScope.mjs +10 -4
  36. package/dist/esm/objects/Frame.mjs +10 -1
  37. package/dist/esm/objects/ParamDefinition.mjs +122 -3
  38. package/dist/esm/objects/PinDefinition.mjs +0 -2
  39. package/dist/esm/render.mjs +79 -141
  40. package/dist/esm/sizing.mjs +34 -8
  41. package/dist/esm/utils.mjs +80 -1
  42. package/dist/esm/visitor.mjs +226 -257
  43. package/dist/types/BaseVisitor.d.ts +1 -1
  44. package/dist/types/antlr/CircuitScriptParser.d.ts +2 -3
  45. package/dist/types/draw_symbols.d.ts +72 -45
  46. package/dist/types/execute.d.ts +15 -10
  47. package/dist/types/geometry.d.ts +31 -19
  48. package/dist/types/globals.d.ts +15 -11
  49. package/dist/types/helpers.d.ts +2 -1
  50. package/dist/types/layout.d.ts +35 -54
  51. package/dist/types/logger.d.ts +1 -1
  52. package/dist/types/objects/ClassComponent.d.ts +19 -16
  53. package/dist/types/objects/ExecutionScope.d.ts +3 -2
  54. package/dist/types/objects/Frame.d.ts +9 -2
  55. package/dist/types/objects/ParamDefinition.d.ts +32 -2
  56. package/dist/types/objects/PinDefinition.d.ts +0 -2
  57. package/dist/types/render.d.ts +2 -1
  58. package/dist/types/utils.d.ts +14 -1
  59. package/dist/types/visitor.d.ts +4 -5
  60. package/libs/lib.cst +25 -8
  61. package/package.json +7 -3
@@ -1,9 +1,9 @@
1
1
  import { ClassComponent } from './objects/ClassComponent.mjs';
2
- import { NumericValue, ParamDefinition } from './objects/ParamDefinition.mjs';
2
+ import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.mjs';
3
3
  import { PinDefinition, PinIdType } from './objects/PinDefinition.mjs';
4
4
  import { PinTypes } from './objects/PinTypes.mjs';
5
5
  import { DeclaredReference, UndeclaredReference } from './objects/types.mjs';
6
- import { BlockTypes, ComponentTypes, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ReferenceTypes, WireAutoDirection } from './globals.mjs';
6
+ import { BlockTypes, ComponentTypes, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, WireAutoDirection } from './globals.mjs';
7
7
  import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.mjs';
8
8
  import { BaseVisitor } from './BaseVisitor.mjs';
9
9
  import { getPortType } from './utils.mjs';
@@ -12,9 +12,7 @@ import { FrameParamKeys } from './objects/Frame.mjs';
12
12
  export class ParserVisitor extends BaseVisitor {
13
13
  visitKeyword_assignment_expr = (ctx) => {
14
14
  const id = ctx.ID().getText();
15
- const ctxDataExpr = ctx.data_expr();
16
- this.visit(ctxDataExpr);
17
- const value = this.getResult(ctxDataExpr);
15
+ const value = this.visitResult(ctx.data_expr());
18
16
  this.setResult(ctx, [id, value]);
19
17
  };
20
18
  visitPin_select_expr = (ctx) => {
@@ -30,56 +28,48 @@ export class ParserVisitor extends BaseVisitor {
30
28
  this.setResult(ctx, value);
31
29
  };
32
30
  visitAdd_component_expr = (ctx) => {
33
- const ctxDataWithAssignmentExpr = ctx.data_expr_with_assignment();
34
- this.visit(ctxDataWithAssignmentExpr);
35
- const [component, pinValue] = this.getResult(ctxDataWithAssignmentExpr);
31
+ const [component, pinValue] = this.visitResult(ctx.data_expr_with_assignment());
36
32
  this.getExecutor().addComponentExisting(component, pinValue);
37
33
  };
38
34
  visitAt_component_expr = (ctx) => {
39
- if (ctx.Point()) {
40
- this.getExecutor().atPointBlock();
41
- }
42
- else {
43
- const ctxComponentSelectExpr = ctx.component_select_expr();
44
- this.visit(ctxComponentSelectExpr);
45
- const [component, pin] = this.getResult(ctxComponentSelectExpr);
46
- this.getExecutor().atComponent(component, pin, {
47
- addSequence: true
48
- });
49
- }
35
+ const [component, pin] = this.visitResult(ctx.component_select_expr());
36
+ this.getExecutor().atComponent(component, pin, {
37
+ addSequence: true
38
+ });
50
39
  return this.getExecutor().getCurrentPoint();
51
40
  };
52
41
  visitTo_component_expr = (ctx) => {
53
- if (ctx.Point()) {
54
- this.getExecutor().toPointBlock();
55
- }
56
- else {
57
- ctx.component_select_expr().forEach(item => {
58
- this.visit(item);
59
- const [component, pin] = this.getResult(item);
60
- this.getExecutor().toComponent(component, pin, {
61
- addSequence: true
62
- });
42
+ ctx.component_select_expr().forEach(item => {
43
+ const [component, pin] = this.visitResult(item);
44
+ this.getExecutor().toComponent(component, pin, {
45
+ addSequence: true
63
46
  });
64
- }
47
+ });
65
48
  return this.getExecutor().getCurrentPoint();
66
49
  };
67
50
  visitComponent_select_expr = (ctx) => {
68
51
  const ctxDataExprWithAssigment = ctx.data_expr_with_assignment();
69
- if (ctxDataExprWithAssigment) {
70
- this.visit(ctxDataExprWithAssigment);
71
- this.setResult(ctx, this.getResult(ctxDataExprWithAssigment));
52
+ let componentPin = null;
53
+ if (ctx.Point()) {
54
+ const [component, pin,] = this.getExecutor().getPointBlockLocation();
55
+ componentPin = [component, pin];
56
+ }
57
+ else if (ctxDataExprWithAssigment) {
58
+ componentPin = this.visitResult(ctxDataExprWithAssigment);
72
59
  }
73
60
  else {
74
61
  const component = this.getExecutor().scope.currentComponent;
75
62
  let pinId = null;
76
63
  const ctxPinSelectExpr = ctx.pin_select_expr();
77
64
  if (ctxPinSelectExpr) {
78
- this.visit(ctxPinSelectExpr);
79
- pinId = this.getResult(ctxPinSelectExpr);
65
+ pinId = this.visitResult(ctxPinSelectExpr);
66
+ }
67
+ if (pinId === null) {
68
+ this.throwWithContext(ctx, "Could not resolve pin");
80
69
  }
81
- this.setResult(ctx, [component, pinId]);
70
+ componentPin = [component, pinId];
82
71
  }
72
+ this.setResult(ctx, componentPin);
83
73
  };
84
74
  visitPath_blocks = (ctx) => {
85
75
  const blocks = ctx.path_block_inner();
@@ -118,7 +108,7 @@ export class ParserVisitor extends BaseVisitor {
118
108
  visitCreate_component_expr = (ctx) => {
119
109
  const properties = this.getPropertyExprList(ctx.property_expr());
120
110
  const pins = this.parseCreateComponentPins(properties.get('pins'));
121
- let instanceName = this.getExecutor().getUniqueInstanceName('');
111
+ let instanceName = this.getExecutor().getUniqueInstanceName();
122
112
  const propParams = properties.get('params');
123
113
  const params = this.parseCreateComponentParams(propParams);
124
114
  if (params.length > 0) {
@@ -140,12 +130,14 @@ export class ParserVisitor extends BaseVisitor {
140
130
  properties.get('copy') : false;
141
131
  const width = properties.has('width') ?
142
132
  properties.get('width') : null;
143
- const angle = properties.has('angle') ?
144
- properties.get('angle') : null;
133
+ const height = properties.has('height') ?
134
+ properties.get('height') : null;
135
+ const angle = properties.has(ParamKeys.angle) ?
136
+ properties.get(ParamKeys.angle) : null;
145
137
  const followWireOrientation = properties.has('followWireOrientation') ?
146
138
  properties.get('followWireOrientation') : true;
147
139
  const props = {
148
- arrange, display, type, width, copy,
140
+ arrange, display, type, width, height, copy,
149
141
  angle, followWireOrientation
150
142
  };
151
143
  const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
@@ -172,8 +164,7 @@ export class ParserVisitor extends BaseVisitor {
172
164
  const currentStack = this.executionStack.splice(0);
173
165
  this.executionStack.push(...stack);
174
166
  const graphicsExpressionsCtx = ctx.graphic_expressions_block();
175
- this.visit(graphicsExpressionsCtx);
176
- const commands = this.getResult(graphicsExpressionsCtx);
167
+ const commands = this.visitResult(graphicsExpressionsCtx);
177
168
  this.executionStack.splice(0);
178
169
  this.executionStack.push(...currentStack);
179
170
  return commands;
@@ -183,8 +174,7 @@ export class ParserVisitor extends BaseVisitor {
183
174
  };
184
175
  visitGraphic_expressions_block = (ctx) => {
185
176
  const commands = ctx.graphic_expr().reduce((accum, item) => {
186
- this.visit(item);
187
- const [commandName, parameters] = this.getResult(item);
177
+ const [commandName, parameters] = this.visitResult(item);
188
178
  if (commandName === PlaceHolderCommands.for) {
189
179
  accum = accum.concat(parameters);
190
180
  }
@@ -199,7 +189,16 @@ export class ParserVisitor extends BaseVisitor {
199
189
  }
200
190
  return accum;
201
191
  }, []);
202
- accum.push([commandName, positionParams, keywordParams, item]);
192
+ let useCommandName = commandName;
193
+ let usePositionParams = positionParams;
194
+ if (commandName === PlaceHolderCommands.crect) {
195
+ useCommandName = PlaceHolderCommands.rect;
196
+ const [centerX, centerY, width, height] = positionParams;
197
+ const newX = centerX.sub(width.half());
198
+ const newY = centerY.sub(height.half());
199
+ usePositionParams = [newX, newY, width, height];
200
+ }
201
+ accum.push([useCommandName, usePositionParams, keywordParams, item]);
203
202
  }
204
203
  return accum;
205
204
  }, []);
@@ -217,18 +216,15 @@ export class ParserVisitor extends BaseVisitor {
217
216
  let parameters = [];
218
217
  const ctxNestedProperties = ctx.nested_properties_inner();
219
218
  if (ctxNestedProperties) {
220
- this.visit(ctxNestedProperties);
221
- const nestedKeyValues = this.getResult(ctxNestedProperties);
219
+ const nestedKeyValues = this.visitResult(ctxNestedProperties);
222
220
  nestedKeyValues.forEach((value, key) => {
223
221
  parameters.push(['keyword', key, value]);
224
222
  });
225
223
  }
226
224
  else {
227
- const ctxParameters = ctx.parameters();
228
- this.visit(ctxParameters);
229
- parameters = this.getResult(ctxParameters);
225
+ parameters = this.visitResult(ctx.parameters());
230
226
  }
231
- if (commandName === 'label') {
227
+ if (commandName === PlaceHolderCommands.label) {
232
228
  parameters.forEach(item => {
233
229
  if (item[0] == 'keyword' && item[1] === 'portType') {
234
230
  if (item[2] === 'in') {
@@ -244,9 +240,7 @@ export class ParserVisitor extends BaseVisitor {
244
240
  };
245
241
  visitGraphicForExpr = (ctx) => {
246
242
  const forVariableNames = ctx.ID().map(item => item.getText());
247
- const ctxDataExpr = ctx.data_expr();
248
- this.visit(ctxDataExpr);
249
- const listItems = this.getResult(ctxDataExpr);
243
+ const listItems = this.visitResult(ctx.data_expr());
250
244
  let keepLooping = true;
251
245
  let counter = 0;
252
246
  let allCommands = [];
@@ -259,9 +253,7 @@ export class ParserVisitor extends BaseVisitor {
259
253
  useValueArray.forEach((value, index) => {
260
254
  this.getExecutor().scope.variables.set(forVariableNames[index], value);
261
255
  });
262
- const graphicsExpressionsCtx = ctx.graphic_expressions_block();
263
- this.visit(graphicsExpressionsCtx);
264
- const commands = this.getResult(graphicsExpressionsCtx);
256
+ const commands = this.visitResult(ctx.graphic_expressions_block());
265
257
  allCommands = allCommands.concat(commands);
266
258
  counter += 1;
267
259
  }
@@ -273,8 +265,10 @@ export class ParserVisitor extends BaseVisitor {
273
265
  };
274
266
  visitCreate_module_expr = (ctx) => {
275
267
  const properties = this.getPropertyExprList(ctx.property_expr());
276
- const { left: leftPorts, right: rightPorts } = this.parseCreateModulePorts(properties.get('ports'));
277
- const allPorts = [...leftPorts, ...rightPorts].filter(item => {
268
+ const modulePorts = this.parseCreateModulePorts(properties.get('ports'));
269
+ const { [SymbolPinSide.Left]: leftPorts, [SymbolPinSide.Right]: rightPorts, [SymbolPinSide.Top]: topPorts, [SymbolPinSide.Bottom]: bottomPorts } = modulePorts;
270
+ const allPorts = [...leftPorts, ...rightPorts,
271
+ ...topPorts, ...bottomPorts].filter(item => {
278
272
  return !(Array.isArray(item));
279
273
  });
280
274
  const nameToPinId = new Map();
@@ -282,64 +276,42 @@ export class ParserVisitor extends BaseVisitor {
282
276
  nameToPinId.set(portName, index + 1);
283
277
  return new PinDefinition(index + 1, PinIdType.Int, portName, PinTypes.Any);
284
278
  });
285
- const arrangeLeftItems = leftPorts.map(item => {
286
- if (Array.isArray(item)) {
287
- return item;
288
- }
289
- else {
290
- return nameToPinId.get(item);
291
- }
292
- });
293
- const arrangeRightItems = rightPorts.map(item => {
294
- if (Array.isArray(item)) {
295
- return item;
296
- }
297
- else {
298
- return nameToPinId.get(item);
299
- }
300
- });
301
- const arrange = new Map();
302
- if (arrangeLeftItems.length > 0) {
303
- arrange.set('left', arrangeLeftItems);
304
- }
305
- if (arrangeRightItems.length > 0) {
306
- arrange.set('right', arrangeRightItems);
307
- }
279
+ const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
308
280
  const width = properties.has('width') ?
309
281
  properties.get('width') : null;
282
+ const height = properties.has('height') ?
283
+ properties.get('height') : null;
310
284
  const blankParams = [];
311
285
  const props = {
312
- arrange, width
286
+ arrange, width, height,
287
+ copy: false,
288
+ followWireOrientation: true,
313
289
  };
314
- const moduleInstanceName = this.getExecutor().getUniqueInstanceName('');
315
- const createdComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props);
316
- createdComponent.typeProp = 'module';
290
+ const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
291
+ const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
292
+ moduleComponent.typeProp = ComponentTypes.module;
317
293
  const ctxPropertyBlock = ctx.property_block_expr();
318
294
  if (ctxPropertyBlock) {
319
295
  const [firstBlock] = ctxPropertyBlock;
320
- this.visit(firstBlock);
321
- const [keyName, expressionsBlock] = this.getResult(firstBlock);
296
+ const [keyName, expressionsBlock] = this.visitResult(firstBlock);
322
297
  if (keyName === ModuleContainsKeyword) {
323
- createdComponent.moduleContainsExpressions = expressionsBlock;
324
- this.expandModuleContains(createdComponent, this.getExecutor().netNamespace);
298
+ moduleComponent.moduleContainsExpressions = expressionsBlock;
299
+ this.expandModuleContains(moduleComponent, this.getExecutor().netNamespace);
325
300
  }
326
301
  }
327
- this.setResult(ctx, createdComponent);
302
+ if (moduleComponent.moduleContainsExpressions === undefined) {
303
+ throw 'Module has no `contains` block defined!';
304
+ }
305
+ this.setResult(ctx, moduleComponent);
328
306
  };
329
307
  visitProperty_block_expr = (ctx) => {
330
- const tmpCtx = ctx.property_key_expr();
331
- this.visit(tmpCtx);
332
- const keyName = this.getResult(tmpCtx);
308
+ const keyName = this.visitResult(ctx.property_key_expr());
333
309
  const expressionsBlock = ctx.expressions_block();
334
310
  this.setResult(ctx, [keyName, expressionsBlock]);
335
311
  };
336
312
  visitProperty_expr = (ctx) => {
337
- const ctxPropertyKeyExpr = ctx.property_key_expr();
338
- const ctxPropertyValueExpr = ctx.property_value_expr();
339
- this.visit(ctxPropertyKeyExpr);
340
- this.visit(ctxPropertyValueExpr);
341
- const keyName = this.getResult(ctxPropertyKeyExpr);
342
- const value = this.getResult(ctxPropertyValueExpr);
313
+ const keyName = this.visitResult(ctx.property_key_expr());
314
+ const value = this.visitResult(ctx.property_value_expr());
343
315
  if (value instanceof UndeclaredReference && (value.reference.parentValue === undefined
344
316
  && value.reference.value === undefined)) {
345
317
  throw value.throwMessage();
@@ -351,14 +323,11 @@ export class ParserVisitor extends BaseVisitor {
351
323
  visitSingle_line_property = (ctx) => {
352
324
  let value;
353
325
  if (ctx.data_expr().length === 1) {
354
- const ctxFirst = ctx.data_expr(0);
355
- this.visit(ctxFirst);
356
- value = this.getResult(ctxFirst);
326
+ value = this.visitResult(ctx.data_expr(0));
357
327
  }
358
328
  else {
359
329
  value = ctx.data_expr().map(item => {
360
- this.visit(item);
361
- return this.getResult(item);
330
+ return this.visitResult(item);
362
331
  });
363
332
  }
364
333
  this.setResult(ctx, value);
@@ -366,8 +335,7 @@ export class ParserVisitor extends BaseVisitor {
366
335
  visitNested_properties_inner = (ctx) => {
367
336
  const result = new Map();
368
337
  ctx.property_expr().forEach((item) => {
369
- this.visit(item);
370
- const property = this.getResult(item);
338
+ const property = this.visitResult(item);
371
339
  for (const [key, value] of property) {
372
340
  result.set(key, value);
373
341
  }
@@ -375,9 +343,7 @@ export class ParserVisitor extends BaseVisitor {
375
343
  this.setResult(ctx, result);
376
344
  };
377
345
  visitNested_properties = (ctx) => {
378
- const ctxNested = ctx.nested_properties_inner();
379
- this.visit(ctxNested);
380
- this.setResult(ctx, this.getResult(ctxNested));
346
+ this.setResult(ctx, this.visitResult(ctx.nested_properties_inner()));
381
347
  };
382
348
  visitProperty_key_expr = (ctx) => {
383
349
  const ctxID = ctx.ID();
@@ -401,16 +367,14 @@ export class ParserVisitor extends BaseVisitor {
401
367
  const ctxDataExpr = ctx.data_expr();
402
368
  const ctxAssignmentExpr = ctx.assignment_expr();
403
369
  if (ctxDataExpr) {
404
- this.visit(ctxDataExpr);
405
- component = this.getResult(ctxDataExpr);
370
+ component = this.visitResult(ctxDataExpr);
406
371
  componentCtx = ctxDataExpr;
407
372
  if (component === null || component === undefined) {
408
373
  this.throwWithContext(ctxDataExpr, "Could not find component: " + ctxDataExpr.getText());
409
374
  }
410
375
  }
411
376
  else if (ctxAssignmentExpr) {
412
- this.visit(ctxAssignmentExpr);
413
- component = this.getResult(ctxAssignmentExpr);
377
+ component = this.visitResult(ctxAssignmentExpr);
414
378
  componentCtx = ctxAssignmentExpr;
415
379
  }
416
380
  if (component instanceof ClassComponent
@@ -434,27 +398,25 @@ export class ParserVisitor extends BaseVisitor {
434
398
  const ctxID2 = modifier.ID(1);
435
399
  let result = null;
436
400
  if (ctxValueExpr) {
437
- this.visit(ctxValueExpr);
438
- result = this.getResult(ctxValueExpr);
401
+ result = this.visitResult(ctxValueExpr);
439
402
  }
440
403
  else if (ctxID2) {
441
404
  result = ctxID2.getText();
442
405
  }
443
406
  let shouldIgnoreWireOrientation = false;
444
- if (modifierText === 'flip') {
407
+ if (modifierText === ParamKeys.flip) {
445
408
  const flipValue = result;
446
409
  if (flipValue.indexOf('x') !== -1) {
447
- component.setParam('flipX', 1);
410
+ component.setParam(ParamKeys.flipX, 1);
448
411
  shouldIgnoreWireOrientation = true;
449
412
  }
450
413
  if (flipValue.indexOf('y') !== -1) {
451
- component.setParam('flipY', 1);
414
+ component.setParam(ParamKeys.flipY, 1);
452
415
  shouldIgnoreWireOrientation = true;
453
416
  }
454
417
  }
455
- else if (modifierText === 'angle') {
456
- const angleValue = Number(result);
457
- component.setParam('angle', angleValue);
418
+ else if (modifierText === ParamKeys.angle) {
419
+ component.setParam(ParamKeys.angle, result);
458
420
  shouldIgnoreWireOrientation = true;
459
421
  }
460
422
  else if (modifierText === 'anchor') {
@@ -468,8 +430,7 @@ export class ParserVisitor extends BaseVisitor {
468
430
  let pinValue = null;
469
431
  const ctxPinSelectExpr = ctx.pin_select_expr();
470
432
  if (ctxPinSelectExpr) {
471
- this.visit(ctxPinSelectExpr);
472
- pinValue = this.getResult(ctxPinSelectExpr);
433
+ pinValue = this.visitResult(ctxPinSelectExpr);
473
434
  }
474
435
  else {
475
436
  if (component instanceof ClassComponent) {
@@ -486,11 +447,12 @@ export class ParserVisitor extends BaseVisitor {
486
447
  this.getExecutor().log('expanding module `contains`');
487
448
  const executionStack = this.executionStack;
488
449
  const resolveNet = this.createNetResolver(executionStack);
489
- const executionContextName = this.getExecutor().namespace + "_"
450
+ const executor = this.getExecutor();
451
+ const executionContextName = executor.namespace + "_"
490
452
  + component.instanceName
491
453
  + '_' + component.moduleCounter;
492
454
  const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + "_" + component.moduleCounter);
493
- const newExecutor = this.enterNewChildContext(executionStack, this.getExecutor(), executionContextName, { netNamespace: tmpNamespace }, [], []);
455
+ const newExecutor = this.enterNewChildContext(executionStack, executor, executionContextName, { netNamespace: tmpNamespace }, [], []);
494
456
  component.moduleCounter += 1;
495
457
  newExecutor.resolveNet = resolveNet;
496
458
  this.visit(component.moduleContainsExpressions);
@@ -508,9 +470,9 @@ export class ParserVisitor extends BaseVisitor {
508
470
  });
509
471
  const pinIdToPortMap = new Map();
510
472
  moduleComponent.modulePinIdToPortMap = pinIdToPortMap;
511
- for (const [key, component] of executionContext.scope.instances) {
512
- if (component._copyID !== null && component.typeProp === 'port') {
513
- const portName = component.parameters.get('net_name');
473
+ for (const [, component] of executionContext.scope.instances) {
474
+ if (component._copyID !== null && component.typeProp === ComponentTypes.port) {
475
+ const portName = component.parameters.get(ParamKeys.net_name);
514
476
  const modulePinId = modulePinMapping.get(portName);
515
477
  pinIdToPortMap.set(modulePinId, component);
516
478
  const portType = getPortType(component);
@@ -520,7 +482,7 @@ export class ParserVisitor extends BaseVisitor {
520
482
  }
521
483
  }
522
484
  placeModuleContains(moduleComponent) {
523
- if (moduleComponent.typeProp === 'module'
485
+ if (moduleComponent.typeProp === ComponentTypes.module
524
486
  && moduleComponent.moduleContainsExpressions) {
525
487
  this.log('place module `contains`');
526
488
  this.getExecutor().mergeScope(moduleComponent.moduleExecutionContext.scope, moduleComponent.moduleExecutionContextName);
@@ -532,24 +494,23 @@ export class ParserVisitor extends BaseVisitor {
532
494
  }
533
495
  }
534
496
  visitUnaryOperatorExpr = (ctx) => {
535
- this.visit(ctx.data_expr());
536
- let value = this.getResult(ctx.data_expr());
497
+ let value = this.visitResult(ctx.data_expr());
537
498
  const unaryOp = ctx.unary_operator();
538
499
  if (unaryOp) {
539
500
  if (unaryOp.Not()) {
540
501
  if (typeof value === "boolean") {
541
502
  value = !value;
542
503
  }
543
- else if (typeof value === "number") {
544
- value = (value === 0) ? false : true;
504
+ else if (value instanceof NumericValue) {
505
+ value = (value.toNumber() === 0) ? true : false;
545
506
  }
546
507
  else {
547
508
  throw "Failed to do Not operator";
548
509
  }
549
510
  }
550
511
  else if (unaryOp.Minus()) {
551
- if (typeof value === 'number') {
552
- value = -value;
512
+ if (value instanceof NumericValue) {
513
+ value = value.neg();
553
514
  }
554
515
  else {
555
516
  throw "Failed to do Negation operator";
@@ -564,16 +525,13 @@ export class ParserVisitor extends BaseVisitor {
564
525
  const ctxCreateGraphicExpr = ctx.create_graphic_expr();
565
526
  const ctxCreateModuleExpr = ctx.create_module_expr();
566
527
  if (ctxCreateComponentExpr) {
567
- this.visit(ctxCreateComponentExpr);
568
- value = this.getResult(ctxCreateComponentExpr);
528
+ value = this.visitResult(ctxCreateComponentExpr);
569
529
  }
570
530
  else if (ctxCreateGraphicExpr) {
571
- this.visit(ctxCreateGraphicExpr);
572
- value = this.getResult(ctxCreateGraphicExpr);
531
+ value = this.visitResult(ctxCreateGraphicExpr);
573
532
  }
574
533
  else if (ctxCreateModuleExpr) {
575
- this.visit(ctxCreateModuleExpr);
576
- value = this.getResult(ctxCreateModuleExpr);
534
+ value = this.visitResult(ctxCreateModuleExpr);
577
535
  }
578
536
  else {
579
537
  throw "Invalid data expression";
@@ -583,10 +541,14 @@ export class ParserVisitor extends BaseVisitor {
583
541
  visitBinaryOperatorExpr = (ctx) => {
584
542
  const ctx0 = ctx.data_expr(0);
585
543
  const ctx1 = ctx.data_expr(1);
586
- this.visit(ctx0);
587
- this.visit(ctx1);
588
- const value1 = this.getResult(ctx0);
589
- const value2 = this.getResult(ctx1);
544
+ let value1 = this.visitResult(ctx0);
545
+ let value2 = this.visitResult(ctx1);
546
+ if (value1 instanceof NumericValue) {
547
+ value1 = value1.toNumber();
548
+ }
549
+ if (value2 instanceof NumericValue) {
550
+ value2 = value2.toNumber();
551
+ }
590
552
  const binaryOperatorType = ctx.binary_operator();
591
553
  let result = null;
592
554
  if (binaryOperatorType.Equals()) {
@@ -612,60 +574,87 @@ export class ParserVisitor extends BaseVisitor {
612
574
  visitLogicalOperatorExpr = (ctx) => {
613
575
  const ctx0 = ctx.data_expr(0);
614
576
  const ctx1 = ctx.data_expr(1);
615
- this.visit(ctx0);
616
- const value1 = this.getResult(ctx0);
577
+ let value1 = this.visitResult(ctx0);
578
+ if (value1 instanceof NumericValue) {
579
+ value1 = value1.toNumber();
580
+ }
617
581
  let value2 = false;
618
582
  let skipNext = false;
619
- if (ctx.LogicalOr() && value1) {
583
+ const isLogicalOr = ctx.LogicalOr();
584
+ if (isLogicalOr && value1) {
620
585
  skipNext = true;
621
586
  }
622
587
  if (!skipNext) {
623
- this.visit(ctx1);
624
- value2 = this.getResult(ctx1);
588
+ value2 = this.visitResult(ctx1);
589
+ if (value2 instanceof NumericValue) {
590
+ value2 = value2.toNumber();
591
+ }
625
592
  }
626
593
  let result = null;
627
594
  if (ctx.LogicalAnd()) {
628
595
  result = value1 && value2;
629
596
  }
630
- else if (ctx.LogicalOr()) {
597
+ else if (isLogicalOr) {
631
598
  result = value1 || value2;
632
599
  }
600
+ if (typeof result === "number") {
601
+ result = numeric(result);
602
+ }
633
603
  this.setResult(ctx, result);
634
604
  };
635
605
  visitMultiplyExpr = (ctx) => {
636
606
  const value1 = this.resolveDataExpr(ctx.data_expr(0));
637
607
  const value2 = this.resolveDataExpr(ctx.data_expr(1));
608
+ const operator = new NumberOperator();
609
+ const tmpValue1 = operator.prepare(value1);
610
+ const tmpValue2 = operator.prepare(value2);
638
611
  let result = null;
639
612
  if (ctx.Multiply()) {
640
- result = value1 * value2;
613
+ result = operator.multiply(tmpValue1, tmpValue2);
641
614
  }
642
615
  else if (ctx.Divide()) {
643
- result = value1 / value2;
616
+ result = operator.divide(tmpValue1, tmpValue2);
644
617
  }
645
618
  else if (ctx.Modulus()) {
646
- result = value1 % value2;
619
+ result = operator.modulus(tmpValue1, tmpValue2);
647
620
  }
648
621
  this.setResult(ctx, result);
649
622
  };
650
623
  visitAdditionExpr = (ctx) => {
651
624
  const value1 = this.resolveDataExpr(ctx.data_expr(0));
652
625
  const value2 = this.resolveDataExpr(ctx.data_expr(1));
653
- let result = null;
654
- if (ctx.Addition()) {
655
- result = value1 + value2;
626
+ if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
627
+ let tmpValue1 = value1;
628
+ if (value1 instanceof NumericValue) {
629
+ tmpValue1 = value1.toDisplayString();
630
+ }
631
+ let tmpValue2 = value2;
632
+ if (value2 instanceof NumericValue) {
633
+ tmpValue2 = value2.toDisplayString();
634
+ }
635
+ const result = tmpValue1 + tmpValue2;
636
+ this.setResult(ctx, result);
656
637
  }
657
- else if (ctx.Minus()) {
658
- result = value1 - value2;
638
+ else {
639
+ const operator = new NumberOperator();
640
+ const tmpValue1 = operator.prepare(value1);
641
+ const tmpValue2 = operator.prepare(value2);
642
+ let result = null;
643
+ if (ctx.Addition()) {
644
+ result = operator.addition(tmpValue1, tmpValue2);
645
+ }
646
+ else if (ctx.Minus()) {
647
+ result = operator.subtraction(tmpValue1, tmpValue2);
648
+ }
649
+ this.setResult(ctx, result);
659
650
  }
660
- this.setResult(ctx, result);
661
651
  };
662
652
  visitFunction_def_expr = (ctx) => {
663
653
  const functionName = ctx.ID().getText();
664
654
  let funcDefinedParameters = [];
665
655
  const ctxFunctionArgsExpr = ctx.function_args_expr();
666
656
  if (ctxFunctionArgsExpr) {
667
- this.visit(ctxFunctionArgsExpr);
668
- funcDefinedParameters = this.getResult(ctxFunctionArgsExpr);
657
+ funcDefinedParameters = this.visitResult(ctxFunctionArgsExpr);
669
658
  }
670
659
  const executionStack = this.executionStack;
671
660
  const functionCounter = { counter: 0 };
@@ -696,12 +685,9 @@ export class ParserVisitor extends BaseVisitor {
696
685
  this.setResult(ctx, result);
697
686
  };
698
687
  visitAt_block_pin_expr = (ctx) => {
699
- const ctxPinSelectExpr2 = ctx.pin_select_expr2();
700
- this.visit(ctxPinSelectExpr2);
701
- const atPin = this.getResult(ctxPinSelectExpr2);
688
+ const atPin = this.visitResult(ctx.pin_select_expr2());
702
689
  const executor = this.getExecutor();
703
- const currentComponent = executor.scope.currentComponent;
704
- const currentPin = executor.scope.currentPin;
690
+ const [currentComponent, currentPin] = executor.getCurrentPoint();
705
691
  executor.atComponent(currentComponent, atPin, {
706
692
  addSequence: true
707
693
  });
@@ -763,8 +749,7 @@ export class ParserVisitor extends BaseVisitor {
763
749
  useValue = Number(ctxIntegerValue);
764
750
  }
765
751
  else if (ctxDataExpr) {
766
- this.visit(ctxDataExpr);
767
- useValue = this.getResult(ctxDataExpr);
752
+ useValue = this.visitResult(ctxDataExpr);
768
753
  }
769
754
  if (useValue !== null) {
770
755
  this.setResult(ctx, [direction, new UnitDimension(useValue)]);
@@ -776,8 +761,7 @@ export class ParserVisitor extends BaseVisitor {
776
761
  visitWire_expr = (ctx) => {
777
762
  const wireAtomExpr = ctx.wire_atom_expr();
778
763
  const segments = wireAtomExpr.map(wireSegment => {
779
- this.visit(wireSegment);
780
- return this.getResult(wireSegment);
764
+ return this.visitResult(wireSegment);
781
765
  });
782
766
  this.getExecutor().addWire(segments);
783
767
  };
@@ -786,18 +770,12 @@ export class ParserVisitor extends BaseVisitor {
786
770
  return this.getExecutor().addPoint(ID.getText());
787
771
  };
788
772
  visitProperty_set_expr = (ctx) => {
789
- const ctxDataExpr = ctx.data_expr();
790
- this.visit(ctxDataExpr);
791
- const result = this.getResult(ctxDataExpr);
792
- const ctxAtomExpr = ctx.atom_expr();
793
- this.visit(ctxAtomExpr);
794
- const resolvedProperty = this.getResult(ctxAtomExpr);
773
+ const result = this.visitResult(ctx.data_expr());
774
+ const resolvedProperty = this.visitResult(ctx.atom_expr());
795
775
  this.getExecutor().setProperty(resolvedProperty, result);
796
776
  };
797
777
  visitDouble_dot_property_set_expr = (ctx) => {
798
- const ctxDataExpr = ctx.data_expr();
799
- this.visit(ctxDataExpr);
800
- const result = this.getResult(ctxDataExpr);
778
+ const result = this.visitResult(ctx.data_expr());
801
779
  const propertyName = ctx.ID().getText();
802
780
  this.getExecutor().setProperty('..' + propertyName, result);
803
781
  };
@@ -819,8 +797,7 @@ export class ParserVisitor extends BaseVisitor {
819
797
  const hasPlus = ctx.Addition();
820
798
  const ctxDataExpr = ctx.data_expr();
821
799
  if (ctxDataExpr) {
822
- this.visit(ctxDataExpr);
823
- dataValue = this.getResult(ctxDataExpr);
800
+ dataValue = this.visitResult(ctxDataExpr);
824
801
  if (dataValue instanceof UndeclaredReference) {
825
802
  netNamespace = "/" + dataValue.reference.name;
826
803
  }
@@ -837,9 +814,7 @@ export class ParserVisitor extends BaseVisitor {
837
814
  this.setResult(ctx, (hasPlus ? "+" : "") + netNamespace);
838
815
  };
839
816
  visitIf_expr = (ctx) => {
840
- const ctxDataExpr = ctx.data_expr();
841
- this.visit(ctxDataExpr);
842
- const result = this.getResult(ctxDataExpr);
817
+ const result = this.visitResult(ctx.data_expr());
843
818
  let resultValue = result;
844
819
  if (result instanceof UndeclaredReference) {
845
820
  resultValue = false;
@@ -851,9 +826,7 @@ export class ParserVisitor extends BaseVisitor {
851
826
  const ctxInnerIfExprs = ctx.if_inner_expr();
852
827
  let innerIfWasTrue = false;
853
828
  for (let i = 0; i < ctxInnerIfExprs.length; i++) {
854
- const tmpCtx = ctxInnerIfExprs[i];
855
- this.visit(tmpCtx);
856
- const innerResult = this.getResult(tmpCtx);
829
+ const innerResult = this.visitResult(ctxInnerIfExprs[i]);
857
830
  if (innerResult) {
858
831
  innerIfWasTrue = true;
859
832
  break;
@@ -868,9 +841,7 @@ export class ParserVisitor extends BaseVisitor {
868
841
  }
869
842
  };
870
843
  visitIf_inner_expr = (ctx) => {
871
- const ctxDataExpr = ctx.data_expr();
872
- this.visit(ctxDataExpr);
873
- const result = this.getResult(ctxDataExpr);
844
+ const result = this.visitResult(ctx.data_expr());
874
845
  if (result) {
875
846
  this.visit(ctx.expressions_block());
876
847
  }
@@ -882,8 +853,7 @@ export class ParserVisitor extends BaseVisitor {
882
853
  this.log('enter while loop');
883
854
  this.getExecutor().addBreakContext(ctx);
884
855
  while (keepLooping) {
885
- this.visit(dataExpr);
886
- const result = this.getResult(dataExpr);
856
+ const result = this.visitResult(dataExpr);
887
857
  if (result) {
888
858
  this.visit(ctx.expressions_block());
889
859
  keepLooping = true;
@@ -908,10 +878,9 @@ export class ParserVisitor extends BaseVisitor {
908
878
  this.log('exit while loop');
909
879
  };
910
880
  visitFor_expr = (ctx) => {
881
+ this.log('in for loop');
911
882
  const forVariableNames = ctx.ID().map(item => item.getText());
912
- const ctxDataExpr = ctx.data_expr();
913
- this.visit(ctxDataExpr);
914
- const listItems = this.getResult(ctxDataExpr);
883
+ const listItems = this.visitResult(ctx.data_expr());
915
884
  this.getExecutor().addBreakContext(ctx);
916
885
  let keepLooping = true;
917
886
  let counter = 0;
@@ -928,6 +897,7 @@ export class ParserVisitor extends BaseVisitor {
928
897
  keepLooping = true;
929
898
  const currentResult = this.getResult(ctx) ?? {};
930
899
  const { breakSignal = false, continueSignal = false } = currentResult;
900
+ this.log('condition result: ', breakSignal, continueSignal);
931
901
  if (breakSignal && !continueSignal) {
932
902
  keepLooping = false;
933
903
  }
@@ -947,8 +917,7 @@ export class ParserVisitor extends BaseVisitor {
947
917
  this.getExecutor().popBreakContext();
948
918
  };
949
919
  resolveDataExpr(data_expr) {
950
- this.visit(data_expr);
951
- const value = this.getResult(data_expr);
920
+ const value = this.visitResult(data_expr);
952
921
  if (value instanceof UndeclaredReference) {
953
922
  this.throwWithContext(data_expr, value.throwMessage());
954
923
  }
@@ -975,8 +944,8 @@ export class ParserVisitor extends BaseVisitor {
975
944
  ];
976
945
  parseCreateComponentPins(pinData) {
977
946
  const pins = [];
978
- if (typeof pinData === 'number') {
979
- const lastPin = pinData;
947
+ if (pinData instanceof NumericValue) {
948
+ const lastPin = pinData.toNumber();
980
949
  for (let i = 0; i < lastPin; i++) {
981
950
  const pinId = i + 1;
982
951
  pins.push(new PinDefinition(pinId, PinIdType.Int, pinId.toString()));
@@ -1012,30 +981,49 @@ export class ParserVisitor extends BaseVisitor {
1012
981
  else {
1013
982
  pinName = pinDef;
1014
983
  }
984
+ this.log('pins', pinId, pinIdType, pinName, pinType, altPinNames);
1015
985
  pins.push(new PinDefinition(pinId, pinIdType, pinName, pinType, altPinNames));
1016
986
  }
1017
987
  }
1018
988
  return pins;
1019
989
  }
1020
990
  parseCreateModulePorts(portsDefinition) {
1021
- let leftItems = [];
1022
- let rightItems = [];
1023
- if (portsDefinition.has('left')) {
1024
- leftItems = portsDefinition.get('left');
1025
- if (!Array.isArray(leftItems)) {
1026
- leftItems = [leftItems];
991
+ return {
992
+ left: this.getPortItems(portsDefinition, SymbolPinSide.Left),
993
+ right: this.getPortItems(portsDefinition, SymbolPinSide.Right),
994
+ top: this.getPortItems(portsDefinition, SymbolPinSide.Top),
995
+ bottom: this.getPortItems(portsDefinition, SymbolPinSide.Bottom),
996
+ };
997
+ }
998
+ getArrangePropFromModulePorts(modulePorts, nameToPinId) {
999
+ const keys = [SymbolPinSide.Left, SymbolPinSide.Right, SymbolPinSide.Top, SymbolPinSide.Bottom];
1000
+ const arrangeProp = new Map();
1001
+ keys.forEach(key => {
1002
+ if (modulePorts[key]) {
1003
+ const items = modulePorts[key].map(item => {
1004
+ if (Array.isArray(item)) {
1005
+ return item;
1006
+ }
1007
+ else {
1008
+ return numeric(nameToPinId.get(item));
1009
+ }
1010
+ });
1011
+ if (items.length > 0) {
1012
+ arrangeProp.set(key, items);
1013
+ }
1027
1014
  }
1028
- }
1029
- if (portsDefinition.has('right')) {
1030
- rightItems = portsDefinition.get('right');
1031
- if (!Array.isArray(rightItems)) {
1032
- rightItems = [rightItems];
1015
+ });
1016
+ return arrangeProp;
1017
+ }
1018
+ getPortItems(portsDefinition, key) {
1019
+ let tmpItems = [];
1020
+ if (portsDefinition.has(key)) {
1021
+ tmpItems = portsDefinition.get(key);
1022
+ if (!Array.isArray(tmpItems)) {
1023
+ tmpItems = [tmpItems];
1033
1024
  }
1034
1025
  }
1035
- return {
1036
- left: leftItems,
1037
- right: rightItems
1038
- };
1026
+ return tmpItems;
1039
1027
  }
1040
1028
  parseCreateComponentParams(params) {
1041
1029
  const result = [];
@@ -1114,8 +1102,7 @@ export class ParserVisitor extends BaseVisitor {
1114
1102
  const nets = executor.scope.getNets();
1115
1103
  return {
1116
1104
  sequence,
1117
- nets,
1118
- components: Array.from(executor.scope.instances.values())
1105
+ nets
1119
1106
  };
1120
1107
  }
1121
1108
  annotateComponents() {
@@ -1124,16 +1111,11 @@ export class ParserVisitor extends BaseVisitor {
1124
1111
  const instances = this.getExecutor().scope.instances;
1125
1112
  const toAnnotate = [];
1126
1113
  for (const [, instance] of instances) {
1114
+ if (instance.typeProp === ComponentTypes.net
1115
+ || instance.typeProp == ComponentTypes.graphic) {
1116
+ continue;
1117
+ }
1127
1118
  if (instance.assignedRefDes === null) {
1128
- if (instance.typeProp === ComponentTypes.label ||
1129
- instance.typeProp === ComponentTypes.net ||
1130
- instance.typeProp === ComponentTypes.point) {
1131
- continue;
1132
- }
1133
- if (instance.typeProp === null) {
1134
- this.log('Instance has no type:', instance.instanceName, ' assuming connector');
1135
- instance.typeProp = 'conn';
1136
- }
1137
1119
  if (instance.parameters.has('refdes')) {
1138
1120
  const refdes = instance.parameters.get('refdes');
1139
1121
  if (refdes) {
@@ -1147,7 +1129,10 @@ export class ParserVisitor extends BaseVisitor {
1147
1129
  }
1148
1130
  }
1149
1131
  toAnnotate.forEach(instance => {
1150
- const newRefDes = annotater.getAnnotation(instance.typeProp);
1132
+ const useTypeProp = instance.typeProp ?? 'conn';
1133
+ instance.typeProp === null
1134
+ && this.log('Instance has no type:', instance.instanceName, ' assuming connector');
1135
+ const newRefDes = annotater.getAnnotation(useTypeProp);
1151
1136
  if (newRefDes !== null) {
1152
1137
  instance.assignedRefDes = newRefDes;
1153
1138
  this.log(newRefDes, '-', instance.instanceName);
@@ -1170,9 +1155,9 @@ export class ParserVisitor extends BaseVisitor {
1170
1155
  });
1171
1156
  const totalSheets = sheets.length;
1172
1157
  sheets.forEach((item, index) => {
1173
- item.parameters.set(FrameParamKeys.SheetType, frameComponent);
1174
- item.parameters.set(FrameParamKeys.SheetNumber, index + 1);
1175
- item.parameters.set(FrameParamKeys.SheetTotal, totalSheets);
1158
+ item.parameters.set(FrameParamKeys.SheetType, frameComponent)
1159
+ .set(FrameParamKeys.SheetNumber, index + 1)
1160
+ .set(FrameParamKeys.SheetTotal, totalSheets);
1176
1161
  });
1177
1162
  }
1178
1163
  return {
@@ -1197,25 +1182,10 @@ export class ParserVisitor extends BaseVisitor {
1197
1182
  }
1198
1183
  return result;
1199
1184
  }
1200
- setComponentOrientation(component, pin, orientation) {
1201
- if (this.acceptedDirections.indexOf(orientation) !== -1) {
1202
- component.setParam('_addDirection', orientation);
1203
- component.setParam('_addPin', pin);
1204
- }
1205
- else {
1206
- throw "Invalid modifier for orientation";
1207
- }
1208
- }
1209
- setComponentFlip(component, flipValue) {
1210
- if (this.acceptedFlip.indexOf(flipValue) !== -1) {
1211
- component.setParam(flipValue, 1);
1212
- }
1213
- }
1214
1185
  getPropertyExprList(items) {
1215
1186
  const properties = new Map();
1216
1187
  items.forEach((item) => {
1217
- this.visit(item);
1218
- const result = this.getResult(item);
1188
+ const result = this.visitResult(item);
1219
1189
  for (const [key, value] of result) {
1220
1190
  properties.set(key, value);
1221
1191
  }
@@ -1224,14 +1194,14 @@ export class ParserVisitor extends BaseVisitor {
1224
1194
  }
1225
1195
  }
1226
1196
  const ComponentRefDesPrefixes = {
1227
- 'res': 'R',
1228
- 'cap': 'C',
1229
- 'ind': 'L',
1230
- 'diode': 'D',
1231
- 'conn': 'J',
1232
- 'transistor': 'Q',
1233
- 'relay': 'K',
1234
- 'ic': 'U',
1197
+ res: 'R',
1198
+ cap: 'C',
1199
+ ind: 'L',
1200
+ diode: 'D',
1201
+ conn: 'J',
1202
+ transistor: 'Q',
1203
+ relay: 'K',
1204
+ ic: 'U',
1235
1205
  '?': '?',
1236
1206
  };
1237
1207
  class ComponentAnnotater {
@@ -1241,7 +1211,6 @@ class ComponentAnnotater {
1241
1211
  for (const key in ComponentRefDesPrefixes) {
1242
1212
  this.counter[key] = 1;
1243
1213
  }
1244
- this.counter['?'] = 1;
1245
1214
  }
1246
1215
  getAnnotation(type) {
1247
1216
  if (this.counter[type] === undefined && type.length <= 2) {
@@ -1259,7 +1228,7 @@ class ComponentAnnotater {
1259
1228
  return null;
1260
1229
  }
1261
1230
  let attempts = 100;
1262
- let proposedName;
1231
+ let proposedName = "";
1263
1232
  while (attempts >= 0) {
1264
1233
  proposedName = ComponentRefDesPrefixes[type] + this.counter[type];
1265
1234
  this.counter[type]++;