import type { SpecialExpressionType } from '../builtin'; import type { Arity } from '../builtin/interface'; import type { specialExpressionTypes } from '../builtin/specialExpressionTypes'; import type { FunctionType, NodeType, NodeTypes } from '../constants/constants'; import type { Context } from '../evaluator/interface'; import type { Any, Arr, Coll } from '../interface'; import type { ReservedSymbol } from '../tokenizer/reservedNames'; import type { SourceCodeInfo } from '../tokenizer/token'; import type { ATOM_SYMBOL, EFFECT_SYMBOL, FUNCTION_SYMBOL, REGEXP_SYMBOL } from '../utils/symbols'; export type EvaluatedFunction = [BindingTarget[], AstNode[], Context]; interface GenericDvalaFunction { [FUNCTION_SYMBOL]: true; sourceCodeInfo?: SourceCodeInfo; functionType: FunctionType; arity: Arity; } export interface RegularExpression { [REGEXP_SYMBOL]: true; sourceCodeInfo?: SourceCodeInfo; s: string; f: string; } /** Dotted DNS-style identifier for entities with public identity (effects, macros, modules). */ export type QualifiedName = string; export interface EffectRef { [EFFECT_SYMBOL]: true; name: QualifiedName; } /** Atom: a self-evaluating named constant, e.g. :ok, :error */ export interface Atom { [ATOM_SYMBOL]: true; name: string; } export interface UserDefinedFunction extends GenericDvalaFunction { functionType: 'UserDefined'; name: string | undefined; evaluatedfunction: EvaluatedFunction; docString: string; } export interface MacroFunction extends GenericDvalaFunction { functionType: 'Macro'; name: string | undefined; evaluatedfunction: EvaluatedFunction; docString: string; } export interface PartialFunction extends GenericDvalaFunction { functionType: 'Partial'; function: FunctionLike; params: Arr; placeholders: number[]; } export interface CompFunction extends GenericDvalaFunction { functionType: 'Comp'; params: Arr; } export interface ConstantlyFunction extends GenericDvalaFunction { functionType: 'Constantly'; value: Any; } export interface JuxtFunction extends GenericDvalaFunction { functionType: 'Juxt'; params: Arr; } export interface ComplementFunction extends GenericDvalaFunction { functionType: 'Complement'; function: FunctionLike; } export interface EveryPredFunction extends GenericDvalaFunction { functionType: 'EveryPred'; params: Arr; } export interface SomePredFunction extends GenericDvalaFunction { functionType: 'SomePred'; params: Arr; } export interface FNullFunction extends GenericDvalaFunction { functionType: 'Fnull'; function: FunctionLike; params: Arr; } export interface QualifiedMatcherFunction extends GenericDvalaFunction { functionType: 'QualifiedMatcher'; matchType: 'string' | 'regexp'; pattern: string; flags: string; } export interface NormalBuiltinFunction extends GenericDvalaFunction { functionType: 'Builtin'; normalBuiltinSymbolType: string; name: string; } export interface SpecialBuiltinFunction extends GenericDvalaFunction { functionType: 'SpecialBuiltin'; specialBuiltinSymbolType: typeof specialExpressionTypes['&&'] | typeof specialExpressionTypes['||'] | typeof specialExpressionTypes['array'] | typeof specialExpressionTypes['object'] | typeof specialExpressionTypes['recur'] | typeof specialExpressionTypes['??']; } export interface ModuleFunction extends GenericDvalaFunction { functionType: 'Module'; moduleName: string; functionName: string; } /** * A handler clause: maps an effect name to a body expression. * params are the binding targets for the effect's arguments. */ export interface HandlerClause { effectName: string; params: BindingTarget[]; body: AstNode[]; } /** * First-class handler value created by `handler...end`. * Contains named effect clauses and an optional transform clause. * When installed (via `h(-> body)` or `with h;`), provides algebraic effect handling * with resume/abort semantics. */ export interface HandlerFunction extends GenericDvalaFunction { functionType: 'Handler'; clauses: HandlerClause[]; clauseMap: Map; /** Transform clause: [paramBindingTarget, bodyExprs]. Defaults to identity. */ transform: [BindingTarget, AstNode[]] | null; /** If true, shallow handler — resume does NOT reinstall the handler around the continuation. */ shallow: boolean; /** Closure environment captured at handler creation. */ closureEnv: unknown; } /** * First-class resume function created when a handler clause is entered. * When called with a value, it resumes the continuation at the perform site * with the handler reinstalled (deep semantics). */ export interface ResumeFunction extends GenericDvalaFunction { functionType: 'Resume'; /** Reference to the HandlerClauseFrame that owns this resume. * Used to check one-shot guard and set resumed flag. */ clauseFrame: unknown; /** The handler to reinstall on resume (deep semantics). */ handler: HandlerFunction; /** Continuation from perform site up to the AlgebraicHandleFrame. */ performK: unknown; /** Handler environment for reinstallation. */ handlerEnv: unknown; } export type DvalaFunction = UserDefinedFunction | MacroFunction | NormalBuiltinFunction | SpecialBuiltinFunction | ModuleFunction | PartialFunction | CompFunction | ConstantlyFunction | JuxtFunction | ComplementFunction | EveryPredFunction | SomePredFunction | FNullFunction | QualifiedMatcherFunction | HandlerFunction | ResumeFunction; export type DvalaFunctionType = DvalaFunction['functionType']; export type FunctionLike = DvalaFunction | Coll | number; export type AstNode = [T, Payload, number]; export type SpreadNode = AstNode; export type NumberNode = AstNode; export type StringNode = AstNode; export type AtomNode = AstNode; export type TemplateStringNode = AstNode; export type ExpressionNode = NormalExpressionNode | SpecialExpressionNode | NumberNode | StringNode | AtomNode | TemplateStringNode; export type UserDefinedSymbolNode = AstNode; export type BuiltinSymbolNode = AstNode; export type SpecialSymbolNode = AstNode; export type SymbolNode = UserDefinedSymbolNode | BuiltinSymbolNode | SpecialSymbolNode; export type ReservedNode = AstNode; export type EffectNameNode = AstNode; export type SpecialExpressionNode = AstNode; /** * Formatting hints stored in Call node payloads. * Set at parse time to preserve authored syntactic form through formatting. */ export interface CallHints { /** True when authored as infix: `a foo b` rather than `foo(a, b)`. */ isInfix?: boolean; /** True when authored as pipe: `a |> b` rather than `b(a)`. */ isPipe?: boolean; } export type NormalExpressionNodeWithName = AstNode; export type NormalExpressionNodeExpression = AstNode; export type NormalExpressionNode = NormalExpressionNodeWithName | NormalExpressionNodeExpression; export declare const bindingTargetTypes: { readonly symbol: "symbol"; readonly rest: "rest"; readonly object: "object"; readonly array: "array"; readonly literal: "literal"; readonly wildcard: "wildcard"; }; export type BindingTargetType = typeof bindingTargetTypes[keyof typeof bindingTargetTypes]; type GenericTarget = [T, Payload, number]; export type SymbolBindingTarget = GenericTarget; export type RestBindingTarget = GenericTarget; export type ObjectBindingTarget = GenericTarget, AstNode | undefined]>; export type ArrayBindingTarget = GenericTarget; export type LiteralBindingTarget = GenericTarget; export type WildcardBindingTarget = GenericTarget; export type BindingTarget = SymbolBindingTarget | RestBindingTarget | ObjectBindingTarget | ArrayBindingTarget | LiteralBindingTarget | WildcardBindingTarget; export type BindingNode = AstNode; export interface SourceMapPosition { source: number; start: [number, number]; end: [number, number]; /** True for Sym/Builtin/Special/Reserved/Effect — never tracked by the evaluator's onNodeEval hook */ structuralLeaf?: boolean; } export interface SourceMap { sources: { path: string; content: string; }[]; positions: Map; } export declare function resolveSourceCodeInfo(nodeId: number, sourceMap: SourceMap | undefined): SourceCodeInfo | undefined; type AstBody = AstNode[]; /** Parsed effect declaration: effect @name(ArgType) -> RetType */ export interface EffectDeclarationInfo { argType: string; retType: string; } /** Parsed type alias: type Name = Body */ export interface TypeAliasInfo { params: string[]; body: string; } export interface Ast { body: AstBody; sourceMap?: SourceMap; /** Type annotations from source code, keyed by nodeId. Erased before evaluation. */ typeAnnotations?: Map; /** Effect declarations from source code. Erased before evaluation. */ effectDeclarations?: Map; /** Type alias declarations from source code. Erased before evaluation. */ typeAliases?: Map; } export {};