@elaraai/east 0.0.1-beta.9 → 1.0.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 +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/ast_to_ir.js
CHANGED
|
@@ -1,24 +1,89 @@
|
|
|
1
|
-
import { printLocationValue } from "./ir.js";
|
|
2
|
-
import { printLocation } from "./location.js";
|
|
3
1
|
import { toEastTypeValue } from "./type_of_type.js";
|
|
4
|
-
import { ArrayType, DictType, FunctionType, isSubtype, isTypeEqual, NeverType, NullType, printType, RefType, SetType, StructType, VariantType } from "./types.js";
|
|
2
|
+
import { ArrayType, DictType, FunctionType, getTypeId, isSubtype, isTypeEqual, NeverType, NullType, printType, RefType, SetType, StructType, VariantType, VectorType, MatrixType } from "./types.js";
|
|
5
3
|
import { variant } from "./containers/variant.js";
|
|
6
4
|
import { applyTypeParameters, Builtins } from "./builtins.js";
|
|
7
5
|
/** @internal An exception throw for the purpose of early loop continue */
|
|
8
6
|
export class OutOfScopeException extends Error {
|
|
9
7
|
definedLocation;
|
|
10
8
|
constructor(definedLocation) {
|
|
11
|
-
super(`Variable defined at ${
|
|
9
|
+
super(`Variable defined at loc_id ${definedLocation} is out of scope here`);
|
|
12
10
|
this.definedLocation = definedLocation;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Coerce an IR value from `source_type` to `target_type`. When both are
|
|
15
|
+
* `StructType` or both are `VariantType` AND `value_ir` is the matching
|
|
16
|
+
* literal shape (a `Struct` / `Variant` IR node), recursively rewrite each
|
|
17
|
+
* child and rebuild the outer IR with the wider declared type — no outer
|
|
18
|
+
* `As` wrapper. Otherwise (primitives, variable references, invariant
|
|
19
|
+
* containers), emit a single outer `As`, matching legacy behaviour.
|
|
20
|
+
*
|
|
21
|
+
* Narrow→wide compound widening is only possible for Struct (covariant fields)
|
|
22
|
+
* and Variant (subset + covariant cases). All mutable-container parameters
|
|
23
|
+
* (Array/Set/Dict/Vector/Matrix/Ref) are invariant per isSubtypeImpl.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export function coerce_to(value_ir, source_type, target_type, loc_id, visited) {
|
|
28
|
+
if (isTypeEqual(source_type, target_type))
|
|
29
|
+
return value_ir;
|
|
30
|
+
if (!isSubtype(source_type, target_type)) {
|
|
31
|
+
throw new Error(`Cannot coerce value of type ${printType(source_type)} to ${printType(target_type)} at loc_id ${loc_id}`);
|
|
32
|
+
}
|
|
33
|
+
const sid = getTypeId(source_type);
|
|
34
|
+
const tid = getTypeId(target_type);
|
|
35
|
+
const pair_key = `${sid ?? "?"}:${tid ?? "?"}`;
|
|
36
|
+
if (visited !== undefined && visited.has(pair_key)) {
|
|
37
|
+
return variant("As", {
|
|
38
|
+
type: toEastTypeValue(target_type),
|
|
39
|
+
value: value_ir,
|
|
40
|
+
loc_id,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const visited2 = visited ?? new Set();
|
|
44
|
+
visited2.add(pair_key);
|
|
45
|
+
let s = source_type;
|
|
46
|
+
let t = target_type;
|
|
47
|
+
if (s.type === "Recursive")
|
|
48
|
+
s = s.node;
|
|
49
|
+
if (t.type === "Recursive")
|
|
50
|
+
t = t.node;
|
|
51
|
+
if (value_ir.type === "Struct" && s.type === "Struct" && t.type === "Struct") {
|
|
52
|
+
const s_fields = s.fields;
|
|
53
|
+
const t_fields = t.fields;
|
|
54
|
+
const new_fields = value_ir.value.fields.map(({ name, value: field_ir }) => {
|
|
55
|
+
const s_field = s_fields[name];
|
|
56
|
+
const t_field = t_fields[name];
|
|
57
|
+
if (s_field === undefined || t_field === undefined) {
|
|
58
|
+
return { name, value: field_ir };
|
|
59
|
+
}
|
|
60
|
+
return { name, value: coerce_to(field_ir, s_field, t_field, loc_id, visited2) };
|
|
61
|
+
});
|
|
62
|
+
return variant("Struct", {
|
|
63
|
+
type: toEastTypeValue(target_type),
|
|
64
|
+
loc_id: value_ir.value.loc_id,
|
|
65
|
+
fields: new_fields,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (value_ir.type === "Variant" && s.type === "Variant" && t.type === "Variant") {
|
|
69
|
+
const case_name = value_ir.value.case;
|
|
70
|
+
const s_case = s.cases[case_name];
|
|
71
|
+
const t_case = t.cases[case_name];
|
|
72
|
+
const inner = (s_case !== undefined && t_case !== undefined)
|
|
73
|
+
? coerce_to(value_ir.value.value, s_case, t_case, loc_id, visited2)
|
|
74
|
+
: value_ir.value.value;
|
|
75
|
+
return variant("Variant", {
|
|
76
|
+
type: toEastTypeValue(target_type),
|
|
77
|
+
loc_id: value_ir.value.loc_id,
|
|
78
|
+
case: case_name,
|
|
79
|
+
value: inner,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return variant("As", {
|
|
83
|
+
type: toEastTypeValue(target_type),
|
|
84
|
+
value: value_ir,
|
|
85
|
+
loc_id,
|
|
86
|
+
});
|
|
22
87
|
}
|
|
23
88
|
/** Perform scope resolution and type checking on `AST`, produce `IR` ready for serialization, compilation or evaluation.
|
|
24
89
|
*
|
|
@@ -37,7 +102,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
37
102
|
return ir;
|
|
38
103
|
}
|
|
39
104
|
else {
|
|
40
|
-
throw new OutOfScopeException(ast.
|
|
105
|
+
throw new OutOfScopeException(ast.loc_id);
|
|
41
106
|
}
|
|
42
107
|
}
|
|
43
108
|
}
|
|
@@ -47,30 +112,22 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
47
112
|
const variable = variant("Variable", {
|
|
48
113
|
type: toEastTypeValue(ast.variable.type),
|
|
49
114
|
name: `_${ctx.n_vars}`,
|
|
50
|
-
|
|
115
|
+
loc_id: ast.variable.loc_id,
|
|
51
116
|
mutable: ast.variable.mutable,
|
|
52
117
|
captured: false,
|
|
53
118
|
});
|
|
54
|
-
// Insert As node if value type doesn't exactly match variable type
|
|
55
|
-
// This ensures the IR has exact types everywhere
|
|
56
119
|
if (!isTypeEqual(ast.value.type, ast.variable.type)) {
|
|
57
|
-
// Validate subtype relationship before inserting As node
|
|
58
|
-
// This catches type errors early at AST level
|
|
59
120
|
if (!isSubtype(ast.value.type, ast.variable.type)) {
|
|
60
121
|
throw new Error(`Cannot initialize variable of type ${printType(ast.variable.type)} ` +
|
|
61
|
-
`with value of type ${printType(ast.value.type)} at ${
|
|
122
|
+
`with value of type ${printType(ast.value.type)} at loc_id ${ast.loc_id}`);
|
|
62
123
|
}
|
|
63
|
-
value =
|
|
64
|
-
type: toEastTypeValue(ast.variable.type),
|
|
65
|
-
value,
|
|
66
|
-
location: toLocationValue(ast.location),
|
|
67
|
-
});
|
|
124
|
+
value = coerce_to(value, ast.value.type, ast.variable.type, ast.loc_id);
|
|
68
125
|
}
|
|
69
126
|
ctx.n_vars += 1;
|
|
70
127
|
ctx.local_ctx.set(ast.variable, variable);
|
|
71
128
|
return variant("Let", {
|
|
72
129
|
type: toEastTypeValue(ast.type),
|
|
73
|
-
|
|
130
|
+
loc_id: ast.loc_id,
|
|
74
131
|
variable,
|
|
75
132
|
value,
|
|
76
133
|
});
|
|
@@ -79,28 +136,19 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
79
136
|
// Fetch the variable from context
|
|
80
137
|
const variable = ast_to_ir(ast.variable, ctx);
|
|
81
138
|
if (!variable.value.mutable) {
|
|
82
|
-
throw new Error(`Variable defined const at ${
|
|
139
|
+
throw new Error(`Variable defined const at loc_id ${variable.value.loc_id} is being reassigned at loc_id ${ast.loc_id}`);
|
|
83
140
|
}
|
|
84
141
|
let value = ast_to_ir(ast.value, ctx);
|
|
85
|
-
// Get the variable's type from the IR node
|
|
86
|
-
const variableType = variable.value.type;
|
|
87
|
-
// Insert As node if value type doesn't exactly match variable type
|
|
88
|
-
// This ensures the IR has exact types everywhere
|
|
89
142
|
if (!isTypeEqual(ast.value.type, ast.variable.type)) {
|
|
90
|
-
// Validate subtype relationship before inserting As node
|
|
91
143
|
if (!isSubtype(ast.value.type, ast.variable.type)) {
|
|
92
144
|
throw new Error(`Cannot assign value of type ${printType(ast.value.type)} ` +
|
|
93
|
-
`to variable of type ${printType(ast.variable.type)} at ${
|
|
145
|
+
`to variable of type ${printType(ast.variable.type)} at loc_id ${ast.loc_id}`);
|
|
94
146
|
}
|
|
95
|
-
value =
|
|
96
|
-
type: variableType,
|
|
97
|
-
value,
|
|
98
|
-
location: toLocationValue(ast.location),
|
|
99
|
-
});
|
|
147
|
+
value = coerce_to(value, ast.value.type, ast.variable.type, ast.loc_id);
|
|
100
148
|
}
|
|
101
149
|
return variant("Assign", {
|
|
102
150
|
type: toEastTypeValue(ast.type),
|
|
103
|
-
|
|
151
|
+
loc_id: ast.loc_id,
|
|
104
152
|
variable,
|
|
105
153
|
value,
|
|
106
154
|
});
|
|
@@ -113,7 +161,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
113
161
|
ctx.n_loops = ctx2.n_loops;
|
|
114
162
|
return variant("Block", {
|
|
115
163
|
type: toEastTypeValue(ast.type),
|
|
116
|
-
|
|
164
|
+
loc_id: ast.loc_id,
|
|
117
165
|
statements,
|
|
118
166
|
});
|
|
119
167
|
}
|
|
@@ -122,33 +170,28 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
122
170
|
const builtin_name = ast.builtin;
|
|
123
171
|
const builtin_def = Builtins[builtin_name];
|
|
124
172
|
if (!builtin_def) {
|
|
125
|
-
throw new Error(`Unknown builtin function '${builtin_name}' at ${
|
|
173
|
+
throw new Error(`Unknown builtin function '${builtin_name}' at loc_id ${ast.loc_id}`);
|
|
126
174
|
}
|
|
127
175
|
if (builtin_def.type_parameters.length !== ast.type_parameters.length) {
|
|
128
|
-
throw new Error(`Builtin function '${builtin_name}' expected ${builtin_def.type_parameters.length} type parameters, got ${ast.type_parameters.length} at ${
|
|
176
|
+
throw new Error(`Builtin function '${builtin_name}' expected ${builtin_def.type_parameters.length} type parameters, got ${ast.type_parameters.length} at loc_id ${ast.loc_id}`);
|
|
129
177
|
}
|
|
130
178
|
const type_map = new Map(builtin_def.type_parameters.map((name, i) => [name, ast.type_parameters[i]]));
|
|
131
179
|
if (ast.arguments.length !== builtin_def.inputs.length) {
|
|
132
|
-
throw new Error(`Builtin function '${builtin_name}' expected ${builtin_def.inputs.length} arguments, got ${ast.arguments.length} at ${
|
|
180
|
+
throw new Error(`Builtin function '${builtin_name}' expected ${builtin_def.inputs.length} arguments, got ${ast.arguments.length} at loc_id ${ast.loc_id}`);
|
|
133
181
|
}
|
|
134
182
|
return variant("Builtin", {
|
|
135
183
|
type: toEastTypeValue(ast.type),
|
|
136
|
-
|
|
184
|
+
loc_id: ast.loc_id,
|
|
137
185
|
builtin: ast.builtin,
|
|
138
186
|
type_parameters: ast.type_parameters.map(tp => toEastTypeValue(tp)),
|
|
139
187
|
arguments: ast.arguments.map((arg, i) => {
|
|
140
188
|
let arg_ir = ast_to_ir(arg, ctx);
|
|
141
189
|
const expectedType = applyTypeParameters(builtin_def.inputs[i], type_map, [], []);
|
|
142
|
-
// Now check type compatibility
|
|
143
190
|
if (arg.type.type !== "Never" && !isTypeEqual(arg.type, expectedType)) {
|
|
144
191
|
if (!isSubtype(arg.type, expectedType)) {
|
|
145
|
-
throw new Error(`Builtin ${builtin_name} with type parameters [${ast.type_parameters.map(tp => printType(tp)).join(", ")}] argument ${i} of type ${printType(arg.type)} is not compatible with expected type ${printType(expectedType)} at ${
|
|
192
|
+
throw new Error(`Builtin ${builtin_name} with type parameters [${ast.type_parameters.map(tp => printType(tp)).join(", ")}] argument ${i} of type ${printType(arg.type)} is not compatible with expected type ${printType(expectedType)} at loc_id ${ast.loc_id}`);
|
|
146
193
|
}
|
|
147
|
-
arg_ir =
|
|
148
|
-
type: toEastTypeValue(arg.type),
|
|
149
|
-
value: arg_ir,
|
|
150
|
-
location: toLocationValue(ast.location),
|
|
151
|
-
});
|
|
194
|
+
arg_ir = coerce_to(arg_ir, arg.type, expectedType, ast.loc_id);
|
|
152
195
|
}
|
|
153
196
|
return arg_ir;
|
|
154
197
|
}),
|
|
@@ -156,37 +199,35 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
156
199
|
}
|
|
157
200
|
else if (ast.ast_type === "Platform") {
|
|
158
201
|
if (ctx.async === false && ast.async === true) {
|
|
159
|
-
throw new Error(`Async platform call not allowed outside async function at ${
|
|
202
|
+
throw new Error(`Async platform call not allowed outside async function at loc_id ${ast.loc_id}`);
|
|
160
203
|
}
|
|
161
204
|
return variant("Platform", {
|
|
162
205
|
type: toEastTypeValue(ast.type),
|
|
163
|
-
|
|
206
|
+
loc_id: ast.loc_id,
|
|
164
207
|
name: ast.name,
|
|
208
|
+
type_parameters: ast.type_parameters.map(tp => toEastTypeValue(tp)),
|
|
165
209
|
arguments: ast.arguments.map(ast => ast_to_ir(ast, ctx)), // type equality handled at Expr/AST level
|
|
166
210
|
async: ast.async,
|
|
211
|
+
optional: ast.optional,
|
|
167
212
|
});
|
|
168
213
|
}
|
|
169
214
|
else if (ast.ast_type === "Struct") {
|
|
170
215
|
return variant("Struct", {
|
|
171
216
|
type: toEastTypeValue(ast.type),
|
|
172
|
-
|
|
217
|
+
loc_id: ast.loc_id,
|
|
173
218
|
fields: Object.entries(ast.fields).map(([name, fieldAst]) => {
|
|
174
219
|
let value = ast_to_ir(fieldAst, ctx);
|
|
175
220
|
const expectedType = ast.type.fields[name];
|
|
176
221
|
if (!expectedType) {
|
|
177
|
-
throw new Error(`Struct type does not have field '${name}' at ${
|
|
222
|
+
throw new Error(`Struct type does not have field '${name}' at loc_id ${ast.loc_id}`);
|
|
178
223
|
}
|
|
179
224
|
if (!isTypeEqual(fieldAst.type, expectedType)) {
|
|
180
225
|
if (isSubtype(fieldAst.type, expectedType)) {
|
|
181
|
-
value =
|
|
182
|
-
type: toEastTypeValue(expectedType),
|
|
183
|
-
value,
|
|
184
|
-
location: toLocationValue(ast.location),
|
|
185
|
-
});
|
|
226
|
+
value = coerce_to(value, fieldAst.type, expectedType, ast.loc_id);
|
|
186
227
|
}
|
|
187
228
|
else {
|
|
188
229
|
throw new Error(`Cannot assign field '${name}' of type ${printType(ast.type.fields[name])} ` +
|
|
189
|
-
`with value of type ${printType(fieldAst.type)} at ${
|
|
230
|
+
`with value of type ${printType(fieldAst.type)} at loc_id ${ast.loc_id}`);
|
|
190
231
|
}
|
|
191
232
|
}
|
|
192
233
|
return { name, value };
|
|
@@ -196,7 +237,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
196
237
|
else if (ast.ast_type === "GetField") {
|
|
197
238
|
return variant("GetField", {
|
|
198
239
|
type: toEastTypeValue(ast.type),
|
|
199
|
-
|
|
240
|
+
loc_id: ast.loc_id,
|
|
200
241
|
struct: ast_to_ir(ast.struct, ctx),
|
|
201
242
|
field: ast.field,
|
|
202
243
|
});
|
|
@@ -206,20 +247,16 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
206
247
|
let value = ast_to_ir(ast.value, ctx);
|
|
207
248
|
if (!isTypeEqual(ast.value.type, expectedType)) {
|
|
208
249
|
if (isSubtype(ast.value.type, expectedType)) {
|
|
209
|
-
value =
|
|
210
|
-
type: toEastTypeValue(expectedType),
|
|
211
|
-
value,
|
|
212
|
-
location: toLocationValue(ast.location),
|
|
213
|
-
});
|
|
250
|
+
value = coerce_to(value, ast.value.type, expectedType, ast.loc_id);
|
|
214
251
|
}
|
|
215
252
|
else {
|
|
216
253
|
throw new Error(`Cannot assign case '${ast.case}' of type ${printType(expectedType)} ` +
|
|
217
|
-
`with value of type ${printType(ast.value.type)} at ${
|
|
254
|
+
`with value of type ${printType(ast.value.type)} at loc_id ${ast.loc_id}`);
|
|
218
255
|
}
|
|
219
256
|
}
|
|
220
257
|
return variant("Variant", {
|
|
221
258
|
type: toEastTypeValue(ast.type),
|
|
222
|
-
|
|
259
|
+
loc_id: ast.loc_id,
|
|
223
260
|
case: ast.case,
|
|
224
261
|
value,
|
|
225
262
|
});
|
|
@@ -229,7 +266,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
229
266
|
const param = variant("Variable", {
|
|
230
267
|
type: toEastTypeValue(parameter.type),
|
|
231
268
|
name: `_${ctx.n_vars}`,
|
|
232
|
-
|
|
269
|
+
loc_id: parameter.loc_id,
|
|
233
270
|
mutable: parameter.mutable, // false...
|
|
234
271
|
captured: false,
|
|
235
272
|
});
|
|
@@ -243,9 +280,21 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
243
280
|
const body = ast_to_ir(ast.body, ctx2);
|
|
244
281
|
ctx.n_vars = ctx2.n_vars;
|
|
245
282
|
ctx.n_loops = ctx2.n_loops;
|
|
283
|
+
// Propagate captures: if this function captured something from ctx.parent_ctx,
|
|
284
|
+
// then the enclosing function also needs to capture it
|
|
285
|
+
for (const capturedVar of captures) {
|
|
286
|
+
// Check if this variable came from our parent context (not defined locally in enclosing function)
|
|
287
|
+
for (const [_astVar, ir] of ctx.parent_ctx) {
|
|
288
|
+
if (ir === capturedVar) {
|
|
289
|
+
// This capture came from an outer scope, so enclosing function must also capture it
|
|
290
|
+
ctx.captures.add(capturedVar);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
246
295
|
return variant("Function", {
|
|
247
296
|
type: toEastTypeValue(ast.type),
|
|
248
|
-
|
|
297
|
+
loc_id: ast.loc_id,
|
|
249
298
|
parameters,
|
|
250
299
|
captures: [...captures],
|
|
251
300
|
body,
|
|
@@ -256,7 +305,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
256
305
|
const param = variant("Variable", {
|
|
257
306
|
type: toEastTypeValue(parameter.type),
|
|
258
307
|
name: `_${ctx.n_vars}`,
|
|
259
|
-
|
|
308
|
+
loc_id: parameter.loc_id,
|
|
260
309
|
mutable: parameter.mutable, // false...
|
|
261
310
|
captured: false,
|
|
262
311
|
});
|
|
@@ -270,9 +319,21 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
270
319
|
const body = ast_to_ir(ast.body, ctx2);
|
|
271
320
|
ctx.n_vars = ctx2.n_vars;
|
|
272
321
|
ctx.n_loops = ctx2.n_loops;
|
|
322
|
+
// Propagate captures: if this function captured something from ctx.parent_ctx,
|
|
323
|
+
// then the enclosing function also needs to capture it
|
|
324
|
+
for (const capturedVar of captures) {
|
|
325
|
+
// Check if this variable came from our parent context (not defined locally in enclosing function)
|
|
326
|
+
for (const [_astVar, ir] of ctx.parent_ctx) {
|
|
327
|
+
if (ir === capturedVar) {
|
|
328
|
+
// This capture came from an outer scope, so enclosing function must also capture it
|
|
329
|
+
ctx.captures.add(capturedVar);
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
273
334
|
return variant("AsyncFunction", {
|
|
274
335
|
type: toEastTypeValue(ast.type),
|
|
275
|
-
|
|
336
|
+
loc_id: ast.loc_id,
|
|
276
337
|
parameters,
|
|
277
338
|
captures: [...captures],
|
|
278
339
|
body,
|
|
@@ -283,20 +344,16 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
283
344
|
// TODO - what about widening the result with As?
|
|
284
345
|
return variant("Call", {
|
|
285
346
|
type: toEastTypeValue(ast.type),
|
|
286
|
-
|
|
347
|
+
loc_id: ast.loc_id,
|
|
287
348
|
function: ast_to_ir(ast.function, ctx),
|
|
288
349
|
arguments: ast.arguments.map((argument, i) => {
|
|
289
350
|
let arg = ast_to_ir(argument, ctx);
|
|
290
351
|
const expectedType = ast.function.type.inputs[i];
|
|
291
352
|
if (!isTypeEqual(argument.type, expectedType)) {
|
|
292
353
|
if (!isSubtype(argument.type, expectedType)) {
|
|
293
|
-
throw new Error(`Argument ${i} of type ${printType(argument.type)} is not compatible with expected type ${printType(expectedType)} at ${
|
|
354
|
+
throw new Error(`Argument ${i} of type ${printType(argument.type)} is not compatible with expected type ${printType(expectedType)} at loc_id ${ast.loc_id}`);
|
|
294
355
|
}
|
|
295
|
-
arg =
|
|
296
|
-
type: toEastTypeValue(expectedType),
|
|
297
|
-
value: arg,
|
|
298
|
-
location: toLocationValue(ast.location),
|
|
299
|
-
});
|
|
356
|
+
arg = coerce_to(arg, argument.type, expectedType, ast.loc_id);
|
|
300
357
|
}
|
|
301
358
|
return arg;
|
|
302
359
|
}),
|
|
@@ -304,26 +361,22 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
304
361
|
}
|
|
305
362
|
else if (ast.ast_type === "CallAsync") {
|
|
306
363
|
if (ctx.async === false) {
|
|
307
|
-
throw new Error(`Async function call not allowed outside async function at ${
|
|
364
|
+
throw new Error(`Async function call not allowed outside async function at loc_id ${ast.loc_id}`);
|
|
308
365
|
}
|
|
309
366
|
// TODO - type equality could have been handled at Expr/AST level instead
|
|
310
367
|
// TODO - what about widening the result with As?
|
|
311
368
|
return variant("CallAsync", {
|
|
312
369
|
type: toEastTypeValue(ast.type),
|
|
313
|
-
|
|
370
|
+
loc_id: ast.loc_id,
|
|
314
371
|
function: ast_to_ir(ast.function, ctx),
|
|
315
372
|
arguments: ast.arguments.map((argument, i) => {
|
|
316
373
|
let arg = ast_to_ir(argument, ctx);
|
|
317
374
|
const expectedType = ast.function.type.inputs[i];
|
|
318
375
|
if (!isTypeEqual(argument.type, expectedType)) {
|
|
319
376
|
if (!isSubtype(argument.type, expectedType)) {
|
|
320
|
-
throw new Error(`Argument ${i} of type ${printType(argument.type)} is not compatible with expected type ${printType(expectedType)} at ${
|
|
377
|
+
throw new Error(`Argument ${i} of type ${printType(argument.type)} is not compatible with expected type ${printType(expectedType)} at loc_id ${ast.loc_id}`);
|
|
321
378
|
}
|
|
322
|
-
arg =
|
|
323
|
-
type: toEastTypeValue(expectedType),
|
|
324
|
-
value: arg,
|
|
325
|
-
location: toLocationValue(ast.location),
|
|
326
|
-
});
|
|
379
|
+
arg = coerce_to(arg, argument.type, expectedType, ast.loc_id);
|
|
327
380
|
}
|
|
328
381
|
return arg;
|
|
329
382
|
}),
|
|
@@ -334,17 +387,13 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
334
387
|
let value = ast_to_ir(ast.value, ctx);
|
|
335
388
|
if (!isTypeEqual(ast.value.type, valueType)) {
|
|
336
389
|
if (!isSubtype(ast.value.type, valueType)) {
|
|
337
|
-
throw new Error(`Ref value of type ${printType(ast.value.type)} is not compatible with expected type ${printType(valueType)} at ${
|
|
390
|
+
throw new Error(`Ref value of type ${printType(ast.value.type)} is not compatible with expected type ${printType(valueType)} at loc_id ${ast.loc_id}`);
|
|
338
391
|
}
|
|
339
|
-
value =
|
|
340
|
-
type: toEastTypeValue(valueType),
|
|
341
|
-
value,
|
|
342
|
-
location: toLocationValue(ast.location),
|
|
343
|
-
});
|
|
392
|
+
value = coerce_to(value, ast.value.type, valueType, ast.loc_id);
|
|
344
393
|
}
|
|
345
394
|
return variant("NewRef", {
|
|
346
395
|
type: toEastTypeValue(ast.type),
|
|
347
|
-
|
|
396
|
+
loc_id: ast.loc_id,
|
|
348
397
|
value,
|
|
349
398
|
});
|
|
350
399
|
}
|
|
@@ -352,18 +401,14 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
352
401
|
const valueType = ast.type.value;
|
|
353
402
|
return variant("NewArray", {
|
|
354
403
|
type: toEastTypeValue(ast.type),
|
|
355
|
-
|
|
404
|
+
loc_id: ast.loc_id,
|
|
356
405
|
values: ast.values.map((v, i) => {
|
|
357
406
|
let value = ast_to_ir(v, ctx);
|
|
358
407
|
if (!isTypeEqual(v.type, valueType)) {
|
|
359
408
|
if (!isSubtype(v.type, valueType)) {
|
|
360
|
-
throw new Error(`Array value at entry ${i} of type ${printType(v.type)} is not compatible with expected type ${printType(valueType)} at ${
|
|
409
|
+
throw new Error(`Array value at entry ${i} of type ${printType(v.type)} is not compatible with expected type ${printType(valueType)} at loc_id ${ast.loc_id}`);
|
|
361
410
|
}
|
|
362
|
-
value =
|
|
363
|
-
type: toEastTypeValue(valueType),
|
|
364
|
-
value,
|
|
365
|
-
location: toLocationValue(ast.location),
|
|
366
|
-
});
|
|
411
|
+
value = coerce_to(value, v.type, valueType, ast.loc_id);
|
|
367
412
|
}
|
|
368
413
|
return value;
|
|
369
414
|
}),
|
|
@@ -373,18 +418,14 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
373
418
|
const keyType = ast.type.key;
|
|
374
419
|
return variant("NewSet", {
|
|
375
420
|
type: toEastTypeValue(ast.type),
|
|
376
|
-
|
|
421
|
+
loc_id: ast.loc_id,
|
|
377
422
|
values: ast.values.map((k, i) => {
|
|
378
423
|
let key = ast_to_ir(k, ctx);
|
|
379
424
|
if (!isTypeEqual(k.type, keyType)) {
|
|
380
425
|
if (!isSubtype(k.type, keyType)) {
|
|
381
|
-
throw new Error(`Set key at entry ${i} of type ${printType(k.type)} is not compatible with expected type ${printType(keyType)} at ${
|
|
426
|
+
throw new Error(`Set key at entry ${i} of type ${printType(k.type)} is not compatible with expected type ${printType(keyType)} at loc_id ${ast.loc_id}`);
|
|
382
427
|
}
|
|
383
|
-
key =
|
|
384
|
-
type: toEastTypeValue(keyType),
|
|
385
|
-
value: key,
|
|
386
|
-
location: toLocationValue(ast.location),
|
|
387
|
-
});
|
|
428
|
+
key = coerce_to(key, k.type, keyType, ast.loc_id);
|
|
388
429
|
}
|
|
389
430
|
return key;
|
|
390
431
|
}),
|
|
@@ -395,29 +436,21 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
395
436
|
const valueType = ast.type.value;
|
|
396
437
|
return variant("NewDict", {
|
|
397
438
|
type: toEastTypeValue(ast.type),
|
|
398
|
-
|
|
439
|
+
loc_id: ast.loc_id,
|
|
399
440
|
values: ast.values.map(([k, v], i) => {
|
|
400
441
|
let key = ast_to_ir(k, ctx);
|
|
401
442
|
if (!isTypeEqual(k.type, keyType)) {
|
|
402
443
|
if (!isSubtype(k.type, keyType)) {
|
|
403
|
-
throw new Error(`Dict key at entry ${i} of type ${printType(k.type)} is not compatible with expected type ${printType(keyType)} at ${
|
|
444
|
+
throw new Error(`Dict key at entry ${i} of type ${printType(k.type)} is not compatible with expected type ${printType(keyType)} at loc_id ${ast.loc_id}`);
|
|
404
445
|
}
|
|
405
|
-
key =
|
|
406
|
-
type: toEastTypeValue(keyType),
|
|
407
|
-
value: key,
|
|
408
|
-
location: toLocationValue(ast.location),
|
|
409
|
-
});
|
|
446
|
+
key = coerce_to(key, k.type, keyType, ast.loc_id);
|
|
410
447
|
}
|
|
411
448
|
let value = ast_to_ir(v, ctx);
|
|
412
449
|
if (!isTypeEqual(v.type, valueType)) {
|
|
413
450
|
if (!isSubtype(v.type, valueType)) {
|
|
414
|
-
throw new Error(`Dict value at entry ${i} of type ${printType(v.type)} is not compatible with expected type ${printType(valueType)} at ${
|
|
451
|
+
throw new Error(`Dict value at entry ${i} of type ${printType(v.type)} is not compatible with expected type ${printType(valueType)} at loc_id ${ast.loc_id}`);
|
|
415
452
|
}
|
|
416
|
-
value =
|
|
417
|
-
type: toEastTypeValue(valueType),
|
|
418
|
-
value,
|
|
419
|
-
location: toLocationValue(ast.location),
|
|
420
|
-
});
|
|
453
|
+
value = coerce_to(value, v.type, valueType, ast.loc_id);
|
|
421
454
|
}
|
|
422
455
|
;
|
|
423
456
|
return { key, value };
|
|
@@ -443,13 +476,9 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
443
476
|
ctx.n_loops = ctx_branch.n_loops;
|
|
444
477
|
if (branch.body.type.type !== "Never" && !isTypeEqual(branch.body.type, ast.type)) {
|
|
445
478
|
if (!isSubtype(branch.body.type, ast.type)) {
|
|
446
|
-
throw new Error(`If branch body of type ${printType(branch.body.type)} is not compatible with expected type ${printType(ast.type)} at ${
|
|
479
|
+
throw new Error(`If branch body of type ${printType(branch.body.type)} is not compatible with expected type ${printType(ast.type)} at loc_id ${ast.loc_id}`);
|
|
447
480
|
}
|
|
448
|
-
branch_body =
|
|
449
|
-
type: toEastTypeValue(ast.type),
|
|
450
|
-
value: branch_body,
|
|
451
|
-
location: toLocationValue(ast.location),
|
|
452
|
-
});
|
|
481
|
+
branch_body = coerce_to(branch_body, branch.body.type, ast.type, ast.loc_id);
|
|
453
482
|
}
|
|
454
483
|
return { predicate, body: branch_body };
|
|
455
484
|
});
|
|
@@ -469,17 +498,13 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
469
498
|
ctx.n_loops = ctx_else.n_loops;
|
|
470
499
|
if (ast.else_body.type.type !== "Never" && !isTypeEqual(ast.else_body.type, ast.type)) {
|
|
471
500
|
if (!isSubtype(ast.else_body.type, ast.type)) {
|
|
472
|
-
throw new Error(`Else branch body of type ${printType(ast.else_body.type)} is not compatible with expected type ${printType(ast.type)} at ${
|
|
501
|
+
throw new Error(`Else branch body of type ${printType(ast.else_body.type)} is not compatible with expected type ${printType(ast.type)} at loc_id ${ast.loc_id}`);
|
|
473
502
|
}
|
|
474
|
-
else_body =
|
|
475
|
-
type: toEastTypeValue(ast.type),
|
|
476
|
-
value: else_body,
|
|
477
|
-
location: toLocationValue(ast.location),
|
|
478
|
-
});
|
|
503
|
+
else_body = coerce_to(else_body, ast.else_body.type, ast.type, ast.loc_id);
|
|
479
504
|
}
|
|
480
505
|
return variant("IfElse", {
|
|
481
506
|
type: toEastTypeValue(ast.type),
|
|
482
|
-
|
|
507
|
+
loc_id: ast.loc_id,
|
|
483
508
|
ifs,
|
|
484
509
|
else_body,
|
|
485
510
|
});
|
|
@@ -487,7 +512,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
487
512
|
else if (ast.ast_type === "Error") {
|
|
488
513
|
return variant("Error", {
|
|
489
514
|
type: variant("Never", null),
|
|
490
|
-
|
|
515
|
+
loc_id: ast.loc_id,
|
|
491
516
|
message: ast_to_ir(ast.message, ctx),
|
|
492
517
|
});
|
|
493
518
|
}
|
|
@@ -510,7 +535,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
510
535
|
const message = variant("Variable", {
|
|
511
536
|
type: toEastTypeValue(ast.message.type),
|
|
512
537
|
name: `_${ctx.n_vars}`,
|
|
513
|
-
|
|
538
|
+
loc_id: ast.message.loc_id,
|
|
514
539
|
mutable: ast.message.mutable, // false...
|
|
515
540
|
captured: false,
|
|
516
541
|
});
|
|
@@ -518,7 +543,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
518
543
|
const stack = variant("Variable", {
|
|
519
544
|
type: toEastTypeValue(ast.stack.type),
|
|
520
545
|
name: `_${ctx.n_vars}`,
|
|
521
|
-
|
|
546
|
+
loc_id: ast.stack.loc_id,
|
|
522
547
|
mutable: ast.stack.mutable, // false...
|
|
523
548
|
captured: false,
|
|
524
549
|
});
|
|
@@ -558,13 +583,13 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
558
583
|
else {
|
|
559
584
|
finally_body = variant("Value", {
|
|
560
585
|
type: toEastTypeValue(NullType),
|
|
561
|
-
|
|
586
|
+
loc_id: ast.loc_id,
|
|
562
587
|
value: variant("Null", null),
|
|
563
588
|
});
|
|
564
589
|
}
|
|
565
590
|
return variant("TryCatch", {
|
|
566
591
|
type: toEastTypeValue(ast.type),
|
|
567
|
-
|
|
592
|
+
loc_id: ast.loc_id,
|
|
568
593
|
try_body,
|
|
569
594
|
catch_body,
|
|
570
595
|
message,
|
|
@@ -600,26 +625,24 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
600
625
|
throw new Error(`Unsupported literal value type: ${typeof ast.value} (expected ${printType(ast.type)})`);
|
|
601
626
|
}
|
|
602
627
|
if (type.type !== value.type) {
|
|
603
|
-
throw new Error(`Literal value type mismatch at ${
|
|
628
|
+
throw new Error(`Literal value type mismatch at loc_id ${ast.loc_id}: expected .${type.type} but got .${value.type}`);
|
|
604
629
|
}
|
|
605
630
|
return variant("Value", {
|
|
606
631
|
type,
|
|
607
|
-
|
|
632
|
+
loc_id: ast.loc_id,
|
|
608
633
|
value,
|
|
609
634
|
});
|
|
610
635
|
}
|
|
611
636
|
else if (ast.ast_type === "As") {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
value: ast_to_ir(ast.value, ctx),
|
|
616
|
-
});
|
|
637
|
+
// Explicit $.as: use coerce_to so nested narrow variants in a literal
|
|
638
|
+
// struct/variant get deep-rewritten just like implicit widening.
|
|
639
|
+
return coerce_to(ast_to_ir(ast.value, ctx), ast.value.type, ast.type, ast.loc_id);
|
|
617
640
|
}
|
|
618
641
|
else if (ast.ast_type === "While") {
|
|
619
642
|
const predicate = ast_to_ir(ast.predicate, ctx);
|
|
620
643
|
const label = {
|
|
621
644
|
name: `_${ctx.n_loops}`,
|
|
622
|
-
|
|
645
|
+
loc_id: ast.label.loc_id,
|
|
623
646
|
};
|
|
624
647
|
ctx.n_loops += 1;
|
|
625
648
|
const ctx2 = {
|
|
@@ -638,7 +661,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
638
661
|
ctx.n_loops = ctx2.n_loops;
|
|
639
662
|
return variant("While", {
|
|
640
663
|
type: variant("Null", null),
|
|
641
|
-
|
|
664
|
+
loc_id: ast.loc_id,
|
|
642
665
|
label,
|
|
643
666
|
predicate,
|
|
644
667
|
body,
|
|
@@ -648,13 +671,13 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
648
671
|
const array = ast_to_ir(ast.array, ctx);
|
|
649
672
|
const label = {
|
|
650
673
|
name: `_${ctx.n_loops}`,
|
|
651
|
-
|
|
674
|
+
loc_id: ast.label.loc_id,
|
|
652
675
|
};
|
|
653
676
|
ctx.n_loops += 1;
|
|
654
677
|
const value = variant("Variable", {
|
|
655
678
|
type: toEastTypeValue(ast.value.type),
|
|
656
679
|
name: `_${ctx.n_vars}`,
|
|
657
|
-
|
|
680
|
+
loc_id: ast.value.loc_id,
|
|
658
681
|
mutable: ast.value.mutable, // false...
|
|
659
682
|
captured: false,
|
|
660
683
|
});
|
|
@@ -662,7 +685,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
662
685
|
const key = variant("Variable", {
|
|
663
686
|
type: toEastTypeValue(ast.key.type),
|
|
664
687
|
name: `_${ctx.n_vars}`,
|
|
665
|
-
|
|
688
|
+
loc_id: ast.key.loc_id,
|
|
666
689
|
mutable: ast.key.mutable, // false...
|
|
667
690
|
captured: false,
|
|
668
691
|
});
|
|
@@ -683,7 +706,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
683
706
|
ctx.n_loops = ctx2.n_loops;
|
|
684
707
|
return variant("ForArray", {
|
|
685
708
|
type: variant("Null", null),
|
|
686
|
-
|
|
709
|
+
loc_id: ast.loc_id,
|
|
687
710
|
label,
|
|
688
711
|
key,
|
|
689
712
|
value,
|
|
@@ -695,13 +718,13 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
695
718
|
const set = ast_to_ir(ast.set, ctx);
|
|
696
719
|
const label = {
|
|
697
720
|
name: `_${ctx.n_loops}`,
|
|
698
|
-
|
|
721
|
+
loc_id: ast.label.loc_id,
|
|
699
722
|
};
|
|
700
723
|
ctx.n_loops += 1;
|
|
701
724
|
const key = variant("Variable", {
|
|
702
725
|
type: toEastTypeValue(ast.key.type),
|
|
703
726
|
name: `_${ctx.n_vars}`,
|
|
704
|
-
|
|
727
|
+
loc_id: ast.key.loc_id,
|
|
705
728
|
mutable: ast.key.mutable, // false...
|
|
706
729
|
captured: false,
|
|
707
730
|
});
|
|
@@ -722,7 +745,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
722
745
|
ctx.n_loops = ctx2.n_loops;
|
|
723
746
|
return variant("ForSet", {
|
|
724
747
|
type: variant("Null", null),
|
|
725
|
-
|
|
748
|
+
loc_id: ast.loc_id,
|
|
726
749
|
label,
|
|
727
750
|
key,
|
|
728
751
|
set,
|
|
@@ -733,13 +756,13 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
733
756
|
const dict = ast_to_ir(ast.dict, ctx);
|
|
734
757
|
const label = {
|
|
735
758
|
name: `_${ctx.n_loops}`,
|
|
736
|
-
|
|
759
|
+
loc_id: ast.label.loc_id,
|
|
737
760
|
};
|
|
738
761
|
ctx.n_loops += 1;
|
|
739
762
|
const value = variant("Variable", {
|
|
740
763
|
type: toEastTypeValue(ast.value.type),
|
|
741
764
|
name: `_${ctx.n_vars}`,
|
|
742
|
-
|
|
765
|
+
loc_id: ast.value.loc_id,
|
|
743
766
|
mutable: ast.value.mutable, // false...
|
|
744
767
|
captured: false,
|
|
745
768
|
});
|
|
@@ -747,7 +770,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
747
770
|
const key = variant("Variable", {
|
|
748
771
|
type: toEastTypeValue(ast.key.type),
|
|
749
772
|
name: `_${ctx.n_vars}`,
|
|
750
|
-
|
|
773
|
+
loc_id: ast.key.loc_id,
|
|
751
774
|
mutable: ast.key.mutable, // false...
|
|
752
775
|
captured: false,
|
|
753
776
|
});
|
|
@@ -768,7 +791,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
768
791
|
ctx.n_loops = ctx2.n_loops;
|
|
769
792
|
return variant("ForDict", {
|
|
770
793
|
type: variant("Null", null),
|
|
771
|
-
|
|
794
|
+
loc_id: ast.loc_id,
|
|
772
795
|
label,
|
|
773
796
|
key,
|
|
774
797
|
value,
|
|
@@ -783,7 +806,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
783
806
|
const variable = variant("Variable", {
|
|
784
807
|
type: toEastTypeValue(v.variable.type),
|
|
785
808
|
name: `_${ctx.n_vars}`,
|
|
786
|
-
|
|
809
|
+
loc_id: v.variable.loc_id,
|
|
787
810
|
mutable: v.variable.mutable, // false...
|
|
788
811
|
captured: false,
|
|
789
812
|
});
|
|
@@ -804,19 +827,15 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
804
827
|
ctx.n_loops = ctx2.n_loops;
|
|
805
828
|
if (v.body.type.type !== "Never" && !isTypeEqual(v.body.type, ast.type)) {
|
|
806
829
|
if (!isSubtype(v.body.type, ast.type)) {
|
|
807
|
-
throw new Error(`Match case '${k}' body of type ${printType(v.body.type)} is not compatible with expected type ${printType(ast.type)} at ${
|
|
830
|
+
throw new Error(`Match case '${k}' body of type ${printType(v.body.type)} is not compatible with expected type ${printType(ast.type)} at loc_id ${ast.loc_id}`);
|
|
808
831
|
}
|
|
809
|
-
body =
|
|
810
|
-
type: toEastTypeValue(ast.type),
|
|
811
|
-
value: body,
|
|
812
|
-
location: toLocationValue(ast.location),
|
|
813
|
-
});
|
|
832
|
+
body = coerce_to(body, v.body.type, ast.type, ast.loc_id);
|
|
814
833
|
}
|
|
815
834
|
cases.push({ case: k, variable, body });
|
|
816
835
|
}
|
|
817
836
|
return variant("Match", {
|
|
818
837
|
type: toEastTypeValue(ast.type),
|
|
819
|
-
|
|
838
|
+
loc_id: ast.loc_id,
|
|
820
839
|
variant: variant_expr,
|
|
821
840
|
cases,
|
|
822
841
|
});
|
|
@@ -824,7 +843,7 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
824
843
|
else if (ast.ast_type === "UnwrapRecursive") {
|
|
825
844
|
return variant("UnwrapRecursive", {
|
|
826
845
|
type: toEastTypeValue(ast.type),
|
|
827
|
-
|
|
846
|
+
loc_id: ast.loc_id,
|
|
828
847
|
value: ast_to_ir(ast.value, ctx),
|
|
829
848
|
});
|
|
830
849
|
}
|
|
@@ -835,14 +854,14 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
835
854
|
}
|
|
836
855
|
const existing = ctx.recursiveASTs.has(ast);
|
|
837
856
|
if (existing) {
|
|
838
|
-
throw new Error(`Circular reference detected when converting AST to IR at ${
|
|
857
|
+
throw new Error(`Circular reference detected when converting AST to IR at loc_id ${ast.loc_id}`);
|
|
839
858
|
}
|
|
840
859
|
// Register before recursing (enables cycle detection)
|
|
841
860
|
ctx.recursiveASTs.add(ast);
|
|
842
861
|
// Create WrapRecursive IR node with placeholder
|
|
843
862
|
const wrapIR = variant("WrapRecursive", {
|
|
844
863
|
type: toEastTypeValue(ast.type),
|
|
845
|
-
|
|
864
|
+
loc_id: ast.loc_id,
|
|
846
865
|
value: ast_to_ir(ast.value, ctx),
|
|
847
866
|
});
|
|
848
867
|
// The user may alias this AST value elsewhere in the tree, just not with a circular reference
|
|
@@ -852,35 +871,71 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
852
871
|
else if (ast.ast_type === "Break") {
|
|
853
872
|
const label = ctx.loop_ctx.get(ast.label);
|
|
854
873
|
if (label === undefined) {
|
|
855
|
-
throw new Error(`Label defined at ${
|
|
874
|
+
throw new Error(`Label defined at loc_id ${ast.label.loc_id} is not in scope at break at loc_id ${ast.loc_id}`);
|
|
856
875
|
}
|
|
857
876
|
return variant("Break", {
|
|
858
877
|
type: variant("Never", null),
|
|
859
|
-
|
|
878
|
+
loc_id: ast.loc_id,
|
|
860
879
|
label,
|
|
861
880
|
});
|
|
862
881
|
}
|
|
863
882
|
else if (ast.ast_type === "Continue") {
|
|
864
883
|
const label = ctx.loop_ctx.get(ast.label);
|
|
865
884
|
if (label === undefined) {
|
|
866
|
-
throw new Error(`Label defined at ${
|
|
885
|
+
throw new Error(`Label defined at loc_id ${ast.label.loc_id} is not in scope at continue at loc_id ${ast.loc_id}`);
|
|
867
886
|
}
|
|
868
887
|
return variant("Continue", {
|
|
869
888
|
type: variant("Never", null),
|
|
870
|
-
|
|
889
|
+
loc_id: ast.loc_id,
|
|
871
890
|
label,
|
|
872
891
|
});
|
|
873
892
|
}
|
|
874
893
|
else if (ast.ast_type === "Return") {
|
|
875
894
|
if (!isSubtype(ast.value.type, ctx.output)) {
|
|
876
|
-
throw new Error(`Attempted to return value of type ${printType(ast.value.type)} at ${
|
|
895
|
+
throw new Error(`Attempted to return value of type ${printType(ast.value.type)} at loc_id ${ast.loc_id}, but function expected return type of ${printType(ctx.output)}`);
|
|
877
896
|
}
|
|
878
897
|
return variant("Return", {
|
|
879
898
|
type: variant("Never", null),
|
|
880
|
-
|
|
899
|
+
loc_id: ast.loc_id,
|
|
881
900
|
value: ast_to_ir(ast.value, ctx),
|
|
882
901
|
});
|
|
883
902
|
}
|
|
903
|
+
else if (ast.ast_type === "NewVector") {
|
|
904
|
+
const elementType = ast.type.element;
|
|
905
|
+
return variant("NewVector", {
|
|
906
|
+
type: toEastTypeValue(ast.type),
|
|
907
|
+
loc_id: ast.loc_id,
|
|
908
|
+
values: ast.values.map((v, i) => {
|
|
909
|
+
let value = ast_to_ir(v, ctx);
|
|
910
|
+
if (!isTypeEqual(v.type, elementType)) {
|
|
911
|
+
if (!isSubtype(v.type, elementType)) {
|
|
912
|
+
throw new Error(`Vector value at entry ${i} of type ${printType(v.type)} is not compatible with expected type ${printType(elementType)} at loc_id ${ast.loc_id}`);
|
|
913
|
+
}
|
|
914
|
+
value = coerce_to(value, v.type, elementType, ast.loc_id);
|
|
915
|
+
}
|
|
916
|
+
return value;
|
|
917
|
+
}),
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
else if (ast.ast_type === "NewMatrix") {
|
|
921
|
+
const elementType = ast.type.element;
|
|
922
|
+
return variant("NewMatrix", {
|
|
923
|
+
type: toEastTypeValue(ast.type),
|
|
924
|
+
loc_id: ast.loc_id,
|
|
925
|
+
rows: BigInt(ast.rows),
|
|
926
|
+
cols: BigInt(ast.cols),
|
|
927
|
+
values: ast.values.map((v, i) => {
|
|
928
|
+
let value = ast_to_ir(v, ctx);
|
|
929
|
+
if (!isTypeEqual(v.type, elementType)) {
|
|
930
|
+
if (!isSubtype(v.type, elementType)) {
|
|
931
|
+
throw new Error(`Matrix value at entry ${i} of type ${printType(v.type)} is not compatible with expected type ${printType(elementType)} at loc_id ${ast.loc_id}`);
|
|
932
|
+
}
|
|
933
|
+
value = coerce_to(value, v.type, elementType, ast.loc_id);
|
|
934
|
+
}
|
|
935
|
+
return value;
|
|
936
|
+
}),
|
|
937
|
+
});
|
|
938
|
+
}
|
|
884
939
|
else {
|
|
885
940
|
throw new Error(`Cannot check ${ast.type}`);
|
|
886
941
|
}
|
|
@@ -888,13 +943,13 @@ export function ast_to_ir(ast, ctx = { local_ctx: new Map(), parent_ctx: new Map
|
|
|
888
943
|
catch (e) {
|
|
889
944
|
if (e instanceof Error) {
|
|
890
945
|
if (ast.ast_type === "Builtin") {
|
|
891
|
-
e.message += `\n at ${ast.ast_type} ${ast.builtin} node located at ${
|
|
946
|
+
e.message += `\n at ${ast.ast_type} ${ast.builtin} node located at loc_id ${ast.loc_id}`;
|
|
892
947
|
}
|
|
893
948
|
else if (ast.ast_type === "Platform") {
|
|
894
|
-
e.message += `\n at ${ast.ast_type} ${ast.name} node located at ${
|
|
949
|
+
e.message += `\n at ${ast.ast_type} ${ast.name} node located at loc_id ${ast.loc_id}`;
|
|
895
950
|
}
|
|
896
951
|
else {
|
|
897
|
-
e.message += `\n at ${ast.ast_type} node located at ${
|
|
952
|
+
e.message += `\n at ${ast.ast_type} node located at loc_id ${ast.loc_id}`;
|
|
898
953
|
}
|
|
899
954
|
}
|
|
900
955
|
throw e;
|