@ball-lang/engine 1.68.0 → 1.68.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ball-lang/engine",
3
- "version": "1.68.0",
3
+ "version": "1.68.1",
4
4
  "description": "Ball language engine — interprets Ball programs in TypeScript/JavaScript. Runs in Node.js and browsers.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -2176,15 +2176,20 @@ export class BallEngine {
2176
2176
  }
2177
2177
  let params = (!(func.name.length === 0) ? (__ball_index(this._paramCache, ((__ball_to_string(moduleName) + '.') + __ball_to_string(func.name))) ?? ((hasMetadata(func) ? this._extractParams(func.metadata) : []))) : ((hasMetadata(func) ? this._extractParams(func.metadata) : [])));
2178
2178
  let inputMap = this._asMap(input);
2179
+ let inputIsInstance = (!__ball_eq(inputMap, null) && this._isInstanceValue(inputMap));
2180
+ let boundParams = [];
2179
2181
  if (!(params.length === 0)) {
2180
2182
  if ((__ball_eq(params.length, 1) && !(!__ball_eq(inputMap, null) && __ball_map_has(inputMap, 'map_contains_key', 'self')))) {
2181
- if ((!__ball_eq(inputMap, null) && __ball_map_has(inputMap, 'map_contains_key', __ball_index(params, 0)))) {
2183
+ if (((!__ball_eq(inputMap, null) && !inputIsInstance) && __ball_map_has(inputMap, 'map_contains_key', __ball_index(params, 0)))) {
2182
2184
  scope.bind(__ball_index(params, 0), __ball_index(inputMap, __ball_index(params, 0)));
2185
+ boundParams = (boundParams.push(__ball_index(params, 0)), boundParams);
2183
2186
  } else {
2184
- if (((!__ball_eq(inputMap, null) && __ball_map_has(inputMap, 'map_contains_key', 'arg0')) && !__ball_map_has(inputMap, 'map_contains_key', __ball_index(params, 0)))) {
2187
+ if ((((!__ball_eq(inputMap, null) && !inputIsInstance) && __ball_map_has(inputMap, 'map_contains_key', 'arg0')) && !__ball_map_has(inputMap, 'map_contains_key', __ball_index(params, 0)))) {
2185
2188
  scope.bind(__ball_index(params, 0), __ball_index(inputMap, 'arg0'));
2189
+ boundParams = (boundParams.push(__ball_index(params, 0)), boundParams);
2186
2190
  } else {
2187
2191
  scope.bind(__ball_index(params, 0), input);
2192
+ boundParams = (boundParams.push(__ball_index(params, 0)), boundParams);
2188
2193
  }
2189
2194
  }
2190
2195
  } else {
@@ -2193,12 +2198,15 @@ export class BallEngine {
2193
2198
  let p = __ball_index(params, i);
2194
2199
  if (__ball_map_has(inputMap, 'map_contains_key', p)) {
2195
2200
  scope.bind(p, __ball_index(inputMap, p));
2201
+ boundParams = (boundParams.push(p), boundParams);
2196
2202
  } else {
2197
2203
  if (__ball_map_has(inputMap, 'map_contains_key', ('arg' + __ball_to_string(i)))) {
2198
2204
  scope.bind(p, __ball_index(inputMap, ('arg' + __ball_to_string(i))));
2205
+ boundParams = (boundParams.push(p), boundParams);
2199
2206
  } else {
2200
2207
  if ((((__ball_eq(i, 0) && __ball_eq(params.length, 1)) && __ball_map_has(inputMap, 'map_contains_key', 'value')) && this._isSetter(func))) {
2201
2208
  scope.bind(p, __ball_index(inputMap, 'value'));
2209
+ boundParams = (boundParams.push(p), boundParams);
2202
2210
  }
2203
2211
  }
2204
2212
  }
@@ -2207,6 +2215,7 @@ export class BallEngine {
2207
2215
  if (Array.isArray(input)) {
2208
2216
  for (let i = 0; (__ball_lt(i, params.length) && __ball_lt(i, input.length)); (i++)) {
2209
2217
  scope.bind(__ball_index(params, i), __ball_index(input, i));
2218
+ boundParams = (boundParams.push(__ball_index(params, i)), boundParams);
2210
2219
  }
2211
2220
  }
2212
2221
  }
@@ -2218,7 +2227,7 @@ export class BallEngine {
2218
2227
  let selfMap = this._asMap(self);
2219
2228
  if (!__ball_eq(selfMap, null)) {
2220
2229
  for (const entry of selfMap.entries) {
2221
- if (!entry.key.startsWith('__')) {
2230
+ if ((!entry.key.startsWith('__') && !boundParams.includes(entry.key))) {
2222
2231
  scope.bind(entry.key, entry.value);
2223
2232
  }
2224
2233
  }
@@ -2330,12 +2339,9 @@ export class BallEngine {
2330
2339
  if (__ball_eq(typeDef, null)) {
2331
2340
  return null;
2332
2341
  }
2333
- let inputMap = (this._asMap(input) ?? { ['arg0']: input });
2342
+ let rawInputMap = this._asMap(input);
2343
+ let inputMap = ((__ball_eq(rawInputMap, null) || this._isInstanceValue(rawInputMap)) ? { ['arg0']: input } : rawInputMap);
2334
2344
  let instanceFields = {};
2335
- for (const fieldName of typeDef.fieldNames) {
2336
- instanceFields[fieldName] = null;
2337
- }
2338
- let allFieldNames = this._collectAllFieldNames(typeName);
2339
2345
  let params = (hasMetadata(func) ? this._extractParams(func.metadata) : []);
2340
2346
  let paramsMeta = (hasMetadata(func) ? this._extractParamsMeta(func.metadata) : []);
2341
2347
  let resolvedParams = {};
@@ -2354,15 +2360,16 @@ export class BallEngine {
2354
2360
  }
2355
2361
  resolvedParams[param] = value;
2356
2362
  let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
2357
- if ((isThis || allFieldNames.includes(param))) {
2363
+ if (isThis) {
2358
2364
  instanceFields[param] = value;
2359
- } else {
2360
- if ((__ball_eq(params.length, 1) && __ball_eq(allFieldNames.length, 1))) {
2361
- instanceFields[allFieldNames.first] = value;
2362
- }
2363
2365
  }
2364
2366
  }
2365
2367
  this._initFieldDefaults(typeName, instanceFields);
2368
+ for (const fieldName of typeDef.fieldNames) {
2369
+ if (!__ball_map_has(instanceFields, 'map_contains_key', fieldName)) {
2370
+ instanceFields[fieldName] = null;
2371
+ }
2372
+ }
2366
2373
  this._applyConstructorInitializers(func, instanceFields, resolvedParams, true);
2367
2374
  let superclass = this._getMetaString(typeDef, 'superclass');
2368
2375
  let superObject;
@@ -2470,7 +2477,8 @@ export class BallEngine {
2470
2477
  let typeName = (__ball_ge(dotIdx, 0) ? func.name.substring(0, dotIdx) : func.name);
2471
2478
  instance['__type__'] = typeName;
2472
2479
  let resolvedParams = {};
2473
- let inputMap = this._asMap(input);
2480
+ let rawInputMap = this._asMap(input);
2481
+ let inputMap = ((!__ball_eq(rawInputMap, null) && this._isInstanceValue(rawInputMap)) ? { ['arg0']: input } : rawInputMap);
2474
2482
  if (!__ball_eq(inputMap, null)) {
2475
2483
  for (let i = 0; __ball_lt(i, params.length); (i++)) {
2476
2484
  let p = __ball_index(params, i);
@@ -2507,6 +2515,7 @@ export class BallEngine {
2507
2515
  }
2508
2516
  this._applyConstructorInitializers(func, instance, resolvedParams);
2509
2517
  let typeDef = this._findTypeDef(typeName);
2518
+ this._initFieldDefaults(typeName, instance);
2510
2519
  if (!__ball_eq(typeDef, null)) {
2511
2520
  let superclass = this._getMetaString(typeDef, 'superclass');
2512
2521
  if ((!__ball_eq(superclass, null) && !(superclass.length === 0))) {
@@ -4353,7 +4362,6 @@ export class BallEngine {
4353
4362
  }
4354
4363
  }
4355
4364
  let instanceFields = {};
4356
- let allFieldNames = this._collectAllFieldNames(msg.typeName);
4357
4365
  for (const entry of fields.entries) {
4358
4366
  if (!entry.key.startsWith('arg')) {
4359
4367
  instanceFields[entry.key] = entry.value;
@@ -4385,12 +4393,8 @@ export class BallEngine {
4385
4393
  }
4386
4394
  resolvedParams[param] = value;
4387
4395
  let isThis = (__ball_lt(i, paramsMeta.length) && __ball_eq(__ball_index(__ball_index(paramsMeta, i), 'is_this'), true));
4388
- if ((isThis || allFieldNames.includes(param))) {
4396
+ if (isThis) {
4389
4397
  instanceFields[param] = value;
4390
- } else {
4391
- if ((__ball_eq(params.length, 1) && __ball_eq(allFieldNames.length, 1))) {
4392
- instanceFields[allFieldNames.first] = value;
4393
- }
4394
4398
  }
4395
4399
  }
4396
4400
  }
@@ -4684,26 +4688,16 @@ export class BallEngine {
4684
4688
  }
4685
4689
  }
4686
4690
 
4687
- _collectAllFieldNames(typeName: any): any {
4688
- const input = typeName;
4689
- let names = [];
4690
- let typeDef = this._findTypeDef(typeName);
4691
- if (__ball_eq(typeDef, null)) {
4692
- return names;
4693
- }
4694
- let colonIdx = typeName.indexOf(':');
4695
- let modPart = (__ball_ge(colonIdx, 0) ? typeName.substring(0, colonIdx) : this._currentModule);
4696
- let superclass = typeDef.superclass;
4697
- if ((!__ball_eq(superclass, null) && !(superclass.length === 0))) {
4698
- let qualifiedSuper = (superclass.includes(':') ? superclass : ((__ball_to_string(modPart) + ':') + __ball_to_string(superclass)));
4699
- __ball_push_all(names, this._collectAllFieldNames(qualifiedSuper));
4691
+ _isInstanceValue(map: any): any {
4692
+ const input = map;
4693
+ let typeName = __ball_index(map, '__type__');
4694
+ if ((!((typeof typeName === 'string')) || (typeName.length === 0))) {
4695
+ return false;
4700
4696
  }
4701
- for (const fieldName of typeDef.fieldNames) {
4702
- if (!names.includes(fieldName)) {
4703
- names = (names.push(fieldName), names);
4704
- }
4697
+ if (__ball_map_has(map, 'map_contains_key', '__fields__')) {
4698
+ return true;
4705
4699
  }
4706
- return names;
4700
+ return !__ball_eq(this._findTypeDef(typeName), null);
4707
4701
  }
4708
4702
 
4709
4703
  _buildSuperObject(superclass: any, childFields: any): any {