circuitscript 0.0.17 → 0.0.19
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/__tests__/parseScripts.ts +160 -1
- package/__tests__/renderData/script1.cst.svg +1 -1
- package/__tests__/renderData/script5.cst.svg +1 -1
- package/__tests__/renderData/script6.cst +28 -0
- package/__tests__/renderData/script6.cst.svg +1 -0
- package/__tests__/renderData/script7.cst +26 -0
- package/__tests__/renderData/script7.cst.svg +1 -0
- package/__tests__/renderData/script8.cst +37 -0
- package/__tests__/renderData/script8.cst.svg +1 -0
- package/__tests__/testParse.ts +6 -2
- package/__tests__/testRender.ts +4 -1
- package/build/src/antlr/CircuitScriptLexer.js +152 -143
- package/build/src/antlr/CircuitScriptParser.js +731 -619
- package/build/src/antlr/CircuitScriptVisitor.js +2 -2
- package/build/src/draw_symbols.js +5 -2
- package/build/src/execute.js +140 -73
- package/build/src/export.js +2 -2
- package/build/src/globals.js +8 -0
- package/build/src/layout.js +27 -13
- package/build/src/objects/ExecutionScope.js +1 -1
- package/build/src/visitor.js +51 -25
- package/package.json +1 -1
- package/src/antlr/CircuitScript.g4 +9 -7
- package/src/antlr/CircuitScriptLexer.ts +152 -143
- package/src/antlr/CircuitScriptParser.ts +728 -616
- package/src/antlr/CircuitScriptVisitor.ts +6 -6
- package/src/draw_symbols.ts +7 -2
- package/src/execute.ts +185 -91
- package/src/export.ts +2 -2
- package/src/globals.ts +8 -0
- package/src/layout.ts +54 -29
- package/src/objects/ExecutionScope.ts +11 -3
- package/src/visitor.ts +64 -37
|
@@ -15,7 +15,7 @@ export class ExecutionScope {
|
|
|
15
15
|
|
|
16
16
|
variables: Map<string, ValueType | ClassComponent> = new Map();
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
blockStack: Map<number, any> = new Map();
|
|
19
19
|
|
|
20
20
|
wires: Wire[] = [];
|
|
21
21
|
frames: Frame[] = [];
|
|
@@ -165,12 +165,20 @@ export class ExecutionScope {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
export enum SequenceAction {
|
|
168
|
+
// Link current insertion point to component pin
|
|
168
169
|
To = 'to',
|
|
170
|
+
|
|
171
|
+
// Move insertion point at component pin
|
|
169
172
|
At = 'at',
|
|
173
|
+
|
|
174
|
+
// Link current insertion point with wire of given segments
|
|
170
175
|
Wire = 'wire',
|
|
171
176
|
|
|
177
|
+
// Jump to wire with target ID. Pin 0 of wire is the start of the
|
|
178
|
+
// wire, pin 1 is the other end of the wire.
|
|
172
179
|
WireJump = 'wire-jump',
|
|
173
180
|
|
|
181
|
+
// Creates a new frame group
|
|
174
182
|
Frame = 'frame',
|
|
175
183
|
}
|
|
176
184
|
|
|
@@ -187,7 +195,7 @@ export enum ActiveObject {
|
|
|
187
195
|
|
|
188
196
|
export type SequenceItem =
|
|
189
197
|
[SequenceAction.To | SequenceAction.At, ClassComponent, number, LayoutDirection?, string?]
|
|
190
|
-
| [SequenceAction.Wire, number, WireSegment[]]
|
|
191
|
-
| [SequenceAction.WireJump, number]
|
|
198
|
+
| [SequenceAction.Wire, wireId: number, WireSegment[]]
|
|
199
|
+
| [SequenceAction.WireJump, wireId: number, pinId: number]
|
|
192
200
|
| [SequenceAction.Frame, Frame, "enter" | "exit"]
|
|
193
201
|
;
|
package/src/visitor.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
Atom_exprContext,
|
|
16
16
|
BinaryOperatorExprContext,
|
|
17
17
|
Blank_exprContext,
|
|
18
|
-
|
|
18
|
+
Path_blocksContext,
|
|
19
19
|
Component_select_exprContext,
|
|
20
20
|
Create_component_exprContext,
|
|
21
21
|
Create_graphic_exprContext,
|
|
@@ -59,10 +59,10 @@ import {
|
|
|
59
59
|
import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
|
|
60
60
|
import { PinTypes } from './objects/PinTypes.js';
|
|
61
61
|
import { ExecutionScope } from './objects/ExecutionScope.js';
|
|
62
|
-
import {
|
|
62
|
+
import { CFunctionOptions, CallableParameter, ComplexType, ComponentPin,
|
|
63
63
|
ComponentPinNet, FunctionDefinedParameter, ReferenceType, UndeclaredReference, ValueType } from './objects/types.js';
|
|
64
64
|
import { Logger } from './logger.js';
|
|
65
|
-
import { ComponentTypes } from './globals.js';
|
|
65
|
+
import { BlockTypes, ComponentTypes, NoNetText } from './globals.js';
|
|
66
66
|
import { Net } from './objects/Net.js';
|
|
67
67
|
import { SubExpressionCommand, SymbolDrawingCommands } from './draw_symbols.js';
|
|
68
68
|
import { parseFileWithVisitor } from './parser.js';
|
|
@@ -303,36 +303,48 @@ export class MainVisitor extends ParseTreeVisitor<any> {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
visitAt_component_expr(ctx: At_component_exprContext): ComponentPin {
|
|
306
|
-
|
|
306
|
+
if (ctx.Point()) {
|
|
307
|
+
this.getExecutor().atPointBlock();
|
|
307
308
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
309
|
+
} else {
|
|
310
|
+
const [component, pin] = this.visit(ctx.component_select_expr());
|
|
311
|
+
|
|
312
|
+
const currentPoint = this.getExecutor().atComponent(component, pin, {
|
|
313
|
+
addSequence: true,
|
|
314
|
+
cloneNetComponent: true
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
if (ctx.ID()) {
|
|
318
|
+
// If there is ID specified, then it can only be for the
|
|
319
|
+
// component orientation.
|
|
320
|
+
this.setComponentOrientation(currentPoint[0],
|
|
321
|
+
currentPoint[1], ctx.ID().getText())
|
|
322
|
+
}
|
|
318
323
|
}
|
|
319
|
-
|
|
320
|
-
return
|
|
324
|
+
|
|
325
|
+
return this.getExecutor().getCurrentPoint();
|
|
321
326
|
}
|
|
322
327
|
|
|
323
|
-
visitTo_component_expr(ctx: To_component_exprContext): ComponentPin
|
|
328
|
+
visitTo_component_expr(ctx: To_component_exprContext): ComponentPin {
|
|
324
329
|
let currentPoint: ComponentPin;
|
|
325
|
-
ctx.component_select_expr_list().forEach((item) => {
|
|
326
|
-
const [component, pin] = this.visit(item);
|
|
327
|
-
currentPoint = this.getExecutor().toComponent(component, pin, {
|
|
328
|
-
addSequence: true, cloneNetComponent: true});
|
|
329
|
-
});
|
|
330
330
|
|
|
331
|
-
if (ctx.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
331
|
+
if (ctx.Point()) {
|
|
332
|
+
this.getExecutor().toPointBlock();
|
|
333
|
+
|
|
334
|
+
} else {
|
|
335
|
+
ctx.component_select_expr_list().forEach((item) => {
|
|
336
|
+
const [component, pin] = this.visit(item);
|
|
337
|
+
currentPoint = this.getExecutor().toComponent(component, pin, {
|
|
338
|
+
addSequence: true, cloneNetComponent: true
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
if (ctx.ID()) {
|
|
343
|
+
// If there is ID specified, then it can only be for the
|
|
344
|
+
// component orientation.
|
|
345
|
+
this.setComponentOrientation(currentPoint[0],
|
|
346
|
+
currentPoint[1], ctx.ID().getText())
|
|
347
|
+
}
|
|
336
348
|
}
|
|
337
349
|
|
|
338
350
|
return this.getExecutor().getCurrentPoint();
|
|
@@ -352,19 +364,34 @@ export class MainVisitor extends ParseTreeVisitor<any> {
|
|
|
352
364
|
}
|
|
353
365
|
}
|
|
354
366
|
|
|
355
|
-
|
|
356
|
-
|
|
367
|
+
visitPath_blocks(ctx: Path_blocksContext): ComponentPin {
|
|
368
|
+
const blocks = ctx.path_block_inner_list();
|
|
369
|
+
let blockType = BlockTypes.Branch;
|
|
370
|
+
|
|
371
|
+
if (blocks.length > 0){
|
|
372
|
+
const firstBlock = blocks[0];
|
|
373
|
+
if (firstBlock.Branch()){
|
|
374
|
+
blockType = BlockTypes.Branch
|
|
375
|
+
} else if (firstBlock.Join()){
|
|
376
|
+
blockType = BlockTypes.Join;
|
|
377
|
+
} else if (firstBlock.Parallel()){
|
|
378
|
+
blockType = BlockTypes.Parallel;
|
|
379
|
+
} else if (firstBlock.Point()){
|
|
380
|
+
blockType = BlockTypes.Point;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
this.getExecutor().enterBlocks(blockType);
|
|
357
385
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
this.getExecutor().enterBranch(index);
|
|
386
|
+
blocks.forEach((branch, index) => {
|
|
387
|
+
this.getExecutor().enterBlock(index);
|
|
361
388
|
|
|
362
389
|
this.visit(branch);
|
|
363
390
|
|
|
364
|
-
this.getExecutor().
|
|
391
|
+
this.getExecutor().exitBlock(index);
|
|
365
392
|
});
|
|
366
393
|
|
|
367
|
-
this.getExecutor().
|
|
394
|
+
this.getExecutor().exitBlocks();
|
|
368
395
|
return this.getExecutor().getCurrentPoint();
|
|
369
396
|
}
|
|
370
397
|
|
|
@@ -733,7 +760,7 @@ export class MainVisitor extends ParseTreeVisitor<any> {
|
|
|
733
760
|
|
|
734
761
|
// Function execution is completed, get the last executor
|
|
735
762
|
const lastExecution = executionStack.pop();
|
|
736
|
-
|
|
763
|
+
|
|
737
764
|
// Merge what ever was created in the scope with the outer scope
|
|
738
765
|
const nextLastExecution = executionStack[executionStack.length - 1];
|
|
739
766
|
nextLastExecution.mergeScope(
|
|
@@ -1396,8 +1423,8 @@ export class MainVisitor extends ParseTreeVisitor<any> {
|
|
|
1396
1423
|
const result = [];
|
|
1397
1424
|
|
|
1398
1425
|
for (const [pinId, pin] of instance.pins) {
|
|
1399
|
-
let netName =
|
|
1400
|
-
let netBaseName =
|
|
1426
|
+
let netName = NoNetText;
|
|
1427
|
+
let netBaseName = NoNetText;
|
|
1401
1428
|
|
|
1402
1429
|
if (scope.hasNet(instance, pinId)) {
|
|
1403
1430
|
const netObject = scope.getNet(instance, pinId);
|