@ball-lang/compiler 1.63.0 → 1.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js +69 -44
- package/dist/compiler.js.map +1 -1
- package/dist/preamble.d.ts.map +1 -1
- package/dist/preamble.js +30 -0
- package/dist/preamble.js.map +1 -1
- package/package.json +1 -1
- package/src/compiler.ts +72 -43
- package/src/preamble.ts +30 -0
package/dist/compiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAMV,MAAM,EACN,OAAO,EAIR,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,cAAc;IAC7B,2EAA2E;IAC3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAQD,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAElC,+CAA+C;IAC/C,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,KAAK,CAAK;IAElB,4EAA4E;IAC5E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAE/C,sEAAsE;IACtE,OAAO,CAAC,YAAY,CAA0B;IAE9C,mEAAmE;IACnE,OAAO,CAAC,kBAAkB,CAA0B;IAEpD,mEAAmE;IACnE,OAAO,CAAC,mBAAmB,CAA0B;IAErD,0EAA0E;IAC1E,OAAO,CAAC,uBAAuB,CAA0B;IAEzD;0EACsE;IACtE,OAAO,CAAC,uBAAuB,CAA0B;IAEzD;;;;OAIG;IACH,OAAO,CAAC,uBAAuB,CAA0B;IAEzD,8EAA8E;IAC9E,OAAO,CAAC,gBAAgB,CAAqB;IAE7C,8EAA8E;IAC9E,OAAO,CAAC,sBAAsB,CAA0B;IAExD,y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,cAAc;IA4+BtB,OAAO,CAAC,iBAAiB;IAoJzB,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,WAAW;IA2CnB,OAAO,CAAC,YAAY;IAUpB,OAAO,CAAC,iBAAiB;IA6HzB;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAqBxB,OAAO,CAAC,iBAAiB;IAiCzB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,YAAY;CAgDrB;AA07BD,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CAE1E;AAMD,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CA+HpF"}
|
package/dist/compiler.js
CHANGED
|
@@ -456,32 +456,15 @@ $1_getFieldDefaults(typeName: any): any {
|
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
$1async _resolveAndCallFunction(`);
|
|
459
|
-
//
|
|
460
|
-
//
|
|
461
|
-
//
|
|
462
|
-
//
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
// Try searching all functions for a matching suffix
|
|
470
|
-
// e.g., typeName="main:_gcd" should match "main.main:Fraction._gcd"
|
|
471
|
-
const __bareType = String(msg.typeName).indexOf(':') >= 0 ? String(msg.typeName).substring(String(msg.typeName).indexOf(':') + 1) : String(msg.typeName);
|
|
472
|
-
for (const __fk of Object.keys(this._functions)) {
|
|
473
|
-
if (__fk.endsWith('.' + __bareType) || __fk.endsWith('.' + msg.typeName)) {
|
|
474
|
-
const __fm = this._functions[__fk];
|
|
475
|
-
if (__fm && !__fm.isBase && __fm.hasBody()) {
|
|
476
|
-
return this._callFunction(this._currentModule, __fm, fields);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
return fields;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
_findTypeDef`);
|
|
459
|
+
// NOTE (#489/#499): a former post-processing pass injected a
|
|
460
|
+
// function-resolution fallback into _evalMessageCreation, anchored on the
|
|
461
|
+
// literal text `return fields; } _findTypeDef`. The reference engine's
|
|
462
|
+
// emitted shape moved on, so the regex stopped matching and the pass
|
|
463
|
+
// became a SILENT no-op (verified against the committed compiled_engine.ts
|
|
464
|
+
// on main: neither `__fnKey` nor any of its injected identifiers appears,
|
|
465
|
+
// while the engine is nevertheless at full conformance parity). It was
|
|
466
|
+
// removed rather than left behind as a dead `.replace` that reads as
|
|
467
|
+
// working behaviour.
|
|
485
468
|
// Post-processing: inject constructor instance building.
|
|
486
469
|
// When a function has no body and its metadata says kind='constructor',
|
|
487
470
|
// build an instance object from is_this params instead of returning null.
|
|
@@ -2351,6 +2334,16 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2351
2334
|
}
|
|
2352
2335
|
}
|
|
2353
2336
|
}
|
|
2337
|
+
// Dart runs a constructor's INITIALIZER LIST before its body, and a
|
|
2338
|
+
// constructor may have both (`Point(int a, int b) : x = a, y = b { … }`).
|
|
2339
|
+
// Only `super(...)` and `this.`-params were emitted here, so every
|
|
2340
|
+
// initializer-list field stayed `undefined` (conformance 438).
|
|
2341
|
+
const rawParamNames = rawParams.map((p) => p.name);
|
|
2342
|
+
for (const init of initializers) {
|
|
2343
|
+
if (init?.kind !== "field" || typeof init.name !== "string")
|
|
2344
|
+
continue;
|
|
2345
|
+
prologueParts.push(`this.${init.name} = ${resolveInitializerValue(init.value, rawParamNames)};`);
|
|
2346
|
+
}
|
|
2354
2347
|
const prologue = prologueParts.join("\n");
|
|
2355
2348
|
// Filter out self-recursive patterns from the constructor body.
|
|
2356
2349
|
// The encoder emits `let self = messageCreation{typeName:"mod:ClassName"}`
|
|
@@ -2453,30 +2446,29 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
2453
2446
|
// This directly instantiates with fields set.
|
|
2454
2447
|
const assignments = initializers
|
|
2455
2448
|
.filter((i) => i?.kind === "field")
|
|
2456
|
-
.map((init) => {
|
|
2457
|
-
const valueStr = typeof init.value === "string" ? init.value : "null";
|
|
2458
|
-
let resolvedValue;
|
|
2459
|
-
if (params.includes(valueStr))
|
|
2460
|
-
resolvedValue = sanitize(valueStr);
|
|
2461
|
-
else if (/^-?\d+(\.\d+)?$/.test(valueStr))
|
|
2462
|
-
resolvedValue = valueStr.includes(".") ? `new BallDouble(${valueStr})` : valueStr;
|
|
2463
|
-
else if (valueStr.startsWith("'") || valueStr.startsWith('"'))
|
|
2464
|
-
resolvedValue = valueStr;
|
|
2465
|
-
else {
|
|
2466
|
-
const idxMatch = /^(\w+)\[(\d+)\]$/.exec(valueStr);
|
|
2467
|
-
if (idxMatch && params.includes(idxMatch[1]))
|
|
2468
|
-
resolvedValue = `${sanitize(idxMatch[1])}[${idxMatch[2]}]`;
|
|
2469
|
-
else
|
|
2470
|
-
resolvedValue = valueStr;
|
|
2471
|
-
}
|
|
2472
|
-
return `__inst.${init.name} = ${resolvedValue};`;
|
|
2473
|
-
});
|
|
2449
|
+
.map((init) => `__inst.${init.name} = ${resolveInitializerValue(init.value, params)};`);
|
|
2474
2450
|
// For is_this params, assign them as fields
|
|
2475
2451
|
const thisAssignments = thisParams.map(p => `__inst.${p.name} = ${sanitize(p.name)};`);
|
|
2476
2452
|
const allAssignments = [...assignments, ...thisAssignments];
|
|
2477
2453
|
bodyParts.push(`const __inst = Object.create(${className}.prototype);`);
|
|
2478
2454
|
for (const a of allAssignments)
|
|
2479
2455
|
bodyParts.push(a);
|
|
2456
|
+
// A named constructor may have BOTH an initializer list / `this.`-params
|
|
2457
|
+
// AND a body (`Countdown.pair(int s) : value = s { tail = …; }`, or
|
|
2458
|
+
// `Countdown.from(this.value) { … }`). Dart runs the list first, then the
|
|
2459
|
+
// body; the body used to be dropped entirely by this branch, so every
|
|
2460
|
+
// field the body set stayed unset (conformance 436/438). `.call(__inst)`
|
|
2461
|
+
// — a real `function`, not an arrow — gives the compiled body the
|
|
2462
|
+
// instance as `this`, so its `this.<field>` writes land on `__inst`,
|
|
2463
|
+
// while the constructor's parameters stay in scope by closure.
|
|
2464
|
+
if (fn.body) {
|
|
2465
|
+
const captured = this.withMethodContext(new Set(params), classFields, () => this.captureInto(() => {
|
|
2466
|
+
this.emitStatementOrExpression(fn.body, false);
|
|
2467
|
+
}));
|
|
2468
|
+
if (captured.trim() !== "") {
|
|
2469
|
+
bodyParts.push(`(function () {\n${captured}\n}).call(__inst);`);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2480
2472
|
bodyParts.push(`return __inst;`);
|
|
2481
2473
|
}
|
|
2482
2474
|
else if (fn.body) {
|
|
@@ -4336,6 +4328,15 @@ function __isUnknownFnError(e: any): boolean {
|
|
|
4336
4328
|
return `(${this.expr(f.get("value"))} == null)`;
|
|
4337
4329
|
}
|
|
4338
4330
|
case "as": return this.expr(f.get("value"));
|
|
4331
|
+
// #489 — the value's canonical runtime type NAME. The TS encoder emits
|
|
4332
|
+
// this for JS `typeof`, but bare `typeof` does not match the vocabulary
|
|
4333
|
+
// (`typeof [] === 'object'`), so route through the preamble helper.
|
|
4334
|
+
case "type_of": {
|
|
4335
|
+
const val = f.get("value") ?? f.get("target") ?? f.get("arg0");
|
|
4336
|
+
if (!val)
|
|
4337
|
+
throw new Error("TS compiler: std.type_of is missing its `value` field");
|
|
4338
|
+
return `__ball_type_of(${this.expr(val)})`;
|
|
4339
|
+
}
|
|
4339
4340
|
case "if": {
|
|
4340
4341
|
const cond = this.expr(f.get("condition"));
|
|
4341
4342
|
const thenExpr = f.get("then");
|
|
@@ -5734,6 +5735,30 @@ function extractParams(fn) {
|
|
|
5734
5735
|
}
|
|
5735
5736
|
return out;
|
|
5736
5737
|
}
|
|
5738
|
+
/**
|
|
5739
|
+
* Resolve a constructor initializer-list value. The encoder stores these as
|
|
5740
|
+
* SOURCE TEXT (`x = a` -> "a", `label = 'pt'` -> "'pt'", `x = coords[0]` ->
|
|
5741
|
+
* "coords[0]"), so a param reference, a literal and an indexed read all arrive
|
|
5742
|
+
* as plain strings. Shared by the unnamed and named constructor builders so the
|
|
5743
|
+
* two can never drift.
|
|
5744
|
+
*/
|
|
5745
|
+
function resolveInitializerValue(rawValue, params) {
|
|
5746
|
+
const valueStr = typeof rawValue === "string" ? rawValue : "null";
|
|
5747
|
+
if (params.includes(valueStr))
|
|
5748
|
+
return sanitize(valueStr);
|
|
5749
|
+
if (/^-?\d+(\.\d+)?$/.test(valueStr)) {
|
|
5750
|
+
return valueStr.includes(".") ? `new BallDouble(${valueStr})` : valueStr;
|
|
5751
|
+
}
|
|
5752
|
+
if (valueStr.startsWith("'") || valueStr.startsWith('"'))
|
|
5753
|
+
return valueStr;
|
|
5754
|
+
if (valueStr === "true" || valueStr === "false" || valueStr === "null")
|
|
5755
|
+
return valueStr;
|
|
5756
|
+
const idxMatch = /^(\w+)\[(\d+)\]$/.exec(valueStr);
|
|
5757
|
+
if (idxMatch && params.includes(idxMatch[1])) {
|
|
5758
|
+
return `${sanitize(idxMatch[1])}[${idxMatch[2]}]`;
|
|
5759
|
+
}
|
|
5760
|
+
return valueStr;
|
|
5761
|
+
}
|
|
5737
5762
|
function extractCtorParams(meta) {
|
|
5738
5763
|
const raw = meta["params"];
|
|
5739
5764
|
if (!Array.isArray(raw))
|