tricu

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

execution.ts (1762B)


      1 import type { Budget, CollectionPolicy } from './graph.js';
      2 // Execution has no application node/work/frame ceilings. Browser memory remains
      3 // finite; Stop terminates the owning Worker. GC thresholds are not budgets.
      4 export const BROWSER_BUDGET: Readonly<Budget> = Object.freeze({ nodes: Infinity, fuel: Infinity, stack: Infinity });
      5 export const PACKAGE_LOAD_MS = 60_000;
      6 // Export is bounded transport/rendering, not program execution.
      7 export const EXPORT_ACTIVE_MS = 120_000;
      8 export const EXECUTION_COLLECTION = Object.freeze({ threshold: 250_000 });
      9 export const PACKAGE_COLLECTION = Object.freeze({ threshold: 100_000 });
     10 export function collectionPolicy(budget: Readonly<Budget>, threshold: number = EXECUTION_COLLECTION.threshold): CollectionPolicy | undefined {
     11   return budget.nodes < 2 ? undefined : { threshold: Math.min(threshold, budget.nodes) };
     12 }
     13 
     14 export type Operation = 'catalogue' | 'loading' | 'compiling' | 'running' | 'exporting' | 'downloading';
     15 const operationLabels: Readonly<Record<Operation, string>> = {
     16   catalogue: 'Program catalogue loading', loading: 'Package loading',
     17   compiling: 'Draft compilation', running: 'Program execution',
     18   exporting: 'Definition export', downloading: 'Bundle download',
     19 };
     20 export function operationFailure(operation: Operation | undefined, message: string): string {
     21   return operation ? `${operationLabels[operation]} failed: ${message}` : message;
     22 }
     23 export function operationTimeout(operation: Operation): string {
     24   return operation === 'loading' || operation === 'downloading' || operation === 'catalogue'
     25     ? `${operationLabels[operation]} timed out. The deadline includes transfer and processing time; try again.`
     26     : `${operationLabels[operation]} stopped: active time limit exceeded.`;
     27 }