/** * Variable Access and Mutation * * Handles variable access, mutation, and capture operations: * - Variable lookup with scope chain traversal * - Variable assignment with type checking * - Capture syntax (:> $name) * * LIMITATIONS: * - Property access chains ($data.field[0]) require access.ts * - Existence checks (.?field) require access.ts * - Default values ($data ?? default) require access.ts or control-flow.ts * * Interface requirements (from spec): * - setVariable(name, value, explicitType?, location?) -> void * - evaluateVariable(node) -> RillValue * - evaluateVariableAsync(node) -> Promise * - evaluateCapture(node, input) -> RillValue * * Depends on: * - EvalState: ctx; shared.ts: checkAborted(), getNodeLocation() * - context utilities: getVariable, hasVariable * * Extended by: * - access.ts: adds property chain evaluation to evaluateVariableAsync * * Error Handling: * - Undefined variables throw RuntimeError(RUNTIME_UNDEFINED_VARIABLE) * - Type mismatches throw RuntimeError(RUNTIME_TYPE_ERROR) * * @internal */ import type { ASTNode, VariableNode, CaptureNode, RillTypeName, SourceLocation, ExpressionNode } from '../../../../types.js'; import type { TypeStructure, RillValue } from '../../types/structures.js'; import type { EvalState } from '../state.js'; /** * Set a variable with type checking. * - First assignment locks the type (inferred or explicit) * - Subsequent assignments must match the locked type * - Explicit type annotation is validated against value type * - Cannot shadow outer scope variables (produces error) */ export declare function setVariable(s: EvalState, name: string, value: RillValue, explicitType?: RillTypeName | TypeStructure, location?: SourceLocation): void; /** * Evaluate variable access synchronously. * Handles bare variable references: $name or $. * * Note: This is a simplified synchronous version. The full implementation * with property access chains is in evaluateVariableAsync. */ export declare function evaluateVariable(s: EvalState, node: VariableNode): RillValue; /** * Apply bracket-index access (`receiver[indexExpr]`) to a list or dict * receiver, evaluating `indexExpr` as a pipe chain to obtain the index/key. * * Shared by the `$var[i]` access-chain path (evaluateVariableAsync) and the * postfix `expr[i]` method-chain path (evaluatePostfixExpr / the pipe-target * PostfixExpr case in core.ts) so both surfaces halt identically: * - List: negative-index normalization, out-of-bounds halts via RILL_R009. * - Dict: number/boolean keys resolve via the typed-key sidecar * (hasTypedKey/getTypedKey); string keys use an own-key gate so inherited * JS members never resolve as dict fields. * - Any other receiver type (including tuple and string) halts with * 'Cannot index ' via RILL_R002 — no element access is defined for * those types. * * `location` and `fn` are supplied by the caller so trace frames match the * calling context exactly (e.g. 'evaluateVariableAsync' for the $var[i] * path). */ export declare function applyBracketIndex(s: EvalState, receiver: RillValue, indexExpr: ExpressionNode, location: SourceLocation | undefined, fn: string): Promise; /** * Evaluate an existence check (`.?field`) against an already-resolved * access-chain value, returning whether the final path element exists * (and, when `typeRef` is set, whether it matches that type). * * Extracted from the inline `node.existenceCheck` branch of * evaluateVariableAsync so other access-chain evaluators can reuse the * same logic against a resolved receiver and node for location info. */ export declare function evaluateExistenceCheck(s: EvalState, value: RillValue, existenceCheck: NonNullable, node: ASTNode): Promise; /** * Evaluate variable access asynchronously. * Async variant that supports access chains ($.field, $var.field). * * Handles property access chains and default values. */ export declare function evaluateVariableAsync(s: EvalState, node: VariableNode): Promise; /** * Handle statement capture (public API wrapper). * Returns capture info if a capture occurred. */ export declare function handleCapture(s: EvalState, capture: CaptureNode | null, value: RillValue): Promise<{ name: string; value: RillValue; } | undefined>;