@cobol-ts/cel-implementation 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +76 -5
  2. package/dist/src/cel.access.d.ts +12 -0
  3. package/dist/src/cel.access.js +281 -0
  4. package/dist/src/cel.access.js.map +1 -0
  5. package/dist/src/cel.access.spec.d.ts +1 -0
  6. package/dist/src/cel.access.spec.js +30 -0
  7. package/dist/src/cel.access.spec.js.map +1 -0
  8. package/dist/src/cel.collection.d.ts +12 -0
  9. package/dist/src/cel.collection.index.d.ts +8 -0
  10. package/dist/src/cel.collection.index.js +59 -0
  11. package/dist/src/cel.collection.index.js.map +1 -0
  12. package/dist/src/cel.collection.index.spec.d.ts +1 -0
  13. package/dist/src/cel.collection.index.spec.js +47 -0
  14. package/dist/src/cel.collection.index.spec.js.map +1 -0
  15. package/dist/src/cel.collection.js +273 -0
  16. package/dist/src/cel.collection.js.map +1 -0
  17. package/dist/src/cel.collection.spec.d.ts +1 -0
  18. package/dist/src/cel.collection.spec.js +78 -0
  19. package/dist/src/cel.collection.spec.js.map +1 -0
  20. package/dist/src/cel.compile.d.ts +5 -16
  21. package/dist/src/cel.compile.diagnostics.spec.d.ts +1 -0
  22. package/dist/src/cel.compile.diagnostics.spec.js +60 -0
  23. package/dist/src/cel.compile.diagnostics.spec.js.map +1 -0
  24. package/dist/src/cel.compile.js +17 -1056
  25. package/dist/src/cel.compile.js.map +1 -1
  26. package/dist/src/cel.compile.spec.js +1 -35
  27. package/dist/src/cel.compile.spec.js.map +1 -1
  28. package/dist/src/cel.compile.types.d.ts +64 -0
  29. package/dist/src/cel.compile.types.js +3 -0
  30. package/dist/src/cel.compile.types.js.map +1 -0
  31. package/dist/src/cel.evaluate.d.ts +3 -0
  32. package/dist/src/cel.evaluate.js +23 -0
  33. package/dist/src/cel.evaluate.js.map +1 -0
  34. package/dist/src/cel.evaluate.spec.d.ts +1 -0
  35. package/dist/src/cel.evaluate.spec.js +52 -0
  36. package/dist/src/cel.evaluate.spec.js.map +1 -0
  37. package/dist/src/cel.frame.d.ts +18 -0
  38. package/dist/src/cel.frame.js +48 -0
  39. package/dist/src/cel.frame.js.map +1 -0
  40. package/dist/src/cel.frame.spec.d.ts +1 -0
  41. package/dist/src/cel.frame.spec.js +53 -0
  42. package/dist/src/cel.frame.spec.js.map +1 -0
  43. package/dist/src/cel.interpreter.d.ts +15 -0
  44. package/dist/src/cel.interpreter.js +82 -0
  45. package/dist/src/cel.interpreter.js.map +1 -0
  46. package/dist/src/cel.interpreter.spec.d.ts +1 -0
  47. package/dist/src/cel.interpreter.spec.js +26 -0
  48. package/dist/src/cel.interpreter.spec.js.map +1 -0
  49. package/dist/src/cel.literal.types.d.ts +26 -0
  50. package/dist/src/cel.literal.types.js +80 -0
  51. package/dist/src/cel.literal.types.js.map +1 -0
  52. package/dist/src/cel.literal.types.spec.d.ts +1 -0
  53. package/dist/src/cel.literal.types.spec.js +41 -0
  54. package/dist/src/cel.literal.types.spec.js.map +1 -0
  55. package/dist/src/cel.literals.d.ts +6 -0
  56. package/dist/src/cel.literals.js +284 -0
  57. package/dist/src/cel.literals.js.map +1 -0
  58. package/dist/src/cel.literals.spec.d.ts +1 -0
  59. package/dist/src/cel.literals.spec.js +289 -0
  60. package/dist/src/cel.literals.spec.js.map +1 -0
  61. package/dist/src/cel.materialise.d.ts +9 -0
  62. package/dist/src/cel.materialise.js +44 -0
  63. package/dist/src/cel.materialise.js.map +1 -0
  64. package/dist/src/cel.materialise.spec.d.ts +1 -0
  65. package/dist/src/cel.materialise.spec.js +21 -0
  66. package/dist/src/cel.materialise.spec.js.map +1 -0
  67. package/dist/src/cel.node.d.ts +18 -0
  68. package/dist/src/cel.node.js +64 -0
  69. package/dist/src/cel.node.js.map +1 -0
  70. package/dist/src/cel.numeric.d.ts +12 -0
  71. package/dist/src/cel.numeric.js +86 -0
  72. package/dist/src/cel.numeric.js.map +1 -0
  73. package/dist/src/cel.numeric.spec.d.ts +1 -0
  74. package/dist/src/cel.numeric.spec.js +37 -0
  75. package/dist/src/cel.numeric.spec.js.map +1 -0
  76. package/dist/src/cel.operations.js +9 -19
  77. package/dist/src/cel.operations.js.map +1 -1
  78. package/dist/src/cel.projection.d.ts +5 -0
  79. package/dist/src/cel.projection.js +56 -0
  80. package/dist/src/cel.projection.js.map +1 -0
  81. package/dist/src/cel.projection.spec.d.ts +1 -0
  82. package/dist/src/cel.projection.spec.js +37 -0
  83. package/dist/src/cel.projection.spec.js.map +1 -0
  84. package/dist/src/cel.root.types.d.ts +14 -0
  85. package/dist/src/cel.root.types.js +3 -0
  86. package/dist/src/cel.root.types.js.map +1 -0
  87. package/dist/src/cel.runner.d.ts +7 -0
  88. package/dist/src/cel.runner.js +77 -0
  89. package/dist/src/cel.runner.js.map +1 -0
  90. package/dist/src/cel.runner.spec.d.ts +1 -0
  91. package/dist/src/cel.runner.spec.js +56 -0
  92. package/dist/src/cel.runner.spec.js.map +1 -0
  93. package/dist/src/cel.scalar.d.ts +10 -0
  94. package/dist/src/cel.scalar.js +120 -0
  95. package/dist/src/cel.scalar.js.map +1 -0
  96. package/dist/src/cel.scalar.spec.d.ts +1 -0
  97. package/dist/src/cel.scalar.spec.js +25 -0
  98. package/dist/src/cel.scalar.spec.js.map +1 -0
  99. package/dist/src/cel.scope.d.ts +14 -0
  100. package/dist/src/cel.scope.js +88 -0
  101. package/dist/src/cel.scope.js.map +1 -0
  102. package/dist/src/cel.scope.spec.d.ts +1 -0
  103. package/dist/src/cel.scope.spec.js +47 -0
  104. package/dist/src/cel.scope.spec.js.map +1 -0
  105. package/package.json +9 -9
