greybel-interpreter 2.6.1 → 2.6.2
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/operations/for.js +33 -23
- package/dist/operations/while.js +30 -18
- package/package.json +1 -1
package/dist/operations/for.js
CHANGED
|
@@ -17,6 +17,7 @@ const string_1 = require("../types/string");
|
|
|
17
17
|
const set_immediate_1 = require("../utils/set-immediate");
|
|
18
18
|
const block_1 = require("./block");
|
|
19
19
|
const operation_1 = require("./operation");
|
|
20
|
+
const FOR_BATCH_SIZE = 30;
|
|
20
21
|
class For extends operation_1.OperationBlock {
|
|
21
22
|
constructor(item, target) {
|
|
22
23
|
super(null, target);
|
|
@@ -49,32 +50,41 @@ class For extends operation_1.OperationBlock {
|
|
|
49
50
|
const idxIdentifier = new string_1.CustomString(`__${identifier}_idx`);
|
|
50
51
|
const varIdentifier = new string_1.CustomString(identifier);
|
|
51
52
|
let iteratorResult = iterator.next();
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
resolve(default_1.DefaultType.Void);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const current = iteratorResult.value;
|
|
59
|
-
loopState.isContinue = false;
|
|
60
|
-
forCtx.set(idxIdentifier, new number_1.CustomNumber(iterator.index - 1));
|
|
61
|
-
forCtx.set(varIdentifier, current);
|
|
62
|
-
yield this.block.handle(forCtx);
|
|
63
|
-
if (loopState.isBreak ||
|
|
64
|
-
forCtx.functionState.isReturn ||
|
|
65
|
-
ctx.isExit()) {
|
|
66
|
-
resolve(default_1.DefaultType.Void);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const idxValue = forCtx.get(idxIdentifier).toNumber();
|
|
70
|
-
iterator.index += idxValue - (iterator.index - 1);
|
|
71
|
-
iteratorResult = iterator.next();
|
|
72
|
-
(0, set_immediate_1.setImmediate)(iteration);
|
|
53
|
+
const next = () => __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (iteratorResult.done) {
|
|
55
|
+
return false;
|
|
73
56
|
}
|
|
74
|
-
|
|
75
|
-
|
|
57
|
+
const current = iteratorResult.value;
|
|
58
|
+
loopState.isContinue = false;
|
|
59
|
+
forCtx.set(idxIdentifier, new number_1.CustomNumber(iterator.index - 1));
|
|
60
|
+
forCtx.set(varIdentifier, current);
|
|
61
|
+
yield this.block.handle(forCtx);
|
|
62
|
+
if (loopState.isBreak ||
|
|
63
|
+
forCtx.functionState.isReturn ||
|
|
64
|
+
ctx.isExit()) {
|
|
65
|
+
return false;
|
|
76
66
|
}
|
|
67
|
+
const idxValue = forCtx.get(idxIdentifier).toNumber();
|
|
68
|
+
iterator.index += idxValue - (iterator.index - 1);
|
|
69
|
+
iteratorResult = iterator.next();
|
|
70
|
+
return true;
|
|
77
71
|
});
|
|
72
|
+
const iteration = function () {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
try {
|
|
75
|
+
for (let index = 0; index < FOR_BATCH_SIZE; index++) {
|
|
76
|
+
if (!(yield next())) {
|
|
77
|
+
resolve(default_1.DefaultType.Void);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
(0, set_immediate_1.setImmediate)(iteration);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
reject(err);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
78
88
|
iteration();
|
|
79
89
|
});
|
|
80
90
|
});
|
package/dist/operations/while.js
CHANGED
|
@@ -15,6 +15,7 @@ const default_1 = require("../types/default");
|
|
|
15
15
|
const set_immediate_1 = require("../utils/set-immediate");
|
|
16
16
|
const block_1 = require("./block");
|
|
17
17
|
const operation_1 = require("./operation");
|
|
18
|
+
const WHILE_BATCH_SIZE = 30;
|
|
18
19
|
class While extends operation_1.OperationBlock {
|
|
19
20
|
constructor(item, target) {
|
|
20
21
|
super(null, target);
|
|
@@ -37,27 +38,38 @@ class While extends operation_1.OperationBlock {
|
|
|
37
38
|
const loopState = new context_1.LoopState();
|
|
38
39
|
whileCtx.loopState = loopState;
|
|
39
40
|
return new Promise((resolve, reject) => {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
loopState.isContinue = false;
|
|
48
|
-
yield this.block.handle(whileCtx);
|
|
49
|
-
if (loopState.isBreak ||
|
|
50
|
-
whileCtx.functionState.isReturn ||
|
|
51
|
-
ctx.isExit()) {
|
|
52
|
-
resolve(default_1.DefaultType.Void);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
(0, set_immediate_1.setImmediate)(iteration);
|
|
41
|
+
const next = () => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const conditionResult = yield whileCtx.step(this.condition);
|
|
43
|
+
if (!conditionResult.toTruthy()) {
|
|
44
|
+
resolve(default_1.DefaultType.Void);
|
|
45
|
+
return false;
|
|
56
46
|
}
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
loopState.isContinue = false;
|
|
48
|
+
yield this.block.handle(whileCtx);
|
|
49
|
+
if (loopState.isBreak ||
|
|
50
|
+
whileCtx.functionState.isReturn ||
|
|
51
|
+
ctx.isExit()) {
|
|
52
|
+
resolve(default_1.DefaultType.Void);
|
|
53
|
+
return false;
|
|
59
54
|
}
|
|
55
|
+
return true;
|
|
60
56
|
});
|
|
57
|
+
const iteration = function () {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
try {
|
|
60
|
+
for (let index = 0; index < WHILE_BATCH_SIZE; index++) {
|
|
61
|
+
if (!(yield next())) {
|
|
62
|
+
resolve(default_1.DefaultType.Void);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
(0, set_immediate_1.setImmediate)(iteration);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
reject(err);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
61
73
|
iteration();
|
|
62
74
|
});
|
|
63
75
|
});
|