@scriptc/types
v0.3.5
Published
Contract types for scriptc: type-only annotations (Int32, NoThrow, Immutable) that scriptc checks and optimizes, with no runtime semantics
Readme
@scriptc/types
Contract types for scriptc: type aliases with no meaning in TypeScript or Node.js that scriptc checks as extra promises. Import them with import type, which TypeScript erases, so Node.js never loads this package.
import type { Immutable, Int32, NoThrow } from "@scriptc/types";
const KEYWORDS: Immutable<Map<string, number>> = new Map([["const", 1]]);
class Token {
pos: Int32 = 0;
}
function isLetter(ch: number): NoThrow<boolean> {
return (ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90);
}Contracts
NoThrow<T>on a function's return type: the function never throws. Callers need no exception checks.Int32on a parameter, variable, class instance field or function result: every stored value is a signed 32-bit integer by construction (an integer literal in range, a bitwise result such asx | 0,Math.imul, anotherInt32, or arithmetic scriptc can bound). The slot is stored as a 32-bit integer.Immutable<T>on a parameter, variable, class instance field or function result: a deep read-only view, and no code writes to the value through any reference. A module constant built from literals becomes immortal data.Acyclicon a class (class C implements Acyclic), interface (interface I extends Acyclic) or object type alias (type T = Acyclic<{ ... }>): no chain of references can lead from such an object back to itself. Its objects carry no cycle-collector header.ProgramLifetimein a class'simplementsclause: instances of the class and its subclasses are never freed, so scriptc skips reference counting and cycle collection for them. Memory only: discarded instances are not reclaimed.
scriptc proves each contract or rejects the program with a diagnostic (SC7001-SC7008) that explains why it does not hold. A program that compiles behaves exactly as under Node.js. See https://scriptc.dev/docs/contracts.
