@telorun/cel 0.107.0 → 0.109.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/backend-runtime.d.ts +46 -8
- package/dist/backend-runtime.d.ts.map +1 -1
- package/dist/backend-runtime.js +133 -30
- package/dist/catalog-runtime.d.ts.map +1 -1
- package/dist/catalog-runtime.js +110 -109
- package/dist/cel-map-value.d.ts +20 -7
- package/dist/cel-map-value.d.ts.map +1 -1
- package/dist/cel-map-value.js +29 -18
- package/dist/cel-value.d.ts +10 -3
- package/dist/cel-value.d.ts.map +1 -1
- package/dist/check-diagnostic.d.ts +3 -2
- package/dist/check-diagnostic.d.ts.map +1 -1
- package/dist/checker.d.ts +9 -0
- package/dist/checker.d.ts.map +1 -1
- package/dist/checker.js +98 -13
- package/dist/closure-backend.js +66 -15
- package/dist/duration-value.d.ts +11 -0
- package/dist/duration-value.d.ts.map +1 -1
- package/dist/duration-value.js +17 -3
- package/dist/emitted-module.d.ts +1 -1
- package/dist/emitted-module.js +1 -1
- package/dist/engine-version.d.ts +1 -1
- package/dist/engine-version.js +1 -1
- package/dist/environment.d.ts +8 -0
- package/dist/environment.d.ts.map +1 -1
- package/dist/environment.js +20 -5
- package/dist/function-registry.d.ts +40 -0
- package/dist/function-registry.d.ts.map +1 -1
- package/dist/function-registry.js +105 -2
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -6
- package/dist/js-emitter.d.ts +3 -2
- package/dist/js-emitter.d.ts.map +1 -1
- package/dist/js-emitter.js +11 -5
- package/dist/macro-check.d.ts +8 -0
- package/dist/macro-check.d.ts.map +1 -1
- package/dist/macro-check.js +1 -1
- package/dist/member-read.d.ts +42 -5
- package/dist/member-read.d.ts.map +1 -1
- package/dist/member-read.js +47 -6
- package/dist/resolved-call.d.ts +13 -0
- package/dist/resolved-call.d.ts.map +1 -1
- package/dist/runtime-library.d.ts +13 -2
- package/dist/runtime-library.d.ts.map +1 -1
- package/dist/runtime-library.js +134 -125
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +20 -4
- package/dist/timestamp-value.d.ts +9 -0
- package/dist/timestamp-value.d.ts.map +1 -1
- package/dist/timestamp-value.js +15 -0
- package/dist/type-expression.d.ts +18 -2
- package/dist/type-expression.d.ts.map +1 -1
- package/dist/type-expression.js +23 -3
- package/dist/value-equality.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/backend-runtime.ts +180 -30
- package/src/catalog-runtime.ts +133 -133
- package/src/cel-map-value.ts +31 -20
- package/src/cel-value.ts +11 -3
- package/src/check-diagnostic.ts +4 -2
- package/src/checker.ts +123 -10
- package/src/closure-backend.ts +59 -14
- package/src/duration-value.ts +18 -3
- package/src/emitted-module.ts +1 -1
- package/src/engine-version.ts +1 -1
- package/src/environment.ts +26 -5
- package/src/function-registry.ts +114 -2
- package/src/index.ts +24 -3
- package/src/js-emitter.ts +13 -5
- package/src/macro-check.ts +7 -1
- package/src/member-read.ts +48 -7
- package/src/resolved-call.ts +13 -0
- package/src/runtime-library.ts +167 -143
- package/src/serializer.ts +19 -3
- package/src/timestamp-value.ts +16 -0
- package/src/type-expression.ts +25 -3
- package/src/value-equality.ts +3 -3
|
@@ -19,7 +19,7 @@ import type { CelActivation } from "./activation.js";
|
|
|
19
19
|
import type { CelType } from "./cel-type.js";
|
|
20
20
|
import type { CelError, CelOptional, CelValue } from "./cel-value.js";
|
|
21
21
|
import type { FunctionRegistry } from "./function-registry.js";
|
|
22
|
-
import type {
|
|
22
|
+
import type { CelCallContext } from "./runtime-library.js";
|
|
23
23
|
import type { CallForm } from "./signature.js";
|
|
24
24
|
import type { CelSelectNode, SourceRange } from "./syntax-tree.js";
|
|
25
25
|
/** A compile-time refusal: a tree neither backend can compile at all. */
|
|
@@ -29,7 +29,15 @@ export declare class CelCompileError extends Error {
|
|
|
29
29
|
/** How many distinct argument-type combinations one call site remembers. */
|
|
30
30
|
export declare const CALL_SITE_CACHE_CAPACITY = 16;
|
|
31
31
|
/** What a namespaced call is dispatched through, when something bound it. */
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* A function bound under a namespace. Its arguments arrive as **one array**, where a
|
|
34
|
+
* registered overload's arrive positionally: a namespace declaration may withhold its
|
|
35
|
+
* parameter list entirely, so the count is the host's and not the dispatch key's. That is
|
|
36
|
+
* the whole rule — positional where the key fixes the arity, one array where the author
|
|
37
|
+
* decides it.
|
|
38
|
+
*/
|
|
39
|
+
export type NamespaceImplementation = (args: readonly CelValue[], ctx: CelCallContext) => CelValue;
|
|
40
|
+
export type NamespaceDispatch = (namespace: string, name: string) => NamespaceImplementation | undefined;
|
|
33
41
|
export interface EvaluationFrame {
|
|
34
42
|
readonly activation: CelActivation;
|
|
35
43
|
readonly slots: CelValue[];
|
|
@@ -93,14 +101,19 @@ export declare function plainMemberChain(node: CelSelectNode, bound: (name: stri
|
|
|
93
101
|
/**
|
|
94
102
|
* A member read in every form. Reading **through an optional** answers an optional
|
|
95
103
|
* whichever form the read is written in, which is what lets a chain over a value that
|
|
96
|
-
* may be absent stay one expression: an absent one propagates as absent, a key the
|
|
97
|
-
* value does not have is absent too
|
|
98
|
-
*
|
|
104
|
+
* may be absent stay one expression: an absent one propagates as absent, and a key the
|
|
105
|
+
* held value does not have is absent too.
|
|
106
|
+
*
|
|
107
|
+
* Which refusals are absence and which are a mistake is `lookupAbsence`'s, and it turns
|
|
108
|
+
* on the FORM the read is written in rather than on what the operand turned out to be: a
|
|
109
|
+
* presence-shaped read over a value that holds no members is absent, while the ordinary
|
|
110
|
+
* read of a member of such a value is the mistake it is outside an optional too.
|
|
99
111
|
*/
|
|
100
112
|
export declare function readThrough(container: CelValue, key: CelValue, optionalForm: boolean, range: SourceRange): CelValue;
|
|
101
113
|
/**
|
|
102
|
-
* `has(a.b)` — presence, which a missing key
|
|
103
|
-
* An absent optional has no members, and a
|
|
114
|
+
* `has(a.b)` — presence, which a missing key and a value that holds no members both
|
|
115
|
+
* answer `false` for rather than erroring. An absent optional has no members, and a
|
|
116
|
+
* present one is asked about what it holds.
|
|
104
117
|
*/
|
|
105
118
|
export declare function hasMember(container: CelValue, field: CelValue, range: SourceRange): CelValue;
|
|
106
119
|
/** A bool operand, or the error it is — a non-bool is a mistake of its own. */
|
|
@@ -129,10 +142,35 @@ export declare class CallSite {
|
|
|
129
142
|
private readonly nominalArity;
|
|
130
143
|
private readonly resolved;
|
|
131
144
|
private readonly context;
|
|
132
|
-
|
|
145
|
+
/** The arity the last resolution was made under; `-1` until there is one. */
|
|
146
|
+
private count;
|
|
147
|
+
private t0;
|
|
148
|
+
private t1;
|
|
149
|
+
private t2;
|
|
150
|
+
private t3;
|
|
133
151
|
private lastDispatch;
|
|
134
152
|
constructor(name: string, form: CallForm, range: SourceRange, registry: FunctionRegistry, nominalArity: (name: string) => number | undefined);
|
|
153
|
+
call0(): CelValue;
|
|
154
|
+
call1(a: CelValue): CelValue;
|
|
155
|
+
call2(a: CelValue, b: CelValue): CelValue;
|
|
156
|
+
call3(a: CelValue, b: CelValue, c: CelValue): CelValue;
|
|
157
|
+
call4(a: CelValue, b: CelValue, c: CelValue, d: CelValue): CelValue;
|
|
158
|
+
/**
|
|
159
|
+
* The array form, for a caller that holds its arguments as one — a call written WIDER than
|
|
160
|
+
* any overload can be (`'42'.replace('2', '1', 1, false)` is five values, which is a row),
|
|
161
|
+
* the conformance and identity gates, and a host comparing a site cold against warm. It
|
|
162
|
+
* routes to the same entry points, so there is one dispatch path and not two.
|
|
163
|
+
*/
|
|
135
164
|
call(values: readonly CelValue[]): CelValue;
|
|
165
|
+
/**
|
|
166
|
+
* A call written with more values than the widest signature may declare. **The arity is
|
|
167
|
+
* the SOURCE's, not the dispatch key's** — anyone may write a call of any width — so this
|
|
168
|
+
* is reachable and answers the ordinary refusal, naming the types it was handed. Nothing
|
|
169
|
+
* resolves here, because a signature that wide is refused where it is registered; the
|
|
170
|
+
* resolution still runs, so one place decides what a call that resolves to nothing says.
|
|
171
|
+
*/
|
|
172
|
+
private wide;
|
|
173
|
+
private resolve;
|
|
136
174
|
private answer;
|
|
137
175
|
}
|
|
138
176
|
/** A call site over an environment, which both backends build one of per call. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backend-runtime.d.ts","sourceRoot":"","sources":["../src/backend-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiB7C,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"backend-runtime.d.ts","sourceRoot":"","sources":["../src/backend-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAiB7C,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAWtE,OAAO,KAAK,EAAE,gBAAgB,EAAiC,MAAM,wBAAwB,CAAC;AAE9F,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,sBAAsB,CAAC;AAE9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAW,aAAa,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE5E,yEAAyE;AACzE,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,4EAA4E;AAC5E,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,6EAA6E;AAC7E;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,IAAI,EAAE,SA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AAI;IAsBZ,OAAO,CAAC,OAAO;IAoDf,OAAO,CAAC,MAAM;CAkBf;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CACxB,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,WAAW,GACjB,QAAQ,CAEV;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,QAAQ,EACf,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GACjD,OAAO,CAkCT"}
|
package/dist/backend-runtime.js
CHANGED
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
import { activationHolds } from "./activation.js";
|
|
19
19
|
import { BoundedCache } from "./bounded-cache.js";
|
|
20
20
|
import { BOOL, BYTES, DOUBLE, DURATION, DYN, INT, listOf, mapOf, NULL, optionalOf, STRING, TIMESTAMP, TYPE, UINT, } from "./cel-type.js";
|
|
21
|
-
import { asyncValueRefused, celError, celNone, celSome, celTypeNameOf, isCelError, isCelOptional, } from "./cel-value.js";
|
|
22
|
-
import { celHas, celLookup, celRead,
|
|
21
|
+
import { asyncValueRefused, CEL_VALUE_TYPE, celError, celNone, celSome, celTypeNameOf, isCelError, isCelOptional, } from "./cel-value.js";
|
|
22
|
+
import { celHas, celLookup, celRead, lookupAbsence, lookupError } from "./member-read.js";
|
|
23
23
|
import { implementationOf } from "./runtime-library.js";
|
|
24
24
|
/** A compile-time refusal: a tree neither backend can compile at all. */
|
|
25
25
|
export class CelCompileError extends Error {
|
|
@@ -120,37 +120,64 @@ export function plainMemberChain(node, bound) {
|
|
|
120
120
|
/**
|
|
121
121
|
* A member read in every form. Reading **through an optional** answers an optional
|
|
122
122
|
* whichever form the read is written in, which is what lets a chain over a value that
|
|
123
|
-
* may be absent stay one expression: an absent one propagates as absent, a key the
|
|
124
|
-
* value does not have is absent too
|
|
125
|
-
*
|
|
123
|
+
* may be absent stay one expression: an absent one propagates as absent, and a key the
|
|
124
|
+
* held value does not have is absent too.
|
|
125
|
+
*
|
|
126
|
+
* Which refusals are absence and which are a mistake is `lookupAbsence`'s, and it turns
|
|
127
|
+
* on the FORM the read is written in rather than on what the operand turned out to be: a
|
|
128
|
+
* presence-shaped read over a value that holds no members is absent, while the ordinary
|
|
129
|
+
* read of a member of such a value is the mistake it is outside an optional too.
|
|
126
130
|
*/
|
|
127
131
|
export function readThrough(container, key, optionalForm, range) {
|
|
132
|
+
// The shape nearly every read has — a record's own string-keyed entry — decided by asking
|
|
133
|
+
// what the container is ONCE. The general path below is three total steps, so it reads the
|
|
134
|
+
// type key twice and the prototype again; this asks each question once and falls through
|
|
135
|
+
// to the one seam for every other container, every other key and every refusal.
|
|
136
|
+
if (!optionalForm && typeof key === "string" && typeof container === "object" && container !== null) {
|
|
137
|
+
if (container[CEL_VALUE_TYPE] === undefined) {
|
|
138
|
+
const prototype = Object.getPrototypeOf(container);
|
|
139
|
+
if ((prototype === Object.prototype || prototype === null) &&
|
|
140
|
+
Object.prototype.hasOwnProperty.call(container, key)) {
|
|
141
|
+
const held = container[key];
|
|
142
|
+
// The thenable door, inline: `readHostValue` is this test and nothing else.
|
|
143
|
+
if (typeof held !== "object" || held === null || typeof held.then !== "function") {
|
|
144
|
+
return held;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
128
149
|
if (isCelOptional(container)) {
|
|
129
150
|
if (!container.present)
|
|
130
151
|
return celNone();
|
|
131
|
-
return optionalRead(container.held, key, range);
|
|
152
|
+
return optionalRead(container.held, key, optionalForm, range);
|
|
132
153
|
}
|
|
133
154
|
if (optionalForm)
|
|
134
|
-
return optionalRead(container, key, range);
|
|
155
|
+
return optionalRead(container, key, true, range);
|
|
135
156
|
// **A member read is a door a host value comes through**, and the value it answers is
|
|
136
157
|
// whatever the host put inside its own object: `readHostValue` is what refuses a thenable
|
|
137
158
|
// there, rather than the aggregate, the operator or the exit that happens to see it next.
|
|
138
159
|
return readHostValue(celRead(container, key, range), range);
|
|
139
160
|
}
|
|
140
|
-
|
|
161
|
+
/**
|
|
162
|
+
* A read that answers an optional. `presence` is whether the read was WRITTEN in a
|
|
163
|
+
* presence-shaped form (`.?`, `[?]`), which is what decides whether a value holding no
|
|
164
|
+
* members is absence or a mistake.
|
|
165
|
+
*/
|
|
166
|
+
function optionalRead(container, key, presence, range) {
|
|
141
167
|
const found = celLookup(container, key);
|
|
142
168
|
if (typeof found !== "symbol") {
|
|
143
169
|
const held = readHostValue(found, range);
|
|
144
170
|
// A value that must be awaited is refused rather than carried as a present optional.
|
|
145
171
|
return isCelError(held) ? held : celSome(held);
|
|
146
172
|
}
|
|
147
|
-
if (found
|
|
173
|
+
if (lookupAbsence(found, presence))
|
|
148
174
|
return celNone();
|
|
149
175
|
return lookupError(found, key, range);
|
|
150
176
|
}
|
|
151
177
|
/**
|
|
152
|
-
* `has(a.b)` — presence, which a missing key
|
|
153
|
-
* An absent optional has no members, and a
|
|
178
|
+
* `has(a.b)` — presence, which a missing key and a value that holds no members both
|
|
179
|
+
* answer `false` for rather than erroring. An absent optional has no members, and a
|
|
180
|
+
* present one is asked about what it holds.
|
|
154
181
|
*/
|
|
155
182
|
export function hasMember(container, field, range) {
|
|
156
183
|
if (isCelOptional(container)) {
|
|
@@ -215,7 +242,12 @@ export class CallSite {
|
|
|
215
242
|
nominalArity;
|
|
216
243
|
resolved = new BoundedCache(CALL_SITE_CACHE_CAPACITY);
|
|
217
244
|
context;
|
|
218
|
-
|
|
245
|
+
/** The arity the last resolution was made under; `-1` until there is one. */
|
|
246
|
+
count = -1;
|
|
247
|
+
t0;
|
|
248
|
+
t1;
|
|
249
|
+
t2;
|
|
250
|
+
t3;
|
|
219
251
|
lastDispatch = null;
|
|
220
252
|
constructor(name, form, range, registry, nominalArity) {
|
|
221
253
|
this.name = name;
|
|
@@ -225,23 +257,89 @@ export class CallSite {
|
|
|
225
257
|
this.nominalArity = nominalArity;
|
|
226
258
|
this.context = { range };
|
|
227
259
|
}
|
|
260
|
+
call0() {
|
|
261
|
+
if (this.count === 0)
|
|
262
|
+
return this.answer(this.lastDispatch);
|
|
263
|
+
return this.resolve(0, undefined, undefined, undefined, undefined);
|
|
264
|
+
}
|
|
265
|
+
call1(a) {
|
|
266
|
+
if (this.count === 1 && celTypeNameOf(a) === this.t0)
|
|
267
|
+
return this.answer(this.lastDispatch, a);
|
|
268
|
+
return this.resolve(1, a, undefined, undefined, undefined);
|
|
269
|
+
}
|
|
270
|
+
call2(a, b) {
|
|
271
|
+
if (this.count === 2 && celTypeNameOf(a) === this.t0 && celTypeNameOf(b) === this.t1) {
|
|
272
|
+
return this.answer(this.lastDispatch, a, b);
|
|
273
|
+
}
|
|
274
|
+
return this.resolve(2, a, b, undefined, undefined);
|
|
275
|
+
}
|
|
276
|
+
call3(a, b, c) {
|
|
277
|
+
if (this.count === 3 &&
|
|
278
|
+
celTypeNameOf(a) === this.t0 &&
|
|
279
|
+
celTypeNameOf(b) === this.t1 &&
|
|
280
|
+
celTypeNameOf(c) === this.t2) {
|
|
281
|
+
return this.answer(this.lastDispatch, a, b, c);
|
|
282
|
+
}
|
|
283
|
+
return this.resolve(3, a, b, c, undefined);
|
|
284
|
+
}
|
|
285
|
+
call4(a, b, c, d) {
|
|
286
|
+
if (this.count === 4 &&
|
|
287
|
+
celTypeNameOf(a) === this.t0 &&
|
|
288
|
+
celTypeNameOf(b) === this.t1 &&
|
|
289
|
+
celTypeNameOf(c) === this.t2 &&
|
|
290
|
+
celTypeNameOf(d) === this.t3) {
|
|
291
|
+
return this.answer(this.lastDispatch, a, b, c, d);
|
|
292
|
+
}
|
|
293
|
+
return this.resolve(4, a, b, c, d);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* The array form, for a caller that holds its arguments as one — a call written WIDER than
|
|
297
|
+
* any overload can be (`'42'.replace('2', '1', 1, false)` is five values, which is a row),
|
|
298
|
+
* the conformance and identity gates, and a host comparing a site cold against warm. It
|
|
299
|
+
* routes to the same entry points, so there is one dispatch path and not two.
|
|
300
|
+
*/
|
|
228
301
|
call(values) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
302
|
+
switch (values.length) {
|
|
303
|
+
case 0:
|
|
304
|
+
return this.call0();
|
|
305
|
+
case 1:
|
|
306
|
+
return this.call1(values[0]);
|
|
307
|
+
case 2:
|
|
308
|
+
return this.call2(values[0], values[1]);
|
|
309
|
+
case 3:
|
|
310
|
+
return this.call3(values[0], values[1], values[2]);
|
|
311
|
+
case 4:
|
|
312
|
+
return this.call4(values[0], values[1], values[2], values[3]);
|
|
313
|
+
default:
|
|
314
|
+
return this.wide(values);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* A call written with more values than the widest signature may declare. **The arity is
|
|
319
|
+
* the SOURCE's, not the dispatch key's** — anyone may write a call of any width — so this
|
|
320
|
+
* is reachable and answers the ordinary refusal, naming the types it was handed. Nothing
|
|
321
|
+
* resolves here, because a signature that wide is refused where it is registered; the
|
|
322
|
+
* resolution still runs, so one place decides what a call that resolves to nothing says.
|
|
323
|
+
*/
|
|
324
|
+
wide(values) {
|
|
325
|
+
const names = new Array(values.length);
|
|
326
|
+
for (let at = 0; at < values.length; at += 1) {
|
|
327
|
+
const held = celTypeNameOf(values[at]);
|
|
328
|
+
if (held === undefined) {
|
|
329
|
+
const named = readHostValue(values[at], this.range);
|
|
330
|
+
if (isCelError(named))
|
|
331
|
+
return named;
|
|
332
|
+
return celError("no_matching_overload", `${this.name} was handed a value of no CEL type`, this.range);
|
|
238
333
|
}
|
|
239
|
-
|
|
240
|
-
return this.answer(this.lastDispatch, values, last);
|
|
334
|
+
names[at] = held;
|
|
241
335
|
}
|
|
336
|
+
return celError("no_matching_overload", `no overload of ${JSON.stringify(this.name)} takes (${names.join(", ")})`, this.range);
|
|
337
|
+
}
|
|
338
|
+
resolve(count, a, b, c, d) {
|
|
242
339
|
const names = new Array(count);
|
|
243
340
|
for (let at = 0; at < count; at += 1) {
|
|
244
|
-
const
|
|
341
|
+
const value = at === 0 ? a : at === 1 ? b : at === 2 ? c : d;
|
|
342
|
+
const held = celTypeNameOf(value);
|
|
245
343
|
if (held === undefined) {
|
|
246
344
|
// A value of no CEL type. A **thenable** is one, and a thenable NESTED inside a host
|
|
247
345
|
// value arrives here rather than through the activation read, because a member read
|
|
@@ -249,7 +347,7 @@ export class CallSite {
|
|
|
249
347
|
// shape, so this is the door a host actually uses. `readHostValue` names it for what
|
|
250
348
|
// it is; anything else is the overload failure it was going to be. The cost is on the
|
|
251
349
|
// slow path only: dispatch was about to fail either way.
|
|
252
|
-
const named = readHostValue(
|
|
350
|
+
const named = readHostValue(value, this.range);
|
|
253
351
|
if (isCelError(named))
|
|
254
352
|
return named;
|
|
255
353
|
return celError("no_matching_overload", `${this.name} was handed a value of no CEL type`, this.range);
|
|
@@ -259,20 +357,25 @@ export class CallSite {
|
|
|
259
357
|
const key = names.join(",");
|
|
260
358
|
let dispatch = this.resolved.get(key);
|
|
261
359
|
if (dispatch === undefined) {
|
|
262
|
-
const types =
|
|
360
|
+
const types = names.map((unused, at) => runtimeType((at === 0 ? a : at === 1 ? b : at === 2 ? c : d), this.nominalArity));
|
|
263
361
|
const resolution = this.registry.resolve(this.name, this.form, this.form === "receiver" ? types.slice(1) : types, this.form === "receiver" ? types[0] : undefined);
|
|
264
362
|
dispatch = dispatchOf(this.name, resolution);
|
|
265
363
|
this.resolved.set(key, dispatch);
|
|
266
364
|
}
|
|
267
|
-
this.
|
|
365
|
+
this.count = count;
|
|
366
|
+
this.t0 = names[0];
|
|
367
|
+
this.t1 = names[1];
|
|
368
|
+
this.t2 = names[2];
|
|
369
|
+
this.t3 = names[3];
|
|
268
370
|
this.lastDispatch = dispatch;
|
|
269
|
-
return this.answer(dispatch,
|
|
371
|
+
return this.answer(dispatch, a, b, c, d);
|
|
270
372
|
}
|
|
271
|
-
answer(dispatch,
|
|
373
|
+
answer(dispatch, a, b, c, d) {
|
|
272
374
|
if (!dispatch) {
|
|
375
|
+
const names = [this.t0, this.t1, this.t2, this.t3].slice(0, Math.max(this.count, 0));
|
|
273
376
|
return celError("no_matching_overload", `no overload of ${JSON.stringify(this.name)} takes (${names.join(", ")})`, this.range);
|
|
274
377
|
}
|
|
275
|
-
const value = dispatch.implementation(
|
|
378
|
+
const value = dispatch.implementation(this.context, a, b, c, d);
|
|
276
379
|
return dispatch.foreign ? readHostValue(value, this.range) : value;
|
|
277
380
|
}
|
|
278
381
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog-runtime.d.ts","sourceRoot":"","sources":["../src/catalog-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"catalog-runtime.d.ts","sourceRoot":"","sources":["../src/catalog-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAOV,QAAQ,EACT,MAAM,gBAAgB,CAAC;AA6BxB;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IACjC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM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