@ball-lang/engine 1.17.2 → 1.18.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/package.json
CHANGED
package/src/compiled_engine.ts
CHANGED
|
@@ -5110,52 +5110,77 @@ export class BallEngine {
|
|
|
5110
5110
|
if ((!__ball_eq(whichExpr(cases), Expression_Expr.literal) || !__ball_eq(whichValue(cases.literal), Literal_Value.listValue))) {
|
|
5111
5111
|
return null;
|
|
5112
5112
|
}
|
|
5113
|
-
let
|
|
5114
|
-
let
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5113
|
+
let elements = cases.literal.listValue.elements;
|
|
5114
|
+
let caseFieldsList = [];
|
|
5115
|
+
let labelToIndex = {};
|
|
5116
|
+
let defaultIndex = __ball_negate(1);
|
|
5117
|
+
for (let i = 0; __ball_lt(i, elements.length); (i++)) {
|
|
5118
|
+
let caseExpr = __ball_index(elements, i);
|
|
5119
5119
|
let cf = {};
|
|
5120
|
-
|
|
5121
|
-
|
|
5120
|
+
if (__ball_eq(whichExpr(caseExpr), Expression_Expr.messageCreation)) {
|
|
5121
|
+
for (const f of caseExpr.messageCreation.fields) {
|
|
5122
|
+
cf[f.name] = f.value;
|
|
5123
|
+
}
|
|
5124
|
+
}
|
|
5125
|
+
caseFieldsList = (caseFieldsList.push(cf), caseFieldsList);
|
|
5126
|
+
let label = this._stringFieldVal(cf, 'label');
|
|
5127
|
+
if ((!__ball_eq(label, null) && !(label.length === 0))) {
|
|
5128
|
+
labelToIndex[label] = i;
|
|
5122
5129
|
}
|
|
5123
5130
|
if (this._caseIsDefault(cf)) {
|
|
5124
|
-
|
|
5131
|
+
defaultIndex = i;
|
|
5132
|
+
}
|
|
5133
|
+
}
|
|
5134
|
+
let index = __ball_negate(1);
|
|
5135
|
+
let bodyScope = scope;
|
|
5136
|
+
for (let i = 0; __ball_lt(i, caseFieldsList.length); (i++)) {
|
|
5137
|
+
let cf = __ball_index(caseFieldsList, i);
|
|
5138
|
+
if (this._caseIsDefault(cf)) {
|
|
5125
5139
|
continue;
|
|
5126
5140
|
}
|
|
5127
|
-
let
|
|
5141
|
+
let bindings = {};
|
|
5142
|
+
let matched = await this._matchesSwitchCasePattern(subjectVal, cf, bindings, scope);
|
|
5128
5143
|
if (!matched) {
|
|
5129
|
-
|
|
5130
|
-
matched = await this._matchesSwitchCasePattern(subjectVal, cf, bindings, scope);
|
|
5131
|
-
if (matched) {
|
|
5132
|
-
bodyScope = this._scopeWithPatternBindings(scope, bindings);
|
|
5133
|
-
let guard = __ball_index(cf, 'guard');
|
|
5134
|
-
if ((!__ball_eq(guard, null) && !this._toBool(await this._evalExpression(guard, bodyScope)))) {
|
|
5135
|
-
matched = false;
|
|
5136
|
-
continue;
|
|
5137
|
-
}
|
|
5138
|
-
}
|
|
5144
|
+
continue;
|
|
5139
5145
|
}
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
continue;
|
|
5145
|
-
}
|
|
5146
|
-
let result = await this._evalExpression(body, bodyScope);
|
|
5147
|
-
if ((((result instanceof _FlowSignal) && __ball_eq(result.kind, 'break')) && __ball_eq(result.label, null))) {
|
|
5148
|
-
return null;
|
|
5149
|
-
}
|
|
5150
|
-
return result;
|
|
5151
|
-
}
|
|
5146
|
+
let matchScope = this._scopeWithPatternBindings(scope, bindings);
|
|
5147
|
+
let guard = __ball_index(cf, 'guard');
|
|
5148
|
+
if ((!__ball_eq(guard, null) && !this._toBool(await this._evalExpression(guard, matchScope)))) {
|
|
5149
|
+
continue;
|
|
5152
5150
|
}
|
|
5151
|
+
index = i;
|
|
5152
|
+
bodyScope = matchScope;
|
|
5153
|
+
break;
|
|
5153
5154
|
}
|
|
5154
|
-
if (
|
|
5155
|
-
|
|
5156
|
-
if ((((result instanceof _FlowSignal) && __ball_eq(result.kind, 'break')) && __ball_eq(result.label, null))) {
|
|
5155
|
+
if (__ball_eq(index, __ball_negate(1))) {
|
|
5156
|
+
if (__ball_eq(defaultIndex, __ball_negate(1))) {
|
|
5157
5157
|
return null;
|
|
5158
5158
|
}
|
|
5159
|
+
index = defaultIndex;
|
|
5160
|
+
bodyScope = scope;
|
|
5161
|
+
}
|
|
5162
|
+
while ((__ball_ge(index, 0) && __ball_lt(index, caseFieldsList.length))) {
|
|
5163
|
+
let cf = __ball_index(caseFieldsList, index);
|
|
5164
|
+
let body = __ball_index(cf, 'body');
|
|
5165
|
+
if ((__ball_eq(body, null) || ((__ball_eq(whichExpr(body), Expression_Expr.block) && (body.block.statements.length === 0)) && !hasResult(body.block)))) {
|
|
5166
|
+
(index++);
|
|
5167
|
+
continue;
|
|
5168
|
+
}
|
|
5169
|
+
let result = await this._evalExpression(body, bodyScope);
|
|
5170
|
+
if ((result instanceof _FlowSignal)) {
|
|
5171
|
+
if ((__ball_eq(result.kind, 'break') && __ball_eq(result.label, null))) {
|
|
5172
|
+
return null;
|
|
5173
|
+
}
|
|
5174
|
+
let label = result.label;
|
|
5175
|
+
if ((__ball_eq(result.kind, 'continue') && !__ball_eq(label, null))) {
|
|
5176
|
+
let targetIndex = __ball_index(labelToIndex, label);
|
|
5177
|
+
if (!__ball_eq(targetIndex, null)) {
|
|
5178
|
+
index = targetIndex;
|
|
5179
|
+
bodyScope = scope;
|
|
5180
|
+
continue;
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
}
|
|
5159
5184
|
return result;
|
|
5160
5185
|
}
|
|
5161
5186
|
}
|