/** * Values the compiler can work out before bar 0, and the folding that gets * there. * * Two parts of the format need this and nothing else does. A constant pool * entry is a value (`compiled-program.md` 2.9), and every declaration field is * written with the value its option resolved to, defaults included (2.3). So a * plot's colour, a study's precision and a table's corner all have to be a * value here or they cannot be carried at all. * * The one thing that is a field and is not a value is the reference form * `{ "input": "" }`, which is why it is a member of this union rather than * something a later stage substitutes. It may stand **in place of** a value and * may not take part in one: `opacity = dim` is carried, `opacity = dim * 2` has * nowhere in the format to live, and folding says so by refusing rather than by * inventing a number from the input's default. * * The colour arithmetic is here because `stdlib.md` 11.2 defines it exactly: * `fade(c, p)` is `withAlpha(c, (100 - p) / 100)`, and every call that computes * a colour rounds the three channels with the language's own rounding, halves * away from zero. Both are written out rather than approximated, because a * colour folded here and the same colour computed by an engine have to be the * same bits. */ import type { Argument, Call, Expression, NameReference } from '../ast/index.js'; import type { Colour, Field } from './program.js'; export type Value = { readonly kind: 'absent'; } | { readonly kind: 'bool'; readonly value: boolean; } | { readonly kind: 'number'; readonly value: number; } | { readonly kind: 'string'; readonly value: string; } | { readonly kind: 'colour'; readonly value: Colour; } | { readonly kind: 'array'; readonly values: readonly Value[]; } /** Carried into a declaration field as the reference of 2.3, never computed with. */ | { readonly kind: 'input'; readonly key: string; }; export declare const ABSENT: Value; export interface FoldEnvironment { /** What a bare name denotes before bar 0, or nothing when it denotes a bar. */ name(reference: NameReference): Value | undefined; /** A resolved call: its library name and its arguments in parameter order. */ call(call: Call): { readonly name: string; readonly args: readonly (Argument | undefined)[]; } | undefined; /** The input an `input()` call declares, as the reference that names it. */ input(call: Call): Value | undefined; } /** The language's own rounding, halves away from zero, `stdlib.md` 8.1. */ export declare function roundHalfAway(x: number): number; /** * The value an expression has before bar 0, or nothing when it has none. * * Nothing here reports a diagnostic. An expression the checker already accepted * as a compile-time constant and this refuses is a shape the format cannot * carry, and the caller is the one that knows which field it was going into. */ export declare function fold(expression: Expression, environment: FoldEnvironment): Value | undefined; /** * A folded value as a declaration field, `compiled-program.md` 2.3. * * Absence is null, because absence is what an argument a script named none for * resolves to and null is the effective value rather than a missing one. An * input is carried as its reference and is resolved away before bar 0. */ export declare function fieldOf(value: Value | undefined): Field; //# sourceMappingURL=values.d.ts.map