circuitscript 0.0.28 → 0.0.31
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 +6 -1
- package/dist/cjs/antlr/CircuitScriptLexer.js +204 -200
- package/dist/cjs/antlr/CircuitScriptParser.js +1066 -1173
- package/dist/cjs/draw_symbols.js +383 -103
- package/dist/cjs/execute.js +39 -14
- package/dist/cjs/geometry.js +79 -18
- package/dist/cjs/globals.js +41 -7
- package/dist/cjs/helpers.js +40 -2
- package/dist/cjs/layout.js +72 -39
- package/dist/cjs/main.js +10 -4
- package/dist/cjs/objects/ClassComponent.js +2 -0
- package/dist/cjs/objects/ExecutionScope.js +1 -1
- package/dist/cjs/objects/Net.js +3 -2
- package/dist/cjs/objects/PinTypes.js +7 -1
- package/dist/cjs/objects/types.js +11 -1
- package/dist/cjs/regenerate-tests.js +84 -14
- package/dist/cjs/render.js +22 -15
- package/dist/cjs/sizing.js +4 -6
- package/dist/cjs/utils.js +29 -5
- package/dist/cjs/visitor.js +176 -10
- package/dist/esm/BaseVisitor.mjs +6 -1
- package/dist/esm/antlr/CircuitScriptLexer.mjs +204 -200
- package/dist/esm/antlr/CircuitScriptParser.mjs +1061 -1171
- package/dist/esm/antlr/CircuitScriptVisitor.mjs +3 -0
- package/dist/esm/draw_symbols.mjs +378 -102
- package/dist/esm/execute.mjs +40 -15
- package/dist/esm/geometry.mjs +79 -17
- package/dist/esm/globals.mjs +40 -6
- package/dist/esm/helpers.mjs +38 -1
- package/dist/esm/layout.mjs +75 -42
- package/dist/esm/main.mjs +11 -5
- package/dist/esm/objects/ClassComponent.mjs +6 -0
- package/dist/esm/objects/ExecutionScope.mjs +1 -1
- package/dist/esm/objects/Net.mjs +3 -2
- package/dist/esm/objects/PinTypes.mjs +6 -0
- package/dist/esm/objects/types.mjs +14 -0
- package/dist/esm/regenerate-tests.mjs +85 -15
- package/dist/esm/render.mjs +23 -16
- package/dist/esm/sizing.mjs +3 -4
- package/dist/esm/utils.mjs +26 -4
- package/dist/esm/visitor.mjs +179 -13
- package/dist/types/antlr/CircuitScriptLexer.d.ts +42 -41
- package/dist/types/antlr/CircuitScriptParser.d.ts +144 -133
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +6 -0
- package/dist/types/draw_symbols.d.ts +24 -6
- package/dist/types/execute.d.ts +5 -4
- package/dist/types/geometry.d.ts +5 -3
- package/dist/types/globals.d.ts +38 -6
- package/dist/types/helpers.d.ts +12 -0
- package/dist/types/layout.d.ts +2 -1
- package/dist/types/objects/ClassComponent.d.ts +8 -0
- package/dist/types/objects/PinTypes.d.ts +1 -0
- package/dist/types/objects/Wire.d.ts +4 -2
- package/dist/types/objects/types.d.ts +8 -0
- package/dist/types/sizing.d.ts +0 -4
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -1
- package/fonts/Arial.ttf +0 -0
- package/libs/lib.cst +78 -55
- package/package.json +1 -1
package/dist/cjs/visitor.js
CHANGED
|
@@ -9,6 +9,8 @@ const types_js_1 = require("./objects/types.js");
|
|
|
9
9
|
const globals_js_1 = require("./globals.js");
|
|
10
10
|
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
11
11
|
const BaseVisitor_js_1 = require("./BaseVisitor.js");
|
|
12
|
+
const utils_js_1 = require("./utils.js");
|
|
13
|
+
const helpers_js_1 = require("./helpers.js");
|
|
12
14
|
class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
13
15
|
constructor() {
|
|
14
16
|
super(...arguments);
|
|
@@ -150,7 +152,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
150
152
|
arrange, display, type, width, copy,
|
|
151
153
|
angle, followWireOrientation
|
|
152
154
|
};
|
|
153
|
-
|
|
155
|
+
const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
|
|
156
|
+
this.setResult(ctx, createdComponent);
|
|
154
157
|
};
|
|
155
158
|
this.visitCreate_graphic_expr = (ctx) => {
|
|
156
159
|
const commands = ctx.graphic_expr().reduce((accum, item) => {
|
|
@@ -196,8 +199,82 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
196
199
|
this.visit(ctxParameters);
|
|
197
200
|
parameters = this.getResult(ctxParameters);
|
|
198
201
|
}
|
|
202
|
+
if (commandName === 'label') {
|
|
203
|
+
parameters.forEach(item => {
|
|
204
|
+
if (item[0] == 'keyword' && item[1] === 'portType') {
|
|
205
|
+
if (item[2] === 'in') {
|
|
206
|
+
item[2] = 'input';
|
|
207
|
+
}
|
|
208
|
+
else if (item[2] === 'out') {
|
|
209
|
+
item[2] = 'output';
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
199
214
|
this.setResult(ctx, [commandName, parameters]);
|
|
200
215
|
};
|
|
216
|
+
this.visitCreate_module_expr = (ctx) => {
|
|
217
|
+
const properties = this.getPropertyExprList(ctx.property_expr());
|
|
218
|
+
const { left: leftPorts, right: rightPorts } = this.parseCreateModulePorts(properties.get('ports'));
|
|
219
|
+
const allPorts = [...leftPorts, ...rightPorts].filter(item => {
|
|
220
|
+
return !(item instanceof ParamDefinition_js_1.PinBlankValue);
|
|
221
|
+
});
|
|
222
|
+
const nameToPinId = new Map();
|
|
223
|
+
const tmpPorts = allPorts.map((portName, index) => {
|
|
224
|
+
nameToPinId.set(portName, index + 1);
|
|
225
|
+
return new PinDefinition_js_1.PinDefinition(index + 1, PinDefinition_js_1.PinIdType.Int, portName, PinTypes_js_1.PinTypes.Any);
|
|
226
|
+
});
|
|
227
|
+
const arrangeLeftItems = leftPorts.map(item => {
|
|
228
|
+
if (item instanceof ParamDefinition_js_1.PinBlankValue) {
|
|
229
|
+
return item;
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
return nameToPinId.get(item);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
const arrangeRightItems = rightPorts.map(item => {
|
|
236
|
+
if (item instanceof ParamDefinition_js_1.PinBlankValue) {
|
|
237
|
+
return item;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
return nameToPinId.get(item);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
const arrange = new Map();
|
|
244
|
+
if (arrangeLeftItems.length > 0) {
|
|
245
|
+
arrange.set('left', arrangeLeftItems);
|
|
246
|
+
}
|
|
247
|
+
if (arrangeRightItems.length > 0) {
|
|
248
|
+
arrange.set('right', arrangeRightItems);
|
|
249
|
+
}
|
|
250
|
+
const width = properties.has('width') ?
|
|
251
|
+
properties.get('width') : null;
|
|
252
|
+
const blankParams = [];
|
|
253
|
+
const props = {
|
|
254
|
+
arrange, width
|
|
255
|
+
};
|
|
256
|
+
const moduleInstanceName = this.getExecutor().getUniqueInstanceName('');
|
|
257
|
+
const createdComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props);
|
|
258
|
+
createdComponent.typeProp = 'module';
|
|
259
|
+
const ctxPropertyBlock = ctx.property_block_expr();
|
|
260
|
+
if (ctxPropertyBlock) {
|
|
261
|
+
const [firstBlock] = ctxPropertyBlock;
|
|
262
|
+
this.visit(firstBlock);
|
|
263
|
+
const [keyName, expressionsBlock] = this.getResult(firstBlock);
|
|
264
|
+
if (keyName === 'contains') {
|
|
265
|
+
createdComponent.moduleContainsExpressions = expressionsBlock;
|
|
266
|
+
this.expandModuleContains(createdComponent, this.getExecutor().netNamespace);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
this.setResult(ctx, createdComponent);
|
|
270
|
+
};
|
|
271
|
+
this.visitProperty_block_expr = (ctx) => {
|
|
272
|
+
const tmpCtx = ctx.property_key_expr();
|
|
273
|
+
this.visit(tmpCtx);
|
|
274
|
+
const keyName = this.getResult(tmpCtx);
|
|
275
|
+
const expressionsBlock = ctx.expressions_block();
|
|
276
|
+
this.setResult(ctx, [keyName, expressionsBlock]);
|
|
277
|
+
};
|
|
201
278
|
this.visitProperty_expr = (ctx) => {
|
|
202
279
|
const ctxPropertyKeyExpr = ctx.property_key_expr();
|
|
203
280
|
const ctxPropertyValueExpr = ctx.property_value_expr();
|
|
@@ -275,6 +352,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
275
352
|
&& component.copyProp) {
|
|
276
353
|
component = this.getExecutor().copyComponent(component);
|
|
277
354
|
}
|
|
355
|
+
if (component instanceof types_js_1.DeclaredReference
|
|
356
|
+
&& component.found
|
|
357
|
+
&& component.trailers
|
|
358
|
+
&& component.trailers.length > 0
|
|
359
|
+
&& component.trailers[0] === 'contains') {
|
|
360
|
+
component = component.value;
|
|
361
|
+
this.placeModuleContains(component);
|
|
362
|
+
}
|
|
278
363
|
if (component && component instanceof ClassComponent_js_1.ClassComponent) {
|
|
279
364
|
const modifiers = ctx.component_modifier_expr();
|
|
280
365
|
modifiers.forEach(modifier => {
|
|
@@ -333,7 +418,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
333
418
|
pinValue = this.getResult(ctxPinSelectExpr);
|
|
334
419
|
}
|
|
335
420
|
else {
|
|
336
|
-
|
|
421
|
+
if (component instanceof ClassComponent_js_1.ClassComponent) {
|
|
422
|
+
pinValue = component.getDefaultPin();
|
|
423
|
+
}
|
|
424
|
+
else {
|
|
425
|
+
const undeclaredRef = component;
|
|
426
|
+
throw 'Invalid component: ' + undeclaredRef.reference.name;
|
|
427
|
+
}
|
|
337
428
|
}
|
|
338
429
|
this.setResult(ctx, [component, pinValue]);
|
|
339
430
|
};
|
|
@@ -365,6 +456,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
365
456
|
let value;
|
|
366
457
|
const ctxCreateComponentExpr = ctx.create_component_expr();
|
|
367
458
|
const ctxCreateGraphicExpr = ctx.create_graphic_expr();
|
|
459
|
+
const ctxCreateModuleExpr = ctx.create_module_expr();
|
|
368
460
|
if (ctxCreateComponentExpr) {
|
|
369
461
|
this.visit(ctxCreateComponentExpr);
|
|
370
462
|
value = this.getResult(ctxCreateComponentExpr);
|
|
@@ -373,6 +465,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
373
465
|
this.visit(ctxCreateGraphicExpr);
|
|
374
466
|
value = this.getResult(ctxCreateGraphicExpr);
|
|
375
467
|
}
|
|
468
|
+
else if (ctxCreateModuleExpr) {
|
|
469
|
+
this.visit(ctxCreateModuleExpr);
|
|
470
|
+
value = this.getResult(ctxCreateModuleExpr);
|
|
471
|
+
}
|
|
376
472
|
else {
|
|
377
473
|
throw "Invalid data expression";
|
|
378
474
|
}
|
|
@@ -541,13 +637,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
541
637
|
}
|
|
542
638
|
};
|
|
543
639
|
this.visitAt_block_pin_expression_complex = (ctx) => {
|
|
544
|
-
ctx.
|
|
545
|
-
this.visit(item);
|
|
546
|
-
});
|
|
640
|
+
this.visit(ctx.expressions_block());
|
|
547
641
|
};
|
|
548
642
|
this.visitWire_expr_direction_only = (ctx) => {
|
|
549
643
|
const value = ctx.ID().getText();
|
|
550
|
-
if (value ===
|
|
644
|
+
if (value === globals_js_1.WireAutoDirection.Auto || value === globals_js_1.WireAutoDirection.Auto_) {
|
|
551
645
|
this.setResult(ctx, [value]);
|
|
552
646
|
}
|
|
553
647
|
else {
|
|
@@ -568,7 +662,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
568
662
|
useValue = this.getResult(ctxDataExpr);
|
|
569
663
|
}
|
|
570
664
|
if (useValue !== null) {
|
|
571
|
-
this.setResult(ctx, [direction, useValue]);
|
|
665
|
+
this.setResult(ctx, [direction, new helpers_js_1.UnitDimension(useValue)]);
|
|
572
666
|
return;
|
|
573
667
|
}
|
|
574
668
|
}
|
|
@@ -602,9 +696,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
602
696
|
const propertyName = ctx.ID().getText();
|
|
603
697
|
this.getExecutor().setProperty('..' + propertyName, result);
|
|
604
698
|
};
|
|
699
|
+
this.visitExpressions_block = (ctx) => {
|
|
700
|
+
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
701
|
+
};
|
|
605
702
|
this.visitFrame_expr = (ctx) => {
|
|
606
703
|
const frameId = this.getExecutor().enterFrame();
|
|
607
|
-
this.
|
|
704
|
+
this.visit(ctx.expressions_block());
|
|
608
705
|
this.getExecutor().exitFrame(frameId);
|
|
609
706
|
};
|
|
610
707
|
this.visitNet_namespace_expr = (ctx) => {
|
|
@@ -635,7 +732,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
635
732
|
this.visit(ctxDataExpr);
|
|
636
733
|
const result = this.getResult(ctxDataExpr);
|
|
637
734
|
if (result) {
|
|
638
|
-
this.
|
|
735
|
+
this.visit(ctx.expressions_block());
|
|
639
736
|
}
|
|
640
737
|
else {
|
|
641
738
|
const ctxInnerIfExprs = ctx.if_inner_expr();
|
|
@@ -662,7 +759,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
662
759
|
this.visit(ctxDataExpr);
|
|
663
760
|
const result = this.getResult(ctxDataExpr);
|
|
664
761
|
if (result) {
|
|
665
|
-
this.
|
|
762
|
+
this.visit(ctx.expressions_block());
|
|
666
763
|
}
|
|
667
764
|
this.setResult(ctx, result);
|
|
668
765
|
};
|
|
@@ -674,6 +771,55 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
674
771
|
PinTypes_js_1.PinTypes.Power,
|
|
675
772
|
];
|
|
676
773
|
}
|
|
774
|
+
expandModuleContains(component, netNamespace) {
|
|
775
|
+
this.getExecutor().log('expanding module `contains`');
|
|
776
|
+
const executionStack = this.executionStack;
|
|
777
|
+
const resolveNet = this.createNetResolver(executionStack);
|
|
778
|
+
const executionContextName = this.getExecutor().namespace + "_"
|
|
779
|
+
+ component.instanceName
|
|
780
|
+
+ '_' + component.moduleCounter;
|
|
781
|
+
const tmpNamespace = this.getNetNamespace(netNamespace, "+/" + component.instanceName + "_" + component.moduleCounter);
|
|
782
|
+
const newExecutor = this.enterNewChildContext(executionStack, this.getExecutor(), executionContextName, { netNamespace: tmpNamespace }, [], []);
|
|
783
|
+
component.moduleCounter += 1;
|
|
784
|
+
newExecutor.resolveNet = resolveNet;
|
|
785
|
+
this.visit(component.moduleContainsExpressions);
|
|
786
|
+
const executionContext = executionStack.pop();
|
|
787
|
+
component.moduleExecutionContext = executionContext;
|
|
788
|
+
component.moduleExecutionContextName = executionContextName;
|
|
789
|
+
this.linkModuleSymbolWithContains(component, executionContext);
|
|
790
|
+
}
|
|
791
|
+
linkModuleSymbolWithContains(moduleComponent, executionContext) {
|
|
792
|
+
this.log('link module symbol');
|
|
793
|
+
const modulePinMapping = new Map();
|
|
794
|
+
moduleComponent.pins.forEach(pin => {
|
|
795
|
+
const pinName = pin.name;
|
|
796
|
+
modulePinMapping.set(pinName, pin.id);
|
|
797
|
+
});
|
|
798
|
+
const pinIdToPortMap = new Map();
|
|
799
|
+
moduleComponent.modulePinIdToPortMap = pinIdToPortMap;
|
|
800
|
+
for (const [key, component] of executionContext.scope.instances) {
|
|
801
|
+
if (component._copyID !== null && component.typeProp === 'port') {
|
|
802
|
+
const portName = component.parameters.get('net_name');
|
|
803
|
+
const modulePinId = modulePinMapping.get(portName);
|
|
804
|
+
pinIdToPortMap.set(modulePinId, component);
|
|
805
|
+
const portType = (0, utils_js_1.getPortType)(component);
|
|
806
|
+
const tmpPin = moduleComponent.pins.get(modulePinId);
|
|
807
|
+
tmpPin.pinType = portType;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
placeModuleContains(moduleComponent) {
|
|
812
|
+
if (moduleComponent.typeProp === 'module'
|
|
813
|
+
&& moduleComponent.moduleContainsExpressions) {
|
|
814
|
+
this.log('place module `contains`');
|
|
815
|
+
this.getExecutor().mergeScope(moduleComponent.moduleExecutionContext.scope, moduleComponent.moduleExecutionContextName);
|
|
816
|
+
this.log('connect module ports');
|
|
817
|
+
for (const [pinId, portComponent] of moduleComponent.modulePinIdToPortMap) {
|
|
818
|
+
this.getExecutor().atComponent(moduleComponent, pinId);
|
|
819
|
+
this.getExecutor().toComponent(portComponent, 1);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
677
823
|
parseCreateComponentPins(pinData) {
|
|
678
824
|
const pins = [];
|
|
679
825
|
if (typeof pinData === 'number') {
|
|
@@ -718,6 +864,26 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
718
864
|
}
|
|
719
865
|
return pins;
|
|
720
866
|
}
|
|
867
|
+
parseCreateModulePorts(portsDefinition) {
|
|
868
|
+
let leftItems = [];
|
|
869
|
+
let rightItems = [];
|
|
870
|
+
if (portsDefinition.has('left')) {
|
|
871
|
+
leftItems = portsDefinition.get('left');
|
|
872
|
+
if (!Array.isArray(leftItems)) {
|
|
873
|
+
leftItems = [leftItems];
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if (portsDefinition.has('right')) {
|
|
877
|
+
rightItems = portsDefinition.get('right');
|
|
878
|
+
if (!Array.isArray(rightItems)) {
|
|
879
|
+
rightItems = [rightItems];
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return {
|
|
883
|
+
left: leftItems,
|
|
884
|
+
right: rightItems
|
|
885
|
+
};
|
|
886
|
+
}
|
|
721
887
|
parseCreateComponentParams(params) {
|
|
722
888
|
const result = [];
|
|
723
889
|
if (params) {
|
package/dist/esm/BaseVisitor.mjs
CHANGED
|
@@ -282,7 +282,12 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
282
282
|
value = reference;
|
|
283
283
|
}
|
|
284
284
|
else {
|
|
285
|
-
|
|
285
|
+
if (reference.trailers && reference.trailers.length > 0) {
|
|
286
|
+
value = reference;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
value = reference.value;
|
|
290
|
+
}
|
|
286
291
|
}
|
|
287
292
|
}
|
|
288
293
|
}
|