tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

runtime-session.ts (1808B)


      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   run(name: string, args: Literal[], output: OutputType, mode: 'pure' | 'io', host: IOHost): Promise<ValueView>;
     19   runExpression(source: string, output: OutputType, mode: 'pure' | 'io', host: IOHost): Promise<ValueView>;
     20   stats(): RuntimeStats;
     21   dispose(): void;
     22 }
     23 export async function createRuntimeSession(name: string | null, compiler: boolean): Promise<RuntimeSession> {
     24   if (name === 'zig-wasm') {
     25     const module = await import(new URL('../runtime/zig/site-session.mjs', import.meta.url).href) as { create(options: { base: URL; compiler: boolean }): Promise<RuntimeSession> };
     26     return module.create({ base: new URL('../', import.meta.url), compiler });
     27   }
     28   if (name !== 'haskell-wasm') throw new Error('Unsupported runtime backend');
     29   return HaskellSession.create(compiler);
     30 }