"use strict";
/**
 * Dynamic loader for train-lang (ESM) from ccweb backend (CommonJS).
 *
 * `import('@tom2012/train-core')` is rewritten by ts-node/tsc as `require()`
 * which fails because train-lang is ESM-only. Wrapping the expression in
 * `new Function(...)` defers it past the TS compiler, leaving a native
 * dynamic import at runtime.
 *
 * Single cache for the whole process. Idempotent.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadTrainCore = loadTrainCore;
exports.makeBuiltinDynamic = makeBuiltinDynamic;
const dynamicImport = new Function('p', 'return import(p)');
let modPromise = null;
async function loadTrainCore() {
    if (!modPromise) {
        modPromise = dynamicImport('@tom2012/train-core');
    }
    return modPromise;
}
/**
 * Async wrapper for makeBuiltin — loads train-lang on first call and
 * forwards the rest. Use whenever you need to construct a BuiltinFunction
 * from CommonJS code.
 */
async function makeBuiltinDynamic(name, call) {
    const train = await loadTrainCore();
    return train.makeBuiltin(name, call);
}
//# sourceMappingURL=train-loader.js.map