/** * The shape of the standard library, as the checker needs to see it. * * `stdlib.md` is the specification of what each call does and what it costs in * bars. What the checker needs from it is narrower: a name, the parameters it * takes, the type it gives back, where it may be written and how many bars it * delays its source by. That is what an entry here holds, and nothing here * implements any of it: the numbers are computed under `src/core/stdlib/`. * * Entries are written as signature strings because a signature is what the * specification's tables already show a reader, so the two can be compared by * eye without translating one of them first. A string is parsed once, when this * module loads, into the record below; there is no code built from text * anywhere, and there cannot be, which is the rule the whole design rests on. */ import type { Type } from './types.js'; /** * How a call's own warmup relates to the warmup of what it was given. * * `delay` and `params` both add bars to the source's own warmup, which is what * makes warmups compose: `sma(ema(close, 10), 10)` is absent until bar 18. * `params` reads the added bars off the call's own arguments, so it can only * be exact when those arguments are literal numbers, and `exact` says whether * the formula in `stdlib.md` is reproduced here or only bounded below. */ export type WarmupRule = { readonly kind: 'delay'; readonly bars: number; } | { readonly kind: 'params'; readonly params: readonly string[]; readonly scale: number; readonly add: number; readonly exact: boolean; } /** A value on bar 0 however late its arguments are: `isNone` is the example. */ | { readonly kind: 'total'; } /** The warmup of one named argument, and of nothing else. */ | { readonly kind: 'argument'; readonly param: string; } /** Present as soon as the earlier of these arguments is: `orElse`. */ | { readonly kind: 'either'; readonly params: readonly string[]; } /** Decided by the data rather than by a length, so a floor is all there is. */ | { readonly kind: 'data'; }; /** * A whole number argument and the range it accepts, for OS3004. * * The bounds are numbers and the sentence is derived from them, so the message * a reader sees and the test the checker runs cannot say different things. A * fractional length is refused rather than truncated (`language.md` 5.1): a * length of 14.5 is a bug in the script and rounding it hides the bug. */ export interface WholeRange { readonly text: string; readonly min: number | undefined; readonly max: number | undefined; } export declare function wholeRange(min?: number, max?: number): WholeRange; export interface LibraryParameter { readonly name: string; readonly type: Type; /** Whether the entry gives it a default. A missing required one is OS3012. */ readonly optional: boolean; /** * The default, written as `stdlib.md`'s own tables write it, or nothing. * * An omitted argument is filled from this text, so the default is a * compile-time fact and no engine carries a table of them * (`compiled-program.md` 4.10). The text is a literal (`14`, `"ema"`, * `false`, `none`) or a library name the compiler reads at the call * (`hlc3`, `chart.timezone`); the emitter decides which, because a default * is a value and values are the emitter's. * * **Nothing here is not "no default".** It means the specification states no * value for this parameter: either it states words rather than a value, as * `leg = the only leg` does, or it states nothing at all. Both are recorded * with their reason in `spec/default-exceptions.json`, and * `scripts/check-defaults.mjs` refuses any optional parameter that is in * neither that file nor this field. The two together are what stop a default * from being dropped again: an argument omitted from a call used to reach an * engine as absence, every function built on it answered absence on every * bar, and nothing anywhere reported it. */ readonly defaultText: string | undefined; } export interface LibraryEntry { /** `ema`, or `draw.line` with its namespace, exactly as a script writes it. */ readonly name: string; /** A value such as `close` is read bare; a function is called. */ readonly callable: boolean; readonly parameters: readonly LibraryParameter[]; readonly returns: Type; readonly warmup: WarmupRule; /** * A rule per output, for an entry whose outputs warm up at different bars. * * `stdlib.md` 2.3 gives each element of a multi-output call its own warmup, * and several of them differ: a signal line is later than the line it * smooths. Empty where the specification states one bar for every element, * because then `warmup` above is already that bar and a second copy of it * would be a fact stated twice. */ readonly elements: readonly WarmupRule[]; /** Holds per-bar state, so a call inside a branch is OS8001. */ readonly stateful: boolean; /** Top level only: OS3006, or OS3007 for `input`. */ readonly topLevel: boolean; /** Available only in a `strategy()` file: OS7001. */ readonly strategyOnly: boolean; /** Named so the surface is legible, and not in this release: OS2020. */ readonly planned: boolean; /** Arguments with a closed set of accepted strings: OS3008. */ readonly values: Readonly>; /** * Arguments that name something the file declares, where this release has no * declaration that could fill the set: OS3023. * * Different from `values` and from `planned`, and the difference is what the * reader is told. `values` holds an argument to a set the language fixes, and * it can only judge a value written out as a literal. `planned` is about the * whole name. This is about an argument whose accepted values are whatever * the file declared, in a release where nothing can declare one: the value * does not come into it, so a computed name is refused exactly as a written * one is, and the message says the file declares none rather than listing an * empty set. */ readonly undeclared: readonly string[]; /** Arguments that must be a whole number, with the range for OS3004. */ readonly whole: Readonly>; /** Arguments read once before bar 0, so a bar-dependent one is OS3003. */ readonly constant: readonly string[]; /** * Arguments the compiled format carries as a plain value, with no input * reference beside it, so a setting written into one is OS3026 rather than * folded to its default with nothing said. */ readonly written: readonly string[]; /** Pairs that set the same thing two ways, so giving both is OS3010. */ readonly conflicts: readonly (readonly [string, string])[]; } export interface EntryOptions { readonly warmup?: WarmupRule; readonly elements?: readonly WarmupRule[]; readonly stateful?: true; readonly topLevel?: true; readonly strategyOnly?: true; readonly planned?: true; readonly values?: Readonly>; readonly undeclared?: readonly string[]; readonly whole?: Readonly>; readonly constant?: readonly string[]; readonly written?: readonly string[]; readonly conflicts?: readonly (readonly [string, string])[]; } /** * A type as the signature strings spell it. * * `any` and the single letters are not types of the language. `any` is a * parameter that takes whatever it is given, which is what `isNone` and `text` * want. A single letter is a stand-in carried from one parameter to another, so * that `push(arr, v)` can say that `v` is whatever `arr` holds and `orElse` * can say it gives back what it was given. Both are resolved at the call site * and neither ever reaches a name's type. * * `line | box` is not either of those and is not a general union: it is the set * of object kinds one parameter accepts, which is what a `draw` setter takes, * and it is checked like any other declared type. `any` used to stand there, * and an `any` that means "one of these two" accepts a label and a number as * readily, which is the defect it is written to end. */ export declare const ANY: Type; /** * One entry, from `name(param: type, optional?: type) -> result`. * * A name with no bracket is a value a script reads bare, such as `close` or * `bar.index`. A `?` after a parameter name means the library gives it a * default, and `= value` after the type says what that default is, written the * way `stdlib.md`'s tables write it so the two can still be compared by eye. * The text is carried, never interpreted here: the emitter turns it into a * value, because that is where a default belongs (4.10). */ export declare function entry(signature: string, options?: EntryOptions): LibraryEntry; /** `bar `len - 1`` and its relatives, the commonest warmup shape in the library. */ export declare function fromLength(param: string, add: number, scale?: number): WarmupRule; /** A sum of lengths, as `bar `len + smoothK - 2`` and its relatives state it. */ export declare function fromLengths(params: readonly string[], add: number): WarmupRule; /** A warmup this module bounds below rather than reproducing the formula for. */ export declare function atLeastLength(params: readonly string[], add?: number): WarmupRule; export declare const DELAY_ZERO: WarmupRule; export declare const TOTAL: WarmupRule; export declare const DATA_DRIVEN: WarmupRule; export declare function delayBars(bars: number): WarmupRule; /** * Every entry of a name, in the order they were declared. * * A bare name may carry more than one signature (stdlib.md 2.2), so a lookup * answers with a list and the call site picks by arity and by argument type. * There is no run-time dispatch anywhere: the choice is made here, once. */ export type LibraryIndex = ReadonlyMap; export declare function indexOf(entries: readonly LibraryEntry[]): LibraryIndex; //# sourceMappingURL=library.d.ts.map