@ball-lang/engine 1.3.5 → 1.3.7
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 +8 -12
- package/dist/compiled_engine.js.map +1 -1
- package/dist/engine_setup.d.ts +1 -1
- package/dist/engine_setup.d.ts.map +1 -1
- package/dist/engine_setup.js +24 -2
- package/dist/engine_setup.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/compiled_engine.ts +7 -12
- package/src/engine_setup.ts +24 -2
- package/src/index.ts +17 -2
package/dist/engine_setup.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare function createEngineSetup(mod: EngineModule): {
|
|
|
35
35
|
call(fn: string, input: any, _engine: any): any;
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
-
registerExtraStdFunctions: (stdHandler: any) => void;
|
|
38
|
+
registerExtraStdFunctions: (stdHandler: any, engine: any) => void;
|
|
39
39
|
patchCompiledEngine: (engine: any) => void;
|
|
40
40
|
seedGlobalScope: (engine: any) => void;
|
|
41
41
|
patchScopeBindings: (globalScope: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine_setup.d.ts","sourceRoot":"","sources":["../src/engine_setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,GAAG,CAAC;IAChB,gBAAgB,EAAE,GAAG,CAAC;IACtB,aAAa,EAAE,GAAG,CAAC;IACnB,WAAW,EAAE,GAAG,CAAC;IACjB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY;qBA8TzB,GAAG,2BAAuB,GAAG;qBA6E7B,GAAG,KAAG,GAAG;eAqCf,GAAG,KAAG,MAAM;;;;4BA8CZ,GAAG,GAAG,OAAO;0BACf,GAAG,GAAG,IAAI;qBACf,MAAM,SAAS,GAAG,WAAW,GAAG,GAAG,GAAG;;;
|
|
1
|
+
{"version":3,"file":"engine_setup.d.ts","sourceRoot":"","sources":["../src/engine_setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,GAAG,CAAC;IAChB,gBAAgB,EAAE,GAAG,CAAC;IACtB,aAAa,EAAE,GAAG,CAAC;IACnB,WAAW,EAAE,GAAG,CAAC;IACjB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY;qBA8TzB,GAAG,2BAAuB,GAAG;qBA6E7B,GAAG,KAAG,GAAG;eAqCf,GAAG,KAAG,MAAM;;;;4BA8CZ,GAAG,GAAG,OAAO;0BACf,GAAG,GAAG,IAAI;qBACf,MAAM,SAAS,GAAG,WAAW,GAAG,GAAG,GAAG;;;yDAqIkB,GAAG,KAAG,IAAI;0CA0iBvB,IAAI;sCAgfR,IAAI;sCA0Bb,GAAG,KAAG,IAAI;uBA5nDzB,GAAG,KAAG,OAAO;0BAwmCV,GAAG,KAAG,GAAG;EA0jBvC"}
|
package/dist/engine_setup.js
CHANGED
|
@@ -678,9 +678,23 @@ export function createEngineSetup(mod) {
|
|
|
678
678
|
// the Dart std library. In TypeScript we need to provide JS implementations
|
|
679
679
|
// for functions that the compiled engine's _buildStdDispatch doesn't cover
|
|
680
680
|
// (collection higher-order functions, string helpers, etc.).
|
|
681
|
-
|
|
681
|
+
/**
|
|
682
|
+
* Register the hand-written std-function overrides on `stdHandler`.
|
|
683
|
+
*
|
|
684
|
+
* `engine` is the compiled BallEngine instance the handler is wired to.
|
|
685
|
+
* It is REQUIRED for handlers that allocate proportionally to their input
|
|
686
|
+
* (list_filled / list_generate): they charge the allocation against the
|
|
687
|
+
* engine's memory accounting so `maxMemoryBytes` is enforced (#24). The
|
|
688
|
+
* compiled engine's handler-call protocol passes a bound `callFunction`
|
|
689
|
+
* (not the engine) as the third argument, so the engine must be captured
|
|
690
|
+
* here at registration time.
|
|
691
|
+
*/
|
|
692
|
+
function registerExtraStdFunctions(stdHandler, engine) {
|
|
682
693
|
const _r = stdHandler.register.bind(stdHandler);
|
|
683
694
|
const _m = (i) => (typeof i === 'object' && i !== null) ? i : {};
|
|
695
|
+
// Mirrors the compiled engine's `_ballPointerBytes` accounting constant.
|
|
696
|
+
const _ptrBytes = 8;
|
|
697
|
+
const _track = (bytes) => engine._trackMemoryAllocation(bytes);
|
|
684
698
|
// ── Collection: list_* ─────────────────────────────────────────────
|
|
685
699
|
_r('list_foreach', async (i) => {
|
|
686
700
|
const m = _m(i);
|
|
@@ -1352,13 +1366,18 @@ export function createEngineSetup(mod) {
|
|
|
1352
1366
|
return val;
|
|
1353
1367
|
return val;
|
|
1354
1368
|
});
|
|
1355
|
-
// Override dart_list_generate (compiled version's lambda calling may fail)
|
|
1369
|
+
// Override dart_list_generate (compiled version's lambda calling may fail).
|
|
1370
|
+
// These overrides shadow the compiled `_stdListFilled`/`_stdListGenerate`
|
|
1371
|
+
// implementations, which already track allocations — so they must charge
|
|
1372
|
+
// the allocation against the engine's memory accounting themselves
|
|
1373
|
+
// (maxMemoryBytes, #24).
|
|
1356
1374
|
_r('dart_list_generate', async (i) => {
|
|
1357
1375
|
const m = _m(i);
|
|
1358
1376
|
const count = Number(m['count'] ?? m['arg0'] ?? 0);
|
|
1359
1377
|
const gen = m['generator'] ?? m['arg1'];
|
|
1360
1378
|
if (typeof gen !== 'function')
|
|
1361
1379
|
return [];
|
|
1380
|
+
_track(Math.max(0, count | 0) * _ptrBytes);
|
|
1362
1381
|
const result = [];
|
|
1363
1382
|
for (let idx = 0; idx < count; idx++) {
|
|
1364
1383
|
let v = gen(idx);
|
|
@@ -1371,11 +1390,13 @@ export function createEngineSetup(mod) {
|
|
|
1371
1390
|
_r('dart_list_filled', (i) => {
|
|
1372
1391
|
const m = _m(i);
|
|
1373
1392
|
const count = Number(m['count'] ?? m['length'] ?? m['arg0'] ?? 0);
|
|
1393
|
+
_track(Math.max(0, count | 0) * _ptrBytes);
|
|
1374
1394
|
return Array(Math.max(0, count | 0)).fill(m['value'] ?? m['arg1'] ?? null);
|
|
1375
1395
|
});
|
|
1376
1396
|
_r('list_filled', (i) => {
|
|
1377
1397
|
const m = _m(i);
|
|
1378
1398
|
const count = Number(m['count'] ?? m['length'] ?? m['arg0'] ?? 0);
|
|
1399
|
+
_track(Math.max(0, count | 0) * _ptrBytes);
|
|
1379
1400
|
return Array(Math.max(0, count | 0)).fill(m['value'] ?? m['arg1'] ?? null);
|
|
1380
1401
|
});
|
|
1381
1402
|
_r('list_generate', (i) => {
|
|
@@ -1384,6 +1405,7 @@ export function createEngineSetup(mod) {
|
|
|
1384
1405
|
const fn = m['function'] ?? m['generator'] ?? m['callback'] ?? m['value'];
|
|
1385
1406
|
if (typeof fn !== 'function')
|
|
1386
1407
|
return [];
|
|
1408
|
+
_track(Math.max(0, count | 0) * _ptrBytes);
|
|
1387
1409
|
const out = [];
|
|
1388
1410
|
for (let i2 = 0; i2 < count; i2++) {
|
|
1389
1411
|
let r = fn(i2);
|