tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

runtime-session.ts (1720B)


      1 import type { ModuleStage } from './module-stage.js';
      2 import type { LocalModuleInput } from './local-modules.js';
      3 import { HaskellSession } from './haskell-session.js';
      4 import type { BundleHash } from './bundle.js';
      5 import type { Literal, OutputType, ValueView } from './codecs.js';
      6 import type { IOHost } from './io.js';
      7 import type { RuntimeStats } from './runtime-backends.js';
      8 // Coarse backend boundary. The page/driver never sees pointers, evaluator nodes,
      9 // internal IO tokens, or runtime-specific checkpoints. Implementations own their
     10 // private protocol; unsupported backends are never replaced by another.
     11 export interface RuntimeSession {
     12   readonly disposed: boolean;
     13   load(bytes: Uint8Array, hash: BundleHash): Promise<void>;
     14   compile(source: string, profileName?: string, localModules?: LocalModuleInput[]): Promise<string[]>;
     15   // Read-only native header inspection in an initialized compiler session.
     16   inspectModule(source: string): Promise<ModuleStage>;
     17   exportModule(): Promise<Uint8Array>;
     18   runDefinitionIO(name: string, output: OutputType, host: IOHost): Promise<ValueView>;
     19   probeIO(name: string): Promise<boolean>;
     20   inspectDefinition(name: string, output: OutputType): Promise<ValueView>;
     21   run(name: string, args: Literal[], output: OutputType, mode: 'pure' | 'io', host: IOHost): Promise<ValueView>;
     22   runExpression(source: string, output: OutputType, mode: 'pure' | 'io', host: IOHost): Promise<ValueView>;
     23   stats(): RuntimeStats;
     24   dispose(): void;
     25 }
     26 export async function createRuntimeSession(name: string | null, compiler: boolean): Promise<RuntimeSession> {
     27   if (name !== 'haskell-wasm') throw new Error('Unsupported runtime backend');
     28   return HaskellSession.create(compiler);
     29 }