@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/src/compiled_engine.ts
CHANGED
|
@@ -120,8 +120,14 @@ class BallDouble {
|
|
|
120
120
|
|
|
121
121
|
// Arithmetic helpers that propagate BallDouble through operations.
|
|
122
122
|
// If either operand is BallDouble, the result is BallDouble (preserving .0).
|
|
123
|
+
//
|
|
124
|
+
// Operator-overload dispatch checks for __op_X__ methods (TRAILING double
|
|
125
|
+
// underscore) — this MUST match the Dart encoder's canonical operator naming
|
|
126
|
+
// (_canonicalOperatorName in dart/encoder/lib/encoder.dart), which always
|
|
127
|
+
// emits a trailing __. A single-underscore lookup (__op_mul) never matches,
|
|
128
|
+
// so overloaded operators silently fall through to raw JS arithmetic (#205).
|
|
123
129
|
function __ball_mul(a: any, b: any): any {
|
|
124
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
130
|
+
if (a != null && typeof a === 'object' && typeof a.__op_mul__ === 'function') return a.__op_mul__(b);
|
|
125
131
|
if (typeof a === 'bigint' || typeof b === 'bigint') return __i64_wrap(__to_bigint(a) * __to_bigint(b));
|
|
126
132
|
const av = a instanceof BallDouble ? a.value : a;
|
|
127
133
|
const bv = b instanceof BallDouble ? b.value : b;
|
|
@@ -129,7 +135,7 @@ function __ball_mul(a: any, b: any): any {
|
|
|
129
135
|
return (a instanceof BallDouble || b instanceof BallDouble) ? new BallDouble(r) : r;
|
|
130
136
|
}
|
|
131
137
|
function __ball_add(a: any, b: any): any {
|
|
132
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
138
|
+
if (a != null && typeof a === 'object' && typeof a.__op_add__ === 'function') return a.__op_add__(b);
|
|
133
139
|
if (typeof a === 'bigint' || typeof b === 'bigint') return __i64_wrap(__to_bigint(a) + __to_bigint(b));
|
|
134
140
|
const av = a instanceof BallDouble ? a.value : a;
|
|
135
141
|
const bv = b instanceof BallDouble ? b.value : b;
|
|
@@ -137,7 +143,7 @@ function __ball_add(a: any, b: any): any {
|
|
|
137
143
|
return (a instanceof BallDouble || b instanceof BallDouble) ? new BallDouble(r) : r;
|
|
138
144
|
}
|
|
139
145
|
function __ball_sub(a: any, b: any): any {
|
|
140
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
146
|
+
if (a != null && typeof a === 'object' && typeof a.__op_sub__ === 'function') return a.__op_sub__(b);
|
|
141
147
|
if (typeof a === 'bigint' || typeof b === 'bigint') return __i64_wrap(__to_bigint(a) - __to_bigint(b));
|
|
142
148
|
const av = a instanceof BallDouble ? a.value : a;
|
|
143
149
|
const bv = b instanceof BallDouble ? b.value : b;
|
|
@@ -147,7 +153,7 @@ function __ball_sub(a: any, b: any): any {
|
|
|
147
153
|
|
|
148
154
|
// Dart equality: NaN != NaN, BallDouble value comparison, null == undefined.
|
|
149
155
|
function __ball_eq(a: any, b: any): boolean {
|
|
150
|
-
if (a != null && typeof a === 'object' && typeof a.
|
|
156
|
+
if (a != null && typeof a === 'object' && typeof a.__op_eq__ === 'function') return a.__op_eq__(b);
|
|
151
157
|
if (typeof a === 'bigint' || typeof b === 'bigint') {
|
|
152
158
|
if (typeof a === 'bigint' && typeof b === 'bigint') return a === b;
|
|
153
159
|
if (typeof a === 'bigint' && typeof b === 'number') return a === BigInt(b);
|
|
@@ -165,6 +171,39 @@ function __ball_eq(a: any, b: any): boolean {
|
|
|
165
171
|
return a === b;
|
|
166
172
|
}
|
|
167
173
|
|
|
174
|
+
// Relational operator-overload dispatch (less-than/greater-than/etc.),
|
|
175
|
+
// matching the __op_add__-style convention above. Unlike arithmetic,
|
|
176
|
+
// relational comparisons had NO overload attempt at all before #205 — every
|
|
177
|
+
// overloaded Vec2 < x etc. compiled straight to raw JS comparison.
|
|
178
|
+
function __ball_lt(a: any, b: any): any {
|
|
179
|
+
if (a != null && typeof a === 'object' && typeof a.__op_lt__ === 'function') return a.__op_lt__(b);
|
|
180
|
+
if (typeof a === 'bigint' || typeof b === 'bigint') return __to_bigint(a) < __to_bigint(b);
|
|
181
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
182
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
183
|
+
return av < bv;
|
|
184
|
+
}
|
|
185
|
+
function __ball_gt(a: any, b: any): any {
|
|
186
|
+
if (a != null && typeof a === 'object' && typeof a.__op_gt__ === 'function') return a.__op_gt__(b);
|
|
187
|
+
if (typeof a === 'bigint' || typeof b === 'bigint') return __to_bigint(a) > __to_bigint(b);
|
|
188
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
189
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
190
|
+
return av > bv;
|
|
191
|
+
}
|
|
192
|
+
function __ball_le(a: any, b: any): any {
|
|
193
|
+
if (a != null && typeof a === 'object' && typeof a.__op_le__ === 'function') return a.__op_le__(b);
|
|
194
|
+
if (typeof a === 'bigint' || typeof b === 'bigint') return __to_bigint(a) <= __to_bigint(b);
|
|
195
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
196
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
197
|
+
return av <= bv;
|
|
198
|
+
}
|
|
199
|
+
function __ball_ge(a: any, b: any): any {
|
|
200
|
+
if (a != null && typeof a === 'object' && typeof a.__op_ge__ === 'function') return a.__op_ge__(b);
|
|
201
|
+
if (typeof a === 'bigint' || typeof b === 'bigint') return __to_bigint(a) >= __to_bigint(b);
|
|
202
|
+
const av = a instanceof BallDouble ? a.value : a;
|
|
203
|
+
const bv = b instanceof BallDouble ? b.value : b;
|
|
204
|
+
return av >= bv;
|
|
205
|
+
}
|
|
206
|
+
|
|
168
207
|
function __ball_to_string(v: any): string {
|
|
169
208
|
if (v === null || v === undefined) return 'null';
|
|
170
209
|
if (typeof v === 'bigint') return v.toString();
|
|
@@ -1437,13 +1476,13 @@ export class BallEngine {
|
|
|
1437
1476
|
|
|
1438
1477
|
_validateProgramLimits(): any {
|
|
1439
1478
|
let moduleCount = this.program.modules.length;
|
|
1440
|
-
if ((moduleCount
|
|
1479
|
+
if (__ball_gt(moduleCount, this.maxModules)) {
|
|
1441
1480
|
throw new BallRuntimeError((((('Too many modules: ' + __ball_to_string(moduleCount)) + ' (max ') + __ball_to_string(this.maxModules)) + ')'));
|
|
1442
1481
|
}
|
|
1443
1482
|
let maxProgramBytes = this.maxProgramSizeBytes;
|
|
1444
1483
|
if (!__ball_eq(maxProgramBytes, null)) {
|
|
1445
1484
|
let programSizeBytes = this.program.writeToBuffer().length;
|
|
1446
|
-
if ((programSizeBytes
|
|
1485
|
+
if (__ball_gt(programSizeBytes, maxProgramBytes)) {
|
|
1447
1486
|
throw new BallRuntimeError((((('Program too large: ' + __ball_to_string(programSizeBytes)) + ' bytes (max ') + __ball_to_string(maxProgramBytes)) + ')'));
|
|
1448
1487
|
}
|
|
1449
1488
|
}
|
|
@@ -1466,7 +1505,7 @@ export class BallEngine {
|
|
|
1466
1505
|
while (!(stack.length === 0)) {
|
|
1467
1506
|
let current = stack.pop();
|
|
1468
1507
|
let depth = current.depth;
|
|
1469
|
-
if ((depth
|
|
1508
|
+
if (__ball_gt(depth, this.maxExpressionDepth)) {
|
|
1470
1509
|
throw new BallRuntimeError((((('Expression too deep: ' + __ball_to_string(depth)) + ' levels (max ') + __ball_to_string(this.maxExpressionDepth)) + ')'));
|
|
1471
1510
|
}
|
|
1472
1511
|
do {
|
|
@@ -1536,7 +1575,7 @@ export class BallEngine {
|
|
|
1536
1575
|
|
|
1537
1576
|
_checkExpressionDepth(): any {
|
|
1538
1577
|
this._expressionDepth += 1;
|
|
1539
|
-
if ((this._expressionDepth
|
|
1578
|
+
if (__ball_gt(this._expressionDepth, this.maxExpressionDepth)) {
|
|
1540
1579
|
throw new BallRuntimeError((((('Expression too deep: ' + __ball_to_string(this._expressionDepth)) + ' levels (max ') + __ball_to_string(this.maxExpressionDepth)) + ')'));
|
|
1541
1580
|
}
|
|
1542
1581
|
}
|
|
@@ -1551,7 +1590,7 @@ export class BallEngine {
|
|
|
1551
1590
|
if (hasDescriptor(td)) {
|
|
1552
1591
|
this._types[td.name] = td.descriptor;
|
|
1553
1592
|
let tc = td.name.indexOf(':');
|
|
1554
|
-
if ((tc
|
|
1593
|
+
if (__ball_ge(tc, 0)) {
|
|
1555
1594
|
this._types[td.name.substring(__ball_add(tc, 1))] = td.descriptor;
|
|
1556
1595
|
}
|
|
1557
1596
|
}
|
|
@@ -1560,14 +1599,14 @@ export class BallEngine {
|
|
|
1560
1599
|
let enumName = enumDesc.name;
|
|
1561
1600
|
let enumMap = {};
|
|
1562
1601
|
let enumValueList = enumDesc.value;
|
|
1563
|
-
for (let vi = 0; (vi
|
|
1602
|
+
for (let vi = 0; __ball_lt(vi, enumValueList.length); (vi++)) {
|
|
1564
1603
|
let v = __ball_index(enumValueList, vi);
|
|
1565
1604
|
let entry = { ['__type__']: enumName, ['name']: v.name, ['index']: v.number };
|
|
1566
1605
|
enumMap[v.name] = entry;
|
|
1567
1606
|
}
|
|
1568
1607
|
this._enumValues[enumName] = enumMap;
|
|
1569
1608
|
let ec = enumName.indexOf(':');
|
|
1570
|
-
if ((ec
|
|
1609
|
+
if (__ball_ge(ec, 0)) {
|
|
1571
1610
|
this._enumValues[enumName.substring(__ball_add(ec, 1))] = enumMap;
|
|
1572
1611
|
}
|
|
1573
1612
|
}
|
|
@@ -1603,7 +1642,7 @@ export class BallEngine {
|
|
|
1603
1642
|
if (__ball_eq((__ball_eq(kindField, null) ? null : kindField.stringValue), 'constructor')) {
|
|
1604
1643
|
let entry = { module: module.name, func: func };
|
|
1605
1644
|
let dotIdx = func.name.indexOf('.');
|
|
1606
|
-
if ((dotIdx
|
|
1645
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
1607
1646
|
let className = func.name.substring(0, dotIdx);
|
|
1608
1647
|
let ctorSuffix = func.name.substring(__ball_add(dotIdx, 1));
|
|
1609
1648
|
if (__ball_eq(ctorSuffix, 'new')) {
|
|
@@ -1639,7 +1678,7 @@ export class BallEngine {
|
|
|
1639
1678
|
}
|
|
1640
1679
|
if (__ball_eq(kind, 'static_field')) {
|
|
1641
1680
|
let dotIdx = func.name.lastIndexOf('.');
|
|
1642
|
-
if ((dotIdx
|
|
1681
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
1643
1682
|
let bareName = func.name.substring(__ball_add(dotIdx, 1));
|
|
1644
1683
|
(this._staticFieldRefs[bareName] ??= ((() => {
|
|
1645
1684
|
return { module: module.name, func: func, fullName: func.name };
|
|
@@ -1649,7 +1688,7 @@ export class BallEngine {
|
|
|
1649
1688
|
}
|
|
1650
1689
|
let funcName = func.name;
|
|
1651
1690
|
let dotIdx = funcName.lastIndexOf('.');
|
|
1652
|
-
if ((dotIdx
|
|
1691
|
+
if (__ball_lt(dotIdx, 0)) {
|
|
1653
1692
|
return;
|
|
1654
1693
|
}
|
|
1655
1694
|
let methodName = funcName.substring(__ball_add(dotIdx, 1));
|
|
@@ -1686,7 +1725,7 @@ export class BallEngine {
|
|
|
1686
1725
|
|
|
1687
1726
|
_lookupTypeMethodWithInheritance(typeName: any, methodName: any): any {
|
|
1688
1727
|
let colonIdx = typeName.indexOf(':');
|
|
1689
|
-
let modPart = ((colonIdx
|
|
1728
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
1690
1729
|
let current = typeName;
|
|
1691
1730
|
while (!(current.length === 0)) {
|
|
1692
1731
|
let direct = __ball_index(this._typeMethodDispatch, BallEngine._typeMethodKey(current, methodName));
|
|
@@ -1694,7 +1733,7 @@ export class BallEngine {
|
|
|
1694
1733
|
return direct;
|
|
1695
1734
|
}
|
|
1696
1735
|
let currentColon = current.indexOf(':');
|
|
1697
|
-
if ((currentColon
|
|
1736
|
+
if (__ball_ge(currentColon, 0)) {
|
|
1698
1737
|
let bare = current.substring(__ball_add(currentColon, 1));
|
|
1699
1738
|
let bareHit = __ball_index(this._typeMethodDispatch, BallEngine._typeMethodKey(bare, methodName));
|
|
1700
1739
|
if (!__ball_eq(bareHit, null)) {
|
|
@@ -1716,7 +1755,7 @@ export class BallEngine {
|
|
|
1716
1755
|
return mixinHit;
|
|
1717
1756
|
}
|
|
1718
1757
|
let mixinColon = qualMixin.indexOf(':');
|
|
1719
|
-
if ((mixinColon
|
|
1758
|
+
if (__ball_ge(mixinColon, 0)) {
|
|
1720
1759
|
let bareMixin = qualMixin.substring(__ball_add(mixinColon, 1));
|
|
1721
1760
|
let bareMixinHit = __ball_index(this._typeMethodDispatch, BallEngine._typeMethodKey(bareMixin, methodName));
|
|
1722
1761
|
if (!__ball_eq(bareMixinHit, null)) {
|
|
@@ -1784,7 +1823,7 @@ export class BallEngine {
|
|
|
1784
1823
|
return;
|
|
1785
1824
|
}
|
|
1786
1825
|
let elapsed = __ball_sub(DateTime.now().millisecondsSinceEpoch, start);
|
|
1787
|
-
if ((elapsed
|
|
1826
|
+
if (__ball_gt(elapsed, timeout)) {
|
|
1788
1827
|
throw new BallRuntimeError('Execution timeout exceeded');
|
|
1789
1828
|
}
|
|
1790
1829
|
}
|
|
@@ -1804,10 +1843,10 @@ export class BallEngine {
|
|
|
1804
1843
|
_trackMemoryAllocation(bytes: any): any {
|
|
1805
1844
|
const input = bytes;
|
|
1806
1845
|
let limit = this.maxMemoryBytes;
|
|
1807
|
-
if ((__ball_eq(limit, null) || (bytes
|
|
1846
|
+
if ((__ball_eq(limit, null) || __ball_le(bytes, 0))) {
|
|
1808
1847
|
return;
|
|
1809
1848
|
}
|
|
1810
|
-
if ((__ball_add(this._memoryUsedBytes, bytes)
|
|
1849
|
+
if (__ball_gt(__ball_add(this._memoryUsedBytes, bytes), limit)) {
|
|
1811
1850
|
throw new BallRuntimeError('Memory limit exceeded');
|
|
1812
1851
|
}
|
|
1813
1852
|
this._memoryUsedBytes += bytes;
|
|
@@ -1834,7 +1873,7 @@ export class BallEngine {
|
|
|
1834
1873
|
if (func.isBase) {
|
|
1835
1874
|
return this._callBaseFunction(moduleName, func.name, input);
|
|
1836
1875
|
}
|
|
1837
|
-
if ((this._recursionDepth
|
|
1876
|
+
if (__ball_ge(this._recursionDepth, this.maxRecursionDepth)) {
|
|
1838
1877
|
throw new BallRuntimeError(('Maximum recursion depth exceeded: ' + __ball_to_string(this.maxRecursionDepth)));
|
|
1839
1878
|
}
|
|
1840
1879
|
(this._recursionDepth++);
|
|
@@ -1851,7 +1890,7 @@ export class BallEngine {
|
|
|
1851
1890
|
if (__ball_eq(kind, 'constructor')) {
|
|
1852
1891
|
let constructorInput = this._asMap(input);
|
|
1853
1892
|
let dotIdx = func.name.indexOf('.');
|
|
1854
|
-
let typeName = ((dotIdx
|
|
1893
|
+
let typeName = (__ball_ge(dotIdx, 0) ? func.name.substring(0, dotIdx) : func.name);
|
|
1855
1894
|
let isFactory = (hasMetadata(func) && _metadataBool(__ball_index(func.metadata.fields, 'is_factory')));
|
|
1856
1895
|
if (((!isFactory && (__ball_eq(constructorInput, null) || !('self' in constructorInput))) && !__ball_eq(this._findTypeDef(typeName), null))) {
|
|
1857
1896
|
return this._callObjectConstructor(moduleName, func, input);
|
|
@@ -1878,7 +1917,7 @@ export class BallEngine {
|
|
|
1878
1917
|
}
|
|
1879
1918
|
} else {
|
|
1880
1919
|
if (!__ball_eq(inputMap, null)) {
|
|
1881
|
-
for (let i = 0; (i
|
|
1920
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
1882
1921
|
let p = __ball_index(params, i);
|
|
1883
1922
|
if ((p in inputMap)) {
|
|
1884
1923
|
scope.bind(p, __ball_index(inputMap, p));
|
|
@@ -1894,7 +1933,7 @@ export class BallEngine {
|
|
|
1894
1933
|
}
|
|
1895
1934
|
} else {
|
|
1896
1935
|
if (Array.isArray(input)) {
|
|
1897
|
-
for (let i = 0; ((i
|
|
1936
|
+
for (let i = 0; (__ball_lt(i, params.length) && __ball_lt(i, input.length)); (i++)) {
|
|
1898
1937
|
scope.bind(__ball_index(params, i), __ball_index(input, i));
|
|
1899
1938
|
}
|
|
1900
1939
|
}
|
|
@@ -2014,7 +2053,7 @@ export class BallEngine {
|
|
|
2014
2053
|
|
|
2015
2054
|
async _callObjectConstructor(moduleName: any, func: any, input: any): Promise<any> {
|
|
2016
2055
|
let dotIdx = func.name.indexOf('.');
|
|
2017
|
-
let typeName = ((dotIdx
|
|
2056
|
+
let typeName = (__ball_ge(dotIdx, 0) ? func.name.substring(0, dotIdx) : func.name);
|
|
2018
2057
|
let typeDef = this._findTypeDef(typeName);
|
|
2019
2058
|
if (__ball_eq(typeDef, null)) {
|
|
2020
2059
|
return null;
|
|
@@ -2028,7 +2067,7 @@ export class BallEngine {
|
|
|
2028
2067
|
let params = (hasMetadata(func) ? this._extractParams(func.metadata) : []);
|
|
2029
2068
|
let paramsMeta = (hasMetadata(func) ? this._extractParamsMeta(func.metadata) : []);
|
|
2030
2069
|
let resolvedParams = {};
|
|
2031
|
-
for (let i = 0; (i
|
|
2070
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
2032
2071
|
let param = __ball_index(params, i);
|
|
2033
2072
|
let value = __no_init__;
|
|
2034
2073
|
if ((param in inputMap)) {
|
|
@@ -2038,11 +2077,11 @@ export class BallEngine {
|
|
|
2038
2077
|
value = __ball_index(inputMap, ('arg' + __ball_to_string(i)));
|
|
2039
2078
|
}
|
|
2040
2079
|
}
|
|
2041
|
-
if (((__ball_eq(value, null) && (i
|
|
2080
|
+
if (((__ball_eq(value, null) && __ball_lt(i, paramsMeta.length)) && ('default' in __ball_index(paramsMeta, i)))) {
|
|
2042
2081
|
value = __ball_index(__ball_index(paramsMeta, i), 'default');
|
|
2043
2082
|
}
|
|
2044
2083
|
resolvedParams[param] = value;
|
|
2045
|
-
let isThis = ((i
|
|
2084
|
+
let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
|
|
2046
2085
|
if ((isThis || allFieldNames.includes(param))) {
|
|
2047
2086
|
instanceFields[param] = value;
|
|
2048
2087
|
} else {
|
|
@@ -2110,7 +2149,7 @@ export class BallEngine {
|
|
|
2110
2149
|
let idx = __ball_parse_int(indexMatch.group(2));
|
|
2111
2150
|
let rawArr = __ball_index(resolvedParams, arrName);
|
|
2112
2151
|
let arr = (false /* BallList is List in TS */ ? rawArr.items : rawArr);
|
|
2113
|
-
if ((Array.isArray(arr) && (idx
|
|
2152
|
+
if ((Array.isArray(arr) && __ball_lt(idx, arr.length))) {
|
|
2114
2153
|
targetFields[name] = __ball_index(arr, idx);
|
|
2115
2154
|
} else {
|
|
2116
2155
|
targetFields[name] = null;
|
|
@@ -2151,14 +2190,14 @@ export class BallEngine {
|
|
|
2151
2190
|
let paramsMeta = this._extractParamsMeta(func.metadata);
|
|
2152
2191
|
let instance = {};
|
|
2153
2192
|
let dotIdx = func.name.indexOf('.');
|
|
2154
|
-
let typeName = ((dotIdx
|
|
2193
|
+
let typeName = (__ball_ge(dotIdx, 0) ? func.name.substring(0, dotIdx) : func.name);
|
|
2155
2194
|
instance['__type__'] = typeName;
|
|
2156
2195
|
let resolvedParams = {};
|
|
2157
2196
|
let inputMap = this._asMap(input);
|
|
2158
2197
|
if (!__ball_eq(inputMap, null)) {
|
|
2159
|
-
for (let i = 0; (i
|
|
2198
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
2160
2199
|
let p = __ball_index(params, i);
|
|
2161
|
-
let isThis = ((i
|
|
2200
|
+
let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
|
|
2162
2201
|
let val = __no_init__;
|
|
2163
2202
|
if ((p in inputMap)) {
|
|
2164
2203
|
val = __ball_index(inputMap, p);
|
|
@@ -2166,7 +2205,7 @@ export class BallEngine {
|
|
|
2166
2205
|
if ((('arg' + __ball_to_string(i)) in inputMap)) {
|
|
2167
2206
|
val = __ball_index(inputMap, ('arg' + __ball_to_string(i)));
|
|
2168
2207
|
} else {
|
|
2169
|
-
val = ((i
|
|
2208
|
+
val = (__ball_lt(i, paramsMeta.length) ? __ball_index(__ball_index(paramsMeta, i), 'default') : null);
|
|
2170
2209
|
}
|
|
2171
2210
|
}
|
|
2172
2211
|
resolvedParams[p] = val;
|
|
@@ -2234,7 +2273,7 @@ export class BallEngine {
|
|
|
2234
2273
|
})() ?? '');
|
|
2235
2274
|
let argNames = this._parseSuperArgs(argsStr);
|
|
2236
2275
|
let superInput = {};
|
|
2237
|
-
for (let i = 0; (i
|
|
2276
|
+
for (let i = 0; __ball_lt(i, argNames.length); (i++)) {
|
|
2238
2277
|
let token = __ball_index(argNames, i);
|
|
2239
2278
|
if ((token in resolvedParams)) {
|
|
2240
2279
|
superInput[('arg' + __ball_to_string(i))] = __ball_index(resolvedParams, token);
|
|
@@ -2268,7 +2307,7 @@ export class BallEngine {
|
|
|
2268
2307
|
let superCtorEntry = this._lookupConstructor(superclass);
|
|
2269
2308
|
if (!__ball_eq(superCtorEntry, null)) {
|
|
2270
2309
|
let superInput = {};
|
|
2271
|
-
for (let i = 0; (i
|
|
2310
|
+
for (let i = 0; __ball_lt(i, resolvedParams.length); (i++)) {
|
|
2272
2311
|
superInput[('arg' + __ball_to_string(i))] = resolvedParams.values.elementAt(i);
|
|
2273
2312
|
}
|
|
2274
2313
|
return this._callFunction(superCtorEntry.module, superCtorEntry.func, superInput);
|
|
@@ -2289,7 +2328,7 @@ export class BallEngine {
|
|
|
2289
2328
|
for (const entry of this._constructors.entries) {
|
|
2290
2329
|
let key = entry.key;
|
|
2291
2330
|
let colonIdx = key.indexOf(':');
|
|
2292
|
-
let bare = ((colonIdx
|
|
2331
|
+
let bare = (__ball_ge(colonIdx, 0) ? key.substring(__ball_add(colonIdx, 1)) : key);
|
|
2293
2332
|
if (__ball_eq(bare, name)) {
|
|
2294
2333
|
return entry.value;
|
|
2295
2334
|
}
|
|
@@ -2812,7 +2851,7 @@ export class BallEngine {
|
|
|
2812
2851
|
if (__ball_eq((__ball_eq(kindField, null) ? null : kindField.stringValue), 'constructor')) {
|
|
2813
2852
|
let entry = { module: module.name, func: func };
|
|
2814
2853
|
let dotIdx = func.name.indexOf('.');
|
|
2815
|
-
if ((dotIdx
|
|
2854
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
2816
2855
|
let className = func.name.substring(0, dotIdx);
|
|
2817
2856
|
let ctorSuffix = func.name.substring(__ball_add(dotIdx, 1));
|
|
2818
2857
|
if (__ball_eq(ctorSuffix, 'new')) {
|
|
@@ -3042,7 +3081,7 @@ export class BallEngine {
|
|
|
3042
3081
|
let className = __ball_index(selfMap, '__class_ref__');
|
|
3043
3082
|
let qualifiedName = (className.includes(':') ? className : ((__ball_to_string(this._currentModule) + ':') + __ball_to_string(className)));
|
|
3044
3083
|
let colonIdx2 = qualifiedName.indexOf(':');
|
|
3045
|
-
let modPart2 = ((colonIdx2
|
|
3084
|
+
let modPart2 = (__ball_ge(colonIdx2, 0) ? qualifiedName.substring(0, colonIdx2) : this._currentModule);
|
|
3046
3085
|
let staticKey = ((((__ball_to_string(modPart2) + '.') + __ball_to_string(qualifiedName)) + '.') + __ball_to_string(call.function));
|
|
3047
3086
|
let staticFunc = __ball_index(this._functions, staticKey);
|
|
3048
3087
|
if (!__ball_eq(staticFunc, null)) {
|
|
@@ -3398,7 +3437,7 @@ export class BallEngine {
|
|
|
3398
3437
|
});
|
|
3399
3438
|
}
|
|
3400
3439
|
let colonIdx = name.indexOf(':');
|
|
3401
|
-
if ((colonIdx
|
|
3440
|
+
if (__ball_ge(colonIdx, 0)) {
|
|
3402
3441
|
let bare = name.substring(__ball_add(colonIdx, 1));
|
|
3403
3442
|
let bareEntry = __ball_index(this._constructors, bare);
|
|
3404
3443
|
if (!__ball_eq(bareEntry, null)) {
|
|
@@ -3564,7 +3603,7 @@ export class BallEngine {
|
|
|
3564
3603
|
});
|
|
3565
3604
|
}
|
|
3566
3605
|
let colonIdx = qualifiedName.indexOf(':');
|
|
3567
|
-
let modPart = ((colonIdx
|
|
3606
|
+
let modPart = (__ball_ge(colonIdx, 0) ? qualifiedName.substring(0, colonIdx) : this._currentModule);
|
|
3568
3607
|
let staticKey = ((((__ball_to_string(modPart) + '.') + __ball_to_string(qualifiedName)) + '.') + __ball_to_string(fieldName));
|
|
3569
3608
|
let staticFunc = __ball_index(this._functions, staticKey);
|
|
3570
3609
|
if (!__ball_eq(staticFunc, null)) {
|
|
@@ -3736,6 +3775,7 @@ export class BallEngine {
|
|
|
3736
3775
|
return e.key;
|
|
3737
3776
|
}))];
|
|
3738
3777
|
}
|
|
3778
|
+
throw new BallRuntimeError(('Cannot access field "keys" on ' + __ball_to_string(((__ball_eq(object, null) ? null : object.runtimeType) ?? 'null'))));
|
|
3739
3779
|
}
|
|
3740
3780
|
else if ((__sw === 'values')) {
|
|
3741
3781
|
if ((typeof object === 'object' && object !== null && !Array.isArray(object) && !(object instanceof BallDouble) && !(object instanceof Set))) {
|
|
@@ -3753,6 +3793,7 @@ export class BallEngine {
|
|
|
3753
3793
|
}
|
|
3754
3794
|
return vals;
|
|
3755
3795
|
}
|
|
3796
|
+
throw new BallRuntimeError(('Cannot access field "values" on ' + __ball_to_string(((__ball_eq(object, null) ? null : object.runtimeType) ?? 'null'))));
|
|
3756
3797
|
}
|
|
3757
3798
|
else if ((__sw === 'isNaN')) {
|
|
3758
3799
|
return _ballNumIsNaN(object);
|
|
@@ -3833,7 +3874,7 @@ export class BallEngine {
|
|
|
3833
3874
|
return _sentinel;
|
|
3834
3875
|
}
|
|
3835
3876
|
let colonIdx = typeName.indexOf(':');
|
|
3836
|
-
let modPart = ((colonIdx
|
|
3877
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
3837
3878
|
let getterKey = ((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(fieldName));
|
|
3838
3879
|
let getterFunc = (__ball_index(this._getters, getterKey) ?? __ball_index(this._functions, getterKey));
|
|
3839
3880
|
if ((!__ball_eq(getterFunc, null) && this._isGetter(getterFunc))) {
|
|
@@ -3845,8 +3886,8 @@ export class BallEngine {
|
|
|
3845
3886
|
let superType = __ball_index(superMap, '__type__');
|
|
3846
3887
|
if (!__ball_eq(superType, null)) {
|
|
3847
3888
|
let sColonIdx = superType.indexOf(':');
|
|
3848
|
-
let sModPart = ((sColonIdx
|
|
3849
|
-
let sTypeName = ((sColonIdx
|
|
3889
|
+
let sModPart = (__ball_ge(sColonIdx, 0) ? superType.substring(0, sColonIdx) : modPart);
|
|
3890
|
+
let sTypeName = (__ball_ge(sColonIdx, 0) ? superType : ((__ball_to_string(sModPart) + ':') + __ball_to_string(superType)));
|
|
3850
3891
|
let superGetterKey = ((((__ball_to_string(sModPart) + '.') + __ball_to_string(sTypeName)) + '.') + __ball_to_string(fieldName));
|
|
3851
3892
|
let superGetterFunc = (__ball_index(this._getters, superGetterKey) ?? __ball_index(this._functions, superGetterKey));
|
|
3852
3893
|
if ((!__ball_eq(superGetterFunc, null) && this._isGetter(superGetterFunc))) {
|
|
@@ -3894,7 +3935,7 @@ export class BallEngine {
|
|
|
3894
3935
|
return _sentinel;
|
|
3895
3936
|
}
|
|
3896
3937
|
let colonIdx = typeName.indexOf(':');
|
|
3897
|
-
let modPart = ((colonIdx
|
|
3938
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
3898
3939
|
let setterKey = (((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(fieldName)) + '=');
|
|
3899
3940
|
let setterKeyNoEq = ((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(fieldName));
|
|
3900
3941
|
let setterFunc = ((__ball_index(this._setters, setterKey) ?? __ball_index(this._setters, setterKeyNoEq)) ?? __ball_index(this._functions, setterKey));
|
|
@@ -3909,8 +3950,8 @@ export class BallEngine {
|
|
|
3909
3950
|
let superType = __ball_index(superMap, '__type__');
|
|
3910
3951
|
if (!__ball_eq(superType, null)) {
|
|
3911
3952
|
let sColonIdx = superType.indexOf(':');
|
|
3912
|
-
let sModPart = ((sColonIdx
|
|
3913
|
-
let sTypeName = ((sColonIdx
|
|
3953
|
+
let sModPart = (__ball_ge(sColonIdx, 0) ? superType.substring(0, sColonIdx) : modPart);
|
|
3954
|
+
let sTypeName = (__ball_ge(sColonIdx, 0) ? superType : ((__ball_to_string(sModPart) + ':') + __ball_to_string(superType)));
|
|
3914
3955
|
let superSetterKey = (((((__ball_to_string(sModPart) + '.') + __ball_to_string(sTypeName)) + '.') + __ball_to_string(fieldName)) + '=');
|
|
3915
3956
|
let superSetterKeyNoEq = ((((__ball_to_string(sModPart) + '.') + __ball_to_string(sTypeName)) + '.') + __ball_to_string(fieldName));
|
|
3916
3957
|
let superSetterFunc = ((__ball_index(this._setters, superSetterKey) ?? __ball_index(this._setters, superSetterKeyNoEq)) ?? __ball_index(this._functions, superSetterKey));
|
|
@@ -4008,7 +4049,7 @@ export class BallEngine {
|
|
|
4008
4049
|
if ((!__ball_eq(ctorEntry, null) && hasMetadata(ctorEntry.func))) {
|
|
4009
4050
|
let params = this._extractParams(ctorEntry.func.metadata);
|
|
4010
4051
|
let paramsMeta = this._extractParamsMeta(ctorEntry.func.metadata);
|
|
4011
|
-
for (let i = 0; (i
|
|
4052
|
+
for (let i = 0; __ball_lt(i, params.length); (i++)) {
|
|
4012
4053
|
let param = __ball_index(params, i);
|
|
4013
4054
|
let value = __no_init__;
|
|
4014
4055
|
if ((param in fields)) {
|
|
@@ -4018,11 +4059,11 @@ export class BallEngine {
|
|
|
4018
4059
|
value = __ball_index(fields, ('arg' + __ball_to_string(i)));
|
|
4019
4060
|
}
|
|
4020
4061
|
}
|
|
4021
|
-
if (((__ball_eq(value, null) && (i
|
|
4062
|
+
if (((__ball_eq(value, null) && __ball_lt(i, paramsMeta.length)) && ('default' in __ball_index(paramsMeta, i)))) {
|
|
4022
4063
|
value = __ball_index(__ball_index(paramsMeta, i), 'default');
|
|
4023
4064
|
}
|
|
4024
4065
|
resolvedParams[param] = value;
|
|
4025
|
-
let isThis = ((i
|
|
4066
|
+
let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
|
|
4026
4067
|
if ((isThis || allFieldNames.includes(param))) {
|
|
4027
4068
|
instanceFields[param] = value;
|
|
4028
4069
|
} else {
|
|
@@ -4153,7 +4194,7 @@ export class BallEngine {
|
|
|
4153
4194
|
let selfType = __ball_index(selfObjMap, '__type__');
|
|
4154
4195
|
if (!__ball_eq(selfType, null)) {
|
|
4155
4196
|
let colonIdx = msg.typeName.indexOf(':');
|
|
4156
|
-
let methodName = ((colonIdx
|
|
4197
|
+
let methodName = (__ball_ge(colonIdx, 0) ? msg.typeName.substring(__ball_add(colonIdx, 1)) : msg.typeName);
|
|
4157
4198
|
let resolved = this._resolveMethod(selfType, methodName);
|
|
4158
4199
|
if (!__ball_eq(resolved, null)) {
|
|
4159
4200
|
fields['self'] = selfObj;
|
|
@@ -4284,7 +4325,7 @@ export class BallEngine {
|
|
|
4284
4325
|
if ((__ball_eq(trimmed, '""') || __ball_eq(trimmed, '\'\''))) {
|
|
4285
4326
|
return '';
|
|
4286
4327
|
}
|
|
4287
|
-
if ((((trimmed.length
|
|
4328
|
+
if (((__ball_ge(trimmed.length, 2) && trimmed.startsWith('[')) && trimmed.endsWith(']'))) {
|
|
4288
4329
|
let inner = trimmed.substring(1, __ball_sub(trimmed.length, 1)).trim();
|
|
4289
4330
|
if ((inner.length === 0)) {
|
|
4290
4331
|
return [];
|
|
@@ -4310,7 +4351,7 @@ export class BallEngine {
|
|
|
4310
4351
|
if (!__ball_eq(doubleVal, null)) {
|
|
4311
4352
|
return doubleVal;
|
|
4312
4353
|
}
|
|
4313
|
-
if (((trimmed.length
|
|
4354
|
+
if ((__ball_ge(trimmed.length, 2) && ((trimmed.startsWith('\'') && trimmed.endsWith('\'')) || (trimmed.startsWith('"') && trimmed.endsWith('"'))))) {
|
|
4314
4355
|
return trimmed.substring(1, __ball_sub(trimmed.length, 1));
|
|
4315
4356
|
}
|
|
4316
4357
|
return trimmed;
|
|
@@ -4330,7 +4371,7 @@ export class BallEngine {
|
|
|
4330
4371
|
return names;
|
|
4331
4372
|
}
|
|
4332
4373
|
let colonIdx = typeName.indexOf(':');
|
|
4333
|
-
let modPart = ((colonIdx
|
|
4374
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
4334
4375
|
let superclass = typeDef.superclass;
|
|
4335
4376
|
if ((!__ball_eq(superclass, null) && !(superclass.length === 0))) {
|
|
4336
4377
|
let qualifiedSuper = (superclass.includes(':') ? superclass : ((__ball_to_string(modPart) + ':') + __ball_to_string(superclass)));
|
|
@@ -4386,7 +4427,7 @@ export class BallEngine {
|
|
|
4386
4427
|
});
|
|
4387
4428
|
methods[func.name] = closure;
|
|
4388
4429
|
let dotIdx = func.name.lastIndexOf('.');
|
|
4389
|
-
if ((dotIdx
|
|
4430
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
4390
4431
|
methods[func.name.substring(__ball_add(dotIdx, 1))] = closure;
|
|
4391
4432
|
}
|
|
4392
4433
|
continue;
|
|
@@ -4394,7 +4435,7 @@ export class BallEngine {
|
|
|
4394
4435
|
}
|
|
4395
4436
|
let funcName = func.name;
|
|
4396
4437
|
let dotIdx = funcName.lastIndexOf('.');
|
|
4397
|
-
if ((dotIdx
|
|
4438
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
4398
4439
|
let prefix = funcName.substring(0, dotIdx);
|
|
4399
4440
|
let suffix = funcName.substring(__ball_add(dotIdx, 1));
|
|
4400
4441
|
if (__ball_eq(suffix, 'new')) {
|
|
@@ -4424,7 +4465,7 @@ export class BallEngine {
|
|
|
4424
4465
|
const input = typeName;
|
|
4425
4466
|
let methods = {};
|
|
4426
4467
|
let colonIdx = typeName.indexOf(':');
|
|
4427
|
-
let modPart = ((colonIdx
|
|
4468
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
4428
4469
|
let typeDef = this._findTypeDef(typeName);
|
|
4429
4470
|
if (((!__ball_eq(typeDef, null) && !__ball_eq(typeDef.superclass, null)) && !(typeDef.superclass.length === 0))) {
|
|
4430
4471
|
let qualSuper = (typeDef.superclass.includes(':') ? typeDef.superclass : ((__ball_to_string(modPart) + ':') + __ball_to_string(typeDef.superclass)));
|
|
@@ -4512,7 +4553,7 @@ export class BallEngine {
|
|
|
4512
4553
|
}
|
|
4513
4554
|
}
|
|
4514
4555
|
if (!(paramNames.length === 0)) {
|
|
4515
|
-
for (let i = 0; (i
|
|
4556
|
+
for (let i = 0; __ball_lt(i, paramNames.length); (i++)) {
|
|
4516
4557
|
let p = __ball_index(paramNames, i);
|
|
4517
4558
|
if (!lambdaScope.has(p)) {
|
|
4518
4559
|
if ((p in inputMap)) {
|
|
@@ -5042,7 +5083,7 @@ export class BallEngine {
|
|
|
5042
5083
|
|
|
5043
5084
|
_matchSwitchPattern(subject: any, pattern: any): any {
|
|
5044
5085
|
let dotIdx = pattern.indexOf('.');
|
|
5045
|
-
if ((dotIdx
|
|
5086
|
+
if (__ball_ge(dotIdx, 0)) {
|
|
5046
5087
|
let enumType = pattern.substring(0, dotIdx);
|
|
5047
5088
|
let enumValue = pattern.substring(__ball_add(dotIdx, 1));
|
|
5048
5089
|
let subjectMap = this._cfAsMap(subject);
|
|
@@ -5050,7 +5091,7 @@ export class BallEngine {
|
|
|
5050
5091
|
let typeName = __ball_index(subjectMap, '__type__');
|
|
5051
5092
|
if (!__ball_eq(typeName, null)) {
|
|
5052
5093
|
let colonIdx = typeName.indexOf(':');
|
|
5053
|
-
let bareType = ((colonIdx
|
|
5094
|
+
let bareType = (__ball_ge(colonIdx, 0) ? typeName.substring(__ball_add(colonIdx, 1)) : typeName);
|
|
5054
5095
|
if ((__ball_eq(bareType, enumType) && __ball_eq(__ball_index(subjectMap, 'name'), enumValue))) {
|
|
5055
5096
|
return true;
|
|
5056
5097
|
}
|
|
@@ -5124,13 +5165,13 @@ export class BallEngine {
|
|
|
5124
5165
|
if ((e instanceof BallException)) {
|
|
5125
5166
|
let eType = e['typeName'];
|
|
5126
5167
|
let eColonIdx = eType.indexOf(':');
|
|
5127
|
-
let eBare = ((eColonIdx
|
|
5168
|
+
let eBare = (__ball_ge(eColonIdx, 0) ? eType.substring(__ball_add(eColonIdx, 1)) : eType);
|
|
5128
5169
|
matches = (__ball_eq(eType, catchType) || __ball_eq(eBare, catchType));
|
|
5129
5170
|
} else {
|
|
5130
5171
|
if (((typeof e === 'object' && e !== null && !Array.isArray(e) && !(e instanceof BallDouble) && !(e instanceof Set)) && !__ball_eq(__ball_index(e, '__type__'), null))) {
|
|
5131
5172
|
let eType = __ball_to_string(__ball_index(e, '__type__'));
|
|
5132
5173
|
let eColonIdx = eType.indexOf(':');
|
|
5133
|
-
let eBare = ((eColonIdx
|
|
5174
|
+
let eBare = (__ball_ge(eColonIdx, 0) ? eType.substring(__ball_add(eColonIdx, 1)) : eType);
|
|
5134
5175
|
matches = (__ball_eq(eType, catchType) || __ball_eq(eBare, catchType));
|
|
5135
5176
|
} else {
|
|
5136
5177
|
matches = __ball_eq(__ball_to_string(e['runtimeType']), catchType);
|
|
@@ -6083,15 +6124,15 @@ export class BallEngine {
|
|
|
6083
6124
|
else if ((__sw === 'sort')) {
|
|
6084
6125
|
if ((typeof arg0 === 'function')) {
|
|
6085
6126
|
let sorted = [...self];
|
|
6086
|
-
for (let j = 1; (j
|
|
6127
|
+
for (let j = 1; __ball_lt(j, sorted.length); (j++)) {
|
|
6087
6128
|
let key = __ball_index(sorted, j);
|
|
6088
6129
|
let k = __ball_sub(j, 1);
|
|
6089
|
-
while ((k
|
|
6130
|
+
while (__ball_ge(k, 0)) {
|
|
6090
6131
|
let r = arg0({ ['arg0']: __ball_index(sorted, k), ['arg1']: key, ['a']: __ball_index(sorted, k), ['b']: key, ['left']: __ball_index(sorted, k), ['right']: key });
|
|
6091
6132
|
if ((r != null)) {
|
|
6092
6133
|
r = await r;
|
|
6093
6134
|
}
|
|
6094
|
-
if (((typeof r === 'number' || r instanceof BallDouble) && (r
|
|
6135
|
+
if (((typeof r === 'number' || r instanceof BallDouble) && __ball_gt(r, 0))) {
|
|
6095
6136
|
sorted[__ball_add(k, 1)] = __ball_index(sorted, k);
|
|
6096
6137
|
(k--);
|
|
6097
6138
|
} else {
|
|
@@ -6624,14 +6665,14 @@ export class BallEngine {
|
|
|
6624
6665
|
}
|
|
6625
6666
|
let typeName = __ball_index(leftMap, '__type__');
|
|
6626
6667
|
let colonIdx = typeName.indexOf(':');
|
|
6627
|
-
let modPart = ((colonIdx
|
|
6668
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
6628
6669
|
let current = leftMap;
|
|
6629
6670
|
while (!__ball_eq(current, null)) {
|
|
6630
6671
|
let curType = __ball_index(current, '__type__');
|
|
6631
6672
|
if (!__ball_eq(curType, null)) {
|
|
6632
6673
|
let cColonIdx = curType.indexOf(':');
|
|
6633
|
-
let cModPart = ((cColonIdx
|
|
6634
|
-
let cTypeName = ((cColonIdx
|
|
6674
|
+
let cModPart = (__ball_ge(cColonIdx, 0) ? curType.substring(0, cColonIdx) : modPart);
|
|
6675
|
+
let cTypeName = (__ball_ge(cColonIdx, 0) ? curType : ((__ball_to_string(cModPart) + ':') + __ball_to_string(curType)));
|
|
6635
6676
|
let opSymbol = __ball_index(_stdFunctionToOperatorSymbol, function_);
|
|
6636
6677
|
let method = __ball_index(this._functions, ((((__ball_to_string(cModPart) + '.') + __ball_to_string(cTypeName)) + '.') + __ball_to_string(op)));
|
|
6637
6678
|
method ??= (__ball_eq(opSymbol, null) ? null : __ball_index(this._functions, ((((__ball_to_string(cModPart) + '.') + __ball_to_string(cTypeName)) + '.') + __ball_to_string(opSymbol))));
|
|
@@ -6758,22 +6799,22 @@ export class BallEngine {
|
|
|
6758
6799
|
}), ['less_than']: ((i) => {
|
|
6759
6800
|
const input = i;
|
|
6760
6801
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
6761
|
-
return (a
|
|
6802
|
+
return __ball_lt(a, b);
|
|
6762
6803
|
}));
|
|
6763
6804
|
}), ['greater_than']: ((i) => {
|
|
6764
6805
|
const input = i;
|
|
6765
6806
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
6766
|
-
return (a
|
|
6807
|
+
return __ball_gt(a, b);
|
|
6767
6808
|
}));
|
|
6768
6809
|
}), ['lte']: ((i) => {
|
|
6769
6810
|
const input = i;
|
|
6770
6811
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
6771
|
-
return (a
|
|
6812
|
+
return __ball_le(a, b);
|
|
6772
6813
|
}));
|
|
6773
6814
|
}), ['gte']: ((i) => {
|
|
6774
6815
|
const input = i;
|
|
6775
6816
|
return this._stdBinaryComp(i, ((a, b) => {
|
|
6776
|
-
return (a
|
|
6817
|
+
return __ball_ge(a, b);
|
|
6777
6818
|
}));
|
|
6778
6819
|
}), ['and']: ((i) => {
|
|
6779
6820
|
const input = i;
|
|
@@ -6885,7 +6926,7 @@ export class BallEngine {
|
|
|
6885
6926
|
}
|
|
6886
6927
|
let a = this._toNum(v);
|
|
6887
6928
|
let b = this._toNum(other);
|
|
6888
|
-
return ((a
|
|
6929
|
+
return (__ball_lt(a, b) ? __ball_negate(1) : ((__ball_gt(a, b) ? 1 : 0)));
|
|
6889
6930
|
}), ['to_string_as_fixed']: ((i) => {
|
|
6890
6931
|
const input = i;
|
|
6891
6932
|
let m = (this._stdAsMap(i) ?? { ['value']: i });
|
|
@@ -6893,7 +6934,7 @@ export class BallEngine {
|
|
|
6893
6934
|
let digits = (__ball_index(m, 'digits') ?? __ball_index(m, 'fractionDigits'));
|
|
6894
6935
|
let n = this._toNum(v);
|
|
6895
6936
|
let s = (+(n)).toFixed(this._toInt(digits));
|
|
6896
|
-
if (((__ball_eq(n, 0) && (new BallDouble(Number(new BallDouble(1)) / Number(n))
|
|
6937
|
+
if (((__ball_eq(n, 0) && __ball_lt(new BallDouble(Number(new BallDouble(1)) / Number(n)), 0)) && !s.startsWith('-'))) {
|
|
6897
6938
|
return ('-' + __ball_to_string(s));
|
|
6898
6939
|
}
|
|
6899
6940
|
return s;
|
|
@@ -7179,16 +7220,16 @@ export class BallEngine {
|
|
|
7179
7220
|
}));
|
|
7180
7221
|
return sorted;
|
|
7181
7222
|
}
|
|
7182
|
-
for (let j = 1; (j
|
|
7223
|
+
for (let j = 1; __ball_lt(j, sorted.length); (j++)) {
|
|
7183
7224
|
let key = __ball_index(sorted, j);
|
|
7184
7225
|
let k = __ball_sub(j, 1);
|
|
7185
|
-
while ((k
|
|
7226
|
+
while (__ball_ge(k, 0)) {
|
|
7186
7227
|
let r = cb({ ['left']: __ball_index(sorted, k), ['right']: key, ['arg0']: __ball_index(sorted, k), ['arg1']: key, ['a']: __ball_index(sorted, k), ['b']: key });
|
|
7187
7228
|
if ((r != null)) {
|
|
7188
7229
|
r = await r;
|
|
7189
7230
|
}
|
|
7190
7231
|
let cmp = ((typeof r === 'number' && Number.isInteger(r)) ? r : __ball_to_int(r));
|
|
7191
|
-
if ((cmp
|
|
7232
|
+
if (__ball_le(cmp, 0)) {
|
|
7192
7233
|
break;
|
|
7193
7234
|
}
|
|
7194
7235
|
sorted[__ball_add(k, 1)] = __ball_index(sorted, k);
|
|
@@ -7240,7 +7281,7 @@ export class BallEngine {
|
|
|
7240
7281
|
} else {
|
|
7241
7282
|
if (('value' in m)) {
|
|
7242
7283
|
let v = __ball_index(m, 'value');
|
|
7243
|
-
if ((Array.isArray(v) && (v.length
|
|
7284
|
+
if ((Array.isArray(v) && __ball_ge(v.length, 2))) {
|
|
7244
7285
|
s = this._toInt(__ball_index(v, 0));
|
|
7245
7286
|
e = this._toInt(__ball_index(v, 1));
|
|
7246
7287
|
} else {
|
|
@@ -7286,7 +7327,7 @@ export class BallEngine {
|
|
|
7286
7327
|
let m = this._stdAsMap(i);
|
|
7287
7328
|
let a = this._stdAsList(__ball_index(m, 'list'));
|
|
7288
7329
|
let b = this._stdAsList(__ball_index(m, 'value'));
|
|
7289
|
-
let len = ((a.length
|
|
7330
|
+
let len = (__ball_lt(a.length, b.length) ? a.length : b.length);
|
|
7290
7331
|
this._trackMemoryAllocation(__ball_mul(len, _ballPointerBytes));
|
|
7291
7332
|
return List.generate(len, ((j) => {
|
|
7292
7333
|
const input = j;
|
|
@@ -7450,19 +7491,27 @@ export class BallEngine {
|
|
|
7450
7491
|
}), ['map_keys']: ((i) => {
|
|
7451
7492
|
const input = i;
|
|
7452
7493
|
let m = this._stdAsMap(i);
|
|
7453
|
-
|
|
7494
|
+
let target = __ball_index(m, 'map');
|
|
7495
|
+
if (this._isBallSet(target)) {
|
|
7454
7496
|
return [];
|
|
7455
7497
|
}
|
|
7456
|
-
|
|
7498
|
+
if ((!((typeof target === 'object' && target !== null && !Array.isArray(target) && !(target instanceof BallDouble) && !(target instanceof Set))) && !(false /* BallMap is Map in TS */))) {
|
|
7499
|
+
throw new BallRuntimeError('map_keys: expected Map or Set');
|
|
7500
|
+
}
|
|
7501
|
+
let result = _ballMapKeysDyn(target);
|
|
7457
7502
|
this._trackMemoryAllocation(__ball_mul(result.length, _ballPointerBytes));
|
|
7458
7503
|
return result;
|
|
7459
7504
|
}), ['map_values']: ((i) => {
|
|
7460
7505
|
const input = i;
|
|
7461
7506
|
let m = this._stdAsMap(i);
|
|
7462
|
-
|
|
7507
|
+
let target = __ball_index(m, 'map');
|
|
7508
|
+
if (this._isBallSet(target)) {
|
|
7463
7509
|
return [];
|
|
7464
7510
|
}
|
|
7465
|
-
|
|
7511
|
+
if ((!((typeof target === 'object' && target !== null && !Array.isArray(target) && !(target instanceof BallDouble) && !(target instanceof Set))) && !(false /* BallMap is Map in TS */))) {
|
|
7512
|
+
throw new BallRuntimeError('map_values: expected Map or Set');
|
|
7513
|
+
}
|
|
7514
|
+
let result = _ballMapValuesDyn(target);
|
|
7466
7515
|
this._trackMemoryAllocation(__ball_mul(result.length, _ballPointerBytes));
|
|
7467
7516
|
return result;
|
|
7468
7517
|
}), ['map_entries']: ((i) => {
|
|
@@ -7919,12 +7968,12 @@ export class BallEngine {
|
|
|
7919
7968
|
}), ['math_min']: ((i) => {
|
|
7920
7969
|
const input = i;
|
|
7921
7970
|
return this._stdBinary(i, ((a, b) => {
|
|
7922
|
-
return ((a
|
|
7971
|
+
return (__ball_lt(a, b) ? a : b);
|
|
7923
7972
|
}));
|
|
7924
7973
|
}), ['math_max']: ((i) => {
|
|
7925
7974
|
const input = i;
|
|
7926
7975
|
return this._stdBinary(i, ((a, b) => {
|
|
7927
|
-
return ((a
|
|
7976
|
+
return (__ball_gt(a, b) ? a : b);
|
|
7928
7977
|
}));
|
|
7929
7978
|
}), ['math_clamp']: this._stdMathClamp.bind(this), ['math_pi']: ((_) => {
|
|
7930
7979
|
const input = _;
|
|
@@ -7993,7 +8042,7 @@ export class BallEngine {
|
|
|
7993
8042
|
}), ['sleep_ms']: (async (i) => {
|
|
7994
8043
|
const input = i;
|
|
7995
8044
|
let ms = ((typeof i === 'number' || i instanceof BallDouble) ? __ball_to_int(i) : 0);
|
|
7996
|
-
if ((ms
|
|
8045
|
+
if (__ball_gt(ms, 0)) {
|
|
7997
8046
|
await Future.delayed(new Duration({ milliseconds: ms }));
|
|
7998
8047
|
}
|
|
7999
8048
|
}), ['timestamp_ms']: ((_) => {
|
|
@@ -8171,7 +8220,7 @@ export class BallEngine {
|
|
|
8171
8220
|
_manualReverse(list: any): any {
|
|
8172
8221
|
const input = list;
|
|
8173
8222
|
let result = [];
|
|
8174
|
-
for (let i = __ball_sub(list.length, 1); (i
|
|
8223
|
+
for (let i = __ball_sub(list.length, 1); __ball_ge(i, 0); (i--)) {
|
|
8175
8224
|
result = (result.push(__ball_index(list, i)), result);
|
|
8176
8225
|
}
|
|
8177
8226
|
return result;
|
|
@@ -8179,7 +8228,7 @@ export class BallEngine {
|
|
|
8179
8228
|
|
|
8180
8229
|
_resolveMethod(typeName: any, methodName: any): any {
|
|
8181
8230
|
let colonIdx = typeName.indexOf(':');
|
|
8182
|
-
let modPart = ((colonIdx
|
|
8231
|
+
let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
|
|
8183
8232
|
let methodKey = ((((__ball_to_string(modPart) + '.') + __ball_to_string(typeName)) + '.') + __ball_to_string(methodName));
|
|
8184
8233
|
let method = __ball_index(this._functions, methodKey);
|
|
8185
8234
|
if ((!__ball_eq(method, null) && !method.isBase)) {
|
|
@@ -8429,7 +8478,7 @@ export class BallEngine {
|
|
|
8429
8478
|
}
|
|
8430
8479
|
this._trackMemoryAllocation(__ball_mul(length, _ballPointerBytes));
|
|
8431
8480
|
let result = [];
|
|
8432
|
-
for (let index = 0; (index
|
|
8481
|
+
for (let index = 0; __ball_lt(index, length); (index++)) {
|
|
8433
8482
|
let value = generator(index);
|
|
8434
8483
|
if ((value != null)) {
|
|
8435
8484
|
value = await value;
|
|
@@ -8579,7 +8628,7 @@ export class BallEngine {
|
|
|
8579
8628
|
}
|
|
8580
8629
|
}
|
|
8581
8630
|
if (__ball_eq(objTypeArgs.length, typeArgs.length)) {
|
|
8582
|
-
for (let i = 0; (i
|
|
8631
|
+
for (let i = 0; __ball_lt(i, typeArgs.length); (i++)) {
|
|
8583
8632
|
if (!__ball_eq(__ball_index(objTypeArgs, i), __ball_index(typeArgs, i))) {
|
|
8584
8633
|
return false;
|
|
8585
8634
|
}
|
|
@@ -8662,7 +8711,7 @@ export class BallEngine {
|
|
|
8662
8711
|
}
|
|
8663
8712
|
let objColon = objType.indexOf(':');
|
|
8664
8713
|
let checkColon = checkType.indexOf(':');
|
|
8665
|
-
if (((objColon
|
|
8714
|
+
if ((__ball_ge(objColon, 0) && __ball_ge(checkColon, 0))) {
|
|
8666
8715
|
return __ball_eq(objType.substring(__ball_add(objColon, 1)), checkType.substring(__ball_add(checkColon, 1)));
|
|
8667
8716
|
}
|
|
8668
8717
|
return false;
|
|
@@ -8673,7 +8722,7 @@ export class BallEngine {
|
|
|
8673
8722
|
let args = [];
|
|
8674
8723
|
let depth = 0;
|
|
8675
8724
|
let start = 0;
|
|
8676
|
-
for (let i = 0; (i
|
|
8725
|
+
for (let i = 0; __ball_lt(i, str.length); (i++)) {
|
|
8677
8726
|
if (__ball_eq(__ball_index(str, i), '<')) {
|
|
8678
8727
|
(depth++);
|
|
8679
8728
|
}
|
|
@@ -8844,7 +8893,7 @@ export class BallEngine {
|
|
|
8844
8893
|
let rhsStr = relMatch.group(2).trim();
|
|
8845
8894
|
let rhs = num.tryParse(rhsStr);
|
|
8846
8895
|
if (!__ball_eq(rhs, null)) {
|
|
8847
|
-
return ((op === '==') ? (__ball_eq(value, rhs)) : ((op === '!=') ? (!__ball_eq(value, rhs)) : ((op === '>') ? ((value
|
|
8896
|
+
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))))));
|
|
8848
8897
|
}
|
|
8849
8898
|
}
|
|
8850
8899
|
if (this._matchesTypePattern(value, trimmed)) {
|
|
@@ -8907,10 +8956,10 @@ export class BallEngine {
|
|
|
8907
8956
|
if ((__ball_eq(restIndex, __ball_negate(1)) && !__ball_eq(listVal.length, fixedCount))) {
|
|
8908
8957
|
return false;
|
|
8909
8958
|
}
|
|
8910
|
-
if ((!__ball_eq(restIndex, __ball_negate(1)) && (listVal.length
|
|
8959
|
+
if ((!__ball_eq(restIndex, __ball_negate(1)) && __ball_lt(listVal.length, fixedCount))) {
|
|
8911
8960
|
return false;
|
|
8912
8961
|
}
|
|
8913
|
-
for (let i = 0; (i
|
|
8962
|
+
for (let i = 0; __ball_lt(i, elements.length); (i++)) {
|
|
8914
8963
|
let elem = __ball_index(elements, i);
|
|
8915
8964
|
let elemMap = this._stdAsMap(elem);
|
|
8916
8965
|
if ((!__ball_eq(elemMap, null) && __ball_eq(this._patternKind(elemMap), 'rest'))) {
|
|
@@ -8921,7 +8970,7 @@ export class BallEngine {
|
|
|
8921
8970
|
}
|
|
8922
8971
|
continue;
|
|
8923
8972
|
}
|
|
8924
|
-
let valueIndex = ((__ball_eq(restIndex, __ball_negate(1)) || (i
|
|
8973
|
+
let valueIndex = ((__ball_eq(restIndex, __ball_negate(1)) || __ball_lt(i, restIndex)) ? i : __ball_sub(listVal.length, __ball_sub(elements.length, i)));
|
|
8925
8974
|
if (!this._matchPattern(__ball_index(listVal, valueIndex), elem, bindings)) {
|
|
8926
8975
|
return false;
|
|
8927
8976
|
}
|
|
@@ -9090,7 +9139,7 @@ export class BallEngine {
|
|
|
9090
9139
|
if (__ball_eq(operator, null)) {
|
|
9091
9140
|
return false;
|
|
9092
9141
|
}
|
|
9093
|
-
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
|
|
9142
|
+
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))))));
|
|
9094
9143
|
}
|
|
9095
9144
|
|
|
9096
9145
|
_matchesObjectType(value: any, patternType: any): any {
|
|
@@ -9166,7 +9215,7 @@ export class BallEngine {
|
|
|
9166
9215
|
|
|
9167
9216
|
_matchesTypePattern(value: any, pattern: any): any {
|
|
9168
9217
|
let p = ((typeof pattern === 'string') ? pattern : this._ballToStringSimple(pattern));
|
|
9169
|
-
if ((((p.length
|
|
9218
|
+
if (((__ball_gt(p.length, 1) && p.endsWith('?')) && !p.includes(' '))) {
|
|
9170
9219
|
if ((__ball_eq(value, null) || (value == null))) {
|
|
9171
9220
|
return true;
|
|
9172
9221
|
}
|
|
@@ -9232,7 +9281,7 @@ export class BallEngine {
|
|
|
9232
9281
|
|
|
9233
9282
|
_repeatString(s: any, count: any): any {
|
|
9234
9283
|
let out = '';
|
|
9235
|
-
for (let k = 0; (k
|
|
9284
|
+
for (let k = 0; __ball_lt(k, count); (k++)) {
|
|
9236
9285
|
out = (__ball_to_string(out) + __ball_to_string(s));
|
|
9237
9286
|
}
|
|
9238
9287
|
return out;
|
|
@@ -9993,14 +10042,14 @@ function _ballDoubleToInt64(value: any): any {
|
|
|
9993
10042
|
return value.value;
|
|
9994
10043
|
}
|
|
9995
10044
|
let d = (((typeof value === 'number' || value instanceof BallDouble) ? value.value : new BallDouble(Number(value))));
|
|
9996
|
-
if ((d
|
|
10045
|
+
if (__ball_ge(d, new BallDouble(9223372036854776000))) {
|
|
9997
10046
|
return 9223372036854775807n;
|
|
9998
10047
|
}
|
|
9999
|
-
if ((d
|
|
10048
|
+
if (__ball_le(d, __ball_negate(new BallDouble(9223372036854776000)))) {
|
|
10000
10049
|
return __ball_negate(0);
|
|
10001
10050
|
}
|
|
10002
10051
|
let r = __ball_to_int(d);
|
|
10003
|
-
if (((d
|
|
10052
|
+
if ((__ball_gt(d, new BallDouble(0)) && __ball_lt(r, 0))) {
|
|
10004
10053
|
return 9223372036854775807n;
|
|
10005
10054
|
}
|
|
10006
10055
|
return r;
|