greybel-interpreter 0.7.0 → 0.7.1
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/while.js +65 -53
- package/package.json +1 -1
package/dist/operations/while.js
CHANGED
|
@@ -68,63 +68,75 @@ var WhileOperation = /** @class */ (function (_super) {
|
|
|
68
68
|
WhileOperation.prototype.run = function (operationContext) {
|
|
69
69
|
return __awaiter(this, void 0, void 0, function () {
|
|
70
70
|
var me, opc, loopContext, resolveCondition;
|
|
71
|
+
var _this = this;
|
|
71
72
|
return __generator(this, function (_a) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
me = this;
|
|
74
|
+
opc = operationContext.fork({
|
|
75
|
+
type: context_1.ContextType.LOOP,
|
|
76
|
+
state: context_1.ContextState.TEMPORARY
|
|
77
|
+
});
|
|
78
|
+
loopContext = {
|
|
79
|
+
isBreak: false,
|
|
80
|
+
isContinue: false
|
|
81
|
+
};
|
|
82
|
+
resolveCondition = function (item) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var value, value;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
if (!(item instanceof expression_1.Expression)) return [3 /*break*/, 2];
|
|
89
|
+
return [4 /*yield*/, item.get(opc)];
|
|
90
|
+
case 1:
|
|
91
|
+
value = _a.sent();
|
|
92
|
+
return [2 /*return*/, value.toTruthy()];
|
|
93
|
+
case 2:
|
|
94
|
+
if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
95
|
+
return [4 /*yield*/, item.get(opc)];
|
|
96
|
+
case 3:
|
|
97
|
+
value = _a.sent();
|
|
98
|
+
return [2 /*return*/, value.toTruthy()];
|
|
99
|
+
case 4:
|
|
100
|
+
if ((0, typer_1.isCustomValue)(item)) {
|
|
101
|
+
return [2 /*return*/, item.toTruthy()];
|
|
102
|
+
}
|
|
103
|
+
_a.label = 5;
|
|
104
|
+
case 5:
|
|
105
|
+
operationContext.debugger.raise('Unexpected condition', me, item);
|
|
106
|
+
return [2 /*return*/];
|
|
107
|
+
}
|
|
78
108
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
case 2:
|
|
95
|
-
if (!(item instanceof operation_1.Operation)) return [3 /*break*/, 4];
|
|
96
|
-
return [4 /*yield*/, item.get(opc)];
|
|
97
|
-
case 3:
|
|
98
|
-
value = _a.sent();
|
|
99
|
-
return [2 /*return*/, value.toTruthy()];
|
|
100
|
-
case 4:
|
|
101
|
-
if ((0, typer_1.isCustomValue)(item)) {
|
|
102
|
-
return [2 /*return*/, item.toTruthy()];
|
|
103
|
-
}
|
|
104
|
-
_a.label = 5;
|
|
105
|
-
case 5:
|
|
106
|
-
operationContext.debugger.raise('Unexpected condition', me, item);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
opc.setMemory('loopContext', loopContext);
|
|
112
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
113
|
+
var iteration = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
114
|
+
var condition;
|
|
115
|
+
return __generator(this, function (_a) {
|
|
116
|
+
switch (_a.label) {
|
|
117
|
+
case 0:
|
|
118
|
+
loopContext.isContinue = false;
|
|
119
|
+
return [4 /*yield*/, resolveCondition(me.condition)];
|
|
120
|
+
case 1:
|
|
121
|
+
condition = _a.sent();
|
|
122
|
+
if (!condition) {
|
|
123
|
+
resolve();
|
|
107
124
|
return [2 /*return*/];
|
|
108
|
-
|
|
109
|
-
|
|
125
|
+
}
|
|
126
|
+
return [4 /*yield*/, me.body.run(opc)];
|
|
127
|
+
case 2:
|
|
128
|
+
_a.sent();
|
|
129
|
+
if (loopContext.isBreak || operationContext.isExit()) {
|
|
130
|
+
resolve();
|
|
131
|
+
return [2 /*return*/];
|
|
132
|
+
}
|
|
133
|
+
process.nextTick(iteration);
|
|
134
|
+
return [2 /*return*/];
|
|
135
|
+
}
|
|
110
136
|
});
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
case 1: return [4 /*yield*/, resolveCondition(me.condition)];
|
|
115
|
-
case 2:
|
|
116
|
-
if (!_a.sent()) return [3 /*break*/, 4];
|
|
117
|
-
loopContext.isContinue = false;
|
|
118
|
-
return [4 /*yield*/, me.body.run(opc)];
|
|
119
|
-
case 3:
|
|
120
|
-
_a.sent();
|
|
121
|
-
if (loopContext.isContinue)
|
|
122
|
-
return [3 /*break*/, 1];
|
|
123
|
-
if (loopContext.isBreak || operationContext.isExit())
|
|
124
|
-
return [3 /*break*/, 4];
|
|
125
|
-
return [3 /*break*/, 1];
|
|
126
|
-
case 4: return [2 /*return*/];
|
|
127
|
-
}
|
|
137
|
+
}); };
|
|
138
|
+
iteration();
|
|
139
|
+
})];
|
|
128
140
|
});
|
|
129
141
|
});
|
|
130
142
|
};
|