mevento 1.4.0 → 1.9.0
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/esm2020/lib/mevento.mjs +173 -57
- package/fesm2015/mevento.mjs +181 -59
- package/fesm2015/mevento.mjs.map +1 -1
- package/fesm2020/mevento.mjs +173 -57
- package/fesm2020/mevento.mjs.map +1 -1
- package/lib/mevento.d.ts +31 -6
- package/package.json +1 -1
package/fesm2015/mevento.mjs
CHANGED
|
@@ -79,6 +79,7 @@ TokenType.with = 39;
|
|
|
79
79
|
TokenType.in = 40;
|
|
80
80
|
TokenType.TILL = 41;
|
|
81
81
|
TokenType.BREAK = 42;
|
|
82
|
+
TokenType.CONTINUE = 43;
|
|
82
83
|
class Token {
|
|
83
84
|
constructor(type, value, line = 1, col = 1) {
|
|
84
85
|
this.type = type;
|
|
@@ -145,6 +146,7 @@ class Lexer {
|
|
|
145
146
|
return this._source;
|
|
146
147
|
}
|
|
147
148
|
_resolveLanguage() {
|
|
149
|
+
var _a;
|
|
148
150
|
let token = this.nextToken();
|
|
149
151
|
if (token.type === TokenType.less) {
|
|
150
152
|
// language setting
|
|
@@ -153,7 +155,7 @@ class Lexer {
|
|
|
153
155
|
error(token);
|
|
154
156
|
}
|
|
155
157
|
const lang = idToken.value.toString();
|
|
156
|
-
this._language = Lexer.languages.find((element) => element.lang === lang)
|
|
158
|
+
this._language = (_a = Lexer.languages.find((element) => element.lang === lang)) !== null && _a !== void 0 ? _a : Lexer._defaultLanguage;
|
|
157
159
|
token = this.nextToken();
|
|
158
160
|
if (token.type !== TokenType.great) {
|
|
159
161
|
error(token);
|
|
@@ -218,6 +220,7 @@ class Lexer {
|
|
|
218
220
|
return false;
|
|
219
221
|
}
|
|
220
222
|
_id() {
|
|
223
|
+
var _a, _b;
|
|
221
224
|
let ret = "";
|
|
222
225
|
const lastC = this._col;
|
|
223
226
|
const lastP = this._position;
|
|
@@ -227,9 +230,9 @@ class Lexer {
|
|
|
227
230
|
this._advance();
|
|
228
231
|
}
|
|
229
232
|
const translatedId = this._language
|
|
230
|
-
? (this._language.keywords[ret])
|
|
233
|
+
? (_a = (this._language.keywords[ret])) !== null && _a !== void 0 ? _a : ret
|
|
231
234
|
: ret;
|
|
232
|
-
return Lexer.RESERVED[translatedId]
|
|
235
|
+
return (_b = Lexer.RESERVED[translatedId]) !== null && _b !== void 0 ? _b : new Token(TokenType.id, ret, line, lastC);
|
|
233
236
|
}
|
|
234
237
|
_isLineEnd(c) {
|
|
235
238
|
return c === 10 ||
|
|
@@ -490,6 +493,7 @@ Lexer._defaultLanguage = new LexerDictionary("en", {
|
|
|
490
493
|
"till": "till",
|
|
491
494
|
"in": "in",
|
|
492
495
|
"break": "break",
|
|
496
|
+
"continue": "continue",
|
|
493
497
|
});
|
|
494
498
|
Lexer.languages = [
|
|
495
499
|
Lexer._defaultLanguage,
|
|
@@ -502,11 +506,12 @@ Lexer.languages = [
|
|
|
502
506
|
"tanque": "while",
|
|
503
507
|
"pour": "for",
|
|
504
508
|
"avec": "with",
|
|
505
|
-
"
|
|
509
|
+
"mont": "up",
|
|
506
510
|
"desc": "down",
|
|
507
511
|
"jusqua": "till",
|
|
508
512
|
"dans": "in",
|
|
509
513
|
"couper": "break",
|
|
514
|
+
"continuer": "continue",
|
|
510
515
|
}),
|
|
511
516
|
new LexerDictionary("bm", {
|
|
512
517
|
"nii": "if",
|
|
@@ -522,6 +527,7 @@ Lexer.languages = [
|
|
|
522
527
|
"kata": "till",
|
|
523
528
|
"kono": "in",
|
|
524
529
|
"tike": "break",
|
|
530
|
+
"ipan": "continue",
|
|
525
531
|
}),
|
|
526
532
|
];
|
|
527
533
|
Lexer.RESERVED = {
|
|
@@ -538,6 +544,7 @@ Lexer.RESERVED = {
|
|
|
538
544
|
"till": Token.from(TokenType.TILL, "till"),
|
|
539
545
|
"in": Token.from(TokenType.in, "in"),
|
|
540
546
|
"break": Token.from(TokenType.BREAK, "break"),
|
|
547
|
+
"continue": Token.from(TokenType.CONTINUE, "continue"),
|
|
541
548
|
};
|
|
542
549
|
/**
|
|
543
550
|
* Parser
|
|
@@ -744,6 +751,11 @@ class BreakAST extends AST {
|
|
|
744
751
|
super(line, col);
|
|
745
752
|
}
|
|
746
753
|
}
|
|
754
|
+
class ContinueAST extends AST {
|
|
755
|
+
constructor(line, col) {
|
|
756
|
+
super(line, col);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
747
759
|
class Parser {
|
|
748
760
|
constructor(lexer) {
|
|
749
761
|
this.currentToken = lexer.nextToken();
|
|
@@ -986,8 +998,7 @@ class Parser {
|
|
|
986
998
|
}
|
|
987
999
|
// const body = _statements();
|
|
988
1000
|
const body = [this._statement()];
|
|
989
|
-
while (
|
|
990
|
-
this.currentToken.type === TokenType.semi) {
|
|
1001
|
+
while (true) {
|
|
991
1002
|
this._eatSemiOrEOL();
|
|
992
1003
|
if (this.currentToken.type === TokenType.rbrace || this.currentToken.type === TokenType.eof) {
|
|
993
1004
|
// _eat(this.currentToken!.type);
|
|
@@ -1051,7 +1062,6 @@ class Parser {
|
|
|
1051
1062
|
return new WhileLoopStatement(test, body, token, this.currentToken);
|
|
1052
1063
|
}
|
|
1053
1064
|
_forOfIdentifier() {
|
|
1054
|
-
let node;
|
|
1055
1065
|
switch (this.currentToken.type) {
|
|
1056
1066
|
case TokenType.lparen: {
|
|
1057
1067
|
// probable tuple
|
|
@@ -1127,11 +1137,14 @@ class Parser {
|
|
|
1127
1137
|
return node;
|
|
1128
1138
|
}
|
|
1129
1139
|
_statement() {
|
|
1130
|
-
var _a, _b;
|
|
1140
|
+
var _a, _b, _c, _d;
|
|
1131
1141
|
switch (this.currentToken.type) {
|
|
1132
1142
|
case TokenType.BREAK:
|
|
1133
1143
|
this._eat(TokenType.BREAK);
|
|
1134
1144
|
return new BreakAST((_a = this.currentToken) === null || _a === void 0 ? void 0 : _a.line, (_b = this.currentToken) === null || _b === void 0 ? void 0 : _b.col);
|
|
1145
|
+
case TokenType.CONTINUE:
|
|
1146
|
+
this._eat(TokenType.CONTINUE);
|
|
1147
|
+
return new ContinueAST((_c = this.currentToken) === null || _c === void 0 ? void 0 : _c.line, (_d = this.currentToken) === null || _d === void 0 ? void 0 : _d.col);
|
|
1135
1148
|
case TokenType.semi:
|
|
1136
1149
|
this._eatSemi();
|
|
1137
1150
|
return this._statement();
|
|
@@ -1164,7 +1177,12 @@ class Parser {
|
|
|
1164
1177
|
this._eat(TokenType.eof);
|
|
1165
1178
|
break;
|
|
1166
1179
|
}
|
|
1167
|
-
|
|
1180
|
+
if (this.currentToken.type === TokenType.lbrace) {
|
|
1181
|
+
results.push(this._blockStatement());
|
|
1182
|
+
}
|
|
1183
|
+
else {
|
|
1184
|
+
results.push(this._statement());
|
|
1185
|
+
}
|
|
1168
1186
|
// if (this.currentToken!.type !== TokenType.eol &&
|
|
1169
1187
|
// this.currentToken!.type !== TokenType.semi &&
|
|
1170
1188
|
// this.currentToken!.type !== TokenType.eof) {
|
|
@@ -1196,7 +1214,11 @@ Parser._binopPrecdences = {
|
|
|
1196
1214
|
[TokenType.div]: 40,
|
|
1197
1215
|
[TokenType.mod]: 40,
|
|
1198
1216
|
};
|
|
1199
|
-
class
|
|
1217
|
+
class LoopControl {
|
|
1218
|
+
}
|
|
1219
|
+
class BreakBranch extends LoopControl {
|
|
1220
|
+
}
|
|
1221
|
+
class ContinueBranch extends LoopControl {
|
|
1200
1222
|
}
|
|
1201
1223
|
// AST Wallker
|
|
1202
1224
|
class ANodeVisitor {
|
|
@@ -1231,6 +1253,7 @@ class NodeVisitor extends ANodeVisitor {
|
|
|
1231
1253
|
this.registerVisitor(ForLoopStatement, this.visitForLoopStatement);
|
|
1232
1254
|
this.registerVisitor(ForOfStatement, this.visitForOfStatement);
|
|
1233
1255
|
this.registerVisitor(BreakAST, this.visitBreakAST);
|
|
1256
|
+
this.registerVisitor(ContinueAST, this.visitContinueAST);
|
|
1234
1257
|
}
|
|
1235
1258
|
visit(node) {
|
|
1236
1259
|
const methodName = `visit${node.constructor.name}`;
|
|
@@ -1248,14 +1271,61 @@ class NodeVisitor extends ANodeVisitor {
|
|
|
1248
1271
|
else { }
|
|
1249
1272
|
}
|
|
1250
1273
|
}
|
|
1274
|
+
class MEventScope {
|
|
1275
|
+
constructor(name, memory, parent) {
|
|
1276
|
+
this.memory = {};
|
|
1277
|
+
this.name = name;
|
|
1278
|
+
this.memory = memory;
|
|
1279
|
+
this.parent = parent;
|
|
1280
|
+
}
|
|
1281
|
+
resolve(key) {
|
|
1282
|
+
return Object.keys(this.memory).includes(key) ? this.memory[key] : (this.parent ? this.parent.resolve(key) : null);
|
|
1283
|
+
}
|
|
1284
|
+
change(key, value, declare = true) {
|
|
1285
|
+
if (Object.keys(this.memory).includes(key)) {
|
|
1286
|
+
// change here
|
|
1287
|
+
this.memory[key] = value;
|
|
1288
|
+
return true;
|
|
1289
|
+
}
|
|
1290
|
+
if (this.parent && this.parent.change(key, value, false)) {
|
|
1291
|
+
return true;
|
|
1292
|
+
}
|
|
1293
|
+
if (!declare) {
|
|
1294
|
+
return false;
|
|
1295
|
+
}
|
|
1296
|
+
this.memory[key] = value;
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1251
1300
|
class MEvento extends NodeVisitor {
|
|
1252
1301
|
constructor() {
|
|
1253
1302
|
super();
|
|
1254
|
-
this.
|
|
1303
|
+
this.rootScope = new MEventScope("Program", {});
|
|
1304
|
+
this.currentScrope = this.rootScope;
|
|
1255
1305
|
this.debug = false;
|
|
1256
1306
|
this._functionsRegistry = {};
|
|
1257
1307
|
this._functionsRegistry = Object.assign({}, MEvento._globalFunctionsRegistry);
|
|
1258
1308
|
}
|
|
1309
|
+
resolve(name) {
|
|
1310
|
+
var _a, _b;
|
|
1311
|
+
return (_b = (_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.resolve(name)) !== null && _b !== void 0 ? _b : null;
|
|
1312
|
+
}
|
|
1313
|
+
changeVariable(name, value) {
|
|
1314
|
+
var _a;
|
|
1315
|
+
if ((_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.change(name, value)) {
|
|
1316
|
+
return value;
|
|
1317
|
+
}
|
|
1318
|
+
else
|
|
1319
|
+
return null;
|
|
1320
|
+
}
|
|
1321
|
+
pushScope(name) {
|
|
1322
|
+
const scope = new MEventScope(name, {}, this.currentScrope);
|
|
1323
|
+
this.currentScrope = scope;
|
|
1324
|
+
}
|
|
1325
|
+
popScope() {
|
|
1326
|
+
var _a;
|
|
1327
|
+
this.currentScrope = (_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.parent;
|
|
1328
|
+
}
|
|
1259
1329
|
log(message) {
|
|
1260
1330
|
if (this.debug) {
|
|
1261
1331
|
console.log(message);
|
|
@@ -1272,14 +1342,20 @@ class MEvento extends NodeVisitor {
|
|
|
1272
1342
|
visitBlockStatementAST(node) {
|
|
1273
1343
|
const list = node.body;
|
|
1274
1344
|
let last;
|
|
1345
|
+
this.pushScope("Block");
|
|
1275
1346
|
for (const n of list) {
|
|
1276
1347
|
last = this.visit(n);
|
|
1348
|
+
if (last instanceof LoopControl) {
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1277
1351
|
}
|
|
1352
|
+
this.popScope();
|
|
1278
1353
|
return last;
|
|
1279
1354
|
}
|
|
1280
1355
|
visitIdentifierAST(node) {
|
|
1356
|
+
var _a, _b;
|
|
1281
1357
|
const id = node.value;
|
|
1282
|
-
return this.
|
|
1358
|
+
return (_b = (_a = this.currentScrope) === null || _a === void 0 ? void 0 : _a.resolve(id)) !== null && _b !== void 0 ? _b : null;
|
|
1283
1359
|
}
|
|
1284
1360
|
visitLiteralAST(node) {
|
|
1285
1361
|
const value = node.value;
|
|
@@ -1297,7 +1373,7 @@ class MEvento extends NodeVisitor {
|
|
|
1297
1373
|
}
|
|
1298
1374
|
else if (id instanceof IdentifierAST) {
|
|
1299
1375
|
value = this.visit(init);
|
|
1300
|
-
this.
|
|
1376
|
+
this.changeVariable(id.value, value);
|
|
1301
1377
|
}
|
|
1302
1378
|
return value;
|
|
1303
1379
|
}
|
|
@@ -1467,45 +1543,59 @@ class MEvento extends NodeVisitor {
|
|
|
1467
1543
|
if (ret instanceof BreakBranch) {
|
|
1468
1544
|
break;
|
|
1469
1545
|
}
|
|
1546
|
+
if (ret instanceof ContinueBranch) {
|
|
1547
|
+
continue;
|
|
1548
|
+
}
|
|
1470
1549
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
|
|
1471
1550
|
}
|
|
1472
|
-
return retainer
|
|
1551
|
+
return retainer !== null && retainer !== void 0 ? retainer : null;
|
|
1473
1552
|
}
|
|
1474
1553
|
visitForLoopStatement(node) {
|
|
1475
1554
|
const retainer = node.retain ? [] : undefined;
|
|
1476
1555
|
const loopIdentifier = node.init.identifier;
|
|
1477
1556
|
if (!(loopIdentifier instanceof IdentifierAST))
|
|
1478
1557
|
throw new Error("Unexpected identifer found");
|
|
1558
|
+
this.pushScope("ForLoopStatement");
|
|
1479
1559
|
const initialValue = this.visit(node.init.init);
|
|
1480
|
-
this.
|
|
1560
|
+
this.changeVariable(loopIdentifier.value, initialValue);
|
|
1481
1561
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(initialValue);
|
|
1482
1562
|
const test = () => {
|
|
1483
1563
|
const ret = this.visit(node.test);
|
|
1484
1564
|
if (isNum(ret)) {
|
|
1485
|
-
const tmp = this.
|
|
1565
|
+
const tmp = this.resolve(loopIdentifier.value);
|
|
1486
1566
|
return node.direction.type === TokenType.up ? ret >= tmp : ret <= tmp;
|
|
1487
1567
|
}
|
|
1488
1568
|
return _boolValue(ret);
|
|
1489
1569
|
};
|
|
1570
|
+
const update = () => {
|
|
1571
|
+
const updateValue = this.visit(node.update);
|
|
1572
|
+
if (isNum(updateValue)) {
|
|
1573
|
+
// auto handle
|
|
1574
|
+
const tmp = this.resolve(loopIdentifier.value);
|
|
1575
|
+
if (!isNum(tmp))
|
|
1576
|
+
throw Error("Cant update value");
|
|
1577
|
+
this.changeVariable(loopIdentifier.value, node.direction.type === TokenType.up ? tmp + updateValue : tmp - updateValue);
|
|
1578
|
+
// console.log('Update loop from ' + tmp + ' to ' + this.resolve(loopIdentifier.value))
|
|
1579
|
+
}
|
|
1580
|
+
else {
|
|
1581
|
+
throw Error("Update value cant be non number");
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1490
1584
|
while (test()) {
|
|
1491
1585
|
const ret = this.visit(node.body);
|
|
1492
1586
|
if (ret instanceof BreakBranch) {
|
|
1493
1587
|
break;
|
|
1494
1588
|
}
|
|
1589
|
+
if (ret instanceof ContinueBranch) {
|
|
1590
|
+
update();
|
|
1591
|
+
continue;
|
|
1592
|
+
}
|
|
1495
1593
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
|
|
1496
1594
|
// update
|
|
1497
|
-
|
|
1498
|
-
// auto handle
|
|
1499
|
-
const tmp = this._memory[loopIdentifier.value];
|
|
1500
|
-
if (!isNum(tmp))
|
|
1501
|
-
throw Error("Can update value");
|
|
1502
|
-
this._memory[loopIdentifier.value] = node.direction.type === TokenType.up ? tmp + node.update.value : tmp - node.update.value;
|
|
1503
|
-
}
|
|
1504
|
-
else {
|
|
1505
|
-
this.visit(node.update);
|
|
1506
|
-
}
|
|
1595
|
+
update();
|
|
1507
1596
|
}
|
|
1508
|
-
|
|
1597
|
+
this.popScope();
|
|
1598
|
+
return retainer !== null && retainer !== void 0 ? retainer : null;
|
|
1509
1599
|
}
|
|
1510
1600
|
visitForOfStatement(node) {
|
|
1511
1601
|
const collection = this.visit(node.collection);
|
|
@@ -1513,27 +1603,33 @@ class MEvento extends NodeVisitor {
|
|
|
1513
1603
|
throw Error("Can iterate non array object");
|
|
1514
1604
|
}
|
|
1515
1605
|
const retainer = node.retain ? [] : undefined;
|
|
1606
|
+
this.pushScope("ForOfStatement");
|
|
1516
1607
|
for (const it of collection) {
|
|
1517
1608
|
this._declareForIdentifier(node.identifier, it);
|
|
1518
1609
|
const ret = this.visit(node.body);
|
|
1519
1610
|
if (ret instanceof BreakBranch) {
|
|
1520
1611
|
break;
|
|
1521
1612
|
}
|
|
1613
|
+
if (ret instanceof ContinueBranch) {
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1522
1616
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
|
|
1523
1617
|
}
|
|
1524
|
-
|
|
1618
|
+
this.popScope();
|
|
1619
|
+
return retainer !== null && retainer !== void 0 ? retainer : null;
|
|
1620
|
+
}
|
|
1621
|
+
visitContinueAST(node) {
|
|
1622
|
+
return new ContinueBranch();
|
|
1525
1623
|
}
|
|
1526
1624
|
_declareForIdentifier(node, value) {
|
|
1527
1625
|
if (node instanceof TupleExpression) {
|
|
1528
1626
|
if (!Array.isArray(value)) {
|
|
1529
1627
|
throw Error("Unable to make a tuple from non Array element");
|
|
1530
1628
|
}
|
|
1531
|
-
this.
|
|
1532
|
-
this.
|
|
1533
|
-
null;
|
|
1629
|
+
this.changeVariable(node.first.value, value[0]);
|
|
1630
|
+
this.changeVariable(node.second.value, value[1]);
|
|
1534
1631
|
}
|
|
1535
|
-
this.
|
|
1536
|
-
null;
|
|
1632
|
+
this.changeVariable(node.value, value);
|
|
1537
1633
|
}
|
|
1538
1634
|
resolveArguments(args) {
|
|
1539
1635
|
return args.map((it) => {
|
|
@@ -1582,12 +1678,12 @@ class MEvento extends NodeVisitor {
|
|
|
1582
1678
|
clone() {
|
|
1583
1679
|
var ret = new MEvento();
|
|
1584
1680
|
ret._functionsRegistry = Object.assign({}, this._functionsRegistry);
|
|
1585
|
-
ret.
|
|
1681
|
+
ret.rootScope.memory = Object.assign({}, this.rootScope.memory);
|
|
1586
1682
|
return ret;
|
|
1587
1683
|
}
|
|
1588
1684
|
newAsyncInstance() {
|
|
1589
1685
|
const asyncIns = MEventoAsync.newInstance();
|
|
1590
|
-
asyncIns.
|
|
1686
|
+
asyncIns.rootScope.memory = this.rootScope.memory;
|
|
1591
1687
|
/// ????
|
|
1592
1688
|
asyncIns._functionsRegistry = this._functionsRegistry;
|
|
1593
1689
|
return asyncIns;
|
|
@@ -1614,16 +1710,21 @@ class MEventoAsync extends MEvento {
|
|
|
1614
1710
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1615
1711
|
const list = node.body;
|
|
1616
1712
|
let last;
|
|
1713
|
+
this.pushScope("Block");
|
|
1617
1714
|
for (const n of list) {
|
|
1618
1715
|
last = yield this.visit(n);
|
|
1716
|
+
if (last instanceof LoopControl) {
|
|
1717
|
+
break;
|
|
1718
|
+
}
|
|
1619
1719
|
}
|
|
1720
|
+
this.popScope();
|
|
1620
1721
|
return last;
|
|
1621
1722
|
});
|
|
1622
1723
|
}
|
|
1623
1724
|
visitIdentifierAST(node) {
|
|
1624
1725
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1625
1726
|
const id = node.value;
|
|
1626
|
-
return this.
|
|
1727
|
+
return this.resolve(id);
|
|
1627
1728
|
});
|
|
1628
1729
|
}
|
|
1629
1730
|
visitLiteralAST(node) {
|
|
@@ -1645,7 +1746,7 @@ class MEventoAsync extends MEvento {
|
|
|
1645
1746
|
}
|
|
1646
1747
|
else if (id instanceof IdentifierAST) {
|
|
1647
1748
|
value = yield this.visit(init);
|
|
1648
|
-
this.
|
|
1749
|
+
this.changeVariable(id.value, value);
|
|
1649
1750
|
}
|
|
1650
1751
|
return value;
|
|
1651
1752
|
});
|
|
@@ -1743,6 +1844,9 @@ class MEventoAsync extends MEvento {
|
|
|
1743
1844
|
const arg = node.argument;
|
|
1744
1845
|
const op = node.operation;
|
|
1745
1846
|
const argValue = yield this.visit(arg);
|
|
1847
|
+
if (op.type === TokenType.not) {
|
|
1848
|
+
return _boolValue(argValue) === false;
|
|
1849
|
+
}
|
|
1746
1850
|
if (isNum(argValue)) {
|
|
1747
1851
|
throw new Error(`Operation ${op.value} not allowed no num value`);
|
|
1748
1852
|
}
|
|
@@ -1826,11 +1930,14 @@ class MEventoAsync extends MEvento {
|
|
|
1826
1930
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1827
1931
|
this.log(`WhileLoopStatement ${node.test} ${node.body}`);
|
|
1828
1932
|
const retainer = node.retain ? [] : undefined;
|
|
1829
|
-
while (_boolValue(this.visit(node.test))) {
|
|
1933
|
+
while (_boolValue(yield this.visit(node.test))) {
|
|
1830
1934
|
const ret = yield this.visit(node.body);
|
|
1831
1935
|
if (ret instanceof BreakBranch) {
|
|
1832
1936
|
break;
|
|
1833
1937
|
}
|
|
1938
|
+
if (ret instanceof ContinueBranch) {
|
|
1939
|
+
continue;
|
|
1940
|
+
}
|
|
1834
1941
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
|
|
1835
1942
|
}
|
|
1836
1943
|
return retainer;
|
|
@@ -1842,53 +1949,68 @@ class MEventoAsync extends MEvento {
|
|
|
1842
1949
|
const loopIdentifier = node.init.identifier;
|
|
1843
1950
|
if (!(loopIdentifier instanceof IdentifierAST))
|
|
1844
1951
|
throw new Error("Unexpected identifer found");
|
|
1845
|
-
|
|
1846
|
-
this.
|
|
1952
|
+
this.pushScope("ForLoopStatement");
|
|
1953
|
+
const initialValue = yield this.visit(node.init.init);
|
|
1954
|
+
this.changeVariable(loopIdentifier.value, initialValue);
|
|
1847
1955
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(initialValue);
|
|
1848
|
-
const test = () => {
|
|
1849
|
-
const ret = this.visit(node.test);
|
|
1956
|
+
const test = () => __awaiter(this, void 0, void 0, function* () {
|
|
1957
|
+
const ret = yield this.visit(node.test);
|
|
1850
1958
|
if (isNum(ret)) {
|
|
1851
|
-
const tmp = this.
|
|
1959
|
+
const tmp = this.resolve(loopIdentifier.value);
|
|
1852
1960
|
return node.direction.type === TokenType.up ? ret >= tmp : ret <= tmp;
|
|
1853
1961
|
}
|
|
1854
1962
|
return _boolValue(ret);
|
|
1855
|
-
};
|
|
1856
|
-
|
|
1963
|
+
});
|
|
1964
|
+
const update = () => __awaiter(this, void 0, void 0, function* () {
|
|
1965
|
+
const updateValue = yield this.visit(node.update);
|
|
1966
|
+
if (isNum(updateValue)) {
|
|
1967
|
+
// auto handle
|
|
1968
|
+
const tmp = this.resolve(loopIdentifier.value);
|
|
1969
|
+
if (!isNum(tmp))
|
|
1970
|
+
throw Error("Cant update value");
|
|
1971
|
+
this.changeVariable(loopIdentifier.value, node.direction.type === TokenType.up ? tmp + updateValue : tmp - updateValue);
|
|
1972
|
+
}
|
|
1973
|
+
else {
|
|
1974
|
+
throw Error("Update value cant be non number");
|
|
1975
|
+
}
|
|
1976
|
+
});
|
|
1977
|
+
while (yield test()) {
|
|
1857
1978
|
const ret = yield this.visit(node.body);
|
|
1858
1979
|
if (ret instanceof BreakBranch) {
|
|
1859
1980
|
break;
|
|
1860
1981
|
}
|
|
1982
|
+
if (ret instanceof ContinueBranch) {
|
|
1983
|
+
yield update();
|
|
1984
|
+
continue;
|
|
1985
|
+
}
|
|
1861
1986
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
|
|
1862
1987
|
// update
|
|
1863
|
-
|
|
1864
|
-
// auto handle
|
|
1865
|
-
const tmp = this._memory[loopIdentifier.value];
|
|
1866
|
-
if (!isNum(tmp))
|
|
1867
|
-
throw Error("Can update value");
|
|
1868
|
-
this._memory[loopIdentifier.value] = node.direction.type === TokenType.up ? tmp + node.update.value : tmp - node.update.value;
|
|
1869
|
-
}
|
|
1870
|
-
else {
|
|
1871
|
-
this.visit(node.update);
|
|
1872
|
-
}
|
|
1988
|
+
yield update();
|
|
1873
1989
|
}
|
|
1874
|
-
|
|
1990
|
+
this.popScope();
|
|
1991
|
+
return retainer !== null && retainer !== void 0 ? retainer : null;
|
|
1875
1992
|
});
|
|
1876
1993
|
}
|
|
1877
1994
|
visitForOfStatement(node) {
|
|
1878
1995
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1879
|
-
const collection = this.visit(node.collection);
|
|
1996
|
+
const collection = yield this.visit(node.collection);
|
|
1880
1997
|
if (!Array.isArray(collection)) {
|
|
1881
1998
|
throw Error("Can iterate non array object");
|
|
1882
1999
|
}
|
|
1883
2000
|
const retainer = node.retain ? [] : undefined;
|
|
2001
|
+
this.pushScope("ForOfStatement");
|
|
1884
2002
|
for (const it of collection) {
|
|
1885
2003
|
this._declareForIdentifier(node.identifier, it);
|
|
1886
2004
|
const ret = yield this.visit(node.body);
|
|
1887
2005
|
if (ret instanceof BreakBranch) {
|
|
1888
2006
|
break;
|
|
1889
2007
|
}
|
|
2008
|
+
if (ret instanceof ContinueBranch) {
|
|
2009
|
+
continue;
|
|
2010
|
+
}
|
|
1890
2011
|
retainer === null || retainer === void 0 ? void 0 : retainer.push(ret);
|
|
1891
2012
|
}
|
|
2013
|
+
this.popScope();
|
|
1892
2014
|
return retainer;
|
|
1893
2015
|
});
|
|
1894
2016
|
}
|
|
@@ -1924,7 +2046,7 @@ class MEventoAsync extends MEvento {
|
|
|
1924
2046
|
clone() {
|
|
1925
2047
|
var ret = new MEventoAsync();
|
|
1926
2048
|
ret._functionsRegistry = Object.assign({}, this._functionsRegistry);
|
|
1927
|
-
ret.
|
|
2049
|
+
ret.rootScope.memory = Object.assign({}, this.rootScope.memory);
|
|
1928
2050
|
return ret;
|
|
1929
2051
|
}
|
|
1930
2052
|
}
|
|
@@ -1937,5 +2059,5 @@ class MEventoAsync extends MEvento {
|
|
|
1937
2059
|
* Generated bundle index. Do not edit.
|
|
1938
2060
|
*/
|
|
1939
2061
|
|
|
1940
|
-
export { AST, ArrayExpression, AssignmentExpressionAST, BinaryExpressionAST, BlockStatementAST, BreakAST, BreakBranch, CallExpressionAST, ExpressionStatementAST, ForLoopStatement, ForOfStatement, IdentifierAST, IfStatementAST, IndexAccessorAST, LexerDictionary, LiteralAST, LogicalExpressionAST, MEvento, MEventoAsync, NodeVisitor, ObjectExpression, ObjectProperty, RootAST, Token, TokenType, TupleExpression, UnaryExpressionAST, WhileLoopStatement };
|
|
2062
|
+
export { AST, ArrayExpression, AssignmentExpressionAST, BinaryExpressionAST, BlockStatementAST, BreakAST, BreakBranch, CallExpressionAST, ContinueAST, ContinueBranch, ExpressionStatementAST, ForLoopStatement, ForOfStatement, IdentifierAST, IfStatementAST, IndexAccessorAST, LexerDictionary, LiteralAST, LogicalExpressionAST, LoopControl, MEventScope, MEvento, MEventoAsync, NodeVisitor, ObjectExpression, ObjectProperty, RootAST, Token, TokenType, TupleExpression, UnaryExpressionAST, WhileLoopStatement };
|
|
1941
2063
|
//# sourceMappingURL=mevento.mjs.map
|