circuitscript 0.0.18 → 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 +106 -1
- 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 +5 -2
- package/__tests__/testRender.ts +3 -1
- package/build/src/antlr/CircuitScriptLexer.js +159 -154
- package/build/src/antlr/CircuitScriptParser.js +722 -632
- package/build/src/antlr/CircuitScriptVisitor.js +2 -2
- package/build/src/execute.js +87 -45
- package/build/src/globals.js +7 -5
- package/build/src/objects/ExecutionScope.js +1 -1
- package/build/src/visitor.js +46 -30
- package/package.json +1 -1
- package/src/antlr/CircuitScript.g4 +9 -8
- package/src/antlr/CircuitScriptLexer.ts +159 -154
- package/src/antlr/CircuitScriptParser.ts +719 -629
- package/src/antlr/CircuitScriptVisitor.ts +6 -6
- package/src/execute.ts +113 -56
- package/src/globals.ts +5 -3
- package/src/objects/ExecutionScope.ts +1 -1
- package/src/visitor.ts +58 -42
|
@@ -2,8 +2,8 @@ import { ParseTreeVisitor } from 'antlr4';
|
|
|
2
2
|
export default class CircuitScriptVisitor extends ParseTreeVisitor {
|
|
3
3
|
visitScript;
|
|
4
4
|
visitExpression;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
visitPath_blocks;
|
|
6
|
+
visitPath_block_inner;
|
|
7
7
|
visitProperty_set_expr2;
|
|
8
8
|
visitAssignment_expr2;
|
|
9
9
|
visitData_expr_with_assignment;
|
package/build/src/execute.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockTypes, ComponentTypes, GlobalNames, NoNetText, ParamKeys, ReferenceTypes } from './globals.js';
|
|
2
2
|
import { ClassComponent } from './objects/ClassComponent.js';
|
|
3
3
|
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.js';
|
|
4
4
|
import { Net } from './objects/Net.js';
|
|
@@ -11,7 +11,7 @@ export class ExecutionContext {
|
|
|
11
11
|
netNamespace;
|
|
12
12
|
executionLevel;
|
|
13
13
|
scope;
|
|
14
|
-
|
|
14
|
+
tmpPointId = 0;
|
|
15
15
|
resolveNet = null;
|
|
16
16
|
stopFurtherExpressions = false;
|
|
17
17
|
returnValue = null;
|
|
@@ -305,24 +305,32 @@ export class ExecutionContext {
|
|
|
305
305
|
this.print('created clone of net component:', cloneInstanceName);
|
|
306
306
|
return clonedComponent;
|
|
307
307
|
}
|
|
308
|
-
|
|
309
|
-
|
|
308
|
+
enterBlocks(blockType) {
|
|
309
|
+
if (blockType === BlockTypes.Point) {
|
|
310
|
+
this.addPoint(`_point.${this.name}.${this.tmpPointId}`, false);
|
|
311
|
+
this.tmpPointId += 1;
|
|
312
|
+
}
|
|
313
|
+
else if (blockType === BlockTypes.Parallel) {
|
|
314
|
+
this.addPoint(`_parallel.${this.name}.${this.tmpPointId}`, false);
|
|
315
|
+
this.tmpPointId += 1;
|
|
316
|
+
}
|
|
317
|
+
this.scope.blockStack.set(this.scope.indentLevel, {
|
|
310
318
|
entered_at: [
|
|
311
319
|
this.scope.currentComponent,
|
|
312
320
|
this.scope.currentPin,
|
|
313
321
|
this.scope.currentWireId
|
|
314
322
|
],
|
|
315
|
-
|
|
323
|
+
inner_blocks: new Map(),
|
|
316
324
|
current_index: null,
|
|
317
|
-
type:
|
|
325
|
+
type: blockType,
|
|
318
326
|
});
|
|
319
|
-
this.print('enter
|
|
327
|
+
this.print('enter blocks');
|
|
320
328
|
}
|
|
321
|
-
|
|
322
|
-
const stackRef = this.scope.
|
|
323
|
-
const { type:
|
|
324
|
-
if (
|
|
325
|
-
const {
|
|
329
|
+
exitBlocks() {
|
|
330
|
+
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
331
|
+
const { type: blockType } = stackRef;
|
|
332
|
+
if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
|
|
333
|
+
const { final_point: finalPoint } = stackRef;
|
|
326
334
|
const [component, pin, wireId] = finalPoint;
|
|
327
335
|
this.scope.currentComponent = component;
|
|
328
336
|
this.scope.currentPin = pin;
|
|
@@ -333,65 +341,99 @@ export class ExecutionContext {
|
|
|
333
341
|
]);
|
|
334
342
|
}
|
|
335
343
|
}
|
|
336
|
-
|
|
344
|
+
else if (blockType === BlockTypes.Point) {
|
|
345
|
+
const { entered_at: [component, pin,] } = stackRef;
|
|
346
|
+
this.atComponent(component, pin, { addSequence: true });
|
|
347
|
+
}
|
|
348
|
+
this.print('exit blocks');
|
|
337
349
|
}
|
|
338
|
-
|
|
339
|
-
const stackRef = this.scope.
|
|
340
|
-
stackRef['
|
|
341
|
-
const { type:
|
|
342
|
-
stackRef['
|
|
350
|
+
enterBlock(blockIndex) {
|
|
351
|
+
const stackRef = this.scope.blockStack.get(this.scope.indentLevel);
|
|
352
|
+
stackRef['block_index'] = blockIndex;
|
|
353
|
+
const { type: blockType } = stackRef;
|
|
354
|
+
stackRef['inner_blocks'].set(blockIndex, {
|
|
343
355
|
last_net: null,
|
|
344
356
|
ignore_last_net: false,
|
|
345
357
|
});
|
|
346
|
-
if (
|
|
358
|
+
if (blockType === BlockTypes.Join || blockType === BlockTypes.Point) {
|
|
347
359
|
this.scope.currentComponent = null;
|
|
348
360
|
this.scope.currentPin = null;
|
|
349
361
|
this.scope.currentWireId = -1;
|
|
350
362
|
}
|
|
351
|
-
|
|
363
|
+
else if (blockType === BlockTypes.Parallel) {
|
|
364
|
+
const { entered_at: [component, pin,] } = stackRef;
|
|
365
|
+
this.atComponent(component, pin, { addSequence: true });
|
|
366
|
+
}
|
|
367
|
+
this.print(`enter inner block of type (${blockType}) >>>`);
|
|
352
368
|
this.scope.indentLevel += 1;
|
|
353
369
|
}
|
|
354
|
-
|
|
355
|
-
const stackRef = this.scope.
|
|
356
|
-
const { type:
|
|
357
|
-
const
|
|
358
|
-
|
|
370
|
+
exitBlock(blockIndex) {
|
|
371
|
+
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1);
|
|
372
|
+
const { type: blockType } = stackRef;
|
|
373
|
+
const blockIndexRef = stackRef['inner_blocks'].get(blockIndex);
|
|
374
|
+
blockIndexRef['last_net'] = [
|
|
359
375
|
this.scope.currentComponent,
|
|
360
376
|
this.scope.currentPin,
|
|
361
377
|
this.scope.currentWireId
|
|
362
378
|
];
|
|
363
|
-
stackRef['
|
|
364
|
-
const [preBranchComponent, preBranchPin, preBranchWireId] = stackRef['entered_at'];
|
|
379
|
+
stackRef['block_index'] = null;
|
|
365
380
|
this.scope.indentLevel -= 1;
|
|
366
|
-
this.print('exit inner
|
|
367
|
-
if (
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
381
|
+
this.print('exit inner block <<<');
|
|
382
|
+
if (blockType === BlockTypes.Branch) {
|
|
383
|
+
const { entered_at: [component, pin, wireId] } = stackRef;
|
|
384
|
+
this.atComponent(component, pin, { addSequence: true });
|
|
385
|
+
if (wireId !== -1) {
|
|
386
|
+
this.scope.sequence.push([SequenceAction.WireJump, wireId, 1]);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
else if (blockType === BlockTypes.Join || blockType === BlockTypes.Parallel) {
|
|
390
|
+
if (blockIndex === 0) {
|
|
391
|
+
const pointIdName = (blockType === BlockTypes.Join) ? '_join' : '_parallel';
|
|
392
|
+
this.addPoint(`${pointIdName}.${this.name}.${this.tmpPointId}`, false);
|
|
393
|
+
this.tmpPointId += 1;
|
|
394
|
+
stackRef['final_point'] = [
|
|
378
395
|
this.scope.currentComponent,
|
|
379
396
|
this.scope.currentPin,
|
|
380
397
|
this.scope.currentWireId
|
|
381
398
|
];
|
|
382
399
|
}
|
|
383
400
|
else {
|
|
384
|
-
const {
|
|
385
|
-
const [
|
|
386
|
-
this.toComponent(
|
|
401
|
+
const { final_point: finalPoint } = stackRef;
|
|
402
|
+
const [component, pin,] = finalPoint;
|
|
403
|
+
this.toComponent(component, pin, { addSequence: true });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
atPointBlock() {
|
|
408
|
+
const [component, pin,] = this.getPointBlockLocation();
|
|
409
|
+
this.atComponent(component, pin, {
|
|
410
|
+
addSequence: true
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
toPointBlock() {
|
|
414
|
+
const [component, pin,] = this.getPointBlockLocation();
|
|
415
|
+
this.toComponent(component, pin, {
|
|
416
|
+
addSequence: true
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
getPointBlockLocation() {
|
|
420
|
+
this.print('get block point');
|
|
421
|
+
for (let i = 0; i < this.scope.indentLevel; i++) {
|
|
422
|
+
const stackRef = this.scope.blockStack.get(this.scope.indentLevel - 1 - i);
|
|
423
|
+
const { entered_at } = stackRef;
|
|
424
|
+
const component = entered_at[0];
|
|
425
|
+
if (component.instanceName.startsWith('_point.')) {
|
|
426
|
+
return entered_at;
|
|
387
427
|
}
|
|
388
428
|
}
|
|
429
|
+
this.print('did not find block point');
|
|
430
|
+
return null;
|
|
389
431
|
}
|
|
390
432
|
breakBranch() {
|
|
391
433
|
this.print('break branch');
|
|
392
|
-
const branchesInfo = this.scope.
|
|
393
|
-
const branchIndex = branchesInfo['
|
|
394
|
-
const branchIndexRef = branchesInfo['
|
|
434
|
+
const branchesInfo = this.scope.blockStack.get(this.scope.indentLevel - 1);
|
|
435
|
+
const branchIndex = branchesInfo['block_index'];
|
|
436
|
+
const branchIndexRef = branchesInfo['inner_blocks'].get(branchIndex);
|
|
395
437
|
branchIndexRef['ignore_last_net'] = true;
|
|
396
438
|
}
|
|
397
439
|
createFunction(functionName, __runFunc) {
|
package/build/src/globals.js
CHANGED
|
@@ -48,8 +48,10 @@ export var ReferenceTypes;
|
|
|
48
48
|
ReferenceTypes["variable"] = "variable";
|
|
49
49
|
ReferenceTypes["instance"] = "instance";
|
|
50
50
|
})(ReferenceTypes || (ReferenceTypes = {}));
|
|
51
|
-
export var
|
|
52
|
-
(function (
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
export var BlockTypes;
|
|
52
|
+
(function (BlockTypes) {
|
|
53
|
+
BlockTypes[BlockTypes["Branch"] = 1] = "Branch";
|
|
54
|
+
BlockTypes[BlockTypes["Join"] = 2] = "Join";
|
|
55
|
+
BlockTypes[BlockTypes["Parallel"] = 3] = "Parallel";
|
|
56
|
+
BlockTypes[BlockTypes["Point"] = 4] = "Point";
|
|
57
|
+
})(BlockTypes || (BlockTypes = {}));
|
package/build/src/visitor.js
CHANGED
|
@@ -8,7 +8,7 @@ import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
|
|
|
8
8
|
import { PinTypes } from './objects/PinTypes.js';
|
|
9
9
|
import { UndeclaredReference } from './objects/types.js';
|
|
10
10
|
import { Logger } from './logger.js';
|
|
11
|
-
import {
|
|
11
|
+
import { BlockTypes, ComponentTypes, NoNetText } from './globals.js';
|
|
12
12
|
import { SymbolDrawingCommands } from './draw_symbols.js';
|
|
13
13
|
import { parseFileWithVisitor } from './parser.js';
|
|
14
14
|
export class MainVisitor extends ParseTreeVisitor {
|
|
@@ -186,26 +186,36 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
186
186
|
return this.getExecutor().addComponentExisting(component, pinValue);
|
|
187
187
|
}
|
|
188
188
|
visitAt_component_expr(ctx) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
addSequence: true,
|
|
192
|
-
cloneNetComponent: true
|
|
193
|
-
});
|
|
194
|
-
if (ctx.ID()) {
|
|
195
|
-
this.setComponentOrientation(currentPoint[0], currentPoint[1], ctx.ID().getText());
|
|
189
|
+
if (ctx.Point()) {
|
|
190
|
+
this.getExecutor().atPointBlock();
|
|
196
191
|
}
|
|
197
|
-
|
|
192
|
+
else {
|
|
193
|
+
const [component, pin] = this.visit(ctx.component_select_expr());
|
|
194
|
+
const currentPoint = this.getExecutor().atComponent(component, pin, {
|
|
195
|
+
addSequence: true,
|
|
196
|
+
cloneNetComponent: true
|
|
197
|
+
});
|
|
198
|
+
if (ctx.ID()) {
|
|
199
|
+
this.setComponentOrientation(currentPoint[0], currentPoint[1], ctx.ID().getText());
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return this.getExecutor().getCurrentPoint();
|
|
198
203
|
}
|
|
199
204
|
visitTo_component_expr(ctx) {
|
|
200
205
|
let currentPoint;
|
|
201
|
-
ctx.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
206
|
+
if (ctx.Point()) {
|
|
207
|
+
this.getExecutor().toPointBlock();
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
ctx.component_select_expr_list().forEach((item) => {
|
|
211
|
+
const [component, pin] = this.visit(item);
|
|
212
|
+
currentPoint = this.getExecutor().toComponent(component, pin, {
|
|
213
|
+
addSequence: true, cloneNetComponent: true
|
|
214
|
+
});
|
|
205
215
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
216
|
+
if (ctx.ID()) {
|
|
217
|
+
this.setComponentOrientation(currentPoint[0], currentPoint[1], ctx.ID().getText());
|
|
218
|
+
}
|
|
209
219
|
}
|
|
210
220
|
return this.getExecutor().getCurrentPoint();
|
|
211
221
|
}
|
|
@@ -222,25 +232,31 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
222
232
|
return [component, pinId];
|
|
223
233
|
}
|
|
224
234
|
}
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
let
|
|
228
|
-
if (
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
231
|
-
|
|
235
|
+
visitPath_blocks(ctx) {
|
|
236
|
+
const blocks = ctx.path_block_inner_list();
|
|
237
|
+
let blockType = BlockTypes.Branch;
|
|
238
|
+
if (blocks.length > 0) {
|
|
239
|
+
const firstBlock = blocks[0];
|
|
240
|
+
if (firstBlock.Branch()) {
|
|
241
|
+
blockType = BlockTypes.Branch;
|
|
242
|
+
}
|
|
243
|
+
else if (firstBlock.Join()) {
|
|
244
|
+
blockType = BlockTypes.Join;
|
|
245
|
+
}
|
|
246
|
+
else if (firstBlock.Parallel()) {
|
|
247
|
+
blockType = BlockTypes.Parallel;
|
|
232
248
|
}
|
|
233
|
-
else if (
|
|
234
|
-
|
|
249
|
+
else if (firstBlock.Point()) {
|
|
250
|
+
blockType = BlockTypes.Point;
|
|
235
251
|
}
|
|
236
252
|
}
|
|
237
|
-
this.getExecutor().
|
|
238
|
-
|
|
239
|
-
this.getExecutor().
|
|
253
|
+
this.getExecutor().enterBlocks(blockType);
|
|
254
|
+
blocks.forEach((branch, index) => {
|
|
255
|
+
this.getExecutor().enterBlock(index);
|
|
240
256
|
this.visit(branch);
|
|
241
|
-
this.getExecutor().
|
|
257
|
+
this.getExecutor().exitBlock(index);
|
|
242
258
|
});
|
|
243
|
-
this.getExecutor().
|
|
259
|
+
this.getExecutor().exitBlocks();
|
|
244
260
|
return this.getExecutor().getCurrentPoint();
|
|
245
261
|
}
|
|
246
262
|
visitBreak_keyword() {
|
package/package.json
CHANGED
|
@@ -17,11 +17,12 @@ Add: 'add';
|
|
|
17
17
|
At: 'at';
|
|
18
18
|
To: 'to';
|
|
19
19
|
Point: 'point';
|
|
20
|
+
Join: 'join';
|
|
21
|
+
Parallel: 'parallel';
|
|
20
22
|
|
|
21
23
|
Return: 'return';
|
|
22
24
|
Define: 'def';
|
|
23
25
|
Import: 'import';
|
|
24
|
-
Join: 'join';
|
|
25
26
|
|
|
26
27
|
If: 'if';
|
|
27
28
|
Not: '!';
|
|
@@ -47,18 +48,18 @@ expression: add_component_expr
|
|
|
47
48
|
| break_keyword
|
|
48
49
|
| function_def_expr
|
|
49
50
|
| wire_expr
|
|
50
|
-
| point_expr
|
|
51
51
|
| import_expr
|
|
52
52
|
| frame_expr
|
|
53
53
|
| atom_expr
|
|
54
54
|
|
|
55
55
|
| at_block
|
|
56
|
-
|
|
|
56
|
+
| path_blocks
|
|
57
|
+
| point_expr
|
|
57
58
|
;
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(Branch|Join) ':' NEWLINE INDENT (NEWLINE | expression)+ DEDENT;
|
|
60
|
+
path_blocks: path_block_inner+;
|
|
61
|
+
path_block_inner:
|
|
62
|
+
(Branch | Join | Parallel | Point) ':' NEWLINE INDENT (NEWLINE | expression)+ DEDENT;
|
|
62
63
|
|
|
63
64
|
property_set_expr2:
|
|
64
65
|
atom_expr ':' NEWLINE INDENT ( NEWLINE | assignment_expr2)+ DEDENT;
|
|
@@ -73,10 +74,10 @@ pin_select_expr: Pin (INTEGER_VALUE | STRING_VALUE);
|
|
|
73
74
|
// This does not have the 'pin' word
|
|
74
75
|
pin_select_expr2: INTEGER_VALUE | STRING_VALUE;
|
|
75
76
|
|
|
76
|
-
at_component_expr: At component_select_expr ID
|
|
77
|
+
at_component_expr: At ((component_select_expr ID?) | Point); // ID? is for orientation
|
|
77
78
|
// at_component_expr_next: 'at' component_select_expr (',' component_select_expr)*;
|
|
78
79
|
|
|
79
|
-
to_component_expr: To component_select_expr (',' component_select_expr)* ID
|
|
80
|
+
to_component_expr: To ((component_select_expr (',' component_select_expr)* ID?) | Point); // ID? is for orientation
|
|
80
81
|
// pin_select_expr_next: 'pin' INTEGER_VALUE (',' INTEGER_VALUE)?;
|
|
81
82
|
|
|
82
83
|
at_to_multiple_expr: At component_select_expr To component_select_expr (',' component_select_expr)* ':' NEWLINE INDENT (NEWLINE | at_to_multiple_line_expr) + DEDENT;
|