/** * Standard Library for Elo * * Provides a type-based dispatch system for function implementations. * Each target compiler (JS, Ruby, SQL) defines its own implementations * that are looked up by function name and argument types. */ import { EloType } from "./types"; import { IRExpr } from "./ir"; /** * A function signature: name + argument types */ export interface FunctionSignature { name: string; argTypes: EloType[]; } /** * Create a signature key for lookup * e.g., "add:int,int" or "neg:float" */ export declare function signatureKey(name: string, argTypes: EloType[]): string; /** * Format a function signature for user-friendly error messages * e.g., "foo(Int, String)" or "upper(Any)" */ export declare function formatSignature(name: string, argTypes: EloType[]): string; /** * Generate all generalizations of argument types by progressively replacing * concrete types with 'any'. Returns type arrays in order from most specific * to most general. * * For [int, float]: returns [int,float], [any,float], [int,any], [any,any] * Types that are already 'any' don't generate additional combinations. */ export declare function typeGeneralizations(argTypes: EloType[]): EloType[][]; /** * Context passed to emitters for recursive emission */ export interface EmitContext { emit: (ir: IRExpr) => T; emitWithParens: (ir: IRExpr, parentOp: string, side: "left" | "right") => T; /** Track a required helper function (e.g., 'kAdd', 'kSub') */ requireHelper?: (name: string) => void; } /** * A function implementation that emits code for a specific signature */ export type FunctionEmitter = (args: IRExpr[], ctx: EmitContext) => T; /** * A library of function implementations for a target language */ export declare class StdLib { private implementations; private fallback; /** * Register an implementation for a specific signature */ register(name: string, argTypes: EloType[], emitter: FunctionEmitter): this; /** * Register a fallback for unmatched signatures */ registerFallback(handler: (name: string, args: IRExpr[], argTypes: EloType[], ctx: EmitContext) => T): this; /** * Look up an implementation by signature. * Tries progressively more general type signatures before giving up. * For example, for add(int, float), tries: * add(int, float) -> add(any, float) -> add(int, any) -> add(any, any) * * If any argument type is 'any' and no match is found through generalization, * falls back to finding any implementation with matching name and arity. * This allows functions like abs(any) to find abs(int) or abs(float). */ lookup(name: string, argTypes: EloType[]): FunctionEmitter | undefined; /** * Emit code for a function call */ emit(name: string, args: IRExpr[], argTypes: EloType[], ctx: EmitContext): T; } /** * Helper to create a binary operator emitter */ export declare function binaryOp(op: string, format: (left: T, right: T) => T): FunctionEmitter; /** * Helper to create a simple binary operator that just joins with the operator */ export declare function simpleBinaryOp(op: string): FunctionEmitter; /** * Helper to create a unary operator emitter */ export declare function unaryOp(format: (operand: T, needsParens: boolean) => T, needsParensCheck: (arg: IRExpr) => boolean): FunctionEmitter; /** * Helper for method call style: arg0.method(arg1) */ export declare function methodCall(method: string): FunctionEmitter; /** * Helper for nullary function (no args) */ export declare function nullary(value: T): FunctionEmitter; /** * Helper for unary method call: arg0.method() */ export declare function unaryMethod(method: string): FunctionEmitter; /** * Check if an IR expression is a binary operation (needs parens for postfix method calls) */ export declare function isBinaryOp(ir: IRExpr): boolean; /** * Helper for Ruby-style postfix method call that wraps binary expressions in parens. * Use for: arg0.method() where Ruby's precedence requires parens around binary ops. */ export declare function rubyMethod(method: string): FunctionEmitter; /** * Helper for function call style: fn(arg0, arg1, ...) */ export declare function fnCall(fnName: string): FunctionEmitter; /** * Helper for runtime helper function call (tracks the helper as required) * Used for dynamically-typed operations that need runtime support. */ export declare function helperCall(helperName: string): FunctionEmitter; //# sourceMappingURL=stdlib.d.ts.map