package/README.md CHANGED
@@ -10,17 +10,88 @@ This package compiles CEL syntax into reusable execution functions through the t
10
10
 
11
11
  **Public modules.** [cel.compile.ts](./src/cel.compile.ts), [cel.operations.ts](./src/cel.operations.ts).
12
12
 
13
- **Tests.** [cel.collections.spec.ts](src/cel.collections.spec.ts), [cel.compile.spec.ts](src/cel.compile.spec.ts), [cel.indexed.slot.spec.ts](src/cel.indexed.slot.spec.ts) (+3 more)
13
+ **Tests.** Public compiler integration and type-contract tests, with focused unit tests alongside internal implementations.
14
14
 
15
15
  **Related packages.** [@cobol-ts/cel](../../execution/cel/README.md) · [@cobol-ts/cel-access](../access/README.md).
16
16
 
17
+ ## Internal architecture
18
+
19
+ The public entry points in `cel.compile.ts` assemble the functional interpreter in
20
+ `cel.interpreter.ts`, parse the expression and construct the appropriate runner.
21
+ The package retains its existing public exports; internal modules are not public extension points.
22
+
23
+ | Module | Responsibility |
24
+ | --- | --- |
25
+ | `cel.compile.types.ts`, `cel.root.types.ts`, `cel.node.ts` | Compiled nodes, root contracts and type translation |
26
+ | `cel.scalar.ts`, `cel.numeric.ts`, `cel.operations.ts` | Scalar compilation, numeric rules and operation strategies |
27
+ | `cel.scope.ts` | Compilation-local lexical bindings and slot allocation |
28
+ | `cel.access.ts`, `cel.projection.ts` | Root, projection and indexed access compilation |
29
+ | `cel.collection.ts`, `cel.collection.index.ts` | Demand-driven collection operations and logical scalar indexing |
30
+ | `cel.literals.ts`, `cel.literal.types.ts` | Lazy literal compilation, lookup and contextual type inference |
31
+ | `cel.frame.ts`, `cel.runner.ts` | Evaluation scratch and reusable runner construction |
32
+ | `cel.materialise.ts` | Terminal shallow source-object rendering |
33
+ | `cel.evaluate.ts` | Public evaluation-boundary error policy |
34
+ | `cel.input.usage.ts` | Input dependency discovery |
35
+
36
+ Compilation resolves types, accessors and operations. Evaluation is synchronous and
37
+ uses the resulting closures; no compilation state is needed by a runner. Pure
38
+ utilities are imported directly, and variable policies and stateful capabilities
39
+ are supplied explicitly. The compiler does not create a graph session or own
40
+ caller records.
41
+
17
42
  ## Scalar expressions
18
43
 
19
44
  `compileCelExpression(expression, projection, access, functions?, roots?)` compiles a scalar result. Supported scalar kinds are `int`, `uint`, `double`, `string`, `bool`, and `null`. Integer arithmetic uses JavaScript `number` when the source policy selects it; `bigint` operations retain checked 64-bit semantics when required. Boolean `&&`/`||` and conditionals short-circuit; functions can be injected with declared argument and result kinds.
20
45
 
21
46
  The current TypeScript projection decoder supplies `number` for integer fields. The default CEL policy preserves that logical output; an injected PIC policy may request `bigint` conversion, in which case the decoder value is checked for safe integer precision first. Exact integers above the JavaScript safe-number range require a decoder that preserves that precision.
22
47
 
23
- A compiled expression exposes `run(record, indices)`. `evaluateCompiled` applies the `throw` or `continue` failure policy at the evaluation boundary. Continue mode reports diagnostics and never invents a value unless an explicitly typed fallback is provided. Floating-point `NaN` can be a valid result.
48
+ A compiled expression exposes `run(record, indices)` and `createRunner()`. Standalone calls use invocation-local scratch when required; a reusable runner owns its own scratch and is intended for sequential, non-reentrant use. Independent runners can evaluate the same compiled expression without sharing scratch. `evaluateCompiled` applies the `throw` or `continue` failure policy at the evaluation boundary. Continue mode reports diagnostics and never invents a value unless an explicitly typed fallback is provided. Floating-point `NaN` can be a valid result.
49
+
50
+ ## Lazy array and map literals
51
+
52
+ CEL supplies the syntax, not an obligation to reproduce eager CEL evaluation.
53
+ Every subexpression is compiled and statically validated. Only the expressions
54
+ needed to produce the requested result are evaluated at runtime.
55
+
56
+ ```cel
57
+ [1, 2, 1 / 0][0] // 1
58
+ [1, 2, 1 / 0].size() // 3
59
+ [1, 2, 1 / 0].exists(x, x == 1) // true
60
+ [input.credit, input.debit].max()
61
+ [1, 2, 3].filter(x, x > 1)[0] // 2
62
+ {"GB": 1, "FR": 2}[input.country]
63
+ {"credit": input.credit, "debit": input.debit}.credit
64
+ "A" in {"A": 1 / 0} // true
65
+ {"A": [1, 2], "B": [3, 4]}["B"][0] // 3
66
+ ```
67
+
68
+ Array literals contain homogeneous semantic types (number and bigint can
69
+ coexist for the same integer kind). Direct indexing is zero-based and skips
70
+ all unselected elements. Logical indexing after scalar `map` or `filter`
71
+ traverses only as far as the selected element. `in` stops after the first match.
72
+ Nested literal arrays and maps can be selected without materialising them.
73
+ Empty literal type holes are inferred from compatible sibling literals; absent
74
+ such context, array elements and map values default to the configured signed
75
+ integer representation, and map keys default to string. Empty membership is
76
+ false without evaluating the searched value. Indexing an empty or missing
77
+ collection entry throws when that lookup is demanded.
78
+
79
+ Maps accept homogeneous string, bool, int or uint keys and homogeneous value
80
+ types. Direct literal keys, including signed numeric literals, are indexed in
81
+ a compile-time lookup table; duplicate literal keys are rejected. Other key
82
+ expressions are evaluated from left to right until the first matching key.
83
+ Dynamic duplicate keys use first-match semantics. `size()` counts distinct
84
+ keys and never evaluates values; dynamic counting uses reusable runner scratch.
85
+ Integer keys are compared exactly across number and bigint representations.
86
+ No runtime map construction is needed for lookup or membership.
87
+
88
+ Literal lookup and size can execute without a frame when their operands do not
89
+ require scratch. Arrays are traversed through compiled element evaluators;
90
+ only terminal array results and nested computed list values are materialised.
91
+ The existing public scalar and array result APIs are unchanged: whole-map
92
+ materialisation, heterogeneous literal types, structured lexical bindings over
93
+ computed nested arrays/maps and general nested computed-list indexing remain
94
+ outside this contract. Source objects must be explicitly projected to values.
24
95
 
