@elaraai/east 1.0.68 → 1.0.70
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/src/ast.d.ts +2 -0
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast_to_ir.d.ts +7 -3
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +62 -15
- package/dist/src/ast_to_ir.js.map +1 -1
- package/dist/src/builtins.d.ts +1 -1
- package/dist/src/builtins.d.ts.map +1 -1
- package/dist/src/builtins.js +7 -0
- package/dist/src/builtins.js.map +1 -1
- package/dist/src/codegen/codegen.spec.d.ts +6 -0
- package/dist/src/codegen/codegen.spec.d.ts.map +1 -0
- package/dist/src/codegen/codegen.spec.js +763 -0
- package/dist/src/codegen/codegen.spec.js.map +1 -0
- package/dist/src/codegen/doc.d.ts +111 -0
- package/dist/src/codegen/doc.d.ts.map +1 -0
- package/dist/src/codegen/doc.js +350 -0
- package/dist/src/codegen/doc.js.map +1 -0
- package/dist/src/codegen/doc.spec.d.ts +6 -0
- package/dist/src/codegen/doc.spec.d.ts.map +1 -0
- package/dist/src/codegen/doc.spec.js +86 -0
- package/dist/src/codegen/doc.spec.js.map +1 -0
- package/dist/src/codegen/index.d.ts +15 -0
- package/dist/src/codegen/index.d.ts.map +1 -0
- package/dist/src/codegen/index.js +15 -0
- package/dist/src/codegen/index.js.map +1 -0
- package/dist/src/codegen/printer.d.ts +63 -0
- package/dist/src/codegen/printer.d.ts.map +1 -0
- package/dist/src/codegen/printer.js +1529 -0
- package/dist/src/codegen/printer.js.map +1 -0
- package/dist/src/codegen/spellings.d.ts +73 -0
- package/dist/src/codegen/spellings.d.ts.map +1 -0
- package/dist/src/codegen/spellings.js +299 -0
- package/dist/src/codegen/spellings.js.map +1 -0
- package/dist/src/codegen/spellings.spec.d.ts +6 -0
- package/dist/src/codegen/spellings.spec.d.ts.map +1 -0
- package/dist/src/codegen/spellings.spec.js +191 -0
- package/dist/src/codegen/spellings.spec.js.map +1 -0
- package/dist/src/codegen/types.d.ts +67 -0
- package/dist/src/codegen/types.d.ts.map +1 -0
- package/dist/src/codegen/types.js +173 -0
- package/dist/src/codegen/types.js.map +1 -0
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +50 -2
- package/dist/src/compile.js.map +1 -1
- package/dist/src/compile.open_beast.spec.d.ts +6 -0
- package/dist/src/compile.open_beast.spec.d.ts.map +1 -0
- package/dist/src/compile.open_beast.spec.js +99 -0
- package/dist/src/compile.open_beast.spec.js.map +1 -0
- package/dist/src/expr/blob.d.ts +41 -1
- package/dist/src/expr/blob.d.ts.map +1 -1
- package/dist/src/expr/blob.js +52 -0
- package/dist/src/expr/blob.js.map +1 -1
- package/dist/src/expr/block.d.ts +148 -0
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +168 -4
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/index.d.ts +155 -2
- package/dist/src/expr/index.d.ts.map +1 -1
- package/dist/src/expr/index.js +155 -2
- package/dist/src/expr/index.js.map +1 -1
- package/dist/src/expr/libs/datetime.d.ts +11 -0
- package/dist/src/expr/libs/datetime.d.ts.map +1 -1
- package/dist/src/expr/libs/datetime.js +11 -0
- package/dist/src/expr/libs/datetime.js.map +1 -1
- package/dist/src/functions.crossimport.spec.d.ts +6 -0
- package/dist/src/functions.crossimport.spec.d.ts.map +1 -0
- package/dist/src/functions.crossimport.spec.js +45 -0
- package/dist/src/functions.crossimport.spec.js.map +1 -0
- package/dist/src/functions.d.ts +4103 -0
- package/dist/src/functions.d.ts.map +1 -0
- package/dist/src/functions.js +443 -0
- package/dist/src/functions.js.map +1 -0
- package/dist/src/functions.spec.d.ts +6 -0
- package/dist/src/functions.spec.d.ts.map +1 -0
- package/dist/src/functions.spec.js +123 -0
- package/dist/src/functions.spec.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/naming.d.ts +50 -0
- package/dist/src/naming.d.ts.map +1 -0
- package/dist/src/naming.js +194 -0
- package/dist/src/naming.js.map +1 -0
- package/dist/src/naming.spec.d.ts +6 -0
- package/dist/src/naming.spec.d.ts.map +1 -0
- package/dist/src/naming.spec.js +154 -0
- package/dist/src/naming.spec.js.map +1 -0
- package/dist/src/serialization/beast2/index.d.ts +16 -1
- package/dist/src/serialization/beast2/index.d.ts.map +1 -1
- package/dist/src/serialization/beast2/index.js +24 -3
- package/dist/src/serialization/beast2/index.js.map +1 -1
- package/dist/src/serialization/beast2/index.spec.js +25 -0
- package/dist/src/serialization/beast2/index.spec.js.map +1 -1
- package/dist/src/serialization/beast2/shared.d.ts +1 -1
- package/dist/src/serialization/beast2/shared.d.ts.map +1 -1
- package/dist/src/serialization/beast2/shared.js +9 -1
- package/dist/src/serialization/beast2/shared.js.map +1 -1
- package/dist/src/serialization/beast2/v4/container.d.ts +10 -0
- package/dist/src/serialization/beast2/v4/container.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v4/container.js +13 -0
- package/dist/src/serialization/beast2/v4/container.js.map +1 -1
- package/dist/src/serialization/beast2/v5/frames.d.ts +17 -0
- package/dist/src/serialization/beast2/v5/frames.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/frames.js +40 -0
- package/dist/src/serialization/beast2/v5/frames.js.map +1 -1
- package/dist/src/serialization/beast2/v5/geometry.d.ts +10 -113
- package/dist/src/serialization/beast2/v5/geometry.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/geometry.js +7 -151
- package/dist/src/serialization/beast2/v5/geometry.js.map +1 -1
- package/dist/src/serialization/beast2/v5/lazy.d.ts +8 -2
- package/dist/src/serialization/beast2/v5/lazy.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/lazy.js +9 -3
- package/dist/src/serialization/beast2/v5/lazy.js.map +1 -1
- package/dist/src/serialization/beast2/v5/range.d.ts +201 -0
- package/dist/src/serialization/beast2/v5/range.d.ts.map +1 -0
- package/dist/src/serialization/beast2/v5/range.js +252 -0
- package/dist/src/serialization/beast2/v5/range.js.map +1 -0
- package/dist/src/serialization/beast2/v5/stream.d.ts +29 -5
- package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/stream.js +86 -19
- package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
- package/dist/src/serialization/beast2/v5/sync-reader.spec.d.ts +6 -0
- package/dist/src/serialization/beast2/v5/sync-reader.spec.d.ts.map +1 -0
- package/dist/src/serialization/beast2/v5/sync-reader.spec.js +228 -0
- package/dist/src/serialization/beast2/v5/sync-reader.spec.js.map +1 -0
- package/dist/src/serialization/index.d.ts +1 -1
- package/dist/src/serialization/index.d.ts.map +1 -1
- package/dist/src/serialization/index.js +1 -1
- package/dist/src/serialization/index.js.map +1 -1
- package/package.json +11 -2
package/dist/src/expr/block.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {} from "../ast.js";
|
|
6
6
|
import { ensure_source_map, get_current_source_map, get_location, get_location_id, printLocations } from "../location.js";
|
|
7
|
+
import { bindingNameAt, parameterNames } from "../naming.js";
|
|
7
8
|
import { FunctionType, isSubtype, NullType, printType, isTypeEqual, StringType, NeverType, VariantType, BooleanType, TypeUnion, IntegerType, StructType, ArrayType, AsyncFunctionType, assignTypeId } from "../types.js";
|
|
8
9
|
import { typeMismatchError } from "../type_diff.js";
|
|
9
10
|
import { AstSymbol, Expr, SourceMapSymbol, TypeSymbol } from "./expr.js";
|
|
@@ -28,6 +29,7 @@ import { isVariant } from "../containers/variant.js";
|
|
|
28
29
|
import { RefExpr } from "./ref.js";
|
|
29
30
|
import { AsyncFunctionExpr, createAsyncFunctionExpr } from "./asyncfunction.js";
|
|
30
31
|
import { PatchType } from "../patch/index.js";
|
|
32
|
+
import { applyTypeParameters, Builtins } from "../builtins.js";
|
|
31
33
|
import { VectorExpr } from "./vector.js";
|
|
32
34
|
import { MatrixExpr } from "./matrix.js";
|
|
33
35
|
/** A factory function to help build `Expr` from AST.
|
|
@@ -141,11 +143,12 @@ export function from(value, type) {
|
|
|
141
143
|
// pointer to user code (issue #204).
|
|
142
144
|
return ensure_source_map(() => {
|
|
143
145
|
const { inputs, output } = type;
|
|
144
|
-
const input_variables = inputs.map(i => ({
|
|
146
|
+
const input_variables = inputs.map((i, k) => ({
|
|
145
147
|
ast_type: "Variable",
|
|
146
148
|
type: i,
|
|
147
149
|
loc_id: get_location_id(),
|
|
148
150
|
mutable: false,
|
|
151
|
+
name: parameterNames(value)?.[k + 1],
|
|
149
152
|
}));
|
|
150
153
|
const $ = BlockBuilder(output);
|
|
151
154
|
const input_exprs = input_variables.map(fromAst);
|
|
@@ -229,11 +232,12 @@ export function from(value, type) {
|
|
|
229
232
|
}
|
|
230
233
|
return ensure_source_map(() => {
|
|
231
234
|
const { inputs, output } = type;
|
|
232
|
-
const input_variables = inputs.map(i => ({
|
|
235
|
+
const input_variables = inputs.map((i, k) => ({
|
|
233
236
|
ast_type: "Variable",
|
|
234
237
|
type: i,
|
|
235
238
|
loc_id: get_location_id(),
|
|
236
239
|
mutable: false,
|
|
240
|
+
name: parameterNames(value)?.[k + 1],
|
|
237
241
|
}));
|
|
238
242
|
const $ = BlockBuilder(output);
|
|
239
243
|
const input_exprs = input_variables.map(fromAst);
|
|
@@ -327,11 +331,12 @@ export function from(value, type) {
|
|
|
327
331
|
}
|
|
328
332
|
export function func(input_types, output_type, body) {
|
|
329
333
|
return ensure_source_map(() => {
|
|
330
|
-
const parameters = input_types.map(i => ({
|
|
334
|
+
const parameters = input_types.map((i, k) => ({
|
|
331
335
|
ast_type: "Variable",
|
|
332
336
|
type: i,
|
|
333
337
|
loc_id: get_location_id(),
|
|
334
338
|
mutable: false,
|
|
339
|
+
name: parameterNames(body)?.[k + 1],
|
|
335
340
|
}));
|
|
336
341
|
const $ = BlockBuilder(output_type ?? NeverType);
|
|
337
342
|
let ret = body($, ...parameters.map(fromAst));
|
|
@@ -413,11 +418,12 @@ export function func(input_types, output_type, body) {
|
|
|
413
418
|
}
|
|
414
419
|
export function asyncFunction(input_types, output_type, body) {
|
|
415
420
|
return ensure_source_map(() => {
|
|
416
|
-
const parameters = input_types.map(i => ({
|
|
421
|
+
const parameters = input_types.map((i, k) => ({
|
|
417
422
|
ast_type: "Variable",
|
|
418
423
|
type: i,
|
|
419
424
|
loc_id: get_location_id(),
|
|
420
425
|
mutable: false,
|
|
426
|
+
name: parameterNames(body)?.[k + 1],
|
|
421
427
|
}));
|
|
422
428
|
const $ = BlockBuilder(output_type ?? NeverType);
|
|
423
429
|
let ret = body($, ...parameters.map(fromAst));
|
|
@@ -759,6 +765,7 @@ export function matchExpr(variant, handlers) {
|
|
|
759
765
|
type: t,
|
|
760
766
|
loc_id: get_location_id(),
|
|
761
767
|
mutable: false,
|
|
768
|
+
name: parameterNames(handler)?.[1],
|
|
762
769
|
};
|
|
763
770
|
const ast = handler === undefined ? valueOrExprToAstTyped(null, NullType) : block($ => handler($, fromAst(data_variable)))[AstSymbol];
|
|
764
771
|
out_type = TypeUnion(out_type, ast.type);
|
|
@@ -784,12 +791,14 @@ export function tryCatch(try_body, catch_body) {
|
|
|
784
791
|
type: StringType,
|
|
785
792
|
loc_id: get_location_id(),
|
|
786
793
|
mutable: false,
|
|
794
|
+
name: parameterNames(catch_body)?.[1],
|
|
787
795
|
};
|
|
788
796
|
const stack_variable = {
|
|
789
797
|
ast_type: "Variable",
|
|
790
798
|
type: ArrayType(StructType({ filename: StringType, line: IntegerType, column: IntegerType })),
|
|
791
799
|
loc_id: get_location_id(),
|
|
792
800
|
mutable: false,
|
|
801
|
+
name: parameterNames(catch_body)?.[2],
|
|
793
802
|
};
|
|
794
803
|
if (typeof catch_body !== "function") {
|
|
795
804
|
throw new Error(`tryCatch expected catch_body to be a function, got ${typeof catch_body}`);
|
|
@@ -926,6 +935,107 @@ export function is(left, right) {
|
|
|
926
935
|
arguments: [Expr.ast(left), rightAst],
|
|
927
936
|
});
|
|
928
937
|
}
|
|
938
|
+
/**
|
|
939
|
+
* Calls an East builtin by name — the raw spelling for a builtin the surface
|
|
940
|
+
* has no method for, and the form the codegen printers fall back to for one
|
|
941
|
+
* (`RAW_ONLY`). The python twin is `East.builtin`.
|
|
942
|
+
*
|
|
943
|
+
* @param name - The builtin's IR name, e.g. `"ArrayGetKeys"`
|
|
944
|
+
* @param typeParameters - Its type parameters, in declaration order
|
|
945
|
+
* @param args - Its arguments in IR order — expressions, values, or callbacks
|
|
946
|
+
* @param outputType - The type of the result
|
|
947
|
+
* @returns The `Builtin` expression, typed `outputType`
|
|
948
|
+
* @throws {Error} When `name` is not a builtin, or the type-parameter or
|
|
949
|
+
* argument counts do not match its declaration
|
|
950
|
+
*
|
|
951
|
+
* @example
|
|
952
|
+
* ```ts
|
|
953
|
+
* const size = East.function([ArrayType(IntegerType)], IntegerType, ($, xs) => {
|
|
954
|
+
* $.return(East.builtin("ArraySize", [IntegerType], [xs], IntegerType));
|
|
955
|
+
* });
|
|
956
|
+
* const compiled = East.compile(size, []);
|
|
957
|
+
* compiled([1n, 2n, 3n]); // 3n
|
|
958
|
+
* ```
|
|
959
|
+
*/
|
|
960
|
+
export function builtin(name, typeParameters, args, outputType) {
|
|
961
|
+
const def = Builtins[name];
|
|
962
|
+
if (def === undefined) {
|
|
963
|
+
throw new Error(`Unknown builtin function '${name}'`);
|
|
964
|
+
}
|
|
965
|
+
if (def.type_parameters.length !== typeParameters.length) {
|
|
966
|
+
throw new Error(`Builtin function '${name}' expected ${def.type_parameters.length} type parameters, got ${typeParameters.length}`);
|
|
967
|
+
}
|
|
968
|
+
if (def.inputs.length !== args.length) {
|
|
969
|
+
throw new Error(`Builtin function '${name}' expected ${def.inputs.length} arguments, got ${args.length}`);
|
|
970
|
+
}
|
|
971
|
+
const typeMap = new Map(def.type_parameters.map((param, i) => [param, typeParameters[i]]));
|
|
972
|
+
const argAsts = args.map((arg, i) => {
|
|
973
|
+
const expected = applyTypeParameters(def.inputs[i], typeMap, [], []);
|
|
974
|
+
return valueOrExprToAstTyped(arg, expected);
|
|
975
|
+
});
|
|
976
|
+
return fromAst({
|
|
977
|
+
ast_type: "Builtin",
|
|
978
|
+
type: outputType,
|
|
979
|
+
loc_id: get_location_id(),
|
|
980
|
+
builtin: name,
|
|
981
|
+
type_parameters: typeParameters,
|
|
982
|
+
arguments: argAsts,
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Widens a value to a declared supertype explicitly — an `As` node. The
|
|
987
|
+
* builder inserts the same node itself wherever a narrower value meets a
|
|
988
|
+
* wider declared type (a `$.const(x, T)`, a function argument), so this is
|
|
989
|
+
* the spelling for the other positions; the codegen printers spell every
|
|
990
|
+
* IR `As` with it. The python twin is `East.as_`.
|
|
991
|
+
*
|
|
992
|
+
* @param value - The value or expression to widen
|
|
993
|
+
* @param type - The wider type; the value's type must be a subtype of it
|
|
994
|
+
* @returns The value as an expression of `type`
|
|
995
|
+
* @throws {Error} When the value's type is not a subtype of `type`
|
|
996
|
+
*
|
|
997
|
+
* @example
|
|
998
|
+
* ```ts
|
|
999
|
+
* const Shape = VariantType({ circle: FloatType, square: FloatType });
|
|
1000
|
+
* const widen = East.function([FloatType], Shape, ($, r) => {
|
|
1001
|
+
* $.return(East.as(East.value(variant("circle", r)), Shape));
|
|
1002
|
+
* });
|
|
1003
|
+
* const compiled = East.compile(widen, []);
|
|
1004
|
+
* compiled(2.0); // variant("circle", 2.0)
|
|
1005
|
+
* ```
|
|
1006
|
+
*/
|
|
1007
|
+
export function as(value, type) {
|
|
1008
|
+
const ast = valueOrExprToAstTyped(value, type);
|
|
1009
|
+
return fromAst({
|
|
1010
|
+
ast_type: "As",
|
|
1011
|
+
type,
|
|
1012
|
+
loc_id: get_location_id(),
|
|
1013
|
+
value: ast,
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Wraps a value or expression of a recursive type's node type in the
|
|
1018
|
+
* recursive type — a `WrapRecursive` node; {@link RecursiveExpr.unwrap} is
|
|
1019
|
+
* its inverse. The python twin is `East.wrap_recursive`.
|
|
1020
|
+
*
|
|
1021
|
+
* @param value - The value or expression of the wrapper's node type
|
|
1022
|
+
* @param type - The recursive type to wrap it in
|
|
1023
|
+
* @returns A `RecursiveExpr` of `type`
|
|
1024
|
+
*
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```ts
|
|
1027
|
+
* const ListType = RecursiveType(self => VariantType({ nil: NullType, cons: StructType({ head: IntegerType, tail: self }) }));
|
|
1028
|
+
* const singleton = East.function([IntegerType], ListType, ($, x) => {
|
|
1029
|
+
* const nil = $.const(East.wrapRecursive(variant("nil", null), ListType));
|
|
1030
|
+
* $.return(East.wrapRecursive(variant("cons", { head: x, tail: nil }), ListType));
|
|
1031
|
+
* });
|
|
1032
|
+
* const compiled = East.compile(singleton, []);
|
|
1033
|
+
* compiled(1n); // variant("cons", { head: 1n, tail: variant("nil", null) })
|
|
1034
|
+
* ```
|
|
1035
|
+
*/
|
|
1036
|
+
export function wrapRecursive(value, type) {
|
|
1037
|
+
return RecursiveExpr.wrap(value, type, fromAst);
|
|
1038
|
+
}
|
|
929
1039
|
/** Print a value as a string. */
|
|
930
1040
|
export function print(value) {
|
|
931
1041
|
const valueAst = Expr.ast(value);
|
|
@@ -1009,6 +1119,42 @@ export function invertPatch(patch, type) {
|
|
|
1009
1119
|
arguments: [patchAst],
|
|
1010
1120
|
});
|
|
1011
1121
|
}
|
|
1122
|
+
/**
|
|
1123
|
+
* The brand every declaration handle carries — a registered symbol, so a
|
|
1124
|
+
* handle built by any copy of `@elaraai/east` in the process is recognised.
|
|
1125
|
+
*/
|
|
1126
|
+
export const PLATFORM_DECLARATION = Symbol.for("elaraai.east.platformDeclaration");
|
|
1127
|
+
/**
|
|
1128
|
+
* Whether `value` is a platform declaration handle — what `East.platform`,
|
|
1129
|
+
* `East.asyncPlatform`, `East.genericPlatform` and `East.asyncGenericPlatform`
|
|
1130
|
+
* return.
|
|
1131
|
+
*
|
|
1132
|
+
* @param value - Anything
|
|
1133
|
+
* @returns True for a declaration handle, whose identity fields are then typed
|
|
1134
|
+
*
|
|
1135
|
+
* @example
|
|
1136
|
+
* ```ts
|
|
1137
|
+
* const log = East.platform("log", [StringType], NullType);
|
|
1138
|
+
* isPlatformDeclaration(log); // true
|
|
1139
|
+
* log.name; // "log"
|
|
1140
|
+
* ```
|
|
1141
|
+
*/
|
|
1142
|
+
export function isPlatformDeclaration(value) {
|
|
1143
|
+
return typeof value === "function" && value[PLATFORM_DECLARATION] === true;
|
|
1144
|
+
}
|
|
1145
|
+
/** Stamps a handle with its identity: the brand, and the declaration fields as own properties. */
|
|
1146
|
+
function brandDeclaration(fn, declaration) {
|
|
1147
|
+
Object.defineProperty(fn, PLATFORM_DECLARATION, { value: true });
|
|
1148
|
+
// a function's `name` is configurable: the handle's is the platform function's, not `fn`
|
|
1149
|
+
Object.defineProperty(fn, "name", { value: declaration.name, configurable: true });
|
|
1150
|
+
Object.defineProperty(fn, "inputs", { value: declaration.inputs, enumerable: true });
|
|
1151
|
+
Object.defineProperty(fn, "output", { value: declaration.output, enumerable: true });
|
|
1152
|
+
Object.defineProperty(fn, "async", { value: declaration.async, enumerable: true });
|
|
1153
|
+
Object.defineProperty(fn, "optional", { value: declaration.optional, enumerable: true });
|
|
1154
|
+
if (declaration.typeParameters !== undefined) {
|
|
1155
|
+
Object.defineProperty(fn, "typeParameters", { value: declaration.typeParameters, enumerable: true });
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1012
1158
|
/** Create a callable helper to invoke a synchronous platform function.
|
|
1013
1159
|
*
|
|
1014
1160
|
* Platform functions provide access to external capabilities (logging, I/O, database access, etc.)
|
|
@@ -1110,6 +1256,7 @@ export function platform(name, input_types, output_type, options = {}) {
|
|
|
1110
1256
|
};
|
|
1111
1257
|
}
|
|
1112
1258
|
};
|
|
1259
|
+
brandDeclaration(fn, { name, inputs: input_types, output: output_type, async: false, optional: isOptional });
|
|
1113
1260
|
return fn;
|
|
1114
1261
|
}
|
|
1115
1262
|
/** Create a callable helper to invoke an asynchronous platform function.
|
|
@@ -1203,6 +1350,7 @@ export function asyncPlatform(name, input_types, output_type, options = {}) {
|
|
|
1203
1350
|
};
|
|
1204
1351
|
}
|
|
1205
1352
|
};
|
|
1353
|
+
brandDeclaration(fn, { name, inputs: input_types, output: output_type, async: true, optional: isOptional });
|
|
1206
1354
|
return fn;
|
|
1207
1355
|
}
|
|
1208
1356
|
// Runtime type substitution function
|
|
@@ -1410,6 +1558,7 @@ export function genericPlatform(name, typeParams, inputs, output, options = {})
|
|
|
1410
1558
|
fn: factory,
|
|
1411
1559
|
};
|
|
1412
1560
|
};
|
|
1561
|
+
brandDeclaration(fn, { name, inputs, output, async: false, optional: isOptional, typeParameters: typeParams });
|
|
1413
1562
|
return fn;
|
|
1414
1563
|
}
|
|
1415
1564
|
/** Create a callable helper to invoke an asynchronous generic (polymorphic) platform function.
|
|
@@ -1548,6 +1697,7 @@ export function asyncGenericPlatform(name, typeParams, inputs, output, options =
|
|
|
1548
1697
|
fn: factory,
|
|
1549
1698
|
};
|
|
1550
1699
|
};
|
|
1700
|
+
brandDeclaration(fn, { name, inputs, output, async: true, optional: isOptional, typeParameters: typeParams });
|
|
1551
1701
|
return fn;
|
|
1552
1702
|
}
|
|
1553
1703
|
export const BlockBuilder = (return_type) => {
|
|
@@ -1584,6 +1734,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1584
1734
|
type: type ?? ast.type,
|
|
1585
1735
|
loc_id: get_location_id(),
|
|
1586
1736
|
mutable: false,
|
|
1737
|
+
name: bindingNameAt(get_location()) ?? undefined,
|
|
1587
1738
|
};
|
|
1588
1739
|
statements.push({
|
|
1589
1740
|
ast_type: "Let",
|
|
@@ -1613,6 +1764,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1613
1764
|
type: type ?? ast.type,
|
|
1614
1765
|
loc_id: get_location_id(),
|
|
1615
1766
|
mutable: true,
|
|
1767
|
+
name: bindingNameAt(get_location()) ?? undefined,
|
|
1616
1768
|
};
|
|
1617
1769
|
statements.push({
|
|
1618
1770
|
ast_type: "Let",
|
|
@@ -1764,6 +1916,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1764
1916
|
type: t,
|
|
1765
1917
|
loc_id: get_location_id(),
|
|
1766
1918
|
mutable: false,
|
|
1919
|
+
name: parameterNames(f)?.[1],
|
|
1767
1920
|
};
|
|
1768
1921
|
if (f === undefined) {
|
|
1769
1922
|
cases_out[k] = { variable: data_variable, body: { ast_type: "Value", type: NullType, loc_id: get_location_id(), value: null } };
|
|
@@ -1874,6 +2027,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1874
2027
|
type: Expr.type(collection).value,
|
|
1875
2028
|
loc_id: get_location_id(),
|
|
1876
2029
|
mutable: false,
|
|
2030
|
+
name: parameterNames(body)?.[1],
|
|
1877
2031
|
};
|
|
1878
2032
|
const value = fromAst(value_variable);
|
|
1879
2033
|
const key_variable = {
|
|
@@ -1881,6 +2035,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1881
2035
|
type: IntegerType,
|
|
1882
2036
|
loc_id: get_location_id(),
|
|
1883
2037
|
mutable: false,
|
|
2038
|
+
name: parameterNames(body)?.[2],
|
|
1884
2039
|
};
|
|
1885
2040
|
const key = fromAst(key_variable);
|
|
1886
2041
|
const label = { loc_id: get_location_id() };
|
|
@@ -1930,6 +2085,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1930
2085
|
type: Expr.type(collection).key,
|
|
1931
2086
|
loc_id: get_location_id(),
|
|
1932
2087
|
mutable: false,
|
|
2088
|
+
name: parameterNames(body)?.[1],
|
|
1933
2089
|
};
|
|
1934
2090
|
const key = fromAst(key_variable);
|
|
1935
2091
|
const label = { loc_id: get_location_id() };
|
|
@@ -1978,6 +2134,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1978
2134
|
type: Expr.type(collection).value,
|
|
1979
2135
|
loc_id: get_location_id(),
|
|
1980
2136
|
mutable: false,
|
|
2137
|
+
name: parameterNames(body)?.[1],
|
|
1981
2138
|
};
|
|
1982
2139
|
const value = fromAst(value_variable);
|
|
1983
2140
|
const key_variable = {
|
|
@@ -1985,6 +2142,7 @@ export const BlockBuilder = (return_type) => {
|
|
|
1985
2142
|
type: Expr.type(collection).key,
|
|
1986
2143
|
loc_id: get_location_id(),
|
|
1987
2144
|
mutable: false,
|
|
2145
|
+
name: parameterNames(body)?.[2],
|
|
1988
2146
|
};
|
|
1989
2147
|
const key = fromAst(key_variable);
|
|
1990
2148
|
const label = { loc_id: get_location_id() };
|
|
@@ -2207,6 +2365,12 @@ class TryCatchExpr extends NullExpr {
|
|
|
2207
2365
|
}
|
|
2208
2366
|
this.catchCalled = true;
|
|
2209
2367
|
const $ = BlockBuilder(this.return_type);
|
|
2368
|
+
// the handler names the catch variables (#639): `($, message, stack) => …`
|
|
2369
|
+
const names = parameterNames(body);
|
|
2370
|
+
if (names?.[1] !== undefined)
|
|
2371
|
+
this.message_variable.name = names[1];
|
|
2372
|
+
if (names?.[2] !== undefined)
|
|
2373
|
+
this.stack_variable.name = names[2];
|
|
2210
2374
|
const ret = body($, fromAst(this.message_variable), fromAst(this.stack_variable));
|
|
2211
2375
|
const stmts = $.statements;
|
|
2212
2376
|
if (ret !== undefined) {
|