import { Type } from './type.js'; import { ReflectionOp } from '../type-spec/index.js'; import { ClassType } from '../core/index.js'; export type RuntimeStackEntry = Type | Object | (() => ClassType | Object) | string | number | boolean | bigint; export type Packed = (RuntimeStackEntry | string)[] & { __is?: (data: any) => boolean; } & { __type?: Type; } & { __unpack?: PackStruct; }; export declare class PackStruct { ops: ReflectionOp[]; stack: RuntimeStackEntry[]; constructor(ops?: ReflectionOp[], stack?: RuntimeStackEntry[]); } export declare function encodeOps(ops: ReflectionOp[]): string; /** * Pack a pack structure (op instructions + pre-defined stack) and create a encoded version of it. */ export declare function pack(packOrOps: PackStruct | ReflectionOp[]): Packed; export declare function unpack(pack: Packed): PackStruct; export declare function resolvePacked(type: Packed, args?: any[], options?: ReflectOptions): Type; /** * Computes a type of given object. This function caches the result on the object itself. * This is the slow path, using the full type virtual machine to resolve the type. * If you want to handle some fast paths (including cache), try using resolveReceiveType() instead. */ export declare function resolveRuntimeType(o: ClassType | Function | Packed | any, args?: any[], options?: ReflectOptions): Type; interface Frame { index: number; startIndex: number; variables: number; inputs: RuntimeStackEntry[]; previous?: Frame; mappedType?: Loop; distributiveLoop?: Loop; } declare class Loop { fromType: Type; private types; private i; constructor(fromType: Type); next(): Type | undefined; } interface Program { frame: Frame; active: boolean; stack: (RuntimeStackEntry | Type)[]; stackPointer: number; program: number; depth: number; initialStack: (RuntimeStackEntry | Type)[]; resultType: Type; ops: ReflectionOp[]; end: number; inputs: RuntimeStackEntry[]; resultTypes?: Type[]; started: number; typeParameters?: Type[]; previous?: Program; directReturn?: boolean; object?: ClassType | Function | Packed | any; } export interface ReflectOptions { /** * */ reuseCached?: boolean; inline?: boolean; typeName?: string; } /** * @reflection never */ export declare class Processor { static typeProcessor?: Processor; static get(): Processor; private cache; /** * Linked list of programs to execute. For each external call to external program will this be changed. */ protected program: Program; reflect(object: ClassType | Function | Packed | any, inputs?: RuntimeStackEntry[], options?: ReflectOptions): Type; _reflect(object: ClassType | Function | Packed | any, inputs?: RuntimeStackEntry[], options?: ReflectOptions): Type; run(ops: ReflectionOp[], initialStack: RuntimeStackEntry[], inputs?: RuntimeStackEntry[], object?: ClassType | Function | Packed | any): Type; runProgram(program: Program): Type; /** * Semantic is important here: This triggers true only for the very last op of a program. * If it is checked in OP inline then it could be true or false: * * type t = T; => false since we have nominal past the inline op * typeOf() => true since we have no nominal past the inline op */ protected isEnded(): boolean; /** * Runs all scheduled programs until termination. */ protected loop(until?: Program): Type | RuntimeStackEntry; private handleTuple; private handleIntersection; private handleDistribute; private handleIndexAccess; private handleKeyOf; private handleMappedType; private handleTemplateLiteral; protected push(entry: RuntimeStackEntry, program?: Program): void; protected pop(): RuntimeStackEntry; protected pushFrame(): void; protected popFrame(): RuntimeStackEntry[]; /** * Create a new stack frame with the calling convention. */ protected call(program: number, jumpBackTo?: number): void; /** * Removes the stack frame, and puts the latest entry on the stack. */ protected returnFrame(): void; protected pushType(type: Type): void; protected eatParameter(): RuntimeStackEntry; } export declare function typeInfer(value: any): Type; export declare function getEnumType(values: any[]): Type; export {}; export declare type __ΩRuntimeStackEntry = any[]; export declare type __ΩPacked = any[]; export declare type __ΩReflectOptions = any[];