/** * expr-eval.ts — expression-ir.md の参照評価器(規範実装)。 * * 値モデル(../expression-ir.md §5): * int = bigint(i64 checked) / float = number(IEEE754, NaN/Inf は Failure) * / string / bool / null / arr / obj * * 規範ポイント(§6/§8 の罠に対応): * - int 演算は checked i64(オーバーフロー = Failure)。TS では BigInt で実装 * - 評価結果が NaN / ±Infinity になった時点で Failure * - mod は truncated division(符号は被除数。Python の % と異なる) * - 文字列比較は code point 順(TS ネイティブ `<` の UTF-16 順ではない) * - and / or / coalesce / cond は短絡評価(短絡側の Failure は発生しない) * - 未知オペレータは fail-closed */ import type { ErrorDetail } from "./plan.js"; export type Value = bigint | number | string | boolean | null | Value[] | { [k: string]: Value; }; export type Scope = Record; export type FailureCode = "INT_OVERFLOW" | "NAN_OR_INF" | "MOD_ZERO" | "PRECISION_LOSS" | "TYPE_MISMATCH" | "NULL_REF" | "MISSING_PROP" | "UNKNOWN_BINDING" | "UNKNOWN_OP" | "INVALID_NODE" | "INVALID_LITERAL" | "FORBIDDEN_KEY"; export declare class ExprFailure extends Error { code: FailureCode; /** * 構造化された回復可能ペイロード(scp-error.md「The Error Value」)。宣言型と実際の値の**両方**を * 持つ地点(handler 結果の outType 適合検査)で載る。該当が無ければ undefined。 */ detail?: ErrorDetail; constructor(code: FailureCode, message: string, detail?: ErrorDetail); } export declare const I64_MIN: bigint; export declare const I64_MAX: bigint; export declare function cmpCodePoints(a: string, b: string): -1 | 0 | 1; /** * 禁止キー(expression-ir.md §2.3/§8)。IR/JSON 由来の任意文字列キーからオブジェクトを * 構築するすべての経路で own key `"__proto__"` を fail-closed で拒否する。JS では * `out["__proto__"] = v` が prototype セッタを叩きキーが値として保持されない(TS では消える) * 一方、Python/Rust/Go は素直に保持するため、同一 IR が言語間で発散する(prototype * pollution の温床でもある)。全言語で `FORBIDDEN_KEY` に倒して一致させる。 */ export declare const FORBIDDEN_OBJECT_KEY = "__proto__"; /** add/sub/mul(int×int checked, float×float finite, 混在 TYPE_MISMATCH)。 */ export declare function arithCore(op: "add" | "sub" | "mul", a: Value, b: Value): Value; /** 単項マイナス。 */ export declare function negCore(a: Value): Value; /** div(常に float。0除算は NaN/Inf 規則で Failure)。 */ export declare function divCore(a: Value, b: Value): Value; /** mod(truncated、符号は被除数。int mod 0 は MOD_ZERO)。 */ export declare function modCore(a: Value, b: Value): Value; /** concat(n-ary。string のみ。arity 検査は呼び側)。 */ export declare function concatCore(parts: Value[]): Value; /** eq/ne。 */ export declare function eqNeCore(op: "eq" | "ne", a: Value, b: Value): Value; /** * lt/le/gt/ge(同一型 int/float/string、string は code-point 順)。 * * float は IEEE-754 の**半順序**: NaN が絡む対は「順序付け不能」(`null`)で、lt/le/gt/ge は * すべて false。int/string は全順序なので `null` にならない。半順序を 3 値に畳むと NaN が * 「等しい」に落ちて `le` と `ge` が同時に true になる(順序として非整合)うえ、生成物 * (go/rust typed-native は IEEE 演算子を直に出す)と結果が食い違う。 */ export declare function compareCore(op: "lt" | "le" | "gt" | "ge", a: Value, b: Value): Value; /** len(配列のみ)。 */ export declare function lenCore(a: Value): Value; /** bool ゲート(短絡系の native 制御フローが使う)。 */ export declare function requireBoolCore(v: Value, ctx: string): boolean; /** obj 構築(キー順・__proto__ は値評価前に FORBIDDEN_KEY)。entries は [key, 遅延評価 thunk]。 */ export declare function makeObjCore(entries: Array<[string, () => Value]>): Value; /** {int:"…"} リテラル。 */ export declare function intLitCore(s: string): Value; /** {float:n} リテラル。 */ export declare function floatLitCore(n: number): Value; /** bare number リテラル(§2.3 分類)。 */ export declare function numberLitCore(n: number): Value; /** ref/refOpt の native scope walk(optional=true は中間 null を null 伝播)。path は静的 string[]。 */ export declare function refCore(path: string[], scope: Scope, optional: boolean): Value; export declare function evaluate(node: unknown, scope?: Scope): Value; export declare function encodeValue(v: Value): unknown; //# sourceMappingURL=expr-eval.d.ts.map