import * as IR from "../ir"; import { XorShift } from "../utils/xorshift"; import { Namespace, PassthroughNamespace } from "./namespaces"; import type { Pattern } from "./logic/unification"; import type { CrochetTrace } from "./tracing/trace"; export declare type Primitive = boolean | null | bigint | number; export declare enum Tag { NOTHING = 0, INTEGER = 1, FLOAT_64 = 2, TEXT = 3, TRUE = 4, FALSE = 5, INTERPOLATION = 6, LIST = 7, RECORD = 8, INSTANCE = 9, LAMBDA = 10, NATIVE_LAMBDA = 11, PARTIAL = 12, THUNK = 13, CELL = 14, TYPE = 15, ACTION = 16, ACTION_CHOICE = 17, UNKNOWN = 18, PROTECTED = 19 } export declare type PayloadType = { [Tag.NOTHING]: null; [Tag.INTEGER]: bigint; [Tag.FLOAT_64]: number; [Tag.TEXT]: string; [Tag.TRUE]: null; [Tag.FALSE]: null; [Tag.INTERPOLATION]: (string | CrochetValue)[]; [Tag.LIST]: CrochetValue[]; [Tag.RECORD]: Map; [Tag.INSTANCE]: CrochetValue[]; [Tag.PARTIAL]: CrochetPartial; [Tag.LAMBDA]: CrochetLambda; [Tag.NATIVE_LAMBDA]: CrochetNativeLambda; [Tag.THUNK]: CrochetThunk; [Tag.CELL]: CrochetCell; [Tag.TYPE]: CrochetType; [Tag.ACTION]: BoundAction; [Tag.ACTION_CHOICE]: ActionChoice; [Tag.UNKNOWN]: unknown; [Tag.PROTECTED]: CrochetProtectedValue; }; export interface ActionChoice { score: number; action: Action; env: Environment; } export interface BoundAction { action: Action; env: Environment; } export declare class CrochetValue { readonly tag: T; readonly type: CrochetType; readonly payload: PayloadType[T]; constructor(tag: T, type: CrochetType, payload: PayloadType[T]); equals(that: CrochetValue): boolean; hashCode(): number; } export declare class CrochetLambda { readonly env: Environment; readonly parameters: string[]; readonly body: IR.BasicBlock; constructor(env: Environment, parameters: string[], body: IR.BasicBlock); } export declare class CrochetNativeLambda { readonly arity: number; readonly handlers: HandlerStack; readonly fn: (...args: CrochetValue[]) => Machine; constructor(arity: number, handlers: HandlerStack, fn: (...args: CrochetValue[]) => Machine); } export declare class CrochetPartial { readonly module: CrochetModule; readonly name: string; readonly arity: number; constructor(module: CrochetModule, name: string, arity: number); } export declare class CrochetCell { value: CrochetValue; constructor(value: CrochetValue); } export declare class CrochetCapturedContext { readonly state: State; constructor(state: State); } export declare class CrochetThunk { readonly env: Environment; readonly body: IR.BasicBlock; value: CrochetValue | null; constructor(env: Environment, body: IR.BasicBlock); } export declare class CrochetProtectedValue { readonly value: CrochetValue; protected_by: Set; constructor(value: CrochetValue); } export declare class CrochetTrait { readonly module: CrochetModule | null; readonly name: string; readonly documentation: string; readonly meta: IR.Metadata | null; readonly implemented_by: Set; readonly protected_by: Set; constructor(module: CrochetModule | null, name: string, documentation: string, meta: IR.Metadata | null); } export declare class CrochetType { readonly module: CrochetModule | null; readonly name: string; readonly documentation: string; readonly parent: CrochetType | null; readonly fields: string[]; readonly types: CrochetTypeConstraint[]; readonly is_static: boolean; readonly meta: IR.Metadata | null; sealed: boolean; readonly layout: Map; readonly sub_types: CrochetType[]; readonly traits: Set; readonly protected_by: Set; constructor(module: CrochetModule | null, name: string, documentation: string, parent: CrochetType | null, fields: string[], types: CrochetTypeConstraint[], is_static: boolean, meta: IR.Metadata | null); } export declare class CrochetTypeConstraint { readonly type: CrochetType; readonly traits: CrochetTrait[]; constructor(type: CrochetType, traits: CrochetTrait[]); } export declare class CrochetCapability { readonly module: CrochetModule | null; readonly name: string; readonly documentation: string; readonly meta: IR.Metadata | null; readonly protecting: Set; constructor(module: CrochetModule | null, name: string, documentation: string, meta: IR.Metadata | null); get full_name(): string; } export declare function equals(left: CrochetValue, right: CrochetValue): boolean; export declare class CrochetCommand { readonly name: string; readonly arity: number; readonly branches: CrochetCommandBranch[]; readonly versions: CrochetCommandBranch[][]; constructor(name: string, arity: number); } export declare class CrochetCommandBranch { readonly module: CrochetModule; readonly env: Environment; readonly name: string; readonly documentation: string; readonly parameters: string[]; readonly types: CrochetTypeConstraint[]; readonly body: IR.BasicBlock; readonly meta: IR.Metadata | null; constructor(module: CrochetModule, env: Environment, name: string, documentation: string, parameters: string[], types: CrochetTypeConstraint[], body: IR.BasicBlock, meta: IR.Metadata | null); get arity(): number; } export declare enum NativeTag { NATIVE_SYNCHRONOUS = 0, NATIVE_MACHINE = 1 } export declare type Machine = Generator; export declare type NativePayload = { [NativeTag.NATIVE_SYNCHRONOUS]: (...args: CrochetValue[]) => CrochetValue; [NativeTag.NATIVE_MACHINE]: (...args: CrochetValue[]) => Machine; }; export declare class NativeFunction { readonly tag: T; readonly name: string; readonly pkg: CrochetPackage; readonly payload: NativePayload[T]; constructor(tag: T, name: string, pkg: CrochetPackage, payload: NativePayload[T]); } export declare class Metadata { readonly source: string; readonly table: Map; constructor(source: string, table: Map); } export declare class CrochetTest { readonly module: CrochetModule; readonly env: Environment; readonly title: string; readonly body: IR.BasicBlock; constructor(module: CrochetModule, env: Environment, title: string, body: IR.BasicBlock); } export declare class CrochetPrelude { readonly env: Environment; readonly body: IR.BasicBlock; constructor(env: Environment, body: IR.BasicBlock); } export declare class CrochetWorld { readonly commands: Namespace; readonly types: Namespace; readonly traits: Namespace; readonly definitions: Namespace>; readonly relations: Namespace>; readonly native_types: Namespace; readonly native_functions: Namespace>; readonly actions: Namespace; readonly contexts: Namespace; readonly capabilities: Namespace; readonly global_context: GlobalContext; readonly prelude: CrochetPrelude[]; readonly tests: CrochetTest[]; readonly packages: Map; } export declare class CrochetPackage { readonly world: CrochetWorld; readonly name: string; readonly filename: string; readonly types: PassthroughNamespace; readonly traits: PassthroughNamespace; readonly definitions: PassthroughNamespace; readonly relations: PassthroughNamespace; readonly native_functions: Namespace; readonly actions: PassthroughNamespace; readonly contexts: PassthroughNamespace; readonly capabilities: PassthroughNamespace; readonly dependencies: Set; readonly granted_capabilities: Set; constructor(world: CrochetWorld, name: string, filename: string); } export declare class CrochetModule { readonly pkg: CrochetPackage; readonly filename: string; readonly metadata: Metadata | null; readonly types: Namespace; readonly definitions: Namespace; readonly relations: Namespace; readonly actions: Namespace; readonly contexts: Namespace; readonly traits: Namespace; readonly open_prefixes: Set; constructor(pkg: CrochetPackage, filename: string, metadata: Metadata | null); } export declare enum RelationTag { CONCRETE = 0, PROCEDURAL = 1 } export declare type RelationPayload = { [RelationTag.CONCRETE]: ConcreteRelation; [RelationTag.PROCEDURAL]: ProceduralRelation; }; export declare class CrochetRelation { readonly tag: T; readonly name: string; readonly documentation: string; readonly payload: RelationPayload[T]; constructor(tag: T, name: string, documentation: string, payload: RelationPayload[T]); } export declare class ConcreteRelation { readonly module: CrochetModule; readonly meta: number; readonly type: TreeType; tree: Tree; constructor(module: CrochetModule, meta: number, type: TreeType, tree: Tree); } export declare class ProceduralRelation { readonly search: (env: Environment, patterns: Pattern[]) => Environment[]; readonly sample: null | ((env: Environment, patterns: Pattern[], size: number) => Environment[]); constructor(search: (env: Environment, patterns: Pattern[]) => Environment[], sample: null | ((env: Environment, patterns: Pattern[], size: number) => Environment[])); } export declare class Pair { readonly value: CrochetValue; tree: Tree; constructor(value: CrochetValue, tree: Tree); } export declare enum TreeTag { ONE = 0, MANY = 1, END = 2 } export declare type TreeType = TTOne | TTMany | TTEnd; export declare class TTOne { readonly next: TreeType; readonly tag = TreeTag.ONE; constructor(next: TreeType); } export declare class TTMany { readonly next: TreeType; readonly tag = TreeTag.MANY; constructor(next: TreeType); } export declare class TTEnd { readonly tag = TreeTag.END; } export declare const type_end: TTEnd; export declare type Tree = TreeOne | TreeMany | TreeEnd; export declare abstract class TreeBase { abstract tag: TreeTag; } export declare class TreeOne extends TreeBase { readonly type: TreeType; readonly tag = TreeTag.ONE; value: Pair | null; constructor(type: TreeType); } export declare class TreeMany extends TreeBase { readonly type: TreeType; readonly tag = TreeTag.MANY; table: CMap; constructor(type: TreeType); } export declare class TreeEnd extends TreeBase { readonly tag = TreeTag.END; constructor(); } export declare const tree_end: TreeEnd; export declare class Action { readonly type: CrochetType; readonly meta: number; readonly module: CrochetModule; readonly name: string; readonly documentation: string; readonly actor_type: CrochetTypeConstraint; readonly self_parameter: string; readonly predicate: IR.Predicate; readonly rank_function: IR.BasicBlock; readonly body: IR.BasicBlock; readonly fired: Set>; constructor(type: CrochetType, meta: number, module: CrochetModule, name: string, documentation: string, actor_type: CrochetTypeConstraint, self_parameter: string, predicate: IR.Predicate, rank_function: IR.BasicBlock, body: IR.BasicBlock); } export declare class When { readonly meta: number; readonly module: CrochetModule; readonly documentation: string; readonly predicate: IR.Predicate; readonly body: IR.BasicBlock; constructor(meta: number, module: CrochetModule, documentation: string, predicate: IR.Predicate, body: IR.BasicBlock); } export declare type Context = CrochetContext | GlobalContext; export declare enum ContextTag { LOCAL = 0, GLOBAL = 1 } export declare class GlobalContext { readonly tag = ContextTag.GLOBAL; readonly actions: Action[]; readonly events: When[]; } export declare class CrochetContext { readonly meta: number; readonly module: CrochetModule; readonly name: string; readonly documentation: string; readonly tag = ContextTag.LOCAL; readonly actions: Action[]; readonly events: When[]; constructor(meta: number, module: CrochetModule, name: string, documentation: string); } export declare class SimulationSignal { readonly meta: number; readonly name: string; readonly parameters: string[]; readonly body: IR.BasicBlock; readonly module: CrochetModule; constructor(meta: number, name: string, parameters: string[], body: IR.BasicBlock, module: CrochetModule); } export declare class SimulationState { readonly state: State; readonly module: CrochetModule; readonly env: Environment; readonly random: XorShift; readonly actors: CrochetValue[]; readonly context: Context; readonly goal: IR.SimulationGoal; readonly signals: Namespace; rounds: bigint; acted: Set>; turn: CrochetValue | null; constructor(state: State, module: CrochetModule, env: Environment, random: XorShift, actors: CrochetValue[], context: Context, goal: IR.SimulationGoal, signals: Namespace); } export declare class Environment { readonly parent: Environment | null; readonly raw_receiver: CrochetValue | null; readonly raw_module: CrochetModule | null; readonly raw_continuation: CrochetActivation | null; readonly bindings: Map>; constructor(parent: Environment | null, raw_receiver: CrochetValue | null, raw_module: CrochetModule | null, raw_continuation: CrochetActivation | null); define(name: string, value: CrochetValue): boolean; has(name: string): boolean; try_lookup(name: string): CrochetValue | null; } export declare class State { readonly universe: Universe; activation: Activation; readonly random: XorShift; constructor(universe: Universe, activation: Activation, random: XorShift); } export declare class HandlerStack { readonly parent: HandlerStack | null; readonly handlers: Handler[]; activation: CrochetActivation | null; constructor(parent: HandlerStack | null, handlers: Handler[]); } export declare class Handler { readonly guard: CrochetType; readonly parameters: string[]; readonly env: Environment; readonly body: IR.BasicBlock; constructor(guard: CrochetType, parameters: string[], env: Environment, body: IR.BasicBlock); } export declare enum ContinuationTag { RETURN = 0, DONE = 1, TAP = 2 } export declare type Continuation = ContinuationDone | ContinuationReturn | ContinuationTap; export declare class ContinuationReturn { readonly tag = ContinuationTag.RETURN; } export declare class ContinuationDone { readonly tag = ContinuationTag.DONE; } export declare class ContinuationTap { readonly saved_state: State; readonly continuation: (previous: State, state: State, value: CrochetValue) => State; readonly tag = ContinuationTag.TAP; constructor(saved_state: State, continuation: (previous: State, state: State, value: CrochetValue) => State); } export declare const _done: ContinuationDone; export declare const _return: ContinuationReturn; export declare enum ActivationTag { CROCHET_ACTIVATION = 0, NATIVE_ACTIVATION = 1 } export declare type Activation = CrochetActivation | NativeActivation; export interface IActivation { tag: ActivationTag; parent: Activation | null; continuation: Continuation; handlers: HandlerStack; } export declare type ActivationLocation = CrochetLambda | CrochetCommandBranch | CrochetThunk | CrochetPrelude | CrochetTest | NativeFunction | SimulationSignal | null; export declare class CrochetActivation implements IActivation { readonly parent: Activation | null; readonly location: ActivationLocation; readonly env: Environment; readonly continuation: Continuation; readonly handlers: HandlerStack; block: IR.BasicBlock; readonly tag = ActivationTag.CROCHET_ACTIVATION; stack: CrochetValue[]; block_stack: [number, IR.BasicBlock][]; private _return; instruction: number; constructor(parent: Activation | null, location: ActivationLocation, env: Environment, continuation: Continuation, handlers: HandlerStack, block: IR.BasicBlock); get current(): IR.Op | null; next(): void; get return_value(): CrochetValue | null; set_return_value(value: CrochetValue): void; push_block(b: IR.BasicBlock): void; pop_block(): void; } export declare enum NativeSignalTag { INVOKE = 0, APPLY = 1, AWAIT = 2, EVALUATE = 3, JUMP = 4, TRANSCRIPT_WRITE = 5, MAKE_CLOSURE = 6, CURRENT_ACTIVATION = 7, CURRENT_UNIVERSE = 8 } export declare type NativeSignal = NSInvoke | NSApply | NSAwait | NSEvaluate | NSJump | NSTranscriptWrite | NSMakeClosure | NSCurrentActivation | NSCurrentUniverse; export declare abstract class NSBase { } export declare class NSInvoke extends NSBase { readonly name: string; readonly args: CrochetValue[]; readonly tag = NativeSignalTag.INVOKE; constructor(name: string, args: CrochetValue[]); } export declare class NSApply extends NSBase { readonly fn: CrochetValue; readonly args: CrochetValue[]; readonly tag = NativeSignalTag.APPLY; constructor(fn: CrochetValue, args: CrochetValue[]); } export declare class NSMakeClosure extends NSBase { readonly arity: number; readonly fn: (...args: CrochetValue[]) => Machine; readonly tag = NativeSignalTag.MAKE_CLOSURE; constructor(arity: number, fn: (...args: CrochetValue[]) => Machine); } export declare class NSCurrentActivation extends NSBase { readonly tag = NativeSignalTag.CURRENT_ACTIVATION; } export declare class NSCurrentUniverse extends NSBase { readonly tag = NativeSignalTag.CURRENT_UNIVERSE; } export declare class NSAwait extends NSBase { readonly promise: Promise; readonly tag = NativeSignalTag.AWAIT; constructor(promise: Promise); } export declare class NSEvaluate extends NSBase { readonly env: Environment; readonly block: IR.BasicBlock; readonly tag = NativeSignalTag.EVALUATE; constructor(env: Environment, block: IR.BasicBlock); } export declare class NSJump extends NSBase { readonly activation: (parent: Activation) => Activation; readonly tag = NativeSignalTag.JUMP; constructor(activation: (parent: Activation) => Activation); } export declare class NSTranscriptWrite extends NSBase { readonly tag_name: string; readonly message: CrochetValue | string; readonly tag = NativeSignalTag.TRANSCRIPT_WRITE; constructor(tag_name: string, message: CrochetValue | string); } export declare type NativeLocation = NativeFunction | null; export declare class NativeActivation implements IActivation { readonly parent: Activation | null; readonly location: NativeLocation; readonly env: Environment; readonly routine: Machine; readonly handlers: HandlerStack; readonly continuation: Continuation; readonly tag = ActivationTag.NATIVE_ACTIVATION; constructor(parent: Activation | null, location: NativeLocation, env: Environment, routine: Machine, handlers: HandlerStack, continuation: Continuation); } export declare class Universe { readonly trace: CrochetTrace; readonly world: CrochetWorld; readonly random: XorShift; readonly types: { Any: CrochetType; Unknown: CrochetType; Protected: CrochetType; Nothing: CrochetType; True: CrochetType; False: CrochetType; Integer: CrochetType; Float: CrochetType; UnsafeArbitraryText: CrochetType; UntrustedText: CrochetType; Text: CrochetType; StaticText: CrochetType; DynamicText: CrochetType; Interpolation: CrochetType; Function: CrochetType[]; NativeFunctions: CrochetType[]; Thunk: CrochetType; Record: CrochetType; List: CrochetType; Enum: CrochetType; Type: CrochetType; Cell: CrochetType; Action: CrochetType; ActionChoice: CrochetType; Effect: CrochetType; Skeleton: { Node: CrochetType; Name: CrochetType; Literal: CrochetType; Dynamic: CrochetType; List: CrochetType; Interpolation: CrochetType; }; }; readonly type_cache: Map; readonly static_type_cache: Map>; readonly registered_instances: Map[]>; readonly nothing: CrochetValue; readonly true: CrochetValue; readonly false: CrochetValue; readonly integer_cache: CrochetValue[]; readonly float_cache: CrochetValue[]; readonly trusted_base: Set; constructor(trace: CrochetTrace, world: CrochetWorld, random: XorShift, types: { Any: CrochetType; Unknown: CrochetType; Protected: CrochetType; Nothing: CrochetType; True: CrochetType; False: CrochetType; Integer: CrochetType; Float: CrochetType; UnsafeArbitraryText: CrochetType; UntrustedText: CrochetType; Text: CrochetType; StaticText: CrochetType; DynamicText: CrochetType; Interpolation: CrochetType; Function: CrochetType[]; NativeFunctions: CrochetType[]; Thunk: CrochetType; Record: CrochetType; List: CrochetType; Enum: CrochetType; Type: CrochetType; Cell: CrochetType; Action: CrochetType; ActionChoice: CrochetType; Effect: CrochetType; Skeleton: { Node: CrochetType; Name: CrochetType; Literal: CrochetType; Dynamic: CrochetType; List: CrochetType; Interpolation: CrochetType; }; }); make_integer(x: bigint): CrochetValue; make_float(x: number): CrochetValue; make_text(x: string): CrochetValue; } export declare class CMap { private _types; private slow_entries; private table; get(key: CrochetValue): V | undefined; private get_slow; has(key: CrochetValue): boolean; set(key: CrochetValue, value: V): void; private set_slow; delete(key: CrochetValue): void; private delete_slow; entries(): Generator<[CrochetValue, V]>; values(): Generator; keys(): Generator, void, unknown>; private remember_type; private materialise_key; get size(): number; }