circuitscript 0.0.19 → 0.0.21
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 +48 -1
- package/__tests__/testParse.ts +17 -1
- package/build/src/antlr/CircuitScriptParser.js +142 -112
- package/build/src/antlr/CircuitScriptVisitor.js +2 -0
- package/build/src/execute.js +3 -0
- package/build/src/visitor.js +32 -16
- package/examples/example_arduino_uno.cst +312 -303
- package/package.json +1 -1
- package/src/antlr/CircuitScript.g4 +3 -2
- package/src/antlr/CircuitScriptParser.ts +117 -87
- package/src/antlr/CircuitScriptVisitor.ts +16 -0
- package/src/execute.ts +5 -0
- package/src/visitor.ts +49 -23
|
@@ -543,4 +543,51 @@ to gnd
|
|
|
543
543
|
['/GND', 'res_1.COMP_1_1k', 2],
|
|
544
544
|
['/GND', 'res_2.COMP_1_1k', 2],
|
|
545
545
|
['/GND', 'gnd:0', 1]
|
|
546
|
-
]);
|
|
546
|
+
]);
|
|
547
|
+
|
|
548
|
+
/*
|
|
549
|
+
Test that consecutive blocks with different block type
|
|
550
|
+
are parsed correctly.
|
|
551
|
+
*/
|
|
552
|
+
export const script16 = new ScriptTest(`
|
|
553
|
+
import lib
|
|
554
|
+
|
|
555
|
+
v5v = supply("5V")
|
|
556
|
+
gnd = dgnd()
|
|
557
|
+
|
|
558
|
+
join:
|
|
559
|
+
at v5v
|
|
560
|
+
wire down 20
|
|
561
|
+
add res(1k) down
|
|
562
|
+
wire down 20
|
|
563
|
+
|
|
564
|
+
join:
|
|
565
|
+
at v5v
|
|
566
|
+
wire down 20
|
|
567
|
+
add res(1k) down
|
|
568
|
+
wire left 100
|
|
569
|
+
|
|
570
|
+
point:
|
|
571
|
+
at v5v
|
|
572
|
+
wire right 20
|
|
573
|
+
add res(1k) right
|
|
574
|
+
wire right 20
|
|
575
|
+
to point
|
|
576
|
+
|
|
577
|
+
wire down 20
|
|
578
|
+
to gnd`, [
|
|
579
|
+
[ '/5V', 'v5v', 1 ],
|
|
580
|
+
[ '/5V', 'v5v:0', 1 ],
|
|
581
|
+
[ '/5V', 'res_0.COMP_1_1k', 1 ],
|
|
582
|
+
[ '/5V', 'v5v:1', 1 ],
|
|
583
|
+
[ '/5V', 'res_1.COMP_1_1k', 1 ],
|
|
584
|
+
[ '/5V', 'v5v:2', 1 ],
|
|
585
|
+
[ '/5V', 'res_2.COMP_1_1k', 1 ],
|
|
586
|
+
[ '/GND', 'gnd', 1 ],
|
|
587
|
+
[ '/GND', 'res_0.COMP_1_1k', 2 ],
|
|
588
|
+
[ '/GND', '_join.__.0', 1 ],
|
|
589
|
+
[ '/GND', 'res_1.COMP_1_1k', 2 ],
|
|
590
|
+
[ '/GND', '_point.__.1', 1 ],
|
|
591
|
+
[ '/GND', 'res_2.COMP_1_1k', 2 ],
|
|
592
|
+
[ '/GND', 'gnd:0', 1 ]
|
|
593
|
+
]);
|
package/__tests__/testParse.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { findItem, findItemByRefDes, runScript } from './helpers.js';
|
|
3
|
-
import { script1, script10, script11, script12, script13, script14, script15, script2,
|
|
3
|
+
import { script1, script10, script11, script12, script13, script14, script15, script16, script2,
|
|
4
4
|
script3, script6, script7, script8, script9 } from './parseScripts.js';
|
|
5
5
|
|
|
6
6
|
describe('test parsing', () => {
|
|
@@ -19,6 +19,7 @@ describe('test parsing', () => {
|
|
|
19
19
|
["corret nets after function call and also `join` keyword", script13],
|
|
20
20
|
["path with 'point' keyword", script14],
|
|
21
21
|
["path with 'parallel' keyword", script15],
|
|
22
|
+
["consecutive blocks with 'join' then 'point'", script16]
|
|
22
23
|
|
|
23
24
|
])('parse script - %s', async (description, scriptTest) => {
|
|
24
25
|
// Test only parsing, does not check the correctness of the
|
|
@@ -222,6 +223,21 @@ R1.mpn = "res-12345"
|
|
|
222
223
|
expect(item1.parameters.get('place')).toBe(false);
|
|
223
224
|
expect(item1.parameters.get('mpn')).toBe('res-12345');
|
|
224
225
|
});
|
|
226
|
+
|
|
227
|
+
test('unary minus operator', async () => {
|
|
228
|
+
const script = `
|
|
229
|
+
b = 20
|
|
230
|
+
print(b)
|
|
231
|
+
print(-b)
|
|
232
|
+
print(--b)
|
|
233
|
+
print(---b)
|
|
234
|
+
`;
|
|
235
|
+
|
|
236
|
+
const { hasError, visitor } = await runScript(script);
|
|
237
|
+
expect(hasError).toBe(false);
|
|
238
|
+
|
|
239
|
+
expect(visitor.printStream).toStrictEqual([20, -20, 20, -20]);
|
|
240
|
+
});
|
|
225
241
|
});
|
|
226
242
|
|
|
227
243
|
// This tests that an error is generated at the right position for
|
|
@@ -1715,67 +1715,66 @@ export default class CircuitScriptParser extends Parser {
|
|
|
1715
1715
|
{
|
|
1716
1716
|
this.state = 329;
|
|
1717
1717
|
this._errHandler.sync(this);
|
|
1718
|
-
switch (this._interp.adaptivePredict(this._input,
|
|
1718
|
+
switch (this._interp.adaptivePredict(this._input, 33, this._ctx)) {
|
|
1719
1719
|
case 1:
|
|
1720
1720
|
{
|
|
1721
|
-
localctx = new
|
|
1721
|
+
localctx = new RoundedBracketsExprContext(this, localctx);
|
|
1722
1722
|
this._ctx = localctx;
|
|
1723
1723
|
_prevctx = localctx;
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
this.state = 316;
|
|
1731
|
-
this.unary_operator();
|
|
1732
|
-
}
|
|
1733
|
-
break;
|
|
1734
|
-
}
|
|
1735
|
-
this.state = 321;
|
|
1736
|
-
this._errHandler.sync(this);
|
|
1737
|
-
switch (this._input.LA(1)) {
|
|
1738
|
-
case 6:
|
|
1739
|
-
case 30:
|
|
1740
|
-
case 36:
|
|
1741
|
-
case 38:
|
|
1742
|
-
case 39:
|
|
1743
|
-
case 40:
|
|
1744
|
-
case 41:
|
|
1745
|
-
case 42:
|
|
1746
|
-
{
|
|
1747
|
-
this.state = 319;
|
|
1748
|
-
this.value_expr();
|
|
1749
|
-
}
|
|
1750
|
-
break;
|
|
1751
|
-
case 29:
|
|
1752
|
-
case 31:
|
|
1753
|
-
case 37:
|
|
1754
|
-
{
|
|
1755
|
-
this.state = 320;
|
|
1756
|
-
this.atom_expr();
|
|
1757
|
-
}
|
|
1758
|
-
break;
|
|
1759
|
-
default:
|
|
1760
|
-
throw new NoViableAltException(this);
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1724
|
+
this.state = 316;
|
|
1725
|
+
this.match(CircuitScriptParser.OPEN_PAREN);
|
|
1726
|
+
this.state = 317;
|
|
1727
|
+
this.data_expr(0);
|
|
1728
|
+
this.state = 318;
|
|
1729
|
+
this.match(CircuitScriptParser.CLOSE_PAREN);
|
|
1763
1730
|
}
|
|
1764
1731
|
break;
|
|
1765
1732
|
case 2:
|
|
1766
1733
|
{
|
|
1767
|
-
localctx = new
|
|
1734
|
+
localctx = new ValueAtomExprContext(this, localctx);
|
|
1735
|
+
this._ctx = localctx;
|
|
1736
|
+
_prevctx = localctx;
|
|
1737
|
+
this.state = 322;
|
|
1738
|
+
this._errHandler.sync(this);
|
|
1739
|
+
switch (this._input.LA(1)) {
|
|
1740
|
+
case 6:
|
|
1741
|
+
case 30:
|
|
1742
|
+
case 36:
|
|
1743
|
+
case 38:
|
|
1744
|
+
case 39:
|
|
1745
|
+
case 40:
|
|
1746
|
+
case 41:
|
|
1747
|
+
case 42:
|
|
1748
|
+
{
|
|
1749
|
+
this.state = 320;
|
|
1750
|
+
this.value_expr();
|
|
1751
|
+
}
|
|
1752
|
+
break;
|
|
1753
|
+
case 29:
|
|
1754
|
+
case 31:
|
|
1755
|
+
case 37:
|
|
1756
|
+
{
|
|
1757
|
+
this.state = 321;
|
|
1758
|
+
this.atom_expr();
|
|
1759
|
+
}
|
|
1760
|
+
break;
|
|
1761
|
+
default:
|
|
1762
|
+
throw new NoViableAltException(this);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
break;
|
|
1766
|
+
case 3:
|
|
1767
|
+
{
|
|
1768
|
+
localctx = new UnaryOperatorExprContext(this, localctx);
|
|
1768
1769
|
this._ctx = localctx;
|
|
1769
1770
|
_prevctx = localctx;
|
|
1770
|
-
this.state = 323;
|
|
1771
|
-
this.match(CircuitScriptParser.OPEN_PAREN);
|
|
1772
1771
|
this.state = 324;
|
|
1773
|
-
this.
|
|
1772
|
+
this.unary_operator();
|
|
1774
1773
|
this.state = 325;
|
|
1775
|
-
this.
|
|
1774
|
+
this.data_expr(6);
|
|
1776
1775
|
}
|
|
1777
1776
|
break;
|
|
1778
|
-
case
|
|
1777
|
+
case 4:
|
|
1779
1778
|
{
|
|
1780
1779
|
localctx = new DataExprContext(this, localctx);
|
|
1781
1780
|
this._ctx = localctx;
|
|
@@ -1784,7 +1783,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
1784
1783
|
this.create_component_expr();
|
|
1785
1784
|
}
|
|
1786
1785
|
break;
|
|
1787
|
-
case
|
|
1786
|
+
case 5:
|
|
1788
1787
|
{
|
|
1789
1788
|
localctx = new DataExprContext(this, localctx);
|
|
1790
1789
|
this._ctx = localctx;
|
|
@@ -1797,7 +1796,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
1797
1796
|
this._ctx.stop = this._input.LT(-1);
|
|
1798
1797
|
this.state = 343;
|
|
1799
1798
|
this._errHandler.sync(this);
|
|
1800
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
1799
|
+
_alt = this._interp.adaptivePredict(this._input, 35, this._ctx);
|
|
1801
1800
|
while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
|
|
1802
1801
|
if (_alt === 1) {
|
|
1803
1802
|
if (this._parseListeners != null) {
|
|
@@ -1807,7 +1806,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
1807
1806
|
{
|
|
1808
1807
|
this.state = 341;
|
|
1809
1808
|
this._errHandler.sync(this);
|
|
1810
|
-
switch (this._interp.adaptivePredict(this._input,
|
|
1809
|
+
switch (this._interp.adaptivePredict(this._input, 34, this._ctx)) {
|
|
1811
1810
|
case 1:
|
|
1812
1811
|
{
|
|
1813
1812
|
localctx = new MultiplyExprContext(this, new Data_exprContext(this, _parentctx, _parentState));
|
|
@@ -1869,7 +1868,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
1869
1868
|
}
|
|
1870
1869
|
this.state = 345;
|
|
1871
1870
|
this._errHandler.sync(this);
|
|
1872
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
1871
|
+
_alt = this._interp.adaptivePredict(this._input, 35, this._ctx);
|
|
1873
1872
|
}
|
|
1874
1873
|
}
|
|
1875
1874
|
}
|
|
@@ -2175,7 +2174,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2175
2174
|
let _alt;
|
|
2176
2175
|
this.state = 408;
|
|
2177
2176
|
this._errHandler.sync(this);
|
|
2178
|
-
switch (this._interp.adaptivePredict(this._input,
|
|
2177
|
+
switch (this._interp.adaptivePredict(this._input, 45, this._ctx)) {
|
|
2179
2178
|
case 1:
|
|
2180
2179
|
this.enterOuterAlt(localctx, 1);
|
|
2181
2180
|
{
|
|
@@ -2183,7 +2182,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2183
2182
|
this.match(CircuitScriptParser.ID);
|
|
2184
2183
|
this.state = 384;
|
|
2185
2184
|
this._errHandler.sync(this);
|
|
2186
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
2185
|
+
_alt = this._interp.adaptivePredict(this._input, 42, this._ctx);
|
|
2187
2186
|
while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
|
|
2188
2187
|
if (_alt === 1) {
|
|
2189
2188
|
{
|
|
@@ -2197,7 +2196,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2197
2196
|
}
|
|
2198
2197
|
this.state = 386;
|
|
2199
2198
|
this._errHandler.sync(this);
|
|
2200
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
2199
|
+
_alt = this._interp.adaptivePredict(this._input, 42, this._ctx);
|
|
2201
2200
|
}
|
|
2202
2201
|
this.state = 393;
|
|
2203
2202
|
this._errHandler.sync(this);
|
|
@@ -2290,7 +2289,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2290
2289
|
this.match(CircuitScriptParser.ID);
|
|
2291
2290
|
this.state = 417;
|
|
2292
2291
|
this._errHandler.sync(this);
|
|
2293
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
2292
|
+
_alt = this._interp.adaptivePredict(this._input, 47, this._ctx);
|
|
2294
2293
|
while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
|
|
2295
2294
|
if (_alt === 1) {
|
|
2296
2295
|
{
|
|
@@ -2302,7 +2301,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2302
2301
|
}
|
|
2303
2302
|
this.state = 419;
|
|
2304
2303
|
this._errHandler.sync(this);
|
|
2305
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
2304
|
+
_alt = this._interp.adaptivePredict(this._input, 47, this._ctx);
|
|
2306
2305
|
}
|
|
2307
2306
|
}
|
|
2308
2307
|
}
|
|
@@ -2395,7 +2394,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2395
2394
|
this.match(CircuitScriptParser.Divide);
|
|
2396
2395
|
this.state = 434;
|
|
2397
2396
|
this._errHandler.sync(this);
|
|
2398
|
-
switch (this._interp.adaptivePredict(this._input,
|
|
2397
|
+
switch (this._interp.adaptivePredict(this._input, 51, this._ctx)) {
|
|
2399
2398
|
case 1:
|
|
2400
2399
|
{
|
|
2401
2400
|
this.state = 433;
|
|
@@ -2598,7 +2597,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2598
2597
|
this.match(CircuitScriptParser.T__0);
|
|
2599
2598
|
this.state = 472;
|
|
2600
2599
|
this._errHandler.sync(this);
|
|
2601
|
-
switch (this._interp.adaptivePredict(this._input,
|
|
2600
|
+
switch (this._interp.adaptivePredict(this._input, 56, this._ctx)) {
|
|
2602
2601
|
case 1:
|
|
2603
2602
|
{
|
|
2604
2603
|
this.state = 467;
|
|
@@ -2844,7 +2843,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2844
2843
|
this.match(CircuitScriptParser.ID);
|
|
2845
2844
|
this.state = 508;
|
|
2846
2845
|
this._errHandler.sync(this);
|
|
2847
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
2846
|
+
_alt = this._interp.adaptivePredict(this._input, 61, this._ctx);
|
|
2848
2847
|
while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) {
|
|
2849
2848
|
if (_alt === 1) {
|
|
2850
2849
|
{
|
|
@@ -2863,7 +2862,7 @@ export default class CircuitScriptParser extends Parser {
|
|
|
2863
2862
|
}
|
|
2864
2863
|
this.state = 510;
|
|
2865
2864
|
this._errHandler.sync(this);
|
|
2866
|
-
_alt = this._interp.adaptivePredict(this._input,
|
|
2865
|
+
_alt = this._interp.adaptivePredict(this._input, 61, this._ctx);
|
|
2867
2866
|
}
|
|
2868
2867
|
}
|
|
2869
2868
|
}
|
|
@@ -3055,40 +3054,40 @@ export default class CircuitScriptParser extends Parser {
|
|
|
3055
3054
|
1, 24, 1, 24, 1, 24, 5, 24, 285, 8, 24, 10, 24, 12, 24, 288, 9, 24, 1, 24, 1, 24, 5, 24, 292, 8,
|
|
3056
3055
|
24, 10, 24, 12, 24, 295, 9, 24, 1, 24, 1, 24, 1, 24, 5, 24, 300, 8, 24, 10, 24, 12, 24, 303, 9,
|
|
3057
3056
|
24, 3, 24, 305, 8, 24, 1, 25, 1, 25, 1, 25, 1, 25, 1, 26, 1, 26, 1, 26, 1, 26, 1, 26, 1, 27, 1, 27,
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
33, 1, 33,
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3057
|
+
1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 3, 27, 323, 8, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 3, 27, 330,
|
|
3058
|
+
8, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 1, 27, 5, 27, 342, 8, 27, 10,
|
|
3059
|
+
27, 12, 27, 345, 9, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 3, 30, 352, 8, 30, 1, 30, 1, 30, 3, 30,
|
|
3060
|
+
356, 8, 30, 1, 31, 1, 31, 1, 31, 1, 31, 3, 31, 362, 8, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31, 1, 31,
|
|
3061
|
+
4, 31, 370, 8, 31, 11, 31, 12, 31, 371, 1, 31, 1, 31, 1, 32, 1, 32, 3, 32, 378, 8, 32, 1, 33, 1,
|
|
3062
|
+
33, 1, 33, 5, 33, 383, 8, 33, 10, 33, 12, 33, 386, 9, 33, 1, 33, 1, 33, 1, 33, 1, 33, 5, 33, 392,
|
|
3063
|
+
8, 33, 10, 33, 12, 33, 395, 9, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 1, 33, 5, 33, 404, 8,
|
|
3064
|
+
33, 10, 33, 12, 33, 407, 9, 33, 3, 33, 409, 8, 33, 1, 34, 3, 34, 412, 8, 34, 1, 34, 1, 34, 5, 34,
|
|
3065
|
+
416, 8, 34, 10, 34, 12, 34, 419, 9, 34, 1, 35, 1, 35, 3, 35, 423, 8, 35, 1, 35, 1, 35, 1, 35, 3,
|
|
3066
|
+
35, 428, 8, 35, 1, 36, 3, 36, 431, 8, 36, 1, 36, 1, 36, 3, 36, 435, 8, 36, 1, 37, 1, 37, 1, 37, 1,
|
|
3067
|
+
38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 1, 38, 4, 38, 447, 8, 38, 11, 38, 12, 38, 448, 1, 38, 1, 38,
|
|
3068
|
+
1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 1, 39, 4, 39, 460, 8, 39, 11, 39, 12, 39, 461, 1, 39, 1,
|
|
3069
|
+
39, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 1, 40, 3, 40, 473, 8, 40, 1, 41, 1, 41, 1, 41, 1, 41,
|
|
3070
|
+
1, 42, 1, 42, 1, 43, 1, 43, 1, 43, 1, 43, 4, 43, 485, 8, 43, 11, 43, 12, 43, 486, 1, 43, 1, 43, 1,
|
|
3071
|
+
43, 1, 43, 5, 43, 493, 8, 43, 10, 43, 12, 43, 496, 9, 43, 3, 43, 498, 8, 43, 1, 44, 1, 44, 1, 44,
|
|
3072
|
+
1, 44, 1, 45, 1, 45, 1, 45, 5, 45, 507, 8, 45, 10, 45, 12, 45, 510, 9, 45, 1, 46, 1, 46, 1, 46, 1,
|
|
3073
|
+
47, 1, 47, 1, 47, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 1, 48, 4, 48, 524, 8, 48, 11, 48, 12, 48, 525,
|
|
3074
|
+
1, 48, 1, 48, 1, 48, 0, 1, 54, 49, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32,
|
|
3075
|
+
34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80,
|
|
3076
|
+
82, 84, 86, 88, 90, 92, 94, 96, 0, 11, 2, 0, 10, 10, 19, 21, 1, 0, 37, 38, 2, 0, 38, 38, 41, 41,
|
|
3077
|
+
2, 0, 35, 35, 38, 38, 1, 0, 31, 32, 1, 0, 29, 30, 1, 0, 27, 28, 2, 0, 26, 26, 30, 30, 2, 0, 36, 36,
|
|
3078
|
+
38, 42, 2, 0, 15, 15, 37, 37, 2, 0, 37, 38, 41, 41, 562, 0, 100, 1, 0, 0, 0, 2, 122, 1, 0, 0, 0, 4,
|
|
3079
|
+
125, 1, 0, 0, 0, 6, 129, 1, 0, 0, 0, 8, 141, 1, 0, 0, 0, 10, 153, 1, 0, 0, 0, 12, 159, 1, 0, 0, 0, 14,
|
|
3080
|
+
164, 1, 0, 0, 0, 16, 171, 1, 0, 0, 0, 18, 173, 1, 0, 0, 0, 20, 176, 1, 0, 0, 0, 22, 178, 1, 0, 0, 0,
|
|
3081
|
+
24, 186, 1, 0, 0, 0, 26, 201, 1, 0, 0, 0, 28, 223, 1, 0, 0, 0, 30, 233, 1, 0, 0, 0, 32, 235, 1, 0,
|
|
3082
|
+
0, 0, 34, 249, 1, 0, 0, 0, 36, 251, 1, 0, 0, 0, 38, 259, 1, 0, 0, 0, 40, 261, 1, 0, 0, 0, 42, 271,
|
|
3083
|
+
1, 0, 0, 0, 44, 273, 1, 0, 0, 0, 46, 277, 1, 0, 0, 0, 48, 304, 1, 0, 0, 0, 50, 306, 1, 0, 0, 0, 52,
|
|
3084
|
+
310, 1, 0, 0, 0, 54, 329, 1, 0, 0, 0, 56, 346, 1, 0, 0, 0, 58, 348, 1, 0, 0, 0, 60, 355, 1, 0, 0, 0,
|
|
3085
|
+
62, 357, 1, 0, 0, 0, 64, 377, 1, 0, 0, 0, 66, 408, 1, 0, 0, 0, 68, 411, 1, 0, 0, 0, 70, 427, 1, 0,
|
|
3086
|
+
0, 0, 72, 430, 1, 0, 0, 0, 74, 436, 1, 0, 0, 0, 76, 439, 1, 0, 0, 0, 78, 452, 1, 0, 0, 0, 80, 465,
|
|
3087
|
+
1, 0, 0, 0, 82, 474, 1, 0, 0, 0, 84, 478, 1, 0, 0, 0, 86, 497, 1, 0, 0, 0, 88, 499, 1, 0, 0, 0, 90,
|
|
3088
|
+
503, 1, 0, 0, 0, 92, 511, 1, 0, 0, 0, 94, 514, 1, 0, 0, 0, 96, 517, 1, 0, 0, 0, 98, 101, 3, 2, 1, 0,
|
|
3089
|
+
99, 101, 5, 45, 0, 0, 100, 98, 1, 0, 0, 0, 100, 99, 1, 0, 0, 0, 101, 102, 1, 0, 0, 0, 102, 100, 1,
|
|
3090
|
+
0, 0, 0, 102, 103, 1, 0, 0, 0, 103, 104, 1, 0, 0, 0, 104, 105, 5, 0, 0, 1, 105, 1, 1, 0, 0, 0, 106,
|
|
3092
3091
|
123, 3, 14, 7, 0, 107, 123, 3, 24, 12, 0, 108, 123, 3, 22, 11, 0, 109, 123, 3, 44, 22, 0, 110,
|
|
3093
3092
|
123, 3, 50, 25, 0, 111, 123, 3, 8, 4, 0, 112, 123, 3, 52, 26, 0, 113, 123, 3, 42, 21, 0, 114, 123,
|
|
3094
3093
|
3, 62, 31, 0, 115, 123, 3, 90, 45, 0, 116, 123, 3, 94, 47, 0, 117, 123, 3, 96, 48, 0, 118, 123,
|
|
@@ -3146,11 +3145,11 @@ export default class CircuitScriptParser extends Parser {
|
|
|
3146
3145
|
0, 0, 0, 302, 305, 1, 0, 0, 0, 303, 301, 1, 0, 0, 0, 304, 281, 1, 0, 0, 0, 304, 296, 1, 0, 0, 0, 305,
|
|
3147
3146
|
49, 1, 0, 0, 0, 306, 307, 3, 68, 34, 0, 307, 308, 5, 3, 0, 0, 308, 309, 3, 54, 27, 0, 309, 51, 1,
|
|
3148
3147
|
0, 0, 0, 310, 311, 5, 4, 0, 0, 311, 312, 5, 37, 0, 0, 312, 313, 5, 3, 0, 0, 313, 314, 3, 54, 27,
|
|
3149
|
-
0, 314, 53, 1, 0, 0, 0, 315,
|
|
3150
|
-
|
|
3151
|
-
1, 0, 0, 0,
|
|
3152
|
-
|
|
3153
|
-
329,
|
|
3148
|
+
0, 314, 53, 1, 0, 0, 0, 315, 316, 6, 27, -1, 0, 316, 317, 5, 33, 0, 0, 317, 318, 3, 54, 27, 0, 318,
|
|
3149
|
+
319, 5, 34, 0, 0, 319, 330, 1, 0, 0, 0, 320, 323, 3, 60, 30, 0, 321, 323, 3, 68, 34, 0, 322, 320,
|
|
3150
|
+
1, 0, 0, 0, 322, 321, 1, 0, 0, 0, 323, 330, 1, 0, 0, 0, 324, 325, 3, 58, 29, 0, 325, 326, 3, 54,
|
|
3151
|
+
27, 6, 326, 330, 1, 0, 0, 0, 327, 330, 3, 76, 38, 0, 328, 330, 3, 78, 39, 0, 329, 315, 1, 0, 0,
|
|
3152
|
+
0, 329, 322, 1, 0, 0, 0, 329, 324, 1, 0, 0, 0, 329, 327, 1, 0, 0, 0, 329, 328, 1, 0, 0, 0, 330, 343,
|
|
3154
3153
|
1, 0, 0, 0, 331, 332, 10, 5, 0, 0, 332, 333, 7, 4, 0, 0, 333, 342, 3, 54, 27, 6, 334, 335, 10, 4,
|
|
3155
3154
|
0, 0, 335, 336, 7, 5, 0, 0, 336, 342, 3, 54, 27, 5, 337, 338, 10, 3, 0, 0, 338, 339, 3, 56, 28,
|
|
3156
3155
|
0, 339, 340, 3, 54, 27, 4, 340, 342, 1, 0, 0, 0, 341, 331, 1, 0, 0, 0, 341, 334, 1, 0, 0, 0, 341,
|
|
@@ -3203,10 +3202,10 @@ export default class CircuitScriptParser extends Parser {
|
|
|
3203
3202
|
5, 8, 0, 0, 518, 519, 5, 1, 0, 0, 519, 520, 5, 45, 0, 0, 520, 523, 5, 47, 0, 0, 521, 524, 5, 45,
|
|
3204
3203
|
0, 0, 522, 524, 3, 2, 1, 0, 523, 521, 1, 0, 0, 0, 523, 522, 1, 0, 0, 0, 524, 525, 1, 0, 0, 0, 525,
|
|
3205
3204
|
523, 1, 0, 0, 0, 525, 526, 1, 0, 0, 0, 526, 527, 1, 0, 0, 0, 527, 528, 5, 48, 0, 0, 528, 97, 1, 0,
|
|
3206
|
-
0, 0,
|
|
3207
|
-
199, 209, 217, 219, 230, 241, 243, 249, 255, 259, 265, 267, 286, 293, 301, 304,
|
|
3208
|
-
|
|
3209
|
-
|
|
3205
|
+
0, 0, 64, 100, 102, 122, 127, 135, 137, 147, 149, 159, 162, 167, 171, 181, 184, 192, 196,
|
|
3206
|
+
199, 209, 217, 219, 230, 241, 243, 249, 255, 259, 265, 267, 286, 293, 301, 304, 322, 329,
|
|
3207
|
+
341, 343, 351, 355, 361, 369, 371, 377, 384, 393, 405, 408, 411, 417, 422, 427, 430, 434,
|
|
3208
|
+
446, 448, 459, 461, 472, 484, 486, 494, 497, 508, 523, 525];
|
|
3210
3209
|
static __ATN;
|
|
3211
3210
|
static get _ATN() {
|
|
3212
3211
|
if (!CircuitScriptParser.__ATN) {
|
|
@@ -4083,15 +4082,6 @@ export class DataExprContext extends Data_exprContext {
|
|
|
4083
4082
|
super(parser, ctx.parentCtx, ctx.invokingState);
|
|
4084
4083
|
super.copyFrom(ctx);
|
|
4085
4084
|
}
|
|
4086
|
-
value_expr() {
|
|
4087
|
-
return this.getTypedRuleContext(Value_exprContext, 0);
|
|
4088
|
-
}
|
|
4089
|
-
atom_expr() {
|
|
4090
|
-
return this.getTypedRuleContext(Atom_exprContext, 0);
|
|
4091
|
-
}
|
|
4092
|
-
unary_operator() {
|
|
4093
|
-
return this.getTypedRuleContext(Unary_operatorContext, 0);
|
|
4094
|
-
}
|
|
4095
4085
|
create_component_expr() {
|
|
4096
4086
|
return this.getTypedRuleContext(Create_component_exprContext, 0);
|
|
4097
4087
|
}
|
|
@@ -4107,6 +4097,46 @@ export class DataExprContext extends Data_exprContext {
|
|
|
4107
4097
|
}
|
|
4108
4098
|
}
|
|
4109
4099
|
}
|
|
4100
|
+
export class UnaryOperatorExprContext extends Data_exprContext {
|
|
4101
|
+
constructor(parser, ctx) {
|
|
4102
|
+
super(parser, ctx.parentCtx, ctx.invokingState);
|
|
4103
|
+
super.copyFrom(ctx);
|
|
4104
|
+
}
|
|
4105
|
+
unary_operator() {
|
|
4106
|
+
return this.getTypedRuleContext(Unary_operatorContext, 0);
|
|
4107
|
+
}
|
|
4108
|
+
data_expr() {
|
|
4109
|
+
return this.getTypedRuleContext(Data_exprContext, 0);
|
|
4110
|
+
}
|
|
4111
|
+
accept(visitor) {
|
|
4112
|
+
if (visitor.visitUnaryOperatorExpr) {
|
|
4113
|
+
return visitor.visitUnaryOperatorExpr(this);
|
|
4114
|
+
}
|
|
4115
|
+
else {
|
|
4116
|
+
return visitor.visitChildren(this);
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
}
|
|
4120
|
+
export class ValueAtomExprContext extends Data_exprContext {
|
|
4121
|
+
constructor(parser, ctx) {
|
|
4122
|
+
super(parser, ctx.parentCtx, ctx.invokingState);
|
|
4123
|
+
super.copyFrom(ctx);
|
|
4124
|
+
}
|
|
4125
|
+
value_expr() {
|
|
4126
|
+
return this.getTypedRuleContext(Value_exprContext, 0);
|
|
4127
|
+
}
|
|
4128
|
+
atom_expr() {
|
|
4129
|
+
return this.getTypedRuleContext(Atom_exprContext, 0);
|
|
4130
|
+
}
|
|
4131
|
+
accept(visitor) {
|
|
4132
|
+
if (visitor.visitValueAtomExpr) {
|
|
4133
|
+
return visitor.visitValueAtomExpr(this);
|
|
4134
|
+
}
|
|
4135
|
+
else {
|
|
4136
|
+
return visitor.visitChildren(this);
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4110
4140
|
export class BinaryOperatorExprContext extends Data_exprContext {
|
|
4111
4141
|
constructor(parser, ctx) {
|
|
4112
4142
|
super(parser, ctx.parentCtx, ctx.invokingState);
|
|
@@ -30,6 +30,8 @@ export default class CircuitScriptVisitor extends ParseTreeVisitor {
|
|
|
30
30
|
visitAdditionExpr;
|
|
31
31
|
visitMultiplyExpr;
|
|
32
32
|
visitDataExpr;
|
|
33
|
+
visitUnaryOperatorExpr;
|
|
34
|
+
visitValueAtomExpr;
|
|
33
35
|
visitBinaryOperatorExpr;
|
|
34
36
|
visitRoundedBracketsExpr;
|
|
35
37
|
visitBinary_operator;
|
package/build/src/execute.js
CHANGED
|
@@ -616,6 +616,9 @@ export class ExecutionContext {
|
|
|
616
616
|
this.print('-- done merging scope --');
|
|
617
617
|
}
|
|
618
618
|
addWire(segments) {
|
|
619
|
+
if (this.scope.currentComponent === null) {
|
|
620
|
+
throw "No current component";
|
|
621
|
+
}
|
|
619
622
|
const tmp = segments.map(item => {
|
|
620
623
|
const [direction, value = null] = item;
|
|
621
624
|
return {
|
package/build/src/visitor.js
CHANGED
|
@@ -234,27 +234,34 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
234
234
|
}
|
|
235
235
|
visitPath_blocks(ctx) {
|
|
236
236
|
const blocks = ctx.path_block_inner_list();
|
|
237
|
+
let blockIndex = 0;
|
|
237
238
|
let blockType = BlockTypes.Branch;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (
|
|
239
|
+
let prevBlockType = null;
|
|
240
|
+
blocks.forEach((block, index) => {
|
|
241
|
+
if (block.Branch()) {
|
|
241
242
|
blockType = BlockTypes.Branch;
|
|
242
243
|
}
|
|
243
|
-
else if (
|
|
244
|
+
else if (block.Join()) {
|
|
244
245
|
blockType = BlockTypes.Join;
|
|
245
246
|
}
|
|
246
|
-
else if (
|
|
247
|
+
else if (block.Parallel()) {
|
|
247
248
|
blockType = BlockTypes.Parallel;
|
|
248
249
|
}
|
|
249
|
-
else if (
|
|
250
|
+
else if (block.Point()) {
|
|
250
251
|
blockType = BlockTypes.Point;
|
|
251
252
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
253
|
+
if (prevBlockType !== blockType) {
|
|
254
|
+
if (index > 0) {
|
|
255
|
+
this.getExecutor().exitBlocks();
|
|
256
|
+
}
|
|
257
|
+
this.getExecutor().enterBlocks(blockType);
|
|
258
|
+
blockIndex = 0;
|
|
259
|
+
}
|
|
260
|
+
this.getExecutor().enterBlock(blockIndex);
|
|
261
|
+
this.visit(block);
|
|
262
|
+
this.getExecutor().exitBlock(blockIndex);
|
|
263
|
+
blockIndex += 1;
|
|
264
|
+
prevBlockType = blockType;
|
|
258
265
|
});
|
|
259
266
|
this.getExecutor().exitBlocks();
|
|
260
267
|
return this.getExecutor().getCurrentPoint();
|
|
@@ -386,7 +393,7 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
386
393
|
}
|
|
387
394
|
return [component, pinValue];
|
|
388
395
|
}
|
|
389
|
-
|
|
396
|
+
visitValueAtomExpr(ctx) {
|
|
390
397
|
let value;
|
|
391
398
|
if (ctx.value_expr()) {
|
|
392
399
|
value = this.visit(ctx.value_expr());
|
|
@@ -400,8 +407,13 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
400
407
|
value = reference.value;
|
|
401
408
|
}
|
|
402
409
|
}
|
|
403
|
-
|
|
404
|
-
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
412
|
+
visitUnaryOperatorExpr(ctx) {
|
|
413
|
+
const value = this.visit(ctx.data_expr());
|
|
414
|
+
const unaryOp = ctx.unary_operator();
|
|
415
|
+
if (unaryOp) {
|
|
416
|
+
if (unaryOp.Not()) {
|
|
405
417
|
if (typeof value === "boolean") {
|
|
406
418
|
value = !value;
|
|
407
419
|
}
|
|
@@ -409,7 +421,7 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
409
421
|
throw "Failed to do Not operator";
|
|
410
422
|
}
|
|
411
423
|
}
|
|
412
|
-
else if (
|
|
424
|
+
else if (unaryOp.Minus()) {
|
|
413
425
|
if (typeof value === 'number') {
|
|
414
426
|
return -value;
|
|
415
427
|
}
|
|
@@ -418,6 +430,10 @@ export class MainVisitor extends ParseTreeVisitor {
|
|
|
418
430
|
}
|
|
419
431
|
}
|
|
420
432
|
}
|
|
433
|
+
return value;
|
|
434
|
+
}
|
|
435
|
+
visitDataExpr(ctx) {
|
|
436
|
+
let value;
|
|
421
437
|
if (ctx.create_component_expr()) {
|
|
422
438
|
value = this.visit(ctx.create_component_expr());
|
|
423
439
|
}
|