25
96
  ## Source-backed collections
26
97
 
@@ -53,7 +124,7 @@ const result=expression.run({orders:[{quantity:1},{quantity:3}]},[])
53
124
  // [30n]
54
125
  ```
55
126
 
56
- The per-evaluation frame owns the occurrence-index vector, reusable depth-specific index windows, and lexical scalar slots. Flat traversals do not allocate an index array or lambda **per consumed element**, and each evaluation owns its own mutable state. Nested traversal invocations still create callback closures, and nested maps returning lists allocate their result arrays. These remaining allocation costs should be benchmarked before claiming allocation-free execution or a throughput improvement.
127
+ The per-evaluation frame owns the occurrence-index vector, reusable depth-specific index windows, and lexical scalar slots. Flat traversals do not allocate an index array or lambda **per consumed element**, and each evaluation owns its own mutable state. Visitor callbacks and depth-specific index vectors are lazily allocated in reusable scratch. Nested maps returning lists and terminal collection materialisation deliberately allocate independent result arrays. Standalone framed `run()` calls create invocation-local scratch; reuse `createRunner()` for repeated record processing. No claim of allocation-free execution follows merely from these design choices.
57
128
 
58
129
  The compiled traversal is **demand-driven**, including across a `map` followed by `exists` or `all`. For instance, a later division by zero is not visited once `exists` has already found a match. This is intentionally different from strict eager-CEL `map` error semantics. An encountered runtime error throws and is caught at the record boundary; `ErrorsOr` is used during compilation, not for each element or node evaluation.
59
130
 
@@ -99,11 +170,11 @@ See `cel.rolling.window.spec.ts`, `cel.graph.rolling.read.spec.ts`, and
99
170
 
100
171
  ## Boundaries
101
172
 
102
- The parser is not a full CEL implementation. List/map literals, general computed-list indexing, `has`, and other receiver functions are deferred. `map` cannot return an unprojected source object collection directly; select scalar fields explicitly. Terminal object filtering can materialise only shallow scalar fields. The format-specific array compiler still determines which COBOL ODO placements are supported.
173
+ The parser is not a full CEL implementation. General structured computed-list indexing, whole-map result materialisation, `has`, and other receiver functions are deferred. `map` cannot return an unprojected source object collection directly; select scalar fields explicitly. Terminal object filtering can materialise only shallow scalar fields. The format-specific array compiler still determines which COBOL ODO placements are supported.
103
174
 
104
175
  Ordinary graph nodes still return scalars unless their canonical value type is rolling-window; no general array-valued graph-node results are introduced. `reduce`, `exists` and `all` can already be used as scalar graph expressions through the graph-runtime's source-access adapter.
105
176
 
106
- `cel.compile.spec.ts` tests scalar compilation and error policies; `cel.collections.spec.ts` exercises map/filter/reduce and the aggregation terminals, lexical scoping, short-circuiting, real nested JSONL and nested COBOL ODO decoding. `cel.compile.typetest.ts` checks typed scalar contracts. Run the repository's TypeScript and Jest suites for full validation.
177
+ `cel.compile.spec.ts` tests scalar compilation; `cel.evaluate.spec.ts` tests evaluation error policies; `cel.collections.spec.ts` exercises map/filter/reduce and the aggregation terminals, lexical scoping, short-circuiting, real nested JSONL and nested COBOL ODO decoding. `cel.literals.spec.ts`, `cel.literal.types.spec.ts` and `cel.collection.index.spec.ts` cover literal typing, lazy evaluation, lookup and recovery. `cel.compile.typetest.ts` checks typed scalar contracts. Run the repository's TypeScript and Jest suites for full validation.
107
178
 
108
179
  For COBOL fields, the CEL access adapter now selects numeric runtime
109
180
  representation through an injected PIC-to-CEL policy. The default follows the
@@ -0,0 +1,12 @@
1
+ import type { ValueType } from '@cobol-ts/value-types';
2
+ import { type ErrorsOr } from '@cobol-ts/errors';
3
+ import type { ProjectionAuthoring } from '@cobol-ts/cursor-loader-types';
4
+ import type { ScalarAccessCompiler, ArrayAccessCompiler } from '@cobol-ts/cel-access';
5
+ import type { IndexSelection, Node } from './cel.compile.types';
6
+ import type { ExtraRootTypes, ExtraRootReaders, ExtraRootRepresentations, ExtraRootValueTypes } from './cel.root.types';
7
+ import { type Frame } from './cel.frame';
8
+ import type { RequireFrame } from './cel.scope';
9
+ export declare function createMemberCompiler<R, P, I extends readonly number[]>(projection: ProjectionAuthoring, projectionTypes: Readonly<Record<string, ValueType>>, accesses: ScalarAccessCompiler<R, P, I> & Partial<ArrayAccessCompiler<R, P, I>>, roots: ExtraRootTypes, rootReaders: ExtraRootReaders<R>, rootRepresentations: ExtraRootRepresentations, rootValueTypes: ExtraRootValueTypes, preferNumberIntegers: boolean, requireFrame: RequireFrame): (target: Node<R, I>, name: string) => ErrorsOr<Node<R, I>>;
10
+ /** Rebind an indexed collection occurrence in an existing reusable frame. */
11
+ export declare function withSelection<R, I extends readonly number[], T>(selection: IndexSelection<R, I>, r: R, i: I, frame: Frame | undefined, run: (r: R, i: I, frame: Frame) => T): T;
12
+ export declare function compileIndex<R, I extends readonly number[]>(projection: ProjectionAuthoring, requireFrame: RequireFrame, target: Node<R, I>, index: Node<R, I>): ErrorsOr<Node<R, I>>;
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMemberCompiler = createMemberCompiler;
4
+ exports.withSelection = withSelection;
5
+ exports.compileIndex = compileIndex;
6
+ const ring_buffer_1 = require("@cobol-ts/ring-buffer");
7
+ const errors_1 = require("@cobol-ts/errors");
8
+ const cel_frame_1 = require("./cel.frame");
9
+ const cel_projection_1 = require("./cel.projection");
10
+ const cel_node_1 = require("./cel.node");
11
+ const cel_numeric_1 = require("./cel.numeric");
12
+ const typeOf = (t) => t === 'integer' ? 'int' : t === 'float' ? 'double' : 'string';
13
+ function createMemberCompiler(projection, projectionTypes, accesses, roots, rootReaders, rootRepresentations, rootValueTypes, preferNumberIntegers, requireFrame) {
14
+ return function compileMember(target, name) {
15
+ if (target.kind !== 'object')
16
+ return (0, errors_1.errors)(`Cannot select ${name} from ${target.kind}`);
17
+ if (target.root !== 'input' && target.root !== 'source')
18
+ return compileRootMember(target.root, target.path, name, roots, rootReaders, rootRepresentations, rootValueTypes, preferNumberIntegers, requireFrame);
19
+ return compileProjectedMember(target, name, projection, projectionTypes, accesses, preferNumberIntegers, requireFrame);
20
+ };
21
+ }
22
+ function rootRepresentation(rootRepresentations, preferNumberIntegers, root, name, kind) {
23
+ return rootRepresentations[root]?.[name] ??
24
+ (kind === 'int' || kind === 'uint' ? (['variables', 'acc'].includes(root) ? 'dynamic' : preferNumberIntegers ? 'number' : 'bigint') :
25
+ kind === 'double' ? 'number' : kind === 'bool' ? 'boolean' : kind === 'null' ? 'null' : 'string');
26
+ }
27
+ /** Rebind an indexed collection occurrence in an existing reusable frame. */
28
+ function withSelection(selection, r, i, frame, run) {
29
+ if (frame === undefined)
30
+ throw new Error('Missing index evaluation frame');
31
+ const raw = selection.index.run(r, i, frame);
32
+ if (typeof raw !== 'number' && typeof raw !== 'bigint')
33
+ throw new RangeError('Array index is not an integer');
34
+ const index = Number(raw);
35
+ const length = selection.length(r, i, frame);
36
+ if (!Number.isSafeInteger(index) || index < 0 || index >= length)
37
+ throw new RangeError('CEL array index out of bounds: ' + String(raw));
38
+ const before = frame.activeLength, old = frame.indices[selection.depth];
39
+ (0, cel_frame_1.setOccurrence)(frame, selection.depth, index);
40
+ try {
41
+ return run(r, i, frame);
42
+ }
43
+ finally {
44
+ frame.activeLength = before;
45
+ if (selection.depth < before)
46
+ frame.indices[selection.depth] = old;
47
+ }
48
+ }
49
+ function compileRootMember(root, parentPath, name, roots, rootReaders, rootRepresentations, rootValueTypes, preferNumberIntegers, requireFrame) {
50
+ const path = [...parentPath, name];
51
+ if (path.length !== 1)
52
+ return (0, errors_1.errors)(`Nested ${root} property ${path.join('.')} requires declared object types`);
53
+ const declaredType = rootValueTypes[root]?.[name];
54
+ if (declaredType?.kind === 'rolling-window') {
55
+ return compileRollingWindow(root, name, declaredType, rootReaders, requireFrame);
56
+ }
57
+ // Narrow the domain scalar once at the CEL boundary. Fixed-point
58
+ // descriptors cannot enter the CEL operation/representation algebra.
59
+ const celType = declaredType === undefined ? undefined :
60
+ (0, cel_node_1.isCelRootScalar)(declaredType) ? declaredType : undefined;
61
+ if (declaredType !== undefined && celType === undefined)
62
+ return (0, errors_1.errors)(`CEL ${root}.${name}: Fixed-point arithmetic is not supported yet`);
63
+ const kind = celType === undefined ? roots[root]?.[name] : (0, cel_node_1.elementKind)(celType);
64
+ if (kind === undefined)
65
+ return (0, errors_1.errors)(`Unknown CEL ${root} value ${name}`);
66
+ if (kind === 'object' || kind === 'list')
67
+ return (0, errors_1.errors)(`CEL ${root}.${name} requires a scalar value type`);
68
+ // Resolve both kind and representation from the same canonical descriptor.
69
+ const representation = celType?.javascriptType ?? rootRepresentation(rootRepresentations, preferNumberIntegers, root, name, kind);
70
+ const binding = rootReaders[root]?.(name, kind);
71
+ if (binding !== undefined && typeof binding !== 'function') {
72
+ if (!['now', 'prev'].includes(root) || !Number.isSafeInteger(binding.index) || binding.index < 0)
73
+ return (0, errors_1.errors)(`Invalid indexed accumulator binding for ${root}.${name}`);
74
+ const position = binding.index;
75
+ return (0, errors_1.value)((0, cel_node_1.scalar)(kind, (record) => {
76
+ const raw = record.acc.values[position];
77
+ if (!(0, cel_numeric_1.ensureRepresentedValue)(kind, representation, raw))
78
+ throw new TypeError(`CEL ${root}.${name} expected ${kind}`);
79
+ return raw;
80
+ }, representation));
81
+ }
82
+ if (typeof binding === 'function') {
83
+ const read = binding;
84
+ return (0, errors_1.value)((0, cel_node_1.scalar)(kind, (record) => {
85
+ const raw = read(record);
86
+ if (!(0, cel_numeric_1.ensureRepresentedValue)(kind, representation, raw))
87
+ throw new TypeError(`CEL ${root}.${name} expected ${kind}`);
88
+ return raw;
89
+ }, representation));
90
+ }
91
+ const storageRoot = root === 'now' || root === 'prev' ? 'acc' : root;
92
+ return (0, errors_1.value)((0, cel_node_1.scalar)(kind, (record) => {
93
+ const raw = record[storageRoot]?.[name];
94
+ if (!(0, cel_numeric_1.ensureRepresentedValue)(kind, representation, raw))
95
+ throw new TypeError(`CEL ${root}.${name} expected ${kind}`);
96
+ return raw;
97
+ }, representation));
98
+ }
99
+ function compileRollingWindow(root, name, declaredType, rootReaders, requireFrame) {
100
+ const element = declaredType.element;
101
+ if (!(0, cel_node_1.isCelRootScalar)(element))
102
+ return (0, errors_1.errors)(`CEL ${root}.${name}: Fixed-point arithmetic is not supported yet`);
103
+ const elementType = element;
104
+ const kind = (0, cel_node_1.elementKind)(elementType);
105
+ const binding = rootReaders[root]?.(name, kind);
106
+ if (binding !== undefined && typeof binding !== 'function' &&
107
+ (!['now', 'prev'].includes(root) || !Number.isSafeInteger(binding.index) || binding.index < 0))
108
+ return (0, errors_1.errors)(`Invalid indexed accumulator binding for ${root}.${name}`);
109
+ // Both accumulator layouts supply the same ring by reference.
110
+ // Select the reader once; no array projection or copy is required.
111
+ const read = typeof binding === 'function' ? binding :
112
+ binding !== undefined
113
+ ? record => record.acc.values[binding.index]
114
+ : record => record[root === 'now' || root === 'prev' ? 'acc' : root]?.[name];
115
+ const ring = (record) => {
116
+ const raw = read(record);
117
+ if (raw === null || typeof raw !== 'object' || !Array.isArray(raw.values))
118
+ throw new TypeError(`CEL ${root}.${name} expected rolling-window`);
119
+ const buffer = raw;
120
+ if (buffer.size !== declaredType.size || buffer.values.length !== declaredType.size + 1 ||
121
+ !Number.isSafeInteger(buffer.count) || buffer.count < 0 || buffer.count > buffer.size ||
122
+ !Number.isSafeInteger(buffer.excluded) || buffer.excluded < 0 || buffer.excluded > buffer.size ||
123
+ typeof buffer.hasExpired !== 'boolean' ||
124
+ (buffer.hasExpired && buffer.count !== buffer.size) ||
125
+ (!buffer.hasExpired && buffer.excluded !== 0))
126
+ throw new TypeError(`CEL ${root}.${name} has invalid rolling-window state`);
127
+ return buffer;
128
+ };
129
+ requireFrame();
130
+ const at = (record, _indices, _frame, index) => {
131
+ const item = (0, ring_buffer_1.get)(ring(record), index);
132
+ if (!(0, cel_numeric_1.ensureRepresentedValue)(kind, element.javascriptType, item))
133
+ throw new TypeError(`CEL ${root}.${name} expected ${kind} element at index ${index}`);
134
+ return item;
135
+ };
136
+ const iterate = (record, _indices, frame, visit) => {
137
+ const buffer = ring(record);
138
+ const count = (0, ring_buffer_1.length)(buffer);
139
+ for (let n = 0; n < count; n++) {
140
+ const item = (0, ring_buffer_1.get)(buffer, n);
141
+ if (!(0, cel_numeric_1.ensureRepresentedValue)(kind, element.javascriptType, item))
142
+ throw new TypeError(`CEL ${root}.${name} expected ${kind} element at index ${n}`);
143
+ if (!visit(item))
144
+ return false;
145
+ }
146
+ return true;
147
+ };
148
+ return (0, errors_1.value)({ kind: 'collection', type: { kind: 'array', element: elementType },
149
+ length: record => (0, ring_buffer_1.length)(ring(record)), at, iterate });
150
+ }
151
+ function compileProjectedMember(target, name, projection, projectionTypes, accesses, preferNumberIntegers, requireFrame) {
152
+ const path = [...target.path, name];
153
+ const defined = (0, cel_projection_1.resolveNode)(projection, path);
154
+ if (defined === undefined)
155
+ return (0, errors_1.errors)(`Unknown CEL projected field input.${path.join('.')}`);
156
+ if (defined.type === 'object')
157
+ return (0, errors_1.value)({ kind: 'object', root: 'input', path, selection: target.selection });
158
+ if (defined.type === 'array')
159
+ return compileProjectedArray(target, path, projection, projectionTypes, accesses, requireFrame);
160
+ return compileProjectedScalar(target, path, defined.type, projection, accesses, preferNumberIntegers);
161
+ }
162
+ function compileProjectedArray(target, path, projection, projectionTypes, accesses, requireFrame) {
163
+ if (accesses.compileArray === undefined)
164
+ return (0, errors_1.errors)('Array accessor required to compile a collection');
165
+ const result = accesses.compileArray(path);
166
+ if ((0, errors_1.isErrors)(result))
167
+ return result;
168
+ requireFrame();
169
+ const dimension = (0, cel_projection_1.arrayDepth)(projection, path) - 1;
170
+ const compiled = result.value;
171
+ const plainLength = (record, _indices, frame) => compiled.length(record, (0, cel_frame_1.windowAt)(frame, dimension));
172
+ const length = target.selection === undefined ? plainLength :
173
+ (record, indices, frame) => withSelection(target.selection, record, indices, frame, plainLength);
174
+ const plainIterate = (record, indices, frame, visit) => {
175
+ const count = plainLength(record, indices, frame);
176
+ const originalLength = frame.activeLength;
177
+ const previous = frame.indices[dimension];
178
+ try {
179
+ for (let n = 0; n < count; n++) {
180
+ (0, cel_frame_1.setOccurrence)(frame, dimension, n);
181
+ if (!visit(undefined))
182
+ return false;
183
+ }
184
+ return true;
185
+ }
186
+ finally {
187
+ frame.activeLength = originalLength;
188
+ if (dimension < originalLength)
189
+ frame.indices[dimension] = previous;
190
+ }
191
+ };
192
+ // A physical array below an indexed joined child must retain that
193
+ // outer occurrence for the entire traversal, not just length().
194
+ const iterate = target.selection === undefined ? plainIterate :
195
+ (record, indices, frame, visit) => {
196
+ const selection = target.selection;
197
+ const raw = selection.index.run(record, indices, frame);
198
+ const index = Number(raw);
199
+ if ((typeof raw !== 'number' && typeof raw !== 'bigint') ||
200
+ !Number.isSafeInteger(index) || index < 0 ||
201
+ index >= selection.length(record, indices, frame))
202
+ throw new RangeError('CEL array index out of bounds: ' + String(raw));
203
+ const originalLength = frame.activeLength;
204
+ const previous = frame.indices[selection.depth];
205
+ (0, cel_frame_1.setOccurrence)(frame, selection.depth, index);
206
+ try {
207
+ return plainIterate(record, indices, frame, visit);
208
+ }
209
+ finally {
210
+ frame.activeLength = originalLength;
211
+ if (selection.depth < originalLength)
212
+ frame.indices[selection.depth] = previous;
213
+ }
214
+ };
215
+ const collectionType = (0, cel_projection_1.projectionValueTypeAt)(projectionTypes, path);
216
+ if (collectionType.kind !== 'array')
217
+ return (0, errors_1.errors)('Expected an array value type for ' + path.join('.'));
218
+ if (!(0, cel_node_1.supportedCelValueType)(collectionType))
219
+ return (0, errors_1.errors)('Unsupported CEL collection element type at ' + path.join('.'));
220
+ return (0, errors_1.value)({ kind: 'collection', type: collectionType, sourcePath: path, length, iterate });
221
+ }
222
+ function compileProjectedScalar(target, path, fieldType, projection, accesses, preferNumberIntegers) {
223
+ const access = accesses.compileScalar(path);
224
+ if ((0, errors_1.isErrors)(access))
225
+ return access;
226
+ const compiled = access.value;
227
+ const kind = typeOf(fieldType);
228
+ const dimension = (0, cel_projection_1.arrayDepth)(projection, path);
229
+ const plainRead = (record, indices, frame) => compiled.read(record, (frame ? (0, cel_frame_1.windowAt)(frame, dimension) : indices));
230
+ const reader = target.selection === undefined ? plainRead :
231
+ (record, indices, frame) => withSelection(target.selection, record, indices, frame, plainRead);
232
+ // Explicit field storage takes precedence over the preference for CEL literals.
233
+ // The preference must not turn a PIC-width-selected bigint into a number.
234
+ const integerStorage = compiled.integerStorage ?? (preferNumberIntegers ? 'number' : 'bigint');
235
+ const representation = fieldType === 'integer'
236
+ ? integerStorage
237
+ : kind === 'double' ? 'number' : kind === 'bool' ? 'boolean' : 'string';
238
+ return (0, errors_1.value)((0, cel_node_1.scalar)(kind, (record, indices, frame) => {
239
+ const raw = reader(record, indices, frame);
240
+ if (fieldType !== 'integer')
241
+ return raw;
242
+ if (integerStorage === 'number') {
243
+ if (typeof raw === 'bigint')
244
+ return (0, cel_numeric_1.safeNumberInteger)(Number(raw));
245
+ return (0, cel_numeric_1.safeNumberInteger)(raw);
246
+ }
247
+ return typeof raw === 'bigint' ? (0, cel_numeric_1.checkInt)(raw, 'int') : (0, cel_numeric_1.readProjectionInteger)(raw);
248
+ }, representation));
249
+ }
250
+ function compileIndex(projection, requireFrame, target, index) {
251
+ if (target.kind === 'collection' && target.at !== undefined) {
252
+ if (!(0, cel_node_1.concrete)(index) || index.kind !== 'int')
253
+ return (0, errors_1.errors)('Array index must be int');
254
+ const element = (0, cel_node_1.scalarElement)(target.type.element);
255
+ if (element === undefined)
256
+ return (0, errors_1.errors)('Indexing requires a scalar collection element');
257
+ const at = target.at;
258
+ requireFrame();
259
+ return (0, errors_1.value)((0, cel_node_1.scalarWithType)(element, (r, i, frame) => {
260
+ if (!frame)
261
+ throw new Error('Missing collection evaluation frame');
262
+ const raw = index.run(r, i, frame);
263
+ const n = typeof raw === 'number' || typeof raw === 'bigint' ? Number(raw) : NaN;
264
+ if (!Number.isSafeInteger(n))
265
+ throw new RangeError('CEL array index out of bounds: ' + String(raw));
266
+ return at(r, i, frame, n);
267
+ }));
268
+ }
269
+ if (target.kind !== 'collection' || (0, cel_node_1.elementKind)(target.type.element) !== 'object' || target.sourcePath === undefined)
270
+ return (0, errors_1.errors)('Indexing requires a source-backed object collection');
271
+ if (!(0, cel_node_1.concrete)(index) || index.kind !== 'int')
272
+ return (0, errors_1.errors)('Array index must be int');
273
+ if (target.length === undefined)
274
+ return (0, errors_1.errors)('Indexed collection has no length reader');
275
+ const path = target.sourcePath;
276
+ const depth = (0, cel_projection_1.arrayDepth)(projection, path) - 1;
277
+ requireFrame();
278
+ return (0, errors_1.value)({ kind: 'object', root: 'source', path,
279
+ selection: { depth, index, length: target.length } });
280
+ }
281
+ //# sourceMappingURL=cel.access.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel.access.js","sourceRoot":"","sources":["../../src/cel.access.ts"],"names":[],"mappings":";;AAkBA,oDAMC;AAQD,sCAYC;AA0LD,oCAwBC;AA7PD,uDAA2F;AAC3F,6CAAiF;AAOjF,2CAA+D;AAC/D,qDAA+E;AAC/E,yCAA+H;AAC/H,+CAAwG;AAIxG,MAAM,MAAM,GAAG,CAAC,CAAqB,EAAgB,EAAE,CAAC,CAAC,KAAG,SAAS,CAAA,CAAC,CAAA,KAAK,CAAA,CAAC,CAAA,CAAC,KAAG,OAAO,CAAA,CAAC,CAAA,QAAQ,CAAA,CAAC,CAAA,QAAQ,CAAA;AAEzG,SAAgB,oBAAoB,CAAkC,UAA8B,EAAC,eAAkD,EAAC,QAAwE,EAAC,KAAoB,EAAC,WAA+B,EAA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AAS;QAAC,OAAO,IAAA,eAAM,EAAC,yCAAyC,CAAC,CAAA;IACrF,MAAM,IAAI,GAAC,MAAM,CAAC,UAAU,CAAA;IAC5B,MAAM,KAAK,GAAC,IAAA,2BAAU,EAAC,UAAU,EAAC,IAAI,CAAC,GAAC,CAAC,CAAA;IACzC,YAAY,EAAE,CAAA;IACd,OAAO,IAAA,cAAK,EAAC,EAAC,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,QAAQ,EAAC,IAAI;QAC1C,SAAS,EAAC,EAAC,KAAK,EAAC,KAAK,EAAC,MAAM,EAAC,MAAM,CAAC,MAAM,EAAC,EAAC,CAAC,CAAA;AACtD,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cel_access_1 = require("./cel.access");
4
+ const cel_frame_1 = require("./cel.frame");
5
+ const cel_node_1 = require("./cel.node");
6
+ describe('indexed occurrence selection', () => {
7
+ test('restores outer occurrence and depth even when the reader throws', () => {
8
+ const frame = (0, cel_frame_1.createFrame)();
9
+ (0, cel_frame_1.bindFrame)(frame, [2, 4]);
10
+ const selection = { depth: 1, index: (0, cel_node_1.scalar)('int', () => 1n), length: () => 3 };
11
+ function failingRead(_r, _i) {
12
+ expect((0, cel_frame_1.windowAt)(frame, 2)).toEqual([2, 1]);
13
+ throw new Error('reader failed');
14
+ }
15
+ expect(() => (0, cel_access_1.withSelection)(selection, {}, [], frame, failingRead)).toThrow('reader failed');
16
+ expect(frame.activeLength).toBe(2);
17
+ expect((0, cel_frame_1.windowAt)(frame, 2)).toEqual([2, 4]);
18
+ expect((0, cel_access_1.withSelection)(selection, {}, [], frame, (_r, _i, f) => (0, cel_frame_1.windowAt)(f, 2)[1])).toBe(1);
19
+ expect((0, cel_frame_1.windowAt)(frame, 2)).toEqual([2, 4]);
20
+ });
21
+ test('rejects an invalid index without changing the frame', () => {
22
+ const frame = (0, cel_frame_1.createFrame)();
23
+ (0, cel_frame_1.bindFrame)(frame, [2]);
24
+ const selection = { depth: 1, index: (0, cel_node_1.scalar)('int', () => 3n), length: () => 3 };
25
+ expect(() => (0, cel_access_1.withSelection)(selection, {}, [], frame, () => 0)).toThrow('CEL array index out of bounds: 3');
26
+ expect(frame.activeLength).toBe(1);
27
+ expect((0, cel_frame_1.windowAt)(frame, 2)).toEqual([2]);
28
+ });
29
+ });
30
+ //# sourceMappingURL=cel.access.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel.access.spec.js","sourceRoot":"","sources":["../../src/cel.access.spec.ts"],"names":[],"mappings":";;AAAA,6CAA0C;AAC1C,2CAA4D;AAC5D,yCAAiC;AAIjC,QAAQ,CAAC,8BAA8B,EAAC,GAAE,EAAE;IACxC,IAAI,CAAC,iEAAiE,EAAC,GAAE,EAAE;QACvE,MAAM,KAAK,GAAC,IAAA,uBAAW,GAAE,CAAA;QACzB,IAAA,qBAAS,EAAC,KAAK,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAA;QACtB,MAAM,SAAS,GAAiC,EAAC,KAAK,EAAC,CAAC,EAAC,KAAK,EAAC,IAAA,iBAAM,EAAC,KAAK,EAAC,GAAE,EAAE,CAAA,EAAE,CAAC,EAAC,MAAM,EAAC,GAAE,EAAE,CAAA,CAAC,EAAC,CAAA;QACjG,SAAS,WAAW,CAAC,EAAU,EAAC,EAAU;YACtC,MAAM,CAAC,IAAA,oBAAQ,EAAC,KAAK,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC,CAAA;YACxC,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;QACpC,CAAC;QACD,MAAM,CAAC,GAAE,EAAE,CAAA,IAAA,0BAAa,EAAC,SAAS,EAAC,EAAE,EAAC,EAAE,EAAC,KAAK,EAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;QACrF,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BAAQ,EAAC,KAAK,EAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { type ErrorsOr } from '@cobol-ts/errors';
2
+ import type { CelCollectionValue } from '@cobol-ts/cel-types';
3
+ import type { Binding, CollectionNode, Node } from './cel.compile.types';
4
+ import { type Frame } from './cel.frame';
5
+ import type { AllocateSlot } from './cel.scope';
6
+ type BindingAt = (offset: number) => Binding | undefined;
7
+ export declare function collect<R, I extends readonly number[]>(node: CollectionNode<R, I>, r: R, i: I, frame: Frame, slot: number): CelCollectionValue[];
8
+ /** Compiles numeric aggregation over the same traversal used by map/filter/reduce. */
9
+ export declare function compileCollectionAggregate<R, I extends readonly number[]>(target: Node<R, I>, name: string, args: Node<R, I>[], preferNumberIntegers: boolean, slot: number): ErrorsOr<Node<R, I>>;
10
+ export declare function compileReduce<R, I extends readonly number[]>(bindingAt: BindingAt, allocateVisitorSlot: AllocateSlot, target: Node<R, I>, initial: Node<R, I>, body: Node<R, I>): ErrorsOr<Node<R, I>>;
11
+ export declare function compileScopedCall<R, I extends readonly number[]>(bindingAt: BindingAt, allocateVisitorSlot: AllocateSlot, target: Node<R, I>, operation: string, body: Node<R, I>): ErrorsOr<Node<R, I>>;
12
+ export {};
@@ -0,0 +1,8 @@
1
+ import { type ErrorsOr } from '@cobol-ts/errors';
2
+ import type { CelValue } from '@cobol-ts/cel-types';
3
+ import type { CollectionNode, ScalarNode, Node } from './cel.compile.types';
4
+ import type { RequireFrame, AllocateSlot } from './cel.scope';
5
+ /** Validate a logical index before reading, without losing wide integer diagnostics. */
6
+ export declare function checkedIndex(raw: CelValue, length?: number): number;
7
+ /** Logical scalar indexing over an existing compiled traversal, with no materialised array. */
8
+ export declare function compileScalarCollectionIndex<R, I extends readonly number[]>(collection: CollectionNode<R, I>, index: ScalarNode<R, I>, requireFrame: RequireFrame, allocateSlot: AllocateSlot): ErrorsOr<Node<R, I>>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkedIndex = checkedIndex;
4
+ exports.compileScalarCollectionIndex = compileScalarCollectionIndex;
5
+ const errors_1 = require("@cobol-ts/errors");
6
+ const cel_node_1 = require("./cel.node");
7
+ const cel_frame_1 = require("./cel.frame");
8
+ /** Validate a logical index before reading, without losing wide integer diagnostics. */
9
+ function checkedIndex(raw, length = Number.MAX_SAFE_INTEGER + 1) {
10
+ const n = typeof raw === 'number' || typeof raw === 'bigint' ? Number(raw) : NaN;
11
+ if (!Number.isSafeInteger(n) || n < 0 || n >= length)
12
+ throw new RangeError('CEL array index out of bounds: ' + String(raw));
13
+ return n;
14
+ }
15
+ function createIndexState() {
16
+ const state = { remaining: 0, found: false, result: undefined, visit: function visit(item) {
17
+ if (state.remaining-- !== 0)
18
+ return true;
19
+ state.result = item;
20
+ state.found = true;
21
+ return false;
22
+ } };
23
+ return state;
24
+ }
25
+ /** Logical scalar indexing over an existing compiled traversal, with no materialised array. */
26
+ function compileScalarCollectionIndex(collection, index, requireFrame, allocateSlot) {
27
+ if (index.kind !== 'int')
28
+ return (0, errors_1.errors)('Array index must be int');
29
+ const element = collection.type.element;
30
+ if (element.kind !== 'scalar')
31
+ return (0, errors_1.errors)('Indexing requires a scalar collection element');
32
+ requireFrame();
33
+ const at = collection.at;
34
+ if (at)
35
+ return (0, errors_1.value)((0, cel_node_1.scalarWithType)(element, function readAt(r, i, f) {
36
+ if (!f)
37
+ throw new Error('Missing collection evaluation frame');
38
+ return at(r, i, f, checkedIndex(index.run(r, i, f)));
39
+ }));
40
+ const slot = allocateSlot();
41
+ return (0, errors_1.value)((0, cel_node_1.scalarWithType)(element, function readTraversal(r, i, f) {
42
+ if (!f)
43
+ throw new Error('Missing collection evaluation frame');
44
+ const raw = index.run(r, i, f), n = checkedIndex(raw);
45
+ const state = (0, cel_frame_1.visitorState)(f, slot, createIndexState);
46
+ state.remaining = n;
47
+ state.found = false;
48
+ try {
49
+ collection.iterate(r, i, f, state.visit);
50
+ if (!state.found)
51
+ throw new RangeError('CEL array index out of bounds: ' + String(raw));
52
+ return state.result;
53
+ }
54
+ finally {
55
+ state.result = undefined;
56
+ }
57
+ }));
58
+ }
59
+ //# sourceMappingURL=cel.collection.index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cel.collection.index.js","sourceRoot":"","sources":["../../src/cel.collection.index.ts"],"names":[],"mappings":";;AAQA,oCAIC;AAcD,oEAsBC;AAhDD,6CAAuE;AAGvE,yCAAyC;AACzC,2CAAwC;AAGxC,wFAAwF;AACxF,SAAgB,YAAY,CAAC,GAAY,EAAC,MAAM,GAAC,MAAM,CAAC,gBAAgB,GAAC,CAAC;IACtE,MAAM,CAAC,GAAC,OAAO,GAAG,KAAG,QAAQ,IAAE,OAAO,GAAG,KAAG,QAAQ,CAAA,CAAC,CAAA,MAAM,CAAC,GAAG,CAAC,CAAA,CAAC,CAAA,GAAG,CAAA;IACpE,IAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAE,CAAC,GAAC,CAAC,IAAE,CAAC,IAAE,MAAM;QAAC,MAAM,IAAI,UAAU,CAAC,iCAAiC,GAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IAC/G,OAAO,CAAC,CAAA;AACZ,CAAC;AAGD,SAAS,gBAAgB;IACrB,MAAM,KAAK,GAAY,EAAC,SAAS,EAAC,CAAC,EAAC,KAAK,EAAC,KAAK,EAAC,MAAM,EAAC,SAAS,EAAC,KAAK,EAAC,SAAS,KAAK,CAAC,IAAI;YACtF,IAAG,KAAK,CAAC,SAAS,EAAE,KAAG,CAAC;gBAAC,OAAO,IAAI,CAAA;YACpC,KAAK,CAAC,MAAM,GAAC,IAAgB,CAAA;YAC7B,KAAK,CAAC,KAAK,GAAC,IAAI,CAAA;YAChB,OAAO,KAAK,CAAA;QAChB,CAAC,E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,wBAAY,EAAC,CAAC,EAAC,IAAI,EAAC,gBAAgB,CAAC,CAAA;QACjD,KAAK,CAAC,SAAS,GAAC,CAAC,CAAC;QAAA,KAAK,CAAC,KAAK,GAAC,KAAK,CAAA;QACnC,IAAG,CAAC;YACA,UAAU,CAAC,OAAO,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,EAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACrC,IAAG,CAAC,KAAK,CAAC,KAAK;gBAAC,MAAM,IAAI,UAAU,CAAC,iCAAiC,GAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;YACnF,OAAO,KAAK,CAAC,MAAkB,CAAA;QACnC,CAAC;gBAAO,CAAC;YAAA,KAAK,CAAC,MAAM,GAAC,SAAS,CAAA;QAAA,CAAC;IACpC,CAAC,CAAC,CAAC,CAAA;AACP,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const errors_1 = require("@cobol-ts/errors");
4
+ const cel_collection_index_1 = require("./cel.collection.index");
5
+ const cel_node_1 = require("./cel.node");
6
+ const cel_frame_1 = require("./cel.frame");
7
+ const type = { kind: 'array', element: { kind: 'scalar', semanticType: 'integer', javascriptType: 'number' } };
8
+ describe('compiled scalar collection indexing', () => {
9
+ test('uses a direct accessor instead of traversal where available', () => {
10
+ const collection = { kind: 'collection', type,
11
+ at: function at(r, _i, _f, n) { return r[n]; }, iterate: function iterate() { throw new Error('unexpected traversal'); } };
12
+ const node = (0, errors_1.valueOrThrow)((0, cel_collection_index_1.compileScalarCollectionIndex)(collection, (0, cel_node_1.scalar)('int', () => 1n), () => { }, () => 0));
13
+ if (node.kind !== 'int')
14
+ throw new Error('Expected int');
15
+ expect(node.run([3, 5], [], (0, cel_frame_1.createFrame)())).toBe(5);
16
+ });
17
+ test('short-circuits traversal and reuses scratch after failure', () => {
18
+ const collection = { kind: 'collection', type, iterate: function iterate(r, _i, _f, visit) {
19
+ for (const item of r) {
20
+ if (item < 0)
21
+ throw new Error('bad item');
22
+ if (!visit(item))
23
+ return false;
24
+ }
25
+ return true;
26
+ } };
27
+ const node = (0, errors_1.valueOrThrow)((0, cel_collection_index_1.compileScalarCollectionIndex)(collection, (0, cel_node_1.scalar)('int', () => 1n), () => { }, () => 0));
28
+ if (node.kind !== 'int')
29
+ throw new Error('Expected int');
30
+ const frame = (0, cel_frame_1.createFrame)();
31
+ expect(node.run([3, 5, -1], [], frame)).toBe(5);
32
+ expect(() => node.run([3, -1], [], frame)).toThrow('bad item');
33
+ expect(() => node.run([3], [], frame)).toThrow('CEL array index out of bounds: 1');
34
+ expect(node.run([8, 9], [], frame)).toBe(9);
35
+ });
36
+ test('rejects negative, fractional, and unsafe indices', () => {
37
+ for (const index of [-1, 1.5, 9007199254740993n])
38
+ expect(() => (0, cel_collection_index_1.checkedIndex)(index)).toThrow('CEL array index out of bounds: ' + String(index));
39
+ expect((0, cel_collection_index_1.checkedIndex)(2n, 3)).toBe(2);
40
+ });
41
+ test('rejects an incorrectly typed index during compilation', () => {
42
+ const collection = { kind: 'collection', type, iterate: () => true };
43
+ expect((0, errors_1.errorsOrThrow)((0, cel_collection_index_1.compileScalarCollectionIndex)(collection, (0, cel_node_1.scalar)('string', () => '1'), () => { }, () => 0)))
44
+ .toEqual(['Array index must be int']);
45
+ });
46
+ });
47
+ //# sourceMappingURL=cel.collection.index.spec.js.map