@elaraai/east 0.0.1-beta.9 → 1.0.1
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 +15 -666
- package/README.md +113 -88
- package/dist/src/analyze.d.ts +3 -0
- package/dist/src/analyze.d.ts.map +1 -1
- package/dist/src/analyze.js +223 -111
- package/dist/src/analyze.js.map +1 -1
- package/dist/src/analyze.spec.d.ts +2 -0
- package/dist/src/analyze.spec.d.ts.map +1 -0
- package/dist/src/analyze.spec.js +445 -0
- package/dist/src/analyze.spec.js.map +1 -0
- package/dist/src/ast.d.ts +54 -35
- package/dist/src/ast.d.ts.map +1 -1
- package/dist/src/ast_to_ir.coerce_to.spec.d.ts +15 -0
- package/dist/src/ast_to_ir.coerce_to.spec.d.ts.map +1 -0
- package/dist/src/ast_to_ir.coerce_to.spec.js +420 -0
- package/dist/src/ast_to_ir.coerce_to.spec.js.map +1 -0
- package/dist/src/ast_to_ir.d.ts +18 -4
- package/dist/src/ast_to_ir.d.ts.map +1 -1
- package/dist/src/ast_to_ir.js +233 -178
- 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 +194 -2
- package/dist/src/builtins.js.map +1 -1
- package/dist/src/comparison.d.ts +2 -2
- package/dist/src/comparison.d.ts.map +1 -1
- package/dist/src/comparison.js +115 -40
- package/dist/src/comparison.js.map +1 -1
- package/dist/src/comparison.spec.d.ts +2 -0
- package/dist/src/comparison.spec.d.ts.map +1 -0
- package/dist/src/comparison.spec.js +1200 -0
- package/dist/src/comparison.spec.js.map +1 -0
- package/dist/src/compile.d.ts +31 -9
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +1048 -548
- package/dist/src/compile.js.map +1 -1
- package/dist/src/containers/matrix.d.ts +15 -0
- package/dist/src/containers/matrix.d.ts.map +1 -0
- package/dist/src/containers/matrix.js +15 -0
- package/dist/src/containers/matrix.js.map +1 -0
- package/dist/src/containers/ref.d.ts.map +1 -1
- package/dist/src/containers/ref.js +1 -1
- package/dist/src/containers/ref.js.map +1 -1
- package/dist/src/containers/sortedmap.spec.d.ts +2 -0
- package/dist/src/containers/sortedmap.spec.d.ts.map +1 -0
- package/dist/src/containers/sortedmap.spec.js +180 -0
- package/dist/src/containers/sortedmap.spec.js.map +1 -0
- package/dist/src/containers/sortedset.spec.d.ts +2 -0
- package/dist/src/containers/sortedset.spec.d.ts.map +1 -0
- package/dist/src/containers/sortedset.spec.js +228 -0
- package/dist/src/containers/sortedset.spec.js.map +1 -0
- package/dist/src/containers/variant.d.ts.map +1 -1
- package/dist/src/containers/variant.js +1 -1
- package/dist/src/containers/variant.js.map +1 -1
- package/dist/src/containers/variant.spec.d.ts +2 -0
- package/dist/src/containers/variant.spec.d.ts.map +1 -0
- package/dist/src/containers/variant.spec.js +217 -0
- package/dist/src/containers/variant.spec.js.map +1 -0
- package/dist/src/datetime_format/parse.spec.d.ts +6 -0
- package/dist/src/datetime_format/parse.spec.d.ts.map +1 -0
- package/dist/src/datetime_format/parse.spec.js +379 -0
- package/dist/src/datetime_format/parse.spec.js.map +1 -0
- package/dist/src/datetime_format/print.spec.d.ts +6 -0
- package/dist/src/datetime_format/print.spec.d.ts.map +1 -0
- package/dist/src/datetime_format/print.spec.js +257 -0
- package/dist/src/datetime_format/print.spec.js.map +1 -0
- package/dist/src/datetime_format/tokenize.spec.d.ts +2 -0
- package/dist/src/datetime_format/tokenize.spec.d.ts.map +1 -0
- package/dist/src/datetime_format/tokenize.spec.js +508 -0
- package/dist/src/datetime_format/tokenize.spec.js.map +1 -0
- package/dist/src/datetime_format/types.d.ts +23 -23
- package/dist/src/default.d.ts.map +1 -1
- package/dist/src/default.js +33 -0
- package/dist/src/default.js.map +1 -1
- package/dist/src/default.spec.d.ts +2 -0
- package/dist/src/default.spec.d.ts.map +1 -0
- package/dist/src/default.spec.js +178 -0
- package/dist/src/default.spec.js.map +1 -0
- package/dist/src/eastir.d.ts +7 -0
- package/dist/src/eastir.d.ts.map +1 -1
- package/dist/src/eastir.js +55 -7
- package/dist/src/eastir.js.map +1 -1
- package/dist/src/error.d.ts +14 -4
- package/dist/src/error.d.ts.map +1 -1
- package/dist/src/error.js +28 -3
- package/dist/src/error.js.map +1 -1
- package/dist/src/example.d.ts +87 -0
- package/dist/src/example.d.ts.map +1 -0
- package/dist/src/example.js +18 -0
- package/dist/src/example.js.map +1 -0
- package/dist/src/expr/array.d.ts +43 -1
- package/dist/src/expr/array.d.ts.map +1 -1
- package/dist/src/expr/array.js +103 -53
- package/dist/src/expr/array.js.map +1 -1
- package/dist/src/expr/ast.d.ts +1 -1
- package/dist/src/expr/ast.d.ts.map +1 -1
- package/dist/src/expr/ast.js +112 -54
- package/dist/src/expr/ast.js.map +1 -1
- package/dist/src/expr/asyncfunction.d.ts.map +1 -1
- package/dist/src/expr/asyncfunction.js +6 -4
- package/dist/src/expr/asyncfunction.js.map +1 -1
- package/dist/src/expr/blob.d.ts +48 -0
- package/dist/src/expr/blob.d.ts.map +1 -1
- package/dist/src/expr/blob.js +63 -8
- package/dist/src/expr/blob.js.map +1 -1
- package/dist/src/expr/block.d.ts +213 -12
- package/dist/src/expr/block.d.ts.map +1 -1
- package/dist/src/expr/block.js +796 -293
- package/dist/src/expr/block.js.map +1 -1
- package/dist/src/expr/boolean.d.ts +44 -0
- package/dist/src/expr/boolean.d.ts.map +1 -1
- package/dist/src/expr/boolean.js +58 -6
- package/dist/src/expr/boolean.js.map +1 -1
- package/dist/src/expr/datetime.d.ts +135 -0
- package/dist/src/expr/datetime.d.ts.map +1 -1
- package/dist/src/expr/datetime.js +184 -34
- package/dist/src/expr/datetime.js.map +1 -1
- package/dist/src/expr/dict.d.ts +47 -2
- package/dist/src/expr/dict.d.ts.map +1 -1
- package/dist/src/expr/dict.js +122 -61
- package/dist/src/expr/dict.js.map +1 -1
- package/dist/src/expr/expr.d.ts +3 -1
- package/dist/src/expr/expr.d.ts.map +1 -1
- package/dist/src/expr/expr.js +4 -3
- package/dist/src/expr/expr.js.map +1 -1
- package/dist/src/expr/float.d.ts +153 -0
- package/dist/src/expr/float.d.ts.map +1 -1
- package/dist/src/expr/float.js +191 -17
- package/dist/src/expr/float.js.map +1 -1
- package/dist/src/expr/function.d.ts +7 -2
- package/dist/src/expr/function.d.ts.map +1 -1
- package/dist/src/expr/function.js +6 -4
- package/dist/src/expr/function.js.map +1 -1
- package/dist/src/expr/index.d.ts +186 -2
- package/dist/src/expr/index.d.ts.map +1 -1
- package/dist/src/expr/index.js +183 -2
- package/dist/src/expr/index.js.map +1 -1
- package/dist/src/expr/integer.d.ts +180 -0
- package/dist/src/expr/integer.d.ts.map +1 -1
- package/dist/src/expr/integer.js +189 -18
- package/dist/src/expr/integer.js.map +1 -1
- package/dist/src/expr/libs/array.js +3 -3
- package/dist/src/expr/libs/array.js.map +1 -1
- package/dist/src/expr/libs/blob.js +3 -3
- package/dist/src/expr/libs/blob.js.map +1 -1
- package/dist/src/expr/libs/dict.js +1 -1
- package/dist/src/expr/libs/dict.js.map +1 -1
- package/dist/src/expr/libs/matrix.d.ts +17 -0
- package/dist/src/expr/libs/matrix.d.ts.map +1 -0
- package/dist/src/expr/libs/matrix.js +60 -0
- package/dist/src/expr/libs/matrix.js.map +1 -0
- package/dist/src/expr/libs/set.js +1 -1
- package/dist/src/expr/libs/set.js.map +1 -1
- package/dist/src/expr/libs/string.d.ts.map +1 -1
- package/dist/src/expr/libs/string.js +2 -1
- package/dist/src/expr/libs/string.js.map +1 -1
- package/dist/src/expr/libs/vector.d.ts +16 -0
- package/dist/src/expr/libs/vector.d.ts.map +1 -0
- package/dist/src/expr/libs/vector.js +44 -0
- package/dist/src/expr/libs/vector.js.map +1 -0
- package/dist/src/expr/matrix.d.ts +109 -0
- package/dist/src/expr/matrix.d.ts.map +1 -0
- package/dist/src/expr/matrix.js +224 -0
- package/dist/src/expr/matrix.js.map +1 -0
- package/dist/src/expr/recursive.d.ts +83 -0
- package/dist/src/expr/recursive.d.ts.map +1 -0
- package/dist/src/expr/recursive.js +99 -0
- package/dist/src/expr/recursive.js.map +1 -0
- package/dist/src/expr/ref.js +5 -5
- package/dist/src/expr/ref.js.map +1 -1
- package/dist/src/expr/set.d.ts +44 -2
- package/dist/src/expr/set.d.ts.map +1 -1
- package/dist/src/expr/set.js +102 -52
- package/dist/src/expr/set.js.map +1 -1
- package/dist/src/expr/string.d.ts +134 -0
- package/dist/src/expr/string.d.ts.map +1 -1
- package/dist/src/expr/string.js +173 -23
- package/dist/src/expr/string.js.map +1 -1
- package/dist/src/expr/struct.d.ts +1 -1
- package/dist/src/expr/struct.d.ts.map +1 -1
- package/dist/src/expr/struct.js +2 -2
- package/dist/src/expr/struct.js.map +1 -1
- package/dist/src/expr/types.d.ts +12 -9
- package/dist/src/expr/types.d.ts.map +1 -1
- package/dist/src/expr/variant.d.ts +108 -11
- package/dist/src/expr/variant.d.ts.map +1 -1
- package/dist/src/expr/variant.js +76 -38
- package/dist/src/expr/variant.js.map +1 -1
- package/dist/src/expr/vector.d.ts +102 -0
- package/dist/src/expr/vector.d.ts.map +1 -0
- package/dist/src/expr/vector.js +202 -0
- package/dist/src/expr/vector.js.map +1 -0
- package/dist/src/fuzz.d.ts +36 -2
- package/dist/src/fuzz.d.ts.map +1 -1
- package/dist/src/fuzz.js +409 -77
- package/dist/src/fuzz.js.map +1 -1
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/internal.d.ts +12 -2
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +13 -2
- package/dist/src/internal.js.map +1 -1
- package/dist/src/ir.d.ts +1754 -1484
- package/dist/src/ir.d.ts.map +1 -1
- package/dist/src/ir.js +51 -34
- package/dist/src/ir.js.map +1 -1
- package/dist/src/ir.spec.d.ts +2 -0
- package/dist/src/ir.spec.d.ts.map +1 -0
- package/dist/src/ir.spec.js +35 -0
- package/dist/src/ir.spec.js.map +1 -0
- package/dist/src/location.d.ts +56 -17
- package/dist/src/location.d.ts.map +1 -1
- package/dist/src/location.js +226 -29
- package/dist/src/location.js.map +1 -1
- package/dist/src/location.spec.d.ts +2 -0
- package/dist/src/location.spec.d.ts.map +1 -0
- package/dist/src/location.spec.js +102 -0
- package/dist/src/location.spec.js.map +1 -0
- package/dist/src/patch/apply.d.ts +15 -0
- package/dist/src/patch/apply.d.ts.map +1 -0
- package/dist/src/patch/apply.js +352 -0
- package/dist/src/patch/apply.js.map +1 -0
- package/dist/src/patch/compose.d.ts +15 -0
- package/dist/src/patch/compose.d.ts.map +1 -0
- package/dist/src/patch/compose.js +448 -0
- package/dist/src/patch/compose.js.map +1 -0
- package/dist/src/patch/diff.d.ts +15 -0
- package/dist/src/patch/diff.d.ts.map +1 -0
- package/dist/src/patch/diff.js +347 -0
- package/dist/src/patch/diff.js.map +1 -0
- package/dist/src/patch/fuzz.d.ts +73 -0
- package/dist/src/patch/fuzz.d.ts.map +1 -0
- package/dist/src/patch/fuzz.js +159 -0
- package/dist/src/patch/fuzz.js.map +1 -0
- package/dist/src/patch/index.d.ts +32 -0
- package/dist/src/patch/index.d.ts.map +1 -0
- package/dist/src/patch/index.js +48 -0
- package/dist/src/patch/index.js.map +1 -0
- package/dist/src/patch/invert.d.ts +15 -0
- package/dist/src/patch/invert.d.ts.map +1 -0
- package/dist/src/patch/invert.js +284 -0
- package/dist/src/patch/invert.js.map +1 -0
- package/dist/src/patch/merge.d.ts +56 -0
- package/dist/src/patch/merge.d.ts.map +1 -0
- package/dist/src/patch/merge.js +586 -0
- package/dist/src/patch/merge.js.map +1 -0
- package/dist/src/patch/merge.spec.d.ts +2 -0
- package/dist/src/patch/merge.spec.d.ts.map +1 -0
- package/dist/src/patch/merge.spec.js +1139 -0
- package/dist/src/patch/merge.spec.js.map +1 -0
- package/dist/src/patch/patch.spec.d.ts +2 -0
- package/dist/src/patch/patch.spec.d.ts.map +1 -0
- package/dist/src/patch/patch.spec.js +452 -0
- package/dist/src/patch/patch.spec.js.map +1 -0
- package/dist/src/patch/path.d.ts +115 -0
- package/dist/src/patch/path.d.ts.map +1 -0
- package/dist/src/patch/path.js +192 -0
- package/dist/src/patch/path.js.map +1 -0
- package/dist/src/patch/path.spec.d.ts +6 -0
- package/dist/src/patch/path.spec.d.ts.map +1 -0
- package/dist/src/patch/path.spec.js +322 -0
- package/dist/src/patch/path.spec.js.map +1 -0
- package/dist/src/patch/prune.d.ts +77 -0
- package/dist/src/patch/prune.d.ts.map +1 -0
- package/dist/src/patch/prune.js +115 -0
- package/dist/src/patch/prune.js.map +1 -0
- package/dist/src/patch/prune.spec.d.ts +6 -0
- package/dist/src/patch/prune.spec.d.ts.map +1 -0
- package/dist/src/patch/prune.spec.js +473 -0
- package/dist/src/patch/prune.spec.js.map +1 -0
- package/dist/src/patch/type_of_patch.d.ts +25 -0
- package/dist/src/patch/type_of_patch.d.ts.map +1 -0
- package/dist/src/patch/type_of_patch.js +144 -0
- package/dist/src/patch/type_of_patch.js.map +1 -0
- package/dist/src/patch/types.d.ts +220 -0
- package/dist/src/patch/types.d.ts.map +1 -0
- package/dist/src/patch/types.js +62 -0
- package/dist/src/patch/types.js.map +1 -0
- package/dist/src/patch/validate.d.ts +44 -0
- package/dist/src/patch/validate.d.ts.map +1 -0
- package/dist/src/patch/validate.js +190 -0
- package/dist/src/patch/validate.js.map +1 -0
- package/dist/src/patch/validate.spec.d.ts +6 -0
- package/dist/src/patch/validate.spec.d.ts.map +1 -0
- package/dist/src/patch/validate.spec.js +225 -0
- package/dist/src/patch/validate.spec.js.map +1 -0
- package/dist/src/patch/walk.d.ts +121 -0
- package/dist/src/patch/walk.d.ts.map +1 -0
- package/dist/src/patch/walk.js +385 -0
- package/dist/src/patch/walk.js.map +1 -0
- package/dist/src/patch/walk.spec.d.ts +6 -0
- package/dist/src/patch/walk.spec.d.ts.map +1 -0
- package/dist/src/patch/walk.spec.js +621 -0
- package/dist/src/patch/walk.spec.js.map +1 -0
- package/dist/src/platform.d.ts +6 -0
- package/dist/src/platform.d.ts.map +1 -1
- package/dist/src/platform.spec.d.ts +2 -0
- package/dist/src/platform.spec.d.ts.map +1 -0
- package/dist/src/platform.spec.js +330 -0
- package/dist/src/platform.spec.js.map +1 -0
- package/dist/src/serialization/beast.d.ts.map +1 -1
- package/dist/src/serialization/beast.js +12 -0
- package/dist/src/serialization/beast.js.map +1 -1
- package/dist/src/serialization/beast.spec.d.ts +6 -0
- package/dist/src/serialization/beast.spec.d.ts.map +1 -0
- package/dist/src/serialization/beast.spec.js +406 -0
- package/dist/src/serialization/beast.spec.js.map +1 -0
- package/dist/src/serialization/beast2/index.d.ts +50 -0
- package/dist/src/serialization/beast2/index.d.ts.map +1 -0
- package/dist/src/serialization/beast2/index.js +756 -0
- package/dist/src/serialization/beast2/index.js.map +1 -0
- package/dist/src/serialization/beast2/index.spec.d.ts +6 -0
- package/dist/src/serialization/beast2/index.spec.d.ts.map +1 -0
- package/dist/src/serialization/beast2/index.spec.js +528 -0
- package/dist/src/serialization/beast2/index.spec.js.map +1 -0
- package/dist/src/serialization/beast2/sourcemap-table.d.ts +29 -0
- package/dist/src/serialization/beast2/sourcemap-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/sourcemap-table.js +82 -0
- package/dist/src/serialization/beast2/sourcemap-table.js.map +1 -0
- package/dist/src/serialization/beast2/string-table.d.ts +16 -0
- package/dist/src/serialization/beast2/string-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/string-table.js +38 -0
- package/dist/src/serialization/beast2/string-table.js.map +1 -0
- package/dist/src/serialization/beast2/type-table.d.ts +86 -0
- package/dist/src/serialization/beast2/type-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/type-table.js +618 -0
- package/dist/src/serialization/beast2/type-table.js.map +1 -0
- package/dist/src/serialization/beast2/value-table.d.ts +40 -0
- package/dist/src/serialization/beast2/value-table.d.ts.map +1 -0
- package/dist/src/serialization/beast2/value-table.js +157 -0
- package/dist/src/serialization/beast2/value-table.js.map +1 -0
- package/dist/src/serialization/binary-utils.d.ts +33 -0
- package/dist/src/serialization/binary-utils.d.ts.map +1 -1
- package/dist/src/serialization/binary-utils.js +157 -0
- package/dist/src/serialization/binary-utils.js.map +1 -1
- package/dist/src/serialization/csv.d.ts +17 -17
- package/dist/src/serialization/csv.d.ts.map +1 -1
- package/dist/src/serialization/csv.js +10 -8
- package/dist/src/serialization/csv.js.map +1 -1
- package/dist/src/serialization/csv.spec.d.ts +2 -0
- package/dist/src/serialization/csv.spec.d.ts.map +1 -0
- package/dist/src/serialization/csv.spec.js +556 -0
- package/dist/src/serialization/csv.spec.js.map +1 -0
- package/dist/src/serialization/east-inferred.spec.d.ts +2 -0
- package/dist/src/serialization/east-inferred.spec.d.ts.map +1 -0
- package/dist/src/serialization/east-inferred.spec.js +322 -0
- package/dist/src/serialization/east-inferred.spec.js.map +1 -0
- package/dist/src/serialization/east.d.ts +1 -1
- package/dist/src/serialization/east.d.ts.map +1 -1
- package/dist/src/serialization/east.js +178 -26
- package/dist/src/serialization/east.js.map +1 -1
- package/dist/src/serialization/east.spec.d.ts +2 -0
- package/dist/src/serialization/east.spec.d.ts.map +1 -0
- package/dist/src/serialization/east.spec.js +1548 -0
- package/dist/src/serialization/east.spec.js.map +1 -0
- package/dist/src/serialization/index.d.ts +1 -2
- package/dist/src/serialization/index.d.ts.map +1 -1
- package/dist/src/serialization/index.js +1 -2
- package/dist/src/serialization/index.js.map +1 -1
- package/dist/src/serialization/json.d.ts +1 -1
- package/dist/src/serialization/json.d.ts.map +1 -1
- package/dist/src/serialization/json.js +123 -24
- package/dist/src/serialization/json.js.map +1 -1
- package/dist/src/serialization/json.spec.d.ts +2 -0
- package/dist/src/serialization/json.spec.d.ts.map +1 -0
- package/dist/src/serialization/json.spec.js +1297 -0
- package/dist/src/serialization/json.spec.js.map +1 -0
- package/dist/src/type_of_type.d.ts +72 -35
- package/dist/src/type_of_type.d.ts.map +1 -1
- package/dist/src/type_of_type.is_data.spec.d.ts +6 -0
- package/dist/src/type_of_type.is_data.spec.d.ts.map +1 -0
- package/dist/src/type_of_type.is_data.spec.js +221 -0
- package/dist/src/type_of_type.is_data.spec.js.map +1 -0
- package/dist/src/type_of_type.js +355 -80
- package/dist/src/type_of_type.js.map +1 -1
- package/dist/src/type_of_type.to_etv.spec.d.ts +6 -0
- package/dist/src/type_of_type.to_etv.spec.d.ts.map +1 -0
- package/dist/src/type_of_type.to_etv.spec.js +263 -0
- package/dist/src/type_of_type.to_etv.spec.js.map +1 -0
- package/dist/src/types.d.ts +82 -12
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.error.spec.d.ts +2 -0
- package/dist/src/types.error.spec.d.ts.map +1 -0
- package/dist/src/types.error.spec.js +665 -0
- package/dist/src/types.error.spec.js.map +1 -0
- package/dist/src/types.js +663 -156
- package/dist/src/types.js.map +1 -1
- package/dist/src/types.spec.d.ts +2 -0
- package/dist/src/types.spec.d.ts.map +1 -0
- package/dist/src/types.spec.js +946 -0
- package/dist/src/types.spec.js.map +1 -0
- package/dist/src/walker.d.ts +65 -0
- package/dist/src/walker.d.ts.map +1 -0
- package/dist/src/walker.js +165 -0
- package/dist/src/walker.js.map +1 -0
- package/dist/src/walker.spec.d.ts +6 -0
- package/dist/src/walker.spec.d.ts.map +1 -0
- package/dist/src/walker.spec.js +109 -0
- package/dist/src/walker.spec.js.map +1 -0
- package/package.json +16 -38
- package/dist/src/serialization/beast2-stream.d.ts +0 -38
- package/dist/src/serialization/beast2-stream.d.ts.map +0 -1
- package/dist/src/serialization/beast2-stream.js +0 -670
- package/dist/src/serialization/beast2-stream.js.map +0 -1
- package/dist/src/serialization/beast2.d.ts +0 -41
- package/dist/src/serialization/beast2.d.ts.map +0 -1
- package/dist/src/serialization/beast2.js +0 -495
- package/dist/src/serialization/beast2.js.map +0 -1
package/dist/src/expr/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
4
|
*/
|
|
5
5
|
import type { variant } from "../containers/variant.js";
|
|
6
|
-
import type { ArrayType, BooleanType, FloatType, FunctionType, IntegerType, NeverType, NullType, StructType, StringType, VariantType, SubType, SetType, DictType, DateTimeType, BlobType, RecursiveType, RecursiveTypeMarker, RefType, AsyncFunctionType } from "../types.js";
|
|
6
|
+
import type { ArrayType, BooleanType, FloatType, FunctionType, IntegerType, NeverType, NullType, StructType, StringType, VariantType, SubType, SetType, DictType, DateTimeType, BlobType, RecursiveType, RecursiveTypeMarker, RefType, AsyncFunctionType, VectorType, MatrixType } from "../types.js";
|
|
7
7
|
import type { Expr } from "./expr.js";
|
|
8
8
|
import type { NeverExpr } from "./never.js";
|
|
9
9
|
import type { NullExpr } from "./null.js";
|
|
@@ -18,24 +18,27 @@ import type { SetExpr } from "./set.js";
|
|
|
18
18
|
import type { DictExpr } from "./dict.js";
|
|
19
19
|
import type { StructExpr } from "./struct.js";
|
|
20
20
|
import type { VariantExpr } from "./variant.js";
|
|
21
|
+
import type { RecursiveExpr } from "./recursive.js";
|
|
21
22
|
import type { CallableFunctionExpr } from "./function.js";
|
|
22
23
|
import type { BlockBuilder } from "./block.js";
|
|
23
24
|
import type { ref } from "../containers/ref.js";
|
|
24
25
|
import type { RefExpr } from "./ref.js";
|
|
25
26
|
import type { CallableAsyncFunctionExpr } from "./asyncfunction.js";
|
|
27
|
+
import type { VectorExpr } from "./vector.js";
|
|
28
|
+
import type { MatrixExpr } from "./matrix.js";
|
|
26
29
|
/**
|
|
27
30
|
* Type mapping for values that can be passed to expression methods
|
|
28
31
|
* Maps East types to their corresponding expression classes or JavaScript values
|
|
29
32
|
*/
|
|
30
|
-
export type SubtypeExprOrValue<T> = T extends never ? never : T extends NeverType ? Expr<NeverType> : T extends NullType ? Expr<NeverType> | Expr<NullType> | null : T extends BooleanType ? Expr<NeverType> | Expr<BooleanType> | boolean : T extends IntegerType ? Expr<NeverType> | Expr<IntegerType> | bigint : T extends FloatType ? Expr<NeverType> | Expr<FloatType> | number : T extends StringType ? Expr<NeverType> | Expr<StringType> | string : T extends DateTimeType ? Expr<NeverType> | Expr<DateTimeType> | Date : T extends BlobType ? Expr<NeverType> | Expr<BlobType> | Uint8Array : T extends RefType<infer U> ? Expr<NeverType> | Expr<RefType<U>> | ref<SubtypeExprOrValue<U>> : T extends ArrayType<infer V> ? Expr<NeverType> | Expr<ArrayType<V>> | SubtypeExprOrValue<V>[] : T extends SetType<infer K> ? Expr<NeverType> | Expr<SetType<K>> | Set<SubtypeExprOrValue<K>> : T extends DictType<infer K, infer V> ? Expr<NeverType> | Expr<DictType<K, V>> | Map<SubtypeExprOrValue<K>, SubtypeExprOrValue<V>> : T extends StructType<infer Fields> ? Expr<NeverType> | Expr<StructType<{
|
|
33
|
+
export type SubtypeExprOrValue<T> = T extends never ? never : T extends NeverType ? Expr<NeverType> : T extends NullType ? Expr<NeverType> | Expr<NullType> | null : T extends BooleanType ? Expr<NeverType> | Expr<BooleanType> | boolean : T extends IntegerType ? Expr<NeverType> | Expr<IntegerType> | bigint : T extends FloatType ? Expr<NeverType> | Expr<FloatType> | number : T extends StringType ? Expr<NeverType> | Expr<StringType> | string : T extends DateTimeType ? Expr<NeverType> | Expr<DateTimeType> | Date : T extends BlobType ? Expr<NeverType> | Expr<BlobType> | Uint8Array : T extends RefType<infer U> ? Expr<NeverType> | Expr<RefType<U>> | ref<SubtypeExprOrValue<U>> : T extends ArrayType<infer V> ? Expr<NeverType> | Expr<ArrayType<V>> | SubtypeExprOrValue<V>[] : T extends VectorType<infer V> ? Expr<NeverType> | Expr<VectorType<V>> | Float64Array | BigInt64Array | Uint8ClampedArray : T extends MatrixType<infer V> ? Expr<NeverType> | Expr<MatrixType<V>> : T extends SetType<infer K> ? Expr<NeverType> | Expr<SetType<K>> | Set<SubtypeExprOrValue<K>> : T extends DictType<infer K, infer V> ? Expr<NeverType> | Expr<DictType<K, V>> | Map<SubtypeExprOrValue<K>, SubtypeExprOrValue<V>> : T extends StructType<infer Fields> ? Expr<NeverType> | Expr<StructType<{
|
|
31
34
|
[K in keyof Fields]: SubType<Fields[K]>;
|
|
32
35
|
}>> | {
|
|
33
36
|
[K in keyof Fields]: SubtypeExprOrValue<Fields[K]>;
|
|
34
|
-
} : T extends VariantType<infer Cases> ? Expr<NeverType> | Expr<VariantType<{
|
|
37
|
+
} : T extends RecursiveType<infer U> ? RecursiveExpr<ExpandOnce<U, T>> | SubtypeExprOrValue<U> : T extends VariantType<infer Cases> ? Expr<NeverType> | Expr<VariantType<{
|
|
35
38
|
[K in keyof Cases]?: SubType<Cases[K]>;
|
|
36
39
|
}>> | {
|
|
37
40
|
[K in keyof Cases]: variant<K, SubtypeExprOrValue<Cases[K]>>;
|
|
38
|
-
}[keyof Cases] : T extends
|
|
41
|
+
}[keyof Cases] : T extends RecursiveTypeMarker ? any : T extends FunctionType<infer I, undefined> ? Expr<FunctionType<I, any>> | (($: BlockBuilder<NeverType>, ...input: {
|
|
39
42
|
[K in keyof I]: ExprType<I[K]>;
|
|
40
43
|
}) => any) : T extends FunctionType<infer I, infer O> ? Expr<FunctionType<I, SubType<O>>> | (($: BlockBuilder<O>, ...input: {
|
|
41
44
|
[K in keyof I]: ExprType<I[K]>;
|
|
@@ -45,21 +48,21 @@ export type SubtypeExprOrValue<T> = T extends never ? never : T extends NeverTyp
|
|
|
45
48
|
[K in keyof I]: ExprType<I[K]>;
|
|
46
49
|
}) => void | SubtypeExprOrValue<O>) : Expr<NeverType> | Expr<T>;
|
|
47
50
|
/** Expand a given recursive type one level deeper */
|
|
48
|
-
export type ExpandOnce<T, NodeType> = T extends RefType<infer U> ? RefType<ExpandOnce<U, NodeType>> : T extends ArrayType<infer U> ? ArrayType<ExpandOnce<U, NodeType>> : T extends SetType<infer U> ? SetType<ExpandOnce<U, NodeType>> : T extends DictType<infer K, infer V> ? DictType<ExpandOnce<K, NodeType>, ExpandOnce<V, NodeType>> : T extends StructType<infer Fields> ? StructType<{
|
|
51
|
+
export type ExpandOnce<T, NodeType> = T extends RefType<infer U> ? RefType<ExpandOnce<U, NodeType>> : T extends ArrayType<infer U> ? ArrayType<ExpandOnce<U, NodeType>> : T extends VectorType<infer V> ? VectorType<ExpandOnce<V, NodeType>> : T extends MatrixType<infer V> ? MatrixType<ExpandOnce<V, NodeType>> : T extends SetType<infer U> ? SetType<ExpandOnce<U, NodeType>> : T extends DictType<infer K, infer V> ? DictType<ExpandOnce<K, NodeType>, ExpandOnce<V, NodeType>> : T extends StructType<infer Fields> ? StructType<{
|
|
49
52
|
[K in keyof Fields]: ExpandOnce<Fields[K], NodeType>;
|
|
50
|
-
}> : T extends VariantType<infer Cases> ? VariantType<{
|
|
53
|
+
}> : T extends RecursiveType<infer U> ? RecursiveType<U> : T extends VariantType<infer Cases> ? VariantType<{
|
|
51
54
|
[K in keyof Cases]: ExpandOnce<Cases[K], NodeType>;
|
|
52
|
-
}> : T extends
|
|
55
|
+
}> : T extends RecursiveTypeMarker ? NodeType : T;
|
|
53
56
|
/**
|
|
54
57
|
* Type mapping from East types to their corresponding expression classes
|
|
55
58
|
* This is the key type that provides concrete expression types to user code
|
|
56
59
|
*/
|
|
57
|
-
export type ExprType<T> = T extends never ? never : T extends NeverType ? NeverExpr : T extends NeverType | NullType ? NullExpr : T extends NeverType | BooleanType ? BooleanExpr : T extends NeverType | IntegerType ? IntegerExpr : T extends NeverType | FloatType ? FloatExpr : T extends NeverType | StringType ? StringExpr : T extends NeverType | DateTimeType ? DateTimeExpr : T extends NeverType | BlobType ? BlobExpr : T extends NeverType | RefType<infer U> ? RefExpr<U> : T extends NeverType | ArrayType<infer V> ? ArrayExpr<V> : T extends NeverType | SetType<infer K> ? SetExpr<K> : T extends NeverType | DictType<infer K, infer V> ? DictExpr<K, V> : T extends NeverType | StructType<infer Fields> ? StructExpr<Fields> : T extends NeverType |
|
|
60
|
+
export type ExprType<T> = T extends never ? never : T extends NeverType ? NeverExpr : T extends NeverType | NullType ? NullExpr : T extends NeverType | BooleanType ? BooleanExpr : T extends NeverType | IntegerType ? IntegerExpr : T extends NeverType | FloatType ? FloatExpr : T extends NeverType | StringType ? StringExpr : T extends NeverType | DateTimeType ? DateTimeExpr : T extends NeverType | BlobType ? BlobExpr : T extends NeverType | RefType<infer U> ? RefExpr<U> : T extends NeverType | ArrayType<infer V> ? ArrayExpr<V> : T extends NeverType | VectorType<infer V> ? VectorExpr<V> : T extends NeverType | MatrixType<infer V> ? MatrixExpr<V> : T extends NeverType | SetType<infer K> ? SetExpr<K> : T extends NeverType | DictType<infer K, infer V> ? DictExpr<K, V> : T extends NeverType | StructType<infer Fields> ? StructExpr<Fields> : T extends NeverType | RecursiveType<infer U> ? RecursiveExpr<ExpandOnce<U, T>> : T extends NeverType | VariantType<infer Cases> ? VariantExpr<Cases> : T extends NeverType | RecursiveTypeMarker ? RecursiveExpr<any> : T extends NeverType | FunctionType<infer I, infer O> ? CallableFunctionExpr<I, O> : T extends NeverType | AsyncFunctionType<infer I, infer O> ? CallableAsyncFunctionExpr<I, O> : Expr<T>;
|
|
58
61
|
/**
|
|
59
62
|
* Type mapping from JavaScript/Expression values to East types
|
|
60
63
|
* Used for type inference in factory methods
|
|
61
64
|
*/
|
|
62
|
-
export type TypeOf<T> = T extends never ? never : T extends Expr<NeverType> ? NeverType : T extends null | Expr<NullType> ? NullType : T extends boolean | Expr<BooleanType> ? BooleanType : T extends bigint | Expr<IntegerType> ? IntegerType : T extends number | Expr<FloatType> ? FloatType : T extends string | Expr<StringType> ? StringType : T extends Date | Expr<DateTimeType> ? DateTimeType : T extends Uint8Array | Expr<BlobType> ? BlobType : T extends Expr<RefType<infer U>> ? RefType<U> : T extends ref<infer U> ? RefType<TypeOf<U>> : T extends Expr<ArrayType<infer U>> ? ArrayType<U> : T extends Array<infer U> ? ArrayType<TypeOf<U>> : T extends Expr<SetType<infer U>> ? SetType<U> : T extends Set<infer U> ? SetType<TypeOf<U>> : T extends Expr<DictType<infer K, infer V>> ? DictType<K, V> : T extends Map<infer K, infer V> ? DictType<TypeOf<K>, TypeOf<V>> : T extends Expr<FunctionType<infer I, infer O>> ? FunctionType<I, O> : T extends Expr<VariantType<infer Cases>> ? VariantType<Cases> : T extends variant<infer Case, infer U> ? Case extends string ? VariantType<{
|
|
65
|
+
export type TypeOf<T> = T extends never ? never : T extends Expr<NeverType> ? NeverType : T extends null | Expr<NullType> ? NullType : T extends boolean | Expr<BooleanType> ? BooleanType : T extends bigint | Expr<IntegerType> ? IntegerType : T extends number | Expr<FloatType> ? FloatType : T extends string | Expr<StringType> ? StringType : T extends Date | Expr<DateTimeType> ? DateTimeType : T extends Float64Array ? VectorType<FloatType> : T extends BigInt64Array ? VectorType<IntegerType> : T extends Uint8ClampedArray ? VectorType<BooleanType> : T extends Uint8Array | Expr<BlobType> ? BlobType : T extends Expr<RefType<infer U>> ? RefType<U> : T extends ref<infer U> ? RefType<TypeOf<U>> : T extends Expr<ArrayType<infer U>> ? ArrayType<U> : T extends Array<infer U> ? ArrayType<TypeOf<U>> : T extends Expr<SetType<infer U>> ? SetType<U> : T extends Set<infer U> ? SetType<TypeOf<U>> : T extends Expr<DictType<infer K, infer V>> ? DictType<K, V> : T extends Map<infer K, infer V> ? DictType<TypeOf<K>, TypeOf<V>> : T extends Expr<FunctionType<infer I, infer O>> ? FunctionType<I, O> : T extends Expr<RecursiveType<infer _U>> ? (T extends Expr<infer R> ? R : never) : T extends Expr<VariantType<infer Cases>> ? VariantType<Cases> : T extends variant<infer Case, infer U> ? Case extends string ? VariantType<{
|
|
63
66
|
[K in Case]: TypeOf<U>;
|
|
64
67
|
}> : never : T extends Expr<StructType<infer Fields>> ? StructType<keyof Fields extends keyof T ? {
|
|
65
68
|
[K in (string & keyof T)]: TypeOf<T[K]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/expr/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OA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,CAAC,SAAS,OAAO,CAAC,MAAM,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,SAAS,MAAM,GAAG,WAAW,CAAC;KAAG,CAAC,IAAI,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;CAAE,CAAC,GAAG,KAAK,GAE9G,CAAC,SAAS,IAAI,CAAC,UAAU,CAAC,MAAM,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,MAAM,SAAS,MAAM,CAAC,GAAG;KAAG,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAAG;KAAG,CAAC,IAAI,MAAM,MAAM,GAAG,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CAAE,CAAC,GACzM,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAC3B,UAAU,CAAC;KAAG,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC,CAAC"}
|
|
@@ -6,7 +6,8 @@ import type { AST } from "../ast.js";
|
|
|
6
6
|
import { BooleanType, NeverType, StringType, TypeUnion, VariantType } from "../types.js";
|
|
7
7
|
import type { BlockBuilder } from "./block.js";
|
|
8
8
|
import { Expr, type ToExpr } from "./expr.js";
|
|
9
|
-
import type { ExprType, TypeOf } from "./types.js";
|
|
9
|
+
import type { ExprType, TypeOf, SubtypeExprOrValue } from "./types.js";
|
|
10
|
+
import type { BooleanExpr } from "./boolean.js";
|
|
10
11
|
/**
|
|
11
12
|
* Expression representing variant (sum type/tagged union) values.
|
|
12
13
|
*
|
|
@@ -134,17 +135,17 @@ export declare class VariantExpr<Cases extends Record<string, any>> extends Expr
|
|
|
134
135
|
unwrap<Case extends keyof Cases>(name: Case): ExprType<Cases[Case]>;
|
|
135
136
|
unwrap(): "some" extends keyof Cases ? ExprType<Cases["some"]> : ExprType<NeverType>;
|
|
136
137
|
/**
|
|
137
|
-
* Pattern match on this variant
|
|
138
|
+
* Pattern match on this variant.
|
|
138
139
|
*
|
|
139
|
-
* This method
|
|
140
|
-
*
|
|
141
|
-
*
|
|
140
|
+
* This method supports two modes:
|
|
141
|
+
* 1. **Exhaustive matching**: Provide handlers for all cases, no default needed
|
|
142
|
+
* 2. **Partial matching**: Provide handlers for some cases with a default fallback
|
|
142
143
|
*
|
|
143
|
-
* @typeParam Handlers -
|
|
144
|
-
* @typeParam Default - Type of the default handler function
|
|
145
|
-
* @param handlers - Object mapping case names to handler functions
|
|
146
|
-
* @param defaultHandler -
|
|
147
|
-
* @returns Expression of the union type of all handler return types
|
|
144
|
+
* @typeParam Handlers - Record of case handlers (all cases required for exhaustive, partial for default mode)
|
|
145
|
+
* @typeParam Default - Type of the default handler function (only for partial matching)
|
|
146
|
+
* @param handlers - Object mapping case names to handler functions
|
|
147
|
+
* @param defaultHandler - Optional handler for unmatched cases (required if not all cases are handled)
|
|
148
|
+
* @returns Expression of the union type of all handler return types
|
|
148
149
|
*
|
|
149
150
|
* @see {@link Expr.match} for exhaustive pattern matching requiring all cases
|
|
150
151
|
* @see {@link unwrap} for extracting a single case value
|
|
@@ -153,7 +154,23 @@ export declare class VariantExpr<Cases extends Record<string, any>> extends Expr
|
|
|
153
154
|
* ```ts
|
|
154
155
|
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
155
156
|
*
|
|
156
|
-
* //
|
|
157
|
+
* // Exhaustive matching - all cases handled, no default needed
|
|
158
|
+
* const getValue = East.function([OptionType], IntegerType, ($, opt) => {
|
|
159
|
+
* $.return(opt.match({
|
|
160
|
+
* some: ($, val) => val,
|
|
161
|
+
* none: ($) => 0n
|
|
162
|
+
* }));
|
|
163
|
+
* });
|
|
164
|
+
* const compiled = East.compile(getValue.toIR(), []);
|
|
165
|
+
* compiled(Expr.variant("some", 42n)); // 42n
|
|
166
|
+
* compiled(Expr.variant("none", null)); // 0n
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
172
|
+
*
|
|
173
|
+
* // Partial matching - only handle some cases, use default for rest
|
|
157
174
|
* const getOrZero = East.function([OptionType], IntegerType, ($, opt) => {
|
|
158
175
|
* $.return(opt.match({
|
|
159
176
|
* some: ($, val) => val
|
|
@@ -181,10 +198,90 @@ export declare class VariantExpr<Cases extends Record<string, any>> extends Expr
|
|
|
181
198
|
* compiled(Expr.variant("pending", null)); // 0n
|
|
182
199
|
* ```
|
|
183
200
|
*/
|
|
201
|
+
match<Handlers extends {
|
|
202
|
+
[K in keyof Cases]: ($: BlockBuilder<NeverType>, data: ExprType<Cases[K]>) => any;
|
|
203
|
+
}>(handlers: Handlers): ExprType<TypeOf<{
|
|
204
|
+
[K in keyof Handlers]: ReturnType<Handlers[K]>;
|
|
205
|
+
}[keyof Handlers]>>;
|
|
184
206
|
match<Handlers extends {
|
|
185
207
|
[K in keyof Cases]?: ($: BlockBuilder<NeverType>, data: ExprType<Cases[K]>) => any;
|
|
186
208
|
}, Default extends ($: BlockBuilder<NeverType>) => any>(handlers: Handlers, defaultHandler: Default): ExprType<TypeUnion<TypeOf<{
|
|
187
209
|
[K in keyof Handlers]: ReturnType<NonNullable<Handlers[K]>>;
|
|
188
210
|
}[keyof Handlers]>, TypeOf<ReturnType<Default>>>>;
|
|
211
|
+
/**
|
|
212
|
+
* Match a single variant tag and handle it, with a default for all other tags.
|
|
213
|
+
*
|
|
214
|
+
* This is a shorthand for partial matching when you only care about one case.
|
|
215
|
+
*
|
|
216
|
+
* @typeParam K - The case name to match
|
|
217
|
+
* @typeParam Default - Type of the default handler function
|
|
218
|
+
* @param tag - The case name to match
|
|
219
|
+
* @param handler - Function to handle the matched case, receiving the unwrapped data
|
|
220
|
+
* @param defaultHandler - Function to handle all other cases
|
|
221
|
+
* @returns Expression of the union type of the handler and default return types
|
|
222
|
+
*
|
|
223
|
+
* @see {@link match} for matching multiple cases
|
|
224
|
+
* @see {@link unwrap} for extracting a single case value
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
229
|
+
*
|
|
230
|
+
* const doubleOrZero = East.function([OptionType], IntegerType, ($, opt) => {
|
|
231
|
+
* $.return(opt.matchTag("some", ($, val) => val.multiply(2n), ($) => 0n));
|
|
232
|
+
* });
|
|
233
|
+
* const compiled = East.compile(doubleOrZero.toIR(), []);
|
|
234
|
+
* compiled(Expr.variant("some", 42n)); // 84n
|
|
235
|
+
* compiled(Expr.variant("none", null)); // 0n
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
matchTag<K extends keyof Cases & string, Handler extends ($: BlockBuilder<NeverType>, data: ExprType<Cases[K]>) => any, Default extends ($: BlockBuilder<NeverType>) => any>(tag: K, handler: Handler, defaultHandler: Default): ExprType<TypeUnion<TypeOf<ReturnType<Handler>>, TypeOf<ReturnType<Default>>>>;
|
|
239
|
+
/**
|
|
240
|
+
* Checks if this variant equals another variant (same tag and value).
|
|
241
|
+
*
|
|
242
|
+
* @param other - The variant to compare against
|
|
243
|
+
* @returns A BooleanExpr that is true if the variants are equal
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
248
|
+
*
|
|
249
|
+
* const isEqual = East.function([OptionType, OptionType], BooleanType, ($, a, b) => {
|
|
250
|
+
* $.return(a.equals(b));
|
|
251
|
+
* });
|
|
252
|
+
* const compiled = East.compile(isEqual.toIR(), []);
|
|
253
|
+
* compiled(variant("some", 42n), variant("some", 42n)); // true
|
|
254
|
+
* compiled(variant("some", 42n), variant("some", 0n)); // false
|
|
255
|
+
* compiled(variant("some", 42n), variant("none", null)); // false
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
equals(other: SubtypeExprOrValue<VariantType<Cases>>): BooleanExpr;
|
|
259
|
+
/**
|
|
260
|
+
* Checks if this variant does not equal another variant.
|
|
261
|
+
*
|
|
262
|
+
* @param other - The variant to compare against
|
|
263
|
+
* @returns A BooleanExpr that is true if the variants are not equal
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
268
|
+
*
|
|
269
|
+
* const isNotEqual = East.function([OptionType, OptionType], BooleanType, ($, a, b) => {
|
|
270
|
+
* $.return(a.notEquals(b));
|
|
271
|
+
* });
|
|
272
|
+
* const compiled = East.compile(isNotEqual.toIR(), []);
|
|
273
|
+
* compiled(variant("some", 42n), variant("some", 0n)); // true
|
|
274
|
+
* compiled(variant("some", 42n), variant("some", 42n)); // false
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
notEquals(other: SubtypeExprOrValue<VariantType<Cases>>): BooleanExpr;
|
|
278
|
+
/** Alias for {@link equals} */
|
|
279
|
+
eq: (other: SubtypeExprOrValue<VariantType<Cases>>) => BooleanExpr;
|
|
280
|
+
/** Alias for {@link equals} */
|
|
281
|
+
equal: (other: SubtypeExprOrValue<VariantType<Cases>>) => BooleanExpr;
|
|
282
|
+
/** Alias for {@link notEquals} */
|
|
283
|
+
ne: (other: SubtypeExprOrValue<VariantType<Cases>>) => BooleanExpr;
|
|
284
|
+
/** Alias for {@link notEquals} */
|
|
285
|
+
notEqual: (other: SubtypeExprOrValue<VariantType<Cases>>) => BooleanExpr;
|
|
189
286
|
}
|
|
190
287
|
//# sourceMappingURL=variant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variant.d.ts","sourceRoot":"","sources":["../../../src/expr/variant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KA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AAG,WAAW,CAiC9C;IAEpB,kCAAkC;IAClC,EAAE,UAde,kBAAkB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAG,WAAW,CAcjD;IACpB,kCAAkC;IAClC,QAAQ,UAhBS,kBAAkB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,KAAG,WAAW,CAgB3C;CAC3B"}
|
package/dist/src/expr/variant.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { get_location_id } from "../location.js";
|
|
2
2
|
import { BooleanType, NeverType, StringType, TypeUnion, VariantType } from "../types.js";
|
|
3
|
+
import { equal, notEqual } from "./block.js";
|
|
3
4
|
import { Expr } from "./expr.js";
|
|
4
5
|
/**
|
|
5
6
|
* Expression representing variant (sum type/tagged union) values.
|
|
@@ -94,68 +95,105 @@ export class VariantExpr extends Expr {
|
|
|
94
95
|
const handlers = Object.fromEntries(Object.keys(this.cases).map(caseName => [caseName, () => name === caseName]));
|
|
95
96
|
return Expr.match(this, handlers);
|
|
96
97
|
}
|
|
97
|
-
unwrap(name = "some", onOther = ($) => $.error(`Variant does not have case ${String(name)}`,
|
|
98
|
+
unwrap(name = "some", onOther = ($) => $.error(`Variant does not have case ${String(name)}`, get_location_id())) {
|
|
98
99
|
if (onOther === undefined) {
|
|
99
|
-
onOther = $ => $.error(`Variant does not have case ${String(name)}`,
|
|
100
|
+
onOther = $ => $.error(`Variant does not have case ${String(name)}`, get_location_id()); // expression-based error should use parent call location
|
|
100
101
|
}
|
|
101
102
|
const handlers = Object.fromEntries(Object.keys(this.cases).map(caseName => [caseName, caseName === name ? (_$, data) => data : ($, _data) => onOther($)]));
|
|
102
103
|
return Expr.match(this, handlers);
|
|
103
104
|
}
|
|
105
|
+
// Implementation
|
|
106
|
+
match(handlers, defaultHandler) {
|
|
107
|
+
// Build complete handler set by filling unhandled cases with default (if provided)
|
|
108
|
+
const completeHandlers = Object.fromEntries(Object.keys(this.cases).map(caseName => [
|
|
109
|
+
caseName,
|
|
110
|
+
handlers[caseName] ?? (defaultHandler ? (($, _data) => defaultHandler($)) : undefined)
|
|
111
|
+
]));
|
|
112
|
+
return Expr.match(this, completeHandlers);
|
|
113
|
+
}
|
|
104
114
|
/**
|
|
105
|
-
*
|
|
115
|
+
* Match a single variant tag and handle it, with a default for all other tags.
|
|
106
116
|
*
|
|
107
|
-
* This
|
|
108
|
-
* with a required default handler for any unmatched cases. This is more ergonomic than
|
|
109
|
-
* exhaustive matching when you only need to handle a subset of cases.
|
|
117
|
+
* This is a shorthand for partial matching when you only care about one case.
|
|
110
118
|
*
|
|
111
|
-
* @typeParam
|
|
119
|
+
* @typeParam K - The case name to match
|
|
112
120
|
* @typeParam Default - Type of the default handler function
|
|
113
|
-
* @param
|
|
114
|
-
* @param
|
|
115
|
-
* @
|
|
121
|
+
* @param tag - The case name to match
|
|
122
|
+
* @param handler - Function to handle the matched case, receiving the unwrapped data
|
|
123
|
+
* @param defaultHandler - Function to handle all other cases
|
|
124
|
+
* @returns Expression of the union type of the handler and default return types
|
|
116
125
|
*
|
|
117
|
-
* @see {@link
|
|
126
|
+
* @see {@link match} for matching multiple cases
|
|
118
127
|
* @see {@link unwrap} for extracting a single case value
|
|
119
128
|
*
|
|
120
129
|
* @example
|
|
121
130
|
* ```ts
|
|
122
131
|
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
123
132
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* $.return(opt.match({
|
|
127
|
-
* some: ($, val) => val
|
|
128
|
-
* }, ($) => 0n));
|
|
133
|
+
* const doubleOrZero = East.function([OptionType], IntegerType, ($, opt) => {
|
|
134
|
+
* $.return(opt.matchTag("some", ($, val) => val.multiply(2n), ($) => 0n));
|
|
129
135
|
* });
|
|
130
|
-
* const compiled = East.compile(
|
|
131
|
-
* compiled(Expr.variant("some", 42n)); //
|
|
136
|
+
* const compiled = East.compile(doubleOrZero.toIR(), []);
|
|
137
|
+
* compiled(Expr.variant("some", 42n)); // 84n
|
|
132
138
|
* compiled(Expr.variant("none", null)); // 0n
|
|
133
139
|
* ```
|
|
140
|
+
*/
|
|
141
|
+
matchTag(tag, handler, defaultHandler) {
|
|
142
|
+
return this.match({ [tag]: handler }, defaultHandler);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks if this variant equals another variant (same tag and value).
|
|
146
|
+
*
|
|
147
|
+
* @param other - The variant to compare against
|
|
148
|
+
* @returns A BooleanExpr that is true if the variants are equal
|
|
134
149
|
*
|
|
135
150
|
* @example
|
|
136
151
|
* ```ts
|
|
137
|
-
* const
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* $.return(result.match({
|
|
142
|
-
* ok: ($, val) => val,
|
|
143
|
-
* error: ($, _msg) => -1n
|
|
144
|
-
* }, ($) => 0n)); // pending -> 0
|
|
152
|
+
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
153
|
+
*
|
|
154
|
+
* const isEqual = East.function([OptionType, OptionType], BooleanType, ($, a, b) => {
|
|
155
|
+
* $.return(a.equals(b));
|
|
145
156
|
* });
|
|
146
|
-
* const compiled = East.compile(
|
|
147
|
-
* compiled(
|
|
148
|
-
* compiled(
|
|
149
|
-
* compiled(
|
|
157
|
+
* const compiled = East.compile(isEqual.toIR(), []);
|
|
158
|
+
* compiled(variant("some", 42n), variant("some", 42n)); // true
|
|
159
|
+
* compiled(variant("some", 42n), variant("some", 0n)); // false
|
|
160
|
+
* compiled(variant("some", 42n), variant("none", null)); // false
|
|
150
161
|
* ```
|
|
151
162
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
equals(other) {
|
|
164
|
+
return equal(this, other);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Checks if this variant does not equal another variant.
|
|
168
|
+
*
|
|
169
|
+
* @param other - The variant to compare against
|
|
170
|
+
* @returns A BooleanExpr that is true if the variants are not equal
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* const OptionType = VariantType({ some: IntegerType, none: NullType });
|
|
175
|
+
*
|
|
176
|
+
* const isNotEqual = East.function([OptionType, OptionType], BooleanType, ($, a, b) => {
|
|
177
|
+
* $.return(a.notEquals(b));
|
|
178
|
+
* });
|
|
179
|
+
* const compiled = East.compile(isNotEqual.toIR(), []);
|
|
180
|
+
* compiled(variant("some", 42n), variant("some", 0n)); // true
|
|
181
|
+
* compiled(variant("some", 42n), variant("some", 42n)); // false
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
notEquals(other) {
|
|
185
|
+
return notEqual(this, other);
|
|
159
186
|
}
|
|
187
|
+
// ============================================================================
|
|
188
|
+
// Aliases for comparison operations
|
|
189
|
+
// ============================================================================
|
|
190
|
+
/** Alias for {@link equals} */
|
|
191
|
+
eq = this.equals;
|
|
192
|
+
/** Alias for {@link equals} */
|
|
193
|
+
equal = this.equals;
|
|
194
|
+
/** Alias for {@link notEquals} */
|
|
195
|
+
ne = this.notEquals;
|
|
196
|
+
/** Alias for {@link notEquals} */
|
|
197
|
+
notEqual = this.notEquals;
|
|
160
198
|
}
|
|
161
199
|
//# sourceMappingURL=variant.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variant.js","sourceRoot":"","sources":["../../../src/expr/variant.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"variant.js","sourceRoot":"","sources":["../../../src/expr/variant.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEzF,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,IAAI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O,EAAS,EAAE,cAAc,CAAQ,CAAC;IACtE,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,MAAM,CAAC,KAA6C;QAClD,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,CAAgB,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,KAA6C;QACrD,OAAO,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAgB,CAAC;IAC9C,CAAC;IAED,+EAA+E;IAC/E,oCAAoC;IACpC,+EAA+E;IAE/E,+BAA+B;IAC/B,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;IACjB,+BAA+B;IAC/B,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;IAEpB,kCAAkC;IAClC,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;IACpB,kCAAkC;IAClC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC;CAC3B"}
|
|
@@ -0,0 +1,102 @@
|
|
|
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 { IntegerType, VectorType, FunctionType, type NeverType } from "../types.js";
|
|
7
|
+
import type { IntegerExpr } from "./integer.js";
|
|
8
|
+
import type { NullExpr } from "./null.js";
|
|
9
|
+
import { Expr, type ToExpr } from "./expr.js";
|
|
10
|
+
import type { SubtypeExprOrValue, ExprType, TypeOf } from "./types.js";
|
|
11
|
+
import type { BlockBuilder } from "./block.js";
|
|
12
|
+
import type { ArrayExpr } from "./array.js";
|
|
13
|
+
import type { MatrixExpr } from "./matrix.js";
|
|
14
|
+
/**
|
|
15
|
+
* Expression representing mutable vector (1D typed array) values and operations.
|
|
16
|
+
*
|
|
17
|
+
* VectorExpr provides methods for vector manipulation including element access,
|
|
18
|
+
* mutation, slicing, concatenation, conversion, and higher-order operations.
|
|
19
|
+
* Vectors are backed by contiguous typed arrays (Float64Array, BigInt64Array,
|
|
20
|
+
* or Uint8Array) for efficient numeric computation and zero-copy interop
|
|
21
|
+
* with ML libraries.
|
|
22
|
+
*/
|
|
23
|
+
export declare class VectorExpr<T extends any> extends Expr<VectorType<T>> {
|
|
24
|
+
private element_type;
|
|
25
|
+
constructor(element_type: T, ast: AST, createExpr: ToExpr);
|
|
26
|
+
/**
|
|
27
|
+
* Returns the number of elements in the vector.
|
|
28
|
+
*
|
|
29
|
+
* @returns An IntegerExpr representing the length
|
|
30
|
+
*/
|
|
31
|
+
length(): IntegerExpr;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the element at the specified index.
|
|
34
|
+
*
|
|
35
|
+
* @param index - The zero-based index to access
|
|
36
|
+
* @returns An expression of the element type
|
|
37
|
+
*
|
|
38
|
+
* @throws East runtime error if the index is out of bounds
|
|
39
|
+
*/
|
|
40
|
+
get(index: SubtypeExprOrValue<IntegerType>): ExprType<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Sets the element at the specified index (mutates the vector).
|
|
43
|
+
*
|
|
44
|
+
* @param index - The zero-based index to set
|
|
45
|
+
* @param value - The new value to store at that index
|
|
46
|
+
* @returns NullExpr (operation performed for side effect)
|
|
47
|
+
*
|
|
48
|
+
* @throws East runtime error if the index is out of bounds
|
|
49
|
+
*/
|
|
50
|
+
set(index: SubtypeExprOrValue<IntegerType>, value: SubtypeExprOrValue<T>): NullExpr;
|
|
51
|
+
/**
|
|
52
|
+
* Returns a new vector containing elements from start (inclusive) to end (exclusive).
|
|
53
|
+
*
|
|
54
|
+
* @param start - The start index (inclusive)
|
|
55
|
+
* @param end - The end index (exclusive)
|
|
56
|
+
* @returns A new VectorExpr containing the sliced elements
|
|
57
|
+
*
|
|
58
|
+
* @throws East runtime error if indices are out of bounds
|
|
59
|
+
*/
|
|
60
|
+
slice(start: SubtypeExprOrValue<IntegerType>, end: SubtypeExprOrValue<IntegerType>): VectorExpr<T>;
|
|
61
|
+
/**
|
|
62
|
+
* Concatenates this vector with another vector of the same element type.
|
|
63
|
+
*
|
|
64
|
+
* @param other - The other vector to concatenate
|
|
65
|
+
* @returns A new VectorExpr containing elements from both vectors
|
|
66
|
+
*/
|
|
67
|
+
concat(other: Expr<VectorType<T>>): VectorExpr<T>;
|
|
68
|
+
/**
|
|
69
|
+
* Converts this vector to an Array.
|
|
70
|
+
*
|
|
71
|
+
* @returns An ArrayExpr containing the same elements
|
|
72
|
+
*/
|
|
73
|
+
toArray(): ArrayExpr<T>;
|
|
74
|
+
/**
|
|
75
|
+
* Reshapes this vector into a matrix with the specified dimensions.
|
|
76
|
+
* Requires rows * cols == length of the vector.
|
|
77
|
+
*
|
|
78
|
+
* @param rows - The number of rows in the resulting matrix
|
|
79
|
+
* @param cols - The number of columns in the resulting matrix
|
|
80
|
+
* @returns A MatrixExpr with the specified shape
|
|
81
|
+
*
|
|
82
|
+
* @throws East runtime error if rows * cols does not equal the vector length
|
|
83
|
+
*/
|
|
84
|
+
toMatrix(rows: SubtypeExprOrValue<IntegerType>, cols: SubtypeExprOrValue<IntegerType>): MatrixExpr<T>;
|
|
85
|
+
/**
|
|
86
|
+
* Maps a function over each element and its index, producing a new vector.
|
|
87
|
+
*
|
|
88
|
+
* @param fn - Function taking (element, index) and returning a new value
|
|
89
|
+
* @returns A new VectorExpr with the mapped values
|
|
90
|
+
*/
|
|
91
|
+
map<T2>(fn: Expr<FunctionType<[T, IntegerType], T2>>): VectorExpr<T2>;
|
|
92
|
+
map<F extends (($: BlockBuilder<NeverType>, v: ExprType<T>, k: ExprType<IntegerType>) => any)>(fn: F): VectorExpr<TypeOf<ReturnType<F>>>;
|
|
93
|
+
/**
|
|
94
|
+
* Reduces the vector to a single value using an accumulator function and initial value.
|
|
95
|
+
*
|
|
96
|
+
* @param combineFn - Function taking (accumulator, element, index) and returning the new accumulator value
|
|
97
|
+
* @param init - Initial value for the reduction (determines output type)
|
|
98
|
+
* @returns The final accumulated value
|
|
99
|
+
*/
|
|
100
|
+
reduce<T2>(combineFn: SubtypeExprOrValue<FunctionType<[previous: TypeOf<NoInfer<T2>>, value: T, key: IntegerType], TypeOf<NoInfer<T2>>>>, init: T2): ExprType<TypeOf<T2>>;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=vector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector.d.ts","sourceRoot":"","sources":["../../../src/expr/vector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAwB,YAAY,EAA4B,KAAK,SAAS,EAAqC,MAAM,aAAa,CAAC;AAEvK,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAa,IAAI,EAA6B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;GAQG;AACH,qBAAa,UAAU,CAAC,CAAC,SAAS,GAAG,CAAE,SAAQ,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,YAAY;gBAAZ,YAAY,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM;IAIjE;;;;OAIG;IACH,MAAM,IAAI,WAAW;IAWrB;;;;;;;OAOG;IACH,GAAG,CAAC,KAAK,EAAE,kBAAkB,CAAC,WAAW,CAAC,GAAG,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