/** * Loading a compiled program, which is everything that happens before bar 0. * * Separate from the bar cycle because it is a different job with a different * failure. A load either refuses, with a code and a reason, or hands back an * engine that has already been proved able to run: verification in full * (`compiled-program.md` 3.5), then the refusals a host makes, then the * settings. Nothing is executed until all three pass, so a program that cannot * run says so before a chart has drawn anything, rather than halfway through * bar four thousand with half a study on the screen. */ import type { Diagnostic } from '../diagnostics/index.js'; import type { SourceFile } from '../source/index.js'; import type { Clock, EngineLimits } from './budget.js'; import { Engine } from './engine.js'; import type { EngineHost } from './host.js'; import type { ResolvedInput, TimeResolver } from './inputs.js'; export interface LoadOptions { /** The host's settings, keyed by input `key`. */ readonly settings?: Readonly>; readonly limits?: Partial; /** The source, so a diagnostic's span can carry an offset as well as a line. */ readonly source?: SourceFile; readonly host?: EngineHost; /** A reading of the wall clock, for the per bar time budget. */ readonly clock?: Clock; /** How a `"time"` input's stored wall clock string becomes a timestamp. */ readonly time?: TimeResolver; } /** * A loaded program, and the settings it was loaded under. * * The resolved inputs come back beside the engine because a declaration field * may be written by an input (`compiled-program.md` 2.3), and a caller outside * the engine reads some of those fields: what a run was carried out with is the * declaration's capital, its commission and the bar a fill is priced at, and * the backtest driver is what reports them. Resolving an input a second time * out there would be the same rule written in two files, and the first host * setting either of them read differently would be a report nobody could * explain. So the resolution happens once, here, and what it produced is handed * over rather than kept. */ export type LoadResult = { readonly ok: true; readonly engine: Engine; readonly inputs: readonly ResolvedInput[]; } | { readonly ok: false; readonly diagnostic: Diagnostic; }; /** * Loads a compiled program. * * Verification runs first and in full (3.5), then the refusals a host makes, * then input resolution. Nothing is executed until all three pass, so a program * that cannot run says so before a chart has drawn anything. */ export declare function load(program: unknown, options?: LoadOptions): LoadResult; /** * Loads a compiled program from text, which is where canonicity is required. * * `load` takes a parsed object because a host that compiled in this process * never serialised, and there is nothing for such an object to be canonical * about. Text is the other boundary, `compiled-program.md` 9.4 step 1 and * section 13 (decision 57): a program an engine reads from outside its process * arrives as the canonical encoding of 2.14, and text that parses to a program * but is not that encoding is refused, because the hash a host recorded was * taken over canonical bytes and text in any other spelling is text that hash * does not name. So the text is parsed, written out again by the one canonical * writer, and the two are compared character for character. Either failure is * OS6018 naming where the text stops being readable or stops being canonical, * counted in characters of the text, which is where an editor's cursor lands. * * What passes here is the object `load` verifies from step 2 on, so every * refusal that applies to an object applies to text as well and in the same * order. */ export declare function loadText(text: string, options?: LoadOptions): LoadResult; //# sourceMappingURL=load.d.ts.map