@ball-lang/engine 1.5.3 → 1.5.5
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/compiled_engine.d.ts.map +1 -1
- package/dist/compiled_engine.js +161 -105
- package/dist/compiled_engine.js.map +1 -1
- package/dist/engine_setup.d.ts.map +1 -1
- package/dist/engine_setup.js +5 -3
- package/dist/engine_setup.js.map +1 -1
- package/package.json +2 -2
- package/src/compiled_engine.ts +150 -101
- package/src/engine_setup.ts +5 -3
package/dist/compiled_engine.js
CHANGED
|
@@ -124,9 +124,15 @@ class BallDouble {
|
|
|
124
124
|
globalThis.BallDouble = BallDouble;
|
|
125
125
|
// Arithmetic helpers that propagate BallDouble through operations.
|
|
126
126
|
// If either operand is BallDouble, the result is BallDouble (preserving .0).
|
|
127
|
+
//
|
|
128
|
+
// Operator-overload dispatch checks for __op_X__ methods (TRAILING double
|
|
129
|
+
// underscore) — this MUST match the Dart encoder's canonical operator naming
|
|
130
|
+
// (_canonicalOperatorName in dart/encoder/lib/encoder.dart), which always
|
|
131
|
+
// emits a trailing __. A single-underscore lookup (__op_mul) never matches,
|
|
132
|
+
// so overloaded operators silently fall through to raw JS arithmetic (#205).
|
|
127
133
|
function __ball_mul(a, b) {
|
|
128
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
129
|
-
return a.
|
|
134
|
+
if (a != null && typeof a === 'object' && typeof a.__op_mul__ === 'function')
|
|
135
|
+
return a.__op_mul__(b);
|
|
130
136
|
if (typeof a === 'bigint' || typeof b === 'bigint')
|
|
131
137
|
return __i64_wrap(__to_bigint(a) * __to_bigint(b));
|
|
132
138
|
const av = a instanceof BallDouble ? a.value : a;
|
|
@@ -135,8 +141,8 @@ function __ball_mul(a, b) {
|
|
|
135
141
|
return (a instanceof BallDouble || b instanceof BallDouble) ? new BallDouble(r) : r;
|
|
136
142
|
}
|
|
137
143
|
function __ball_add(a, b) {
|
|
138
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
139
|
-
return a.
|
|
144
|
+
if (a != null && typeof a === 'object' && typeof a.__op_add__ === 'function')
|
|
145
|
+
return a.__op_add__(b);
|
|
140
146
|
if (typeof a === 'bigint' || typeof b === 'bigint')
|
|
141
147
|
return __i64_wrap(__to_bigint(a) + __to_bigint(b));
|
|
142
148
|
const av = a instanceof BallDouble ? a.value : a;
|
|
@@ -145,8 +151,8 @@ function __ball_add(a, b) {
|
|
|
145
151
|
return (a instanceof BallDouble || b instanceof BallDouble) ? new BallDouble(r) : r;
|
|
146
152
|
}
|
|
147
153
|
function __ball_sub(a, b) {
|
|
148
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
149
|
-
return a.
|
|
154
|
+
if (a != null && typeof a === 'object' && typeof a.__op_sub__ === 'function')
|
|
155
|
+
return a.__op_sub__(b);
|
|
150
156
|
if (typeof a === 'bigint' || typeof b === 'bigint')
|
|
151
157
|
return __i64_wrap(__to_bigint(a) - __to_bigint(b));
|
|
152
158
|
const av = a instanceof BallDouble ? a.value : a;
|
|
@@ -156,8 +162,8 @@ function __ball_sub(a, b) {
|
|
|
156
162
|
}
|
|
157
163
|
// Dart equality: NaN != NaN, BallDouble value comparison, null == undefined.
|
|
158
164
|
function __ball_eq(a, b) {
|
|
159
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
160
|
-
return a.
|
|
165
|
+
if (a != null && typeof a === 'object' && typeof a.__op_eq__ === 'function')
|
|
166
|
+
return a.__op_eq__(b);
|
|
161
167
|
if (typeof a === 'bigint' || typeof b === 'bigint') {
|
|
162
168
|
if (typeof a === 'bigint' && typeof b === 'bigint')
|
|
163
169
|
return a === b;
|
|
@@ -180,6 +186,46 @@ function __ball_eq(a, b) {
|
|
|
180
186
|
return a == b;
|
|
181
187
|
return a === b;
|
|
182
188
|
}
|
|
189
|
+
// Relational operator-overload dispatch (less-than/greater-than/etc.),
|
|
190
|
+
// matching the __op_add__-style convention above. Unlike arithmetic,
|
|
191
|
+
// relational comparisons had NO overload attempt at all before #205 — every
|
|
192
|
+
// overloaded Vec2 < x etc. compiled straight to raw JS comparison.
|
|
193
|
+
function __ball_lt(a, b) {
|
|
194
|
+
if (a != null && typeof a === 'object' && typeof a.__op_lt__ === 'function')
|
|
195
|
+
return a.__op_lt__(b);
|
|
196
|
+
if (typeof a === 'bigint' || typeof b === 'bigint')
|
|
197
|
+
return __to_bigint(a) < __to_bigint(b);
|
|
198
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
199
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
200
|
+
return av < bv;
|
|
201
|
+
}
|
|
202
|
+
function __ball_gt(a, b) {
|
|
203
|
+
if (a != null && typeof a === 'object' && typeof a.__op_gt__ === 'function')
|
|
204
|
+
return a.__op_gt__(b);
|
|
205
|
+
if (typeof a === 'bigint' || typeof b === 'bigint')
|
|
206
|
+
return __to_bigint(a) > __to_bigint(b);
|
|
207
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
208
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
209
|
+
return av > bv;
|
|
210
|
+
}
|
|
211
|
+
function __ball_le(a, b) {
|
|
212
|
+
if (a != null && typeof a === 'object' && typeof a.__op_le__ === 'function')
|
|
213
|
+
return a.__op_le__(b);
|
|
214
|
+
if (typeof a === 'bigint' || typeof b === 'bigint')
|
|
215
|
+
return __to_bigint(a) <= __to_bigint(b);
|
|
216
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
217
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
218
|
+
return av <= bv;
|
|
219
|
+
}
|
|
220
|
+
function __ball_ge(a, b) {
|
|
221
|
+
if (a != null && typeof a === 'object' && typeof a.__op_ge__ === 'function')
|
|
222
|
+
return a.__op_ge__(b);
|
|
223
|
+
if (typeof a === 'bigint' || typeof b === 'bigint')
|
|
224
|
+
return __to_bigint(a) >= __to_bigint(b);
|
|
225
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
226
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
227
|
+
return av >= bv;
|
|
228
|
+
}
|
|
183
229
|
function __ball_to_string(v) {
|
|
184
230
|
if (v === null || v === undefined)
|
|
185
231
|
return 'null';
|
|
@@ -1648,13 +1694,13 @@ export class BallEngine {
|
|
|
1648
1694
|
}
|
|
1649
1695
|
_validateProgramLimits() {
|
|
1650
1696
|
let moduleCount = this.program.modules.length;
|
|
1651
|
-
if ((moduleCount
|
|
1697
|
+
if (__ball_gt(moduleCount, this.maxModules)) {
|
|
1652
1698
|
throw new BallRuntimeError((((('Too many modules: ' + __ball_to_string(moduleCount)) + ' (max ') + __ball_to_string(this.maxModules)) + ')'));
|
|
1653
1699
|
}
|
|
1654
1700
|
let maxProgramBytes = this.maxProgramSizeBytes;
|
|
1655
1701
|
if (!__ball_eq(maxProgramBytes, null)) {
|
|
1656
1702
|
let programSizeBytes = this.program.writeToBuffer().length;
|
|
1657
|
-
if ((programSizeBytes
|
|
1703
|
+
if (__ball_gt(programSizeBytes, maxProgramBytes)) {
|
|
1658
1704
|
throw new BallRuntimeError((((('Program too large: ' + __ball_to_string(programSizeBytes)) + ' bytes (max ') + __ball_to_string(maxProgramBytes)) + ')'));
|
|
1659
1705
|
}
|
|
1660
1706
|
}
|
|
@@ -1675,7 +1721,7 @@ export class BallEngine {
|
|
|
1675
1721
|
while (!(stack.length === 0)) {
|
|
1676
1722
|
let current = stack.pop();
|
|
1677
1723
|
let depth = current.depth;
|
|
1678
|
-
if ((depth
|
|
1724
|
+
if (__ball_gt(depth, this.maxExpressionDepth)) {
|
|
1679
1725
|
throw new BallRuntimeError((((('Expression too deep: ' + __ball_to_string(depth)) + ' levels (max ') + __ball_to_string(this.maxExpressionDepth)) + ')'));
|
|
1680
1726
|
}
|
|
1681
1727
|
do {
|
|
@@ -1744,7 +1790,7 @@ export class BallEngine {
|
|
|
1744
1790
|
}
|
|
1745
1791
|
_checkExpressionDepth() {
|
|
1746
1792
|
this._expressionDepth += 1;
|
|
1747
|
-
if ((this._expressionDepth
|
|
1793
|
+
if (__ball_gt(this._expressionDepth, this.maxExpressionDepth)) {
|
|
1748
1794
|
throw new BallRuntimeError((((('Expression too deep: ' + __ball_to_string(this._expressionDepth)) + ' levels (max ') + __ball_to_string(this.maxExpressionDepth)) + ')'));
|
|
1749
1795
|
}
|
|
1750
1796
|
}
|
|
@@ -1757,7 +1803,7 @@ export class BallEngine {
|
|
|
1757
1803
|
if (hasDescriptor(td)) {
|
|
1758
1804
|
this._types[td.name] = td.descriptor;
|
|
1759
1805
|
let tc = td.name.indexOf(':');
|
|
1760
|
-
if ((tc
|
|
1806
|
+
if (__ball_ge(tc, 0)) {
|
|
1761
1807
|
this._types[td.name.substring(__ball_add(tc, 1))] = td.descriptor;
|
|
1762
1808
|
}
|
|
1763
1809
|
}
|
|
@@ -1766,14 +1812,14 @@ export class BallEngine {
|
|
|
1766
1812
|
let enumName = enumDesc.name;
|
|
1767
1813
|
let enumMap = {};
|
|
1768
1814
|
let enumValueList = enumDesc.value;
|
|
1769
|
-
for (let vi = 0; (vi
|
|
1815
|
+
for (let vi = 0; __ball_lt(vi, enumValueList.length); (vi++)) {
|
|
1770
1816
|
let v = __ball_index(enumValueList, vi);
|
|
1771
1817
|
let entry = { ['__type__']: enumName, ['name']: v.name, ['index']: v.number };
|
|
1772
1818
|
enumMap[v.name] = entry;
|
|
1773
1819
|
}
|
|
1774
1820
|
this._enumValues[enumName] = enumMap;
|
|
1775
1821
|
let ec = enumName.indexOf(':');
|
|
1776
|
-
if ((ec
|
|
1822
|
+
if (__ball_ge(ec, 0)) {
|
|
1777
1823
|
this._enumValues[enumName.substring(__ball_add(ec, 1))] = enumMap;
|
|
1778
1824
|
}
|
|
1779
1825
|
}
|
|
@@ -1812,7 +1858,7 @@ export class BallEngine {
|
|
|
1812
1858
|
if (__ball_eq((__ball_eq(kindField, null) ? null : kindField.stringValue), 'constructor')) {
|
|
1813
1859
|
let entry = { module: module.name, func: func };
|
|
1814
1860
|
let dotIdx = func.name.indexOf('.');
|
|
1815
|
-
if ((dotIdx
|
|
1861
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
1816
1862
|
let className = func.name.substring(0, dotIdx);
|
|
1817
1863
|
let ctorSuffix = func.name.substring(__ball_add(dotIdx, 1));
|
|
1818
1864
|
if (__ball_eq(ctorSuffix, 'new')) {
|
|
@@ -1846,7 +1892,7 @@ export class BallEngine {
|
|
|
1846
1892
|
}
|
|
1847
1893
|
if (__ball_eq(kind, 'static_field')) {
|
|
1848
1894
|
let dotIdx = func.name.lastIndexOf('.');
|
|
1849
|
-
if ((dotIdx
|
|
1895
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
1850
1896
|
let bareName = func.name.substring(__ball_add(dotIdx, 1));
|
|
1851
1897
|
(this._staticFieldRefs[bareName] ??= ((() => {
|
|
1852
1898
|
return { module: module.name, func: func, fullName: func.name };
|
|
@@ -1856,7 +1902,7 @@ export class BallEngine {
|
|
|
1856
1902
|
}
|
|
1857
1903
|
let funcName = func.name;
|
|
1858
1904
|
let dotIdx = funcName.lastIndexOf('.');
|
|
1859
|
-
if ((dotIdx
|
|
1905
|
+
if (__ball_lt(dotIdx, 0)) {
|
|
1860
1906
|
return;
|
|
1861
1907
|
}
|
|
1862
1908
|
let methodName = funcName.substring(__ball_add(dotIdx, 1));
|
|
@@ -1891,7 +1937,7 @@ export class BallEngine {
|
|
|
1891
1937
|
}
|
|
1892
1938
|
_lookupTypeMethodWithInheritance(typeName, methodName) {
|
|
1893
1939
|
let colonIdx = typeName.indexOf(':');
|
|
1894
|
-
let modPart = ((colonIdx
|
|
1940
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
1895
1941
|
let current = typeName;
|
|
1896
1942
|
while (!(current.length === 0)) {
|
|
1897
1943
|
let direct = __ball_index(this._typeMethodDispatch, BallEngine._typeMethodKey(current, methodName));
|
|
@@ -1899,7 +1945,7 @@ export class BallEngine {
|
|
|
1899
1945
|
return direct;
|
|
1900
1946
|
}
|
|
1901
1947
|
let currentColon = current.indexOf(':');
|
|
1902
|
-
if ((currentColon
|
|
1948
|
+
if (__ball_ge(currentColon, 0)) {
|
|
1903
1949
|
let bare = current.substring(__ball_add(currentColon, 1));
|
|
1904
1950
|
let bareHit = __ball_index(this._typeMethodDispatch, BallEngine._typeMethodKey(bare, methodName));
|
|
1905
1951
|
if (!__ball_eq(bareHit, null)) {
|
|
@@ -1921,7 +1967,7 @@ export class BallEngine {
|
|
|
1921
1967
|
return mixinHit;
|
|
1922
1968
|
}
|
|
1923
1969
|
let mixinColon = qualMixin.indexOf(':');
|
|
1924
|
-
if ((mixinColon
|
|
1970
|
+
if (__ball_ge(mixinColon, 0)) {
|
|
1925
1971
|
let bareMixin = qualMixin.substring(__ball_add(mixinColon, 1));
|
|
1926
1972
|
let bareMixinHit = __ball_index(this._typeMethodDispatch, BallEngine._typeMethodKey(bareMixin, methodName));
|
|
1927
1973
|
if (!__ball_eq(bareMixinHit, null)) {
|
|
@@ -1988,7 +2034,7 @@ export class BallEngine {
|
|
|
1988
2034
|
return;
|
|
1989
2035
|
}
|
|
1990
2036
|
let elapsed = __ball_sub(DateTime.now().millisecondsSinceEpoch, start);
|
|
1991
|
-
if ((elapsed
|
|
2037
|
+
if (__ball_gt(elapsed, timeout)) {
|
|
1992
2038
|
throw new BallRuntimeError('Execution timeout exceeded');
|
|
1993
2039
|
}
|
|
1994
2040
|
}
|
|
@@ -2005,10 +2051,10 @@ export class BallEngine {
|
|
|
2005
2051
|
_trackMemoryAllocation(bytes) {
|
|
2006
2052
|
const input = bytes;
|
|
2007
2053
|
let limit = this.maxMemoryBytes;
|
|
2008
|
-
if ((__ball_eq(limit, null) || (bytes
|
|
2054
|
+
if ((__ball_eq(limit, null) || __ball_le(bytes, 0))) {
|
|
2009
2055
|
return;
|
|
2010
2056
|
}
|
|
2011
|
-
if ((__ball_add(this._memoryUsedBytes, bytes)
|
|
2057
|
+
if (__ball_gt(__ball_add(this._memoryUsedBytes, bytes), limit)) {
|
|
2012
2058
|
throw new BallRuntimeError('Memory limit exceeded');
|
|
2013
2059
|
}
|
|
2014
2060
|
this._memoryUsedBytes += bytes;
|
|
@@ -2033,7 +2079,7 @@ export class BallEngine {
|
|
|
2033
2079
|
if (func.isBase) {
|
|
2034
2080
|
return this._callBaseFunction(moduleName, func.name, input);
|
|
2035
2081
|
}
|
|
2036
|
-
if ((this._recursionDepth
|
|
2082
|
+
if (__ball_ge(this._recursionDepth, this.maxRecursionDepth)) {
|
|
2037
2083
|
throw new BallRuntimeError(('Maximum recursion depth exceeded: ' + __ball_to_string(this.maxRecursionDepth)));
|
|
2038
2084
|
}
|
|
2039
2085
|
(this._recursionDepth++);
|
|
@@ -2050,7 +2096,7 @@ export class BallEngine {
|
|
|
2050
2096
|
if (__ball_eq(kind, 'constructor')) {
|
|
2051
2097
|
let constructorInput = this._asMap(input);
|
|
2052
2098
|
let dotIdx = func.name.indexOf('.');
|
|
2053
|
-
let typeName = ((dotIdx
|
|
2099
|
+
let typeName = (__ball_ge(dotIdx, 0) ? func.name.substring(0, dotIdx) : func.name);
|
|
2054
2100
|
let isFactory = (hasMetadata(func) && _metadataBool(__ball_index(func.metadata.fields, 'is_factory')));
|
|
2055
2101
|
if (((!isFactory && (__ball_eq(constructorInput, null) || !('self' in constructorInput))) && !__ball_eq(this._findTypeDef(typeName), null))) {
|
|
2056
2102
|
return this._callObjectConstructor(moduleName, func, input);
|
|
@@ -2080,7 +2126,7 @@ export class BallEngine {
|
|
|
2080
2126
|
}
|
|
2081
2127
|
else {
|
|
2082
2128
|
if (!__ball_eq(inputMap, null)) {
|
|
2083
|
-
for (let i = 0; (i
|
|
2129
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
2084
2130
|
let p = __ball_index(params, i);
|
|
2085
2131
|
if ((p in inputMap)) {
|
|
2086
2132
|
scope.bind(p, __ball_index(inputMap, p));
|
|
@@ -2099,7 +2145,7 @@ export class BallEngine {
|
|
|
2099
2145
|
}
|
|
2100
2146
|
else {
|
|
2101
2147
|
if (Array.isArray(input)) {
|
|
2102
|
-
for (let i = 0; ((i
|
|
2148
|
+
for (let i = 0; (__ball_lt(i, params.length) && __ball_lt(i, input.length)); (i++)) {
|
|
2103
2149
|
scope.bind(__ball_index(params, i), __ball_index(input, i));
|
|
2104
2150
|
}
|
|
2105
2151
|
}
|
|
@@ -2229,7 +2275,7 @@ export class BallEngine {
|
|
|
2229
2275
|
}
|
|
2230
2276
|
async _callObjectConstructor(moduleName, func, input) {
|
|
2231
2277
|
let dotIdx = func.name.indexOf('.');
|
|
2232
|
-
let typeName = ((dotIdx
|
|
2278
|
+
let typeName = (__ball_ge(dotIdx, 0) ? func.name.substring(0, dotIdx) : func.name);
|
|
2233
2279
|
let typeDef = this._findTypeDef(typeName);
|
|
2234
2280
|
if (__ball_eq(typeDef, null)) {
|
|
2235
2281
|
return null;
|
|
@@ -2243,7 +2289,7 @@ export class BallEngine {
|
|
|
2243
2289
|
let params = (hasMetadata(func) ? this._extractParams(func.metadata) : []);
|
|
2244
2290
|
let paramsMeta = (hasMetadata(func) ? this._extractParamsMeta(func.metadata) : []);
|
|
2245
2291
|
let resolvedParams = {};
|
|
2246
|
-
for (let i = 0; (i
|
|
2292
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
2247
2293
|
let param = __ball_index(params, i);
|
|
2248
2294
|
let value = __no_init__;
|
|
2249
2295
|
if ((param in inputMap)) {
|
|
@@ -2254,11 +2300,11 @@ export class BallEngine {
|
|
|
2254
2300
|
value = __ball_index(inputMap, ('arg' + __ball_to_string(i)));
|
|
2255
2301
|
}
|
|
2256
2302
|
}
|
|
2257
|
-
if (((__ball_eq(value, null) && (i
|
|
2303
|
+
if (((__ball_eq(value, null) && __ball_lt(i, paramsMeta.length)) && ('default' in __ball_index(paramsMeta, i)))) {
|
|
2258
2304
|
value = __ball_index(__ball_index(paramsMeta, i), 'default');
|
|
2259
2305
|
}
|
|
2260
2306
|
resolvedParams[param] = value;
|
|
2261
|
-
let isThis = ((i
|
|
2307
|
+
let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
|
|
2262
2308
|
if ((isThis || allFieldNames.includes(param))) {
|
|
2263
2309
|
instanceFields[param] = value;
|
|
2264
2310
|
}
|
|
@@ -2326,7 +2372,7 @@ export class BallEngine {
|
|
|
2326
2372
|
let idx = __ball_parse_int(indexMatch.group(2));
|
|
2327
2373
|
let rawArr = __ball_index(resolvedParams, arrName);
|
|
2328
2374
|
let arr = (false /* BallList is List in TS */ ? rawArr.items : rawArr);
|
|
2329
|
-
if ((Array.isArray(arr) && (idx
|
|
2375
|
+
if ((Array.isArray(arr) && __ball_lt(idx, arr.length))) {
|
|
2330
2376
|
targetFields[name] = __ball_index(arr, idx);
|
|
2331
2377
|
}
|
|
2332
2378
|
else {
|
|
@@ -2374,14 +2420,14 @@ export class BallEngine {
|
|
|
2374
2420
|
let paramsMeta = this._extractParamsMeta(func.metadata);
|
|
2375
2421
|
let instance = {};
|
|
2376
2422
|
let dotIdx = func.name.indexOf('.');
|
|
2377
|
-
let typeName = ((dotIdx
|
|
2423
|
+
let typeName = (__ball_ge(dotIdx, 0) ? func.name.substring(0, dotIdx) : func.name);
|
|
2378
2424
|
instance['__type__'] = typeName;
|
|
2379
2425
|
let resolvedParams = {};
|
|
2380
2426
|
let inputMap = this._asMap(input);
|
|
2381
2427
|
if (!__ball_eq(inputMap, null)) {
|
|
2382
|
-
for (let i = 0; (i
|
|
2428
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
2383
2429
|
let p = __ball_index(params, i);
|
|
2384
|
-
let isThis = ((i
|
|
2430
|
+
let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
|
|
2385
2431
|
let val = __no_init__;
|
|
2386
2432
|
if ((p in inputMap)) {
|
|
2387
2433
|
val = __ball_index(inputMap, p);
|
|
@@ -2391,7 +2437,7 @@ export class BallEngine {
|
|
|
2391
2437
|
val = __ball_index(inputMap, ('arg' + __ball_to_string(i)));
|
|
2392
2438
|
}
|
|
2393
2439
|
else {
|
|
2394
|
-
val = ((i
|
|
2440
|
+
val = (__ball_lt(i, paramsMeta.length) ? __ball_index(__ball_index(paramsMeta, i), 'default') : null);
|
|
2395
2441
|
}
|
|
2396
2442
|
}
|
|
2397
2443
|
resolvedParams[p] = val;
|
|
@@ -2460,7 +2506,7 @@ export class BallEngine {
|
|
|
2460
2506
|
})() ?? '');
|
|
2461
2507
|
let argNames = this._parseSuperArgs(argsStr);
|
|
2462
2508
|
let superInput = {};
|
|
2463
|
-
for (let i = 0; (i
|
|
2509
|
+
for (let i = 0; __ball_lt(i, argNames.length); (i++)) {
|
|
2464
2510
|
let token = __ball_index(argNames, i);
|
|
2465
2511
|
if ((token in resolvedParams)) {
|
|
2466
2512
|
superInput[('arg' + __ball_to_string(i))] = __ball_index(resolvedParams, token);
|
|
@@ -2498,7 +2544,7 @@ export class BallEngine {
|
|
|
2498
2544
|
let superCtorEntry = this._lookupConstructor(superclass);
|
|
2499
2545
|
if (!__ball_eq(superCtorEntry, null)) {
|
|
2500
2546
|
let superInput = {};
|
|
2501
|
-
for (let i = 0; (i
|
|
2547
|
+
for (let i = 0; __ball_lt(i, resolvedParams.length); (i++)) {
|
|
2502
2548
|
superInput[('arg' + __ball_to_string(i))] = resolvedParams.values.elementAt(i);
|
|
2503
2549
|
}
|
|
2504
2550
|
return this._callFunction(superCtorEntry.module, superCtorEntry.func, superInput);
|
|
@@ -2518,7 +2564,7 @@ export class BallEngine {
|
|
|
2518
2564
|
for (const entry of this._constructors.entries) {
|
|
2519
2565
|
let key = entry.key;
|
|
2520
2566
|
let colonIdx = key.indexOf(':');
|
|
2521
|
-
let bare = ((colonIdx
|
|
2567
|
+
let bare = (__ball_ge(colonIdx, 0) ? key.substring(__ball_add(colonIdx, 1)) : key);
|
|
2522
2568
|
if (__ball_eq(bare, name)) {
|
|
2523
2569
|
return entry.value;
|
|
2524
2570
|
}
|
|
@@ -3094,7 +3140,7 @@ export class BallEngine {
|
|
|
3094
3140
|
if (__ball_eq((__ball_eq(kindField, null) ? null : kindField.stringValue), 'constructor')) {
|
|
3095
3141
|
let entry = { module: module.name, func: func };
|
|
3096
3142
|
let dotIdx = func.name.indexOf('.');
|
|
3097
|
-
if ((dotIdx
|
|
3143
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
3098
3144
|
let className = func.name.substring(0, dotIdx);
|
|
3099
3145
|
let ctorSuffix = func.name.substring(__ball_add(dotIdx, 1));
|
|
3100
3146
|
if (__ball_eq(ctorSuffix, 'new')) {
|
|
@@ -3323,7 +3369,7 @@ export class BallEngine {
|
|
|
3323
3369
|
let className = __ball_index(selfMap, '__class_ref__');
|
|
3324
3370
|
let qualifiedName = (className.includes(':') ? className : ((__ball_to_string(this._currentModule) + ':') + __ball_to_string(className)));
|
|
3325
3371
|
let colonIdx2 = qualifiedName.indexOf(':');
|
|
3326
|
-
let modPart2 = ((colonIdx2
|
|
3372
|
+
let modPart2 = (__ball_ge(colonIdx2, 0) ? qualifiedName.substring(0, colonIdx2) : this._currentModule);
|
|
3327
3373
|
let staticKey = ((((__ball_to_string(modPart2) + '.') + __ball_to_string(qualifiedName)) + '.') + __ball_to_string(call.function));
|
|
3328
3374
|
let staticFunc = __ball_index(this._functions, staticKey);
|
|
3329
3375
|
if (!__ball_eq(staticFunc, null)) {
|
|
@@ -3669,7 +3715,7 @@ export class BallEngine {
|
|
|
3669
3715
|
});
|
|
3670
3716
|
}
|
|
3671
3717
|
let colonIdx = name.indexOf(':');
|
|
3672
|
-
if ((colonIdx
|
|
3718
|
+
if (__ball_ge(colonIdx, 0)) {
|
|
3673
3719
|
let bare = name.substring(__ball_add(colonIdx, 1));
|
|
3674
3720
|
let bareEntry = __ball_index(this._constructors, bare);
|
|
3675
3721
|
if (!__ball_eq(bareEntry, null)) {
|
|
@@ -3835,7 +3881,7 @@ export class BallEngine {
|
|
|
3835
3881
|
});
|
|
3836
3882
|
}
|
|
3837
3883
|
let colonIdx = qualifiedName.indexOf(':');
|
|
3838
|
-
let modPart = ((colonIdx
|
|
3884
|
+
let modPart = (__ball_ge(colonIdx, 0) ? qualifiedName.substring(0, colonIdx) : this._currentModule);
|
|
3839
3885
|
let staticKey = ((((__ball_to_string(modPart) + '.') + __ball_to_string(qualifiedName)) + '.') + __ball_to_string(fieldName));
|
|
3840
3886
|
let staticFunc = __ball_index(this._functions, staticKey);
|
|
3841
3887
|
if (!__ball_eq(staticFunc, null)) {
|
|
@@ -4007,6 +4053,7 @@ export class BallEngine {
|
|
|
4007
4053
|
return e.key;
|
|
4008
4054
|
}))];
|
|
4009
4055
|
}
|
|
4056
|
+
throw new BallRuntimeError(('Cannot access field "keys" on ' + __ball_to_string(((__ball_eq(object, null) ? null : object.runtimeType) ?? 'null'))));
|
|
4010
4057
|
}
|
|
4011
4058
|
else if ((__sw === 'values')) {
|
|
4012
4059
|
if ((typeof object === 'object' && object !== null && !Array.isArray(object) && !(object instanceof BallDouble) && !(object instanceof Set))) {
|
|
@@ -4024,6 +4071,7 @@ export class BallEngine {
|
|
|
4024
4071
|
}
|
|
4025
4072
|
return vals;
|
|
4026
4073
|
}
|
|
4074
|
+
throw new BallRuntimeError(('Cannot access field "values" on ' + __ball_to_string(((__ball_eq(object, null) ? null : object.runtimeType) ?? 'null'))));
|
|
4027
4075
|
}
|
|
4028
4076
|
else if ((__sw === 'isNaN')) {
|
|
4029
4077
|
return _ballNumIsNaN(object);
|
|
@@ -4103,7 +4151,7 @@ export class BallEngine {
|
|
|
4103
4151
|
return _sentinel;
|
|
4104
4152
|
}
|
|
4105
4153
|
let colonIdx = typeName.indexOf(':');
|
|
4106
|
-
let modPart = ((colonIdx
|
|
4154
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
4107
4155
|
let getterKey = ((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(fieldName));
|
|
4108
4156
|
let getterFunc = (__ball_index(this._getters, getterKey) ?? __ball_index(this._functions, getterKey));
|
|
4109
4157
|
if ((!__ball_eq(getterFunc, null) && this._isGetter(getterFunc))) {
|
|
@@ -4115,8 +4163,8 @@ export class BallEngine {
|
|
|
4115
4163
|
let superType = __ball_index(superMap, '__type__');
|
|
4116
4164
|
if (!__ball_eq(superType, null)) {
|
|
4117
4165
|
let sColonIdx = superType.indexOf(':');
|
|
4118
|
-
let sModPart = ((sColonIdx
|
|
4119
|
-
let sTypeName = ((sColonIdx
|
|
4166
|
+
let sModPart = (__ball_ge(sColonIdx, 0) ? superType.substring(0, sColonIdx) : modPart);
|
|
4167
|
+
let sTypeName = (__ball_ge(sColonIdx, 0) ? superType : ((__ball_to_string(sModPart) + ':') + __ball_to_string(superType)));
|
|
4120
4168
|
let superGetterKey = ((((__ball_to_string(sModPart) + '.') + __ball_to_string(sTypeName)) + '.') + __ball_to_string(fieldName));
|
|
4121
4169
|
let superGetterFunc = (__ball_index(this._getters, superGetterKey) ?? __ball_index(this._functions, superGetterKey));
|
|
4122
4170
|
if ((!__ball_eq(superGetterFunc, null) && this._isGetter(superGetterFunc))) {
|
|
@@ -4161,7 +4209,7 @@ export class BallEngine {
|
|
|
4161
4209
|
return _sentinel;
|
|
4162
4210
|
}
|
|
4163
4211
|
let colonIdx = typeName.indexOf(':');
|
|
4164
|
-
let modPart = ((colonIdx
|
|
4212
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
4165
4213
|
let setterKey = (((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(fieldName)) + '=');
|
|
4166
4214
|
let setterKeyNoEq = ((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(fieldName));
|
|
4167
4215
|
let setterFunc = ((__ball_index(this._setters, setterKey) ?? __ball_index(this._setters, setterKeyNoEq)) ?? __ball_index(this._functions, setterKey));
|
|
@@ -4176,8 +4224,8 @@ export class BallEngine {
|
|
|
4176
4224
|
let superType = __ball_index(superMap, '__type__');
|
|
4177
4225
|
if (!__ball_eq(superType, null)) {
|
|
4178
4226
|
let sColonIdx = superType.indexOf(':');
|
|
4179
|
-
let sModPart = ((sColonIdx
|
|
4180
|
-
let sTypeName = ((sColonIdx
|
|
4227
|
+
let sModPart = (__ball_ge(sColonIdx, 0) ? superType.substring(0, sColonIdx) : modPart);
|
|
4228
|
+
let sTypeName = (__ball_ge(sColonIdx, 0) ? superType : ((__ball_to_string(sModPart) + ':') + __ball_to_string(superType)));
|
|
4181
4229
|
let superSetterKey = (((((__ball_to_string(sModPart) + '.') + __ball_to_string(sTypeName)) + '.') + __ball_to_string(fieldName)) + '=');
|
|
4182
4230
|
let superSetterKeyNoEq = ((((__ball_to_string(sModPart) + '.') + __ball_to_string(sTypeName)) + '.') + __ball_to_string(fieldName));
|
|
4183
4231
|
let superSetterFunc = ((__ball_index(this._setters, superSetterKey) ?? __ball_index(this._setters, superSetterKeyNoEq)) ?? __ball_index(this._functions, superSetterKey));
|
|
@@ -4275,7 +4323,7 @@ export class BallEngine {
|
|
|
4275
4323
|
if ((!__ball_eq(ctorEntry, null) && hasMetadata(ctorEntry.func))) {
|
|
4276
4324
|
let params = this._extractParams(ctorEntry.func.metadata);
|
|
4277
4325
|
let paramsMeta = this._extractParamsMeta(ctorEntry.func.metadata);
|
|
4278
|
-
for (let i = 0; (i
|
|
4326
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
4279
4327
|
let param = __ball_index(params, i);
|
|
4280
4328
|
let value = __no_init__;
|
|
4281
4329
|
if ((param in fields)) {
|
|
@@ -4286,11 +4334,11 @@ export class BallEngine {
|
|
|
4286
4334
|
value = __ball_index(fields, ('arg' + __ball_to_string(i)));
|
|
4287
4335
|
}
|
|
4288
4336
|
}
|
|
4289
|
-
if (((__ball_eq(value, null) && (i
|
|
4337
|
+
if (((__ball_eq(value, null) && __ball_lt(i, paramsMeta.length)) && ('default' in __ball_index(paramsMeta, i)))) {
|
|
4290
4338
|
value = __ball_index(__ball_index(paramsMeta, i), 'default');
|
|
4291
4339
|
}
|
|
4292
4340
|
resolvedParams[param] = value;
|
|
4293
|
-
let isThis = ((i
|
|
4341
|
+
let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
|
|
4294
4342
|
if ((isThis || allFieldNames.includes(param))) {
|
|
4295
4343
|
instanceFields[param] = value;
|
|
4296
4344
|
}
|
|
@@ -4424,7 +4472,7 @@ export class BallEngine {
|
|
|
4424
4472
|
let selfType = __ball_index(selfObjMap, '__type__');
|
|
4425
4473
|
if (!__ball_eq(selfType, null)) {
|
|
4426
4474
|
let colonIdx = msg.typeName.indexOf(':');
|
|
4427
|
-
let methodName = ((colonIdx
|
|
4475
|
+
let methodName = (__ball_ge(colonIdx, 0) ? msg.typeName.substring(__ball_add(colonIdx, 1)) : msg.typeName);
|
|
4428
4476
|
let resolved = this._resolveMethod(selfType, methodName);
|
|
4429
4477
|
if (!__ball_eq(resolved, null)) {
|
|
4430
4478
|
fields['self'] = selfObj;
|
|
@@ -4552,7 +4600,7 @@ export class BallEngine {
|
|
|
4552
4600
|
if ((__ball_eq(trimmed, '""') || __ball_eq(trimmed, '\'\''))) {
|
|
4553
4601
|
return '';
|
|
4554
4602
|
}
|
|
4555
|
-
if ((((trimmed.length
|
|
4603
|
+
if (((__ball_ge(trimmed.length, 2) && trimmed.startsWith('[')) && trimmed.endsWith(']'))) {
|
|
4556
4604
|
let inner = trimmed.substring(1, __ball_sub(trimmed.length, 1)).trim();
|
|
4557
4605
|
if ((inner.length === 0)) {
|
|
4558
4606
|
return [];
|
|
@@ -4578,7 +4626,7 @@ export class BallEngine {
|
|
|
4578
4626
|
if (!__ball_eq(doubleVal, null)) {
|
|
4579
4627
|
return doubleVal;
|
|
4580
4628
|
}
|
|
4581
|
-
if (((trimmed.length
|
|
4629
|
+
if ((__ball_ge(trimmed.length, 2) && ((trimmed.startsWith('\'') && trimmed.endsWith('\'')) || (trimmed.startsWith('"') && trimmed.endsWith('"'))))) {
|
|
4582
4630
|
return trimmed.substring(1, __ball_sub(trimmed.length, 1));
|
|
4583
4631
|
}
|
|
4584
4632
|
return trimmed;
|
|
@@ -4596,7 +4644,7 @@ export class BallEngine {
|
|
|
4596
4644
|
return names;
|
|
4597
4645
|
}
|
|
4598
4646
|
let colonIdx = typeName.indexOf(':');
|
|
4599
|
-
let modPart = ((colonIdx
|
|
4647
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
4600
4648
|
let superclass = typeDef.superclass;
|
|
4601
4649
|
if ((!__ball_eq(superclass, null) && !(superclass.length === 0))) {
|
|
4602
4650
|
let qualifiedSuper = (superclass.includes(':') ? superclass : ((__ball_to_string(modPart) + ':') + __ball_to_string(superclass)));
|
|
@@ -4650,7 +4698,7 @@ export class BallEngine {
|
|
|
4650
4698
|
});
|
|
4651
4699
|
methods[func.name] = closure;
|
|
4652
4700
|
let dotIdx = func.name.lastIndexOf('.');
|
|
4653
|
-
if ((dotIdx
|
|
4701
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
4654
4702
|
methods[func.name.substring(__ball_add(dotIdx, 1))] = closure;
|
|
4655
4703
|
}
|
|
4656
4704
|
continue;
|
|
@@ -4658,7 +4706,7 @@ export class BallEngine {
|
|
|
4658
4706
|
}
|
|
4659
4707
|
let funcName = func.name;
|
|
4660
4708
|
let dotIdx = funcName.lastIndexOf('.');
|
|
4661
|
-
if ((dotIdx
|
|
4709
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
4662
4710
|
let prefix = funcName.substring(0, dotIdx);
|
|
4663
4711
|
let suffix = funcName.substring(__ball_add(dotIdx, 1));
|
|
4664
4712
|
if (__ball_eq(suffix, 'new')) {
|
|
@@ -4687,7 +4735,7 @@ export class BallEngine {
|
|
|
4687
4735
|
const input = typeName;
|
|
4688
4736
|
let methods = {};
|
|
4689
4737
|
let colonIdx = typeName.indexOf(':');
|
|
4690
|
-
let modPart = ((colonIdx
|
|
4738
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
4691
4739
|
let typeDef = this._findTypeDef(typeName);
|
|
4692
4740
|
if (((!__ball_eq(typeDef, null) && !__ball_eq(typeDef.superclass, null)) && !(typeDef.superclass.length === 0))) {
|
|
4693
4741
|
let qualSuper = (typeDef.superclass.includes(':') ? typeDef.superclass : ((__ball_to_string(modPart) + ':') + __ball_to_string(typeDef.superclass)));
|
|
@@ -4774,7 +4822,7 @@ export class BallEngine {
|
|
|
4774
4822
|
}
|
|
4775
4823
|
}
|
|
4776
4824
|
if (!(paramNames.length === 0)) {
|
|
4777
|
-
for (let i = 0; (i
|
|
4825
|
+
for (let i = 0; __ball_lt(i, paramNames.length); (i++)) {
|
|
4778
4826
|
let p = __ball_index(paramNames, i);
|
|
4779
4827
|
if (!lambdaScope.has(p)) {
|
|
4780
4828
|
if ((p in inputMap)) {
|
|
@@ -5303,7 +5351,7 @@ export class BallEngine {
|
|
|
5303
5351
|
}
|
|
5304
5352
|
_matchSwitchPattern(subject, pattern) {
|
|
5305
5353
|
let dotIdx = pattern.indexOf('.');
|
|
5306
|
-
if ((dotIdx
|
|
5354
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
5307
5355
|
let enumType = pattern.substring(0, dotIdx);
|
|
5308
5356
|
let enumValue = pattern.substring(__ball_add(dotIdx, 1));
|
|
5309
5357
|
let subjectMap = this._cfAsMap(subject);
|
|
@@ -5311,7 +5359,7 @@ export class BallEngine {
|
|
|
5311
5359
|
let typeName = __ball_index(subjectMap, '__type__');
|
|
5312
5360
|
if (!__ball_eq(typeName, null)) {
|
|
5313
5361
|
let colonIdx = typeName.indexOf(':');
|
|
5314
|
-
let bareType = ((colonIdx
|
|
5362
|
+
let bareType = (__ball_ge(colonIdx, 0) ? typeName.substring(__ball_add(colonIdx, 1)) : typeName);
|
|
5315
5363
|
if ((__ball_eq(bareType, enumType) && __ball_eq(__ball_index(subjectMap, 'name'), enumValue))) {
|
|
5316
5364
|
return true;
|
|
5317
5365
|
}
|
|
@@ -5385,14 +5433,14 @@ export class BallEngine {
|
|
|
5385
5433
|
if ((e instanceof BallException)) {
|
|
5386
5434
|
let eType = e['typeName'];
|
|
5387
5435
|
let eColonIdx = eType.indexOf(':');
|
|
5388
|
-
let eBare = ((eColonIdx
|
|
5436
|
+
let eBare = (__ball_ge(eColonIdx, 0) ? eType.substring(__ball_add(eColonIdx, 1)) : eType);
|
|
5389
5437
|
matches = (__ball_eq(eType, catchType) || __ball_eq(eBare, catchType));
|
|
5390
5438
|
}
|
|
5391
5439
|
else {
|
|
5392
5440
|
if (((typeof e === 'object' && e !== null && !Array.isArray(e) && !(e instanceof BallDouble) && !(e instanceof Set)) && !__ball_eq(__ball_index(e, '__type__'), null))) {
|
|
5393
5441
|
let eType = __ball_to_string(__ball_index(e, '__type__'));
|
|
5394
5442
|
let eColonIdx = eType.indexOf(':');
|
|
5395
|
-
let eBare = ((eColonIdx
|
|
5443
|
+
let eBare = (__ball_ge(eColonIdx, 0) ? eType.substring(__ball_add(eColonIdx, 1)) : eType);
|
|
5396
5444
|
matches = (__ball_eq(eType, catchType) || __ball_eq(eBare, catchType));
|
|
5397
5445
|
}
|
|
5398
5446
|
else {
|
|
@@ -6344,15 +6392,15 @@ export class BallEngine {
|
|
|
6344
6392
|
else if ((__sw === 'sort')) {
|
|
6345
6393
|
if ((typeof arg0 === 'function')) {
|
|
6346
6394
|
let sorted = [...self];
|
|
6347
|
-
for (let j = 1; (j
|
|
6395
|
+
for (let j = 1; __ball_lt(j, sorted.length); (j++)) {
|
|
6348
6396
|
let key = __ball_index(sorted, j);
|
|
6349
6397
|
let k = __ball_sub(j, 1);
|
|
6350
|
-
while ((k
|
|
6398
|
+
while (__ball_ge(k, 0)) {
|
|
6351
6399
|
let r = arg0({ ['arg0']: __ball_index(sorted, k), ['arg1']: key, ['a']: __ball_index(sorted, k), ['b']: key, ['left']: __ball_index(sorted, k), ['right']: key });
|
|
6352
6400
|
if ((r != null)) {
|
|
6353
6401
|
r = await r;
|
|
6354
6402
|
}
|
|
6355
|
-
if (((typeof r === 'number' || r instanceof BallDouble) && (r
|
|
6403
|
+
if (((typeof r === 'number' || r instanceof BallDouble) && __ball_gt(r, 0))) {
|
|
6356
6404
|
sorted[__ball_add(k, 1)] = __ball_index(sorted, k);
|
|
6357
6405
|
(k--);
|
|
6358
6406
|
}
|
|
@@ -6887,14 +6935,14 @@ export class BallEngine {
|
|
|
6887
6935
|
}
|
|
6888
6936
|
let typeName = __ball_index(leftMap, '__type__');
|
|
6889
6937
|
let colonIdx = typeName.indexOf(':');
|
|
6890
|
-
let modPart = ((colonIdx
|
|
6938
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
6891
6939
|
let current = leftMap;
|
|
6892
6940
|
while (!__ball_eq(current, null)) {
|
|
6893
6941
|
let curType = __ball_index(current, '__type__');
|
|
6894
6942
|
if (!__ball_eq(curType, null)) {
|
|
6895
6943
|
let cColonIdx = curType.indexOf(':');
|
|
6896
|
-
let cModPart = ((cColonIdx
|
|
6897
|
-
let cTypeName = ((cColonIdx
|
|
6944
|
+
let cModPart = (__ball_ge(cColonIdx, 0) ? curType.substring(0, cColonIdx) : modPart);
|
|
6945
|
+
let cTypeName = (__ball_ge(cColonIdx, 0) ? curType : ((__ball_to_string(cModPart) + ':') + __ball_to_string(curType)));
|
|
6898
6946
|
let opSymbol = __ball_index(_stdFunctionToOperatorSymbol, function_);
|
|
6899
6947
|
let method = __ball_index(this._functions, ((((__ball_to_string(cModPart) + '.') + __ball_to_string(cTypeName)) + '.') + __ball_to_string(op)));
|
|
6900
6948
|
method ??= (__ball_eq(opSymbol, null) ? null : __ball_index(this._functions, ((((__ball_to_string(cModPart) + '.') + __ball_to_string(cTypeName)) + '.') + __ball_to_string(opSymbol))));
|
|
@@ -7018,22 +7066,22 @@ export class BallEngine {
|
|
|
7018
7066
|
}), ['less_than']: ((i) => {
|
|
7019
7067
|
const input = i;
|
|
7020
7068
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
7021
|
-
return (a
|
|
7069
|
+
return __ball_lt(a, b);
|
|
7022
7070
|
}));
|
|
7023
7071
|
}), ['greater_than']: ((i) => {
|
|
7024
7072
|
const input = i;
|
|
7025
7073
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
7026
|
-
return (a
|
|
7074
|
+
return __ball_gt(a, b);
|
|
7027
7075
|
}));
|
|
7028
7076
|
}), ['lte']: ((i) => {
|
|
7029
7077
|
const input = i;
|
|
7030
7078
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
7031
|
-
return (a
|
|
7079
|
+
return __ball_le(a, b);
|
|
7032
7080
|
}));
|
|
7033
7081
|
}), ['gte']: ((i) => {
|
|
7034
7082
|
const input = i;
|
|
7035
7083
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
7036
|
-
return (a
|
|
7084
|
+
return __ball_ge(a, b);
|
|
7037
7085
|
}));
|
|
7038
7086
|
}), ['and']: ((i) => {
|
|
7039
7087
|
const input = i;
|
|
@@ -7145,7 +7193,7 @@ export class BallEngine {
|
|
|
7145
7193
|
}
|
|
7146
7194
|
let a = this._toNum(v);
|
|
7147
7195
|
let b = this._toNum(other);
|
|
7148
|
-
return ((a
|
|
7196
|
+
return (__ball_lt(a, b) ? __ball_negate(1) : ((__ball_gt(a, b) ? 1 : 0)));
|
|
7149
7197
|
}), ['to_string_as_fixed']: ((i) => {
|
|
7150
7198
|
const input = i;
|
|
7151
7199
|
let m = (this._stdAsMap(i) ?? { ['value']: i });
|
|
@@ -7153,7 +7201,7 @@ export class BallEngine {
|
|
|
7153
7201
|
let digits = (__ball_index(m, 'digits') ?? __ball_index(m, 'fractionDigits'));
|
|
7154
7202
|
let n = this._toNum(v);
|
|
7155
7203
|
let s = (+(n)).toFixed(this._toInt(digits));
|
|
7156
|
-
if (((__ball_eq(n, 0) && (new BallDouble(Number(new BallDouble(1)) / Number(n))
|
|
7204
|
+
if (((__ball_eq(n, 0) && __ball_lt(new BallDouble(Number(new BallDouble(1)) / Number(n)), 0)) && !s.startsWith('-'))) {
|
|
7157
7205
|
return ('-' + __ball_to_string(s));
|
|
7158
7206
|
}
|
|
7159
7207
|
return s;
|
|
@@ -7439,16 +7487,16 @@ export class BallEngine {
|
|
|
7439
7487
|
}));
|
|
7440
7488
|
return sorted;
|
|
7441
7489
|
}
|
|
7442
|
-
for (let j = 1; (j
|
|
7490
|
+
for (let j = 1; __ball_lt(j, sorted.length); (j++)) {
|
|
7443
7491
|
let key = __ball_index(sorted, j);
|
|
7444
7492
|
let k = __ball_sub(j, 1);
|
|
7445
|
-
while ((k
|
|
7493
|
+
while (__ball_ge(k, 0)) {
|
|
7446
7494
|
let r = cb({ ['left']: __ball_index(sorted, k), ['right']: key, ['arg0']: __ball_index(sorted, k), ['arg1']: key, ['a']: __ball_index(sorted, k), ['b']: key });
|
|
7447
7495
|
if ((r != null)) {
|
|
7448
7496
|
r = await r;
|
|
7449
7497
|
}
|
|
7450
7498
|
let cmp = ((typeof r === 'number' && Number.isInteger(r)) ? r : __ball_to_int(r));
|
|
7451
|
-
if ((cmp
|
|
7499
|
+
if (__ball_le(cmp, 0)) {
|
|
7452
7500
|
break;
|
|
7453
7501
|
}
|
|
7454
7502
|
sorted[__ball_add(k, 1)] = __ball_index(sorted, k);
|
|
@@ -7504,7 +7552,7 @@ export class BallEngine {
|
|
|
7504
7552
|
else {
|
|
7505
7553
|
if (('value' in m)) {
|
|
7506
7554
|
let v = __ball_index(m, 'value');
|
|
7507
|
-
if ((Array.isArray(v) && (v.length
|
|
7555
|
+
if ((Array.isArray(v) && __ball_ge(v.length, 2))) {
|
|
7508
7556
|
s = this._toInt(__ball_index(v, 0));
|
|
7509
7557
|
e = this._toInt(__ball_index(v, 1));
|
|
7510
7558
|
}
|
|
@@ -7554,7 +7602,7 @@ export class BallEngine {
|
|
|
7554
7602
|
let m = this._stdAsMap(i);
|
|
7555
7603
|
let a = this._stdAsList(__ball_index(m, 'list'));
|
|
7556
7604
|
let b = this._stdAsList(__ball_index(m, 'value'));
|
|
7557
|
-
let len = ((a.length
|
|
7605
|
+
let len = (__ball_lt(a.length, b.length) ? a.length : b.length);
|
|
7558
7606
|
this._trackMemoryAllocation(__ball_mul(len, _ballPointerBytes));
|
|
7559
7607
|
return List.generate(len, ((j) => {
|
|
7560
7608
|
const input = j;
|
|
@@ -7725,19 +7773,27 @@ export class BallEngine {
|
|
|
7725
7773
|
}), ['map_keys']: ((i) => {
|
|
7726
7774
|
const input = i;
|
|
7727
7775
|
let m = this._stdAsMap(i);
|
|
7728
|
-
|
|
7776
|
+
let target = __ball_index(m, 'map');
|
|
7777
|
+
if (this._isBallSet(target)) {
|
|
7729
7778
|
return [];
|
|
7730
7779
|
}
|
|
7731
|
-
|
|
7780
|
+
if ((!((typeof target === 'object' && target !== null && !Array.isArray(target) && !(target instanceof BallDouble) && !(target instanceof Set))) && !(false /* BallMap is Map in TS */))) {
|
|
7781
|
+
throw new BallRuntimeError('map_keys: expected Map or Set');
|
|
7782
|
+
}
|
|
7783
|
+
let result = _ballMapKeysDyn(target);
|
|
7732
7784
|
this._trackMemoryAllocation(__ball_mul(result.length, _ballPointerBytes));
|
|
7733
7785
|
return result;
|
|
7734
7786
|
}), ['map_values']: ((i) => {
|
|
7735
7787
|
const input = i;
|
|
7736
7788
|
let m = this._stdAsMap(i);
|
|
7737
|
-
|
|
7789
|
+
let target = __ball_index(m, 'map');
|
|
7790
|
+
if (this._isBallSet(target)) {
|
|
7738
7791
|
return [];
|
|
7739
7792
|
}
|
|
7740
|
-
|
|
7793
|
+
if ((!((typeof target === 'object' && target !== null && !Array.isArray(target) && !(target instanceof BallDouble) && !(target instanceof Set))) && !(false /* BallMap is Map in TS */))) {
|
|
7794
|
+
throw new BallRuntimeError('map_values: expected Map or Set');
|
|
7795
|
+
}
|
|
7796
|
+
let result = _ballMapValuesDyn(target);
|
|
7741
7797
|
this._trackMemoryAllocation(__ball_mul(result.length, _ballPointerBytes));
|
|
7742
7798
|
return result;
|
|
7743
7799
|
}), ['map_entries']: ((i) => {
|
|
@@ -8206,12 +8262,12 @@ export class BallEngine {
|
|
|
8206
8262
|
}), ['math_min']: ((i) => {
|
|
8207
8263
|
const input = i;
|
|
8208
8264
|
return this._stdBinary(i, ((a, b) => {
|
|
8209
|
-
return ((a
|
|
8265
|
+
return (__ball_lt(a, b) ? a : b);
|
|
8210
8266
|
}));
|
|
8211
8267
|
}), ['math_max']: ((i) => {
|
|
8212
8268
|
const input = i;
|
|
8213
8269
|
return this._stdBinary(i, ((a, b) => {
|
|
8214
|
-
return ((a
|
|
8270
|
+
return (__ball_gt(a, b) ? a : b);
|
|
8215
8271
|
}));
|
|
8216
8272
|
}), ['math_clamp']: this._stdMathClamp.bind(this), ['math_pi']: ((_) => {
|
|
8217
8273
|
const input = _;
|
|
@@ -8280,7 +8336,7 @@ export class BallEngine {
|
|
|
8280
8336
|
}), ['sleep_ms']: (async (i) => {
|
|
8281
8337
|
const input = i;
|
|
8282
8338
|
let ms = ((typeof i === 'number' || i instanceof BallDouble) ? __ball_to_int(i) : 0);
|
|
8283
|
-
if ((ms
|
|
8339
|
+
if (__ball_gt(ms, 0)) {
|
|
8284
8340
|
await Future.delayed(new Duration({ milliseconds: ms }));
|
|
8285
8341
|
}
|
|
8286
8342
|
}), ['timestamp_ms']: ((_) => {
|
|
@@ -8456,14 +8512,14 @@ export class BallEngine {
|
|
|
8456
8512
|
_manualReverse(list) {
|
|
8457
8513
|
const input = list;
|
|
8458
8514
|
let result = [];
|
|
8459
|
-
for (let i = __ball_sub(list.length, 1); (i
|
|
8515
|
+
for (let i = __ball_sub(list.length, 1); __ball_ge(i, 0); (i--)) {
|
|
8460
8516
|
result = (result.push(__ball_index(list, i)), result);
|
|
8461
8517
|
}
|
|
8462
8518
|
return result;
|
|
8463
8519
|
}
|
|
8464
8520
|
_resolveMethod(typeName, methodName) {
|
|
8465
8521
|
let colonIdx = typeName.indexOf(':');
|
|
8466
|
-
let modPart = ((colonIdx
|
|
8522
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
8467
8523
|
let methodKey = ((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(methodName));
|
|
8468
8524
|
let method = __ball_index(this._functions, methodKey);
|
|
8469
8525
|
if ((!__ball_eq(method, null) && !method.isBase)) {
|
|
@@ -8710,7 +8766,7 @@ export class BallEngine {
|
|
|
8710
8766
|
}
|
|
8711
8767
|
this._trackMemoryAllocation(__ball_mul(length, _ballPointerBytes));
|
|
8712
8768
|
let result = [];
|
|
8713
|
-
for (let index = 0; (index
|
|
8769
|
+
for (let index = 0; __ball_lt(index, length); (index++)) {
|
|
8714
8770
|
let value = generator(index);
|
|
8715
8771
|
if ((value != null)) {
|
|
8716
8772
|
value = await value;
|
|
@@ -8858,7 +8914,7 @@ export class BallEngine {
|
|
|
8858
8914
|
}
|
|
8859
8915
|
}
|
|
8860
8916
|
if (__ball_eq(objTypeArgs.length, typeArgs.length)) {
|
|
8861
|
-
for (let i = 0; (i
|
|
8917
|
+
for (let i = 0; __ball_lt(i, typeArgs.length); (i++)) {
|
|
8862
8918
|
if (!__ball_eq(__ball_index(objTypeArgs, i), __ball_index(typeArgs, i))) {
|
|
8863
8919
|
return false;
|
|
8864
8920
|
}
|
|
@@ -8939,7 +8995,7 @@ export class BallEngine {
|
|
|
8939
8995
|
}
|
|
8940
8996
|
let objColon = objType.indexOf(':');
|
|
8941
8997
|
let checkColon = checkType.indexOf(':');
|
|
8942
|
-
if (((objColon
|
|
8998
|
+
if ((__ball_ge(objColon, 0) && __ball_ge(checkColon, 0))) {
|
|
8943
8999
|
return __ball_eq(objType.substring(__ball_add(objColon, 1)), checkType.substring(__ball_add(checkColon, 1)));
|
|
8944
9000
|
}
|
|
8945
9001
|
return false;
|
|
@@ -8949,7 +9005,7 @@ export class BallEngine {
|
|
|
8949
9005
|
let args = [];
|
|
8950
9006
|
let depth = 0;
|
|
8951
9007
|
let start = 0;
|
|
8952
|
-
for (let i = 0; (i
|
|
9008
|
+
for (let i = 0; __ball_lt(i, str.length); (i++)) {
|
|
8953
9009
|
if (__ball_eq(__ball_index(str, i), '<')) {
|
|
8954
9010
|
(depth++);
|
|
8955
9011
|
}
|
|
@@ -9113,7 +9169,7 @@ export class BallEngine {
|
|
|
9113
9169
|
let rhsStr = relMatch.group(2).trim();
|
|
9114
9170
|
let rhs = num.tryParse(rhsStr);
|
|
9115
9171
|
if (!__ball_eq(rhs, null)) {
|
|
9116
|
-
return ((op === '==') ? (__ball_eq(value, rhs)) : ((op === '!=') ? (!__ball_eq(value, rhs)) : ((op === '>') ? ((value
|
|
9172
|
+
return ((op === '==') ? (__ball_eq(value, rhs)) : ((op === '!=') ? (!__ball_eq(value, rhs)) : ((op === '>') ? (__ball_gt(value, rhs)) : ((op === '<') ? (__ball_lt(value, rhs)) : ((op === '>=') ? (__ball_ge(value, rhs)) : ((op === '<=') ? (__ball_le(value, rhs)) : false))))));
|
|
9117
9173
|
}
|
|
9118
9174
|
}
|
|
9119
9175
|
if (this._matchesTypePattern(value, trimmed)) {
|
|
@@ -9175,10 +9231,10 @@ export class BallEngine {
|
|
|
9175
9231
|
if ((__ball_eq(restIndex, __ball_negate(1)) && !__ball_eq(listVal.length, fixedCount))) {
|
|
9176
9232
|
return false;
|
|
9177
9233
|
}
|
|
9178
|
-
if ((!__ball_eq(restIndex, __ball_negate(1)) && (listVal.length
|
|
9234
|
+
if ((!__ball_eq(restIndex, __ball_negate(1)) && __ball_lt(listVal.length, fixedCount))) {
|
|
9179
9235
|
return false;
|
|
9180
9236
|
}
|
|
9181
|
-
for (let i = 0; (i
|
|
9237
|
+
for (let i = 0; __ball_lt(i, elements.length); (i++)) {
|
|
9182
9238
|
let elem = __ball_index(elements, i);
|
|
9183
9239
|
let elemMap = this._stdAsMap(elem);
|
|
9184
9240
|
if ((!__ball_eq(elemMap, null) && __ball_eq(this._patternKind(elemMap), 'rest'))) {
|
|
@@ -9189,7 +9245,7 @@ export class BallEngine {
|
|
|
9189
9245
|
}
|
|
9190
9246
|
continue;
|
|
9191
9247
|
}
|
|
9192
|
-
let valueIndex = ((__ball_eq(restIndex, __ball_negate(1)) || (i
|
|
9248
|
+
let valueIndex = ((__ball_eq(restIndex, __ball_negate(1)) || __ball_lt(i, restIndex)) ? i : __ball_sub(listVal.length, __ball_sub(elements.length, i)));
|
|
9193
9249
|
if (!this._matchPattern(__ball_index(listVal, valueIndex), elem, bindings)) {
|
|
9194
9250
|
return false;
|
|
9195
9251
|
}
|
|
@@ -9355,7 +9411,7 @@ export class BallEngine {
|
|
|
9355
9411
|
if (__ball_eq(operator, null)) {
|
|
9356
9412
|
return false;
|
|
9357
9413
|
}
|
|
9358
|
-
return ((operator === '==') ? (this._ballEquals(value, operand)) : ((operator === '!=') ? (!this._ballEquals(value, operand)) : ((operator === '>') ? ((((typeof value === 'number' || value instanceof BallDouble) && (typeof operand === 'number' || operand instanceof BallDouble)) && (value
|
|
9414
|
+
return ((operator === '==') ? (this._ballEquals(value, operand)) : ((operator === '!=') ? (!this._ballEquals(value, operand)) : ((operator === '>') ? ((((typeof value === 'number' || value instanceof BallDouble) && (typeof operand === 'number' || operand instanceof BallDouble)) && __ball_gt(value, operand))) : ((operator === '<') ? ((((typeof value === 'number' || value instanceof BallDouble) && (typeof operand === 'number' || operand instanceof BallDouble)) && __ball_lt(value, operand))) : ((operator === '>=') ? ((((typeof value === 'number' || value instanceof BallDouble) && (typeof operand === 'number' || operand instanceof BallDouble)) && __ball_ge(value, operand))) : ((operator === '<=') ? ((((typeof value === 'number' || value instanceof BallDouble) && (typeof operand === 'number' || operand instanceof BallDouble)) && __ball_le(value, operand))) : false))))));
|
|
9359
9415
|
}
|
|
9360
9416
|
_matchesObjectType(value, patternType) {
|
|
9361
9417
|
let actual = (() => {
|
|
@@ -9428,7 +9484,7 @@ export class BallEngine {
|
|
|
9428
9484
|
}
|
|
9429
9485
|
_matchesTypePattern(value, pattern) {
|
|
9430
9486
|
let p = ((typeof pattern === 'string') ? pattern : this._ballToStringSimple(pattern));
|
|
9431
|
-
if ((((p.length
|
|
9487
|
+
if (((__ball_gt(p.length, 1) && p.endsWith('?')) && !p.includes(' '))) {
|
|
9432
9488
|
if ((__ball_eq(value, null) || (value == null))) {
|
|
9433
9489
|
return true;
|
|
9434
9490
|
}
|
|
@@ -9491,7 +9547,7 @@ export class BallEngine {
|
|
|
9491
9547
|
}
|
|
9492
9548
|
_repeatString(s, count) {
|
|
9493
9549
|
let out = '';
|
|
9494
|
-
for (let k = 0; (k
|
|
9550
|
+
for (let k = 0; __ball_lt(k, count); (k++)) {
|
|
9495
9551
|
out = (__ball_to_string(out) + __ball_to_string(s));
|
|
9496
9552
|
}
|
|
9497
9553
|
return out;
|
|
@@ -10195,14 +10251,14 @@ function _ballDoubleToInt64(value) {
|
|
|
10195
10251
|
return value.value;
|
|
10196
10252
|
}
|
|
10197
10253
|
let d = (((typeof value === 'number' || value instanceof BallDouble) ? value.value : new BallDouble(Number(value))));
|
|
10198
|
-
if ((d
|
|
10254
|
+
if (__ball_ge(d, new BallDouble(9223372036854776000))) {
|
|
10199
10255
|
return 9223372036854775807n;
|
|
10200
10256
|
}
|
|
10201
|
-
if ((d
|
|
10257
|
+
if (__ball_le(d, __ball_negate(new BallDouble(9223372036854776000)))) {
|
|
10202
10258
|
return __ball_negate(0);
|
|
10203
10259
|
}
|
|
10204
10260
|
let r = __ball_to_int(d);
|
|
10205
|
-
if (((d
|
|
10261
|
+
if ((__ball_gt(d, new BallDouble(0)) && __ball_lt(r, 0))) {
|
|
10206
10262
|
return 9223372036854775807n;
|
|
10207
10263
|
}
|
|
10208
10264
|
return r;
|