@soundscript/soundscript 0.1.12 → 0.1.15
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/package.json +15 -6
- package/project-transform/index.js +2 -0
- package/project-transform/index.ts +8 -0
- package/project-transform/src/annotation_syntax.js +948 -0
- package/project-transform/src/annotation_syntax.ts +1217 -0
- package/project-transform/src/build_package.js +475 -0
- package/project-transform/src/build_package.ts +683 -0
- package/project-transform/src/bundled/portable-web-globals.d.ts +153 -0
- package/project-transform/src/bundled/runtime_externs.js +220 -0
- package/project-transform/src/bundled/runtime_externs.ts +237 -0
- package/project-transform/src/bundled/sound-libs/lib.decorators.d.ts +385 -0
- package/project-transform/src/bundled/sound-libs/lib.decorators.legacy.d.ts +22 -0
- package/project-transform/src/bundled/sound-libs/lib.dom.asynciterable.d.ts +42 -0
- package/project-transform/src/bundled/sound-libs/lib.dom.d.ts +39440 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.collection.d.ts +149 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.core.d.ts +657 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.d.ts +28 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.generator.d.ts +77 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.iterable.d.ts +616 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.promise.d.ts +80 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.proxy.d.ts +128 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.reflect.d.ts +144 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.d.ts +46 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.wellknown.d.ts +170 -0
- package/project-transform/src/bundled/sound-libs/lib.es2016.array.include.d.ts +116 -0
- package/project-transform/src/bundled/sound-libs/lib.es2016.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.arraybuffer.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.date.d.ts +31 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.object.d.ts +49 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.string.d.ts +45 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.typedarrays.d.ts +53 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.asyncgenerator.d.ts +77 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.asynciterable.d.ts +57 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.promise.d.ts +30 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.regexp.d.ts +37 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.array.d.ts +79 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.object.d.ts +47 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.string.d.ts +37 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.symbol.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.bigint.d.ts +765 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.d.ts +27 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.date.d.ts +42 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.number.d.ts +28 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.promise.d.ts +49 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.string.d.ts +44 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.d.ts +23 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.promise.d.ts +48 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.string.d.ts +33 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.weakref.d.ts +78 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.array.d.ts +121 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.error.d.ts +75 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.object.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.regexp.d.ts +39 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.string.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.array.d.ts +924 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.collection.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.d.ts +22 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.arraybuffer.d.ts +65 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.collection.d.ts +29 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.object.d.ts +33 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.promise.d.ts +35 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.regexp.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.string.d.ts +29 -0
- package/project-transform/src/bundled/sound-libs/lib.es5.d.ts +4924 -0
- package/project-transform/src/bundled/sound_stdlib.js +142 -0
- package/project-transform/src/bundled/sound_stdlib.ts +180 -0
- package/project-transform/src/checker/analyze_project.js +1361 -0
- package/project-transform/src/checker/analyze_project.ts +2246 -0
- package/project-transform/src/checker/diagnostics.js +112 -0
- package/project-transform/src/checker/diagnostics.ts +222 -0
- package/project-transform/src/checker/engine/context.js +235 -0
- package/project-transform/src/checker/engine/context.ts +340 -0
- package/project-transform/src/checker/engine/diagnostic_codes.js +72 -0
- package/project-transform/src/checker/engine/diagnostic_codes.ts +95 -0
- package/project-transform/src/checker/engine/facts.js +35 -0
- package/project-transform/src/checker/engine/facts.ts +48 -0
- package/project-transform/src/checker/engine/types.js +1 -0
- package/project-transform/src/checker/engine/types.ts +485 -0
- package/project-transform/src/checker/proof_escape_hatch_diagnostics.js +104 -0
- package/project-transform/src/checker/proof_escape_hatch_diagnostics.ts +173 -0
- package/project-transform/src/checker/rules/async_surface.js +231 -0
- package/project-transform/src/checker/rules/async_surface.ts +335 -0
- package/project-transform/src/checker/rules/class_lifecycle.js +798 -0
- package/project-transform/src/checker/rules/class_lifecycle.ts +1276 -0
- package/project-transform/src/checker/rules/directive_validation.js +571 -0
- package/project-transform/src/checker/rules/directive_validation.ts +938 -0
- package/project-transform/src/checker/rules/directives.js +23 -0
- package/project-transform/src/checker/rules/directives.ts +25 -0
- package/project-transform/src/checker/rules/flow.js +202 -0
- package/project-transform/src/checker/rules/flow.ts +333 -0
- package/project-transform/src/checker/rules/flow_facts.js +601 -0
- package/project-transform/src/checker/rules/flow_facts.ts +978 -0
- package/project-transform/src/checker/rules/flow_invalidation.js +1119 -0
- package/project-transform/src/checker/rules/flow_invalidation.ts +2150 -0
- package/project-transform/src/checker/rules/flow_shared.js +2822 -0
- package/project-transform/src/checker/rules/flow_shared.ts +4383 -0
- package/project-transform/src/checker/rules/foreign_boundary.js +120 -0
- package/project-transform/src/checker/rules/foreign_boundary.ts +196 -0
- package/project-transform/src/checker/rules/foreign_projection.js +279 -0
- package/project-transform/src/checker/rules/foreign_projection.ts +425 -0
- package/project-transform/src/checker/rules/generated_helpers.js +13 -0
- package/project-transform/src/checker/rules/generated_helpers.ts +18 -0
- package/project-transform/src/checker/rules/index.js +35 -0
- package/project-transform/src/checker/rules/index.ts +49 -0
- package/project-transform/src/checker/rules/namespace_object.js +845 -0
- package/project-transform/src/checker/rules/namespace_object.ts +1224 -0
- package/project-transform/src/checker/rules/non_ordinary_recovery.js +1328 -0
- package/project-transform/src/checker/rules/non_ordinary_recovery.ts +2391 -0
- package/project-transform/src/checker/rules/null_prototype.js +3 -0
- package/project-transform/src/checker/rules/null_prototype.ts +6 -0
- package/project-transform/src/checker/rules/overloads.js +181 -0
- package/project-transform/src/checker/rules/overloads.ts +317 -0
- package/project-transform/src/checker/rules/predicate_verification.js +691 -0
- package/project-transform/src/checker/rules/predicate_verification.ts +1088 -0
- package/project-transform/src/checker/rules/prototype_hardening.js +237 -0
- package/project-transform/src/checker/rules/prototype_hardening.ts +343 -0
- package/project-transform/src/checker/rules/receiver_discipline.js +263 -0
- package/project-transform/src/checker/rules/receiver_discipline.ts +356 -0
- package/project-transform/src/checker/rules/relations.js +6861 -0
- package/project-transform/src/checker/rules/relations.ts +12158 -0
- package/project-transform/src/checker/rules/resolved_builtins.js +274 -0
- package/project-transform/src/checker/rules/resolved_builtins.ts +438 -0
- package/project-transform/src/checker/rules/trust.js +217 -0
- package/project-transform/src/checker/rules/trust.ts +301 -0
- package/project-transform/src/checker/rules/type_guards.js +173 -0
- package/project-transform/src/checker/rules/type_guards.ts +257 -0
- package/project-transform/src/checker/rules/universal.js +17 -0
- package/project-transform/src/checker/rules/universal.ts +22 -0
- package/project-transform/src/checker/rules/unsafe_value_origin.js +80 -0
- package/project-transform/src/checker/rules/unsafe_value_origin.ts +125 -0
- package/project-transform/src/checker/rules/unsound_imports.js +218 -0
- package/project-transform/src/checker/rules/unsound_imports.ts +301 -0
- package/project-transform/src/checker/rules/unsound_syntax.js +1695 -0
- package/project-transform/src/checker/rules/unsound_syntax.ts +2540 -0
- package/project-transform/src/checker/rules/value_types.js +206 -0
- package/project-transform/src/checker/rules/value_types.ts +407 -0
- package/project-transform/src/checker/timing.js +43 -0
- package/project-transform/src/checker/timing.ts +78 -0
- package/project-transform/src/checker/unsupported_feature_messages.js +337 -0
- package/project-transform/src/checker/unsupported_feature_messages.ts +531 -0
- package/project-transform/src/cli.js +892 -0
- package/project-transform/src/cli.ts +1476 -0
- package/project-transform/src/compiler/compile_project.js +319 -0
- package/project-transform/src/compiler/compile_project.ts +508 -0
- package/project-transform/src/compiler/errors.js +10 -0
- package/project-transform/src/compiler/errors.ts +29 -0
- package/project-transform/src/compiler/ir.js +1 -0
- package/project-transform/src/compiler/ir.ts +1526 -0
- package/project-transform/src/compiler/lower.js +30550 -0
- package/project-transform/src/compiler/lower.ts +43645 -0
- package/project-transform/src/compiler/lower_arrays.js +140 -0
- package/project-transform/src/compiler/lower_arrays.ts +190 -0
- package/project-transform/src/compiler/lower_strings.js +121 -0
- package/project-transform/src/compiler/lower_strings.ts +198 -0
- package/project-transform/src/compiler/lower_tagged.js +329 -0
- package/project-transform/src/compiler/lower_tagged.ts +427 -0
- package/project-transform/src/compiler/lower_views.js +171 -0
- package/project-transform/src/compiler/lower_views.ts +251 -0
- package/project-transform/src/compiler/object_keys.js +25 -0
- package/project-transform/src/compiler/object_keys.ts +35 -0
- package/project-transform/src/compiler/runtime_ir.js +30 -0
- package/project-transform/src/compiler/runtime_ir.ts +727 -0
- package/project-transform/src/compiler/tagged_boundary.js +18 -0
- package/project-transform/src/compiler/tagged_boundary.ts +37 -0
- package/project-transform/src/compiler/toolchain.js +170 -0
- package/project-transform/src/compiler/toolchain.ts +229 -0
- package/project-transform/src/compiler/unicode_case_data.js +2102 -0
- package/project-transform/src/compiler/unicode_case_data.ts +2112 -0
- package/project-transform/src/compiler/wasm_js_host_runtime.js +656 -0
- package/project-transform/src/compiler/wasm_js_host_runtime.ts +762 -0
- package/project-transform/src/compiler/wat_arrays.js +3132 -0
- package/project-transform/src/compiler/wat_arrays.ts +3768 -0
- package/project-transform/src/compiler/wat_emitter.js +17952 -0
- package/project-transform/src/compiler/wat_emitter.ts +22812 -0
- package/project-transform/src/compiler/wat_strings.js +129 -0
- package/project-transform/src/compiler/wat_strings.ts +187 -0
- package/project-transform/src/compiler/wat_tagged.js +548 -0
- package/project-transform/src/compiler/wat_tagged.ts +674 -0
- package/project-transform/src/compiler_generator_runner.js +153 -0
- package/project-transform/src/compiler_generator_runner.ts +171 -0
- package/project-transform/src/compiler_object_test_helpers.js +69 -0
- package/project-transform/src/compiler_object_test_helpers.ts +96 -0
- package/project-transform/src/compiler_promise_runner.js +2116 -0
- package/project-transform/src/compiler_promise_runner.ts +2184 -0
- package/project-transform/src/compiler_test_helpers.js +854 -0
- package/project-transform/src/compiler_test_helpers.ts +1087 -0
- package/project-transform/src/config.js +568 -0
- package/project-transform/src/config.ts +892 -0
- package/project-transform/src/diagnostic_metadata.js +67 -0
- package/project-transform/src/diagnostic_metadata.ts +99 -0
- package/project-transform/src/diagnostic_reference.js +1368 -0
- package/project-transform/src/diagnostic_reference.ts +1523 -0
- package/project-transform/src/editor_diagnostics_worker.js +176 -0
- package/project-transform/src/editor_diagnostics_worker.ts +250 -0
- package/project-transform/src/editor_projection.js +224 -0
- package/project-transform/src/editor_projection.ts +421 -0
- package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.js +47 -0
- package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.ts +72 -0
- package/project-transform/src/frontend/builtin_macro_support.js +842 -0
- package/project-transform/src/frontend/builtin_macro_support.ts +1386 -0
- package/project-transform/src/frontend/builtin_macros.js +409 -0
- package/project-transform/src/frontend/builtin_macros.ts +542 -0
- package/project-transform/src/frontend/component_poc_runtime.js +279 -0
- package/project-transform/src/frontend/component_poc_runtime.ts +372 -0
- package/project-transform/src/frontend/css_macro.js +148 -0
- package/project-transform/src/frontend/css_macro.ts +222 -0
- package/project-transform/src/frontend/derive_macros.js +2072 -0
- package/project-transform/src/frontend/derive_macros.ts +3188 -0
- package/project-transform/src/frontend/embedded_fragment_support.js +106 -0
- package/project-transform/src/frontend/embedded_fragment_support.ts +172 -0
- package/project-transform/src/frontend/error_normalization.js +403 -0
- package/project-transform/src/frontend/error_normalization.ts +832 -0
- package/project-transform/src/frontend/error_stdlib_support.js +1 -0
- package/project-transform/src/frontend/error_stdlib_support.ts +6 -0
- package/project-transform/src/frontend/expand_project.js +169 -0
- package/project-transform/src/frontend/expand_project.ts +248 -0
- package/project-transform/src/frontend/format_soundscript.js +297 -0
- package/project-transform/src/frontend/format_soundscript.ts +582 -0
- package/project-transform/src/frontend/graphql_macro.js +174 -0
- package/project-transform/src/frontend/graphql_macro.ts +253 -0
- package/project-transform/src/frontend/hash_context.js +83 -0
- package/project-transform/src/frontend/hash_context.ts +113 -0
- package/project-transform/src/frontend/hkt_macro.js +448 -0
- package/project-transform/src/frontend/hkt_macro.ts +897 -0
- package/project-transform/src/frontend/import_binding_usage.js +190 -0
- package/project-transform/src/frontend/import_binding_usage.ts +277 -0
- package/project-transform/src/frontend/macro_advanced_backend_adapter.js +58 -0
- package/project-transform/src/frontend/macro_advanced_backend_adapter.ts +123 -0
- package/project-transform/src/frontend/macro_advanced_context.js +826 -0
- package/project-transform/src/frontend/macro_advanced_context.ts +1102 -0
- package/project-transform/src/frontend/macro_advanced_output.js +21 -0
- package/project-transform/src/frontend/macro_advanced_output.ts +41 -0
- package/project-transform/src/frontend/macro_api.js +353 -0
- package/project-transform/src/frontend/macro_api.ts +1722 -0
- package/project-transform/src/frontend/macro_api_internal.js +35 -0
- package/project-transform/src/frontend/macro_api_internal.ts +80 -0
- package/project-transform/src/frontend/macro_api_module_support.js +39 -0
- package/project-transform/src/frontend/macro_api_module_support.ts +65 -0
- package/project-transform/src/frontend/macro_backend_adapter.js +272 -0
- package/project-transform/src/frontend/macro_backend_adapter.ts +420 -0
- package/project-transform/src/frontend/macro_context.js +816 -0
- package/project-transform/src/frontend/macro_context.ts +1105 -0
- package/project-transform/src/frontend/macro_debug.js +99 -0
- package/project-transform/src/frontend/macro_debug.ts +157 -0
- package/project-transform/src/frontend/macro_definition_support.js +28 -0
- package/project-transform/src/frontend/macro_definition_support.ts +73 -0
- package/project-transform/src/frontend/macro_errors.js +40 -0
- package/project-transform/src/frontend/macro_errors.ts +70 -0
- package/project-transform/src/frontend/macro_expander.js +919 -0
- package/project-transform/src/frontend/macro_expander.ts +1611 -0
- package/project-transform/src/frontend/macro_factory_support.js +176 -0
- package/project-transform/src/frontend/macro_factory_support.ts +263 -0
- package/project-transform/src/frontend/macro_host_ast_internal.js +64 -0
- package/project-transform/src/frontend/macro_host_ast_internal.ts +109 -0
- package/project-transform/src/frontend/macro_index.js +27 -0
- package/project-transform/src/frontend/macro_index.ts +50 -0
- package/project-transform/src/frontend/macro_loader.js +281 -0
- package/project-transform/src/frontend/macro_loader.ts +506 -0
- package/project-transform/src/frontend/macro_operand_semantics.js +838 -0
- package/project-transform/src/frontend/macro_operand_semantics.ts +1489 -0
- package/project-transform/src/frontend/macro_output.js +54 -0
- package/project-transform/src/frontend/macro_output.ts +123 -0
- package/project-transform/src/frontend/macro_parser.js +611 -0
- package/project-transform/src/frontend/macro_parser.ts +832 -0
- package/project-transform/src/frontend/macro_resolver.js +69 -0
- package/project-transform/src/frontend/macro_resolver.ts +125 -0
- package/project-transform/src/frontend/macro_rewrite.js +285 -0
- package/project-transform/src/frontend/macro_rewrite.ts +442 -0
- package/project-transform/src/frontend/macro_runtime_support.js +232 -0
- package/project-transform/src/frontend/macro_runtime_support.ts +324 -0
- package/project-transform/src/frontend/macro_scanner.js +393 -0
- package/project-transform/src/frontend/macro_scanner.ts +455 -0
- package/project-transform/src/frontend/macro_semantic_backend_adapter.js +87 -0
- package/project-transform/src/frontend/macro_semantic_backend_adapter.ts +166 -0
- package/project-transform/src/frontend/macro_semantic_context.js +5 -0
- package/project-transform/src/frontend/macro_semantic_context.ts +12 -0
- package/project-transform/src/frontend/macro_semantic_output.js +24 -0
- package/project-transform/src/frontend/macro_semantic_output.ts +47 -0
- package/project-transform/src/frontend/macro_semantic_types.js +1 -0
- package/project-transform/src/frontend/macro_semantic_types.ts +98 -0
- package/project-transform/src/frontend/macro_semantics.js +1172 -0
- package/project-transform/src/frontend/macro_semantics.ts +1502 -0
- package/project-transform/src/frontend/macro_site_kind_support.js +164 -0
- package/project-transform/src/frontend/macro_site_kind_support.ts +255 -0
- package/project-transform/src/frontend/macro_syntax_internal.js +1950 -0
- package/project-transform/src/frontend/macro_syntax_internal.ts +3338 -0
- package/project-transform/src/frontend/macro_templates.js +57 -0
- package/project-transform/src/frontend/macro_templates.ts +143 -0
- package/project-transform/src/frontend/macro_test_helpers.js +82 -0
- package/project-transform/src/frontend/macro_test_helpers.ts +136 -0
- package/project-transform/src/frontend/macro_types.js +1 -0
- package/project-transform/src/frontend/macro_types.ts +103 -0
- package/project-transform/src/frontend/macro_vm.js +39 -0
- package/project-transform/src/frontend/macro_vm.ts +113 -0
- package/project-transform/src/frontend/match_macro.js +885 -0
- package/project-transform/src/frontend/match_macro.ts +1220 -0
- package/project-transform/src/frontend/numeric_normalization.js +824 -0
- package/project-transform/src/frontend/numeric_normalization.ts +1380 -0
- package/project-transform/src/frontend/numeric_prelude.js +278 -0
- package/project-transform/src/frontend/numeric_prelude.ts +370 -0
- package/project-transform/src/frontend/project_frontend.js +2396 -0
- package/project-transform/src/frontend/project_frontend.ts +3776 -0
- package/project-transform/src/frontend/project_macro_support.js +1401 -0
- package/project-transform/src/frontend/project_macro_support.ts +2137 -0
- package/project-transform/src/frontend/sql_macro.js +175 -0
- package/project-transform/src/frontend/sql_macro.ts +254 -0
- package/project-transform/src/frontend/sql_stdlib_support.js +1 -0
- package/project-transform/src/frontend/sql_stdlib_support.ts +6 -0
- package/project-transform/src/frontend/std_package_support.js +228 -0
- package/project-transform/src/frontend/std_package_support.ts +400 -0
- package/project-transform/src/frontend/value_normalization.js +306 -0
- package/project-transform/src/frontend/value_normalization.ts +599 -0
- package/project-transform/src/lsp/project_service.js +4771 -0
- package/project-transform/src/lsp/project_service.ts +7580 -0
- package/project-transform/src/lsp/protocol.js +9 -0
- package/project-transform/src/lsp/protocol.ts +38 -0
- package/project-transform/src/lsp/server.js +355 -0
- package/project-transform/src/lsp/server.ts +671 -0
- package/project-transform/src/lsp/session.js +49 -0
- package/project-transform/src/lsp/session.ts +48 -0
- package/project-transform/src/lsp/timing.js +43 -0
- package/project-transform/src/lsp/timing.ts +76 -0
- package/project-transform/src/lsp/transport.js +205 -0
- package/project-transform/src/lsp/transport.ts +253 -0
- package/project-transform/src/lsp_main.js +5 -0
- package/project-transform/src/lsp_main.ts +7 -0
- package/project-transform/src/macros.d.ts +1 -0
- package/project-transform/src/macros.js +1 -0
- package/project-transform/src/macros.ts +1 -0
- package/project-transform/src/main.js +24 -0
- package/project-transform/src/main.ts +28 -0
- package/project-transform/src/platform/host.js +264 -0
- package/project-transform/src/platform/host.ts +343 -0
- package/project-transform/src/platform/path.js +8 -0
- package/project-transform/src/platform/path.ts +20 -0
- package/project-transform/src/public_macro_api/macro_api.d.ts +1054 -0
- package/project-transform/src/public_macro_api/macro_semantic_types.d.ts +66 -0
- package/project-transform/src/public_macro_api/macro_types.d.ts +70 -0
- package/project-transform/src/run_program.js +14 -0
- package/project-transform/src/run_program.ts +33 -0
- package/project-transform/src/runtime/materialize.js +371 -0
- package/project-transform/src/runtime/materialize.ts +502 -0
- package/project-transform/src/runtime/on_demand.js +203 -0
- package/project-transform/src/runtime/on_demand.ts +305 -0
- package/project-transform/src/runtime/source_maps.js +205 -0
- package/project-transform/src/runtime/source_maps.ts +297 -0
- package/project-transform/src/runtime/transform.js +148 -0
- package/project-transform/src/runtime/transform.ts +295 -0
- package/project-transform/src/service/types.js +1 -0
- package/project-transform/src/service/types.ts +22 -0
- package/project-transform/src/soundscript_packages.js +477 -0
- package/project-transform/src/soundscript_packages.ts +754 -0
- package/project-transform/src/soundscript_runtime_specifiers.js +88 -0
- package/project-transform/src/soundscript_runtime_specifiers.ts +96 -0
- package/project-transform/src/stdlib/async.d.ts +81 -0
- package/project-transform/src/stdlib/async.js +213 -0
- package/project-transform/src/stdlib/async.ts +315 -0
- package/project-transform/src/stdlib/codec.d.ts +32 -0
- package/project-transform/src/stdlib/codec.js +30 -0
- package/project-transform/src/stdlib/codec.ts +76 -0
- package/project-transform/src/stdlib/compare.d.ts +28 -0
- package/project-transform/src/stdlib/compare.js +115 -0
- package/project-transform/src/stdlib/compare.ts +151 -0
- package/project-transform/src/stdlib/css.d.ts +16 -0
- package/project-transform/src/stdlib/css.js +9 -0
- package/project-transform/src/stdlib/css.ts +28 -0
- package/project-transform/src/stdlib/debug.d.ts +2 -0
- package/project-transform/src/stdlib/debug.js +9 -0
- package/project-transform/src/stdlib/debug.ts +10 -0
- package/project-transform/src/stdlib/decode.d.ts +86 -0
- package/project-transform/src/stdlib/decode.js +254 -0
- package/project-transform/src/stdlib/decode.ts +390 -0
- package/project-transform/src/stdlib/derive.d.ts +6 -0
- package/project-transform/src/stdlib/derive.js +7 -0
- package/project-transform/src/stdlib/derive.ts +7 -0
- package/project-transform/src/stdlib/encode.d.ts +100 -0
- package/project-transform/src/stdlib/encode.js +130 -0
- package/project-transform/src/stdlib/encode.ts +259 -0
- package/project-transform/src/stdlib/failures.d.ts +23 -0
- package/project-transform/src/stdlib/failures.js +41 -0
- package/project-transform/src/stdlib/failures.ts +64 -0
- package/project-transform/src/stdlib/fetch.d.ts +67 -0
- package/project-transform/src/stdlib/fetch.js +5 -0
- package/project-transform/src/stdlib/fetch.ts +11 -0
- package/project-transform/src/stdlib/graphql.d.ts +16 -0
- package/project-transform/src/stdlib/graphql.js +9 -0
- package/project-transform/src/stdlib/graphql.ts +28 -0
- package/project-transform/src/stdlib/hash.d.ts +34 -0
- package/project-transform/src/stdlib/hash.js +110 -0
- package/project-transform/src/stdlib/hash.ts +188 -0
- package/project-transform/src/stdlib/hkt.d.ts +40 -0
- package/project-transform/src/stdlib/hkt.js +3 -0
- package/project-transform/src/stdlib/hkt.ts +41 -0
- package/project-transform/src/stdlib/index.d.ts +9 -0
- package/project-transform/src/stdlib/index.js +15 -0
- package/project-transform/src/stdlib/index.ts +23 -0
- package/project-transform/src/stdlib/json.d.ts +125 -0
- package/project-transform/src/stdlib/json.js +764 -0
- package/project-transform/src/stdlib/json.ts +1034 -0
- package/project-transform/src/stdlib/match.d.ts +11 -0
- package/project-transform/src/stdlib/match.js +13 -0
- package/project-transform/src/stdlib/match.ts +26 -0
- package/project-transform/src/stdlib/numerics.d.ts +523 -0
- package/project-transform/src/stdlib/numerics.js +1356 -0
- package/project-transform/src/stdlib/numerics.ts +1937 -0
- package/project-transform/src/stdlib/random.d.ts +19 -0
- package/project-transform/src/stdlib/random.js +3 -0
- package/project-transform/src/stdlib/random.ts +5 -0
- package/project-transform/src/stdlib/result.d.ts +68 -0
- package/project-transform/src/stdlib/result.js +139 -0
- package/project-transform/src/stdlib/result.ts +248 -0
- package/project-transform/src/stdlib/sql.d.ts +22 -0
- package/project-transform/src/stdlib/sql.js +23 -0
- package/project-transform/src/stdlib/sql.ts +53 -0
- package/project-transform/src/stdlib/text.d.ts +24 -0
- package/project-transform/src/stdlib/text.js +3 -0
- package/project-transform/src/stdlib/text.ts +4 -0
- package/project-transform/src/stdlib/thunk.d.ts +2 -0
- package/project-transform/src/stdlib/thunk.js +9 -0
- package/project-transform/src/stdlib/thunk.ts +15 -0
- package/project-transform/src/stdlib/typeclasses.d.ts +57 -0
- package/project-transform/src/stdlib/typeclasses.js +78 -0
- package/project-transform/src/stdlib/typeclasses.ts +173 -0
- package/project-transform/src/stdlib/url.d.ts +37 -0
- package/project-transform/src/stdlib/url.js +3 -0
- package/project-transform/src/stdlib/url.ts +4 -0
- package/project-transform/src/stdlib/value.d.ts +9 -0
- package/project-transform/src/stdlib/value.js +104 -0
- package/project-transform/src/stdlib/value.ts +133 -0
- package/project-transform/src/test_installed_stdlib.js +147 -0
- package/project-transform/src/test_installed_stdlib.ts +245 -0
- package/project-transform/src/test_macro_package_fixture.js +50 -0
- package/project-transform/src/test_macro_package_fixture.ts +68 -0
- package/project-transform/src/value_deep_safe.js +191 -0
- package/project-transform/src/value_deep_safe.ts +273 -0
|
@@ -0,0 +1,3132 @@
|
|
|
1
|
+
import { CompilerUnsupportedError } from './errors.js';
|
|
2
|
+
import { emitHostTaggedPrimitiveExternrefToTagged, emitTaggedPrimitiveToHostExternref, } from './wat_tagged.js';
|
|
3
|
+
export function emitArrayRuntimeImports(usage) {
|
|
4
|
+
const { usesHeapParamBoundary, usesHeapParamCopyBack, usesHeapResultBoundary, usesStringParamBoundary, usesStringParamCopyBack, usesStringResultBoundary, usesNumberParamBoundary, usesNumberParamCopyBack, usesNumberResultBoundary, usesBooleanParamBoundary, usesBooleanParamCopyBack, usesBooleanResultBoundary, usesTaggedParamBoundary, usesTaggedParamCopyBack, usesTaggedResultBoundary, } = usage;
|
|
5
|
+
if (!usesHeapResultBoundary &&
|
|
6
|
+
!usesHeapParamBoundary && !usesHeapParamCopyBack &&
|
|
7
|
+
!usesStringParamBoundary && !usesStringParamCopyBack && !usesStringResultBoundary &&
|
|
8
|
+
!usesNumberParamBoundary && !usesNumberParamCopyBack && !usesNumberResultBoundary &&
|
|
9
|
+
!usesBooleanParamBoundary && !usesBooleanParamCopyBack && !usesBooleanResultBoundary &&
|
|
10
|
+
!usesTaggedParamBoundary && !usesTaggedParamCopyBack && !usesTaggedResultBoundary) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const usesAnyParamBoundary = usesHeapParamBoundary || usesStringParamBoundary || usesNumberParamBoundary ||
|
|
14
|
+
usesBooleanParamBoundary || usesTaggedParamBoundary;
|
|
15
|
+
const usesAnyHeapBoundary = usesHeapParamBoundary || usesHeapParamCopyBack || usesHeapResultBoundary;
|
|
16
|
+
const usesAnyParamCopyBack = usesHeapParamCopyBack || usesStringParamCopyBack || usesNumberParamCopyBack ||
|
|
17
|
+
usesBooleanParamCopyBack || usesTaggedParamCopyBack || usesTaggedResultBoundary || usesAnyParamBoundary;
|
|
18
|
+
return [
|
|
19
|
+
...(usesAnyParamBoundary || usesAnyHeapBoundary
|
|
20
|
+
? [
|
|
21
|
+
'(import "soundscript_array" "length" (func $host_array_length (param externref) (result i32)))',
|
|
22
|
+
'(import "soundscript_array" "same" (func $host_array_same (param externref) (param externref) (result i32)))',
|
|
23
|
+
]
|
|
24
|
+
: []),
|
|
25
|
+
...(usesAnyHeapBoundary || usesStringParamBoundary || usesTaggedParamBoundary
|
|
26
|
+
? [
|
|
27
|
+
'(import "soundscript_array" "get" (func $host_array_get (param externref) (param i32) (result externref)))',
|
|
28
|
+
]
|
|
29
|
+
: []),
|
|
30
|
+
...(usesHeapResultBoundary || usesHeapParamCopyBack || usesStringParamBoundary || usesStringResultBoundary ||
|
|
31
|
+
usesTaggedParamBoundary || usesTaggedParamCopyBack || usesTaggedResultBoundary
|
|
32
|
+
? [
|
|
33
|
+
'(import "soundscript_array" "push" (func $host_array_push (param externref) (param externref)))',
|
|
34
|
+
]
|
|
35
|
+
: []),
|
|
36
|
+
...(usesAnyParamCopyBack
|
|
37
|
+
? ['(import "soundscript_array" "clear" (func $host_array_clear (param externref)))']
|
|
38
|
+
: []),
|
|
39
|
+
...(usesNumberParamBoundary
|
|
40
|
+
? [
|
|
41
|
+
'(import "soundscript_array" "get_number" (func $host_array_get_number (param externref) (param i32) (result f64)))',
|
|
42
|
+
]
|
|
43
|
+
: []),
|
|
44
|
+
...(usesNumberParamBoundary || usesNumberParamCopyBack || usesNumberResultBoundary
|
|
45
|
+
? [
|
|
46
|
+
'(import "soundscript_array" "push_number" (func $host_number_array_push (param externref) (param f64)))',
|
|
47
|
+
]
|
|
48
|
+
: []),
|
|
49
|
+
...(usesBooleanParamBoundary
|
|
50
|
+
? [
|
|
51
|
+
'(import "soundscript_array" "get_boolean" (func $host_array_get_boolean (param externref) (param i32) (result i32)))',
|
|
52
|
+
]
|
|
53
|
+
: []),
|
|
54
|
+
...(usesBooleanParamBoundary || usesBooleanParamCopyBack || usesBooleanResultBoundary
|
|
55
|
+
? [
|
|
56
|
+
'(import "soundscript_array" "push_boolean" (func $host_boolean_array_push (param externref) (param i32)))',
|
|
57
|
+
]
|
|
58
|
+
: []),
|
|
59
|
+
...(usesHeapResultBoundary || usesHeapParamCopyBack || usesStringResultBoundary ||
|
|
60
|
+
usesTaggedParamCopyBack || usesTaggedResultBoundary
|
|
61
|
+
? ['(import "soundscript_array" "empty" (func $host_array_empty (result externref)))']
|
|
62
|
+
: []),
|
|
63
|
+
...(usesNumberResultBoundary
|
|
64
|
+
? [
|
|
65
|
+
'(import "soundscript_array" "empty_number" (func $host_number_array_empty (result externref)))',
|
|
66
|
+
]
|
|
67
|
+
: []),
|
|
68
|
+
...(usesBooleanResultBoundary
|
|
69
|
+
? [
|
|
70
|
+
'(import "soundscript_array" "empty_boolean" (func $host_boolean_array_empty (result externref)))',
|
|
71
|
+
]
|
|
72
|
+
: []),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
function getOwnedArrayDataWatTypeName(kind) {
|
|
76
|
+
switch (kind) {
|
|
77
|
+
case 'heap':
|
|
78
|
+
return 'owned_heap_array_data';
|
|
79
|
+
case 'string':
|
|
80
|
+
return 'owned_string_array_data';
|
|
81
|
+
case 'number':
|
|
82
|
+
return 'owned_number_array_data';
|
|
83
|
+
case 'boolean':
|
|
84
|
+
return 'owned_boolean_array_data';
|
|
85
|
+
case 'tagged':
|
|
86
|
+
return 'owned_tagged_array_data';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function getOwnedArrayWatTypeName(kind) {
|
|
90
|
+
switch (kind) {
|
|
91
|
+
case 'heap':
|
|
92
|
+
return 'owned_heap_array';
|
|
93
|
+
case 'string':
|
|
94
|
+
return 'owned_string_array';
|
|
95
|
+
case 'number':
|
|
96
|
+
return 'owned_number_array';
|
|
97
|
+
case 'boolean':
|
|
98
|
+
return 'owned_boolean_array';
|
|
99
|
+
case 'tagged':
|
|
100
|
+
return 'owned_tagged_array';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export function emitOwnedArrayTypes(usage) {
|
|
104
|
+
const lines = [];
|
|
105
|
+
if (usage.usesOwnedHeapArray) {
|
|
106
|
+
lines.push('(type $owned_heap_array_data (array (mut (ref null eq))))');
|
|
107
|
+
lines.push('(type $owned_heap_array (struct (field (mut (ref null $owned_heap_array_data)))))');
|
|
108
|
+
}
|
|
109
|
+
if (usage.usesOwnedStringArray) {
|
|
110
|
+
lines.push('(type $owned_string_array_data (array (mut (ref null eq))))');
|
|
111
|
+
lines.push('(type $owned_string_array (struct (field (mut (ref null $owned_string_array_data)))))');
|
|
112
|
+
}
|
|
113
|
+
if (usage.usesOwnedNumberArray) {
|
|
114
|
+
lines.push('(type $owned_number_array_data (array (mut f64)))');
|
|
115
|
+
lines.push('(type $owned_number_array (struct (field (mut (ref null $owned_number_array_data)))))');
|
|
116
|
+
}
|
|
117
|
+
if (usage.usesOwnedBooleanArray) {
|
|
118
|
+
lines.push('(type $owned_boolean_array_data (array (mut i32)))');
|
|
119
|
+
lines.push('(type $owned_boolean_array (struct (field (mut (ref null $owned_boolean_array_data)))))');
|
|
120
|
+
}
|
|
121
|
+
if (usage.usesOwnedTaggedArray) {
|
|
122
|
+
lines.push('(type $owned_tagged_array_data (array (mut (ref null $tagged_value))))');
|
|
123
|
+
lines.push('(type $owned_tagged_array (struct (field (mut (ref null $owned_tagged_array_data)))))');
|
|
124
|
+
}
|
|
125
|
+
return lines;
|
|
126
|
+
}
|
|
127
|
+
export function getOwnedArrayToHostHelperName(kind) {
|
|
128
|
+
switch (kind) {
|
|
129
|
+
case 'string':
|
|
130
|
+
return 'owned_string_array_to_host_array';
|
|
131
|
+
case 'number':
|
|
132
|
+
return 'owned_number_array_to_host_array';
|
|
133
|
+
case 'boolean':
|
|
134
|
+
return 'owned_boolean_array_to_host_array';
|
|
135
|
+
case 'tagged':
|
|
136
|
+
return 'owned_tagged_array_to_host_array';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getTaggedArrayKindsSuffix(kinds) {
|
|
140
|
+
const primitiveSuffix = [
|
|
141
|
+
kinds.includesBoolean ? 'b' : '_',
|
|
142
|
+
kinds.includesNull ? 'n' : '_',
|
|
143
|
+
kinds.includesNumber ? 'd' : '_',
|
|
144
|
+
kinds.includesString ? 's' : '_',
|
|
145
|
+
kinds.includesUndefined ? 'u' : '_',
|
|
146
|
+
].join('');
|
|
147
|
+
if (!kinds.representation) {
|
|
148
|
+
return primitiveSuffix;
|
|
149
|
+
}
|
|
150
|
+
const representationHex = [...new TextEncoder().encode(kinds.representation.name)]
|
|
151
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
152
|
+
.join('');
|
|
153
|
+
return `${primitiveSuffix}__${representationHex}`;
|
|
154
|
+
}
|
|
155
|
+
export function getHostArrayToOwnedTaggedArrayHelperName(kinds) {
|
|
156
|
+
return `host_array_to_owned_tagged_array__${getTaggedArrayKindsSuffix(kinds)}`;
|
|
157
|
+
}
|
|
158
|
+
export function getOwnedTaggedArrayToHostHelperName(kinds) {
|
|
159
|
+
return `owned_tagged_array_to_host_array__${getTaggedArrayKindsSuffix(kinds)}`;
|
|
160
|
+
}
|
|
161
|
+
export function getCopyOwnedTaggedArrayToHostHelperName(kinds) {
|
|
162
|
+
return `copy_owned_tagged_array_to_host_array__${getTaggedArrayKindsSuffix(kinds)}`;
|
|
163
|
+
}
|
|
164
|
+
function getTaggedArraySpecializedObjectToHostHelperName(watTypeId) {
|
|
165
|
+
return `${watTypeId}_to_host_object`;
|
|
166
|
+
}
|
|
167
|
+
function getTaggedArrayHostObjectToSpecializedHelperName(watTypeId) {
|
|
168
|
+
return `host_object_to_${watTypeId}`;
|
|
169
|
+
}
|
|
170
|
+
function getTaggedArrayCopySpecializedObjectToHostHelperName(watTypeId) {
|
|
171
|
+
return `copy_${watTypeId}_to_host_object`;
|
|
172
|
+
}
|
|
173
|
+
function getTaggedArrayCopyFallbackObjectToHostHelperName() {
|
|
174
|
+
return 'copy_fallback_object_to_host_object';
|
|
175
|
+
}
|
|
176
|
+
function getOwnedArrayPushHelperName(kind) {
|
|
177
|
+
switch (kind) {
|
|
178
|
+
case 'string':
|
|
179
|
+
return 'owned_string_array_push';
|
|
180
|
+
case 'number':
|
|
181
|
+
return 'owned_number_array_push';
|
|
182
|
+
case 'boolean':
|
|
183
|
+
return 'owned_boolean_array_push';
|
|
184
|
+
case 'tagged':
|
|
185
|
+
return 'owned_tagged_array_push';
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function getOwnedArrayUnshiftHelperName(kind) {
|
|
189
|
+
switch (kind) {
|
|
190
|
+
case 'string':
|
|
191
|
+
return 'owned_string_array_unshift';
|
|
192
|
+
case 'number':
|
|
193
|
+
return 'owned_number_array_unshift';
|
|
194
|
+
case 'boolean':
|
|
195
|
+
return 'owned_boolean_array_unshift';
|
|
196
|
+
case 'tagged':
|
|
197
|
+
return 'owned_tagged_array_unshift';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function getOwnedArrayPopHelperName(kind) {
|
|
201
|
+
switch (kind) {
|
|
202
|
+
case 'heap':
|
|
203
|
+
return 'owned_heap_array_pop';
|
|
204
|
+
case 'string':
|
|
205
|
+
return 'owned_string_array_pop';
|
|
206
|
+
case 'number':
|
|
207
|
+
return 'owned_number_array_pop';
|
|
208
|
+
case 'boolean':
|
|
209
|
+
return 'owned_boolean_array_pop';
|
|
210
|
+
case 'tagged':
|
|
211
|
+
return 'owned_tagged_array_pop';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function getOwnedArrayShiftHelperName(kind) {
|
|
215
|
+
switch (kind) {
|
|
216
|
+
case 'heap':
|
|
217
|
+
return 'owned_heap_array_shift';
|
|
218
|
+
case 'string':
|
|
219
|
+
return 'owned_string_array_shift';
|
|
220
|
+
case 'number':
|
|
221
|
+
return 'owned_number_array_shift';
|
|
222
|
+
case 'boolean':
|
|
223
|
+
return 'owned_boolean_array_shift';
|
|
224
|
+
case 'tagged':
|
|
225
|
+
return 'owned_tagged_array_shift';
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function getOwnedArrayAtHelperName(kind) {
|
|
229
|
+
switch (kind) {
|
|
230
|
+
case 'heap':
|
|
231
|
+
return 'owned_heap_array_at';
|
|
232
|
+
case 'string':
|
|
233
|
+
return 'owned_string_array_at';
|
|
234
|
+
case 'number':
|
|
235
|
+
return 'owned_number_array_at';
|
|
236
|
+
case 'boolean':
|
|
237
|
+
return 'owned_boolean_array_at';
|
|
238
|
+
case 'tagged':
|
|
239
|
+
return 'owned_tagged_array_at';
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function getOwnedArrayJoinHelperName(kind) {
|
|
243
|
+
switch (kind) {
|
|
244
|
+
case 'string':
|
|
245
|
+
return 'owned_string_array_join';
|
|
246
|
+
case 'number':
|
|
247
|
+
return 'owned_number_array_join';
|
|
248
|
+
case 'boolean':
|
|
249
|
+
return 'owned_boolean_array_join';
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function getOwnedArrayReverseHelperName(kind) {
|
|
253
|
+
switch (kind) {
|
|
254
|
+
case 'heap':
|
|
255
|
+
return 'owned_heap_array_reverse';
|
|
256
|
+
case 'string':
|
|
257
|
+
return 'owned_string_array_reverse';
|
|
258
|
+
case 'number':
|
|
259
|
+
return 'owned_number_array_reverse';
|
|
260
|
+
case 'boolean':
|
|
261
|
+
return 'owned_boolean_array_reverse';
|
|
262
|
+
case 'tagged':
|
|
263
|
+
return 'owned_tagged_array_reverse';
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function getOwnedArrayFillHelperName(kind) {
|
|
267
|
+
switch (kind) {
|
|
268
|
+
case 'heap':
|
|
269
|
+
return 'owned_heap_array_fill';
|
|
270
|
+
case 'string':
|
|
271
|
+
return 'owned_string_array_fill';
|
|
272
|
+
case 'number':
|
|
273
|
+
return 'owned_number_array_fill';
|
|
274
|
+
case 'boolean':
|
|
275
|
+
return 'owned_boolean_array_fill';
|
|
276
|
+
case 'tagged':
|
|
277
|
+
return 'owned_tagged_array_fill';
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function getOwnedArrayCopyWithinHelperName(kind) {
|
|
281
|
+
switch (kind) {
|
|
282
|
+
case 'heap':
|
|
283
|
+
return 'owned_heap_array_copy_within';
|
|
284
|
+
case 'string':
|
|
285
|
+
return 'owned_string_array_copy_within';
|
|
286
|
+
case 'number':
|
|
287
|
+
return 'owned_number_array_copy_within';
|
|
288
|
+
case 'boolean':
|
|
289
|
+
return 'owned_boolean_array_copy_within';
|
|
290
|
+
case 'tagged':
|
|
291
|
+
return 'owned_tagged_array_copy_within';
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function getOwnedArraySliceHelperName(kind) {
|
|
295
|
+
switch (kind) {
|
|
296
|
+
case 'heap':
|
|
297
|
+
return 'owned_heap_array_slice';
|
|
298
|
+
case 'string':
|
|
299
|
+
return 'owned_string_array_slice';
|
|
300
|
+
case 'number':
|
|
301
|
+
return 'owned_number_array_slice';
|
|
302
|
+
case 'boolean':
|
|
303
|
+
return 'owned_boolean_array_slice';
|
|
304
|
+
case 'tagged':
|
|
305
|
+
return 'owned_tagged_array_slice';
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function getOwnedArraySpliceHelperName(kind) {
|
|
309
|
+
switch (kind) {
|
|
310
|
+
case 'heap':
|
|
311
|
+
return 'owned_heap_array_splice';
|
|
312
|
+
case 'string':
|
|
313
|
+
return 'owned_string_array_splice';
|
|
314
|
+
case 'number':
|
|
315
|
+
return 'owned_number_array_splice';
|
|
316
|
+
case 'boolean':
|
|
317
|
+
return 'owned_boolean_array_splice';
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function getOwnedArrayConcatHelperName(kind) {
|
|
321
|
+
switch (kind) {
|
|
322
|
+
case 'heap':
|
|
323
|
+
return 'owned_heap_array_concat';
|
|
324
|
+
case 'string':
|
|
325
|
+
return 'owned_string_array_concat';
|
|
326
|
+
case 'number':
|
|
327
|
+
return 'owned_number_array_concat';
|
|
328
|
+
case 'boolean':
|
|
329
|
+
return 'owned_boolean_array_concat';
|
|
330
|
+
case 'tagged':
|
|
331
|
+
return 'owned_tagged_array_concat';
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function getOwnedArrayIncludesHelperName(kind) {
|
|
335
|
+
switch (kind) {
|
|
336
|
+
case 'heap':
|
|
337
|
+
return 'owned_heap_array_includes';
|
|
338
|
+
case 'string':
|
|
339
|
+
return 'owned_string_array_includes';
|
|
340
|
+
case 'number':
|
|
341
|
+
return 'owned_number_array_includes';
|
|
342
|
+
case 'boolean':
|
|
343
|
+
return 'owned_boolean_array_includes';
|
|
344
|
+
case 'tagged':
|
|
345
|
+
return 'owned_tagged_array_includes';
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function getOwnedArrayIndexOfHelperName(kind) {
|
|
349
|
+
switch (kind) {
|
|
350
|
+
case 'heap':
|
|
351
|
+
return 'owned_heap_array_index_of';
|
|
352
|
+
case 'string':
|
|
353
|
+
return 'owned_string_array_index_of';
|
|
354
|
+
case 'number':
|
|
355
|
+
return 'owned_number_array_index_of';
|
|
356
|
+
case 'boolean':
|
|
357
|
+
return 'owned_boolean_array_index_of';
|
|
358
|
+
case 'tagged':
|
|
359
|
+
return 'owned_tagged_array_index_of';
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function getOwnedArrayLastIndexOfHelperName(kind) {
|
|
363
|
+
switch (kind) {
|
|
364
|
+
case 'heap':
|
|
365
|
+
return 'owned_heap_array_last_index_of';
|
|
366
|
+
case 'string':
|
|
367
|
+
return 'owned_string_array_last_index_of';
|
|
368
|
+
case 'number':
|
|
369
|
+
return 'owned_number_array_last_index_of';
|
|
370
|
+
case 'boolean':
|
|
371
|
+
return 'owned_boolean_array_last_index_of';
|
|
372
|
+
case 'tagged':
|
|
373
|
+
return 'owned_tagged_array_last_index_of';
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function getOwnedArrayBoundaryLabelPrefix(kind) {
|
|
377
|
+
switch (kind) {
|
|
378
|
+
case 'string':
|
|
379
|
+
return 'array';
|
|
380
|
+
case 'number':
|
|
381
|
+
return 'number_array';
|
|
382
|
+
case 'boolean':
|
|
383
|
+
return 'boolean_array';
|
|
384
|
+
case 'tagged':
|
|
385
|
+
return 'tagged_array';
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function getHostArrayGetHelperName(kind) {
|
|
389
|
+
switch (kind) {
|
|
390
|
+
case 'string':
|
|
391
|
+
return 'host_array_get';
|
|
392
|
+
case 'number':
|
|
393
|
+
return 'host_array_get_number';
|
|
394
|
+
case 'boolean':
|
|
395
|
+
return 'host_array_get_boolean';
|
|
396
|
+
case 'tagged':
|
|
397
|
+
return 'host_array_get';
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function getHostArrayPushHelperName(kind) {
|
|
401
|
+
switch (kind) {
|
|
402
|
+
case 'string':
|
|
403
|
+
return 'host_array_push';
|
|
404
|
+
case 'number':
|
|
405
|
+
return 'host_number_array_push';
|
|
406
|
+
case 'boolean':
|
|
407
|
+
return 'host_boolean_array_push';
|
|
408
|
+
case 'tagged':
|
|
409
|
+
return 'host_array_push';
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function getHostArrayEmptyHelperName(kind) {
|
|
413
|
+
switch (kind) {
|
|
414
|
+
case 'string':
|
|
415
|
+
return 'host_array_empty';
|
|
416
|
+
case 'number':
|
|
417
|
+
return 'host_number_array_empty';
|
|
418
|
+
case 'boolean':
|
|
419
|
+
return 'host_boolean_array_empty';
|
|
420
|
+
case 'tagged':
|
|
421
|
+
return 'host_array_empty';
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
function getOwnedArrayPushValueWatType(kind) {
|
|
425
|
+
switch (kind) {
|
|
426
|
+
case 'heap':
|
|
427
|
+
return '(ref null eq)';
|
|
428
|
+
case 'string':
|
|
429
|
+
return '(ref null $string_runtime)';
|
|
430
|
+
case 'number':
|
|
431
|
+
return 'f64';
|
|
432
|
+
case 'boolean':
|
|
433
|
+
return 'i32';
|
|
434
|
+
case 'tagged':
|
|
435
|
+
return '(ref null $tagged_value)';
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function emitHostArrayElementToOwnedBackingLines(kind, backingLocalName, indexLocalName, sourceLocalName, indent, taggedKinds, layoutsByRepresentationName, createUnsupportedHeapRuntimeBackendError) {
|
|
439
|
+
if (kind === 'tagged') {
|
|
440
|
+
if (!taggedKinds) {
|
|
441
|
+
throw new Error('Tagged array host-to-owned helpers require tagged element kinds.');
|
|
442
|
+
}
|
|
443
|
+
if (!taggedKinds.representation) {
|
|
444
|
+
return [
|
|
445
|
+
`${indent(3)}local.get $${sourceLocalName}`,
|
|
446
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
447
|
+
`${indent(3)}call $host_array_get`,
|
|
448
|
+
`${indent(3)}local.set $element_host`,
|
|
449
|
+
...emitHostTaggedPrimitiveExternrefToTagged('element_host', 'element_tag', 'element_tagged', taggedKinds, 3, indent),
|
|
450
|
+
`${indent(3)}local.get $${backingLocalName}`,
|
|
451
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
452
|
+
`${indent(3)}local.get $element_tagged`,
|
|
453
|
+
`${indent(3)}array.set $${getOwnedArrayDataWatTypeName(kind)}`,
|
|
454
|
+
];
|
|
455
|
+
}
|
|
456
|
+
if (!createUnsupportedHeapRuntimeBackendError) {
|
|
457
|
+
throw new Error('Tagged heap-array host-to-owned helpers require backend error construction.');
|
|
458
|
+
}
|
|
459
|
+
const specializedWatTypeId = taggedKinds.representation.kind === 'specialized_object_representation'
|
|
460
|
+
? layoutsByRepresentationName?.get(taggedKinds.representation.name)?.watTypeId ??
|
|
461
|
+
(() => {
|
|
462
|
+
throw createUnsupportedHeapRuntimeBackendError(`Missing specialized object layout for tagged array boundary ${taggedKinds.representation.name}.`);
|
|
463
|
+
})()
|
|
464
|
+
: undefined;
|
|
465
|
+
return [
|
|
466
|
+
`${indent(3)}local.get $${sourceLocalName}`,
|
|
467
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
468
|
+
`${indent(3)}call $host_array_get`,
|
|
469
|
+
`${indent(3)}local.set $element_host`,
|
|
470
|
+
`${indent(3)}local.get $element_host`,
|
|
471
|
+
`${indent(3)}call $tagged_type_tag`,
|
|
472
|
+
`${indent(3)}local.set $element_tag`,
|
|
473
|
+
`${indent(3)}(block $element_tagged_done`,
|
|
474
|
+
...(taggedKinds.includesUndefined
|
|
475
|
+
? [
|
|
476
|
+
`${indent(4)}local.get $element_tag`,
|
|
477
|
+
`${indent(4)}i32.const 0`,
|
|
478
|
+
`${indent(4)}i32.eq`,
|
|
479
|
+
`${indent(4)}(if`,
|
|
480
|
+
`${indent(5)}(then`,
|
|
481
|
+
`${indent(6)}call $tag_undefined`,
|
|
482
|
+
`${indent(6)}local.set $element_tagged`,
|
|
483
|
+
`${indent(6)}br $element_tagged_done`,
|
|
484
|
+
`${indent(5)})`,
|
|
485
|
+
`${indent(4)})`,
|
|
486
|
+
]
|
|
487
|
+
: []),
|
|
488
|
+
...(taggedKinds.includesNull
|
|
489
|
+
? [
|
|
490
|
+
`${indent(4)}local.get $element_tag`,
|
|
491
|
+
`${indent(4)}i32.const 6`,
|
|
492
|
+
`${indent(4)}i32.eq`,
|
|
493
|
+
`${indent(4)}(if`,
|
|
494
|
+
`${indent(5)}(then`,
|
|
495
|
+
`${indent(6)}call $tag_null`,
|
|
496
|
+
`${indent(6)}local.set $element_tagged`,
|
|
497
|
+
`${indent(6)}br $element_tagged_done`,
|
|
498
|
+
`${indent(5)})`,
|
|
499
|
+
`${indent(4)})`,
|
|
500
|
+
]
|
|
501
|
+
: []),
|
|
502
|
+
...(taggedKinds.includesBoolean
|
|
503
|
+
? [
|
|
504
|
+
`${indent(4)}local.get $element_tag`,
|
|
505
|
+
`${indent(4)}i32.const 1`,
|
|
506
|
+
`${indent(4)}i32.eq`,
|
|
507
|
+
`${indent(4)}(if`,
|
|
508
|
+
`${indent(5)}(then`,
|
|
509
|
+
`${indent(6)}local.get $element_host`,
|
|
510
|
+
`${indent(6)}call $tagged_boolean_value`,
|
|
511
|
+
`${indent(6)}call $tag_boolean`,
|
|
512
|
+
`${indent(6)}local.set $element_tagged`,
|
|
513
|
+
`${indent(6)}br $element_tagged_done`,
|
|
514
|
+
`${indent(5)})`,
|
|
515
|
+
`${indent(4)})`,
|
|
516
|
+
]
|
|
517
|
+
: []),
|
|
518
|
+
...(taggedKinds.includesNumber
|
|
519
|
+
? [
|
|
520
|
+
`${indent(4)}local.get $element_tag`,
|
|
521
|
+
`${indent(4)}i32.const 2`,
|
|
522
|
+
`${indent(4)}i32.eq`,
|
|
523
|
+
`${indent(4)}(if`,
|
|
524
|
+
`${indent(5)}(then`,
|
|
525
|
+
`${indent(6)}local.get $element_host`,
|
|
526
|
+
`${indent(6)}call $tagged_number_value`,
|
|
527
|
+
`${indent(6)}call $tag_number`,
|
|
528
|
+
`${indent(6)}local.set $element_tagged`,
|
|
529
|
+
`${indent(6)}br $element_tagged_done`,
|
|
530
|
+
`${indent(5)})`,
|
|
531
|
+
`${indent(4)})`,
|
|
532
|
+
]
|
|
533
|
+
: []),
|
|
534
|
+
...(taggedKinds.includesString
|
|
535
|
+
? [
|
|
536
|
+
`${indent(4)}local.get $element_tag`,
|
|
537
|
+
`${indent(4)}i32.const 3`,
|
|
538
|
+
`${indent(4)}i32.eq`,
|
|
539
|
+
`${indent(4)}(if`,
|
|
540
|
+
`${indent(5)}(then`,
|
|
541
|
+
`${indent(6)}local.get $element_host`,
|
|
542
|
+
`${indent(6)}call $string_to_owned`,
|
|
543
|
+
`${indent(6)}call $tag_string`,
|
|
544
|
+
`${indent(6)}local.set $element_tagged`,
|
|
545
|
+
`${indent(6)}br $element_tagged_done`,
|
|
546
|
+
`${indent(5)})`,
|
|
547
|
+
`${indent(4)})`,
|
|
548
|
+
]
|
|
549
|
+
: []),
|
|
550
|
+
`${indent(4)}local.get $element_tag`,
|
|
551
|
+
`${indent(4)}i32.const 4`,
|
|
552
|
+
`${indent(4)}i32.eq`,
|
|
553
|
+
`${indent(4)}(if`,
|
|
554
|
+
`${indent(5)}(then`,
|
|
555
|
+
`${indent(6)}local.get $element_host`,
|
|
556
|
+
`${indent(6)}call $${taggedKinds.representation.kind === 'specialized_object_representation'
|
|
557
|
+
? getTaggedArrayHostObjectToSpecializedHelperName(specializedWatTypeId)
|
|
558
|
+
: 'host_object_to_fallback_object'}`,
|
|
559
|
+
`${indent(6)}call $tag_heap_object`,
|
|
560
|
+
`${indent(6)}local.set $element_tagged`,
|
|
561
|
+
`${indent(6)}br $element_tagged_done`,
|
|
562
|
+
`${indent(5)})`,
|
|
563
|
+
`${indent(4)})`,
|
|
564
|
+
`${indent(4)}unreachable`,
|
|
565
|
+
`${indent(3)})`,
|
|
566
|
+
`${indent(3)}local.get $${backingLocalName}`,
|
|
567
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
568
|
+
`${indent(3)}local.get $element_tagged`,
|
|
569
|
+
`${indent(3)}array.set $${getOwnedArrayDataWatTypeName(kind)}`,
|
|
570
|
+
];
|
|
571
|
+
}
|
|
572
|
+
return [
|
|
573
|
+
`${indent(3)}local.get $${backingLocalName}`,
|
|
574
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
575
|
+
`${indent(3)}local.get $${sourceLocalName}`,
|
|
576
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
577
|
+
`${indent(3)}call $${getHostArrayGetHelperName(kind)}`,
|
|
578
|
+
...(kind === 'string' ? [`${indent(3)}call $string_to_owned`] : []),
|
|
579
|
+
`${indent(3)}array.set $${getOwnedArrayDataWatTypeName(kind)}`,
|
|
580
|
+
];
|
|
581
|
+
}
|
|
582
|
+
function emitOwnedBackingElementToHostArrayLines(kind, hostTargetLocalName, backingLocalName, indexLocalName, indent, stringRuntimeLayout, taggedKinds, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError) {
|
|
583
|
+
if (kind === 'tagged') {
|
|
584
|
+
if (!taggedKinds) {
|
|
585
|
+
throw new Error('Tagged array owned-to-host helpers require tagged element kinds.');
|
|
586
|
+
}
|
|
587
|
+
if (!taggedKinds.representation) {
|
|
588
|
+
return [
|
|
589
|
+
`${indent(3)}local.get $${backingLocalName}`,
|
|
590
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
591
|
+
`${indent(3)}array.get $${getOwnedArrayDataWatTypeName(kind)}`,
|
|
592
|
+
`${indent(3)}local.set $element_tagged`,
|
|
593
|
+
...emitTaggedPrimitiveToHostExternref('element_tagged', 'element_tag', 'element_host', taggedKinds, 3, indent),
|
|
594
|
+
`${indent(3)}local.get $${hostTargetLocalName}`,
|
|
595
|
+
`${indent(3)}local.get $element_host`,
|
|
596
|
+
`${indent(3)}call $${getHostArrayPushHelperName(kind)}`,
|
|
597
|
+
];
|
|
598
|
+
}
|
|
599
|
+
if (!createUnsupportedHeapRuntimeBackendError) {
|
|
600
|
+
throw new Error('Tagged heap-array owned-to-host helpers require backend error construction.');
|
|
601
|
+
}
|
|
602
|
+
const specializedWatTypeId = taggedKinds.representation.kind === 'specialized_object_representation'
|
|
603
|
+
? layoutsByRepresentationName?.get(taggedKinds.representation.name)?.watTypeId ??
|
|
604
|
+
(() => {
|
|
605
|
+
throw createUnsupportedHeapRuntimeBackendError(`Missing specialized object layout for tagged array boundary ${taggedKinds.representation.name}.`);
|
|
606
|
+
})()
|
|
607
|
+
: undefined;
|
|
608
|
+
const fallbackWatTypeId = taggedKinds.representation.kind === 'fallback_object_representation'
|
|
609
|
+
? fallbackObjectWatTypeId ??
|
|
610
|
+
(() => {
|
|
611
|
+
throw createUnsupportedHeapRuntimeBackendError('Missing fallback object layout for tagged array host boundary helper.');
|
|
612
|
+
})()
|
|
613
|
+
: undefined;
|
|
614
|
+
return [
|
|
615
|
+
`${indent(3)}local.get $${backingLocalName}`,
|
|
616
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
617
|
+
`${indent(3)}array.get $${getOwnedArrayDataWatTypeName(kind)}`,
|
|
618
|
+
`${indent(3)}local.set $element_tagged`,
|
|
619
|
+
`${indent(3)}local.get $element_tagged`,
|
|
620
|
+
`${indent(3)}struct.get $tagged_value 0`,
|
|
621
|
+
`${indent(3)}local.set $element_tag`,
|
|
622
|
+
`${indent(3)}(block $element_host_done`,
|
|
623
|
+
...(taggedKinds.includesUndefined
|
|
624
|
+
? [
|
|
625
|
+
`${indent(4)}local.get $element_tag`,
|
|
626
|
+
`${indent(4)}i32.const 0`,
|
|
627
|
+
`${indent(4)}i32.eq`,
|
|
628
|
+
`${indent(4)}(if`,
|
|
629
|
+
`${indent(5)}(then`,
|
|
630
|
+
`${indent(6)}call $tagged_undefined_value`,
|
|
631
|
+
`${indent(6)}local.set $element_host`,
|
|
632
|
+
`${indent(6)}br $element_host_done`,
|
|
633
|
+
`${indent(5)})`,
|
|
634
|
+
`${indent(4)})`,
|
|
635
|
+
]
|
|
636
|
+
: []),
|
|
637
|
+
...(taggedKinds.includesNull
|
|
638
|
+
? [
|
|
639
|
+
`${indent(4)}local.get $element_tag`,
|
|
640
|
+
`${indent(4)}i32.const 6`,
|
|
641
|
+
`${indent(4)}i32.eq`,
|
|
642
|
+
`${indent(4)}(if`,
|
|
643
|
+
`${indent(5)}(then`,
|
|
644
|
+
`${indent(6)}ref.null extern`,
|
|
645
|
+
`${indent(6)}local.set $element_host`,
|
|
646
|
+
`${indent(6)}br $element_host_done`,
|
|
647
|
+
`${indent(5)})`,
|
|
648
|
+
`${indent(4)})`,
|
|
649
|
+
]
|
|
650
|
+
: []),
|
|
651
|
+
...(taggedKinds.includesBoolean
|
|
652
|
+
? [
|
|
653
|
+
`${indent(4)}local.get $element_tag`,
|
|
654
|
+
`${indent(4)}i32.const 1`,
|
|
655
|
+
`${indent(4)}i32.eq`,
|
|
656
|
+
`${indent(4)}(if`,
|
|
657
|
+
`${indent(5)}(then`,
|
|
658
|
+
`${indent(6)}local.get $element_tagged`,
|
|
659
|
+
`${indent(6)}call $untag_boolean`,
|
|
660
|
+
`${indent(6)}call $tagged_from_boolean`,
|
|
661
|
+
`${indent(6)}local.set $element_host`,
|
|
662
|
+
`${indent(6)}br $element_host_done`,
|
|
663
|
+
`${indent(5)})`,
|
|
664
|
+
`${indent(4)})`,
|
|
665
|
+
]
|
|
666
|
+
: []),
|
|
667
|
+
...(taggedKinds.includesNumber
|
|
668
|
+
? [
|
|
669
|
+
`${indent(4)}local.get $element_tag`,
|
|
670
|
+
`${indent(4)}i32.const 2`,
|
|
671
|
+
`${indent(4)}i32.eq`,
|
|
672
|
+
`${indent(4)}(if`,
|
|
673
|
+
`${indent(5)}(then`,
|
|
674
|
+
`${indent(6)}local.get $element_tagged`,
|
|
675
|
+
`${indent(6)}call $untag_number`,
|
|
676
|
+
`${indent(6)}call $tagged_from_number`,
|
|
677
|
+
`${indent(6)}local.set $element_host`,
|
|
678
|
+
`${indent(6)}br $element_host_done`,
|
|
679
|
+
`${indent(5)})`,
|
|
680
|
+
`${indent(4)})`,
|
|
681
|
+
]
|
|
682
|
+
: []),
|
|
683
|
+
...(taggedKinds.includesString
|
|
684
|
+
? [
|
|
685
|
+
`${indent(4)}local.get $element_tag`,
|
|
686
|
+
`${indent(4)}i32.const 3`,
|
|
687
|
+
`${indent(4)}i32.eq`,
|
|
688
|
+
`${indent(4)}(if`,
|
|
689
|
+
`${indent(5)}(then`,
|
|
690
|
+
`${indent(6)}local.get $element_tagged`,
|
|
691
|
+
`${indent(6)}call $untag_string`,
|
|
692
|
+
`${indent(6)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
693
|
+
`${indent(6)}call $owned_string_to_host`,
|
|
694
|
+
`${indent(6)}local.set $element_host`,
|
|
695
|
+
`${indent(6)}br $element_host_done`,
|
|
696
|
+
`${indent(5)})`,
|
|
697
|
+
`${indent(4)})`,
|
|
698
|
+
]
|
|
699
|
+
: []),
|
|
700
|
+
`${indent(4)}local.get $element_tag`,
|
|
701
|
+
`${indent(4)}i32.const 4`,
|
|
702
|
+
`${indent(4)}i32.eq`,
|
|
703
|
+
`${indent(4)}(if`,
|
|
704
|
+
`${indent(5)}(then`,
|
|
705
|
+
`${indent(6)}local.get $element_tagged`,
|
|
706
|
+
`${indent(6)}call $untag_heap_object`,
|
|
707
|
+
`${indent(6)}ref.cast ${taggedKinds.representation.kind === 'specialized_object_representation'
|
|
708
|
+
? `(ref null $${specializedWatTypeId})`
|
|
709
|
+
: `(ref null $${fallbackWatTypeId})`}`,
|
|
710
|
+
`${indent(6)}call $${taggedKinds.representation.kind === 'specialized_object_representation'
|
|
711
|
+
? getTaggedArraySpecializedObjectToHostHelperName(specializedWatTypeId)
|
|
712
|
+
: 'fallback_object_to_host_object'}`,
|
|
713
|
+
`${indent(6)}local.set $element_host`,
|
|
714
|
+
`${indent(6)}br $element_host_done`,
|
|
715
|
+
`${indent(5)})`,
|
|
716
|
+
`${indent(4)})`,
|
|
717
|
+
`${indent(4)}unreachable`,
|
|
718
|
+
`${indent(3)})`,
|
|
719
|
+
`${indent(3)}local.get $${hostTargetLocalName}`,
|
|
720
|
+
`${indent(3)}local.get $element_host`,
|
|
721
|
+
`${indent(3)}call $${getHostArrayPushHelperName(kind)}`,
|
|
722
|
+
];
|
|
723
|
+
}
|
|
724
|
+
return [
|
|
725
|
+
`${indent(3)}local.get $${hostTargetLocalName}`,
|
|
726
|
+
`${indent(3)}local.get $${backingLocalName}`,
|
|
727
|
+
`${indent(3)}local.get $${indexLocalName}`,
|
|
728
|
+
`${indent(3)}array.get $${getOwnedArrayDataWatTypeName(kind)}`,
|
|
729
|
+
...(kind === 'string'
|
|
730
|
+
? [
|
|
731
|
+
`${indent(3)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
732
|
+
`${indent(3)}call $owned_string_to_host`,
|
|
733
|
+
]
|
|
734
|
+
: []),
|
|
735
|
+
`${indent(3)}call $${getHostArrayPushHelperName(kind)}`,
|
|
736
|
+
];
|
|
737
|
+
}
|
|
738
|
+
function emitHostArrayToOwnedArrayHelper(kind, indent, taggedKinds, layoutsByRepresentationName, createUnsupportedHeapRuntimeBackendError) {
|
|
739
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
740
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
741
|
+
const labelPrefix = getOwnedArrayBoundaryLabelPrefix(kind);
|
|
742
|
+
return [
|
|
743
|
+
`(func $host_array_to_${wrapperTypeName} (param $value externref) (result (ref null $${wrapperTypeName}))`,
|
|
744
|
+
`${indent(1)}(local $length i32)`,
|
|
745
|
+
`${indent(1)}(local $index i32)`,
|
|
746
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
747
|
+
...(kind === 'tagged'
|
|
748
|
+
? [
|
|
749
|
+
`${indent(1)}(local $element_host externref)`,
|
|
750
|
+
`${indent(1)}(local $element_tag i32)`,
|
|
751
|
+
`${indent(1)}(local $element_tagged (ref null $tagged_value))`,
|
|
752
|
+
]
|
|
753
|
+
: []),
|
|
754
|
+
`${indent(1)}local.get $value`,
|
|
755
|
+
`${indent(1)}call $host_array_length`,
|
|
756
|
+
`${indent(1)}local.set $length`,
|
|
757
|
+
`${indent(1)}local.get $length`,
|
|
758
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
759
|
+
`${indent(1)}local.set $backing`,
|
|
760
|
+
`${indent(1)}i32.const 0`,
|
|
761
|
+
`${indent(1)}local.set $index`,
|
|
762
|
+
`${indent(1)}(block $host_${labelPrefix}_done`,
|
|
763
|
+
`${indent(2)}(loop $host_${labelPrefix}_loop`,
|
|
764
|
+
`${indent(3)}local.get $index`,
|
|
765
|
+
`${indent(3)}local.get $length`,
|
|
766
|
+
`${indent(3)}i32.ge_u`,
|
|
767
|
+
`${indent(3)}br_if $host_${labelPrefix}_done`,
|
|
768
|
+
...emitHostArrayElementToOwnedBackingLines(kind, 'backing', 'index', 'value', indent, taggedKinds, layoutsByRepresentationName, createUnsupportedHeapRuntimeBackendError),
|
|
769
|
+
`${indent(3)}local.get $index`,
|
|
770
|
+
`${indent(3)}i32.const 1`,
|
|
771
|
+
`${indent(3)}i32.add`,
|
|
772
|
+
`${indent(3)}local.set $index`,
|
|
773
|
+
`${indent(3)}br $host_${labelPrefix}_loop`,
|
|
774
|
+
`${indent(2)})`,
|
|
775
|
+
`${indent(1)})`,
|
|
776
|
+
`${indent(1)}local.get $backing`,
|
|
777
|
+
`${indent(1)}struct.new $${wrapperTypeName}`,
|
|
778
|
+
')',
|
|
779
|
+
];
|
|
780
|
+
}
|
|
781
|
+
function emitCopyOwnedArrayToHostArrayHelper(kind, indent, stringRuntimeLayout, taggedKinds, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError) {
|
|
782
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
783
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
784
|
+
const copyElementLines = kind === 'tagged' && taggedKinds?.representation
|
|
785
|
+
? (() => {
|
|
786
|
+
if (!createUnsupportedHeapRuntimeBackendError) {
|
|
787
|
+
throw new Error('Tagged heap-array owned-to-host copy helpers require backend error construction.');
|
|
788
|
+
}
|
|
789
|
+
const specializedWatTypeId = taggedKinds.representation.kind === 'specialized_object_representation'
|
|
790
|
+
? layoutsByRepresentationName?.get(taggedKinds.representation.name)?.watTypeId ??
|
|
791
|
+
(() => {
|
|
792
|
+
throw createUnsupportedHeapRuntimeBackendError(`Missing specialized object layout for tagged array boundary ${taggedKinds.representation.name}.`);
|
|
793
|
+
})()
|
|
794
|
+
: undefined;
|
|
795
|
+
const fallbackWatTypeId = taggedKinds.representation.kind === 'fallback_object_representation'
|
|
796
|
+
? fallbackObjectWatTypeId ??
|
|
797
|
+
(() => {
|
|
798
|
+
throw createUnsupportedHeapRuntimeBackendError('Missing fallback object layout for tagged array host copy-back helper.');
|
|
799
|
+
})()
|
|
800
|
+
: undefined;
|
|
801
|
+
return [
|
|
802
|
+
`${indent(3)}local.get $backing`,
|
|
803
|
+
`${indent(3)}local.get $index`,
|
|
804
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
805
|
+
`${indent(3)}local.set $element_tagged`,
|
|
806
|
+
`${indent(3)}local.get $element_tagged`,
|
|
807
|
+
`${indent(3)}struct.get $tagged_value 0`,
|
|
808
|
+
`${indent(3)}local.set $element_tag`,
|
|
809
|
+
`${indent(3)}(block $element_host_done`,
|
|
810
|
+
...(taggedKinds.includesUndefined
|
|
811
|
+
? [
|
|
812
|
+
`${indent(4)}local.get $element_tag`,
|
|
813
|
+
`${indent(4)}i32.const 0`,
|
|
814
|
+
`${indent(4)}i32.eq`,
|
|
815
|
+
`${indent(4)}(if`,
|
|
816
|
+
`${indent(5)}(then`,
|
|
817
|
+
`${indent(6)}call $tagged_undefined_value`,
|
|
818
|
+
`${indent(6)}local.set $element_host`,
|
|
819
|
+
`${indent(6)}br $element_host_done`,
|
|
820
|
+
`${indent(5)})`,
|
|
821
|
+
`${indent(4)})`,
|
|
822
|
+
]
|
|
823
|
+
: []),
|
|
824
|
+
...(taggedKinds.includesNull
|
|
825
|
+
? [
|
|
826
|
+
`${indent(4)}local.get $element_tag`,
|
|
827
|
+
`${indent(4)}i32.const 6`,
|
|
828
|
+
`${indent(4)}i32.eq`,
|
|
829
|
+
`${indent(4)}(if`,
|
|
830
|
+
`${indent(5)}(then`,
|
|
831
|
+
`${indent(6)}ref.null extern`,
|
|
832
|
+
`${indent(6)}local.set $element_host`,
|
|
833
|
+
`${indent(6)}br $element_host_done`,
|
|
834
|
+
`${indent(5)})`,
|
|
835
|
+
`${indent(4)})`,
|
|
836
|
+
]
|
|
837
|
+
: []),
|
|
838
|
+
...(taggedKinds.includesBoolean
|
|
839
|
+
? [
|
|
840
|
+
`${indent(4)}local.get $element_tag`,
|
|
841
|
+
`${indent(4)}i32.const 1`,
|
|
842
|
+
`${indent(4)}i32.eq`,
|
|
843
|
+
`${indent(4)}(if`,
|
|
844
|
+
`${indent(5)}(then`,
|
|
845
|
+
`${indent(6)}local.get $element_tagged`,
|
|
846
|
+
`${indent(6)}call $untag_boolean`,
|
|
847
|
+
`${indent(6)}call $tagged_from_boolean`,
|
|
848
|
+
`${indent(6)}local.set $element_host`,
|
|
849
|
+
`${indent(6)}br $element_host_done`,
|
|
850
|
+
`${indent(5)})`,
|
|
851
|
+
`${indent(4)})`,
|
|
852
|
+
]
|
|
853
|
+
: []),
|
|
854
|
+
...(taggedKinds.includesNumber
|
|
855
|
+
? [
|
|
856
|
+
`${indent(4)}local.get $element_tag`,
|
|
857
|
+
`${indent(4)}i32.const 2`,
|
|
858
|
+
`${indent(4)}i32.eq`,
|
|
859
|
+
`${indent(4)}(if`,
|
|
860
|
+
`${indent(5)}(then`,
|
|
861
|
+
`${indent(6)}local.get $element_tagged`,
|
|
862
|
+
`${indent(6)}call $untag_number`,
|
|
863
|
+
`${indent(6)}call $tagged_from_number`,
|
|
864
|
+
`${indent(6)}local.set $element_host`,
|
|
865
|
+
`${indent(6)}br $element_host_done`,
|
|
866
|
+
`${indent(5)})`,
|
|
867
|
+
`${indent(4)})`,
|
|
868
|
+
]
|
|
869
|
+
: []),
|
|
870
|
+
...(taggedKinds.includesString
|
|
871
|
+
? [
|
|
872
|
+
`${indent(4)}local.get $element_tag`,
|
|
873
|
+
`${indent(4)}i32.const 3`,
|
|
874
|
+
`${indent(4)}i32.eq`,
|
|
875
|
+
`${indent(4)}(if`,
|
|
876
|
+
`${indent(5)}(then`,
|
|
877
|
+
`${indent(6)}local.get $element_tagged`,
|
|
878
|
+
`${indent(6)}call $untag_string`,
|
|
879
|
+
`${indent(6)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
880
|
+
`${indent(6)}call $owned_string_to_host`,
|
|
881
|
+
`${indent(6)}local.set $element_host`,
|
|
882
|
+
`${indent(6)}br $element_host_done`,
|
|
883
|
+
`${indent(5)})`,
|
|
884
|
+
`${indent(4)})`,
|
|
885
|
+
]
|
|
886
|
+
: []),
|
|
887
|
+
`${indent(4)}local.get $element_tag`,
|
|
888
|
+
`${indent(4)}i32.const 4`,
|
|
889
|
+
`${indent(4)}i32.eq`,
|
|
890
|
+
`${indent(4)}(if`,
|
|
891
|
+
`${indent(5)}(then`,
|
|
892
|
+
`${indent(6)}local.get $element_tagged`,
|
|
893
|
+
`${indent(6)}call $untag_heap_object`,
|
|
894
|
+
`${indent(6)}call $host_object_lookup_cached`,
|
|
895
|
+
`${indent(6)}local.tee $element_host`,
|
|
896
|
+
`${indent(6)}ref.is_null`,
|
|
897
|
+
`${indent(6)}if`,
|
|
898
|
+
...(taggedKinds.representation.kind === 'specialized_object_representation'
|
|
899
|
+
? [
|
|
900
|
+
`${indent(7)}local.get $element_tagged`,
|
|
901
|
+
`${indent(7)}call $untag_heap_object`,
|
|
902
|
+
`${indent(7)}ref.cast (ref null $${specializedWatTypeId})`,
|
|
903
|
+
`${indent(7)}call $${getTaggedArraySpecializedObjectToHostHelperName(specializedWatTypeId)}`,
|
|
904
|
+
`${indent(7)}local.set $element_host`,
|
|
905
|
+
]
|
|
906
|
+
: [
|
|
907
|
+
`${indent(7)}local.get $element_tagged`,
|
|
908
|
+
`${indent(7)}call $untag_heap_object`,
|
|
909
|
+
`${indent(7)}ref.cast (ref null $${fallbackWatTypeId})`,
|
|
910
|
+
`${indent(7)}call $fallback_object_to_host_object`,
|
|
911
|
+
`${indent(7)}local.set $element_host`,
|
|
912
|
+
]),
|
|
913
|
+
`${indent(6)}else`,
|
|
914
|
+
...(taggedKinds.representation.kind === 'specialized_object_representation'
|
|
915
|
+
? [
|
|
916
|
+
`${indent(7)}local.get $element_host`,
|
|
917
|
+
`${indent(7)}local.get $element_tagged`,
|
|
918
|
+
`${indent(7)}call $untag_heap_object`,
|
|
919
|
+
`${indent(7)}ref.cast (ref null $${specializedWatTypeId})`,
|
|
920
|
+
`${indent(7)}call $${getTaggedArrayCopySpecializedObjectToHostHelperName(specializedWatTypeId)}`,
|
|
921
|
+
]
|
|
922
|
+
: [
|
|
923
|
+
`${indent(7)}local.get $element_host`,
|
|
924
|
+
`${indent(7)}local.get $element_tagged`,
|
|
925
|
+
`${indent(7)}call $untag_heap_object`,
|
|
926
|
+
`${indent(7)}ref.cast (ref null $${fallbackWatTypeId})`,
|
|
927
|
+
`${indent(7)}call $${getTaggedArrayCopyFallbackObjectToHostHelperName()}`,
|
|
928
|
+
]),
|
|
929
|
+
`${indent(6)}end`,
|
|
930
|
+
`${indent(6)}br $element_host_done`,
|
|
931
|
+
`${indent(5)})`,
|
|
932
|
+
`${indent(4)})`,
|
|
933
|
+
`${indent(4)}unreachable`,
|
|
934
|
+
`${indent(3)})`,
|
|
935
|
+
`${indent(3)}local.get $target`,
|
|
936
|
+
`${indent(3)}local.get $element_host`,
|
|
937
|
+
`${indent(3)}call $host_array_push`,
|
|
938
|
+
];
|
|
939
|
+
})()
|
|
940
|
+
: emitOwnedBackingElementToHostArrayLines(kind, 'target', 'backing', 'index', indent, stringRuntimeLayout, taggedKinds, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError);
|
|
941
|
+
return [
|
|
942
|
+
`(func $copy_${wrapperTypeName}_to_host_array (param $target externref) (param $value (ref null $${wrapperTypeName}))`,
|
|
943
|
+
`${indent(1)}(local $length i32)`,
|
|
944
|
+
`${indent(1)}(local $index i32)`,
|
|
945
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
946
|
+
...(kind === 'tagged'
|
|
947
|
+
? [
|
|
948
|
+
`${indent(1)}(local $element_tag i32)`,
|
|
949
|
+
`${indent(1)}(local $element_tagged (ref null $tagged_value))`,
|
|
950
|
+
`${indent(1)}(local $element_host externref)`,
|
|
951
|
+
]
|
|
952
|
+
: []),
|
|
953
|
+
`${indent(1)}local.get $target`,
|
|
954
|
+
`${indent(1)}call $host_array_clear`,
|
|
955
|
+
`${indent(1)}local.get $value`,
|
|
956
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
957
|
+
`${indent(1)}local.set $backing`,
|
|
958
|
+
`${indent(1)}local.get $backing`,
|
|
959
|
+
`${indent(1)}array.len`,
|
|
960
|
+
`${indent(1)}local.set $length`,
|
|
961
|
+
`${indent(1)}i32.const 0`,
|
|
962
|
+
`${indent(1)}local.set $index`,
|
|
963
|
+
`${indent(1)}(block $copy_${wrapperTypeName}_done`,
|
|
964
|
+
`${indent(2)}(loop $copy_${wrapperTypeName}_loop`,
|
|
965
|
+
`${indent(3)}local.get $index`,
|
|
966
|
+
`${indent(3)}local.get $length`,
|
|
967
|
+
`${indent(3)}i32.ge_u`,
|
|
968
|
+
`${indent(3)}br_if $copy_${wrapperTypeName}_done`,
|
|
969
|
+
...copyElementLines,
|
|
970
|
+
`${indent(3)}local.get $index`,
|
|
971
|
+
`${indent(3)}i32.const 1`,
|
|
972
|
+
`${indent(3)}i32.add`,
|
|
973
|
+
`${indent(3)}local.set $index`,
|
|
974
|
+
`${indent(3)}br $copy_${wrapperTypeName}_loop`,
|
|
975
|
+
`${indent(2)})`,
|
|
976
|
+
`${indent(1)})`,
|
|
977
|
+
')',
|
|
978
|
+
];
|
|
979
|
+
}
|
|
980
|
+
function emitHostArrayToOwnedTaggedArrayHelper(kinds, indent, layoutsByRepresentationName, createUnsupportedHeapRuntimeBackendError) {
|
|
981
|
+
const lines = emitHostArrayToOwnedArrayHelper('tagged', indent, kinds, layoutsByRepresentationName, createUnsupportedHeapRuntimeBackendError);
|
|
982
|
+
lines[0] =
|
|
983
|
+
`(func $${getHostArrayToOwnedTaggedArrayHelperName(kinds)} (param $value externref) (result (ref null $owned_tagged_array))`;
|
|
984
|
+
return lines;
|
|
985
|
+
}
|
|
986
|
+
function emitCopyOwnedTaggedArrayToHostArrayHelper(kinds, indent, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError) {
|
|
987
|
+
const lines = emitCopyOwnedArrayToHostArrayHelper('tagged', indent, undefined, kinds, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError);
|
|
988
|
+
lines[0] =
|
|
989
|
+
`(func $${getCopyOwnedTaggedArrayToHostHelperName(kinds)} (param $target externref) (param $value (ref null $owned_tagged_array))`;
|
|
990
|
+
return lines;
|
|
991
|
+
}
|
|
992
|
+
function emitOwnedTaggedArrayToHostArrayHelper(kinds, indent, stringRuntimeLayout, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError) {
|
|
993
|
+
const lines = emitOwnedArrayToHostArrayHelper('tagged', indent, stringRuntimeLayout, kinds, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError);
|
|
994
|
+
lines[0] =
|
|
995
|
+
`(func $${getOwnedTaggedArrayToHostHelperName(kinds)} (param $value (ref null $owned_tagged_array)) (result externref)`;
|
|
996
|
+
return lines;
|
|
997
|
+
}
|
|
998
|
+
function collectTaggedArrayBoundaryKindSets(module, layoutsByRepresentationName) {
|
|
999
|
+
const sets = new Map();
|
|
1000
|
+
for (const func of module.functions) {
|
|
1001
|
+
for (const param of func.hostTaggedArrayParams ?? []) {
|
|
1002
|
+
sets.set(getTaggedArrayKindsSuffix(param), param);
|
|
1003
|
+
}
|
|
1004
|
+
if (func.hostTaggedArrayResultKinds) {
|
|
1005
|
+
sets.set(getTaggedArrayKindsSuffix(func.hostTaggedArrayResultKinds), func.hostTaggedArrayResultKinds);
|
|
1006
|
+
}
|
|
1007
|
+
for (const property of func.hostFallbackTaggedArrayProperties ?? []) {
|
|
1008
|
+
sets.set(getTaggedArrayKindsSuffix(property), property);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
for (const layout of layoutsByRepresentationName?.values() ?? []) {
|
|
1012
|
+
for (const field of layout.fields ?? []) {
|
|
1013
|
+
if (field.valueType !== 'owned_tagged_array_ref' || !field.taggedPrimitiveKinds) {
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
const boundaryKinds = {
|
|
1017
|
+
...field.taggedPrimitiveKinds,
|
|
1018
|
+
representation: field.heapRepresentation,
|
|
1019
|
+
};
|
|
1020
|
+
sets.set(getTaggedArrayKindsSuffix(boundaryKinds), boundaryKinds);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
for (const field of module.runtime?.classStaticFields ?? []) {
|
|
1024
|
+
if (field.kind !== 'class_static_tagged_array_field') {
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
1027
|
+
const boundaryKinds = {
|
|
1028
|
+
includesBoolean: field.includesBoolean,
|
|
1029
|
+
includesNull: field.includesNull,
|
|
1030
|
+
includesNumber: field.includesNumber,
|
|
1031
|
+
includesString: field.includesString,
|
|
1032
|
+
includesUndefined: field.includesUndefined,
|
|
1033
|
+
representation: field.representation,
|
|
1034
|
+
};
|
|
1035
|
+
sets.set(getTaggedArrayKindsSuffix(boundaryKinds), boundaryKinds);
|
|
1036
|
+
}
|
|
1037
|
+
return [...sets.values()];
|
|
1038
|
+
}
|
|
1039
|
+
function emitOwnedArrayToHostArrayHelper(kind, indent, stringRuntimeLayout, taggedKinds, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError) {
|
|
1040
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
1041
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1042
|
+
const labelPrefix = getOwnedArrayBoundaryLabelPrefix(kind);
|
|
1043
|
+
return [
|
|
1044
|
+
`(func $${getOwnedArrayToHostHelperName(kind)} (param $value (ref null $${wrapperTypeName})) (result externref)`,
|
|
1045
|
+
`${indent(1)}(local $length i32)`,
|
|
1046
|
+
`${indent(1)}(local $index i32)`,
|
|
1047
|
+
`${indent(1)}(local $result externref)`,
|
|
1048
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
1049
|
+
...(kind === 'tagged'
|
|
1050
|
+
? [
|
|
1051
|
+
`${indent(1)}(local $element_tag i32)`,
|
|
1052
|
+
`${indent(1)}(local $element_tagged (ref null $tagged_value))`,
|
|
1053
|
+
`${indent(1)}(local $element_host externref)`,
|
|
1054
|
+
]
|
|
1055
|
+
: []),
|
|
1056
|
+
`${indent(1)}call $${getHostArrayEmptyHelperName(kind)}`,
|
|
1057
|
+
`${indent(1)}local.set $result`,
|
|
1058
|
+
`${indent(1)}local.get $value`,
|
|
1059
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
1060
|
+
`${indent(1)}local.set $backing`,
|
|
1061
|
+
`${indent(1)}local.get $backing`,
|
|
1062
|
+
`${indent(1)}array.len`,
|
|
1063
|
+
`${indent(1)}local.set $length`,
|
|
1064
|
+
`${indent(1)}i32.const 0`,
|
|
1065
|
+
`${indent(1)}local.set $index`,
|
|
1066
|
+
`${indent(1)}(block $owned_${labelPrefix}_done`,
|
|
1067
|
+
`${indent(2)}(loop $owned_${labelPrefix}_loop`,
|
|
1068
|
+
`${indent(3)}local.get $index`,
|
|
1069
|
+
`${indent(3)}local.get $length`,
|
|
1070
|
+
`${indent(3)}i32.ge_u`,
|
|
1071
|
+
`${indent(3)}br_if $owned_${labelPrefix}_done`,
|
|
1072
|
+
...emitOwnedBackingElementToHostArrayLines(kind, 'result', 'backing', 'index', indent, stringRuntimeLayout, taggedKinds, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError),
|
|
1073
|
+
`${indent(3)}local.get $index`,
|
|
1074
|
+
`${indent(3)}i32.const 1`,
|
|
1075
|
+
`${indent(3)}i32.add`,
|
|
1076
|
+
`${indent(3)}local.set $index`,
|
|
1077
|
+
`${indent(3)}br $owned_${labelPrefix}_loop`,
|
|
1078
|
+
`${indent(2)})`,
|
|
1079
|
+
`${indent(1)})`,
|
|
1080
|
+
`${indent(1)}local.get $result`,
|
|
1081
|
+
')',
|
|
1082
|
+
];
|
|
1083
|
+
}
|
|
1084
|
+
function emitOwnedArrayPushHelper(kind, indent) {
|
|
1085
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
1086
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1087
|
+
return [
|
|
1088
|
+
`(func $${getOwnedArrayPushHelperName(kind)} (param $array (ref null $${wrapperTypeName})) (param $value ${getOwnedArrayPushValueWatType(kind)}) (result f64)`,
|
|
1089
|
+
`${indent(1)}(local $old_backing (ref null $${dataTypeName}))`,
|
|
1090
|
+
`${indent(1)}(local $new_backing (ref null $${dataTypeName}))`,
|
|
1091
|
+
`${indent(1)}(local $length i32)`,
|
|
1092
|
+
`${indent(1)}(local $index i32)`,
|
|
1093
|
+
`${indent(1)}local.get $array`,
|
|
1094
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
1095
|
+
`${indent(1)}local.set $old_backing`,
|
|
1096
|
+
`${indent(1)}local.get $old_backing`,
|
|
1097
|
+
`${indent(1)}array.len`,
|
|
1098
|
+
`${indent(1)}local.set $length`,
|
|
1099
|
+
`${indent(1)}local.get $length`,
|
|
1100
|
+
`${indent(1)}i32.const 1`,
|
|
1101
|
+
`${indent(1)}i32.add`,
|
|
1102
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
1103
|
+
`${indent(1)}local.set $new_backing`,
|
|
1104
|
+
`${indent(1)}i32.const 0`,
|
|
1105
|
+
`${indent(1)}local.set $index`,
|
|
1106
|
+
`${indent(1)}(block $${wrapperTypeName}_push_done`,
|
|
1107
|
+
`${indent(2)}(loop $${wrapperTypeName}_push_loop`,
|
|
1108
|
+
`${indent(3)}local.get $index`,
|
|
1109
|
+
`${indent(3)}local.get $length`,
|
|
1110
|
+
`${indent(3)}i32.ge_u`,
|
|
1111
|
+
`${indent(3)}br_if $${wrapperTypeName}_push_done`,
|
|
1112
|
+
`${indent(3)}local.get $new_backing`,
|
|
1113
|
+
`${indent(3)}local.get $index`,
|
|
1114
|
+
`${indent(3)}local.get $old_backing`,
|
|
1115
|
+
`${indent(3)}local.get $index`,
|
|
1116
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
1117
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
1118
|
+
`${indent(3)}local.get $index`,
|
|
1119
|
+
`${indent(3)}i32.const 1`,
|
|
1120
|
+
`${indent(3)}i32.add`,
|
|
1121
|
+
`${indent(3)}local.set $index`,
|
|
1122
|
+
`${indent(3)}br $${wrapperTypeName}_push_loop`,
|
|
1123
|
+
`${indent(2)})`,
|
|
1124
|
+
`${indent(1)})`,
|
|
1125
|
+
`${indent(1)}local.get $new_backing`,
|
|
1126
|
+
`${indent(1)}local.get $length`,
|
|
1127
|
+
`${indent(1)}local.get $value`,
|
|
1128
|
+
`${indent(1)}array.set $${dataTypeName}`,
|
|
1129
|
+
`${indent(1)}local.get $array`,
|
|
1130
|
+
`${indent(1)}local.get $new_backing`,
|
|
1131
|
+
`${indent(1)}struct.set $${wrapperTypeName} 0`,
|
|
1132
|
+
`${indent(1)}local.get $length`,
|
|
1133
|
+
`${indent(1)}i32.const 1`,
|
|
1134
|
+
`${indent(1)}i32.add`,
|
|
1135
|
+
`${indent(1)}f64.convert_i32_u`,
|
|
1136
|
+
')',
|
|
1137
|
+
];
|
|
1138
|
+
}
|
|
1139
|
+
function emitOwnedArrayUnshiftHelper(kind, indent) {
|
|
1140
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
1141
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1142
|
+
return [
|
|
1143
|
+
`(func $${getOwnedArrayUnshiftHelperName(kind)} (param $array (ref null $${wrapperTypeName})) (param $value ${getOwnedArrayPushValueWatType(kind)}) (result f64)`,
|
|
1144
|
+
`${indent(1)}(local $old_backing (ref null $${dataTypeName}))`,
|
|
1145
|
+
`${indent(1)}(local $new_backing (ref null $${dataTypeName}))`,
|
|
1146
|
+
`${indent(1)}(local $length i32)`,
|
|
1147
|
+
`${indent(1)}(local $index i32)`,
|
|
1148
|
+
`${indent(1)}local.get $array`,
|
|
1149
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
1150
|
+
`${indent(1)}local.set $old_backing`,
|
|
1151
|
+
`${indent(1)}local.get $old_backing`,
|
|
1152
|
+
`${indent(1)}array.len`,
|
|
1153
|
+
`${indent(1)}local.set $length`,
|
|
1154
|
+
`${indent(1)}local.get $length`,
|
|
1155
|
+
`${indent(1)}i32.const 1`,
|
|
1156
|
+
`${indent(1)}i32.add`,
|
|
1157
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
1158
|
+
`${indent(1)}local.set $new_backing`,
|
|
1159
|
+
`${indent(1)}local.get $new_backing`,
|
|
1160
|
+
`${indent(1)}i32.const 0`,
|
|
1161
|
+
`${indent(1)}local.get $value`,
|
|
1162
|
+
`${indent(1)}array.set $${dataTypeName}`,
|
|
1163
|
+
`${indent(1)}i32.const 0`,
|
|
1164
|
+
`${indent(1)}local.set $index`,
|
|
1165
|
+
`${indent(1)}(block $${wrapperTypeName}_unshift_done`,
|
|
1166
|
+
`${indent(2)}(loop $${wrapperTypeName}_unshift_loop`,
|
|
1167
|
+
`${indent(3)}local.get $index`,
|
|
1168
|
+
`${indent(3)}local.get $length`,
|
|
1169
|
+
`${indent(3)}i32.ge_u`,
|
|
1170
|
+
`${indent(3)}br_if $${wrapperTypeName}_unshift_done`,
|
|
1171
|
+
`${indent(3)}local.get $new_backing`,
|
|
1172
|
+
`${indent(3)}local.get $index`,
|
|
1173
|
+
`${indent(3)}i32.const 1`,
|
|
1174
|
+
`${indent(3)}i32.add`,
|
|
1175
|
+
`${indent(3)}local.get $old_backing`,
|
|
1176
|
+
`${indent(3)}local.get $index`,
|
|
1177
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
1178
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
1179
|
+
`${indent(3)}local.get $index`,
|
|
1180
|
+
`${indent(3)}i32.const 1`,
|
|
1181
|
+
`${indent(3)}i32.add`,
|
|
1182
|
+
`${indent(3)}local.set $index`,
|
|
1183
|
+
`${indent(3)}br $${wrapperTypeName}_unshift_loop`,
|
|
1184
|
+
`${indent(2)})`,
|
|
1185
|
+
`${indent(1)})`,
|
|
1186
|
+
`${indent(1)}local.get $array`,
|
|
1187
|
+
`${indent(1)}local.get $new_backing`,
|
|
1188
|
+
`${indent(1)}struct.set $${wrapperTypeName} 0`,
|
|
1189
|
+
`${indent(1)}local.get $length`,
|
|
1190
|
+
`${indent(1)}i32.const 1`,
|
|
1191
|
+
`${indent(1)}i32.add`,
|
|
1192
|
+
`${indent(1)}f64.convert_i32_u`,
|
|
1193
|
+
')',
|
|
1194
|
+
];
|
|
1195
|
+
}
|
|
1196
|
+
function emitOwnedArrayPopHelper(kind, indent, stringRuntimeLayout) {
|
|
1197
|
+
if (kind === 'string' && !stringRuntimeLayout) {
|
|
1198
|
+
throw new CompilerUnsupportedError('Owned string-array pop helpers require the owned string runtime.');
|
|
1199
|
+
}
|
|
1200
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
1201
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1202
|
+
const helperName = getOwnedArrayPopHelperName(kind);
|
|
1203
|
+
const poppedLocal = kind === 'heap'
|
|
1204
|
+
? '(local $popped (ref null eq))'
|
|
1205
|
+
: kind === 'string'
|
|
1206
|
+
? `(local $popped (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`
|
|
1207
|
+
: kind === 'number'
|
|
1208
|
+
? '(local $popped f64)'
|
|
1209
|
+
: kind === 'boolean'
|
|
1210
|
+
? '(local $popped i32)'
|
|
1211
|
+
: '(local $popped (ref null $tagged_value))';
|
|
1212
|
+
const tagLines = kind === 'heap'
|
|
1213
|
+
? [
|
|
1214
|
+
`${indent(1)}local.get $popped`,
|
|
1215
|
+
`${indent(1)}call $tag_heap_object`,
|
|
1216
|
+
]
|
|
1217
|
+
: kind === 'string'
|
|
1218
|
+
? [
|
|
1219
|
+
`${indent(1)}local.get $popped`,
|
|
1220
|
+
`${indent(1)}call $tag_string`,
|
|
1221
|
+
]
|
|
1222
|
+
: kind === 'number'
|
|
1223
|
+
? [
|
|
1224
|
+
`${indent(1)}local.get $popped`,
|
|
1225
|
+
`${indent(1)}call $tag_number`,
|
|
1226
|
+
]
|
|
1227
|
+
: kind === 'boolean'
|
|
1228
|
+
? [
|
|
1229
|
+
`${indent(1)}local.get $popped`,
|
|
1230
|
+
`${indent(1)}call $tag_boolean`,
|
|
1231
|
+
]
|
|
1232
|
+
: [
|
|
1233
|
+
`${indent(1)}local.get $popped`,
|
|
1234
|
+
];
|
|
1235
|
+
const captureLines = kind === 'heap'
|
|
1236
|
+
? [
|
|
1237
|
+
`${indent(1)}local.get $old_backing`,
|
|
1238
|
+
`${indent(1)}local.get $length`,
|
|
1239
|
+
`${indent(1)}i32.const 1`,
|
|
1240
|
+
`${indent(1)}i32.sub`,
|
|
1241
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1242
|
+
`${indent(1)}local.set $popped`,
|
|
1243
|
+
]
|
|
1244
|
+
: kind === 'string'
|
|
1245
|
+
? [
|
|
1246
|
+
`${indent(1)}local.get $old_backing`,
|
|
1247
|
+
`${indent(1)}local.get $length`,
|
|
1248
|
+
`${indent(1)}i32.const 1`,
|
|
1249
|
+
`${indent(1)}i32.sub`,
|
|
1250
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1251
|
+
`${indent(1)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
1252
|
+
`${indent(1)}local.set $popped`,
|
|
1253
|
+
]
|
|
1254
|
+
: kind === 'tagged'
|
|
1255
|
+
? [
|
|
1256
|
+
`${indent(1)}local.get $old_backing`,
|
|
1257
|
+
`${indent(1)}local.get $length`,
|
|
1258
|
+
`${indent(1)}i32.const 1`,
|
|
1259
|
+
`${indent(1)}i32.sub`,
|
|
1260
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1261
|
+
`${indent(1)}local.set $popped`,
|
|
1262
|
+
]
|
|
1263
|
+
: [
|
|
1264
|
+
`${indent(1)}local.get $old_backing`,
|
|
1265
|
+
`${indent(1)}local.get $length`,
|
|
1266
|
+
`${indent(1)}i32.const 1`,
|
|
1267
|
+
`${indent(1)}i32.sub`,
|
|
1268
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1269
|
+
`${indent(1)}local.set $popped`,
|
|
1270
|
+
];
|
|
1271
|
+
return [
|
|
1272
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (result (ref null $tagged_value))`,
|
|
1273
|
+
`${indent(1)}(local $old_backing (ref null $${dataTypeName}))`,
|
|
1274
|
+
`${indent(1)}(local $new_backing (ref null $${dataTypeName}))`,
|
|
1275
|
+
`${indent(1)}(local $length i32)`,
|
|
1276
|
+
`${indent(1)}(local $index i32)`,
|
|
1277
|
+
`${indent(1)}${poppedLocal}`,
|
|
1278
|
+
`${indent(1)}local.get $array`,
|
|
1279
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
1280
|
+
`${indent(1)}local.set $old_backing`,
|
|
1281
|
+
`${indent(1)}local.get $old_backing`,
|
|
1282
|
+
`${indent(1)}array.len`,
|
|
1283
|
+
`${indent(1)}local.set $length`,
|
|
1284
|
+
`${indent(1)}local.get $length`,
|
|
1285
|
+
`${indent(1)}i32.eqz`,
|
|
1286
|
+
`${indent(1)}(if`,
|
|
1287
|
+
`${indent(2)}(then`,
|
|
1288
|
+
`${indent(3)}call $tag_undefined`,
|
|
1289
|
+
`${indent(3)}return`,
|
|
1290
|
+
`${indent(2)})`,
|
|
1291
|
+
`${indent(1)})`,
|
|
1292
|
+
...captureLines,
|
|
1293
|
+
`${indent(1)}local.get $length`,
|
|
1294
|
+
`${indent(1)}i32.const 1`,
|
|
1295
|
+
`${indent(1)}i32.sub`,
|
|
1296
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
1297
|
+
`${indent(1)}local.set $new_backing`,
|
|
1298
|
+
`${indent(1)}i32.const 0`,
|
|
1299
|
+
`${indent(1)}local.set $index`,
|
|
1300
|
+
`${indent(1)}(block $${wrapperTypeName}_pop_done`,
|
|
1301
|
+
`${indent(2)}(loop $${wrapperTypeName}_pop_loop`,
|
|
1302
|
+
`${indent(3)}local.get $index`,
|
|
1303
|
+
`${indent(3)}local.get $length`,
|
|
1304
|
+
`${indent(3)}i32.const 1`,
|
|
1305
|
+
`${indent(3)}i32.sub`,
|
|
1306
|
+
`${indent(3)}i32.ge_u`,
|
|
1307
|
+
`${indent(3)}br_if $${wrapperTypeName}_pop_done`,
|
|
1308
|
+
`${indent(3)}local.get $new_backing`,
|
|
1309
|
+
`${indent(3)}local.get $index`,
|
|
1310
|
+
`${indent(3)}local.get $old_backing`,
|
|
1311
|
+
`${indent(3)}local.get $index`,
|
|
1312
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
1313
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
1314
|
+
`${indent(3)}local.get $index`,
|
|
1315
|
+
`${indent(3)}i32.const 1`,
|
|
1316
|
+
`${indent(3)}i32.add`,
|
|
1317
|
+
`${indent(3)}local.set $index`,
|
|
1318
|
+
`${indent(3)}br $${wrapperTypeName}_pop_loop`,
|
|
1319
|
+
`${indent(2)})`,
|
|
1320
|
+
`${indent(1)})`,
|
|
1321
|
+
`${indent(1)}local.get $array`,
|
|
1322
|
+
`${indent(1)}local.get $new_backing`,
|
|
1323
|
+
`${indent(1)}struct.set $${wrapperTypeName} 0`,
|
|
1324
|
+
...tagLines,
|
|
1325
|
+
')',
|
|
1326
|
+
];
|
|
1327
|
+
}
|
|
1328
|
+
function emitOwnedArrayShiftHelper(kind, indent, stringRuntimeLayout) {
|
|
1329
|
+
if (kind === 'string' && !stringRuntimeLayout) {
|
|
1330
|
+
throw new CompilerUnsupportedError('Owned string-array shift helpers require the owned string runtime.');
|
|
1331
|
+
}
|
|
1332
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
1333
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1334
|
+
const helperName = getOwnedArrayShiftHelperName(kind);
|
|
1335
|
+
const shiftedLocal = kind === 'heap'
|
|
1336
|
+
? '(local $shifted (ref null eq))'
|
|
1337
|
+
: kind === 'string'
|
|
1338
|
+
? `(local $shifted (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`
|
|
1339
|
+
: kind === 'number'
|
|
1340
|
+
? '(local $shifted f64)'
|
|
1341
|
+
: kind === 'boolean'
|
|
1342
|
+
? '(local $shifted i32)'
|
|
1343
|
+
: '(local $shifted (ref null $tagged_value))';
|
|
1344
|
+
const tagLines = kind === 'heap'
|
|
1345
|
+
? [
|
|
1346
|
+
`${indent(1)}local.get $shifted`,
|
|
1347
|
+
`${indent(1)}call $tag_heap_object`,
|
|
1348
|
+
]
|
|
1349
|
+
: kind === 'string'
|
|
1350
|
+
? [
|
|
1351
|
+
`${indent(1)}local.get $shifted`,
|
|
1352
|
+
`${indent(1)}call $tag_string`,
|
|
1353
|
+
]
|
|
1354
|
+
: kind === 'number'
|
|
1355
|
+
? [
|
|
1356
|
+
`${indent(1)}local.get $shifted`,
|
|
1357
|
+
`${indent(1)}call $tag_number`,
|
|
1358
|
+
]
|
|
1359
|
+
: kind === 'boolean'
|
|
1360
|
+
? [
|
|
1361
|
+
`${indent(1)}local.get $shifted`,
|
|
1362
|
+
`${indent(1)}call $tag_boolean`,
|
|
1363
|
+
]
|
|
1364
|
+
: [
|
|
1365
|
+
`${indent(1)}local.get $shifted`,
|
|
1366
|
+
];
|
|
1367
|
+
const captureLines = kind === 'heap'
|
|
1368
|
+
? [
|
|
1369
|
+
`${indent(1)}local.get $old_backing`,
|
|
1370
|
+
`${indent(1)}i32.const 0`,
|
|
1371
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1372
|
+
`${indent(1)}local.set $shifted`,
|
|
1373
|
+
]
|
|
1374
|
+
: kind === 'string'
|
|
1375
|
+
? [
|
|
1376
|
+
`${indent(1)}local.get $old_backing`,
|
|
1377
|
+
`${indent(1)}i32.const 0`,
|
|
1378
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1379
|
+
`${indent(1)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
1380
|
+
`${indent(1)}local.set $shifted`,
|
|
1381
|
+
]
|
|
1382
|
+
: kind === 'tagged'
|
|
1383
|
+
? [
|
|
1384
|
+
`${indent(1)}local.get $old_backing`,
|
|
1385
|
+
`${indent(1)}i32.const 0`,
|
|
1386
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1387
|
+
`${indent(1)}local.set $shifted`,
|
|
1388
|
+
]
|
|
1389
|
+
: [
|
|
1390
|
+
`${indent(1)}local.get $old_backing`,
|
|
1391
|
+
`${indent(1)}i32.const 0`,
|
|
1392
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1393
|
+
`${indent(1)}local.set $shifted`,
|
|
1394
|
+
];
|
|
1395
|
+
return [
|
|
1396
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (result (ref null $tagged_value))`,
|
|
1397
|
+
`${indent(1)}(local $old_backing (ref null $${dataTypeName}))`,
|
|
1398
|
+
`${indent(1)}(local $new_backing (ref null $${dataTypeName}))`,
|
|
1399
|
+
`${indent(1)}(local $length i32)`,
|
|
1400
|
+
`${indent(1)}(local $index i32)`,
|
|
1401
|
+
`${indent(1)}${shiftedLocal}`,
|
|
1402
|
+
`${indent(1)}local.get $array`,
|
|
1403
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
1404
|
+
`${indent(1)}local.set $old_backing`,
|
|
1405
|
+
`${indent(1)}local.get $old_backing`,
|
|
1406
|
+
`${indent(1)}array.len`,
|
|
1407
|
+
`${indent(1)}local.set $length`,
|
|
1408
|
+
`${indent(1)}local.get $length`,
|
|
1409
|
+
`${indent(1)}i32.eqz`,
|
|
1410
|
+
`${indent(1)}(if`,
|
|
1411
|
+
`${indent(2)}(then`,
|
|
1412
|
+
`${indent(3)}call $tag_undefined`,
|
|
1413
|
+
`${indent(3)}return`,
|
|
1414
|
+
`${indent(2)})`,
|
|
1415
|
+
`${indent(1)})`,
|
|
1416
|
+
...captureLines,
|
|
1417
|
+
`${indent(1)}local.get $length`,
|
|
1418
|
+
`${indent(1)}i32.const 1`,
|
|
1419
|
+
`${indent(1)}i32.sub`,
|
|
1420
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
1421
|
+
`${indent(1)}local.set $new_backing`,
|
|
1422
|
+
`${indent(1)}i32.const 0`,
|
|
1423
|
+
`${indent(1)}local.set $index`,
|
|
1424
|
+
`${indent(1)}(block $${wrapperTypeName}_shift_done`,
|
|
1425
|
+
`${indent(2)}(loop $${wrapperTypeName}_shift_loop`,
|
|
1426
|
+
`${indent(3)}local.get $index`,
|
|
1427
|
+
`${indent(3)}local.get $length`,
|
|
1428
|
+
`${indent(3)}i32.const 1`,
|
|
1429
|
+
`${indent(3)}i32.sub`,
|
|
1430
|
+
`${indent(3)}i32.ge_u`,
|
|
1431
|
+
`${indent(3)}br_if $${wrapperTypeName}_shift_done`,
|
|
1432
|
+
`${indent(3)}local.get $new_backing`,
|
|
1433
|
+
`${indent(3)}local.get $index`,
|
|
1434
|
+
`${indent(3)}local.get $old_backing`,
|
|
1435
|
+
`${indent(3)}local.get $index`,
|
|
1436
|
+
`${indent(3)}i32.const 1`,
|
|
1437
|
+
`${indent(3)}i32.add`,
|
|
1438
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
1439
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
1440
|
+
`${indent(3)}local.get $index`,
|
|
1441
|
+
`${indent(3)}i32.const 1`,
|
|
1442
|
+
`${indent(3)}i32.add`,
|
|
1443
|
+
`${indent(3)}local.set $index`,
|
|
1444
|
+
`${indent(3)}br $${wrapperTypeName}_shift_loop`,
|
|
1445
|
+
`${indent(2)})`,
|
|
1446
|
+
`${indent(1)})`,
|
|
1447
|
+
`${indent(1)}local.get $array`,
|
|
1448
|
+
`${indent(1)}local.get $new_backing`,
|
|
1449
|
+
`${indent(1)}struct.set $${wrapperTypeName} 0`,
|
|
1450
|
+
...tagLines,
|
|
1451
|
+
')',
|
|
1452
|
+
];
|
|
1453
|
+
}
|
|
1454
|
+
function emitOwnedArrayAtHelper(kind, indent, stringRuntimeLayout) {
|
|
1455
|
+
if (kind === 'string' && !stringRuntimeLayout) {
|
|
1456
|
+
throw new CompilerUnsupportedError('Owned string-array at helpers require the owned string runtime.');
|
|
1457
|
+
}
|
|
1458
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
1459
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1460
|
+
const helperName = getOwnedArrayAtHelperName(kind);
|
|
1461
|
+
const valueLines = kind === 'heap'
|
|
1462
|
+
? [
|
|
1463
|
+
`${indent(1)}local.get $backing`,
|
|
1464
|
+
`${indent(1)}local.get $normalized_index`,
|
|
1465
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1466
|
+
`${indent(1)}call $tag_heap_object`,
|
|
1467
|
+
]
|
|
1468
|
+
: kind === 'string'
|
|
1469
|
+
? [
|
|
1470
|
+
`${indent(1)}local.get $backing`,
|
|
1471
|
+
`${indent(1)}local.get $normalized_index`,
|
|
1472
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1473
|
+
`${indent(1)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
1474
|
+
`${indent(1)}call $tag_string`,
|
|
1475
|
+
]
|
|
1476
|
+
: kind === 'number'
|
|
1477
|
+
? [
|
|
1478
|
+
`${indent(1)}local.get $backing`,
|
|
1479
|
+
`${indent(1)}local.get $normalized_index`,
|
|
1480
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1481
|
+
`${indent(1)}call $tag_number`,
|
|
1482
|
+
]
|
|
1483
|
+
: kind === 'boolean'
|
|
1484
|
+
? [
|
|
1485
|
+
`${indent(1)}local.get $backing`,
|
|
1486
|
+
`${indent(1)}local.get $normalized_index`,
|
|
1487
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1488
|
+
`${indent(1)}call $tag_boolean`,
|
|
1489
|
+
]
|
|
1490
|
+
: [
|
|
1491
|
+
`${indent(1)}local.get $backing`,
|
|
1492
|
+
`${indent(1)}local.get $normalized_index`,
|
|
1493
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1494
|
+
];
|
|
1495
|
+
return [
|
|
1496
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $index f64) (result (ref null $tagged_value))`,
|
|
1497
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
1498
|
+
`${indent(1)}(local $length i32)`,
|
|
1499
|
+
`${indent(1)}(local $normalized_index i32)`,
|
|
1500
|
+
`${indent(1)}local.get $array`,
|
|
1501
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
1502
|
+
`${indent(1)}local.set $backing`,
|
|
1503
|
+
`${indent(1)}local.get $backing`,
|
|
1504
|
+
`${indent(1)}array.len`,
|
|
1505
|
+
`${indent(1)}local.set $length`,
|
|
1506
|
+
`${indent(1)}local.get $index`,
|
|
1507
|
+
`${indent(1)}local.get $index`,
|
|
1508
|
+
`${indent(1)}f64.ne`,
|
|
1509
|
+
`${indent(1)}(if`,
|
|
1510
|
+
`${indent(2)}(then`,
|
|
1511
|
+
`${indent(3)}i32.const 0`,
|
|
1512
|
+
`${indent(3)}local.set $normalized_index`,
|
|
1513
|
+
`${indent(2)})`,
|
|
1514
|
+
`${indent(2)}(else`,
|
|
1515
|
+
`${indent(3)}local.get $index`,
|
|
1516
|
+
`${indent(3)}f64.const 0`,
|
|
1517
|
+
`${indent(3)}f64.ge`,
|
|
1518
|
+
`${indent(3)}(if`,
|
|
1519
|
+
`${indent(4)}(then`,
|
|
1520
|
+
`${indent(5)}local.get $index`,
|
|
1521
|
+
`${indent(5)}local.get $length`,
|
|
1522
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
1523
|
+
`${indent(5)}f64.ge`,
|
|
1524
|
+
`${indent(5)}(if`,
|
|
1525
|
+
`${indent(6)}(then`,
|
|
1526
|
+
`${indent(7)}local.get $length`,
|
|
1527
|
+
`${indent(7)}local.set $normalized_index`,
|
|
1528
|
+
`${indent(6)})`,
|
|
1529
|
+
`${indent(6)}(else`,
|
|
1530
|
+
`${indent(7)}local.get $index`,
|
|
1531
|
+
`${indent(7)}f64.floor`,
|
|
1532
|
+
`${indent(7)}i32.trunc_f64_s`,
|
|
1533
|
+
`${indent(7)}local.set $normalized_index`,
|
|
1534
|
+
`${indent(6)})`,
|
|
1535
|
+
`${indent(5)})`,
|
|
1536
|
+
`${indent(4)})`,
|
|
1537
|
+
`${indent(4)}(else`,
|
|
1538
|
+
`${indent(5)}local.get $index`,
|
|
1539
|
+
`${indent(5)}local.get $length`,
|
|
1540
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
1541
|
+
`${indent(5)}f64.neg`,
|
|
1542
|
+
`${indent(5)}f64.lt`,
|
|
1543
|
+
`${indent(5)}(if`,
|
|
1544
|
+
`${indent(6)}(then`,
|
|
1545
|
+
`${indent(7)}i32.const -1`,
|
|
1546
|
+
`${indent(7)}local.set $normalized_index`,
|
|
1547
|
+
`${indent(6)})`,
|
|
1548
|
+
`${indent(6)}(else`,
|
|
1549
|
+
`${indent(7)}local.get $length`,
|
|
1550
|
+
`${indent(7)}local.get $index`,
|
|
1551
|
+
`${indent(7)}f64.ceil`,
|
|
1552
|
+
`${indent(7)}i32.trunc_f64_s`,
|
|
1553
|
+
`${indent(7)}i32.add`,
|
|
1554
|
+
`${indent(7)}local.set $normalized_index`,
|
|
1555
|
+
`${indent(6)})`,
|
|
1556
|
+
`${indent(5)})`,
|
|
1557
|
+
`${indent(4)})`,
|
|
1558
|
+
`${indent(3)})`,
|
|
1559
|
+
`${indent(2)})`,
|
|
1560
|
+
`${indent(1)})`,
|
|
1561
|
+
`${indent(1)}local.get $normalized_index`,
|
|
1562
|
+
`${indent(1)}i32.const 0`,
|
|
1563
|
+
`${indent(1)}i32.lt_s`,
|
|
1564
|
+
`${indent(1)}(if (result (ref null $tagged_value))`,
|
|
1565
|
+
`${indent(2)}(then`,
|
|
1566
|
+
`${indent(3)}call $tag_undefined`,
|
|
1567
|
+
`${indent(2)})`,
|
|
1568
|
+
`${indent(2)}(else`,
|
|
1569
|
+
`${indent(3)}local.get $normalized_index`,
|
|
1570
|
+
`${indent(3)}local.get $length`,
|
|
1571
|
+
`${indent(3)}i32.ge_s`,
|
|
1572
|
+
`${indent(3)}(if (result (ref null $tagged_value))`,
|
|
1573
|
+
`${indent(4)}(then`,
|
|
1574
|
+
`${indent(5)}call $tag_undefined`,
|
|
1575
|
+
`${indent(4)})`,
|
|
1576
|
+
`${indent(4)}(else`,
|
|
1577
|
+
...valueLines.map((line) => `${indent(3)}${line.slice(indent(1).length)}`),
|
|
1578
|
+
`${indent(4)})`,
|
|
1579
|
+
`${indent(3)})`,
|
|
1580
|
+
`${indent(2)})`,
|
|
1581
|
+
`${indent(1)})`,
|
|
1582
|
+
')',
|
|
1583
|
+
];
|
|
1584
|
+
}
|
|
1585
|
+
function emitTaggedValueComparisonLines(mode, matchLines, indent, stringRuntimeLayout) {
|
|
1586
|
+
const numberEqualityLines = mode === 'same_value_zero'
|
|
1587
|
+
? [
|
|
1588
|
+
`${indent(7)}local.get $candidate_number`,
|
|
1589
|
+
`${indent(7)}local.get $search_number`,
|
|
1590
|
+
`${indent(7)}f64.eq`,
|
|
1591
|
+
`${indent(7)}(if`,
|
|
1592
|
+
`${indent(8)}(then`,
|
|
1593
|
+
...matchLines.map((line) => `${indent(9)}${line}`),
|
|
1594
|
+
`${indent(8)})`,
|
|
1595
|
+
`${indent(7)})`,
|
|
1596
|
+
`${indent(7)}local.get $candidate_number`,
|
|
1597
|
+
`${indent(7)}local.get $candidate_number`,
|
|
1598
|
+
`${indent(7)}f64.ne`,
|
|
1599
|
+
`${indent(7)}local.get $search_number`,
|
|
1600
|
+
`${indent(7)}local.get $search_number`,
|
|
1601
|
+
`${indent(7)}f64.ne`,
|
|
1602
|
+
`${indent(7)}i32.and`,
|
|
1603
|
+
`${indent(7)}(if`,
|
|
1604
|
+
`${indent(8)}(then`,
|
|
1605
|
+
...matchLines.map((line) => `${indent(9)}${line}`),
|
|
1606
|
+
`${indent(8)})`,
|
|
1607
|
+
`${indent(7)})`,
|
|
1608
|
+
]
|
|
1609
|
+
: [
|
|
1610
|
+
`${indent(7)}local.get $candidate_number`,
|
|
1611
|
+
`${indent(7)}local.get $search_number`,
|
|
1612
|
+
`${indent(7)}f64.eq`,
|
|
1613
|
+
`${indent(7)}(if`,
|
|
1614
|
+
`${indent(8)}(then`,
|
|
1615
|
+
...matchLines.map((line) => `${indent(9)}${line}`),
|
|
1616
|
+
`${indent(8)})`,
|
|
1617
|
+
`${indent(7)})`,
|
|
1618
|
+
];
|
|
1619
|
+
return {
|
|
1620
|
+
locals: [
|
|
1621
|
+
'(local $candidate_tag i32)',
|
|
1622
|
+
'(local $search_tag i32)',
|
|
1623
|
+
'(local $candidate_number f64)',
|
|
1624
|
+
'(local $search_number f64)',
|
|
1625
|
+
],
|
|
1626
|
+
lines: [
|
|
1627
|
+
`${indent(3)}local.get $candidate`,
|
|
1628
|
+
`${indent(3)}struct.get $tagged_value 0`,
|
|
1629
|
+
`${indent(3)}local.set $candidate_tag`,
|
|
1630
|
+
`${indent(3)}local.get $search`,
|
|
1631
|
+
`${indent(3)}struct.get $tagged_value 0`,
|
|
1632
|
+
`${indent(3)}local.set $search_tag`,
|
|
1633
|
+
`${indent(3)}local.get $candidate_tag`,
|
|
1634
|
+
`${indent(3)}local.get $search_tag`,
|
|
1635
|
+
`${indent(3)}i32.eq`,
|
|
1636
|
+
`${indent(3)}(if`,
|
|
1637
|
+
`${indent(4)}(then`,
|
|
1638
|
+
`${indent(5)}local.get $candidate_tag`,
|
|
1639
|
+
`${indent(5)}i32.const 0`,
|
|
1640
|
+
`${indent(5)}i32.eq`,
|
|
1641
|
+
`${indent(5)}(if`,
|
|
1642
|
+
`${indent(6)}(then`,
|
|
1643
|
+
...matchLines.map((line) => `${indent(7)}${line}`),
|
|
1644
|
+
`${indent(6)})`,
|
|
1645
|
+
`${indent(5)})`,
|
|
1646
|
+
`${indent(5)}local.get $candidate_tag`,
|
|
1647
|
+
`${indent(5)}i32.const 6`,
|
|
1648
|
+
`${indent(5)}i32.eq`,
|
|
1649
|
+
`${indent(5)}(if`,
|
|
1650
|
+
`${indent(6)}(then`,
|
|
1651
|
+
...matchLines.map((line) => `${indent(7)}${line}`),
|
|
1652
|
+
`${indent(6)})`,
|
|
1653
|
+
`${indent(5)})`,
|
|
1654
|
+
`${indent(5)}local.get $candidate_tag`,
|
|
1655
|
+
`${indent(5)}i32.const 1`,
|
|
1656
|
+
`${indent(5)}i32.eq`,
|
|
1657
|
+
`${indent(5)}(if`,
|
|
1658
|
+
`${indent(6)}(then`,
|
|
1659
|
+
`${indent(7)}local.get $candidate`,
|
|
1660
|
+
`${indent(7)}struct.get $tagged_value 1`,
|
|
1661
|
+
`${indent(7)}local.set $candidate_number`,
|
|
1662
|
+
`${indent(7)}local.get $search`,
|
|
1663
|
+
`${indent(7)}struct.get $tagged_value 1`,
|
|
1664
|
+
`${indent(7)}local.set $search_number`,
|
|
1665
|
+
`${indent(7)}local.get $candidate_number`,
|
|
1666
|
+
`${indent(7)}local.get $search_number`,
|
|
1667
|
+
`${indent(7)}f64.eq`,
|
|
1668
|
+
`${indent(7)}(if`,
|
|
1669
|
+
`${indent(8)}(then`,
|
|
1670
|
+
...matchLines.map((line) => `${indent(9)}${line}`),
|
|
1671
|
+
`${indent(8)})`,
|
|
1672
|
+
`${indent(7)})`,
|
|
1673
|
+
`${indent(6)})`,
|
|
1674
|
+
`${indent(5)})`,
|
|
1675
|
+
`${indent(5)}local.get $candidate_tag`,
|
|
1676
|
+
`${indent(5)}i32.const 2`,
|
|
1677
|
+
`${indent(5)}i32.eq`,
|
|
1678
|
+
`${indent(5)}(if`,
|
|
1679
|
+
`${indent(6)}(then`,
|
|
1680
|
+
`${indent(7)}local.get $candidate`,
|
|
1681
|
+
`${indent(7)}struct.get $tagged_value 1`,
|
|
1682
|
+
`${indent(7)}local.set $candidate_number`,
|
|
1683
|
+
`${indent(7)}local.get $search`,
|
|
1684
|
+
`${indent(7)}struct.get $tagged_value 1`,
|
|
1685
|
+
`${indent(7)}local.set $search_number`,
|
|
1686
|
+
...numberEqualityLines,
|
|
1687
|
+
`${indent(6)})`,
|
|
1688
|
+
`${indent(5)})`,
|
|
1689
|
+
...(stringRuntimeLayout
|
|
1690
|
+
? [
|
|
1691
|
+
`${indent(5)}local.get $candidate_tag`,
|
|
1692
|
+
`${indent(5)}i32.const 3`,
|
|
1693
|
+
`${indent(5)}i32.eq`,
|
|
1694
|
+
`${indent(5)}(if`,
|
|
1695
|
+
`${indent(6)}(then`,
|
|
1696
|
+
`${indent(7)}local.get $candidate`,
|
|
1697
|
+
`${indent(7)}struct.get $tagged_value 2`,
|
|
1698
|
+
`${indent(7)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
1699
|
+
`${indent(7)}local.get $search`,
|
|
1700
|
+
`${indent(7)}struct.get $tagged_value 2`,
|
|
1701
|
+
`${indent(7)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
1702
|
+
`${indent(7)}call $owned_string_equals`,
|
|
1703
|
+
`${indent(7)}(if`,
|
|
1704
|
+
`${indent(8)}(then`,
|
|
1705
|
+
...matchLines.map((line) => `${indent(9)}${line}`),
|
|
1706
|
+
`${indent(8)})`,
|
|
1707
|
+
`${indent(7)})`,
|
|
1708
|
+
`${indent(6)})`,
|
|
1709
|
+
`${indent(5)})`,
|
|
1710
|
+
]
|
|
1711
|
+
: []),
|
|
1712
|
+
`${indent(4)})`,
|
|
1713
|
+
`${indent(3)})`,
|
|
1714
|
+
],
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1717
|
+
function emitOwnedArrayJoinHelper(kind, indent, stringRuntimeLayout) {
|
|
1718
|
+
if (!stringRuntimeLayout) {
|
|
1719
|
+
throw new CompilerUnsupportedError('Owned array join helpers require the owned string runtime.');
|
|
1720
|
+
}
|
|
1721
|
+
const arrayTypeName = getOwnedArrayWatTypeName(kind);
|
|
1722
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1723
|
+
const helperName = getOwnedArrayJoinHelperName(kind);
|
|
1724
|
+
if (kind === 'string') {
|
|
1725
|
+
return [
|
|
1726
|
+
`(func $${helperName} (param $array (ref null $${arrayTypeName})) (param $separator (ref null $${stringRuntimeLayout.runtimeWatTypeId})) (param $empty (ref null $${stringRuntimeLayout.runtimeWatTypeId})) (result (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`,
|
|
1727
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
1728
|
+
`${indent(1)}(local $length i32)`,
|
|
1729
|
+
`${indent(1)}(local $index i32)`,
|
|
1730
|
+
`${indent(1)}(local $result (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`,
|
|
1731
|
+
`${indent(1)}(local $current (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`,
|
|
1732
|
+
`${indent(1)}local.get $array`,
|
|
1733
|
+
`${indent(1)}struct.get $${arrayTypeName} 0`,
|
|
1734
|
+
`${indent(1)}local.set $backing`,
|
|
1735
|
+
`${indent(1)}local.get $backing`,
|
|
1736
|
+
`${indent(1)}array.len`,
|
|
1737
|
+
`${indent(1)}local.set $length`,
|
|
1738
|
+
`${indent(1)}local.get $length`,
|
|
1739
|
+
`${indent(1)}i32.eqz`,
|
|
1740
|
+
`${indent(1)}(if`,
|
|
1741
|
+
`${indent(2)}(then`,
|
|
1742
|
+
`${indent(3)}local.get $empty`,
|
|
1743
|
+
`${indent(3)}return`,
|
|
1744
|
+
`${indent(2)})`,
|
|
1745
|
+
`${indent(1)})`,
|
|
1746
|
+
`${indent(1)}local.get $backing`,
|
|
1747
|
+
`${indent(1)}i32.const 0`,
|
|
1748
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1749
|
+
`${indent(1)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
1750
|
+
`${indent(1)}local.set $result`,
|
|
1751
|
+
`${indent(1)}i32.const 1`,
|
|
1752
|
+
`${indent(1)}local.set $index`,
|
|
1753
|
+
`${indent(1)}(block $${arrayTypeName}_join_done`,
|
|
1754
|
+
`${indent(2)}(loop $${arrayTypeName}_join_loop`,
|
|
1755
|
+
`${indent(3)}local.get $index`,
|
|
1756
|
+
`${indent(3)}local.get $length`,
|
|
1757
|
+
`${indent(3)}i32.ge_u`,
|
|
1758
|
+
`${indent(3)}br_if $${arrayTypeName}_join_done`,
|
|
1759
|
+
`${indent(3)}local.get $result`,
|
|
1760
|
+
`${indent(3)}local.get $separator`,
|
|
1761
|
+
`${indent(3)}call $owned_string_concat`,
|
|
1762
|
+
`${indent(3)}local.set $result`,
|
|
1763
|
+
`${indent(3)}local.get $backing`,
|
|
1764
|
+
`${indent(3)}local.get $index`,
|
|
1765
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
1766
|
+
`${indent(3)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
1767
|
+
`${indent(3)}local.set $current`,
|
|
1768
|
+
`${indent(3)}local.get $result`,
|
|
1769
|
+
`${indent(3)}local.get $current`,
|
|
1770
|
+
`${indent(3)}call $owned_string_concat`,
|
|
1771
|
+
`${indent(3)}local.set $result`,
|
|
1772
|
+
`${indent(3)}local.get $index`,
|
|
1773
|
+
`${indent(3)}i32.const 1`,
|
|
1774
|
+
`${indent(3)}i32.add`,
|
|
1775
|
+
`${indent(3)}local.set $index`,
|
|
1776
|
+
`${indent(3)}br $${arrayTypeName}_join_loop`,
|
|
1777
|
+
`${indent(2)})`,
|
|
1778
|
+
`${indent(1)})`,
|
|
1779
|
+
`${indent(1)}local.get $result`,
|
|
1780
|
+
')',
|
|
1781
|
+
];
|
|
1782
|
+
}
|
|
1783
|
+
const firstValueLines = kind === 'number'
|
|
1784
|
+
? [
|
|
1785
|
+
`${indent(1)}local.get $backing`,
|
|
1786
|
+
`${indent(1)}i32.const 0`,
|
|
1787
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1788
|
+
`${indent(1)}call $tagged_from_number`,
|
|
1789
|
+
`${indent(1)}local.set $host_result`,
|
|
1790
|
+
]
|
|
1791
|
+
: [
|
|
1792
|
+
`${indent(1)}local.get $backing`,
|
|
1793
|
+
`${indent(1)}i32.const 0`,
|
|
1794
|
+
`${indent(1)}array.get $${dataTypeName}`,
|
|
1795
|
+
`${indent(1)}call $tagged_from_boolean`,
|
|
1796
|
+
`${indent(1)}local.set $host_result`,
|
|
1797
|
+
];
|
|
1798
|
+
const appendCurrentLines = kind === 'number'
|
|
1799
|
+
? [
|
|
1800
|
+
`${indent(3)}local.get $host_result`,
|
|
1801
|
+
`${indent(3)}local.get $backing`,
|
|
1802
|
+
`${indent(3)}local.get $index`,
|
|
1803
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
1804
|
+
`${indent(3)}call $tagged_from_number`,
|
|
1805
|
+
`${indent(3)}call $string_concat`,
|
|
1806
|
+
`${indent(3)}local.set $host_result`,
|
|
1807
|
+
]
|
|
1808
|
+
: [
|
|
1809
|
+
`${indent(3)}local.get $host_result`,
|
|
1810
|
+
`${indent(3)}local.get $backing`,
|
|
1811
|
+
`${indent(3)}local.get $index`,
|
|
1812
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
1813
|
+
`${indent(3)}call $tagged_from_boolean`,
|
|
1814
|
+
`${indent(3)}call $string_concat`,
|
|
1815
|
+
`${indent(3)}local.set $host_result`,
|
|
1816
|
+
];
|
|
1817
|
+
return [
|
|
1818
|
+
`(func $${helperName} (param $array (ref null $${arrayTypeName})) (param $separator (ref null $${stringRuntimeLayout.runtimeWatTypeId})) (param $empty (ref null $${stringRuntimeLayout.runtimeWatTypeId})) (result (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`,
|
|
1819
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
1820
|
+
`${indent(1)}(local $length i32)`,
|
|
1821
|
+
`${indent(1)}(local $index i32)`,
|
|
1822
|
+
`${indent(1)}(local $host_separator externref)`,
|
|
1823
|
+
`${indent(1)}(local $host_result externref)`,
|
|
1824
|
+
`${indent(1)}local.get $array`,
|
|
1825
|
+
`${indent(1)}struct.get $${arrayTypeName} 0`,
|
|
1826
|
+
`${indent(1)}local.set $backing`,
|
|
1827
|
+
`${indent(1)}local.get $backing`,
|
|
1828
|
+
`${indent(1)}array.len`,
|
|
1829
|
+
`${indent(1)}local.set $length`,
|
|
1830
|
+
`${indent(1)}local.get $length`,
|
|
1831
|
+
`${indent(1)}i32.eqz`,
|
|
1832
|
+
`${indent(1)}(if`,
|
|
1833
|
+
`${indent(2)}(then`,
|
|
1834
|
+
`${indent(3)}local.get $empty`,
|
|
1835
|
+
`${indent(3)}return`,
|
|
1836
|
+
`${indent(2)})`,
|
|
1837
|
+
`${indent(1)})`,
|
|
1838
|
+
`${indent(1)}local.get $separator`,
|
|
1839
|
+
`${indent(1)}call $owned_string_to_host`,
|
|
1840
|
+
`${indent(1)}local.set $host_separator`,
|
|
1841
|
+
...firstValueLines,
|
|
1842
|
+
`${indent(1)}i32.const 1`,
|
|
1843
|
+
`${indent(1)}local.set $index`,
|
|
1844
|
+
`${indent(1)}(block $${arrayTypeName}_join_done`,
|
|
1845
|
+
`${indent(2)}(loop $${arrayTypeName}_join_loop`,
|
|
1846
|
+
`${indent(3)}local.get $index`,
|
|
1847
|
+
`${indent(3)}local.get $length`,
|
|
1848
|
+
`${indent(3)}i32.ge_u`,
|
|
1849
|
+
`${indent(3)}br_if $${arrayTypeName}_join_done`,
|
|
1850
|
+
`${indent(3)}local.get $host_result`,
|
|
1851
|
+
`${indent(3)}local.get $host_separator`,
|
|
1852
|
+
`${indent(3)}call $string_concat`,
|
|
1853
|
+
`${indent(3)}local.set $host_result`,
|
|
1854
|
+
...appendCurrentLines,
|
|
1855
|
+
`${indent(3)}local.get $index`,
|
|
1856
|
+
`${indent(3)}i32.const 1`,
|
|
1857
|
+
`${indent(3)}i32.add`,
|
|
1858
|
+
`${indent(3)}local.set $index`,
|
|
1859
|
+
`${indent(3)}br $${arrayTypeName}_join_loop`,
|
|
1860
|
+
`${indent(2)})`,
|
|
1861
|
+
`${indent(1)})`,
|
|
1862
|
+
`${indent(1)}local.get $host_result`,
|
|
1863
|
+
`${indent(1)}call $string_to_owned`,
|
|
1864
|
+
')',
|
|
1865
|
+
];
|
|
1866
|
+
}
|
|
1867
|
+
function emitNormalizeSliceIndexLines(sourceLocalName, targetLocalName, indent) {
|
|
1868
|
+
return [
|
|
1869
|
+
`${indent(1)}local.get $${sourceLocalName}`,
|
|
1870
|
+
`${indent(1)}local.get $${sourceLocalName}`,
|
|
1871
|
+
`${indent(1)}f64.ne`,
|
|
1872
|
+
`${indent(1)}(if`,
|
|
1873
|
+
`${indent(2)}(then`,
|
|
1874
|
+
`${indent(3)}i32.const 0`,
|
|
1875
|
+
`${indent(3)}local.set $${targetLocalName}`,
|
|
1876
|
+
`${indent(2)})`,
|
|
1877
|
+
`${indent(2)}(else`,
|
|
1878
|
+
`${indent(3)}local.get $${sourceLocalName}`,
|
|
1879
|
+
`${indent(3)}f64.const 0`,
|
|
1880
|
+
`${indent(3)}f64.ge`,
|
|
1881
|
+
`${indent(3)}(if`,
|
|
1882
|
+
`${indent(4)}(then`,
|
|
1883
|
+
`${indent(5)}local.get $${sourceLocalName}`,
|
|
1884
|
+
`${indent(5)}local.get $length`,
|
|
1885
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
1886
|
+
`${indent(5)}f64.ge`,
|
|
1887
|
+
`${indent(5)}(if`,
|
|
1888
|
+
`${indent(6)}(then`,
|
|
1889
|
+
`${indent(7)}local.get $length`,
|
|
1890
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1891
|
+
`${indent(6)})`,
|
|
1892
|
+
`${indent(6)}(else`,
|
|
1893
|
+
`${indent(7)}local.get $${sourceLocalName}`,
|
|
1894
|
+
`${indent(7)}f64.floor`,
|
|
1895
|
+
`${indent(7)}i32.trunc_f64_s`,
|
|
1896
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1897
|
+
`${indent(6)})`,
|
|
1898
|
+
`${indent(5)})`,
|
|
1899
|
+
`${indent(4)})`,
|
|
1900
|
+
`${indent(4)}(else`,
|
|
1901
|
+
`${indent(5)}local.get $${sourceLocalName}`,
|
|
1902
|
+
`${indent(5)}local.get $length`,
|
|
1903
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
1904
|
+
`${indent(5)}f64.neg`,
|
|
1905
|
+
`${indent(5)}f64.le`,
|
|
1906
|
+
`${indent(5)}(if`,
|
|
1907
|
+
`${indent(6)}(then`,
|
|
1908
|
+
`${indent(7)}i32.const 0`,
|
|
1909
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1910
|
+
`${indent(6)})`,
|
|
1911
|
+
`${indent(6)}(else`,
|
|
1912
|
+
`${indent(7)}local.get $length`,
|
|
1913
|
+
`${indent(7)}local.get $${sourceLocalName}`,
|
|
1914
|
+
`${indent(7)}f64.ceil`,
|
|
1915
|
+
`${indent(7)}i32.trunc_f64_s`,
|
|
1916
|
+
`${indent(7)}i32.add`,
|
|
1917
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1918
|
+
`${indent(6)})`,
|
|
1919
|
+
`${indent(5)})`,
|
|
1920
|
+
`${indent(4)})`,
|
|
1921
|
+
`${indent(3)})`,
|
|
1922
|
+
`${indent(2)})`,
|
|
1923
|
+
`${indent(1)})`,
|
|
1924
|
+
];
|
|
1925
|
+
}
|
|
1926
|
+
function emitNormalizeLastIndexFromIndexLines(sourceLocalName, targetLocalName, indent) {
|
|
1927
|
+
return [
|
|
1928
|
+
`${indent(1)}local.get $${sourceLocalName}`,
|
|
1929
|
+
`${indent(1)}local.get $${sourceLocalName}`,
|
|
1930
|
+
`${indent(1)}f64.ne`,
|
|
1931
|
+
`${indent(1)}(if`,
|
|
1932
|
+
`${indent(2)}(then`,
|
|
1933
|
+
`${indent(3)}i32.const 0`,
|
|
1934
|
+
`${indent(3)}local.set $${targetLocalName}`,
|
|
1935
|
+
`${indent(2)})`,
|
|
1936
|
+
`${indent(2)}(else`,
|
|
1937
|
+
`${indent(3)}local.get $${sourceLocalName}`,
|
|
1938
|
+
`${indent(3)}f64.const 0`,
|
|
1939
|
+
`${indent(3)}f64.ge`,
|
|
1940
|
+
`${indent(3)}(if`,
|
|
1941
|
+
`${indent(4)}(then`,
|
|
1942
|
+
`${indent(5)}local.get $${sourceLocalName}`,
|
|
1943
|
+
`${indent(5)}local.get $length`,
|
|
1944
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
1945
|
+
`${indent(5)}f64.ge`,
|
|
1946
|
+
`${indent(5)}(if`,
|
|
1947
|
+
`${indent(6)}(then`,
|
|
1948
|
+
`${indent(7)}local.get $length`,
|
|
1949
|
+
`${indent(7)}i32.const 1`,
|
|
1950
|
+
`${indent(7)}i32.sub`,
|
|
1951
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1952
|
+
`${indent(6)})`,
|
|
1953
|
+
`${indent(6)}(else`,
|
|
1954
|
+
`${indent(7)}local.get $${sourceLocalName}`,
|
|
1955
|
+
`${indent(7)}f64.floor`,
|
|
1956
|
+
`${indent(7)}i32.trunc_f64_s`,
|
|
1957
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1958
|
+
`${indent(6)})`,
|
|
1959
|
+
`${indent(5)})`,
|
|
1960
|
+
`${indent(4)})`,
|
|
1961
|
+
`${indent(4)}(else`,
|
|
1962
|
+
`${indent(5)}local.get $${sourceLocalName}`,
|
|
1963
|
+
`${indent(5)}local.get $length`,
|
|
1964
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
1965
|
+
`${indent(5)}f64.neg`,
|
|
1966
|
+
`${indent(5)}f64.le`,
|
|
1967
|
+
`${indent(5)}(if`,
|
|
1968
|
+
`${indent(6)}(then`,
|
|
1969
|
+
`${indent(7)}i32.const -1`,
|
|
1970
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1971
|
+
`${indent(6)})`,
|
|
1972
|
+
`${indent(6)}(else`,
|
|
1973
|
+
`${indent(7)}local.get $length`,
|
|
1974
|
+
`${indent(7)}local.get $${sourceLocalName}`,
|
|
1975
|
+
`${indent(7)}f64.ceil`,
|
|
1976
|
+
`${indent(7)}i32.trunc_f64_s`,
|
|
1977
|
+
`${indent(7)}i32.add`,
|
|
1978
|
+
`${indent(7)}local.set $${targetLocalName}`,
|
|
1979
|
+
`${indent(6)})`,
|
|
1980
|
+
`${indent(5)})`,
|
|
1981
|
+
`${indent(4)})`,
|
|
1982
|
+
`${indent(3)})`,
|
|
1983
|
+
`${indent(2)})`,
|
|
1984
|
+
`${indent(1)})`,
|
|
1985
|
+
];
|
|
1986
|
+
}
|
|
1987
|
+
function emitOwnedArraySliceHelper(kind, indent) {
|
|
1988
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
1989
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
1990
|
+
const helperName = getOwnedArraySliceHelperName(kind);
|
|
1991
|
+
return [
|
|
1992
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $start f64) (param $end f64) (param $has_end i32) (result (ref null $${wrapperTypeName}))`,
|
|
1993
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
1994
|
+
`${indent(1)}(local $result_backing (ref null $${dataTypeName}))`,
|
|
1995
|
+
`${indent(1)}(local $length i32)`,
|
|
1996
|
+
`${indent(1)}(local $normalized_start i32)`,
|
|
1997
|
+
`${indent(1)}(local $normalized_end i32)`,
|
|
1998
|
+
`${indent(1)}(local $result_length i32)`,
|
|
1999
|
+
`${indent(1)}(local $index i32)`,
|
|
2000
|
+
`${indent(1)}local.get $array`,
|
|
2001
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2002
|
+
`${indent(1)}local.set $backing`,
|
|
2003
|
+
`${indent(1)}local.get $backing`,
|
|
2004
|
+
`${indent(1)}array.len`,
|
|
2005
|
+
`${indent(1)}local.set $length`,
|
|
2006
|
+
...emitNormalizeSliceIndexLines('start', 'normalized_start', indent),
|
|
2007
|
+
`${indent(1)}local.get $has_end`,
|
|
2008
|
+
`${indent(1)}(if`,
|
|
2009
|
+
`${indent(2)}(then`,
|
|
2010
|
+
...emitNormalizeSliceIndexLines('end', 'normalized_end', indent).map((line) => `${indent(1)}${line.slice(indent(1).length)}`),
|
|
2011
|
+
`${indent(2)})`,
|
|
2012
|
+
`${indent(2)}(else`,
|
|
2013
|
+
`${indent(3)}local.get $length`,
|
|
2014
|
+
`${indent(3)}local.set $normalized_end`,
|
|
2015
|
+
`${indent(2)})`,
|
|
2016
|
+
`${indent(1)})`,
|
|
2017
|
+
`${indent(1)}local.get $normalized_end`,
|
|
2018
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2019
|
+
`${indent(1)}i32.lt_s`,
|
|
2020
|
+
`${indent(1)}(if`,
|
|
2021
|
+
`${indent(2)}(then`,
|
|
2022
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2023
|
+
`${indent(3)}local.set $normalized_end`,
|
|
2024
|
+
`${indent(2)})`,
|
|
2025
|
+
`${indent(1)})`,
|
|
2026
|
+
`${indent(1)}local.get $normalized_end`,
|
|
2027
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2028
|
+
`${indent(1)}i32.sub`,
|
|
2029
|
+
`${indent(1)}local.set $result_length`,
|
|
2030
|
+
`${indent(1)}local.get $result_length`,
|
|
2031
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
2032
|
+
`${indent(1)}local.set $result_backing`,
|
|
2033
|
+
`${indent(1)}i32.const 0`,
|
|
2034
|
+
`${indent(1)}local.set $index`,
|
|
2035
|
+
`${indent(1)}(block $${wrapperTypeName}_slice_done`,
|
|
2036
|
+
`${indent(2)}(loop $${wrapperTypeName}_slice_loop`,
|
|
2037
|
+
`${indent(3)}local.get $index`,
|
|
2038
|
+
`${indent(3)}local.get $result_length`,
|
|
2039
|
+
`${indent(3)}i32.ge_u`,
|
|
2040
|
+
`${indent(3)}br_if $${wrapperTypeName}_slice_done`,
|
|
2041
|
+
`${indent(3)}local.get $result_backing`,
|
|
2042
|
+
`${indent(3)}local.get $index`,
|
|
2043
|
+
`${indent(3)}local.get $backing`,
|
|
2044
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2045
|
+
`${indent(3)}local.get $index`,
|
|
2046
|
+
`${indent(3)}i32.add`,
|
|
2047
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2048
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2049
|
+
`${indent(3)}local.get $index`,
|
|
2050
|
+
`${indent(3)}i32.const 1`,
|
|
2051
|
+
`${indent(3)}i32.add`,
|
|
2052
|
+
`${indent(3)}local.set $index`,
|
|
2053
|
+
`${indent(3)}br $${wrapperTypeName}_slice_loop`,
|
|
2054
|
+
`${indent(2)})`,
|
|
2055
|
+
`${indent(1)})`,
|
|
2056
|
+
`${indent(1)}local.get $result_backing`,
|
|
2057
|
+
`${indent(1)}struct.new $${wrapperTypeName}`,
|
|
2058
|
+
')',
|
|
2059
|
+
];
|
|
2060
|
+
}
|
|
2061
|
+
function emitOwnedArrayConcatHelper(kind, indent) {
|
|
2062
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2063
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2064
|
+
const helperName = getOwnedArrayConcatHelperName(kind);
|
|
2065
|
+
return [
|
|
2066
|
+
`(func $${helperName} (param $left (ref null $${wrapperTypeName})) (param $right (ref null $${wrapperTypeName})) (result (ref null $${wrapperTypeName}))`,
|
|
2067
|
+
`${indent(1)}(local $left_backing (ref null $${dataTypeName}))`,
|
|
2068
|
+
`${indent(1)}(local $right_backing (ref null $${dataTypeName}))`,
|
|
2069
|
+
`${indent(1)}(local $result_backing (ref null $${dataTypeName}))`,
|
|
2070
|
+
`${indent(1)}(local $left_length i32)`,
|
|
2071
|
+
`${indent(1)}(local $right_length i32)`,
|
|
2072
|
+
`${indent(1)}(local $index i32)`,
|
|
2073
|
+
`${indent(1)}local.get $left`,
|
|
2074
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2075
|
+
`${indent(1)}local.set $left_backing`,
|
|
2076
|
+
`${indent(1)}local.get $right`,
|
|
2077
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2078
|
+
`${indent(1)}local.set $right_backing`,
|
|
2079
|
+
`${indent(1)}local.get $left_backing`,
|
|
2080
|
+
`${indent(1)}array.len`,
|
|
2081
|
+
`${indent(1)}local.set $left_length`,
|
|
2082
|
+
`${indent(1)}local.get $right_backing`,
|
|
2083
|
+
`${indent(1)}array.len`,
|
|
2084
|
+
`${indent(1)}local.set $right_length`,
|
|
2085
|
+
`${indent(1)}local.get $left_length`,
|
|
2086
|
+
`${indent(1)}local.get $right_length`,
|
|
2087
|
+
`${indent(1)}i32.add`,
|
|
2088
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
2089
|
+
`${indent(1)}local.set $result_backing`,
|
|
2090
|
+
`${indent(1)}i32.const 0`,
|
|
2091
|
+
`${indent(1)}local.set $index`,
|
|
2092
|
+
`${indent(1)}(block $${wrapperTypeName}_concat_left_done`,
|
|
2093
|
+
`${indent(2)}(loop $${wrapperTypeName}_concat_left_loop`,
|
|
2094
|
+
`${indent(3)}local.get $index`,
|
|
2095
|
+
`${indent(3)}local.get $left_length`,
|
|
2096
|
+
`${indent(3)}i32.ge_u`,
|
|
2097
|
+
`${indent(3)}br_if $${wrapperTypeName}_concat_left_done`,
|
|
2098
|
+
`${indent(3)}local.get $result_backing`,
|
|
2099
|
+
`${indent(3)}local.get $index`,
|
|
2100
|
+
`${indent(3)}local.get $left_backing`,
|
|
2101
|
+
`${indent(3)}local.get $index`,
|
|
2102
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2103
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2104
|
+
`${indent(3)}local.get $index`,
|
|
2105
|
+
`${indent(3)}i32.const 1`,
|
|
2106
|
+
`${indent(3)}i32.add`,
|
|
2107
|
+
`${indent(3)}local.set $index`,
|
|
2108
|
+
`${indent(3)}br $${wrapperTypeName}_concat_left_loop`,
|
|
2109
|
+
`${indent(2)})`,
|
|
2110
|
+
`${indent(1)})`,
|
|
2111
|
+
`${indent(1)}i32.const 0`,
|
|
2112
|
+
`${indent(1)}local.set $index`,
|
|
2113
|
+
`${indent(1)}(block $${wrapperTypeName}_concat_right_done`,
|
|
2114
|
+
`${indent(2)}(loop $${wrapperTypeName}_concat_right_loop`,
|
|
2115
|
+
`${indent(3)}local.get $index`,
|
|
2116
|
+
`${indent(3)}local.get $right_length`,
|
|
2117
|
+
`${indent(3)}i32.ge_u`,
|
|
2118
|
+
`${indent(3)}br_if $${wrapperTypeName}_concat_right_done`,
|
|
2119
|
+
`${indent(3)}local.get $result_backing`,
|
|
2120
|
+
`${indent(3)}local.get $left_length`,
|
|
2121
|
+
`${indent(3)}local.get $index`,
|
|
2122
|
+
`${indent(3)}i32.add`,
|
|
2123
|
+
`${indent(3)}local.get $right_backing`,
|
|
2124
|
+
`${indent(3)}local.get $index`,
|
|
2125
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2126
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2127
|
+
`${indent(3)}local.get $index`,
|
|
2128
|
+
`${indent(3)}i32.const 1`,
|
|
2129
|
+
`${indent(3)}i32.add`,
|
|
2130
|
+
`${indent(3)}local.set $index`,
|
|
2131
|
+
`${indent(3)}br $${wrapperTypeName}_concat_right_loop`,
|
|
2132
|
+
`${indent(2)})`,
|
|
2133
|
+
`${indent(1)})`,
|
|
2134
|
+
`${indent(1)}local.get $result_backing`,
|
|
2135
|
+
`${indent(1)}struct.new $${wrapperTypeName}`,
|
|
2136
|
+
')',
|
|
2137
|
+
];
|
|
2138
|
+
}
|
|
2139
|
+
function emitOwnedArraySpliceHelper(kind, indent) {
|
|
2140
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2141
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2142
|
+
const helperName = getOwnedArraySpliceHelperName(kind);
|
|
2143
|
+
return [
|
|
2144
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $start f64) (param $delete_count f64) (param $items (ref null $${wrapperTypeName})) (result (ref null $${wrapperTypeName}))`,
|
|
2145
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
2146
|
+
`${indent(1)}(local $items_backing (ref null $${dataTypeName}))`,
|
|
2147
|
+
`${indent(1)}(local $remaining_backing (ref null $${dataTypeName}))`,
|
|
2148
|
+
`${indent(1)}(local $removed_backing (ref null $${dataTypeName}))`,
|
|
2149
|
+
`${indent(1)}(local $length i32)`,
|
|
2150
|
+
`${indent(1)}(local $insert_length i32)`,
|
|
2151
|
+
`${indent(1)}(local $normalized_start i32)`,
|
|
2152
|
+
`${indent(1)}(local $available_delete_count i32)`,
|
|
2153
|
+
`${indent(1)}(local $normalized_delete_count i32)`,
|
|
2154
|
+
`${indent(1)}(local $remaining_length i32)`,
|
|
2155
|
+
`${indent(1)}(local $index i32)`,
|
|
2156
|
+
`${indent(1)}local.get $array`,
|
|
2157
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2158
|
+
`${indent(1)}local.set $backing`,
|
|
2159
|
+
`${indent(1)}local.get $items`,
|
|
2160
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2161
|
+
`${indent(1)}local.set $items_backing`,
|
|
2162
|
+
`${indent(1)}local.get $backing`,
|
|
2163
|
+
`${indent(1)}array.len`,
|
|
2164
|
+
`${indent(1)}local.set $length`,
|
|
2165
|
+
`${indent(1)}local.get $items_backing`,
|
|
2166
|
+
`${indent(1)}array.len`,
|
|
2167
|
+
`${indent(1)}local.set $insert_length`,
|
|
2168
|
+
...emitNormalizeSliceIndexLines('start', 'normalized_start', indent),
|
|
2169
|
+
`${indent(1)}local.get $length`,
|
|
2170
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2171
|
+
`${indent(1)}i32.sub`,
|
|
2172
|
+
`${indent(1)}local.set $available_delete_count`,
|
|
2173
|
+
`${indent(1)}local.get $delete_count`,
|
|
2174
|
+
`${indent(1)}local.get $delete_count`,
|
|
2175
|
+
`${indent(1)}f64.ne`,
|
|
2176
|
+
`${indent(1)}(if`,
|
|
2177
|
+
`${indent(2)}(then`,
|
|
2178
|
+
`${indent(3)}i32.const 0`,
|
|
2179
|
+
`${indent(3)}local.set $normalized_delete_count`,
|
|
2180
|
+
`${indent(2)})`,
|
|
2181
|
+
`${indent(2)}(else`,
|
|
2182
|
+
`${indent(3)}local.get $delete_count`,
|
|
2183
|
+
`${indent(3)}f64.const 0`,
|
|
2184
|
+
`${indent(3)}f64.le`,
|
|
2185
|
+
`${indent(3)}(if`,
|
|
2186
|
+
`${indent(4)}(then`,
|
|
2187
|
+
`${indent(5)}i32.const 0`,
|
|
2188
|
+
`${indent(5)}local.set $normalized_delete_count`,
|
|
2189
|
+
`${indent(4)})`,
|
|
2190
|
+
`${indent(4)}(else`,
|
|
2191
|
+
`${indent(5)}local.get $delete_count`,
|
|
2192
|
+
`${indent(5)}local.get $available_delete_count`,
|
|
2193
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2194
|
+
`${indent(5)}f64.ge`,
|
|
2195
|
+
`${indent(5)}(if`,
|
|
2196
|
+
`${indent(6)}(then`,
|
|
2197
|
+
`${indent(7)}local.get $available_delete_count`,
|
|
2198
|
+
`${indent(7)}local.set $normalized_delete_count`,
|
|
2199
|
+
`${indent(6)})`,
|
|
2200
|
+
`${indent(6)}(else`,
|
|
2201
|
+
`${indent(7)}local.get $delete_count`,
|
|
2202
|
+
`${indent(7)}f64.floor`,
|
|
2203
|
+
`${indent(7)}i32.trunc_f64_s`,
|
|
2204
|
+
`${indent(7)}local.set $normalized_delete_count`,
|
|
2205
|
+
`${indent(6)})`,
|
|
2206
|
+
`${indent(5)})`,
|
|
2207
|
+
`${indent(4)})`,
|
|
2208
|
+
`${indent(3)})`,
|
|
2209
|
+
`${indent(2)})`,
|
|
2210
|
+
`${indent(1)})`,
|
|
2211
|
+
`${indent(1)}local.get $normalized_delete_count`,
|
|
2212
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
2213
|
+
`${indent(1)}local.set $removed_backing`,
|
|
2214
|
+
`${indent(1)}local.get $length`,
|
|
2215
|
+
`${indent(1)}local.get $normalized_delete_count`,
|
|
2216
|
+
`${indent(1)}i32.sub`,
|
|
2217
|
+
`${indent(1)}local.get $insert_length`,
|
|
2218
|
+
`${indent(1)}i32.add`,
|
|
2219
|
+
`${indent(1)}local.set $remaining_length`,
|
|
2220
|
+
`${indent(1)}local.get $remaining_length`,
|
|
2221
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
2222
|
+
`${indent(1)}local.set $remaining_backing`,
|
|
2223
|
+
`${indent(1)}i32.const 0`,
|
|
2224
|
+
`${indent(1)}local.set $index`,
|
|
2225
|
+
`${indent(1)}(block $${wrapperTypeName}_splice_removed_done`,
|
|
2226
|
+
`${indent(2)}(loop $${wrapperTypeName}_splice_removed_loop`,
|
|
2227
|
+
`${indent(3)}local.get $index`,
|
|
2228
|
+
`${indent(3)}local.get $normalized_delete_count`,
|
|
2229
|
+
`${indent(3)}i32.ge_u`,
|
|
2230
|
+
`${indent(3)}br_if $${wrapperTypeName}_splice_removed_done`,
|
|
2231
|
+
`${indent(3)}local.get $removed_backing`,
|
|
2232
|
+
`${indent(3)}local.get $index`,
|
|
2233
|
+
`${indent(3)}local.get $backing`,
|
|
2234
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2235
|
+
`${indent(3)}local.get $index`,
|
|
2236
|
+
`${indent(3)}i32.add`,
|
|
2237
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2238
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2239
|
+
`${indent(3)}local.get $index`,
|
|
2240
|
+
`${indent(3)}i32.const 1`,
|
|
2241
|
+
`${indent(3)}i32.add`,
|
|
2242
|
+
`${indent(3)}local.set $index`,
|
|
2243
|
+
`${indent(3)}br $${wrapperTypeName}_splice_removed_loop`,
|
|
2244
|
+
`${indent(2)})`,
|
|
2245
|
+
`${indent(1)})`,
|
|
2246
|
+
`${indent(1)}i32.const 0`,
|
|
2247
|
+
`${indent(1)}local.set $index`,
|
|
2248
|
+
`${indent(1)}(block $${wrapperTypeName}_splice_prefix_done`,
|
|
2249
|
+
`${indent(2)}(loop $${wrapperTypeName}_splice_prefix_loop`,
|
|
2250
|
+
`${indent(3)}local.get $index`,
|
|
2251
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2252
|
+
`${indent(3)}i32.ge_u`,
|
|
2253
|
+
`${indent(3)}br_if $${wrapperTypeName}_splice_prefix_done`,
|
|
2254
|
+
`${indent(3)}local.get $remaining_backing`,
|
|
2255
|
+
`${indent(3)}local.get $index`,
|
|
2256
|
+
`${indent(3)}local.get $backing`,
|
|
2257
|
+
`${indent(3)}local.get $index`,
|
|
2258
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2259
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2260
|
+
`${indent(3)}local.get $index`,
|
|
2261
|
+
`${indent(3)}i32.const 1`,
|
|
2262
|
+
`${indent(3)}i32.add`,
|
|
2263
|
+
`${indent(3)}local.set $index`,
|
|
2264
|
+
`${indent(3)}br $${wrapperTypeName}_splice_prefix_loop`,
|
|
2265
|
+
`${indent(2)})`,
|
|
2266
|
+
`${indent(1)})`,
|
|
2267
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2268
|
+
`${indent(1)}local.set $index`,
|
|
2269
|
+
`${indent(1)}(block $${wrapperTypeName}_splice_insert_done`,
|
|
2270
|
+
`${indent(2)}(loop $${wrapperTypeName}_splice_insert_loop`,
|
|
2271
|
+
`${indent(3)}local.get $index`,
|
|
2272
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2273
|
+
`${indent(3)}local.get $insert_length`,
|
|
2274
|
+
`${indent(3)}i32.add`,
|
|
2275
|
+
`${indent(3)}i32.ge_u`,
|
|
2276
|
+
`${indent(3)}br_if $${wrapperTypeName}_splice_insert_done`,
|
|
2277
|
+
`${indent(3)}local.get $remaining_backing`,
|
|
2278
|
+
`${indent(3)}local.get $index`,
|
|
2279
|
+
`${indent(3)}local.get $items_backing`,
|
|
2280
|
+
`${indent(3)}local.get $index`,
|
|
2281
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2282
|
+
`${indent(3)}i32.sub`,
|
|
2283
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2284
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2285
|
+
`${indent(3)}local.get $index`,
|
|
2286
|
+
`${indent(3)}i32.const 1`,
|
|
2287
|
+
`${indent(3)}i32.add`,
|
|
2288
|
+
`${indent(3)}local.set $index`,
|
|
2289
|
+
`${indent(3)}br $${wrapperTypeName}_splice_insert_loop`,
|
|
2290
|
+
`${indent(2)})`,
|
|
2291
|
+
`${indent(1)})`,
|
|
2292
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2293
|
+
`${indent(1)}local.get $insert_length`,
|
|
2294
|
+
`${indent(1)}i32.add`,
|
|
2295
|
+
`${indent(1)}local.set $index`,
|
|
2296
|
+
`${indent(1)}(block $${wrapperTypeName}_splice_suffix_done`,
|
|
2297
|
+
`${indent(2)}(loop $${wrapperTypeName}_splice_suffix_loop`,
|
|
2298
|
+
`${indent(3)}local.get $index`,
|
|
2299
|
+
`${indent(3)}local.get $remaining_length`,
|
|
2300
|
+
`${indent(3)}i32.ge_u`,
|
|
2301
|
+
`${indent(3)}br_if $${wrapperTypeName}_splice_suffix_done`,
|
|
2302
|
+
`${indent(3)}local.get $remaining_backing`,
|
|
2303
|
+
`${indent(3)}local.get $index`,
|
|
2304
|
+
`${indent(3)}local.get $backing`,
|
|
2305
|
+
`${indent(3)}local.get $index`,
|
|
2306
|
+
`${indent(3)}local.get $insert_length`,
|
|
2307
|
+
`${indent(3)}i32.sub`,
|
|
2308
|
+
`${indent(3)}local.get $normalized_delete_count`,
|
|
2309
|
+
`${indent(3)}i32.add`,
|
|
2310
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2311
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2312
|
+
`${indent(3)}local.get $index`,
|
|
2313
|
+
`${indent(3)}i32.const 1`,
|
|
2314
|
+
`${indent(3)}i32.add`,
|
|
2315
|
+
`${indent(3)}local.set $index`,
|
|
2316
|
+
`${indent(3)}br $${wrapperTypeName}_splice_suffix_loop`,
|
|
2317
|
+
`${indent(2)})`,
|
|
2318
|
+
`${indent(1)})`,
|
|
2319
|
+
`${indent(1)}local.get $array`,
|
|
2320
|
+
`${indent(1)}local.get $remaining_backing`,
|
|
2321
|
+
`${indent(1)}struct.set $${wrapperTypeName} 0`,
|
|
2322
|
+
`${indent(1)}local.get $removed_backing`,
|
|
2323
|
+
`${indent(1)}struct.new $${wrapperTypeName}`,
|
|
2324
|
+
')',
|
|
2325
|
+
];
|
|
2326
|
+
}
|
|
2327
|
+
function emitOwnedArrayReverseHelper(kind, indent) {
|
|
2328
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2329
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2330
|
+
const helperName = getOwnedArrayReverseHelperName(kind);
|
|
2331
|
+
const tempLocal = kind === 'heap'
|
|
2332
|
+
? '(local $temp (ref null eq))'
|
|
2333
|
+
: kind === 'string'
|
|
2334
|
+
? '(local $temp (ref null eq))'
|
|
2335
|
+
: kind === 'number'
|
|
2336
|
+
? '(local $temp f64)'
|
|
2337
|
+
: kind === 'boolean'
|
|
2338
|
+
? '(local $temp i32)'
|
|
2339
|
+
: '(local $temp (ref null $tagged_value))';
|
|
2340
|
+
return [
|
|
2341
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (result (ref null $${wrapperTypeName}))`,
|
|
2342
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
2343
|
+
`${indent(1)}(local $left i32)`,
|
|
2344
|
+
`${indent(1)}(local $right i32)`,
|
|
2345
|
+
`${indent(1)}${tempLocal}`,
|
|
2346
|
+
`${indent(1)}local.get $array`,
|
|
2347
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2348
|
+
`${indent(1)}local.set $backing`,
|
|
2349
|
+
`${indent(1)}i32.const 0`,
|
|
2350
|
+
`${indent(1)}local.set $left`,
|
|
2351
|
+
`${indent(1)}local.get $backing`,
|
|
2352
|
+
`${indent(1)}array.len`,
|
|
2353
|
+
`${indent(1)}i32.const 1`,
|
|
2354
|
+
`${indent(1)}i32.sub`,
|
|
2355
|
+
`${indent(1)}local.set $right`,
|
|
2356
|
+
`${indent(1)}(block $${wrapperTypeName}_reverse_done`,
|
|
2357
|
+
`${indent(2)}(loop $${wrapperTypeName}_reverse_loop`,
|
|
2358
|
+
`${indent(3)}local.get $left`,
|
|
2359
|
+
`${indent(3)}local.get $right`,
|
|
2360
|
+
`${indent(3)}i32.ge_s`,
|
|
2361
|
+
`${indent(3)}br_if $${wrapperTypeName}_reverse_done`,
|
|
2362
|
+
`${indent(3)}local.get $backing`,
|
|
2363
|
+
`${indent(3)}local.get $left`,
|
|
2364
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2365
|
+
`${indent(3)}local.set $temp`,
|
|
2366
|
+
`${indent(3)}local.get $backing`,
|
|
2367
|
+
`${indent(3)}local.get $left`,
|
|
2368
|
+
`${indent(3)}local.get $backing`,
|
|
2369
|
+
`${indent(3)}local.get $right`,
|
|
2370
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2371
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2372
|
+
`${indent(3)}local.get $backing`,
|
|
2373
|
+
`${indent(3)}local.get $right`,
|
|
2374
|
+
`${indent(3)}local.get $temp`,
|
|
2375
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2376
|
+
`${indent(3)}local.get $left`,
|
|
2377
|
+
`${indent(3)}i32.const 1`,
|
|
2378
|
+
`${indent(3)}i32.add`,
|
|
2379
|
+
`${indent(3)}local.set $left`,
|
|
2380
|
+
`${indent(3)}local.get $right`,
|
|
2381
|
+
`${indent(3)}i32.const 1`,
|
|
2382
|
+
`${indent(3)}i32.sub`,
|
|
2383
|
+
`${indent(3)}local.set $right`,
|
|
2384
|
+
`${indent(3)}br $${wrapperTypeName}_reverse_loop`,
|
|
2385
|
+
`${indent(2)})`,
|
|
2386
|
+
`${indent(1)})`,
|
|
2387
|
+
`${indent(1)}local.get $array`,
|
|
2388
|
+
')',
|
|
2389
|
+
];
|
|
2390
|
+
}
|
|
2391
|
+
function emitOwnedArrayFillHelper(kind, indent) {
|
|
2392
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2393
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2394
|
+
const helperName = getOwnedArrayFillHelperName(kind);
|
|
2395
|
+
const valueType = getOwnedArrayPushValueWatType(kind);
|
|
2396
|
+
return [
|
|
2397
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $value ${valueType}) (param $start f64) (param $end f64) (param $has_end i32) (result (ref null $${wrapperTypeName}))`,
|
|
2398
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
2399
|
+
`${indent(1)}(local $length i32)`,
|
|
2400
|
+
`${indent(1)}(local $normalized_start i32)`,
|
|
2401
|
+
`${indent(1)}(local $normalized_end i32)`,
|
|
2402
|
+
`${indent(1)}(local $index i32)`,
|
|
2403
|
+
`${indent(1)}local.get $array`,
|
|
2404
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2405
|
+
`${indent(1)}local.set $backing`,
|
|
2406
|
+
`${indent(1)}local.get $backing`,
|
|
2407
|
+
`${indent(1)}array.len`,
|
|
2408
|
+
`${indent(1)}local.set $length`,
|
|
2409
|
+
...emitNormalizeSliceIndexLines('start', 'normalized_start', indent),
|
|
2410
|
+
`${indent(1)}local.get $has_end`,
|
|
2411
|
+
`${indent(1)}(if`,
|
|
2412
|
+
`${indent(2)}(then`,
|
|
2413
|
+
...emitNormalizeSliceIndexLines('end', 'normalized_end', indent).map((line) => `${indent(1)}${line.slice(indent(1).length)}`),
|
|
2414
|
+
`${indent(2)})`,
|
|
2415
|
+
`${indent(2)}(else`,
|
|
2416
|
+
`${indent(3)}local.get $length`,
|
|
2417
|
+
`${indent(3)}local.set $normalized_end`,
|
|
2418
|
+
`${indent(2)})`,
|
|
2419
|
+
`${indent(1)})`,
|
|
2420
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2421
|
+
`${indent(1)}local.set $index`,
|
|
2422
|
+
`${indent(1)}(block $${wrapperTypeName}_fill_done`,
|
|
2423
|
+
`${indent(2)}(loop $${wrapperTypeName}_fill_loop`,
|
|
2424
|
+
`${indent(3)}local.get $index`,
|
|
2425
|
+
`${indent(3)}local.get $normalized_end`,
|
|
2426
|
+
`${indent(3)}i32.ge_u`,
|
|
2427
|
+
`${indent(3)}br_if $${wrapperTypeName}_fill_done`,
|
|
2428
|
+
`${indent(3)}local.get $backing`,
|
|
2429
|
+
`${indent(3)}local.get $index`,
|
|
2430
|
+
`${indent(3)}local.get $value`,
|
|
2431
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2432
|
+
`${indent(3)}local.get $index`,
|
|
2433
|
+
`${indent(3)}i32.const 1`,
|
|
2434
|
+
`${indent(3)}i32.add`,
|
|
2435
|
+
`${indent(3)}local.set $index`,
|
|
2436
|
+
`${indent(3)}br $${wrapperTypeName}_fill_loop`,
|
|
2437
|
+
`${indent(2)})`,
|
|
2438
|
+
`${indent(1)})`,
|
|
2439
|
+
`${indent(1)}local.get $array`,
|
|
2440
|
+
')',
|
|
2441
|
+
];
|
|
2442
|
+
}
|
|
2443
|
+
function emitOwnedArrayCopyWithinHelper(kind, indent) {
|
|
2444
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2445
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2446
|
+
const helperName = getOwnedArrayCopyWithinHelperName(kind);
|
|
2447
|
+
return [
|
|
2448
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $target f64) (param $start f64) (param $end f64) (param $has_end i32) (result (ref null $${wrapperTypeName}))`,
|
|
2449
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
2450
|
+
`${indent(1)}(local $copy_backing (ref null $${dataTypeName}))`,
|
|
2451
|
+
`${indent(1)}(local $length i32)`,
|
|
2452
|
+
`${indent(1)}(local $normalized_target i32)`,
|
|
2453
|
+
`${indent(1)}(local $normalized_start i32)`,
|
|
2454
|
+
`${indent(1)}(local $normalized_end i32)`,
|
|
2455
|
+
`${indent(1)}(local $copy_length i32)`,
|
|
2456
|
+
`${indent(1)}(local $available_target i32)`,
|
|
2457
|
+
`${indent(1)}(local $index i32)`,
|
|
2458
|
+
`${indent(1)}local.get $array`,
|
|
2459
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2460
|
+
`${indent(1)}local.set $backing`,
|
|
2461
|
+
`${indent(1)}local.get $backing`,
|
|
2462
|
+
`${indent(1)}array.len`,
|
|
2463
|
+
`${indent(1)}local.set $length`,
|
|
2464
|
+
...emitNormalizeSliceIndexLines('target', 'normalized_target', indent),
|
|
2465
|
+
...emitNormalizeSliceIndexLines('start', 'normalized_start', indent),
|
|
2466
|
+
`${indent(1)}local.get $has_end`,
|
|
2467
|
+
`${indent(1)}(if`,
|
|
2468
|
+
`${indent(2)}(then`,
|
|
2469
|
+
...emitNormalizeSliceIndexLines('end', 'normalized_end', indent).map((line) => `${indent(1)}${line.slice(indent(1).length)}`),
|
|
2470
|
+
`${indent(2)})`,
|
|
2471
|
+
`${indent(2)}(else`,
|
|
2472
|
+
`${indent(3)}local.get $length`,
|
|
2473
|
+
`${indent(3)}local.set $normalized_end`,
|
|
2474
|
+
`${indent(2)})`,
|
|
2475
|
+
`${indent(1)})`,
|
|
2476
|
+
`${indent(1)}local.get $normalized_end`,
|
|
2477
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2478
|
+
`${indent(1)}i32.lt_s`,
|
|
2479
|
+
`${indent(1)}(if`,
|
|
2480
|
+
`${indent(2)}(then`,
|
|
2481
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2482
|
+
`${indent(3)}local.set $normalized_end`,
|
|
2483
|
+
`${indent(2)})`,
|
|
2484
|
+
`${indent(1)})`,
|
|
2485
|
+
`${indent(1)}local.get $normalized_end`,
|
|
2486
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2487
|
+
`${indent(1)}i32.sub`,
|
|
2488
|
+
`${indent(1)}local.set $copy_length`,
|
|
2489
|
+
`${indent(1)}local.get $length`,
|
|
2490
|
+
`${indent(1)}local.get $normalized_target`,
|
|
2491
|
+
`${indent(1)}i32.sub`,
|
|
2492
|
+
`${indent(1)}local.set $available_target`,
|
|
2493
|
+
`${indent(1)}local.get $available_target`,
|
|
2494
|
+
`${indent(1)}local.get $copy_length`,
|
|
2495
|
+
`${indent(1)}i32.lt_s`,
|
|
2496
|
+
`${indent(1)}(if`,
|
|
2497
|
+
`${indent(2)}(then`,
|
|
2498
|
+
`${indent(3)}local.get $available_target`,
|
|
2499
|
+
`${indent(3)}i32.const 0`,
|
|
2500
|
+
`${indent(3)}i32.lt_s`,
|
|
2501
|
+
`${indent(3)}(if`,
|
|
2502
|
+
`${indent(4)}(then`,
|
|
2503
|
+
`${indent(5)}i32.const 0`,
|
|
2504
|
+
`${indent(5)}local.set $copy_length`,
|
|
2505
|
+
`${indent(4)})`,
|
|
2506
|
+
`${indent(4)}(else`,
|
|
2507
|
+
`${indent(5)}local.get $available_target`,
|
|
2508
|
+
`${indent(5)}local.set $copy_length`,
|
|
2509
|
+
`${indent(4)})`,
|
|
2510
|
+
`${indent(3)})`,
|
|
2511
|
+
`${indent(2)})`,
|
|
2512
|
+
`${indent(1)})`,
|
|
2513
|
+
`${indent(1)}local.get $copy_length`,
|
|
2514
|
+
`${indent(1)}array.new_default $${dataTypeName}`,
|
|
2515
|
+
`${indent(1)}local.set $copy_backing`,
|
|
2516
|
+
`${indent(1)}i32.const 0`,
|
|
2517
|
+
`${indent(1)}local.set $index`,
|
|
2518
|
+
`${indent(1)}(block $${wrapperTypeName}_copy_within_capture_done`,
|
|
2519
|
+
`${indent(2)}(loop $${wrapperTypeName}_copy_within_capture_loop`,
|
|
2520
|
+
`${indent(3)}local.get $index`,
|
|
2521
|
+
`${indent(3)}local.get $copy_length`,
|
|
2522
|
+
`${indent(3)}i32.ge_u`,
|
|
2523
|
+
`${indent(3)}br_if $${wrapperTypeName}_copy_within_capture_done`,
|
|
2524
|
+
`${indent(3)}local.get $copy_backing`,
|
|
2525
|
+
`${indent(3)}local.get $index`,
|
|
2526
|
+
`${indent(3)}local.get $backing`,
|
|
2527
|
+
`${indent(3)}local.get $normalized_start`,
|
|
2528
|
+
`${indent(3)}local.get $index`,
|
|
2529
|
+
`${indent(3)}i32.add`,
|
|
2530
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2531
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2532
|
+
`${indent(3)}local.get $index`,
|
|
2533
|
+
`${indent(3)}i32.const 1`,
|
|
2534
|
+
`${indent(3)}i32.add`,
|
|
2535
|
+
`${indent(3)}local.set $index`,
|
|
2536
|
+
`${indent(3)}br $${wrapperTypeName}_copy_within_capture_loop`,
|
|
2537
|
+
`${indent(2)})`,
|
|
2538
|
+
`${indent(1)})`,
|
|
2539
|
+
`${indent(1)}i32.const 0`,
|
|
2540
|
+
`${indent(1)}local.set $index`,
|
|
2541
|
+
`${indent(1)}(block $${wrapperTypeName}_copy_within_write_done`,
|
|
2542
|
+
`${indent(2)}(loop $${wrapperTypeName}_copy_within_write_loop`,
|
|
2543
|
+
`${indent(3)}local.get $index`,
|
|
2544
|
+
`${indent(3)}local.get $copy_length`,
|
|
2545
|
+
`${indent(3)}i32.ge_u`,
|
|
2546
|
+
`${indent(3)}br_if $${wrapperTypeName}_copy_within_write_done`,
|
|
2547
|
+
`${indent(3)}local.get $backing`,
|
|
2548
|
+
`${indent(3)}local.get $normalized_target`,
|
|
2549
|
+
`${indent(3)}local.get $index`,
|
|
2550
|
+
`${indent(3)}i32.add`,
|
|
2551
|
+
`${indent(3)}local.get $copy_backing`,
|
|
2552
|
+
`${indent(3)}local.get $index`,
|
|
2553
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2554
|
+
`${indent(3)}array.set $${dataTypeName}`,
|
|
2555
|
+
`${indent(3)}local.get $index`,
|
|
2556
|
+
`${indent(3)}i32.const 1`,
|
|
2557
|
+
`${indent(3)}i32.add`,
|
|
2558
|
+
`${indent(3)}local.set $index`,
|
|
2559
|
+
`${indent(3)}br $${wrapperTypeName}_copy_within_write_loop`,
|
|
2560
|
+
`${indent(2)})`,
|
|
2561
|
+
`${indent(1)})`,
|
|
2562
|
+
`${indent(1)}local.get $array`,
|
|
2563
|
+
')',
|
|
2564
|
+
];
|
|
2565
|
+
}
|
|
2566
|
+
function emitOwnedArrayIncludesHelper(kind, indent, stringRuntimeLayout) {
|
|
2567
|
+
if (kind === 'string' && !stringRuntimeLayout) {
|
|
2568
|
+
throw new CompilerUnsupportedError('Owned string-array includes helpers require the owned string runtime.');
|
|
2569
|
+
}
|
|
2570
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2571
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2572
|
+
const helperName = getOwnedArrayIncludesHelperName(kind);
|
|
2573
|
+
const searchType = getOwnedArrayPushValueWatType(kind);
|
|
2574
|
+
const taggedComparison = kind === 'tagged'
|
|
2575
|
+
? emitTaggedValueComparisonLines('same_value_zero', [
|
|
2576
|
+
'i32.const 1',
|
|
2577
|
+
'local.set $found',
|
|
2578
|
+
`br $${wrapperTypeName}_includes_done`,
|
|
2579
|
+
], indent, stringRuntimeLayout)
|
|
2580
|
+
: undefined;
|
|
2581
|
+
const candidateLocal = kind === 'heap'
|
|
2582
|
+
? '(local $candidate (ref null eq))'
|
|
2583
|
+
: kind === 'string'
|
|
2584
|
+
? `(local $candidate (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`
|
|
2585
|
+
: kind === 'number'
|
|
2586
|
+
? '(local $candidate f64)'
|
|
2587
|
+
: kind === 'boolean'
|
|
2588
|
+
? '(local $candidate i32)'
|
|
2589
|
+
: '(local $candidate (ref null $tagged_value))';
|
|
2590
|
+
const equalityLines = kind === 'heap'
|
|
2591
|
+
? [
|
|
2592
|
+
`${indent(3)}local.get $candidate`,
|
|
2593
|
+
`${indent(3)}local.get $search`,
|
|
2594
|
+
`${indent(3)}ref.eq`,
|
|
2595
|
+
`${indent(3)}(if`,
|
|
2596
|
+
`${indent(4)}(then`,
|
|
2597
|
+
`${indent(5)}i32.const 1`,
|
|
2598
|
+
`${indent(5)}local.set $found`,
|
|
2599
|
+
`${indent(5)}br $${wrapperTypeName}_includes_done`,
|
|
2600
|
+
`${indent(4)})`,
|
|
2601
|
+
`${indent(3)})`,
|
|
2602
|
+
]
|
|
2603
|
+
: kind === 'string'
|
|
2604
|
+
? [
|
|
2605
|
+
`${indent(3)}local.get $candidate`,
|
|
2606
|
+
`${indent(3)}local.get $search`,
|
|
2607
|
+
`${indent(3)}call $owned_string_equals`,
|
|
2608
|
+
`${indent(3)}(if`,
|
|
2609
|
+
`${indent(4)}(then`,
|
|
2610
|
+
`${indent(5)}i32.const 1`,
|
|
2611
|
+
`${indent(5)}local.set $found`,
|
|
2612
|
+
`${indent(5)}br $${wrapperTypeName}_includes_done`,
|
|
2613
|
+
`${indent(4)})`,
|
|
2614
|
+
`${indent(3)})`,
|
|
2615
|
+
]
|
|
2616
|
+
: kind === 'number'
|
|
2617
|
+
? [
|
|
2618
|
+
`${indent(3)}local.get $candidate`,
|
|
2619
|
+
`${indent(3)}local.get $search`,
|
|
2620
|
+
`${indent(3)}f64.eq`,
|
|
2621
|
+
`${indent(3)}(if`,
|
|
2622
|
+
`${indent(4)}(then`,
|
|
2623
|
+
`${indent(5)}i32.const 1`,
|
|
2624
|
+
`${indent(5)}local.set $found`,
|
|
2625
|
+
`${indent(5)}br $${wrapperTypeName}_includes_done`,
|
|
2626
|
+
`${indent(4)})`,
|
|
2627
|
+
`${indent(3)})`,
|
|
2628
|
+
`${indent(3)}local.get $candidate`,
|
|
2629
|
+
`${indent(3)}local.get $candidate`,
|
|
2630
|
+
`${indent(3)}f64.ne`,
|
|
2631
|
+
`${indent(3)}local.get $search`,
|
|
2632
|
+
`${indent(3)}local.get $search`,
|
|
2633
|
+
`${indent(3)}f64.ne`,
|
|
2634
|
+
`${indent(3)}i32.and`,
|
|
2635
|
+
`${indent(3)}(if`,
|
|
2636
|
+
`${indent(4)}(then`,
|
|
2637
|
+
`${indent(5)}i32.const 1`,
|
|
2638
|
+
`${indent(5)}local.set $found`,
|
|
2639
|
+
`${indent(5)}br $${wrapperTypeName}_includes_done`,
|
|
2640
|
+
`${indent(4)})`,
|
|
2641
|
+
`${indent(3)})`,
|
|
2642
|
+
]
|
|
2643
|
+
: kind === 'boolean'
|
|
2644
|
+
? [
|
|
2645
|
+
`${indent(3)}local.get $candidate`,
|
|
2646
|
+
`${indent(3)}local.get $search`,
|
|
2647
|
+
`${indent(3)}i32.eq`,
|
|
2648
|
+
`${indent(3)}(if`,
|
|
2649
|
+
`${indent(4)}(then`,
|
|
2650
|
+
`${indent(5)}i32.const 1`,
|
|
2651
|
+
`${indent(5)}local.set $found`,
|
|
2652
|
+
`${indent(5)}br $${wrapperTypeName}_includes_done`,
|
|
2653
|
+
`${indent(4)})`,
|
|
2654
|
+
`${indent(3)})`,
|
|
2655
|
+
]
|
|
2656
|
+
: taggedComparison.lines;
|
|
2657
|
+
return [
|
|
2658
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $search ${searchType}) (param $from_index f64) (param $has_from_index i32) (result i32)`,
|
|
2659
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
2660
|
+
`${indent(1)}(local $length i32)`,
|
|
2661
|
+
`${indent(1)}(local $normalized_start i32)`,
|
|
2662
|
+
`${indent(1)}(local $index i32)`,
|
|
2663
|
+
`${indent(1)}(local $found i32)`,
|
|
2664
|
+
`${indent(1)}${candidateLocal}`,
|
|
2665
|
+
...(taggedComparison?.locals.map((local) => `${indent(1)}${local}`) ?? []),
|
|
2666
|
+
`${indent(1)}local.get $array`,
|
|
2667
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2668
|
+
`${indent(1)}local.set $backing`,
|
|
2669
|
+
`${indent(1)}local.get $backing`,
|
|
2670
|
+
`${indent(1)}array.len`,
|
|
2671
|
+
`${indent(1)}local.set $length`,
|
|
2672
|
+
`${indent(1)}local.get $has_from_index`,
|
|
2673
|
+
`${indent(1)}(if`,
|
|
2674
|
+
`${indent(2)}(then`,
|
|
2675
|
+
...emitNormalizeSliceIndexLines('from_index', 'normalized_start', indent).map((line) => `${indent(1)}${line.slice(indent(1).length)}`),
|
|
2676
|
+
`${indent(2)})`,
|
|
2677
|
+
`${indent(2)}(else`,
|
|
2678
|
+
`${indent(3)}i32.const 0`,
|
|
2679
|
+
`${indent(3)}local.set $normalized_start`,
|
|
2680
|
+
`${indent(2)})`,
|
|
2681
|
+
`${indent(1)})`,
|
|
2682
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2683
|
+
`${indent(1)}local.set $index`,
|
|
2684
|
+
`${indent(1)}i32.const 0`,
|
|
2685
|
+
`${indent(1)}local.set $found`,
|
|
2686
|
+
`${indent(1)}(block $${wrapperTypeName}_includes_done`,
|
|
2687
|
+
`${indent(2)}(loop $${wrapperTypeName}_includes_loop`,
|
|
2688
|
+
`${indent(3)}local.get $index`,
|
|
2689
|
+
`${indent(3)}local.get $length`,
|
|
2690
|
+
`${indent(3)}i32.ge_u`,
|
|
2691
|
+
`${indent(3)}br_if $${wrapperTypeName}_includes_done`,
|
|
2692
|
+
...(kind === 'string'
|
|
2693
|
+
? [
|
|
2694
|
+
`${indent(3)}local.get $backing`,
|
|
2695
|
+
`${indent(3)}local.get $index`,
|
|
2696
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2697
|
+
`${indent(3)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
2698
|
+
`${indent(3)}local.set $candidate`,
|
|
2699
|
+
]
|
|
2700
|
+
: [
|
|
2701
|
+
`${indent(3)}local.get $backing`,
|
|
2702
|
+
`${indent(3)}local.get $index`,
|
|
2703
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2704
|
+
`${indent(3)}local.set $candidate`,
|
|
2705
|
+
]),
|
|
2706
|
+
...equalityLines,
|
|
2707
|
+
`${indent(3)}local.get $index`,
|
|
2708
|
+
`${indent(3)}i32.const 1`,
|
|
2709
|
+
`${indent(3)}i32.add`,
|
|
2710
|
+
`${indent(3)}local.set $index`,
|
|
2711
|
+
`${indent(3)}br $${wrapperTypeName}_includes_loop`,
|
|
2712
|
+
`${indent(2)})`,
|
|
2713
|
+
`${indent(1)})`,
|
|
2714
|
+
`${indent(1)}local.get $found`,
|
|
2715
|
+
')',
|
|
2716
|
+
];
|
|
2717
|
+
}
|
|
2718
|
+
function emitOwnedArrayIndexOfHelper(kind, indent, stringRuntimeLayout) {
|
|
2719
|
+
if (kind === 'string' && !stringRuntimeLayout) {
|
|
2720
|
+
throw new CompilerUnsupportedError('Owned string-array indexOf helpers require the owned string runtime.');
|
|
2721
|
+
}
|
|
2722
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2723
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2724
|
+
const helperName = getOwnedArrayIndexOfHelperName(kind);
|
|
2725
|
+
const searchType = getOwnedArrayPushValueWatType(kind);
|
|
2726
|
+
const taggedComparison = kind === 'tagged'
|
|
2727
|
+
? emitTaggedValueComparisonLines('strict', [
|
|
2728
|
+
'local.get $index',
|
|
2729
|
+
'f64.convert_i32_s',
|
|
2730
|
+
'return',
|
|
2731
|
+
], indent, stringRuntimeLayout)
|
|
2732
|
+
: undefined;
|
|
2733
|
+
const candidateLocal = kind === 'heap'
|
|
2734
|
+
? '(local $candidate (ref null eq))'
|
|
2735
|
+
: kind === 'string'
|
|
2736
|
+
? `(local $candidate (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`
|
|
2737
|
+
: kind === 'number'
|
|
2738
|
+
? '(local $candidate f64)'
|
|
2739
|
+
: kind === 'boolean'
|
|
2740
|
+
? '(local $candidate i32)'
|
|
2741
|
+
: '(local $candidate (ref null $tagged_value))';
|
|
2742
|
+
const equalityLines = kind === 'heap'
|
|
2743
|
+
? [
|
|
2744
|
+
`${indent(3)}local.get $candidate`,
|
|
2745
|
+
`${indent(3)}local.get $search`,
|
|
2746
|
+
`${indent(3)}ref.eq`,
|
|
2747
|
+
`${indent(3)}(if`,
|
|
2748
|
+
`${indent(4)}(then`,
|
|
2749
|
+
`${indent(5)}local.get $index`,
|
|
2750
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2751
|
+
`${indent(5)}return`,
|
|
2752
|
+
`${indent(4)})`,
|
|
2753
|
+
`${indent(3)})`,
|
|
2754
|
+
]
|
|
2755
|
+
: kind === 'string'
|
|
2756
|
+
? [
|
|
2757
|
+
`${indent(3)}local.get $candidate`,
|
|
2758
|
+
`${indent(3)}local.get $search`,
|
|
2759
|
+
`${indent(3)}call $owned_string_equals`,
|
|
2760
|
+
`${indent(3)}(if`,
|
|
2761
|
+
`${indent(4)}(then`,
|
|
2762
|
+
`${indent(5)}local.get $index`,
|
|
2763
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2764
|
+
`${indent(5)}return`,
|
|
2765
|
+
`${indent(4)})`,
|
|
2766
|
+
`${indent(3)})`,
|
|
2767
|
+
]
|
|
2768
|
+
: kind === 'number'
|
|
2769
|
+
? [
|
|
2770
|
+
`${indent(3)}local.get $candidate`,
|
|
2771
|
+
`${indent(3)}local.get $search`,
|
|
2772
|
+
`${indent(3)}f64.eq`,
|
|
2773
|
+
`${indent(3)}(if`,
|
|
2774
|
+
`${indent(4)}(then`,
|
|
2775
|
+
`${indent(5)}local.get $index`,
|
|
2776
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2777
|
+
`${indent(5)}return`,
|
|
2778
|
+
`${indent(4)})`,
|
|
2779
|
+
`${indent(3)})`,
|
|
2780
|
+
]
|
|
2781
|
+
: kind === 'boolean'
|
|
2782
|
+
? [
|
|
2783
|
+
`${indent(3)}local.get $candidate`,
|
|
2784
|
+
`${indent(3)}local.get $search`,
|
|
2785
|
+
`${indent(3)}i32.eq`,
|
|
2786
|
+
`${indent(3)}(if`,
|
|
2787
|
+
`${indent(4)}(then`,
|
|
2788
|
+
`${indent(5)}local.get $index`,
|
|
2789
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2790
|
+
`${indent(5)}return`,
|
|
2791
|
+
`${indent(4)})`,
|
|
2792
|
+
`${indent(3)})`,
|
|
2793
|
+
]
|
|
2794
|
+
: taggedComparison.lines;
|
|
2795
|
+
return [
|
|
2796
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $search ${searchType}) (param $from_index f64) (param $has_from_index i32) (result f64)`,
|
|
2797
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
2798
|
+
`${indent(1)}(local $length i32)`,
|
|
2799
|
+
`${indent(1)}(local $normalized_start i32)`,
|
|
2800
|
+
`${indent(1)}(local $index i32)`,
|
|
2801
|
+
`${indent(1)}${candidateLocal}`,
|
|
2802
|
+
...(taggedComparison?.locals.map((local) => `${indent(1)}${local}`) ?? []),
|
|
2803
|
+
`${indent(1)}local.get $array`,
|
|
2804
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2805
|
+
`${indent(1)}local.set $backing`,
|
|
2806
|
+
`${indent(1)}local.get $backing`,
|
|
2807
|
+
`${indent(1)}array.len`,
|
|
2808
|
+
`${indent(1)}local.set $length`,
|
|
2809
|
+
`${indent(1)}local.get $has_from_index`,
|
|
2810
|
+
`${indent(1)}(if`,
|
|
2811
|
+
`${indent(2)}(then`,
|
|
2812
|
+
...emitNormalizeSliceIndexLines('from_index', 'normalized_start', indent).map((line) => `${indent(1)}${line.slice(indent(1).length)}`),
|
|
2813
|
+
`${indent(2)})`,
|
|
2814
|
+
`${indent(2)}(else`,
|
|
2815
|
+
`${indent(3)}i32.const 0`,
|
|
2816
|
+
`${indent(3)}local.set $normalized_start`,
|
|
2817
|
+
`${indent(2)})`,
|
|
2818
|
+
`${indent(1)})`,
|
|
2819
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2820
|
+
`${indent(1)}local.set $index`,
|
|
2821
|
+
`${indent(1)}(block $${wrapperTypeName}_index_of_done`,
|
|
2822
|
+
`${indent(2)}(loop $${wrapperTypeName}_index_of_loop`,
|
|
2823
|
+
`${indent(3)}local.get $index`,
|
|
2824
|
+
`${indent(3)}local.get $length`,
|
|
2825
|
+
`${indent(3)}i32.ge_u`,
|
|
2826
|
+
`${indent(3)}br_if $${wrapperTypeName}_index_of_done`,
|
|
2827
|
+
...(kind === 'string'
|
|
2828
|
+
? [
|
|
2829
|
+
`${indent(3)}local.get $backing`,
|
|
2830
|
+
`${indent(3)}local.get $index`,
|
|
2831
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2832
|
+
`${indent(3)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
2833
|
+
`${indent(3)}local.set $candidate`,
|
|
2834
|
+
]
|
|
2835
|
+
: [
|
|
2836
|
+
`${indent(3)}local.get $backing`,
|
|
2837
|
+
`${indent(3)}local.get $index`,
|
|
2838
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2839
|
+
`${indent(3)}local.set $candidate`,
|
|
2840
|
+
]),
|
|
2841
|
+
...equalityLines,
|
|
2842
|
+
`${indent(3)}local.get $index`,
|
|
2843
|
+
`${indent(3)}i32.const 1`,
|
|
2844
|
+
`${indent(3)}i32.add`,
|
|
2845
|
+
`${indent(3)}local.set $index`,
|
|
2846
|
+
`${indent(3)}br $${wrapperTypeName}_index_of_loop`,
|
|
2847
|
+
`${indent(2)})`,
|
|
2848
|
+
`${indent(1)})`,
|
|
2849
|
+
`${indent(1)}f64.const -1`,
|
|
2850
|
+
')',
|
|
2851
|
+
];
|
|
2852
|
+
}
|
|
2853
|
+
function emitOwnedArrayLastIndexOfHelper(kind, indent, stringRuntimeLayout) {
|
|
2854
|
+
if (kind === 'string' && !stringRuntimeLayout) {
|
|
2855
|
+
throw new CompilerUnsupportedError('Owned string-array lastIndexOf helpers require the owned string runtime.');
|
|
2856
|
+
}
|
|
2857
|
+
const wrapperTypeName = getOwnedArrayWatTypeName(kind);
|
|
2858
|
+
const dataTypeName = getOwnedArrayDataWatTypeName(kind);
|
|
2859
|
+
const helperName = getOwnedArrayLastIndexOfHelperName(kind);
|
|
2860
|
+
const searchType = getOwnedArrayPushValueWatType(kind);
|
|
2861
|
+
const taggedComparison = kind === 'tagged'
|
|
2862
|
+
? emitTaggedValueComparisonLines('strict', [
|
|
2863
|
+
'local.get $index',
|
|
2864
|
+
'f64.convert_i32_s',
|
|
2865
|
+
'return',
|
|
2866
|
+
], indent, stringRuntimeLayout)
|
|
2867
|
+
: undefined;
|
|
2868
|
+
const candidateLocal = kind === 'heap'
|
|
2869
|
+
? '(local $candidate (ref null eq))'
|
|
2870
|
+
: kind === 'string'
|
|
2871
|
+
? `(local $candidate (ref null $${stringRuntimeLayout.runtimeWatTypeId}))`
|
|
2872
|
+
: kind === 'number'
|
|
2873
|
+
? '(local $candidate f64)'
|
|
2874
|
+
: kind === 'boolean'
|
|
2875
|
+
? '(local $candidate i32)'
|
|
2876
|
+
: '(local $candidate (ref null $tagged_value))';
|
|
2877
|
+
const equalityLines = kind === 'heap'
|
|
2878
|
+
? [
|
|
2879
|
+
`${indent(3)}local.get $candidate`,
|
|
2880
|
+
`${indent(3)}local.get $search`,
|
|
2881
|
+
`${indent(3)}ref.eq`,
|
|
2882
|
+
`${indent(3)}(if`,
|
|
2883
|
+
`${indent(4)}(then`,
|
|
2884
|
+
`${indent(5)}local.get $index`,
|
|
2885
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2886
|
+
`${indent(5)}return`,
|
|
2887
|
+
`${indent(4)})`,
|
|
2888
|
+
`${indent(3)})`,
|
|
2889
|
+
]
|
|
2890
|
+
: kind === 'string'
|
|
2891
|
+
? [
|
|
2892
|
+
`${indent(3)}local.get $candidate`,
|
|
2893
|
+
`${indent(3)}local.get $search`,
|
|
2894
|
+
`${indent(3)}call $owned_string_equals`,
|
|
2895
|
+
`${indent(3)}(if`,
|
|
2896
|
+
`${indent(4)}(then`,
|
|
2897
|
+
`${indent(5)}local.get $index`,
|
|
2898
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2899
|
+
`${indent(5)}return`,
|
|
2900
|
+
`${indent(4)})`,
|
|
2901
|
+
`${indent(3)})`,
|
|
2902
|
+
]
|
|
2903
|
+
: kind === 'number'
|
|
2904
|
+
? [
|
|
2905
|
+
`${indent(3)}local.get $candidate`,
|
|
2906
|
+
`${indent(3)}local.get $search`,
|
|
2907
|
+
`${indent(3)}f64.eq`,
|
|
2908
|
+
`${indent(3)}(if`,
|
|
2909
|
+
`${indent(4)}(then`,
|
|
2910
|
+
`${indent(5)}local.get $index`,
|
|
2911
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2912
|
+
`${indent(5)}return`,
|
|
2913
|
+
`${indent(4)})`,
|
|
2914
|
+
`${indent(3)})`,
|
|
2915
|
+
]
|
|
2916
|
+
: kind === 'boolean'
|
|
2917
|
+
? [
|
|
2918
|
+
`${indent(3)}local.get $candidate`,
|
|
2919
|
+
`${indent(3)}local.get $search`,
|
|
2920
|
+
`${indent(3)}i32.eq`,
|
|
2921
|
+
`${indent(3)}(if`,
|
|
2922
|
+
`${indent(4)}(then`,
|
|
2923
|
+
`${indent(5)}local.get $index`,
|
|
2924
|
+
`${indent(5)}f64.convert_i32_s`,
|
|
2925
|
+
`${indent(5)}return`,
|
|
2926
|
+
`${indent(4)})`,
|
|
2927
|
+
`${indent(3)})`,
|
|
2928
|
+
]
|
|
2929
|
+
: taggedComparison.lines;
|
|
2930
|
+
return [
|
|
2931
|
+
`(func $${helperName} (param $array (ref null $${wrapperTypeName})) (param $search ${searchType}) (param $from_index f64) (param $has_from_index i32) (result f64)`,
|
|
2932
|
+
`${indent(1)}(local $backing (ref null $${dataTypeName}))`,
|
|
2933
|
+
`${indent(1)}(local $length i32)`,
|
|
2934
|
+
`${indent(1)}(local $normalized_start i32)`,
|
|
2935
|
+
`${indent(1)}(local $index i32)`,
|
|
2936
|
+
`${indent(1)}${candidateLocal}`,
|
|
2937
|
+
...(taggedComparison?.locals.map((local) => `${indent(1)}${local}`) ?? []),
|
|
2938
|
+
`${indent(1)}local.get $array`,
|
|
2939
|
+
`${indent(1)}struct.get $${wrapperTypeName} 0`,
|
|
2940
|
+
`${indent(1)}local.set $backing`,
|
|
2941
|
+
`${indent(1)}local.get $backing`,
|
|
2942
|
+
`${indent(1)}array.len`,
|
|
2943
|
+
`${indent(1)}local.set $length`,
|
|
2944
|
+
`${indent(1)}local.get $length`,
|
|
2945
|
+
`${indent(1)}i32.eqz`,
|
|
2946
|
+
`${indent(1)}(if`,
|
|
2947
|
+
`${indent(2)}(then`,
|
|
2948
|
+
`${indent(3)}f64.const -1`,
|
|
2949
|
+
`${indent(3)}return`,
|
|
2950
|
+
`${indent(2)})`,
|
|
2951
|
+
`${indent(1)})`,
|
|
2952
|
+
`${indent(1)}local.get $has_from_index`,
|
|
2953
|
+
`${indent(1)}(if`,
|
|
2954
|
+
`${indent(2)}(then`,
|
|
2955
|
+
...emitNormalizeLastIndexFromIndexLines('from_index', 'normalized_start', indent).map((line) => `${indent(1)}${line.slice(indent(1).length)}`),
|
|
2956
|
+
`${indent(2)})`,
|
|
2957
|
+
`${indent(2)}(else`,
|
|
2958
|
+
`${indent(3)}local.get $length`,
|
|
2959
|
+
`${indent(3)}i32.const 1`,
|
|
2960
|
+
`${indent(3)}i32.sub`,
|
|
2961
|
+
`${indent(3)}local.set $normalized_start`,
|
|
2962
|
+
`${indent(2)})`,
|
|
2963
|
+
`${indent(1)})`,
|
|
2964
|
+
`${indent(1)}local.get $normalized_start`,
|
|
2965
|
+
`${indent(1)}local.set $index`,
|
|
2966
|
+
`${indent(1)}(block $${wrapperTypeName}_last_index_of_done`,
|
|
2967
|
+
`${indent(2)}(loop $${wrapperTypeName}_last_index_of_loop`,
|
|
2968
|
+
`${indent(3)}local.get $index`,
|
|
2969
|
+
`${indent(3)}i32.const 0`,
|
|
2970
|
+
`${indent(3)}i32.lt_s`,
|
|
2971
|
+
`${indent(3)}br_if $${wrapperTypeName}_last_index_of_done`,
|
|
2972
|
+
...(kind === 'string'
|
|
2973
|
+
? [
|
|
2974
|
+
`${indent(3)}local.get $backing`,
|
|
2975
|
+
`${indent(3)}local.get $index`,
|
|
2976
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2977
|
+
`${indent(3)}ref.cast (ref null $${stringRuntimeLayout.runtimeWatTypeId})`,
|
|
2978
|
+
`${indent(3)}local.set $candidate`,
|
|
2979
|
+
]
|
|
2980
|
+
: [
|
|
2981
|
+
`${indent(3)}local.get $backing`,
|
|
2982
|
+
`${indent(3)}local.get $index`,
|
|
2983
|
+
`${indent(3)}array.get $${dataTypeName}`,
|
|
2984
|
+
`${indent(3)}local.set $candidate`,
|
|
2985
|
+
]),
|
|
2986
|
+
...equalityLines,
|
|
2987
|
+
`${indent(3)}local.get $index`,
|
|
2988
|
+
`${indent(3)}i32.const 1`,
|
|
2989
|
+
`${indent(3)}i32.sub`,
|
|
2990
|
+
`${indent(3)}local.set $index`,
|
|
2991
|
+
`${indent(3)}br $${wrapperTypeName}_last_index_of_loop`,
|
|
2992
|
+
`${indent(2)})`,
|
|
2993
|
+
`${indent(1)})`,
|
|
2994
|
+
`${indent(1)}f64.const -1`,
|
|
2995
|
+
')',
|
|
2996
|
+
];
|
|
2997
|
+
}
|
|
2998
|
+
export function emitHostOwnedArrayResultAdaptation(resultKind, ownedArrayParamKinds, level, indent) {
|
|
2999
|
+
return ownedArrayParamKinds.includes(resultKind)
|
|
3000
|
+
? [
|
|
3001
|
+
`${indent(level)}call $copy_owned_${resultKind}_array_to_host_array`,
|
|
3002
|
+
`${indent(level)}local.get $result_host_param`,
|
|
3003
|
+
]
|
|
3004
|
+
: [`${indent(level)}call $${getOwnedArrayToHostHelperName(resultKind)}`];
|
|
3005
|
+
}
|
|
3006
|
+
export function emitOwnedArrayBoundaryHelpers(module, options) {
|
|
3007
|
+
const { usesStringParamBoundary, usesStringParamCopyBack, usesStringResultBoundary, usesNumberParamBoundary, usesNumberParamCopyBack, usesNumberResultBoundary, usesBooleanParamBoundary, usesBooleanParamCopyBack, usesBooleanResultBoundary, usesTaggedParamBoundary, usesTaggedParamCopyBack, usesTaggedResultBoundary, indent, createUnsupportedHeapRuntimeBackendError, fallbackObjectWatTypeId, layoutsByRepresentationName, stringRuntimeLayout, } = options;
|
|
3008
|
+
if (!usesStringParamBoundary && !usesStringParamCopyBack && !usesStringResultBoundary &&
|
|
3009
|
+
!usesNumberParamBoundary && !usesNumberParamCopyBack && !usesNumberResultBoundary &&
|
|
3010
|
+
!usesBooleanParamBoundary && !usesBooleanParamCopyBack && !usesBooleanResultBoundary &&
|
|
3011
|
+
!usesTaggedParamBoundary && !usesTaggedParamCopyBack && !usesTaggedResultBoundary) {
|
|
3012
|
+
return [];
|
|
3013
|
+
}
|
|
3014
|
+
if ((usesStringParamBoundary || usesStringParamCopyBack || usesStringResultBoundary) &&
|
|
3015
|
+
!stringRuntimeLayout) {
|
|
3016
|
+
throw createUnsupportedHeapRuntimeBackendError('Owned string-array host boundaries require the owned string runtime.');
|
|
3017
|
+
}
|
|
3018
|
+
const taggedKindSets = usesTaggedParamBoundary || usesTaggedParamCopyBack || usesTaggedResultBoundary
|
|
3019
|
+
? collectTaggedArrayBoundaryKindSets(module, layoutsByRepresentationName)
|
|
3020
|
+
: [];
|
|
3021
|
+
return [
|
|
3022
|
+
...(usesStringParamBoundary ? emitHostArrayToOwnedArrayHelper('string', indent) : []),
|
|
3023
|
+
...(usesStringParamBoundary || usesStringParamCopyBack
|
|
3024
|
+
? emitCopyOwnedArrayToHostArrayHelper('string', indent, stringRuntimeLayout)
|
|
3025
|
+
: []),
|
|
3026
|
+
...(usesStringResultBoundary
|
|
3027
|
+
? emitOwnedArrayToHostArrayHelper('string', indent, stringRuntimeLayout)
|
|
3028
|
+
: []),
|
|
3029
|
+
...(usesNumberParamBoundary ? emitHostArrayToOwnedArrayHelper('number', indent) : []),
|
|
3030
|
+
...(usesNumberParamBoundary || usesNumberParamCopyBack
|
|
3031
|
+
? emitCopyOwnedArrayToHostArrayHelper('number', indent)
|
|
3032
|
+
: []),
|
|
3033
|
+
...(usesNumberResultBoundary ? emitOwnedArrayToHostArrayHelper('number', indent) : []),
|
|
3034
|
+
...(usesBooleanParamBoundary ? emitHostArrayToOwnedArrayHelper('boolean', indent) : []),
|
|
3035
|
+
...(usesBooleanParamBoundary || usesBooleanParamCopyBack
|
|
3036
|
+
? emitCopyOwnedArrayToHostArrayHelper('boolean', indent)
|
|
3037
|
+
: []),
|
|
3038
|
+
...(usesBooleanResultBoundary ? emitOwnedArrayToHostArrayHelper('boolean', indent) : []),
|
|
3039
|
+
...(usesTaggedParamBoundary
|
|
3040
|
+
? taggedKindSets.flatMap((kinds) => emitHostArrayToOwnedTaggedArrayHelper(kinds, indent, layoutsByRepresentationName, createUnsupportedHeapRuntimeBackendError))
|
|
3041
|
+
: []),
|
|
3042
|
+
...(usesTaggedParamCopyBack || usesTaggedResultBoundary
|
|
3043
|
+
? taggedKindSets.flatMap((kinds) => emitCopyOwnedTaggedArrayToHostArrayHelper(kinds, indent, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError))
|
|
3044
|
+
: []),
|
|
3045
|
+
...(usesTaggedParamCopyBack || usesTaggedResultBoundary
|
|
3046
|
+
? taggedKindSets.flatMap((kinds) => emitOwnedTaggedArrayToHostArrayHelper(kinds, indent, stringRuntimeLayout, layoutsByRepresentationName, fallbackObjectWatTypeId, createUnsupportedHeapRuntimeBackendError))
|
|
3047
|
+
: []),
|
|
3048
|
+
];
|
|
3049
|
+
}
|
|
3050
|
+
export function emitOwnedArrayNativeHelpers(options, indent, stringRuntimeLayout) {
|
|
3051
|
+
const { usesOwnedStringPush, usesOwnedNumberPush, usesOwnedBooleanPush, usesOwnedTaggedPush, usesOwnedStringUnshift, usesOwnedNumberUnshift, usesOwnedBooleanUnshift, usesOwnedTaggedUnshift, usesOwnedHeapPop, usesOwnedStringPop, usesOwnedNumberPop, usesOwnedBooleanPop, usesOwnedTaggedPop, usesOwnedHeapShift, usesOwnedStringShift, usesOwnedNumberShift, usesOwnedBooleanShift, usesOwnedTaggedShift, usesOwnedHeapAt, usesOwnedStringAt, usesOwnedNumberAt, usesOwnedBooleanAt, usesOwnedTaggedAt, usesOwnedStringJoin, usesOwnedNumberJoin, usesOwnedBooleanJoin, usesOwnedHeapReverse, usesOwnedStringReverse, usesOwnedNumberReverse, usesOwnedBooleanReverse, usesOwnedTaggedReverse, usesOwnedHeapFill, usesOwnedStringFill, usesOwnedNumberFill, usesOwnedBooleanFill, usesOwnedTaggedFill, usesOwnedHeapCopyWithin, usesOwnedStringCopyWithin, usesOwnedNumberCopyWithin, usesOwnedBooleanCopyWithin, usesOwnedTaggedCopyWithin, usesOwnedHeapConcat, usesOwnedStringConcat, usesOwnedNumberConcat, usesOwnedBooleanConcat, usesOwnedTaggedConcat, usesOwnedHeapSlice, usesOwnedStringSlice, usesOwnedNumberSlice, usesOwnedBooleanSlice, usesOwnedTaggedSlice, usesOwnedHeapSplice, usesOwnedStringSplice, usesOwnedNumberSplice, usesOwnedBooleanSplice, usesOwnedHeapIncludes, usesOwnedStringIncludes, usesOwnedNumberIncludes, usesOwnedBooleanIncludes, usesOwnedTaggedIncludes, usesOwnedHeapIndexOf, usesOwnedStringIndexOf, usesOwnedNumberIndexOf, usesOwnedBooleanIndexOf, usesOwnedTaggedIndexOf, usesOwnedHeapLastIndexOf, usesOwnedStringLastIndexOf, usesOwnedNumberLastIndexOf, usesOwnedBooleanLastIndexOf, usesOwnedTaggedLastIndexOf, } = options;
|
|
3052
|
+
return [
|
|
3053
|
+
...(usesOwnedStringPush ? emitOwnedArrayPushHelper('string', indent) : []),
|
|
3054
|
+
...(usesOwnedNumberPush ? emitOwnedArrayPushHelper('number', indent) : []),
|
|
3055
|
+
...(usesOwnedBooleanPush ? emitOwnedArrayPushHelper('boolean', indent) : []),
|
|
3056
|
+
...(usesOwnedTaggedPush ? emitOwnedArrayPushHelper('tagged', indent) : []),
|
|
3057
|
+
...(usesOwnedStringUnshift ? emitOwnedArrayUnshiftHelper('string', indent) : []),
|
|
3058
|
+
...(usesOwnedNumberUnshift ? emitOwnedArrayUnshiftHelper('number', indent) : []),
|
|
3059
|
+
...(usesOwnedBooleanUnshift ? emitOwnedArrayUnshiftHelper('boolean', indent) : []),
|
|
3060
|
+
...(usesOwnedTaggedUnshift ? emitOwnedArrayUnshiftHelper('tagged', indent) : []),
|
|
3061
|
+
...(usesOwnedHeapPop ? emitOwnedArrayPopHelper('heap', indent) : []),
|
|
3062
|
+
...(usesOwnedStringPop ? emitOwnedArrayPopHelper('string', indent, stringRuntimeLayout) : []),
|
|
3063
|
+
...(usesOwnedNumberPop ? emitOwnedArrayPopHelper('number', indent) : []),
|
|
3064
|
+
...(usesOwnedBooleanPop ? emitOwnedArrayPopHelper('boolean', indent) : []),
|
|
3065
|
+
...(usesOwnedTaggedPop ? emitOwnedArrayPopHelper('tagged', indent) : []),
|
|
3066
|
+
...(usesOwnedHeapShift ? emitOwnedArrayShiftHelper('heap', indent) : []),
|
|
3067
|
+
...(usesOwnedStringShift ? emitOwnedArrayShiftHelper('string', indent, stringRuntimeLayout) : []),
|
|
3068
|
+
...(usesOwnedNumberShift ? emitOwnedArrayShiftHelper('number', indent) : []),
|
|
3069
|
+
...(usesOwnedBooleanShift ? emitOwnedArrayShiftHelper('boolean', indent) : []),
|
|
3070
|
+
...(usesOwnedTaggedShift ? emitOwnedArrayShiftHelper('tagged', indent) : []),
|
|
3071
|
+
...(usesOwnedHeapAt ? emitOwnedArrayAtHelper('heap', indent) : []),
|
|
3072
|
+
...(usesOwnedStringAt ? emitOwnedArrayAtHelper('string', indent, stringRuntimeLayout) : []),
|
|
3073
|
+
...(usesOwnedNumberAt ? emitOwnedArrayAtHelper('number', indent) : []),
|
|
3074
|
+
...(usesOwnedBooleanAt ? emitOwnedArrayAtHelper('boolean', indent) : []),
|
|
3075
|
+
...(usesOwnedTaggedAt ? emitOwnedArrayAtHelper('tagged', indent) : []),
|
|
3076
|
+
...(usesOwnedStringJoin ? emitOwnedArrayJoinHelper('string', indent, stringRuntimeLayout) : []),
|
|
3077
|
+
...(usesOwnedNumberJoin ? emitOwnedArrayJoinHelper('number', indent, stringRuntimeLayout) : []),
|
|
3078
|
+
...(usesOwnedBooleanJoin ? emitOwnedArrayJoinHelper('boolean', indent, stringRuntimeLayout) : []),
|
|
3079
|
+
...(usesOwnedHeapReverse ? emitOwnedArrayReverseHelper('heap', indent) : []),
|
|
3080
|
+
...(usesOwnedStringReverse ? emitOwnedArrayReverseHelper('string', indent) : []),
|
|
3081
|
+
...(usesOwnedNumberReverse ? emitOwnedArrayReverseHelper('number', indent) : []),
|
|
3082
|
+
...(usesOwnedBooleanReverse ? emitOwnedArrayReverseHelper('boolean', indent) : []),
|
|
3083
|
+
...(usesOwnedTaggedReverse ? emitOwnedArrayReverseHelper('tagged', indent) : []),
|
|
3084
|
+
...(usesOwnedHeapFill ? emitOwnedArrayFillHelper('heap', indent) : []),
|
|
3085
|
+
...(usesOwnedStringFill ? emitOwnedArrayFillHelper('string', indent) : []),
|
|
3086
|
+
...(usesOwnedNumberFill ? emitOwnedArrayFillHelper('number', indent) : []),
|
|
3087
|
+
...(usesOwnedBooleanFill ? emitOwnedArrayFillHelper('boolean', indent) : []),
|
|
3088
|
+
...(usesOwnedTaggedFill ? emitOwnedArrayFillHelper('tagged', indent) : []),
|
|
3089
|
+
...(usesOwnedHeapCopyWithin ? emitOwnedArrayCopyWithinHelper('heap', indent) : []),
|
|
3090
|
+
...(usesOwnedStringCopyWithin ? emitOwnedArrayCopyWithinHelper('string', indent) : []),
|
|
3091
|
+
...(usesOwnedNumberCopyWithin ? emitOwnedArrayCopyWithinHelper('number', indent) : []),
|
|
3092
|
+
...(usesOwnedBooleanCopyWithin ? emitOwnedArrayCopyWithinHelper('boolean', indent) : []),
|
|
3093
|
+
...(usesOwnedTaggedCopyWithin ? emitOwnedArrayCopyWithinHelper('tagged', indent) : []),
|
|
3094
|
+
...(usesOwnedHeapConcat ? emitOwnedArrayConcatHelper('heap', indent) : []),
|
|
3095
|
+
...(usesOwnedStringConcat ? emitOwnedArrayConcatHelper('string', indent) : []),
|
|
3096
|
+
...(usesOwnedNumberConcat ? emitOwnedArrayConcatHelper('number', indent) : []),
|
|
3097
|
+
...(usesOwnedBooleanConcat ? emitOwnedArrayConcatHelper('boolean', indent) : []),
|
|
3098
|
+
...(usesOwnedTaggedConcat ? emitOwnedArrayConcatHelper('tagged', indent) : []),
|
|
3099
|
+
...(usesOwnedHeapSlice ? emitOwnedArraySliceHelper('heap', indent) : []),
|
|
3100
|
+
...(usesOwnedStringSlice ? emitOwnedArraySliceHelper('string', indent) : []),
|
|
3101
|
+
...(usesOwnedNumberSlice ? emitOwnedArraySliceHelper('number', indent) : []),
|
|
3102
|
+
...(usesOwnedBooleanSlice ? emitOwnedArraySliceHelper('boolean', indent) : []),
|
|
3103
|
+
...(usesOwnedTaggedSlice ? emitOwnedArraySliceHelper('tagged', indent) : []),
|
|
3104
|
+
...(usesOwnedHeapSplice ? emitOwnedArraySpliceHelper('heap', indent) : []),
|
|
3105
|
+
...(usesOwnedStringSplice ? emitOwnedArraySpliceHelper('string', indent) : []),
|
|
3106
|
+
...(usesOwnedNumberSplice ? emitOwnedArraySpliceHelper('number', indent) : []),
|
|
3107
|
+
...(usesOwnedBooleanSplice ? emitOwnedArraySpliceHelper('boolean', indent) : []),
|
|
3108
|
+
...(usesOwnedHeapIncludes ? emitOwnedArrayIncludesHelper('heap', indent) : []),
|
|
3109
|
+
...(usesOwnedStringIncludes
|
|
3110
|
+
? emitOwnedArrayIncludesHelper('string', indent, stringRuntimeLayout)
|
|
3111
|
+
: []),
|
|
3112
|
+
...(usesOwnedNumberIncludes ? emitOwnedArrayIncludesHelper('number', indent) : []),
|
|
3113
|
+
...(usesOwnedBooleanIncludes ? emitOwnedArrayIncludesHelper('boolean', indent) : []),
|
|
3114
|
+
...(usesOwnedTaggedIncludes ? emitOwnedArrayIncludesHelper('tagged', indent, stringRuntimeLayout) : []),
|
|
3115
|
+
...(usesOwnedHeapIndexOf ? emitOwnedArrayIndexOfHelper('heap', indent) : []),
|
|
3116
|
+
...(usesOwnedStringIndexOf
|
|
3117
|
+
? emitOwnedArrayIndexOfHelper('string', indent, stringRuntimeLayout)
|
|
3118
|
+
: []),
|
|
3119
|
+
...(usesOwnedNumberIndexOf ? emitOwnedArrayIndexOfHelper('number', indent) : []),
|
|
3120
|
+
...(usesOwnedBooleanIndexOf ? emitOwnedArrayIndexOfHelper('boolean', indent) : []),
|
|
3121
|
+
...(usesOwnedTaggedIndexOf ? emitOwnedArrayIndexOfHelper('tagged', indent, stringRuntimeLayout) : []),
|
|
3122
|
+
...(usesOwnedHeapLastIndexOf ? emitOwnedArrayLastIndexOfHelper('heap', indent) : []),
|
|
3123
|
+
...(usesOwnedStringLastIndexOf
|
|
3124
|
+
? emitOwnedArrayLastIndexOfHelper('string', indent, stringRuntimeLayout)
|
|
3125
|
+
: []),
|
|
3126
|
+
...(usesOwnedNumberLastIndexOf ? emitOwnedArrayLastIndexOfHelper('number', indent) : []),
|
|
3127
|
+
...(usesOwnedBooleanLastIndexOf ? emitOwnedArrayLastIndexOfHelper('boolean', indent) : []),
|
|
3128
|
+
...(usesOwnedTaggedLastIndexOf
|
|
3129
|
+
? emitOwnedArrayLastIndexOfHelper('tagged', indent, stringRuntimeLayout)
|
|
3130
|
+
: []),
|
|
3131
|
+
];
|
|
3132
|
+
}
|