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.
@@ -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
- switch (_a.label) {
73
- case 0:
74
- me = this;
75
- opc = operationContext.fork({
76
- type: context_1.ContextType.LOOP,
77
- state: context_1.ContextState.TEMPORARY
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
- loopContext = {
80
- isBreak: false,
81
- isContinue: false
82
- };
83
- resolveCondition = function (item) {
84
- return __awaiter(this, void 0, void 0, function () {
85
- var value, value;
86
- return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0:
89
- if (!(item instanceof expression_1.Expression)) return [3 /*break*/, 2];
90
- return [4 /*yield*/, item.get(opc)];
91
- case 1:
92
- value = _a.sent();
93
- return [2 /*return*/, value.toTruthy()];
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
- opc.setMemory('loopContext', loopContext);
113
- _a.label = 1;
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",