@elaraai/east 0.0.1-beta.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/LICENSE.md +682 -0
- package/README.md +276 -0
- package/dist/src/analyze.d.ts +95 -0
- package/dist/src/analyze.d.ts.map +1 -0
- package/dist/src/analyze.js +1110 -0
- package/dist/src/analyze.js.map +1 -0
- package/dist/src/ast.d.ts +263 -0
- package/dist/src/ast.d.ts.map +1 -0
- package/dist/src/ast.js +151 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/ast_to_ir.d.ts +24 -0
- package/dist/src/ast_to_ir.d.ts.map +1 -0
- package/dist/src/ast_to_ir.js +834 -0
- package/dist/src/ast_to_ir.js.map +1 -0
- package/dist/src/builtins.d.ts +18 -0
- package/dist/src/builtins.d.ts.map +1 -0
- package/dist/src/builtins.js +1105 -0
- package/dist/src/builtins.js.map +1 -0
- package/dist/src/comparison.d.ts +28 -0
- package/dist/src/comparison.d.ts.map +1 -0
- package/dist/src/comparison.js +1017 -0
- package/dist/src/comparison.js.map +1 -0
- package/dist/src/compile.d.ts +22 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +3260 -0
- package/dist/src/compile.js.map +1 -0
- package/dist/src/containers/ref.d.ts +106 -0
- package/dist/src/containers/ref.d.ts.map +1 -0
- package/dist/src/containers/ref.js +100 -0
- package/dist/src/containers/ref.js.map +1 -0
- package/dist/src/containers/sortedmap.d.ts +165 -0
- package/dist/src/containers/sortedmap.d.ts.map +1 -0
- package/dist/src/containers/sortedmap.js +237 -0
- package/dist/src/containers/sortedmap.js.map +1 -0
- package/dist/src/containers/sortedset.d.ts +185 -0
- package/dist/src/containers/sortedset.d.ts.map +1 -0
- package/dist/src/containers/sortedset.js +312 -0
- package/dist/src/containers/sortedset.js.map +1 -0
- package/dist/src/containers/variant.d.ts +131 -0
- package/dist/src/containers/variant.d.ts.map +1 -0
- package/dist/src/containers/variant.js +68 -0
- package/dist/src/containers/variant.js.map +1 -0
- package/dist/src/datetime_format/parse.d.ts +50 -0
- package/dist/src/datetime_format/parse.d.ts.map +1 -0
- package/dist/src/datetime_format/parse.js +908 -0
- package/dist/src/datetime_format/parse.js.map +1 -0
- package/dist/src/datetime_format/print.d.ts +35 -0
- package/dist/src/datetime_format/print.d.ts.map +1 -0
- package/dist/src/datetime_format/print.js +157 -0
- package/dist/src/datetime_format/print.js.map +1 -0
- package/dist/src/datetime_format/tokenize.d.ts +76 -0
- package/dist/src/datetime_format/tokenize.d.ts.map +1 -0
- package/dist/src/datetime_format/tokenize.js +271 -0
- package/dist/src/datetime_format/tokenize.js.map +1 -0
- package/dist/src/datetime_format/types.d.ts +99 -0
- package/dist/src/datetime_format/types.d.ts.map +1 -0
- package/dist/src/datetime_format/types.js +103 -0
- package/dist/src/datetime_format/types.js.map +1 -0
- package/dist/src/datetime_format/validate.d.ts +51 -0
- package/dist/src/datetime_format/validate.d.ts.map +1 -0
- package/dist/src/datetime_format/validate.js +208 -0
- package/dist/src/datetime_format/validate.js.map +1 -0
- package/dist/src/default.d.ts +21 -0
- package/dist/src/default.d.ts.map +1 -0
- package/dist/src/default.js +82 -0
- package/dist/src/default.js.map +1 -0
- package/dist/src/eastir.d.ts +33 -0
- package/dist/src/eastir.d.ts.map +1 -0
- package/dist/src/eastir.js +92 -0
- package/dist/src/eastir.js.map +1 -0
- package/dist/src/error.d.ts +13 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +8 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/expr/array.d.ts +1711 -0
- package/dist/src/expr/array.d.ts.map +1 -0
- package/dist/src/expr/array.js +1805 -0
- package/dist/src/expr/array.js.map +1 -0
- package/dist/src/expr/ast.d.ts +17 -0
- package/dist/src/expr/ast.d.ts.map +1 -0
- package/dist/src/expr/ast.js +302 -0
- package/dist/src/expr/ast.js.map +1 -0
- package/dist/src/expr/blob.d.ts +141 -0
- package/dist/src/expr/blob.d.ts.map +1 -0
- package/dist/src/expr/blob.js +198 -0
- package/dist/src/expr/blob.js.map +1 -0
- package/dist/src/expr/block.d.ts +201 -0
- package/dist/src/expr/block.d.ts.map +1 -0
- package/dist/src/expr/block.js +1505 -0
- package/dist/src/expr/block.js.map +1 -0
- package/dist/src/expr/boolean.d.ts +207 -0
- package/dist/src/expr/boolean.d.ts.map +1 -0
- package/dist/src/expr/boolean.js +261 -0
- package/dist/src/expr/boolean.js.map +1 -0
- package/dist/src/expr/datetime.d.ts +544 -0
- package/dist/src/expr/datetime.d.ts.map +1 -0
- package/dist/src/expr/datetime.js +980 -0
- package/dist/src/expr/datetime.js.map +1 -0
- package/dist/src/expr/dict.d.ts +1242 -0
- package/dist/src/expr/dict.d.ts.map +1 -0
- package/dist/src/expr/dict.js +1492 -0
- package/dist/src/expr/dict.js.map +1 -0
- package/dist/src/expr/expr.d.ts +95 -0
- package/dist/src/expr/expr.d.ts.map +1 -0
- package/dist/src/expr/expr.js +171 -0
- package/dist/src/expr/expr.js.map +1 -0
- package/dist/src/expr/float.d.ts +357 -0
- package/dist/src/expr/float.d.ts.map +1 -0
- package/dist/src/expr/float.js +637 -0
- package/dist/src/expr/float.js.map +1 -0
- package/dist/src/expr/function.d.ts +46 -0
- package/dist/src/expr/function.d.ts.map +1 -0
- package/dist/src/expr/function.js +58 -0
- package/dist/src/expr/function.js.map +1 -0
- package/dist/src/expr/index.d.ts +450 -0
- package/dist/src/expr/index.d.ts.map +1 -0
- package/dist/src/expr/index.js +423 -0
- package/dist/src/expr/index.js.map +1 -0
- package/dist/src/expr/integer.d.ts +256 -0
- package/dist/src/expr/integer.d.ts.map +1 -0
- package/dist/src/expr/integer.js +311 -0
- package/dist/src/expr/integer.js.map +1 -0
- package/dist/src/expr/libs/array.d.ts +106 -0
- package/dist/src/expr/libs/array.d.ts.map +1 -0
- package/dist/src/expr/libs/array.js +140 -0
- package/dist/src/expr/libs/array.js.map +1 -0
- package/dist/src/expr/libs/blob.d.ts +42 -0
- package/dist/src/expr/libs/blob.d.ts.map +1 -0
- package/dist/src/expr/libs/blob.js +70 -0
- package/dist/src/expr/libs/blob.js.map +1 -0
- package/dist/src/expr/libs/datetime.d.ts +479 -0
- package/dist/src/expr/libs/datetime.d.ts.map +1 -0
- package/dist/src/expr/libs/datetime.js +624 -0
- package/dist/src/expr/libs/datetime.js.map +1 -0
- package/dist/src/expr/libs/dict.d.ts +66 -0
- package/dist/src/expr/libs/dict.d.ts.map +1 -0
- package/dist/src/expr/libs/dict.js +77 -0
- package/dist/src/expr/libs/dict.js.map +1 -0
- package/dist/src/expr/libs/float.d.ts +299 -0
- package/dist/src/expr/libs/float.d.ts.map +1 -0
- package/dist/src/expr/libs/float.js +564 -0
- package/dist/src/expr/libs/float.js.map +1 -0
- package/dist/src/expr/libs/integer.d.ts +228 -0
- package/dist/src/expr/libs/integer.d.ts.map +1 -0
- package/dist/src/expr/libs/integer.js +398 -0
- package/dist/src/expr/libs/integer.js.map +1 -0
- package/dist/src/expr/libs/set.d.ts +59 -0
- package/dist/src/expr/libs/set.d.ts.map +1 -0
- package/dist/src/expr/libs/set.js +69 -0
- package/dist/src/expr/libs/set.js.map +1 -0
- package/dist/src/expr/libs/string.d.ts +71 -0
- package/dist/src/expr/libs/string.d.ts.map +1 -0
- package/dist/src/expr/libs/string.js +75 -0
- package/dist/src/expr/libs/string.js.map +1 -0
- package/dist/src/expr/never.d.ts +15 -0
- package/dist/src/expr/never.d.ts.map +1 -0
- package/dist/src/expr/never.js +12 -0
- package/dist/src/expr/never.js.map +1 -0
- package/dist/src/expr/null.d.ts +15 -0
- package/dist/src/expr/null.d.ts.map +1 -0
- package/dist/src/expr/null.js +12 -0
- package/dist/src/expr/null.js.map +1 -0
- package/dist/src/expr/ref.d.ts +103 -0
- package/dist/src/expr/ref.d.ts.map +1 -0
- package/dist/src/expr/ref.js +131 -0
- package/dist/src/expr/ref.js.map +1 -0
- package/dist/src/expr/regex_validation.d.ts +25 -0
- package/dist/src/expr/regex_validation.d.ts.map +1 -0
- package/dist/src/expr/regex_validation.js +130 -0
- package/dist/src/expr/regex_validation.js.map +1 -0
- package/dist/src/expr/set.d.ts +1071 -0
- package/dist/src/expr/set.d.ts.map +1 -0
- package/dist/src/expr/set.js +1137 -0
- package/dist/src/expr/set.js.map +1 -0
- package/dist/src/expr/string.d.ts +414 -0
- package/dist/src/expr/string.d.ts.map +1 -0
- package/dist/src/expr/string.js +683 -0
- package/dist/src/expr/string.js.map +1 -0
- package/dist/src/expr/struct.d.ts +48 -0
- package/dist/src/expr/struct.d.ts.map +1 -0
- package/dist/src/expr/struct.js +65 -0
- package/dist/src/expr/struct.js.map +1 -0
- package/dist/src/expr/types.d.ts +68 -0
- package/dist/src/expr/types.d.ts.map +1 -0
- package/dist/src/expr/types.js +6 -0
- package/dist/src/expr/types.js.map +1 -0
- package/dist/src/expr/variant.d.ts +137 -0
- package/dist/src/expr/variant.d.ts.map +1 -0
- package/dist/src/expr/variant.js +105 -0
- package/dist/src/expr/variant.js.map +1 -0
- package/dist/src/fuzz.d.ts +80 -0
- package/dist/src/fuzz.d.ts.map +1 -0
- package/dist/src/fuzz.js +300 -0
- package/dist/src/fuzz.js.map +1 -0
- package/dist/src/index.d.ts +21 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/internal.d.ts +36 -0
- package/dist/src/internal.d.ts.map +1 -0
- package/dist/src/internal.js +11 -0
- package/dist/src/internal.js.map +1 -0
- package/dist/src/ir.d.ts +1571 -0
- package/dist/src/ir.d.ts.map +1 -0
- package/dist/src/ir.js +56 -0
- package/dist/src/ir.js.map +1 -0
- package/dist/src/location.d.ts +48 -0
- package/dist/src/location.d.ts.map +1 -0
- package/dist/src/location.js +62 -0
- package/dist/src/location.js.map +1 -0
- package/dist/src/platform.d.ts +21 -0
- package/dist/src/platform.d.ts.map +1 -0
- package/dist/src/platform.js +8 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/serialization/beast.d.ts +39 -0
- package/dist/src/serialization/beast.d.ts.map +1 -0
- package/dist/src/serialization/beast.js +555 -0
- package/dist/src/serialization/beast.js.map +1 -0
- package/dist/src/serialization/beast2-stream.d.ts +38 -0
- package/dist/src/serialization/beast2-stream.d.ts.map +1 -0
- package/dist/src/serialization/beast2-stream.js +665 -0
- package/dist/src/serialization/beast2-stream.js.map +1 -0
- package/dist/src/serialization/beast2.d.ts +41 -0
- package/dist/src/serialization/beast2.d.ts.map +1 -0
- package/dist/src/serialization/beast2.js +489 -0
- package/dist/src/serialization/beast2.js.map +1 -0
- package/dist/src/serialization/binary-utils.d.ts +151 -0
- package/dist/src/serialization/binary-utils.d.ts.map +1 -0
- package/dist/src/serialization/binary-utils.js +929 -0
- package/dist/src/serialization/binary-utils.js.map +1 -0
- package/dist/src/serialization/east.d.ts +84 -0
- package/dist/src/serialization/east.d.ts.map +1 -0
- package/dist/src/serialization/east.js +1802 -0
- package/dist/src/serialization/east.js.map +1 -0
- package/dist/src/serialization/index.d.ts +11 -0
- package/dist/src/serialization/index.d.ts.map +1 -0
- package/dist/src/serialization/index.js +12 -0
- package/dist/src/serialization/index.js.map +1 -0
- package/dist/src/serialization/json.d.ts +36 -0
- package/dist/src/serialization/json.d.ts.map +1 -0
- package/dist/src/serialization/json.js +849 -0
- package/dist/src/serialization/json.js.map +1 -0
- package/dist/src/type_of_type.d.ts +115 -0
- package/dist/src/type_of_type.d.ts.map +1 -0
- package/dist/src/type_of_type.js +362 -0
- package/dist/src/type_of_type.js.map +1 -0
- package/dist/src/types.d.ts +648 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +1631 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { FunctionType, type EastType, IntegerType, SetType } from "../../types.js";
|
|
6
|
+
import { Expr } from "../expr.js";
|
|
7
|
+
import type { SubtypeExprOrValue, ExprType } from "../types.js";
|
|
8
|
+
/** Standard library functions for sets */
|
|
9
|
+
declare const _default: {
|
|
10
|
+
/**
|
|
11
|
+
* Generates a set of a given size programmatically with a function from index to key.
|
|
12
|
+
*
|
|
13
|
+
* @typeParam K - The type of the set keys
|
|
14
|
+
* @param size - The number of elements to generate
|
|
15
|
+
* @param keyType - The East type of the set keys
|
|
16
|
+
* @param keyFn - A function that takes an index and returns the key at that index
|
|
17
|
+
* @param onConflict - Optional function `(key) => null` to handle duplicate keys by ignoring them
|
|
18
|
+
* @returns A set expression containing the programmatically generated keys
|
|
19
|
+
*
|
|
20
|
+
* @throws East runtime error if duplicate keys are produced and no onConflict is provided
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* If the generator produces duplicate keys, an error will be thrown by default.
|
|
24
|
+
* To handle duplicates, provide an `onConflict` function that receives the duplicate key
|
|
25
|
+
* and returns `null` to ignore it.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Generate set with string keys
|
|
30
|
+
* const makeSet = East.function([], SetType(StringType), ($) => {
|
|
31
|
+
* $.return(East.Set.generate(
|
|
32
|
+
* 3n,
|
|
33
|
+
* StringType,
|
|
34
|
+
* ($, i) => Expr.str`key${i}`
|
|
35
|
+
* ));
|
|
36
|
+
* });
|
|
37
|
+
* const compiled = East.compile(makeSet.toIR(), []);
|
|
38
|
+
* compiled(); // Set(["key0", "key1", "key2"])
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* // Generate set with conflict resolution (ignore duplicates)
|
|
44
|
+
* const makeSetConflict = East.function([], SetType(IntegerType), ($) => {
|
|
45
|
+
* $.return(East.Set.generate(
|
|
46
|
+
* 5n,
|
|
47
|
+
* IntegerType,
|
|
48
|
+
* ($, i) => i.remainder(3n), // Creates duplicates: 0,1,2,0,1
|
|
49
|
+
* ($, key) => null // Ignore duplicates
|
|
50
|
+
* ));
|
|
51
|
+
* });
|
|
52
|
+
* const compiled = East.compile(makeSetConflict.toIR(), []);
|
|
53
|
+
* compiled(); // Set([0n, 1n, 2n])
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
generate<K extends EastType>(size: Expr<IntegerType> | bigint, keyType: K, keyFn: SubtypeExprOrValue<FunctionType<[IntegerType], NoInfer<K>>>, onConflict?: SubtypeExprOrValue<FunctionType<[NoInfer<K>], NoInfer<K>>>): ExprType<SetType<K>>;
|
|
57
|
+
};
|
|
58
|
+
export default _default;
|
|
59
|
+
//# sourceMappingURL=set.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../../../src/expr/libs/set.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,KAAK,QAAQ,EAAE,WAAW,EAAY,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAa,IAAI,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEhE,0CAA0C;;IAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;aACM,CAAC,SAAS,QAAQ,QAAQ,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,WAAW,CAAC,SAAS,kBAAkB,CAAC,YAAY,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,kBAAkB,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;;AA/C/O,wBA6DC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { FunctionType, IntegerType, NullType, SetType } from "../../types.js";
|
|
6
|
+
import { AstSymbol, Expr } from "../expr.js";
|
|
7
|
+
/** Standard library functions for sets */
|
|
8
|
+
export default {
|
|
9
|
+
/**
|
|
10
|
+
* Generates a set of a given size programmatically with a function from index to key.
|
|
11
|
+
*
|
|
12
|
+
* @typeParam K - The type of the set keys
|
|
13
|
+
* @param size - The number of elements to generate
|
|
14
|
+
* @param keyType - The East type of the set keys
|
|
15
|
+
* @param keyFn - A function that takes an index and returns the key at that index
|
|
16
|
+
* @param onConflict - Optional function `(key) => null` to handle duplicate keys by ignoring them
|
|
17
|
+
* @returns A set expression containing the programmatically generated keys
|
|
18
|
+
*
|
|
19
|
+
* @throws East runtime error if duplicate keys are produced and no onConflict is provided
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* If the generator produces duplicate keys, an error will be thrown by default.
|
|
23
|
+
* To handle duplicates, provide an `onConflict` function that receives the duplicate key
|
|
24
|
+
* and returns `null` to ignore it.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Generate set with string keys
|
|
29
|
+
* const makeSet = East.function([], SetType(StringType), ($) => {
|
|
30
|
+
* $.return(East.Set.generate(
|
|
31
|
+
* 3n,
|
|
32
|
+
* StringType,
|
|
33
|
+
* ($, i) => Expr.str`key${i}`
|
|
34
|
+
* ));
|
|
35
|
+
* });
|
|
36
|
+
* const compiled = East.compile(makeSet.toIR(), []);
|
|
37
|
+
* compiled(); // Set(["key0", "key1", "key2"])
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // Generate set with conflict resolution (ignore duplicates)
|
|
43
|
+
* const makeSetConflict = East.function([], SetType(IntegerType), ($) => {
|
|
44
|
+
* $.return(East.Set.generate(
|
|
45
|
+
* 5n,
|
|
46
|
+
* IntegerType,
|
|
47
|
+
* ($, i) => i.remainder(3n), // Creates duplicates: 0,1,2,0,1
|
|
48
|
+
* ($, key) => null // Ignore duplicates
|
|
49
|
+
* ));
|
|
50
|
+
* });
|
|
51
|
+
* const compiled = East.compile(makeSetConflict.toIR(), []);
|
|
52
|
+
* compiled(); // Set([0n, 1n, 2n])
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
generate(size, keyType, keyFn, onConflict) {
|
|
56
|
+
const length_expr = Expr.from(size, IntegerType);
|
|
57
|
+
const generator_expr = Expr.from(keyFn, FunctionType([IntegerType], keyType, []));
|
|
58
|
+
const on_conflict_expr = onConflict ? Expr.from(onConflict, FunctionType([keyType], NullType, [])) : Expr.function([keyType], NullType, ($, key) => $.error(Expr.str `Duplicate key ${key} in set`));
|
|
59
|
+
return Expr.fromAst({
|
|
60
|
+
ast_type: "Builtin",
|
|
61
|
+
type: SetType(keyType),
|
|
62
|
+
builtin: "SetGenerate",
|
|
63
|
+
type_parameters: [keyType],
|
|
64
|
+
arguments: [length_expr[AstSymbol], generator_expr[AstSymbol], on_conflict_expr[AstSymbol]],
|
|
65
|
+
location: length_expr[AstSymbol].location,
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set.js","sourceRoot":"","sources":["../../../../src/expr/libs/set.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAiB,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAG7C,0CAA0C;AAC1C,eAAe;IACb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6CG;IACH,QAAQ,CAAqB,IAAgC,EAAE,OAAU,EAAE,KAAkE,EAAE,UAAuE;QACpN,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QACjD,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,KAAY,EAAE,YAAY,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QACzF,MAAM,gBAAgB,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,UAAiB,EAAE,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAA,iBAAiB,GAAG,SAAS,CAAC,CAAC,CAAC;QAE3M,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC;YACtB,OAAO,EAAE,aAAa;YACtB,eAAe,EAAE,CAAC,OAAO,CAAC;YAC1B,SAAS,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;YAC3F,QAAQ,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,QAAQ;SAC1C,CAAC,CAAC;IACL,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { type StructType, StringType, type IntegerType } from "../../types.js";
|
|
6
|
+
import type { ArrayExpr } from "../array.js";
|
|
7
|
+
import { Expr } from "../expr.js";
|
|
8
|
+
import type { StringExpr } from "../string.js";
|
|
9
|
+
/** Standard library for string values */
|
|
10
|
+
declare const _default: {
|
|
11
|
+
/**
|
|
12
|
+
* Formats an error message and stack trace in a human-readable form.
|
|
13
|
+
*
|
|
14
|
+
* @param message - The error message to display
|
|
15
|
+
* @param stack - An array of stack frames, each containing `filename`, `line`, and `column`
|
|
16
|
+
* @returns A formatted error string with the message and stack trace
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const StackFrameType = StructType({ filename: StringType, line: IntegerType, column: IntegerType });
|
|
21
|
+
*
|
|
22
|
+
* const formatError = East.function([StringType, ArrayType(StackFrameType)], StringType, ($, msg, stack) => {
|
|
23
|
+
* $.return(East.printError(msg, stack));
|
|
24
|
+
* });
|
|
25
|
+
* const compiled = East.compile(formatError.toIR(), []);
|
|
26
|
+
* const result = compiled("Division by zero", [
|
|
27
|
+
* { filename: "app.ts", line: 42n, column: 10n },
|
|
28
|
+
* { filename: "main.ts", line: 15n, column: 5n }
|
|
29
|
+
* ]);
|
|
30
|
+
* // Returns:
|
|
31
|
+
* // "Error: Division by zero
|
|
32
|
+
* // [0] app.ts 42:10
|
|
33
|
+
* // [1] main.ts 15:5"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
printError(message: StringExpr, stack: ArrayExpr<StructType<{
|
|
37
|
+
filename: StringType;
|
|
38
|
+
line: IntegerType;
|
|
39
|
+
column: IntegerType;
|
|
40
|
+
}>>): StringExpr;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a string containing East's canonical JSON representation of a value.
|
|
43
|
+
*
|
|
44
|
+
* @param value - The East value to serialize to JSON
|
|
45
|
+
* @returns A JSON string representation of the value
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
50
|
+
*
|
|
51
|
+
* const toJson = East.function([PersonType], StringType, ($, person) => {
|
|
52
|
+
* $.return(East.String.printJson(person));
|
|
53
|
+
* });
|
|
54
|
+
* const compiled = East.compile(toJson.toIR(), []);
|
|
55
|
+
* compiled({ name: "Alice", age: 30n }); // '{"name":"Alice","age":30}'
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* // Array to JSON
|
|
61
|
+
* const arrayToJson = East.function([ArrayType(IntegerType)], StringType, ($, arr) => {
|
|
62
|
+
* $.return(East.String.printJson(arr));
|
|
63
|
+
* });
|
|
64
|
+
* const compiled = East.compile(arrayToJson.toIR(), []);
|
|
65
|
+
* compiled([1n, 2n, 3n]); // '[1,2,3]'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
printJson(value: Expr): StringExpr;
|
|
69
|
+
};
|
|
70
|
+
export default _default;
|
|
71
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../../src/expr/libs/string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,UAAU,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,yCAAyC;;IAEvC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;wBACiB,UAAU,SAAS,SAAS,CAAC,UAAU,CAAC;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,IAAI,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC,GAAG,UAAU;IAI3I;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;qBACc,IAAI,GAAG,UAAU;;AAzDpC,wBAmEC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { StringType } from "../../types.js";
|
|
6
|
+
import { Expr } from "../expr.js";
|
|
7
|
+
/** Standard library for string values */
|
|
8
|
+
export default {
|
|
9
|
+
/**
|
|
10
|
+
* Formats an error message and stack trace in a human-readable form.
|
|
11
|
+
*
|
|
12
|
+
* @param message - The error message to display
|
|
13
|
+
* @param stack - An array of stack frames, each containing `filename`, `line`, and `column`
|
|
14
|
+
* @returns A formatted error string with the message and stack trace
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const StackFrameType = StructType({ filename: StringType, line: IntegerType, column: IntegerType });
|
|
19
|
+
*
|
|
20
|
+
* const formatError = East.function([StringType, ArrayType(StackFrameType)], StringType, ($, msg, stack) => {
|
|
21
|
+
* $.return(East.printError(msg, stack));
|
|
22
|
+
* });
|
|
23
|
+
* const compiled = East.compile(formatError.toIR(), []);
|
|
24
|
+
* const result = compiled("Division by zero", [
|
|
25
|
+
* { filename: "app.ts", line: 42n, column: 10n },
|
|
26
|
+
* { filename: "main.ts", line: 15n, column: 5n }
|
|
27
|
+
* ]);
|
|
28
|
+
* // Returns:
|
|
29
|
+
* // "Error: Division by zero
|
|
30
|
+
* // [0] app.ts 42:10
|
|
31
|
+
* // [1] main.ts 15:5"
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
printError(message, stack) {
|
|
35
|
+
return Expr.str `Error: ${message}\n ${stack.map((_$, { filename, line, column }, i) => Expr.str `[${i}] ${filename} ${line}:${column}`).stringJoin("\n ")}`;
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Creates a string containing East's canonical JSON representation of a value.
|
|
39
|
+
*
|
|
40
|
+
* @param value - The East value to serialize to JSON
|
|
41
|
+
* @returns A JSON string representation of the value
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const PersonType = StructType({ name: StringType, age: IntegerType });
|
|
46
|
+
*
|
|
47
|
+
* const toJson = East.function([PersonType], StringType, ($, person) => {
|
|
48
|
+
* $.return(East.String.printJson(person));
|
|
49
|
+
* });
|
|
50
|
+
* const compiled = East.compile(toJson.toIR(), []);
|
|
51
|
+
* compiled({ name: "Alice", age: 30n }); // '{"name":"Alice","age":30}'
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // Array to JSON
|
|
57
|
+
* const arrayToJson = East.function([ArrayType(IntegerType)], StringType, ($, arr) => {
|
|
58
|
+
* $.return(East.String.printJson(arr));
|
|
59
|
+
* });
|
|
60
|
+
* const compiled = East.compile(arrayToJson.toIR(), []);
|
|
61
|
+
* compiled([1n, 2n, 3n]); // '[1,2,3]'
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
printJson(value) {
|
|
65
|
+
return Expr.fromAst({
|
|
66
|
+
ast_type: "Builtin",
|
|
67
|
+
type: StringType,
|
|
68
|
+
builtin: "StringPrintJSON",
|
|
69
|
+
location: { filename: "stdlib", line: 1, column: 1 },
|
|
70
|
+
type_parameters: [Expr.type(value)],
|
|
71
|
+
arguments: [Expr.ast(value)],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../../../src/expr/libs/string.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAmB,UAAU,EAAoB,MAAM,gBAAgB,CAAC;AAE/E,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGlC,yCAAyC;AACzC,eAAe;IACb;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,UAAU,CAAC,OAAmB,EAAE,KAA8F;QAC5H,OAAO,IAAI,CAAC,GAAG,CAAA,UAAU,OAAO,SAAS,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAA,IAAI,CAAC,KAAK,QAAQ,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;IACnK,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,SAAS,CAAC,KAAW;QACnB,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,iBAAiB;YAC1B,QAAQ,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;YACpD,eAAe,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnC,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC7B,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import type { AST } from "../ast.js";
|
|
6
|
+
import { NeverType } from "../types.js";
|
|
7
|
+
import { Expr, type ToExpr } from "./expr.js";
|
|
8
|
+
/**
|
|
9
|
+
* Expression representing the Never type (bottom type).
|
|
10
|
+
* Used for error expressions and unreachable code paths.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NeverExpr extends Expr<NeverType> {
|
|
13
|
+
constructor(ast: AST, createExpr: ToExpr);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=never.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"never.d.ts","sourceRoot":"","sources":["../../../src/expr/never.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAE9C;;;GAGG;AACH,qBAAa,SAAU,SAAQ,IAAI,CAAC,SAAS,CAAC;gBAChC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM;CAGzC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NeverType } from "../types.js";
|
|
2
|
+
import { Expr } from "./expr.js";
|
|
3
|
+
/**
|
|
4
|
+
* Expression representing the Never type (bottom type).
|
|
5
|
+
* Used for error expressions and unreachable code paths.
|
|
6
|
+
*/
|
|
7
|
+
export class NeverExpr extends Expr {
|
|
8
|
+
constructor(ast, createExpr) {
|
|
9
|
+
super(NeverType, ast, createExpr);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=never.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"never.js","sourceRoot":"","sources":["../../../src/expr/never.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAe,MAAM,WAAW,CAAC;AAE9C;;;GAGG;AACH,MAAM,OAAO,SAAU,SAAQ,IAAe;IAC5C,YAAY,GAAQ,EAAE,UAAkB;QACtC,KAAK,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import type { AST } from "../ast.js";
|
|
6
|
+
import { NullType } from "../types.js";
|
|
7
|
+
import { Expr, type ToExpr } from "./expr.js";
|
|
8
|
+
/**
|
|
9
|
+
* Expression representing the Null type (unit/void type).
|
|
10
|
+
* Used for null values and statement expressions.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NullExpr extends Expr<NullType> {
|
|
13
|
+
constructor(ast: AST, createExpr: ToExpr);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=null.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null.d.ts","sourceRoot":"","sources":["../../../src/expr/null.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAE9C;;;EAGE;AACF,qBAAa,QAAS,SAAQ,IAAI,CAAC,QAAQ,CAAC;gBAC9B,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM;CAGzC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NullType } from "../types.js";
|
|
2
|
+
import { Expr } from "./expr.js";
|
|
3
|
+
/**
|
|
4
|
+
* Expression representing the Null type (unit/void type).
|
|
5
|
+
* Used for null values and statement expressions.
|
|
6
|
+
*/
|
|
7
|
+
export class NullExpr extends Expr {
|
|
8
|
+
constructor(ast, createExpr) {
|
|
9
|
+
super(NullType, ast, createExpr);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=null.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null.js","sourceRoot":"","sources":["../../../src/expr/null.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,IAAI,EAAe,MAAM,WAAW,CAAC;AAE9C;;;EAGE;AACF,MAAM,OAAO,QAAS,SAAQ,IAAc;IAC1C,YAAY,GAAQ,EAAE,UAAkB;QACtC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import type { AST } from "../ast.js";
|
|
6
|
+
import { FunctionType, NullType, RefType } from "../types.js";
|
|
7
|
+
import { Expr, type ToExpr } from "./expr.js";
|
|
8
|
+
import type { ExprType, SubtypeExprOrValue } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Expression representing reference cells (mutable containers) in East.
|
|
11
|
+
*
|
|
12
|
+
* RefExpr provides a reference cell type that can be shared across closures and modified.
|
|
13
|
+
* Unlike variables declared with `$.let()`, references can be captured and modified from
|
|
14
|
+
* within nested functions, making them useful for shared mutable state.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // Creating and getting a reference value
|
|
19
|
+
* const getRefValue = East.function([], IntegerType, ($) => {
|
|
20
|
+
* const counter = $.let(East.value(ref(42n)));
|
|
21
|
+
* $.return(counter.get());
|
|
22
|
+
* });
|
|
23
|
+
* const compiled = East.compile(getRefValue.toIR(), []);
|
|
24
|
+
* compiled(); // 42n
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Updating a reference value
|
|
30
|
+
* const updateRef = East.function([IntegerType], IntegerType, ($, newValue) => {
|
|
31
|
+
* const counter = $.let(East.value(ref(0n)));
|
|
32
|
+
* $(counter.update(newValue));
|
|
33
|
+
* $.return(counter.get());
|
|
34
|
+
* });
|
|
35
|
+
* const compiled = East.compile(updateRef.toIR(), []);
|
|
36
|
+
* compiled(100n); // 100n
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class RefExpr<T extends any> extends Expr<RefType<T>> {
|
|
40
|
+
private value_type;
|
|
41
|
+
constructor(value_type: T, ast: AST, createExpr: ToExpr);
|
|
42
|
+
/**
|
|
43
|
+
* Gets the current value stored in the reference cell.
|
|
44
|
+
*
|
|
45
|
+
* @returns An expression of the value type stored in the reference
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const getRefValue = East.function([], IntegerType, ($) => {
|
|
50
|
+
* const counter = $.let(East.value(ref(42n)));
|
|
51
|
+
* $.return(counter.get());
|
|
52
|
+
* });
|
|
53
|
+
* const compiled = East.compile(getRefValue.toIR(), []);
|
|
54
|
+
* compiled(); // 42n
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
get(): ExprType<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Replaces the value in the reference cell with a new value.
|
|
60
|
+
*
|
|
61
|
+
* @param value - The new value to store in the reference cell
|
|
62
|
+
* @returns A NullExpr (used for side effects)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const updateRef = East.function([IntegerType], IntegerType, ($, newValue) => {
|
|
67
|
+
* const counter = $.let(East.value(ref(0n)));
|
|
68
|
+
* $(counter.update(newValue));
|
|
69
|
+
* $.return(counter.get());
|
|
70
|
+
* });
|
|
71
|
+
* const compiled = East.compile(updateRef.toIR(), []);
|
|
72
|
+
* compiled(100n); // 100n
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see {@link merge} for modifying the value based on its current value.
|
|
76
|
+
*/
|
|
77
|
+
update(value: ExprType<T>): Expr<NullType>;
|
|
78
|
+
/**
|
|
79
|
+
* Modifies the reference value by merging it with a new value using a function.
|
|
80
|
+
*
|
|
81
|
+
* This is useful for patterns where you want to update a reference based on its current value,
|
|
82
|
+
* e.g. incrementing a number, appending to a string, updating fields in a struct, or pushing to an array.
|
|
83
|
+
*
|
|
84
|
+
* @param value - The new value to merge with the current value
|
|
85
|
+
* @param updateFn - Function that takes (current, new) and returns the merged value
|
|
86
|
+
* @returns A NullExpr (used for side effects)
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const incrementRef = East.function([IntegerType], IntegerType, ($, delta) => {
|
|
91
|
+
* const counter = $.let(East.value(ref(10n)));
|
|
92
|
+
* $(counter.merge(delta, ($, current, newVal) => current.add(newVal)));
|
|
93
|
+
* $.return(counter.get());
|
|
94
|
+
* });
|
|
95
|
+
* const compiled = East.compile(incrementRef.toIR(), []);
|
|
96
|
+
* compiled(5n); // 15n
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @see {@link update} for simply replacing the value.
|
|
100
|
+
*/
|
|
101
|
+
merge<T2>(value: Expr<T2>, updateFn: SubtypeExprOrValue<FunctionType<[T, NoInfer<T2>], T>>): ExprType<NullType>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../../src/expr/ref.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAiB,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAa,IAAI,EAA6B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,OAAO,CAAC,CAAC,SAAS,GAAG,CAAE,SAAQ,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,UAAU;gBAAV,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM;IAI/D;;;;;;;;;;;;;;OAcG;IACH,GAAG,IAAI,QAAQ,CAAC,CAAC,CAAC;IAWlB;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;IAW1C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC;CAehH"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { get_location } from "../location.js";
|
|
2
|
+
import { FunctionType, NullType, RefType } from "../types.js";
|
|
3
|
+
import { AstSymbol, Expr, FactorySymbol, TypeSymbol } from "./expr.js";
|
|
4
|
+
/**
|
|
5
|
+
* Expression representing reference cells (mutable containers) in East.
|
|
6
|
+
*
|
|
7
|
+
* RefExpr provides a reference cell type that can be shared across closures and modified.
|
|
8
|
+
* Unlike variables declared with `$.let()`, references can be captured and modified from
|
|
9
|
+
* within nested functions, making them useful for shared mutable state.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Creating and getting a reference value
|
|
14
|
+
* const getRefValue = East.function([], IntegerType, ($) => {
|
|
15
|
+
* const counter = $.let(East.value(ref(42n)));
|
|
16
|
+
* $.return(counter.get());
|
|
17
|
+
* });
|
|
18
|
+
* const compiled = East.compile(getRefValue.toIR(), []);
|
|
19
|
+
* compiled(); // 42n
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // Updating a reference value
|
|
25
|
+
* const updateRef = East.function([IntegerType], IntegerType, ($, newValue) => {
|
|
26
|
+
* const counter = $.let(East.value(ref(0n)));
|
|
27
|
+
* $(counter.update(newValue));
|
|
28
|
+
* $.return(counter.get());
|
|
29
|
+
* });
|
|
30
|
+
* const compiled = East.compile(updateRef.toIR(), []);
|
|
31
|
+
* compiled(100n); // 100n
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class RefExpr extends Expr {
|
|
35
|
+
value_type;
|
|
36
|
+
constructor(value_type, ast, createExpr) {
|
|
37
|
+
super(RefType(value_type), ast, createExpr);
|
|
38
|
+
this.value_type = value_type;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Gets the current value stored in the reference cell.
|
|
42
|
+
*
|
|
43
|
+
* @returns An expression of the value type stored in the reference
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const getRefValue = East.function([], IntegerType, ($) => {
|
|
48
|
+
* const counter = $.let(East.value(ref(42n)));
|
|
49
|
+
* $.return(counter.get());
|
|
50
|
+
* });
|
|
51
|
+
* const compiled = East.compile(getRefValue.toIR(), []);
|
|
52
|
+
* compiled(); // 42n
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
get() {
|
|
56
|
+
return this[FactorySymbol]({
|
|
57
|
+
ast_type: "Builtin",
|
|
58
|
+
type: this.value_type,
|
|
59
|
+
location: get_location(2),
|
|
60
|
+
builtin: "RefGet",
|
|
61
|
+
type_parameters: [this.value_type],
|
|
62
|
+
arguments: [Expr.ast(this)],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Replaces the value in the reference cell with a new value.
|
|
67
|
+
*
|
|
68
|
+
* @param value - The new value to store in the reference cell
|
|
69
|
+
* @returns A NullExpr (used for side effects)
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const updateRef = East.function([IntegerType], IntegerType, ($, newValue) => {
|
|
74
|
+
* const counter = $.let(East.value(ref(0n)));
|
|
75
|
+
* $(counter.update(newValue));
|
|
76
|
+
* $.return(counter.get());
|
|
77
|
+
* });
|
|
78
|
+
* const compiled = East.compile(updateRef.toIR(), []);
|
|
79
|
+
* compiled(100n); // 100n
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @see {@link merge} for modifying the value based on its current value.
|
|
83
|
+
*/
|
|
84
|
+
update(value) {
|
|
85
|
+
return this[FactorySymbol]({
|
|
86
|
+
ast_type: "Builtin",
|
|
87
|
+
type: NullType,
|
|
88
|
+
location: get_location(2),
|
|
89
|
+
builtin: "RefUpdate",
|
|
90
|
+
type_parameters: [this.value_type],
|
|
91
|
+
arguments: [Expr.ast(this), Expr.ast(value)],
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Modifies the reference value by merging it with a new value using a function.
|
|
96
|
+
*
|
|
97
|
+
* This is useful for patterns where you want to update a reference based on its current value,
|
|
98
|
+
* e.g. incrementing a number, appending to a string, updating fields in a struct, or pushing to an array.
|
|
99
|
+
*
|
|
100
|
+
* @param value - The new value to merge with the current value
|
|
101
|
+
* @param updateFn - Function that takes (current, new) and returns the merged value
|
|
102
|
+
* @returns A NullExpr (used for side effects)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* const incrementRef = East.function([IntegerType], IntegerType, ($, delta) => {
|
|
107
|
+
* const counter = $.let(East.value(ref(10n)));
|
|
108
|
+
* $(counter.merge(delta, ($, current, newVal) => current.add(newVal)));
|
|
109
|
+
* $.return(counter.get());
|
|
110
|
+
* });
|
|
111
|
+
* const compiled = East.compile(incrementRef.toIR(), []);
|
|
112
|
+
* compiled(5n); // 15n
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @see {@link update} for simply replacing the value.
|
|
116
|
+
*/
|
|
117
|
+
merge(value, updateFn) {
|
|
118
|
+
const location = get_location(2);
|
|
119
|
+
const value2Type = value[TypeSymbol];
|
|
120
|
+
const updateFnExpr = Expr.from(updateFn, FunctionType([value2Type, this.value_type], this.value_type, null));
|
|
121
|
+
return this[FactorySymbol]({
|
|
122
|
+
ast_type: "Builtin",
|
|
123
|
+
type: NullType,
|
|
124
|
+
location,
|
|
125
|
+
builtin: "RefMerge",
|
|
126
|
+
type_parameters: [this.value_type, value2Type],
|
|
127
|
+
arguments: [this[AstSymbol], value[AstSymbol], updateFnExpr[AstSymbol]],
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/expr/ref.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAiB,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAe,MAAM,WAAW,CAAC;AAGpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,OAAuB,SAAQ,IAAgB;IACtC;IAApB,YAAoB,UAAa,EAAE,GAAQ,EAAE,UAAkB;QAC7D,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;QAD1B,eAAU,GAAV,UAAU,CAAG;IAEjC,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,GAAG;QACD,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;YACzB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,IAAI,CAAC,UAAsB;YACjC,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;YACzB,OAAO,EAAE,QAAQ;YACjB,eAAe,EAAE,CAAC,IAAI,CAAC,UAAsB,CAAC;YAC9C,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SAC5B,CAAgB,CAAC;IACpB,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,KAAkB;QACvB,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;YACzB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;YACzB,OAAO,EAAE,WAAW;YACpB,eAAe,EAAE,CAAC,IAAI,CAAC,UAAsB,CAAC;YAC9C,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC7C,CAAmB,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAK,KAAe,EAAE,QAA+D;QACxF,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;QAErC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,QAAe,EAAE,YAAY,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;QAEpH,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;YACzB,QAAQ,EAAE,SAAS;YACnB,IAAI,EAAE,QAAQ;YACd,QAAQ;YACR,OAAO,EAAE,UAAU;YACnB,eAAe,EAAE,CAAC,IAAI,CAAC,UAAsB,EAAE,UAAsB,CAAC;YACtE,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;SACxE,CAAuB,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
interface ValidationResult {
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
warnings: string[];
|
|
8
|
+
errors: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function validateCrossPlatformCompatible(regex: RegExp): ValidationResult;
|
|
11
|
+
export declare function runCompatibilityTests(): void;
|
|
12
|
+
export declare const RECOMMENDED_PATTERNS: {
|
|
13
|
+
email: RegExp;
|
|
14
|
+
phoneUS: RegExp;
|
|
15
|
+
uuid: RegExp;
|
|
16
|
+
ipv4: RegExp;
|
|
17
|
+
url: RegExp;
|
|
18
|
+
identifier: RegExp;
|
|
19
|
+
number: RegExp;
|
|
20
|
+
whitespace: RegExp;
|
|
21
|
+
word: RegExp;
|
|
22
|
+
lineBreak: RegExp;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=regex_validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex_validation.d.ts","sourceRoot":"","sources":["../../../src/expr/regex_validation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,UAAU,gBAAgB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,CAkB/E;AAqED,wBAAgB,qBAAqB,IAAI,IAAI,CAyC5C;AAGD,eAAO,MAAM,oBAAoB;;;;;;;;;;;CAWhC,CAAC"}
|