import type { IRNode } from '../types.js'; import type { ValueIR } from '../value-ir.js'; export type KernValue = { kind: 'null'; } | { kind: 'undefined'; } | { kind: 'boolean'; value: boolean; } | { kind: 'number'; value: number; } | { kind: 'string'; value: string; } | { kind: 'decimal'; canonical: string; } | { kind: 'array'; items: KernValue[]; } | { kind: 'record'; entries: Record; } | KernFunctionValue | KernBuiltinValue | KernClassValue | KernInstanceValue | KernBoundMethodValue | KernSuperValue; export interface KernFunctionValue { kind: 'function'; name?: string; params: RuntimeParam[]; body: IRNode[]; env: CoreRuntimeEnv; } export interface KernBuiltinValue { kind: 'builtin'; name: string; call: (args: KernValue[]) => KernValue; } export interface KernClassValue { kind: 'class'; name: string; node: IRNode; env: CoreRuntimeEnv; staticFields: Record; runtimeRootContext?: IRNode | readonly IRNode[]; } export interface KernInstanceValue { kind: 'instance'; classValue: KernClassValue; fields: Record; initializedClasses: Set; } export interface KernBoundMethodValue { kind: 'bound-method'; name: string; receiver: KernInstanceValue; methodNode: IRNode; ownerClass: KernClassValue; } export interface KernSuperValue { kind: 'super'; receiver: KernInstanceValue | KernClassValue; ownerClass: KernClassValue; mode: 'constructor' | 'method' | 'static'; } export interface RuntimeParam { name: string; type?: string; defaultExpr?: string; } export type CoreCompletion = { kind: 'normal'; value: KernValue; } | { kind: 'return'; value: KernValue; }; export interface CoreRuntimeResult { completion: CoreCompletion; env: CoreRuntimeEnv; } export interface CreateCoreRuntimeEnvOptions { globals?: Record; parent?: CoreRuntimeEnv; } export declare class CoreRuntimeEnv { readonly parent?: CoreRuntimeEnv | undefined; private readonly bindings; private runtimeRootContext?; constructor(parent?: CoreRuntimeEnv | undefined); define(name: string, value: KernValue): KernValue; assign(name: string, value: KernValue): KernValue; lookup(name: string): KernValue; has(name: string): boolean; /** Slice 1b — flatten this scope chain into the `bindings` Map the reference's * Decimal evaluators read (`env.bindings.get(name)`), so a bound decimal value * is a reusable operand: `let d = Decimal.of("1"); Decimal.add(d, Decimal.of("2"))`. * Outer scopes are collected first so inner scopes shadow them (lexical scoping). * Decimals become tagged `DecimalValue`s; scalars pass through so a non-decimal * operand fails the reference's "not a Decimal value" guard identically to a real * reference run. Complex kinds (function/class/…) are omitted — they can only ever * be a rejected decimal operand, where absence yields the same reject. */ collectDecimalEvalBindings(into?: Map): Map; child(): CoreRuntimeEnv; setRuntimeRootContext(root: IRNode | readonly IRNode[]): void; getRuntimeRootContext(): IRNode | readonly IRNode[] | undefined; } export declare const kNull: () => KernValue; export declare const kUndefined: () => KernValue; export declare const kBoolean: (value: boolean) => KernValue; export declare const kNumber: (value: number) => KernValue; export declare const kString: (value: string) => KernValue; export declare const DECIMAL_DOWNSTREAM_UNSUPPORTED = "KERN core runtime: Decimal downstream value semantics are not yet supported."; export declare function createCoreRuntimeEnv(options?: CreateCoreRuntimeEnvOptions): CoreRuntimeEnv; export declare function fromHostValue(value: unknown): KernValue; export declare function toHostValue(value: KernValue | undefined): unknown; export declare function kernTruthy(value: KernValue): boolean; export declare function evalCoreExpression(expr: string | ValueIR, env?: CoreRuntimeEnv): KernValue; export declare function runCoreRuntime(nodeOrNodes: IRNode | readonly IRNode[], env?: CoreRuntimeEnv): CoreRuntimeResult; export declare function callCoreFunction(fnNode: IRNode, args: KernValue[], env?: CoreRuntimeEnv): { value: KernValue; env: CoreRuntimeEnv; };