/** * The six values a running program can hold, `compiled-program.md` 3.1. * * Absence is `null`, a number is a number, a boolean is a boolean and a string * is a string, so four of the six tags are the ones the host language already * carries and cost nothing to test. The two that have no native tag, a colour * and a reference, are objects carrying a `tag` field, so `typeof` answers the * question for every value in one step and no value can be mistaken for * another. * * **Absence is never a number.** Section 3.4 is explicit that a not-a-number * sentinel would make absence propagate through arithmetic by accident, which * is the right answer for four operators and the wrong one for six, and would * turn `isNone` into a floating point comparison. `null` has none of those * properties, and the two rules the arithmetic actually needs, absence in * gives absence out and a non-finite result becomes absent, are then written * once each rather than hidden inside a representation. * * **A reference is an integer into the heap, not a pointer to an object.** * That choice is what makes section 6.2's hardest requirement free: a * checkpoint copies the heap table, every reference in a restored cell is the * same integer it was, and two cells that shared an array still share it. A * representation that put the object itself in the cell would have to work out * which cells pointed at the same object and rebuild the graph, and a restore * that deep copied each cell separately would silently turn one array into two. */ /** Red, green and blue as whole numbers 0 to 255, alpha as a number 0 to 1. */ export interface ColourValue { readonly tag: 'color'; readonly r: number; readonly g: number; readonly b: number; readonly a: number; } /** A handle into the object heap. Opaque to a script, and equal only to itself. */ export interface Reference { readonly tag: 'ref'; readonly id: number; } /** A value on the machine. */ export type Value = null | number | boolean | string | ColourValue | Reference; /** Absence, the value a script writes `none`. */ export declare const ABSENT: null; export declare function isAbsent(value: Value): value is null; export declare function isNumber(value: Value): value is number; export declare function isBool(value: Value): value is boolean; export declare function isString(value: Value): value is string; export declare function isColour(value: Value): value is ColourValue; export declare function isRef(value: Value): value is Reference; export declare function reference(id: number): Reference; /** * A number made safe to store, by the two rules of section 3.1 that hold at * every arithmetic result and every store. * * A result with no finite value is absent, checked here rather than at the end * of an expression so that `(1e308 * 10) / 10` is absent rather than depending * on where an engine happens to round. Negative zero becomes positive zero, so * nothing downstream can observe the sign of a zero and two engines cannot * differ over a minus in front of one. */ export declare function numberValue(x: number): Value; /** Normalise numeric zero at a store or identity result, preserving every other tag. */ export declare function storedValue(value: Value): Value; /** The name of a value's tag, for a diagnostic that has to say what it found. */ export declare function tagOf(value: Value): string; /** * Whole channels, and an alpha held to its range. * * `stdlib.md` 11.2 requires every call that computes a colour to round red, * green and blue with the language's own rounding, halves away from zero, * before it returns, so that the value model's invariant holds of every colour * and not only of a literal. */ export declare function colour(r: number, g: number, b: number, a: number): ColourValue; /** * Whether two values are equal under `EQ`, which is total: it always answers. * * Absent equals absent and nothing else. Two colours are equal when all four * channels match. Two references are equal when they are the same object, * which is `language.md` 9.3 and the reason `arrayEqual` exists in the library * for comparing contents. */ export declare function valuesEqual(a: Value, b: Value): boolean; //# sourceMappingURL=value.d.ts.map