@rcrsr/rill 0.17.0 → 0.18.0
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.
- package/dist/ast-nodes.d.ts +14 -4
- package/dist/ast-unions.d.ts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -0
- package/dist/error-registry.js +228 -0
- package/dist/ext/crypto/index.js +5 -5
- package/dist/ext/exec/index.js +3 -3
- package/dist/ext/fetch/index.js +4 -4
- package/dist/ext/fetch/request.js +1 -1
- package/dist/ext/fs/index.js +101 -114
- package/dist/ext/fs/sandbox.d.ts +18 -0
- package/dist/ext/fs/sandbox.js +33 -0
- package/dist/ext/kv/index.js +12 -12
- package/dist/ext/kv/store.d.ts +1 -1
- package/dist/ext/kv/store.js +1 -1
- package/dist/generated/version-data.d.ts +1 -1
- package/dist/generated/version-data.js +2 -2
- package/dist/highlight-map.js +1 -0
- package/dist/index.d.ts +1 -15
- package/dist/index.js +1 -14
- package/dist/lexer/operators.js +1 -0
- package/dist/parser/helpers.js +1 -0
- package/dist/parser/parser-expr.js +44 -5
- package/dist/parser/parser-literals.js +111 -4
- package/dist/parser/parser-shape.js +2 -2
- package/dist/parser/parser-use.js +19 -2
- package/dist/parser/parser.d.ts +2 -0
- package/dist/parser/parser.js +2 -0
- package/dist/runtime/core/callable.d.ts +5 -6
- package/dist/runtime/core/callable.js +10 -17
- package/dist/runtime/core/context.d.ts +2 -2
- package/dist/runtime/core/context.js +8 -8
- package/dist/runtime/core/eval/base.d.ts +2 -2
- package/dist/runtime/core/eval/base.js +2 -0
- package/dist/runtime/core/eval/evaluator.d.ts +1 -1
- package/dist/runtime/core/eval/index.d.ts +2 -2
- package/dist/runtime/core/eval/mixins/closures.js +367 -27
- package/dist/runtime/core/eval/mixins/collections.js +81 -6
- package/dist/runtime/core/eval/mixins/control-flow.js +1 -1
- package/dist/runtime/core/eval/mixins/conversion.js +17 -12
- package/dist/runtime/core/eval/mixins/core.js +15 -2
- package/dist/runtime/core/eval/mixins/expressions.js +3 -2
- package/dist/runtime/core/eval/mixins/extraction.js +2 -3
- package/dist/runtime/core/eval/mixins/list-dispatch.js +1 -1
- package/dist/runtime/core/eval/mixins/literals.js +14 -3
- package/dist/runtime/core/eval/mixins/types.js +30 -1
- package/dist/runtime/core/eval/mixins/variables.js +3 -1
- package/dist/runtime/core/execute.d.ts +1 -1
- package/dist/runtime/core/field-descriptor.d.ts +1 -1
- package/dist/runtime/core/introspection.d.ts +2 -2
- package/dist/runtime/core/introspection.js +2 -1
- package/dist/runtime/core/resolvers.d.ts +1 -1
- package/dist/runtime/core/signals.d.ts +6 -1
- package/dist/runtime/core/signals.js +9 -0
- package/dist/runtime/core/types/constructors.d.ts +54 -0
- package/dist/runtime/core/types/constructors.js +201 -0
- package/dist/runtime/core/types/guards.d.ts +42 -0
- package/dist/runtime/core/types/guards.js +88 -0
- package/dist/runtime/core/types/index.d.ts +18 -0
- package/dist/runtime/core/types/index.js +19 -0
- package/dist/runtime/core/types/operations.d.ts +98 -0
- package/dist/runtime/core/types/operations.js +804 -0
- package/dist/runtime/core/{type-registrations.d.ts → types/registrations.d.ts} +12 -22
- package/dist/runtime/core/{type-registrations.js → types/registrations.js} +94 -92
- package/dist/runtime/core/{types.d.ts → types/runtime.d.ts} +8 -8
- package/dist/runtime/core/{type-structures.d.ts → types/structures.d.ts} +21 -3
- package/dist/runtime/core/values.d.ts +13 -102
- package/dist/runtime/core/values.js +26 -722
- package/dist/runtime/ext/builtins.js +9 -8
- package/dist/runtime/ext/extensions.d.ts +2 -2
- package/dist/runtime/ext/extensions.js +2 -1
- package/dist/runtime/ext/test-context.d.ts +2 -2
- package/dist/runtime/ext/test-context.js +3 -2
- package/dist/runtime/index.d.ts +8 -22
- package/dist/runtime/index.js +10 -16
- package/dist/signature-parser.d.ts +1 -1
- package/dist/token-types.d.ts +1 -0
- package/dist/token-types.js +1 -0
- package/package.json +1 -1
- /package/dist/runtime/core/{markers.d.ts → types/markers.d.ts} +0 -0
- /package/dist/runtime/core/{markers.js → types/markers.js} +0 -0
- /package/dist/runtime/core/{types.js → types/runtime.js} +0 -0
- /package/dist/runtime/core/{type-structures.js → types/structures.js} +0 -0
|
@@ -7,17 +7,18 @@
|
|
|
7
7
|
* convertTo, serialize), and a methods record populated from BUILTIN_METHODS.
|
|
8
8
|
*
|
|
9
9
|
* Dispatch functions (inferType, formatValue, deepEquals, serializeValue,
|
|
10
|
-
* deserializeValue
|
|
11
|
-
*
|
|
10
|
+
* deserializeValue) iterate registrations and delegate to per-type
|
|
11
|
+
* protocol implementations.
|
|
12
12
|
*
|
|
13
13
|
* Registration order:
|
|
14
14
|
* primitives -> discriminator-based -> structural -> list -> dict fallback
|
|
15
15
|
*
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
import type { TypeStructure, RillValue, RillFieldDef, RillTuple, RillOrdered, RillVector, RillTypeValue, RillIterator } from './
|
|
19
|
-
import type { RillFunction } from '
|
|
20
|
-
import { isTuple, isVector, isOrdered, isTypeValue, isIterator
|
|
18
|
+
import type { TypeStructure, RillValue, RillFieldDef, RillTuple, RillOrdered, RillVector, RillTypeValue, RillIterator, RillStream } from './structures.js';
|
|
19
|
+
import type { RillFunction } from '../callable.js';
|
|
20
|
+
import { isStream, isTuple, isVector, isOrdered, isTypeValue, isIterator } from './guards.js';
|
|
21
|
+
import { createTuple, createOrdered, createVector } from './constructors.js';
|
|
21
22
|
/**
|
|
22
23
|
* Protocol functions that define per-type behavior.
|
|
23
24
|
* Every type must provide `format`. All other protocols are optional.
|
|
@@ -44,20 +45,20 @@ export interface TypeDefinition {
|
|
|
44
45
|
protocol: TypeProtocol;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
* All
|
|
48
|
+
* All 13 built-in type registrations.
|
|
48
49
|
*
|
|
49
50
|
* Registration order:
|
|
50
51
|
* 1. Primitives: string, number, bool
|
|
51
52
|
* 2. Discriminator-based: tuple, ordered, vector, type, closure, field_descriptor
|
|
52
|
-
* 3. Structural: iterator
|
|
53
|
+
* 3. Structural: iterator, stream
|
|
53
54
|
* 4. list
|
|
54
55
|
* 5. dict (fallback, must be last)
|
|
55
56
|
*
|
|
56
|
-
* AC-1:
|
|
57
|
+
* AC-1: 13 registrations, one per type.
|
|
57
58
|
* BC-2: Vector identity checked before dict fallback.
|
|
58
59
|
* EC-3: Iterator has no protocol.eq.
|
|
59
60
|
* EC-4: Bool has no protocol.compare.
|
|
60
|
-
* EC-8: Non-serializable types throw
|
|
61
|
+
* EC-8: Non-serializable types throw RuntimeError (RILL-R067).
|
|
61
62
|
*/
|
|
62
63
|
export declare const BUILT_IN_TYPES: readonly TypeDefinition[];
|
|
63
64
|
/**
|
|
@@ -102,15 +103,6 @@ export declare function serializeValue(value: RillValue): unknown;
|
|
|
102
103
|
* EC-10: null/undefined input raises RILL-R004.
|
|
103
104
|
*/
|
|
104
105
|
export declare function deserializeValue(data: unknown, typeName: string): RillValue;
|
|
105
|
-
/**
|
|
106
|
-
* Copy a Rill value.
|
|
107
|
-
* Reads immutable flag from registration.
|
|
108
|
-
* Immutable types return same reference.
|
|
109
|
-
* Mutable types (list, dict, iterator) recurse.
|
|
110
|
-
*
|
|
111
|
-
* IR-9: Renamed from deepCopyRillValue.
|
|
112
|
-
*/
|
|
113
|
-
export declare function copyValue(value: RillValue): RillValue;
|
|
114
106
|
/**
|
|
115
107
|
* Populate registration `methods` fields from BUILTIN_METHODS.
|
|
116
108
|
*
|
|
@@ -129,8 +121,6 @@ export declare function copyValue(value: RillValue): RillValue;
|
|
|
129
121
|
*/
|
|
130
122
|
export declare function populateBuiltinMethods(builtinMethods: Record<string, Record<string, RillFunction>>): void;
|
|
131
123
|
export { createTuple, createOrdered, createVector };
|
|
132
|
-
export { isTuple, isVector, isTypeValue, isOrdered, isIterator };
|
|
133
|
-
/** @deprecated Use isIterator instead. */
|
|
134
|
-
export declare const isRillIterator: typeof isIterator;
|
|
124
|
+
export { isStream, isTuple, isVector, isTypeValue, isOrdered, isIterator };
|
|
135
125
|
export type { TypeStructure };
|
|
136
|
-
export type { RillValue, RillTuple, RillOrdered, RillVector, RillTypeValue, RillIterator, RillFieldDef, };
|
|
126
|
+
export type { RillValue, RillTuple, RillOrdered, RillVector, RillTypeValue, RillIterator, RillStream, RillFieldDef, };
|
|
@@ -7,17 +7,19 @@
|
|
|
7
7
|
* convertTo, serialize), and a methods record populated from BUILTIN_METHODS.
|
|
8
8
|
*
|
|
9
9
|
* Dispatch functions (inferType, formatValue, deepEquals, serializeValue,
|
|
10
|
-
* deserializeValue
|
|
11
|
-
*
|
|
10
|
+
* deserializeValue) iterate registrations and delegate to per-type
|
|
11
|
+
* protocol implementations.
|
|
12
12
|
*
|
|
13
13
|
* Registration order:
|
|
14
14
|
* primitives -> discriminator-based -> structural -> list -> dict fallback
|
|
15
15
|
*
|
|
16
16
|
* @internal
|
|
17
17
|
*/
|
|
18
|
-
import { isTuple, isVector, isOrdered, isTypeValue, isIterator,
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
18
|
+
import { isStream, isTuple, isVector, isOrdered, isTypeValue, isIterator, } from './guards.js';
|
|
19
|
+
import { createTuple, createOrdered, createVector } from './constructors.js';
|
|
20
|
+
import { formatStructure, structureEquals } from './operations.js';
|
|
21
|
+
import { isCallable, isDict, isScriptCallable, callableEquals, } from '../callable.js';
|
|
22
|
+
import { RuntimeError } from '../../../types.js';
|
|
21
23
|
// ============================================================
|
|
22
24
|
// IDENTITY HELPERS
|
|
23
25
|
// ============================================================
|
|
@@ -72,6 +74,9 @@ function formatFieldDescriptor(_v) {
|
|
|
72
74
|
function formatIterator(_v) {
|
|
73
75
|
return 'type(iterator)';
|
|
74
76
|
}
|
|
77
|
+
function formatStream(_v) {
|
|
78
|
+
return 'type(stream)';
|
|
79
|
+
}
|
|
75
80
|
function formatList(v) {
|
|
76
81
|
const arr = v;
|
|
77
82
|
return `list[${arr.map(formatValue).join(', ')}]`;
|
|
@@ -93,40 +98,47 @@ function eqNumber(a, b) {
|
|
|
93
98
|
function eqBool(a, b) {
|
|
94
99
|
return a === b;
|
|
95
100
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Parameterized element-wise comparison for collections.
|
|
103
|
+
* Replaces duplicated loops in eqTuple, eqList, eqOrdered.
|
|
104
|
+
*
|
|
105
|
+
* AC-40: Zero-length collections return true.
|
|
106
|
+
* AC-19: eqTuple, eqList, eqOrdered delegate loop body here.
|
|
107
|
+
*/
|
|
108
|
+
function compareElements(aEntries, bEntries, comparator) {
|
|
109
|
+
if (aEntries.length !== bEntries.length)
|
|
100
110
|
return false;
|
|
101
|
-
for (let i = 0; i <
|
|
102
|
-
|
|
103
|
-
const bVal = b.entries[i];
|
|
104
|
-
if (aVal === undefined || bVal === undefined) {
|
|
105
|
-
if (aVal !== bVal)
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
else if (!deepEquals(aVal, bVal)) {
|
|
111
|
+
for (let i = 0; i < aEntries.length; i++) {
|
|
112
|
+
if (!comparator(aEntries[i], bEntries[i]))
|
|
109
113
|
return false;
|
|
110
|
-
}
|
|
111
114
|
}
|
|
112
115
|
return true;
|
|
113
116
|
}
|
|
117
|
+
/** Element comparator for tuple and list entries: handles undefined, delegates to deepEquals. */
|
|
118
|
+
function compareByDeepEquals(a, b) {
|
|
119
|
+
if (a === undefined || b === undefined)
|
|
120
|
+
return a === b;
|
|
121
|
+
return deepEquals(a, b);
|
|
122
|
+
}
|
|
123
|
+
/** Entry comparator for ordered: keys by identity, values by deepEquals. */
|
|
124
|
+
function compareOrderedEntry(a, b) {
|
|
125
|
+
const aEntry = a;
|
|
126
|
+
const bEntry = b;
|
|
127
|
+
if (aEntry === undefined || bEntry === undefined)
|
|
128
|
+
return false;
|
|
129
|
+
if (aEntry[0] !== bEntry[0])
|
|
130
|
+
return false;
|
|
131
|
+
return deepEquals(aEntry[1], bEntry[1]);
|
|
132
|
+
}
|
|
133
|
+
function eqTuple(a, b) {
|
|
134
|
+
if (!isTuple(a) || !isTuple(b))
|
|
135
|
+
return false;
|
|
136
|
+
return compareElements(a.entries, b.entries, compareByDeepEquals);
|
|
137
|
+
}
|
|
114
138
|
function eqOrdered(a, b) {
|
|
115
139
|
if (!isOrdered(a) || !isOrdered(b))
|
|
116
140
|
return false;
|
|
117
|
-
|
|
118
|
-
return false;
|
|
119
|
-
for (let i = 0; i < a.entries.length; i++) {
|
|
120
|
-
const aEntry = a.entries[i];
|
|
121
|
-
const bEntry = b.entries[i];
|
|
122
|
-
if (aEntry === undefined || bEntry === undefined)
|
|
123
|
-
return false;
|
|
124
|
-
if (aEntry[0] !== bEntry[0])
|
|
125
|
-
return false;
|
|
126
|
-
if (!deepEquals(aEntry[1], bEntry[1]))
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
return true;
|
|
141
|
+
return compareElements(a.entries, b.entries, compareOrderedEntry);
|
|
130
142
|
}
|
|
131
143
|
function eqVector(a, b) {
|
|
132
144
|
if (!isVector(a) || !isVector(b))
|
|
@@ -163,20 +175,7 @@ function eqFieldDescriptor(a, b) {
|
|
|
163
175
|
function eqList(a, b) {
|
|
164
176
|
if (!Array.isArray(a) || !Array.isArray(b))
|
|
165
177
|
return false;
|
|
166
|
-
|
|
167
|
-
return false;
|
|
168
|
-
for (let i = 0; i < a.length; i++) {
|
|
169
|
-
const aElem = a[i];
|
|
170
|
-
const bElem = b[i];
|
|
171
|
-
if (aElem === undefined || bElem === undefined) {
|
|
172
|
-
if (aElem !== bElem)
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
else if (!deepEquals(aElem, bElem)) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return true;
|
|
178
|
+
return compareElements(a, b, compareByDeepEquals);
|
|
180
179
|
}
|
|
181
180
|
function eqDict(a, b) {
|
|
182
181
|
const aDict = a;
|
|
@@ -228,7 +227,7 @@ const stringConvertTo = {
|
|
|
228
227
|
const str = v;
|
|
229
228
|
const parsed = Number(str);
|
|
230
229
|
if (isNaN(parsed) || str.trim() === '') {
|
|
231
|
-
throw new
|
|
230
|
+
throw new RuntimeError('RILL-R064', `cannot convert string "${str}" to number`);
|
|
232
231
|
}
|
|
233
232
|
return parsed;
|
|
234
233
|
},
|
|
@@ -238,7 +237,7 @@ const stringConvertTo = {
|
|
|
238
237
|
return true;
|
|
239
238
|
if (s === 'false')
|
|
240
239
|
return false;
|
|
241
|
-
throw new
|
|
240
|
+
throw new RuntimeError('RILL-R065', `cannot convert string "${s}" to bool`);
|
|
242
241
|
},
|
|
243
242
|
};
|
|
244
243
|
/**
|
|
@@ -254,7 +253,7 @@ const numberConvertTo = {
|
|
|
254
253
|
return false;
|
|
255
254
|
if (n === 1)
|
|
256
255
|
return true;
|
|
257
|
-
throw new
|
|
256
|
+
throw new RuntimeError('RILL-R066', `cannot convert number ${n} to bool`);
|
|
258
257
|
},
|
|
259
258
|
};
|
|
260
259
|
/**
|
|
@@ -333,6 +332,13 @@ const closureConvertTo = {
|
|
|
333
332
|
const iteratorConvertTo = {
|
|
334
333
|
string: (_v) => 'type(iterator)',
|
|
335
334
|
};
|
|
335
|
+
/**
|
|
336
|
+
* Stream convertTo targets.
|
|
337
|
+
* - stream -> string: format
|
|
338
|
+
*/
|
|
339
|
+
const streamConvertTo = {
|
|
340
|
+
string: (_v) => 'type(stream)',
|
|
341
|
+
};
|
|
336
342
|
// ============================================================
|
|
337
343
|
// PROTOCOL IMPLEMENTATIONS: SERIALIZE
|
|
338
344
|
// ============================================================
|
|
@@ -363,17 +369,19 @@ function serializeListElement(v) {
|
|
|
363
369
|
if (Array.isArray(v))
|
|
364
370
|
return v.map(serializeListElement);
|
|
365
371
|
if (isCallable(v))
|
|
366
|
-
throw new
|
|
372
|
+
throw new RuntimeError('RILL-R067', 'closures are not JSON-serializable');
|
|
367
373
|
if (isTuple(v))
|
|
368
|
-
throw new
|
|
374
|
+
throw new RuntimeError('RILL-R067', 'tuples are not JSON-serializable');
|
|
369
375
|
if (isOrdered(v))
|
|
370
|
-
throw new
|
|
376
|
+
throw new RuntimeError('RILL-R067', 'ordered values are not JSON-serializable');
|
|
371
377
|
if (isVector(v))
|
|
372
|
-
throw new
|
|
378
|
+
throw new RuntimeError('RILL-R067', 'vectors are not JSON-serializable');
|
|
373
379
|
if (isTypeValue(v))
|
|
374
|
-
throw new
|
|
380
|
+
throw new RuntimeError('RILL-R067', 'type values are not JSON-serializable');
|
|
375
381
|
if (isIterator(v))
|
|
376
|
-
throw new
|
|
382
|
+
throw new RuntimeError('RILL-R067', 'iterators are not JSON-serializable');
|
|
383
|
+
if (isStream(v))
|
|
384
|
+
throw new RuntimeError('RILL-R067', 'streams are not JSON-serializable');
|
|
377
385
|
// Plain dict
|
|
378
386
|
const dict = v;
|
|
379
387
|
const result = {};
|
|
@@ -392,27 +400,27 @@ function serializeDict(v) {
|
|
|
392
400
|
}
|
|
393
401
|
function throwNotSerializable(typeName) {
|
|
394
402
|
return (_v) => {
|
|
395
|
-
throw new
|
|
403
|
+
throw new RuntimeError('RILL-R067', `${typeName}s are not JSON-serializable`);
|
|
396
404
|
};
|
|
397
405
|
}
|
|
398
406
|
// ============================================================
|
|
399
407
|
// BUILT-IN TYPE REGISTRATIONS
|
|
400
408
|
// ============================================================
|
|
401
409
|
/**
|
|
402
|
-
* All
|
|
410
|
+
* All 13 built-in type registrations.
|
|
403
411
|
*
|
|
404
412
|
* Registration order:
|
|
405
413
|
* 1. Primitives: string, number, bool
|
|
406
414
|
* 2. Discriminator-based: tuple, ordered, vector, type, closure, field_descriptor
|
|
407
|
-
* 3. Structural: iterator
|
|
415
|
+
* 3. Structural: iterator, stream
|
|
408
416
|
* 4. list
|
|
409
417
|
* 5. dict (fallback, must be last)
|
|
410
418
|
*
|
|
411
|
-
* AC-1:
|
|
419
|
+
* AC-1: 13 registrations, one per type.
|
|
412
420
|
* BC-2: Vector identity checked before dict fallback.
|
|
413
421
|
* EC-3: Iterator has no protocol.eq.
|
|
414
422
|
* EC-4: Bool has no protocol.compare.
|
|
415
|
-
* EC-8: Non-serializable types throw
|
|
423
|
+
* EC-8: Non-serializable types throw RuntimeError (RILL-R067).
|
|
416
424
|
*/
|
|
417
425
|
export const BUILT_IN_TYPES = Object.freeze([
|
|
418
426
|
// ---- Primitives ----
|
|
@@ -538,6 +546,31 @@ export const BUILT_IN_TYPES = Object.freeze([
|
|
|
538
546
|
},
|
|
539
547
|
},
|
|
540
548
|
// ---- Structural ----
|
|
549
|
+
// Stream must precede iterator: streams satisfy the iterator shape
|
|
550
|
+
// (done + next + value) but have the __rill_stream discriminator.
|
|
551
|
+
{
|
|
552
|
+
name: 'stream',
|
|
553
|
+
identity: (v) => isStream(v),
|
|
554
|
+
isLeaf: false,
|
|
555
|
+
immutable: true,
|
|
556
|
+
methods: {},
|
|
557
|
+
protocol: {
|
|
558
|
+
format: formatStream,
|
|
559
|
+
convertTo: streamConvertTo,
|
|
560
|
+
serialize: throwNotSerializable('stream'),
|
|
561
|
+
structure: (v) => {
|
|
562
|
+
const raw = v;
|
|
563
|
+
const chunk = raw['__rill_stream_chunk_type'];
|
|
564
|
+
const ret = raw['__rill_stream_ret_type'];
|
|
565
|
+
const result = { kind: 'stream' };
|
|
566
|
+
if (chunk !== undefined)
|
|
567
|
+
result.chunk = chunk;
|
|
568
|
+
if (ret !== undefined)
|
|
569
|
+
result.ret = ret;
|
|
570
|
+
return result;
|
|
571
|
+
},
|
|
572
|
+
},
|
|
573
|
+
},
|
|
541
574
|
{
|
|
542
575
|
// EC-3: iterator has no protocol.eq (equality raises RILL-R002)
|
|
543
576
|
name: 'iterator',
|
|
@@ -669,35 +702,6 @@ export function deserializeValue(data, typeName) {
|
|
|
669
702
|
}
|
|
670
703
|
throw new RuntimeError('RILL-R004', `Cannot deserialize as ${typeName}`);
|
|
671
704
|
}
|
|
672
|
-
/**
|
|
673
|
-
* Copy a Rill value.
|
|
674
|
-
* Reads immutable flag from registration.
|
|
675
|
-
* Immutable types return same reference.
|
|
676
|
-
* Mutable types (list, dict, iterator) recurse.
|
|
677
|
-
*
|
|
678
|
-
* IR-9: Renamed from deepCopyRillValue.
|
|
679
|
-
*/
|
|
680
|
-
export function copyValue(value) {
|
|
681
|
-
if (value === null || typeof value !== 'object')
|
|
682
|
-
return value;
|
|
683
|
-
for (const reg of BUILT_IN_TYPES) {
|
|
684
|
-
if (reg.identity(value)) {
|
|
685
|
-
if (reg.immutable)
|
|
686
|
-
return value;
|
|
687
|
-
break;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
// Mutable: list or dict, recurse
|
|
691
|
-
if (Array.isArray(value)) {
|
|
692
|
-
return value.map(copyValue);
|
|
693
|
-
}
|
|
694
|
-
const dict = value;
|
|
695
|
-
const copy = {};
|
|
696
|
-
for (const [k, v] of Object.entries(dict)) {
|
|
697
|
-
copy[k] = copyValue(v);
|
|
698
|
-
}
|
|
699
|
-
return copy;
|
|
700
|
-
}
|
|
701
705
|
// ============================================================
|
|
702
706
|
// METHOD POPULATION
|
|
703
707
|
// ============================================================
|
|
@@ -730,7 +734,7 @@ export function populateBuiltinMethods(builtinMethods) {
|
|
|
730
734
|
for (const reg of BUILT_IN_TYPES) {
|
|
731
735
|
if (METHOD_BEARING_TYPES.has(reg.name) && reg.name in builtinMethods) {
|
|
732
736
|
if (Object.isFrozen(reg)) {
|
|
733
|
-
throw new
|
|
737
|
+
throw new RuntimeError('RILL-R068', `populateBuiltinMethods: registration '${reg.name}' is frozen; cannot assign methods`);
|
|
734
738
|
}
|
|
735
739
|
reg.methods =
|
|
736
740
|
builtinMethods[reg.name];
|
|
@@ -744,6 +748,4 @@ export { createTuple, createOrdered, createVector };
|
|
|
744
748
|
// ============================================================
|
|
745
749
|
// RE-EXPORTED GUARD FUNCTIONS
|
|
746
750
|
// ============================================================
|
|
747
|
-
export { isTuple, isVector, isTypeValue, isOrdered, isIterator };
|
|
748
|
-
/** @deprecated Use isIterator instead. */
|
|
749
|
-
export const isRillIterator = isIterator;
|
|
751
|
+
export { isStream, isTuple, isVector, isTypeValue, isOrdered, isIterator };
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* Public types for runtime configuration and execution results.
|
|
5
5
|
* These types are the primary interface for host applications.
|
|
6
6
|
*/
|
|
7
|
-
import type { RillTypeName } from '
|
|
8
|
-
import type { CallableFn, RillFunction } from '
|
|
9
|
-
import type { TypeStructure, RillValue } from './
|
|
10
|
-
export type { NativeArray, NativePlainObject, NativeValue } from '
|
|
7
|
+
import type { RillTypeName } from '../../../types.js';
|
|
8
|
+
import type { CallableFn, RillFunction } from '../callable.js';
|
|
9
|
+
import type { TypeStructure, RillValue } from './structures.js';
|
|
10
|
+
export type { NativeArray, NativePlainObject, NativeValue } from '../values.js';
|
|
11
11
|
/** I/O callbacks for runtime operations */
|
|
12
12
|
export interface RuntimeCallbacks {
|
|
13
13
|
/** Called when .log is invoked */
|
|
@@ -121,7 +121,7 @@ export interface RuntimeContext {
|
|
|
121
121
|
/** Variable types - locked after first assignment (local to this scope) */
|
|
122
122
|
readonly variableTypes: Map<string, RillTypeName | TypeStructure>;
|
|
123
123
|
/** Built-in and user-defined functions (CallableFn for untyped, ApplicationCallable for typed) */
|
|
124
|
-
readonly functions: Map<string, CallableFn | import('
|
|
124
|
+
readonly functions: Map<string, CallableFn | import('../callable.js').ApplicationCallable>;
|
|
125
125
|
/** I/O callbacks */
|
|
126
126
|
readonly callbacks: RuntimeCallbacks;
|
|
127
127
|
/** Observability callbacks */
|
|
@@ -152,7 +152,7 @@ export interface RuntimeContext {
|
|
|
152
152
|
* Call stack for error context.
|
|
153
153
|
* Managed by evaluator; pushed on function entry, popped on exit.
|
|
154
154
|
*/
|
|
155
|
-
readonly callStack: import('
|
|
155
|
+
readonly callStack: import('../../../types.js').CallFrame[];
|
|
156
156
|
/** Arbitrary string metadata passed from the host (e.g. request IDs, user IDs) */
|
|
157
157
|
readonly metadata?: Record<string, string> | undefined;
|
|
158
158
|
/**
|
|
@@ -184,7 +184,7 @@ export interface RuntimeContext {
|
|
|
184
184
|
* Must be provided when `kind: 'source'` resolver results are expected.
|
|
185
185
|
* Omit if only `kind: 'value'` resolvers are used.
|
|
186
186
|
*/
|
|
187
|
-
readonly parseSource?: ((text: string) => import('
|
|
187
|
+
readonly parseSource?: ((text: string) => import('../../../types.js').ScriptNode) | undefined;
|
|
188
188
|
/** Identifies the current source file for cross-module error reporting */
|
|
189
189
|
readonly sourceId?: string | undefined;
|
|
190
190
|
/** Source text of the current file for cross-module error snippets */
|
|
@@ -224,7 +224,7 @@ export interface RuntimeOptions {
|
|
|
224
224
|
* Parser function for executing resolver source results.
|
|
225
225
|
* Required when resolvers may return `kind: 'source'` results.
|
|
226
226
|
*/
|
|
227
|
-
parseSource?: (text: string) => import('
|
|
227
|
+
parseSource?: (text: string) => import('../../../types.js').ScriptNode;
|
|
228
228
|
}
|
|
229
229
|
/** Result of script execution */
|
|
230
230
|
export interface ExecutionResult {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* `.kind` as its discriminator instead of `.type`, enabling future
|
|
10
10
|
* coexistence during migration.
|
|
11
11
|
*/
|
|
12
|
-
import type { RillTypeName } from '
|
|
12
|
+
import type { RillTypeName } from '../../../types.js';
|
|
13
13
|
import type { CallableMarker, FieldDescriptorMarker } from './markers.js';
|
|
14
14
|
/**
|
|
15
15
|
* Field definition - describes a single field in a structural type.
|
|
@@ -27,7 +27,7 @@ export interface RillFieldDef {
|
|
|
27
27
|
* Structural type descriptor - describes the shape of a value in the type system.
|
|
28
28
|
* Discriminated by `.kind` (not `.type`).
|
|
29
29
|
*
|
|
30
|
-
* Includes all
|
|
30
|
+
* Includes all 13 built-in variants plus a catch-all for types without
|
|
31
31
|
* parameterized structure (e.g. iterator).
|
|
32
32
|
*/
|
|
33
33
|
export type TypeStructure = {
|
|
@@ -66,6 +66,10 @@ export type TypeStructure = {
|
|
|
66
66
|
members: TypeStructure[];
|
|
67
67
|
} | {
|
|
68
68
|
kind: 'iterator';
|
|
69
|
+
} | {
|
|
70
|
+
kind: 'stream';
|
|
71
|
+
chunk?: TypeStructure;
|
|
72
|
+
ret?: TypeStructure;
|
|
69
73
|
} | {
|
|
70
74
|
kind: string;
|
|
71
75
|
data?: unknown;
|
|
@@ -122,7 +126,21 @@ export interface RillIterator extends Record<string, RillValue> {
|
|
|
122
126
|
readonly next: CallableMarker;
|
|
123
127
|
readonly value?: RillValue;
|
|
124
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Stream type - represents an async lazy sequence with resolution.
|
|
131
|
+
* A stream is a dict with:
|
|
132
|
+
* - __rill_stream: true - discriminator for stream detection
|
|
133
|
+
* - done: boolean - whether all chunks have been consumed
|
|
134
|
+
* - next: callable - function to advance to the next stream step
|
|
135
|
+
* - value?: any - current chunk value (present when done is false)
|
|
136
|
+
*/
|
|
137
|
+
export interface RillStream extends Record<string, RillValue> {
|
|
138
|
+
readonly __rill_stream: true;
|
|
139
|
+
readonly done: boolean;
|
|
140
|
+
readonly next: CallableMarker;
|
|
141
|
+
readonly value?: RillValue;
|
|
142
|
+
}
|
|
125
143
|
/** Any value that can flow through Rill */
|
|
126
144
|
export type RillValue = string | number | boolean | null | RillValue[] | {
|
|
127
145
|
[key: string]: RillValue;
|
|
128
|
-
} | CallableMarker | RillTuple | RillOrdered | RillVector | FieldDescriptorMarker | RillTypeValue;
|
|
146
|
+
} | CallableMarker | RillTuple | RillOrdered | RillVector | FieldDescriptorMarker | RillTypeValue | RillStream;
|
|
@@ -4,92 +4,26 @@
|
|
|
4
4
|
* Core value types that flow through Rill programs.
|
|
5
5
|
* Public API for host applications.
|
|
6
6
|
*
|
|
7
|
+
* Structural operations (structureEquals, structureMatches, formatStructure,
|
|
8
|
+
* inferStructure, commonType) live in types/operations.ts and are re-exported.
|
|
9
|
+
*
|
|
7
10
|
* Dispatch functions (inferType, formatValue, deepEquals, serializeValue,
|
|
8
11
|
* copyValue) re-export from type-registrations.ts protocol implementations.
|
|
9
12
|
*/
|
|
10
13
|
import type { RillTypeName } from '../../types.js';
|
|
11
|
-
import type {
|
|
14
|
+
import type { RillCallable } from './callable.js';
|
|
15
|
+
import { isDict, isIterator, isOrdered, isStream, isTuple, isTypeValue, isVector } from './types/guards.js';
|
|
16
|
+
/** isCallable guard widened to narrow to full RillCallable (not just CallableMarker) */
|
|
17
|
+
declare const isCallable: (value: RillValue) => value is RillCallable;
|
|
18
|
+
import type { RillFieldDef, RillIterator, RillOrdered, RillTuple, RillTypeValue, RillValue, RillVector, TypeStructure } from './types/structures.js';
|
|
12
19
|
export type { RillFieldDef, RillIterator, RillOrdered, RillTuple, RillTypeValue, RillValue, RillVector, TypeStructure, };
|
|
13
|
-
export type DictStructure
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
export type TupleStructure = {
|
|
19
|
-
kind: 'tuple';
|
|
20
|
-
elements?: RillFieldDef[];
|
|
21
|
-
valueType?: TypeStructure;
|
|
22
|
-
};
|
|
23
|
-
export type OrderedStructure = {
|
|
24
|
-
kind: 'ordered';
|
|
25
|
-
fields?: RillFieldDef[];
|
|
26
|
-
valueType?: TypeStructure;
|
|
27
|
-
};
|
|
28
|
-
/** @deprecated Use TypeStructure instead. */
|
|
29
|
-
export type RillType = TypeStructure;
|
|
30
|
-
/** Type guard for RillTuple (spread args) */
|
|
31
|
-
export declare function isTuple(value: RillValue): value is RillTuple;
|
|
32
|
-
/** Type guard for RillVector */
|
|
33
|
-
export declare function isVector(value: RillValue): value is RillVector;
|
|
34
|
-
/** Type guard for RillOrdered (named spread args) */
|
|
35
|
-
export declare function isOrdered(value: RillValue): value is RillOrdered;
|
|
36
|
-
/** Type guard for RillTypeValue */
|
|
37
|
-
export declare function isTypeValue(value: RillValue): value is RillTypeValue;
|
|
38
|
-
/**
|
|
39
|
-
* Create ordered from entries array (named, preserves insertion order).
|
|
40
|
-
* Entries may be 2-element [name, value] or 3-element [name, value, default]
|
|
41
|
-
* tuples; the third element carries a default value for `.^input` reflection.
|
|
42
|
-
*/
|
|
43
|
-
export declare function createOrdered(entries: [string, RillValue, RillValue?][]): RillOrdered;
|
|
44
|
-
/** Create tuple from entries array (positional, preserves order) */
|
|
45
|
-
export declare function createTuple(entries: RillValue[]): RillTuple;
|
|
46
|
-
/**
|
|
47
|
-
* Create vector from Float32Array with model name.
|
|
48
|
-
* @throws {Error} if data.length is 0 (zero-dimension vectors not allowed)
|
|
49
|
-
*/
|
|
50
|
-
export declare function createVector(data: Float32Array, model: string): RillVector;
|
|
20
|
+
export type { DictStructure, TupleStructure, OrderedStructure, } from './types/operations.js';
|
|
21
|
+
export { isCallable, isDict, isIterator, isOrdered, isStream, isTuple, isTypeValue, isVector, };
|
|
22
|
+
export { copyValue, createOrdered, createTuple, createVector, emptyForType, } from './types/constructors.js';
|
|
23
|
+
export { commonType, compareStructuredFields, formatStructure, inferElementType, inferStructure, paramToFieldDef, structureEquals, structureMatches, } from './types/operations.js';
|
|
24
|
+
export type { FieldComparisonCallbacks } from './types/operations.js';
|
|
51
25
|
/** Infer the Rill type from a runtime value. Delegates to type-registrations. */
|
|
52
26
|
export declare const inferType: (value: RillValue) => string;
|
|
53
|
-
/**
|
|
54
|
-
* Infer the element type for a homogeneous list.
|
|
55
|
-
* Empty arrays return { kind: 'any' }.
|
|
56
|
-
* Mixed types throw RILL-R002.
|
|
57
|
-
*/
|
|
58
|
-
export declare function inferElementType(elements: RillValue[]): TypeStructure;
|
|
59
|
-
/**
|
|
60
|
-
* Return the most specific shared type for two TypeStructure values.
|
|
61
|
-
* Returns null when types are incompatible at the top level.
|
|
62
|
-
*
|
|
63
|
-
* Cascade priority:
|
|
64
|
-
* 1. Any-narrowing: if either side is `any`, return the other
|
|
65
|
-
* 2. Structural match: delegate to structureEquals; on true, return a
|
|
66
|
-
* 3. Recursive list: merge inner element types
|
|
67
|
-
* 3b. Uniform valueType: merge dict/tuple/ordered value types
|
|
68
|
-
* 4. Bare type fallback: same compound type but structural mismatch
|
|
69
|
-
* 5. Incompatible: different top-level types return null
|
|
70
|
-
*/
|
|
71
|
-
export declare function commonType(a: TypeStructure, b: TypeStructure): TypeStructure | null;
|
|
72
|
-
/** Compare two structural types for equality. */
|
|
73
|
-
export declare function structureEquals(a: TypeStructure, b: TypeStructure): boolean;
|
|
74
|
-
/** @deprecated Use structureEquals instead. */
|
|
75
|
-
export declare const structuralTypeEquals: typeof structureEquals;
|
|
76
|
-
/** Infer the structural type descriptor for any Rill value. */
|
|
77
|
-
export declare function inferStructure(value: RillValue): TypeStructure;
|
|
78
|
-
/** @deprecated Use inferStructure instead. */
|
|
79
|
-
export declare const inferStructuralType: typeof inferStructure;
|
|
80
|
-
/**
|
|
81
|
-
* Check if a value matches a structural type descriptor.
|
|
82
|
-
* Used for runtime type checking (`:?` operator).
|
|
83
|
-
*/
|
|
84
|
-
export declare function structureMatches(value: RillValue, type: TypeStructure): boolean;
|
|
85
|
-
/** @deprecated Use structureMatches instead. */
|
|
86
|
-
export declare const structuralTypeMatches: typeof structureMatches;
|
|
87
|
-
/** Build a closure param field definition from name, type, and optional default. */
|
|
88
|
-
export declare function paramToFieldDef(name: string, type: TypeStructure, defaultValue: RillValue | undefined): RillFieldDef;
|
|
89
|
-
/** Format a structural type descriptor as a human-readable string. */
|
|
90
|
-
export declare function formatStructure(type: TypeStructure): string;
|
|
91
|
-
/** @deprecated Use formatStructure instead. */
|
|
92
|
-
export declare const formatStructuralType: typeof formatStructure;
|
|
93
27
|
/**
|
|
94
28
|
* Check if a value is of the expected type.
|
|
95
29
|
* Returns true if the value matches the expected type, false otherwise.
|
|
@@ -123,8 +57,6 @@ export interface NativeResult {
|
|
|
123
57
|
}
|
|
124
58
|
/** Serialize a Rill value for JSON transport. Delegates to type-registrations. */
|
|
125
59
|
export declare const serializeValue: (value: RillValue) => unknown;
|
|
126
|
-
/** @deprecated Use serializeValue instead. */
|
|
127
|
-
export declare const valueToJSON: (value: RillValue) => unknown;
|
|
128
60
|
/**
|
|
129
61
|
* Convert a RillValue to a NativeResult for host consumption.
|
|
130
62
|
* Non-representable types (closures, vectors, type values, iterators) produce descriptor objects.
|
|
@@ -146,32 +78,11 @@ export declare const anyTypeValue: RillTypeValue;
|
|
|
146
78
|
* Falls back to 'any' for compound types that lack a direct RillTypeName mapping.
|
|
147
79
|
*/
|
|
148
80
|
export declare function structureToTypeValue(type: TypeStructure): RillTypeValue;
|
|
149
|
-
/** @deprecated Use structureToTypeValue instead. */
|
|
150
|
-
export declare const rillTypeToTypeValue: typeof structureToTypeValue;
|
|
151
81
|
/**
|
|
152
82
|
* Check if a type is a collection (dict, ordered, tuple) with defined
|
|
153
83
|
* fields or elements. Used to decide if an empty collection can be
|
|
154
84
|
* synthesized and hydrated.
|
|
155
85
|
*/
|
|
156
86
|
export declare function hasCollectionFields(type: TypeStructure): boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Create an empty collection value matching the given TypeStructure.
|
|
159
|
-
* Assumes the type is dict, ordered, or tuple.
|
|
160
|
-
*/
|
|
161
|
-
export declare function emptyForType(type: TypeStructure): RillValue;
|
|
162
87
|
/** Check if a key name is reserved */
|
|
163
88
|
export declare function isReservedMethod(name: string): boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Type guard for Rill iterator (lazy sequence).
|
|
166
|
-
* An iterator is a dict with:
|
|
167
|
-
* - done: boolean - whether iteration is complete
|
|
168
|
-
* - next: callable - function to get next iterator
|
|
169
|
-
* - value: any (only required when not done) - current element
|
|
170
|
-
*/
|
|
171
|
-
export declare function isIterator(value: RillValue): value is RillIterator;
|
|
172
|
-
/** @deprecated Use isIterator instead. */
|
|
173
|
-
export declare const isRillIterator: typeof isIterator;
|
|
174
|
-
/** Copy a RillValue. Delegates to type-registrations. */
|
|
175
|
-
export declare const copyValue: (value: RillValue) => RillValue;
|
|
176
|
-
/** @deprecated Use copyValue instead. */
|
|
177
|
-
export declare const deepCopyRillValue: (value: RillValue) => RillValue;
|