/** * The canonical encoding, `compiled-program.md` 2.14, and the one number writer. * * It exists so that a hash of a program means something: two compilers, in two * languages, handed the same source, produce the same bytes. So none of the * rules below is cosmetic, and none of them is this file's invention. * * - UTF-8, no byte order mark, no whitespace between tokens. * - Object keys sorted ascending by Unicode code point. Sorted rather than in * the specification's listed order, because a sort is a rule an emitter in any * language can follow without a table. * - A number is written by the rule of `language.md` 5.5, which is the same * rule for every number that becomes text anywhere in the language. * - A string escapes only the quote, the backslash and the code points below * 0x20, the last as `\u00XX` except for `\n`, `\r` and `\t`. */ import type { CompiledProgram } from './program.js'; /** * A number as text: the one writer. * * Two engines compare numbers as bits, but they compare text in a case file, an * expected column, a table cell and `text(x)`, so how a number becomes text has * to be one rule that both implement, and in this repository it has to be one * function. This is that function. `scripts/check-number-writer.mjs` reads * every file under `src` and refuses a conversion outside this module, so a * number cannot reach text by a host's default somewhere else and disagree with * this one by a plus sign. * * **The digits are the host's and the layout is not.** The shortest decimal * digit string that reads back as the same binary64 is what every host this * engine runs on produces, and what a second engine's host produces too; that * part is taken from the host's own shortest form. Where the two hosts part * company is the layout, when a value is written positionally and when with an * exponent, and how the exponent is spelled, so that half is written here from * the rule in `language.md` 5.5 and not left to the host. The rule is the one * the first host follows natively, minus the `+` it writes on a positive * exponent, and `spec/vectors/number-text.json` holds the boundary cases a * second engine checks itself against. */ export declare function canonicalNumber(value: number): string; export declare function canonicalString(value: string): string; export declare function canonicalise(value: unknown): string; /** * The two hashes a host records against a run. * * `source.hash` identifies the source and the hash of the canonical encoding * identifies the program, and they are two answers because a compiler change * that alters what a source compiles to has to be visible without the source * having changed at all. */ export declare function sourceHash(text: string): string; export declare function programHash(program: CompiledProgram): string; //# sourceMappingURL=canonical.d.ts.map