kumi 0.0.18 → 0.0.20
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +27 -0
- data/CLAUDE.md +26 -139
- data/README.md +143 -372
- data/data/functions/agg/boolean.yaml +14 -0
- data/data/functions/agg/numeric.yaml +80 -0
- data/data/functions/agg/string.yaml +8 -0
- data/data/functions/core/arithmetic.yaml +50 -0
- data/data/functions/core/boolean.yaml +18 -0
- data/data/functions/core/comparison.yaml +42 -0
- data/data/functions/core/constructor.yaml +32 -0
- data/data/functions/core/select.yaml +7 -0
- data/data/functions/core/stencil.yaml +21 -0
- data/data/functions/core/string.yaml +19 -0
- data/data/kernels/javascript/agg/boolean.yaml +12 -0
- data/data/kernels/javascript/agg/numeric.yaml +27 -0
- data/data/kernels/javascript/agg/string.yaml +5 -0
- data/data/kernels/javascript/core/arithmetic.yaml +32 -0
- data/data/kernels/javascript/core/boolean.yaml +12 -0
- data/data/kernels/javascript/core/comparison.yaml +24 -0
- data/data/kernels/javascript/core/constructor.yaml +15 -0
- data/data/kernels/javascript/core/select.yaml +7 -0
- data/data/kernels/javascript/core/string.yaml +12 -0
- data/data/kernels/ruby/agg/boolean.yaml +18 -0
- data/data/kernels/ruby/agg/numeric.yaml +29 -0
- data/data/kernels/ruby/agg/string.yaml +5 -0
- data/data/kernels/ruby/core/arithmetic.yaml +38 -0
- data/data/kernels/ruby/core/boolean.yaml +15 -0
- data/data/kernels/ruby/core/comparison.yaml +30 -0
- data/data/kernels/ruby/core/constructor.yaml +17 -0
- data/data/kernels/ruby/core/select.yaml +4 -0
- data/data/kernels/ruby/core/string.yaml +15 -0
- data/debug_ordering.rb +52 -0
- data/docs/FORM_SCHEMA.md +85 -0
- data/docs/OUTPUT_SCHEMA.md +69 -0
- data/docs/SYNTAX.md +626 -373
- data/golden/array_element/expected/ast.txt +21 -0
- data/golden/array_element/expected/input_plan.txt +5 -0
- data/golden/array_element/expected/lir_00_unoptimized.txt +13 -0
- data/golden/array_element/expected/lir_01_hoist_scalar_references.txt +13 -0
- data/golden/array_element/expected/lir_02_inlined.txt +13 -0
- data/golden/array_element/expected/lir_03_cse.txt +13 -0
- data/golden/array_element/expected/lir_04_1_loop_fusion.txt +13 -0
- data/golden/array_element/expected/lir_04_loop_invcm.txt +13 -0
- data/golden/array_element/expected/lir_06_const_prop.txt +13 -0
- data/golden/array_element/expected/nast.txt +7 -0
- data/golden/array_element/expected/schema_javascript.mjs +13 -0
- data/golden/array_element/expected/schema_ruby.rb +41 -0
- data/golden/array_element/expected/snast.txt +7 -0
- data/golden/array_element/expected.json +5 -0
- data/golden/array_element/input.json +9 -0
- data/golden/array_element/schema.kumi +11 -0
- data/golden/array_index/expected/ast.txt +59 -0
- data/golden/array_index/expected/input_plan.txt +5 -0
- data/golden/array_index/expected/lir_00_unoptimized.txt +41 -0
- data/golden/array_index/expected/lir_01_hoist_scalar_references.txt +41 -0
- data/golden/array_index/expected/lir_02_inlined.txt +42 -0
- data/golden/array_index/expected/lir_03_cse.txt +40 -0
- data/golden/array_index/expected/lir_04_1_loop_fusion.txt +40 -0
- data/golden/array_index/expected/lir_04_loop_invcm.txt +40 -0
- data/golden/array_index/expected/lir_06_const_prop.txt +40 -0
- data/golden/array_index/expected/nast.txt +33 -0
- data/golden/array_index/expected/schema_javascript.mjs +46 -0
- data/golden/array_index/expected/schema_ruby.rb +75 -0
- data/golden/array_index/expected/snast.txt +33 -0
- data/golden/array_index/expected.json +5 -0
- data/golden/array_index/input.json +1 -0
- data/golden/array_index/schema.kumi +19 -0
- data/golden/array_operations/expected/ast.txt +50 -0
- data/golden/array_operations/expected/input_plan.txt +10 -0
- data/golden/array_operations/expected/lir_00_unoptimized.txt +47 -0
- data/golden/array_operations/expected/lir_01_hoist_scalar_references.txt +47 -0
- data/golden/array_operations/expected/lir_02_inlined.txt +47 -0
- data/golden/array_operations/expected/lir_03_cse.txt +47 -0
- data/golden/array_operations/expected/lir_04_1_loop_fusion.txt +47 -0
- data/golden/array_operations/expected/lir_04_loop_invcm.txt +47 -0
- data/golden/array_operations/expected/lir_06_const_prop.txt +47 -0
- data/golden/array_operations/expected/nast.txt +32 -0
- data/golden/array_operations/expected/schema_javascript.mjs +60 -0
- data/golden/array_operations/expected/schema_ruby.rb +91 -0
- data/golden/array_operations/expected/snast.txt +32 -0
- data/golden/array_operations/expected.json +27 -0
- data/golden/array_operations/input.json +8 -0
- data/golden/array_operations/schema.kumi +12 -10
- data/golden/cascade_logic/expected/ast.txt +37 -0
- data/golden/cascade_logic/expected/input_plan.txt +2 -0
- data/golden/cascade_logic/expected/lir_00_unoptimized.txt +29 -0
- data/golden/cascade_logic/expected/lir_01_hoist_scalar_references.txt +29 -0
- data/golden/cascade_logic/expected/lir_02_inlined.txt +37 -0
- data/golden/cascade_logic/expected/lir_03_cse.txt +30 -0
- data/golden/cascade_logic/expected/lir_04_1_loop_fusion.txt +30 -0
- data/golden/cascade_logic/expected/lir_04_loop_invcm.txt +30 -0
- data/golden/cascade_logic/expected/lir_06_const_prop.txt +30 -0
- data/golden/cascade_logic/expected/nast.txt +32 -0
- data/golden/cascade_logic/expected/schema_javascript.mjs +31 -0
- data/golden/cascade_logic/expected/schema_ruby.rb +57 -0
- data/golden/cascade_logic/expected/snast.txt +32 -0
- data/golden/cascade_logic/expected.json +5 -0
- data/golden/cascade_logic/input.json +4 -0
- data/golden/cascade_logic/schema.kumi +1 -3
- data/golden/chained_fusion/expected/ast.txt +57 -0
- data/golden/chained_fusion/expected/input_plan.txt +13 -0
- data/golden/chained_fusion/expected/lir_00_unoptimized.txt +76 -0
- data/golden/chained_fusion/expected/lir_01_hoist_scalar_references.txt +76 -0
- data/golden/chained_fusion/expected/lir_02_inlined.txt +114 -0
- data/golden/chained_fusion/expected/lir_03_cse.txt +97 -0
- data/golden/chained_fusion/expected/lir_04_1_loop_fusion.txt +99 -0
- data/golden/chained_fusion/expected/lir_04_loop_invcm.txt +97 -0
- data/golden/chained_fusion/expected/lir_06_const_prop.txt +97 -0
- data/golden/chained_fusion/expected/nast.txt +55 -0
- data/golden/chained_fusion/expected/schema_javascript.mjs +116 -0
- data/golden/chained_fusion/expected/schema_ruby.rb +149 -0
- data/golden/chained_fusion/expected/snast.txt +55 -0
- data/golden/chained_fusion/expected.json +45 -0
- data/golden/chained_fusion/input.json +51 -0
- data/golden/chained_fusion/schema.kumi +52 -0
- data/golden/element_arrays/expected/ast.txt +55 -0
- data/golden/element_arrays/expected/input_plan.txt +7 -0
- data/golden/element_arrays/expected/lir_00_unoptimized.txt +81 -0
- data/golden/element_arrays/expected/lir_01_hoist_scalar_references.txt +81 -0
- data/golden/element_arrays/expected/lir_02_inlined.txt +85 -0
- data/golden/element_arrays/expected/lir_03_cse.txt +83 -0
- data/golden/element_arrays/expected/lir_04_1_loop_fusion.txt +83 -0
- data/golden/element_arrays/expected/lir_04_loop_invcm.txt +83 -0
- data/golden/element_arrays/expected/lir_06_const_prop.txt +83 -0
- data/golden/element_arrays/expected/nast.txt +42 -0
- data/golden/element_arrays/expected/schema_javascript.mjs +106 -0
- data/golden/element_arrays/expected/schema_ruby.rb +141 -0
- data/golden/element_arrays/expected/snast.txt +42 -0
- data/golden/element_arrays/expected.json +55 -0
- data/golden/element_arrays/input.json +12 -0
- data/golden/element_arrays/schema.kumi +21 -0
- data/golden/empty_and_null_inputs/expected/ast.txt +42 -0
- data/golden/empty_and_null_inputs/expected/input_plan.txt +12 -0
- data/golden/empty_and_null_inputs/expected/lir_00_unoptimized.txt +31 -0
- data/golden/empty_and_null_inputs/expected/lir_01_hoist_scalar_references.txt +31 -0
- data/golden/empty_and_null_inputs/expected/lir_02_inlined.txt +51 -0
- data/golden/empty_and_null_inputs/expected/lir_03_cse.txt +49 -0
- data/golden/empty_and_null_inputs/expected/lir_04_1_loop_fusion.txt +49 -0
- data/golden/empty_and_null_inputs/expected/lir_04_loop_invcm.txt +49 -0
- data/golden/empty_and_null_inputs/expected/lir_06_const_prop.txt +49 -0
- data/golden/empty_and_null_inputs/expected/nast.txt +18 -0
- data/golden/empty_and_null_inputs/expected/schema_javascript.mjs +47 -0
- data/golden/empty_and_null_inputs/expected/schema_ruby.rb +79 -0
- data/golden/empty_and_null_inputs/expected/snast.txt +18 -0
- data/golden/empty_and_null_inputs/expected.json +8 -0
- data/golden/empty_and_null_inputs/input.json +16 -0
- data/golden/empty_and_null_inputs/schema.kumi +30 -0
- data/golden/game_of_life/expected/ast.txt +118 -0
- data/golden/game_of_life/expected/input_plan.txt +5 -0
- data/golden/game_of_life/expected/lir_00_unoptimized.txt +343 -0
- data/golden/game_of_life/expected/lir_01_hoist_scalar_references.txt +343 -0
- data/golden/game_of_life/expected/lir_02_inlined.txt +1918 -0
- data/golden/game_of_life/expected/lir_03_cse.txt +766 -0
- data/golden/game_of_life/expected/lir_04_1_loop_fusion.txt +766 -0
- data/golden/game_of_life/expected/lir_04_loop_invcm.txt +766 -0
- data/golden/game_of_life/expected/lir_06_const_prop.txt +766 -0
- data/golden/game_of_life/expected/nast.txt +104 -0
- data/golden/game_of_life/expected/schema_javascript.mjs +98 -0
- data/golden/game_of_life/expected/schema_ruby.rb +125 -0
- data/golden/game_of_life/expected/snast.txt +104 -0
- data/golden/game_of_life/expected.json +3 -0
- data/golden/game_of_life/input.json +8 -0
- data/golden/game_of_life/schema.kumi +33 -0
- data/golden/hash_keys/expected/ast.txt +29 -0
- data/golden/hash_keys/expected/input_plan.txt +2 -0
- data/golden/hash_keys/expected/lir_00_unoptimized.txt +18 -0
- data/golden/hash_keys/expected/lir_01_hoist_scalar_references.txt +18 -0
- data/golden/hash_keys/expected/lir_02_inlined.txt +18 -0
- data/golden/hash_keys/expected/lir_03_cse.txt +18 -0
- data/golden/hash_keys/expected/lir_04_1_loop_fusion.txt +18 -0
- data/golden/hash_keys/expected/lir_04_loop_invcm.txt +18 -0
- data/golden/hash_keys/expected/lir_06_const_prop.txt +18 -0
- data/golden/hash_keys/expected/nast.txt +46 -0
- data/golden/hash_keys/expected/schema_javascript.mjs +34 -0
- data/golden/hash_keys/expected/schema_ruby.rb +61 -0
- data/golden/hash_keys/expected/snast.txt +46 -0
- data/golden/hash_keys/expected.json +20 -0
- data/golden/hash_keys/input.json +4 -0
- data/golden/hash_keys/schema.kumi +14 -0
- data/golden/hash_value/expected/ast.txt +37 -0
- data/golden/hash_value/expected/input_plan.txt +7 -0
- data/golden/hash_value/expected/lir_00_unoptimized.txt +30 -0
- data/golden/hash_value/expected/lir_01_hoist_scalar_references.txt +30 -0
- data/golden/hash_value/expected/lir_02_inlined.txt +36 -0
- data/golden/hash_value/expected/lir_03_cse.txt +33 -0
- data/golden/hash_value/expected/lir_04_1_loop_fusion.txt +33 -0
- data/golden/hash_value/expected/lir_04_loop_invcm.txt +33 -0
- data/golden/hash_value/expected/lir_06_const_prop.txt +33 -0
- data/golden/hash_value/expected/nast.txt +25 -0
- data/golden/hash_value/expected/schema_javascript.mjs +46 -0
- data/golden/hash_value/expected/schema_ruby.rb +75 -0
- data/golden/hash_value/expected/snast.txt +25 -0
- data/golden/hash_value/expected.json +19 -0
- data/golden/hash_value/input.json +12 -0
- data/golden/hash_value/schema.kumi +19 -0
- data/golden/hierarchical_complex/expected/ast.txt +85 -0
- data/golden/hierarchical_complex/expected/input_plan.txt +23 -0
- data/golden/hierarchical_complex/expected/lir_00_unoptimized.txt +87 -0
- data/golden/hierarchical_complex/expected/lir_01_hoist_scalar_references.txt +87 -0
- data/golden/hierarchical_complex/expected/lir_02_inlined.txt +115 -0
- data/golden/hierarchical_complex/expected/lir_03_cse.txt +89 -0
- data/golden/hierarchical_complex/expected/lir_04_1_loop_fusion.txt +89 -0
- data/golden/hierarchical_complex/expected/lir_04_loop_invcm.txt +89 -0
- data/golden/hierarchical_complex/expected/lir_06_const_prop.txt +89 -0
- data/golden/hierarchical_complex/expected/nast.txt +49 -0
- data/golden/hierarchical_complex/expected/schema_javascript.mjs +121 -0
- data/golden/hierarchical_complex/expected/schema_ruby.rb +151 -0
- data/golden/hierarchical_complex/expected/snast.txt +49 -0
- data/golden/hierarchical_complex/expected.json +34 -0
- data/golden/hierarchical_complex/input.json +26 -0
- data/golden/hierarchical_complex/schema.kumi +38 -0
- data/golden/input_reference/expected/ast.txt +46 -0
- data/golden/input_reference/expected/input_plan.txt +15 -0
- data/golden/input_reference/expected/lir_00_unoptimized.txt +39 -0
- data/golden/input_reference/expected/lir_01_hoist_scalar_references.txt +39 -0
- data/golden/input_reference/expected/lir_02_inlined.txt +39 -0
- data/golden/input_reference/expected/lir_03_cse.txt +39 -0
- data/golden/input_reference/expected/lir_04_1_loop_fusion.txt +39 -0
- data/golden/input_reference/expected/lir_04_loop_invcm.txt +39 -0
- data/golden/input_reference/expected/lir_06_const_prop.txt +39 -0
- data/golden/input_reference/expected/nast.txt +21 -0
- data/golden/input_reference/expected/schema_javascript.mjs +45 -0
- data/golden/input_reference/expected/schema_ruby.rb +74 -0
- data/golden/input_reference/expected/snast.txt +21 -0
- data/golden/input_reference/expected.json +7 -0
- data/golden/input_reference/input.json +11 -0
- data/golden/input_reference/schema.kumi +22 -0
- data/golden/interleaved_fusion/expected/ast.txt +51 -0
- data/golden/interleaved_fusion/expected/input_plan.txt +13 -0
- data/golden/interleaved_fusion/expected/lir_00_unoptimized.txt +53 -0
- data/golden/interleaved_fusion/expected/lir_01_hoist_scalar_references.txt +53 -0
- data/golden/interleaved_fusion/expected/lir_02_inlined.txt +89 -0
- data/golden/interleaved_fusion/expected/lir_03_cse.txt +77 -0
- data/golden/interleaved_fusion/expected/lir_04_1_loop_fusion.txt +77 -0
- data/golden/interleaved_fusion/expected/lir_04_loop_invcm.txt +77 -0
- data/golden/interleaved_fusion/expected/lir_06_const_prop.txt +77 -0
- data/golden/interleaved_fusion/expected/nast.txt +41 -0
- data/golden/interleaved_fusion/expected/schema_javascript.mjs +86 -0
- data/golden/interleaved_fusion/expected/schema_ruby.rb +122 -0
- data/golden/interleaved_fusion/expected/snast.txt +41 -0
- data/golden/interleaved_fusion/expected.json +37 -0
- data/golden/interleaved_fusion/input.json +26 -0
- data/golden/interleaved_fusion/schema.kumi +57 -0
- data/golden/let_inline/expected/ast.txt +33 -0
- data/golden/let_inline/expected/input_plan.txt +2 -0
- data/golden/let_inline/expected/lir_00_unoptimized.txt +26 -0
- data/golden/let_inline/expected/lir_01_hoist_scalar_references.txt +26 -0
- data/golden/let_inline/expected/lir_02_inlined.txt +36 -0
- data/golden/let_inline/expected/lir_03_cse.txt +30 -0
- data/golden/let_inline/expected/lir_04_1_loop_fusion.txt +30 -0
- data/golden/let_inline/expected/lir_04_loop_invcm.txt +30 -0
- data/golden/let_inline/expected/lir_06_const_prop.txt +30 -0
- data/golden/let_inline/expected/nast.txt +26 -0
- data/golden/let_inline/expected/schema_javascript.mjs +11 -0
- data/golden/let_inline/expected/schema_ruby.rb +37 -0
- data/golden/let_inline/expected/snast.txt +26 -0
- data/golden/let_inline/expected.json +1 -0
- data/golden/let_inline/input.json +1 -0
- data/golden/let_inline/schema.kumi +11 -0
- data/golden/loop_fusion/expected/ast.txt +44 -0
- data/golden/loop_fusion/expected/input_plan.txt +13 -0
- data/golden/loop_fusion/expected/lir_00_unoptimized.txt +43 -0
- data/golden/loop_fusion/expected/lir_01_hoist_scalar_references.txt +43 -0
- data/golden/loop_fusion/expected/lir_02_inlined.txt +62 -0
- data/golden/loop_fusion/expected/lir_03_cse.txt +57 -0
- data/golden/loop_fusion/expected/lir_04_1_loop_fusion.txt +57 -0
- data/golden/loop_fusion/expected/lir_04_loop_invcm.txt +57 -0
- data/golden/loop_fusion/expected/lir_06_const_prop.txt +57 -0
- data/golden/loop_fusion/expected/nast.txt +32 -0
- data/golden/loop_fusion/expected/schema_javascript.mjs +64 -0
- data/golden/loop_fusion/expected/schema_ruby.rb +97 -0
- data/golden/loop_fusion/expected/snast.txt +32 -0
- data/golden/loop_fusion/expected.json +30 -0
- data/golden/loop_fusion/input.json +28 -0
- data/golden/loop_fusion/schema.kumi +32 -0
- data/golden/min_reduce_scope/expected/ast.txt +49 -0
- data/golden/min_reduce_scope/expected/input_plan.txt +9 -0
- data/golden/min_reduce_scope/expected/lir_00_unoptimized.txt +59 -0
- data/golden/min_reduce_scope/expected/lir_01_hoist_scalar_references.txt +59 -0
- data/golden/min_reduce_scope/expected/lir_02_inlined.txt +63 -0
- data/golden/min_reduce_scope/expected/lir_03_cse.txt +60 -0
- data/golden/min_reduce_scope/expected/lir_04_1_loop_fusion.txt +60 -0
- data/golden/min_reduce_scope/expected/lir_04_loop_invcm.txt +60 -0
- data/golden/min_reduce_scope/expected/lir_06_const_prop.txt +60 -0
- data/golden/min_reduce_scope/expected/nast.txt +29 -0
- data/golden/min_reduce_scope/expected/schema_javascript.mjs +66 -0
- data/golden/min_reduce_scope/expected/schema_ruby.rb +99 -0
- data/golden/min_reduce_scope/expected/snast.txt +29 -0
- data/golden/min_reduce_scope/expected.json +9 -0
- data/golden/min_reduce_scope/input.json +18 -0
- data/golden/min_reduce_scope/schema.kumi +25 -0
- data/golden/mixed_dimensions/expected/ast.txt +54 -0
- data/golden/mixed_dimensions/expected/input_plan.txt +15 -0
- data/golden/mixed_dimensions/expected/lir_00_unoptimized.txt +42 -0
- data/golden/mixed_dimensions/expected/lir_01_hoist_scalar_references.txt +42 -0
- data/golden/mixed_dimensions/expected/lir_02_inlined.txt +48 -0
- data/golden/mixed_dimensions/expected/lir_03_cse.txt +48 -0
- data/golden/mixed_dimensions/expected/lir_04_1_loop_fusion.txt +48 -0
- data/golden/mixed_dimensions/expected/lir_04_loop_invcm.txt +48 -0
- data/golden/mixed_dimensions/expected/lir_06_const_prop.txt +48 -0
- data/golden/mixed_dimensions/expected/nast.txt +22 -0
- data/golden/mixed_dimensions/expected/schema_javascript.mjs +53 -0
- data/golden/mixed_dimensions/expected/schema_ruby.rb +84 -0
- data/golden/mixed_dimensions/expected/snast.txt +22 -0
- data/golden/mixed_dimensions/expected.json +6 -0
- data/golden/mixed_dimensions/input.json +22 -0
- data/golden/mixed_dimensions/schema.kumi +35 -0
- data/golden/multirank_hoisting/expected/ast.txt +72 -0
- data/golden/multirank_hoisting/expected/input_plan.txt +18 -0
- data/golden/multirank_hoisting/expected/lir_00_unoptimized.txt +75 -0
- data/golden/multirank_hoisting/expected/lir_01_hoist_scalar_references.txt +75 -0
- data/golden/multirank_hoisting/expected/lir_02_inlined.txt +126 -0
- data/golden/multirank_hoisting/expected/lir_03_cse.txt +109 -0
- data/golden/multirank_hoisting/expected/lir_04_1_loop_fusion.txt +109 -0
- data/golden/multirank_hoisting/expected/lir_04_loop_invcm.txt +109 -0
- data/golden/multirank_hoisting/expected/lir_06_const_prop.txt +109 -0
- data/golden/multirank_hoisting/expected/nast.txt +39 -0
- data/golden/multirank_hoisting/expected/schema_javascript.mjs +128 -0
- data/golden/multirank_hoisting/expected/schema_ruby.rb +162 -0
- data/golden/multirank_hoisting/expected/snast.txt +39 -0
- data/golden/multirank_hoisting/expected.json +15 -0
- data/golden/multirank_hoisting/input.json +19 -0
- data/golden/multirank_hoisting/schema.kumi +38 -0
- data/golden/nested_hash/expected/ast.txt +22 -0
- data/golden/nested_hash/expected/input_plan.txt +5 -0
- data/golden/nested_hash/expected/lir_00_unoptimized.txt +10 -0
- data/golden/nested_hash/expected/lir_01_hoist_scalar_references.txt +10 -0
- data/golden/nested_hash/expected/lir_02_inlined.txt +10 -0
- data/golden/nested_hash/expected/lir_03_cse.txt +10 -0
- data/golden/nested_hash/expected/lir_04_1_loop_fusion.txt +10 -0
- data/golden/nested_hash/expected/lir_04_loop_invcm.txt +10 -0
- data/golden/nested_hash/expected/lir_06_const_prop.txt +10 -0
- data/golden/nested_hash/expected/nast.txt +8 -0
- data/golden/nested_hash/expected/schema_javascript.mjs +9 -0
- data/golden/nested_hash/expected/schema_ruby.rb +35 -0
- data/golden/nested_hash/expected/snast.txt +8 -0
- data/golden/nested_hash/expected.json +3 -0
- data/golden/nested_hash/input.json +7 -0
- data/golden/nested_hash/schema.kumi +11 -0
- data/golden/reduction_broadcast/expected/ast.txt +49 -0
- data/golden/reduction_broadcast/expected/input_plan.txt +13 -0
- data/golden/reduction_broadcast/expected/lir_00_unoptimized.txt +49 -0
- data/golden/reduction_broadcast/expected/lir_01_hoist_scalar_references.txt +49 -0
- data/golden/reduction_broadcast/expected/lir_02_inlined.txt +80 -0
- data/golden/reduction_broadcast/expected/lir_03_cse.txt +68 -0
- data/golden/reduction_broadcast/expected/lir_04_1_loop_fusion.txt +68 -0
- data/golden/reduction_broadcast/expected/lir_04_loop_invcm.txt +68 -0
- data/golden/reduction_broadcast/expected/lir_06_const_prop.txt +68 -0
- data/golden/reduction_broadcast/expected/nast.txt +24 -0
- data/golden/reduction_broadcast/expected/schema_javascript.mjs +74 -0
- data/golden/reduction_broadcast/expected/schema_ruby.rb +110 -0
- data/golden/reduction_broadcast/expected/snast.txt +24 -0
- data/golden/reduction_broadcast/expected.json +25 -0
- data/golden/reduction_broadcast/input.json +19 -0
- data/golden/reduction_broadcast/schema.kumi +34 -0
- data/golden/roll/expected/ast.txt +36 -0
- data/golden/roll/expected/input_plan.txt +3 -0
- data/golden/roll/expected/lir_00_unoptimized.txt +56 -0
- data/golden/roll/expected/lir_01_hoist_scalar_references.txt +56 -0
- data/golden/roll/expected/lir_02_inlined.txt +56 -0
- data/golden/roll/expected/lir_03_cse.txt +55 -0
- data/golden/roll/expected/lir_04_1_loop_fusion.txt +55 -0
- data/golden/roll/expected/lir_04_loop_invcm.txt +55 -0
- data/golden/roll/expected/lir_06_const_prop.txt +55 -0
- data/golden/roll/expected/nast.txt +26 -0
- data/golden/roll/expected/schema_javascript.mjs +65 -0
- data/golden/roll/expected/schema_ruby.rb +95 -0
- data/golden/roll/expected/snast.txt +26 -0
- data/golden/roll/expected.json +6 -0
- data/golden/roll/input.json +1 -0
- data/golden/roll/schema.kumi +13 -0
- data/golden/shift/expected/ast.txt +48 -0
- data/golden/shift/expected/input_plan.txt +3 -0
- data/golden/shift/expected/lir_00_unoptimized.txt +96 -0
- data/golden/shift/expected/lir_01_hoist_scalar_references.txt +96 -0
- data/golden/shift/expected/lir_02_inlined.txt +96 -0
- data/golden/shift/expected/lir_03_cse.txt +90 -0
- data/golden/shift/expected/lir_04_1_loop_fusion.txt +90 -0
- data/golden/shift/expected/lir_04_loop_invcm.txt +90 -0
- data/golden/shift/expected/lir_06_const_prop.txt +90 -0
- data/golden/shift/expected/nast.txt +38 -0
- data/golden/shift/expected/schema_javascript.mjs +106 -0
- data/golden/shift/expected/schema_ruby.rb +138 -0
- data/golden/shift/expected/snast.txt +38 -0
- data/golden/shift/expected.json +8 -0
- data/golden/shift/input.json +1 -0
- data/golden/shift/schema.kumi +15 -0
- data/golden/shift_2d/expected/ast.txt +88 -0
- data/golden/shift_2d/expected/input_plan.txt +5 -0
- data/golden/shift_2d/expected/lir_00_unoptimized.txt +274 -0
- data/golden/shift_2d/expected/lir_01_hoist_scalar_references.txt +274 -0
- data/golden/shift_2d/expected/lir_02_inlined.txt +274 -0
- data/golden/shift_2d/expected/lir_03_cse.txt +262 -0
- data/golden/shift_2d/expected/lir_04_1_loop_fusion.txt +262 -0
- data/golden/shift_2d/expected/lir_04_loop_invcm.txt +262 -0
- data/golden/shift_2d/expected/lir_06_const_prop.txt +262 -0
- data/golden/shift_2d/expected/nast.txt +74 -0
- data/golden/shift_2d/expected/schema_javascript.mjs +320 -0
- data/golden/shift_2d/expected/schema_ruby.rb +358 -0
- data/golden/shift_2d/expected/snast.txt +74 -0
- data/golden/shift_2d/expected.json +15 -0
- data/golden/shift_2d/input.json +14 -0
- data/golden/shift_2d/schema.kumi +25 -0
- data/golden/simple_math/expected/ast.txt +40 -0
- data/golden/simple_math/expected/input_plan.txt +2 -0
- data/golden/simple_math/expected/lir_00_unoptimized.txt +31 -0
- data/golden/simple_math/expected/lir_01_hoist_scalar_references.txt +31 -0
- data/golden/simple_math/expected/lir_02_inlined.txt +31 -0
- data/golden/simple_math/expected/lir_03_cse.txt +31 -0
- data/golden/simple_math/expected/lir_04_1_loop_fusion.txt +31 -0
- data/golden/simple_math/expected/lir_04_loop_invcm.txt +31 -0
- data/golden/simple_math/expected/lir_06_const_prop.txt +31 -0
- data/golden/simple_math/expected/nast.txt +33 -0
- data/golden/simple_math/expected/schema_javascript.mjs +33 -0
- data/golden/simple_math/expected/schema_ruby.rb +59 -0
- data/golden/simple_math/expected/snast.txt +33 -0
- data/golden/simple_math/expected.json +1 -0
- data/golden/simple_math/input.json +4 -0
- data/golden/simple_math/schema.kumi +2 -1
- data/golden/streaming_basics/expected/ast.txt +64 -0
- data/golden/streaming_basics/expected/input_plan.txt +8 -0
- data/golden/streaming_basics/expected/lir_00_unoptimized.txt +73 -0
- data/golden/streaming_basics/expected/lir_01_hoist_scalar_references.txt +73 -0
- data/golden/streaming_basics/expected/lir_02_inlined.txt +100 -0
- data/golden/streaming_basics/expected/lir_03_cse.txt +84 -0
- data/golden/streaming_basics/expected/lir_04_1_loop_fusion.txt +84 -0
- data/golden/streaming_basics/expected/lir_04_loop_invcm.txt +84 -0
- data/golden/streaming_basics/expected/lir_06_const_prop.txt +84 -0
- data/golden/streaming_basics/expected/nast.txt +48 -0
- data/golden/streaming_basics/expected/schema_javascript.mjs +94 -0
- data/golden/streaming_basics/expected/schema_ruby.rb +127 -0
- data/golden/streaming_basics/expected/snast.txt +48 -0
- data/golden/streaming_basics/expected.json +10 -0
- data/golden/streaming_basics/input.json +8 -0
- data/golden/streaming_basics/schema.kumi +24 -0
- data/golden/tuples/expected/ast.txt +48 -0
- data/golden/tuples/expected/input_plan.txt +1 -0
- data/golden/tuples/expected/lir_00_unoptimized.txt +40 -0
- data/golden/tuples/expected/lir_01_hoist_scalar_references.txt +40 -0
- data/golden/tuples/expected/lir_02_inlined.txt +48 -0
- data/golden/tuples/expected/lir_03_cse.txt +48 -0
- data/golden/tuples/expected/lir_04_1_loop_fusion.txt +48 -0
- data/golden/tuples/expected/lir_04_loop_invcm.txt +48 -0
- data/golden/tuples/expected/lir_06_const_prop.txt +48 -0
- data/golden/tuples/expected/nast.txt +42 -0
- data/golden/tuples/expected/schema_javascript.mjs +51 -0
- data/golden/tuples/expected/schema_ruby.rb +77 -0
- data/golden/tuples/expected/snast.txt +42 -0
- data/golden/tuples/expected.json +7 -0
- data/golden/tuples/input.json +3 -0
- data/golden/tuples/schema.kumi +11 -0
- data/golden/tuples_and_arrays/expected/ast.txt +44 -0
- data/golden/tuples_and_arrays/expected/input_plan.txt +7 -0
- data/golden/tuples_and_arrays/expected/lir_00_unoptimized.txt +41 -0
- data/golden/tuples_and_arrays/expected/lir_01_hoist_scalar_references.txt +41 -0
- data/golden/tuples_and_arrays/expected/lir_02_inlined.txt +62 -0
- data/golden/tuples_and_arrays/expected/lir_03_cse.txt +51 -0
- data/golden/tuples_and_arrays/expected/lir_04_1_loop_fusion.txt +51 -0
- data/golden/tuples_and_arrays/expected/lir_04_loop_invcm.txt +51 -0
- data/golden/tuples_and_arrays/expected/lir_06_const_prop.txt +51 -0
- data/golden/tuples_and_arrays/expected/nast.txt +28 -0
- data/golden/tuples_and_arrays/expected/schema_javascript.mjs +58 -0
- data/golden/tuples_and_arrays/expected/schema_ruby.rb +88 -0
- data/golden/tuples_and_arrays/expected/snast.txt +28 -0
- data/golden/tuples_and_arrays/expected.json +18 -0
- data/golden/tuples_and_arrays/input.json +7 -0
- data/golden/tuples_and_arrays/schema.kumi +38 -0
- data/golden/with_constants/expected/ast.txt +28 -0
- data/golden/with_constants/expected/input_plan.txt +2 -0
- data/golden/with_constants/expected/lir_00_unoptimized.txt +17 -0
- data/golden/with_constants/expected/lir_01_hoist_scalar_references.txt +17 -0
- data/golden/with_constants/expected/lir_02_inlined.txt +17 -0
- data/golden/with_constants/expected/lir_03_cse.txt +17 -0
- data/golden/with_constants/expected/lir_04_1_loop_fusion.txt +17 -0
- data/golden/with_constants/expected/lir_04_loop_invcm.txt +17 -0
- data/golden/with_constants/expected/lir_06_const_prop.txt +17 -0
- data/golden/with_constants/expected/nast.txt +21 -0
- data/golden/with_constants/expected/schema_javascript.mjs +18 -0
- data/golden/with_constants/expected/schema_ruby.rb +44 -0
- data/golden/with_constants/expected/snast.txt +15 -0
- data/golden/with_constants/schema.kumi +10 -0
- data/lib/kumi/analyzer.rb +76 -24
- data/lib/kumi/configuration.rb +60 -0
- data/lib/kumi/core/analyzer/binder.rb +121 -0
- data/lib/kumi/core/analyzer/checkpoint.rb +15 -9
- data/lib/kumi/core/analyzer/constant_evaluator.rb +32 -37
- data/lib/kumi/core/analyzer/constant_folding_helpers.rb +55 -0
- data/lib/kumi/core/analyzer/debug.rb +14 -16
- data/lib/kumi/core/analyzer/fn_aliases.rb +46 -0
- data/lib/kumi/core/analyzer/folder.rb +94 -0
- data/lib/kumi/core/analyzer/macro_expander.rb +69 -0
- data/lib/kumi/core/analyzer/passes/assemble_irv2_pass.rb +130 -0
- data/lib/kumi/core/analyzer/passes/attach_anchors_pass.rb +71 -0
- data/lib/kumi/core/analyzer/passes/attach_terminal_info_pass.rb +181 -0
- data/lib/kumi/core/analyzer/passes/codegen/js/declaration_emitter.rb +317 -0
- data/lib/kumi/core/analyzer/passes/codegen/js/emitter.rb +75 -0
- data/lib/kumi/core/analyzer/passes/codegen/js/output_buffer.rb +103 -0
- data/lib/kumi/core/analyzer/passes/codegen/js_pass.rb +27 -0
- data/lib/kumi/core/analyzer/passes/codegen/ruby/declaration_emitter.rb +321 -0
- data/lib/kumi/core/analyzer/passes/codegen/ruby/emitter.rb +85 -0
- data/lib/kumi/core/analyzer/passes/codegen/ruby/output_buffer.rb +111 -0
- data/lib/kumi/core/analyzer/passes/codegen/ruby_pass.rb +32 -0
- data/lib/kumi/core/analyzer/passes/constant_folding_pass.rb +33 -0
- data/lib/kumi/core/analyzer/passes/contract_checker_pass.rb +220 -0
- data/lib/kumi/core/analyzer/passes/dependency_resolver.rb +5 -6
- data/lib/kumi/core/analyzer/passes/input_access_planner_pass.rb +7 -3
- data/lib/kumi/core/analyzer/passes/input_collector.rb +74 -122
- data/lib/kumi/core/analyzer/passes/input_form_schema_pass.rb +43 -0
- data/lib/kumi/core/analyzer/passes/ir_dependency_pass.rb +1 -1
- data/lib/kumi/core/analyzer/passes/ir_execution_schedule_pass.rb +1 -1
- data/lib/kumi/core/analyzer/passes/join_reduce_planning_pass.rb +21 -23
- data/lib/kumi/core/analyzer/passes/lir/constant_propagation_pass.rb +84 -0
- data/lib/kumi/core/analyzer/passes/lir/dead_code_elimination_pass.rb +93 -0
- data/lib/kumi/core/analyzer/passes/lir/hoist_scalar_references_pass.rb +115 -0
- data/lib/kumi/core/analyzer/passes/lir/inline_declarations_pass.rb +274 -0
- data/lib/kumi/core/analyzer/passes/lir/instruction_scheduling_pass.rb +198 -0
- data/lib/kumi/core/analyzer/passes/lir/kernel_binding_pass.rb +30 -0
- data/lib/kumi/core/analyzer/passes/lir/local_cse_pass.rb +121 -0
- data/lib/kumi/core/analyzer/passes/lir/loop_fusion_pass.rb +156 -0
- data/lib/kumi/core/analyzer/passes/lir/loop_invariant_code_motion_pass.rb +148 -0
- data/lib/kumi/core/analyzer/passes/lir/lower_pass.rb +407 -0
- data/lib/kumi/core/analyzer/passes/lir/stencil_emitter.rb +243 -0
- data/lib/kumi/core/analyzer/passes/lir/validation_pass.rb +83 -0
- data/lib/kumi/core/analyzer/passes/load_input_cse.rb +17 -16
- data/lib/kumi/core/analyzer/passes/lower_to_ir_pass.rb +4 -2
- data/lib/kumi/core/analyzer/passes/lower_to_irv2_pass.rb +197 -0
- data/lib/kumi/core/analyzer/passes/name_indexer.rb +4 -1
- data/lib/kumi/core/analyzer/passes/nast_dimensional_analyzer_pass.rb +237 -0
- data/lib/kumi/core/analyzer/passes/normalize_to_nast_pass.rb +156 -0
- data/lib/kumi/core/analyzer/passes/output_schema_pass.rb +38 -0
- data/lib/kumi/core/analyzer/passes/pass_base.rb +30 -4
- data/lib/kumi/core/analyzer/passes/precompute_access_paths_pass.rb +93 -0
- data/lib/kumi/core/analyzer/passes/scope_resolution_pass.rb +33 -30
- data/lib/kumi/core/analyzer/passes/semantic_constraint_validator.rb +5 -26
- data/lib/kumi/core/analyzer/passes/snast_pass.rb +229 -0
- data/lib/kumi/core/analyzer/passes/toposorter.rb +1 -0
- data/lib/kumi/core/analyzer/passes/type_checker.rb +13 -0
- data/lib/kumi/core/analyzer/passes/type_inferencer_pass.rb +14 -16
- data/lib/kumi/core/analyzer/passes/unsat_detector.rb +2 -1
- data/lib/kumi/core/analyzer/plans.rb +12 -0
- data/lib/kumi/core/analyzer/state_serde.rb +4 -4
- data/lib/kumi/core/analyzer/structs/access_plan.rb +2 -2
- data/lib/kumi/core/analyzer/unsat_constant_evaluator.rb +59 -0
- data/lib/kumi/core/compiler/access_codegen.rb +1 -1
- data/lib/kumi/core/compiler/access_emit/base.rb +9 -5
- data/lib/kumi/core/compiler/access_emit/each_indexed.rb +10 -3
- data/lib/kumi/core/compiler/access_emit/materialize.rb +12 -5
- data/lib/kumi/core/compiler/access_emit/ravel.rb +10 -3
- data/lib/kumi/core/compiler/access_emit/read.rb +4 -1
- data/lib/kumi/core/compiler/access_planner.rb +42 -4
- data/lib/kumi/core/compiler/access_planner_v2.rb +164 -0
- data/lib/kumi/core/explain.rb +18 -11
- data/lib/kumi/core/functions/loader.rb +47 -0
- data/lib/kumi/core/functions/model.rb +10 -0
- data/lib/kumi/core/functions/type_rules.rb +108 -0
- data/lib/kumi/core/ir/execution_engine/interpreter.rb +1 -1
- data/lib/kumi/core/ir/execution_engine/profiler.rb +107 -97
- data/lib/kumi/core/ir.rb +6 -2
- data/lib/kumi/core/irv2/builder.rb +48 -0
- data/lib/kumi/core/irv2/declaration.rb +28 -0
- data/lib/kumi/core/irv2/module.rb +108 -0
- data/lib/kumi/core/irv2/value.rb +28 -0
- data/lib/kumi/core/lir/analyze.rb +64 -0
- data/lib/kumi/core/lir/build.rb +363 -0
- data/lib/kumi/core/lir/emit.rb +62 -0
- data/lib/kumi/core/lir/structs/instruction.rb +44 -0
- data/lib/kumi/core/lir/structs/literal.rb +14 -0
- data/lib/kumi/core/lir/structs/stamp.rb +13 -0
- data/lib/kumi/core/lir/support/error.rb +9 -0
- data/lib/kumi/core/lir/support/ids.rb +34 -0
- data/lib/kumi/core/lir/validate.rb +74 -0
- data/lib/kumi/core/lir.rb +34 -0
- data/lib/kumi/core/nast.rb +216 -0
- data/lib/kumi/core/ruby_parser/dsl.rb +2 -2
- data/lib/kumi/core/ruby_parser/dsl_cascade_builder.rb +1 -1
- data/lib/kumi/core/ruby_parser/expression_converter.rb +10 -0
- data/lib/kumi/core/ruby_parser/input_builder.rb +16 -17
- data/lib/kumi/core/ruby_parser/schema_builder.rb +36 -10
- data/lib/kumi/core/ruby_parser/sugar.rb +64 -0
- data/lib/kumi/core/types/builder.rb +2 -2
- data/lib/kumi/core/types/normalizer.rb +2 -0
- data/lib/kumi/core/types/validator.rb +10 -3
- data/lib/kumi/core/types.rb +7 -0
- data/lib/kumi/dev/codegen.rb +194 -0
- data/lib/kumi/dev/golden/generator.rb +105 -0
- data/lib/kumi/dev/golden/reporter.rb +160 -0
- data/lib/kumi/dev/golden/representation.rb +45 -0
- data/lib/kumi/dev/golden/result.rb +98 -0
- data/lib/kumi/dev/golden/runtime_test.rb +93 -0
- data/lib/kumi/dev/golden/suite.rb +131 -0
- data/lib/kumi/dev/golden/verifier.rb +76 -0
- data/lib/kumi/dev/golden.rb +75 -0
- data/lib/kumi/dev/ir.rb +4 -4
- data/lib/kumi/dev/parse.rb +1 -1
- data/lib/kumi/dev/pretty_printer.rb +229 -0
- data/lib/kumi/dev/printer/irv2_formatter.rb +163 -0
- data/lib/kumi/dev/printer/width_aware_json.rb +44 -0
- data/lib/kumi/dev/profile_aggregator.rb +36 -38
- data/lib/kumi/dev/profile_runner.rb +19 -23
- data/lib/kumi/dev/runner.rb +12 -22
- data/lib/kumi/dev/support/kumi_runner.mjs +39 -0
- data/lib/kumi/dev.rb +3 -3
- data/lib/kumi/frontends/ruby.rb +12 -12
- data/lib/kumi/frontends/text.rb +26 -21
- data/lib/kumi/frontends.rb +6 -8
- data/lib/kumi/kernel_registry.rb +59 -0
- data/lib/kumi/pack/builder.rb +229 -0
- data/lib/kumi/pack.rb +15 -0
- data/lib/kumi/registry_v2/loader.rb +81 -0
- data/lib/kumi/registry_v2.rb +118 -0
- data/lib/kumi/schema.rb +83 -43
- data/lib/kumi/support/diff.rb +3 -2
- data/lib/kumi/support/ir_render.rb +1 -1
- data/lib/kumi/support/lir_printer.rb +143 -0
- data/lib/kumi/support/nast_printer.rb +93 -0
- data/lib/kumi/support/s_expression_printer.rb +5 -4
- data/lib/kumi/support/snast_printer.rb +111 -0
- data/lib/kumi/syntax/call_expression.rb +1 -1
- data/lib/kumi/syntax/input_declaration.rb +2 -2
- data/lib/kumi/syntax/node.rb +4 -12
- data/lib/kumi/syntax/root.rb +10 -0
- data/lib/kumi/syntax/trait_declaration.rb +1 -0
- data/lib/kumi/syntax/value_declaration.rb +1 -0
- data/lib/kumi/version.rb +1 -1
- data/lib/kumi.rb +46 -4
- metadata +571 -54
- data/docs/AST.md +0 -133
- data/docs/DSL.md +0 -154
- data/docs/FUNCTIONS.md +0 -176
- data/docs/VECTOR_SEMANTICS.md +0 -286
- data/docs/compiler_design_principles.md +0 -86
- data/docs/dev/analyzer-debug.md +0 -52
- data/docs/dev/parse-command.md +0 -64
- data/docs/dev/vm-profiling.md +0 -95
- data/docs/development/README.md +0 -120
- data/docs/development/error-reporting.md +0 -361
- data/docs/features/README.md +0 -58
- data/docs/features/analysis-type-inference.md +0 -42
- data/docs/features/analysis-unsat-detection.md +0 -71
- data/docs/features/hierarchical-broadcasting.md +0 -415
- data/docs/features/input-declaration-system.md +0 -58
- data/docs/features/performance.md +0 -14
- data/docs/features/s-expression-printer.md +0 -77
- data/docs/schema_metadata/broadcasts.md +0 -53
- data/docs/schema_metadata/cascades.md +0 -45
- data/docs/schema_metadata/declarations.md +0 -54
- data/docs/schema_metadata/dependencies.md +0 -57
- data/docs/schema_metadata/evaluation_order.md +0 -29
- data/docs/schema_metadata/examples.md +0 -95
- data/docs/schema_metadata/inferred_types.md +0 -46
- data/docs/schema_metadata/inputs.md +0 -86
- data/docs/schema_metadata.md +0 -108
- data/golden/mixed_nesting/schema.kumi +0 -42
- data/lib/kumi/core/function_registry/collection_functions.rb +0 -298
- data/lib/kumi/core/function_registry/comparison_functions.rb +0 -33
- data/lib/kumi/core/function_registry/conditional_functions.rb +0 -48
- data/lib/kumi/core/function_registry/function_builder.rb +0 -184
- data/lib/kumi/core/function_registry/logical_functions.rb +0 -214
- data/lib/kumi/core/function_registry/math_functions.rb +0 -74
- data/lib/kumi/core/function_registry/stat_functions.rb +0 -156
- data/lib/kumi/core/function_registry/string_functions.rb +0 -57
- data/lib/kumi/core/function_registry/type_functions.rb +0 -53
- data/lib/kumi/core/function_registry.rb +0 -176
- data/lib/kumi/registry.rb +0 -32
- data/lib/kumi/runtime/executable.rb +0 -135
- data/lib/kumi/runtime/run.rb +0 -105
- data/performance_results.txt +0 -63
- data/scripts/analyze_broadcast_methods.rb +0 -68
- data/scripts/analyze_cascade_methods.rb +0 -74
- data/scripts/check_broadcasting_coverage.rb +0 -51
- data/scripts/find_dead_code.rb +0 -114
- data/scripts/generate_function_docs.rb +0 -71
- data/scripts/test_mixed_nesting_performance.rb +0 -206
@@ -0,0 +1,130 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kumi
|
4
|
+
module Core
|
5
|
+
module Analyzer
|
6
|
+
module Passes
|
7
|
+
# Assembles the final IRv2 JSON structure from analyzer state
|
8
|
+
#
|
9
|
+
# Input: state[:irv2_module], state[:ir_input_plans]
|
10
|
+
# Output: state[:irv2] (complete JSON structure ready for serialization)
|
11
|
+
class AssembleIRV2Pass < PassBase
|
12
|
+
def run(errors)
|
13
|
+
irv2_module = get_state(:irv2_module, required: true)
|
14
|
+
input_plans = get_state(:ir_input_plans, required: true)
|
15
|
+
|
16
|
+
irv2_structure = build_irv2_structure(irv2_module, input_plans, errors)
|
17
|
+
debug "Assembled IRv2 structure with #{irv2_structure['declarations'].size} declarations"
|
18
|
+
|
19
|
+
state.with(:irv2, irv2_structure.freeze)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def build_irv2_structure(irv2_module, input_plans, _errors)
|
25
|
+
{
|
26
|
+
"version" => IR_SCHEMA_VERSION,
|
27
|
+
"module" => determine_module_name(irv2_module),
|
28
|
+
"declarations" => build_declarations(irv2_module.declarations),
|
29
|
+
"analysis" => build_analysis_section(input_plans, irv2_module.metadata)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def determine_module_name(irv2_module)
|
34
|
+
irv2_module.metadata.dig("module_name") || "schema_module"
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_declarations(declarations_hash)
|
38
|
+
result = {}
|
39
|
+
declarations_hash.each do |name, declaration|
|
40
|
+
result[name.to_s] = build_declaration_structure(declaration)
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_declaration_structure(declaration)
|
46
|
+
{
|
47
|
+
"name" => declaration.name.to_s,
|
48
|
+
"parameters" => build_parameters(declaration.parameters),
|
49
|
+
"operations" => build_operations(declaration.operations, declaration.name),
|
50
|
+
"result" => declaration.result.id
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_parameters(parameters)
|
55
|
+
parameters.map do |param|
|
56
|
+
case param[:type]
|
57
|
+
when :input
|
58
|
+
{ "kind" => "input", "path" => param[:source] }
|
59
|
+
when :dependency
|
60
|
+
{ "kind" => "dependency", "source" => param[:source] }
|
61
|
+
else
|
62
|
+
param
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_operations(operations, _current_decl_name)
|
68
|
+
operations.map do |op|
|
69
|
+
h = {
|
70
|
+
"id" => op.id,
|
71
|
+
"op" => op.op.to_s,
|
72
|
+
"args" => build_operation_args(op.args)
|
73
|
+
}
|
74
|
+
h["stamp"] = op.stamp if op.stamp
|
75
|
+
h["elem_stamps"] = op.elem_stamps if op.elem_stamps
|
76
|
+
attrs = build_operation_attrs(op.attrs)
|
77
|
+
h["attrs"] = attrs unless attrs.empty?
|
78
|
+
h
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def build_operation_args(args)
|
83
|
+
args.map { |arg| arg.respond_to?(:id) ? arg.id : arg }
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_operation_attrs(attrs)
|
87
|
+
attrs.each_with_object({}) { |(k, v), h| h[k.to_s] = v }
|
88
|
+
end
|
89
|
+
|
90
|
+
def build_analysis_section(input_plans, _metadata)
|
91
|
+
{
|
92
|
+
"defaults" => {
|
93
|
+
"key_policy" => "indifferent",
|
94
|
+
"on_missing" => "error"
|
95
|
+
},
|
96
|
+
"inputs" => build_canonical_inputs(input_plans)
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
def build_canonical_inputs(input_plans)
|
101
|
+
input_plans.map do |plan|
|
102
|
+
result = {
|
103
|
+
"path_fqn" => plan.path_fqn,
|
104
|
+
"axes" => plan.axes.map(&:to_s),
|
105
|
+
"dtype" => plan.dtype.to_s,
|
106
|
+
"navigation_steps" => plan.navigation_steps,
|
107
|
+
"key_policy" => plan.key_policy.to_s,
|
108
|
+
"on_missing" => plan.missing_policy.to_s
|
109
|
+
}
|
110
|
+
stringify_deep(result)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def stringify_deep(obj)
|
115
|
+
case obj
|
116
|
+
when Hash
|
117
|
+
obj.each_with_object({}) { |(k, v), h| h[k.to_s] = stringify_deep(v) }
|
118
|
+
when Array
|
119
|
+
obj.map { |v| stringify_deep(v) }
|
120
|
+
when Symbol
|
121
|
+
obj.to_s
|
122
|
+
else
|
123
|
+
obj
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kumi
|
4
|
+
module Core
|
5
|
+
module Analyzer
|
6
|
+
module Passes
|
7
|
+
class AttachAnchorsPass < PassBase
|
8
|
+
NAST = Kumi::Core::NAST
|
9
|
+
|
10
|
+
def run(_errors)
|
11
|
+
@snast = get_state(:snast_module, required: true)
|
12
|
+
|
13
|
+
out = {}
|
14
|
+
@snast.decls.each do |name, decl|
|
15
|
+
out[name] ||= {}
|
16
|
+
|
17
|
+
wanted = axes_of(decl)
|
18
|
+
wanted = axes_of(decl.body) if wanted.empty?
|
19
|
+
|
20
|
+
# No anchors needed for scalars (rank-0)
|
21
|
+
next if wanted.empty?
|
22
|
+
|
23
|
+
out[name][wanted] = pick_anchor_fqn(decl.body, wanted)
|
24
|
+
end
|
25
|
+
|
26
|
+
state.with(:anchor_by_decl, out.freeze)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def pick_anchor_fqn(node, wanted_axes)
|
32
|
+
return nil if Array(wanted_axes).empty?
|
33
|
+
|
34
|
+
found = nil
|
35
|
+
walk = lambda do |x|
|
36
|
+
case x
|
37
|
+
when NAST::InputRef
|
38
|
+
ax = axes_of(x)
|
39
|
+
found ||= ir_fqn(x) if prefix?(wanted_axes, ax)
|
40
|
+
when NAST::Ref
|
41
|
+
decl = @snast.decls.fetch(x.name) { raise "unknown declaration #{x.name}" }
|
42
|
+
walk.call(decl.body)
|
43
|
+
when NAST::Select
|
44
|
+
walk.call(x.cond)
|
45
|
+
walk.call(x.on_true)
|
46
|
+
walk.call(x.on_false)
|
47
|
+
when NAST::Reduce, NAST::Fold
|
48
|
+
walk.call(x.arg)
|
49
|
+
when NAST::Call, NAST::Tuple
|
50
|
+
x.args.each { walk.call(_1) }
|
51
|
+
when NAST::Hash
|
52
|
+
x.pairs.each { walk.call(_1) }
|
53
|
+
when NAST::Pair
|
54
|
+
walk.call(x.value)
|
55
|
+
when NAST::IndexRef
|
56
|
+
found ||= x.input_fqn
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
walk.call(node)
|
61
|
+
found or raise "no anchor for axes #{wanted_axes.inspect}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def axes_of(n) = Array(n.meta[:stamp]&.dig(:axes))
|
65
|
+
def prefix?(pre, full) = pre.each_with_index.all? { |tok, i| full[i] == tok }
|
66
|
+
def ir_fqn(n) = n.instance_variable_get(:@fqn) || n.path.join(".")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Kumi
|
6
|
+
module Core
|
7
|
+
module Analyzer
|
8
|
+
module Passes
|
9
|
+
# AttachTerminalInfoPass with debug tracing
|
10
|
+
class AttachTerminalInfoPass < PassBase
|
11
|
+
NAST = Kumi::Core::NAST
|
12
|
+
|
13
|
+
def run(_errors)
|
14
|
+
@dbg = ENV["KUMI_DEBUG_TERMINAL"] == "1"
|
15
|
+
plans = get_state(:input_table, required: true) # Array<InputPlan>
|
16
|
+
by_fqn = plans.each_with_object({}) { |p, h| h[p.path_fqn.to_s] = p }
|
17
|
+
mod = get_state(:snast_module, required: true)
|
18
|
+
annotate!(mod, by_fqn)
|
19
|
+
state
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def annotate!(node, by_fqn)
|
25
|
+
case node
|
26
|
+
when NAST::Module
|
27
|
+
node.decls.each_value { |d| annotate!(d, by_fqn) }
|
28
|
+
when NAST::Declaration
|
29
|
+
annotate!(node.body, by_fqn)
|
30
|
+
when NAST::InputRef
|
31
|
+
annotate_input_ref!(node, by_fqn)
|
32
|
+
when NAST::Tuple, NAST::Call
|
33
|
+
node.args.each { |a| annotate!(a, by_fqn) }
|
34
|
+
when NAST::Hash
|
35
|
+
node.pairs.each { |p| annotate!(p.value, by_fqn) }
|
36
|
+
when NAST::Pair
|
37
|
+
annotate!(node.value, by_fqn)
|
38
|
+
when NAST::Select
|
39
|
+
annotate!(node.cond, by_fqn)
|
40
|
+
annotate!(node.on_true, by_fqn)
|
41
|
+
annotate!(node.on_false, by_fqn)
|
42
|
+
when NAST::Reduce, NAST::Fold
|
43
|
+
annotate!(node.arg, by_fqn)
|
44
|
+
when NAST::IndexRef
|
45
|
+
# no-op
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def annotate_input_ref!(node, by_fqn)
|
50
|
+
plan = by_fqn.fetch(node.path_fqn.to_s) { raise KeyError, "No InputPlan for #{node.path_fqn.inspect}" }
|
51
|
+
steps = normalize_steps(plan.navigation_steps) # do not mutate original
|
52
|
+
|
53
|
+
# Compute from original steps
|
54
|
+
base_sym, full_chain = detect_base_and_full_chain(steps)
|
55
|
+
tail = tail_after_last_loop(steps)
|
56
|
+
element_terminal = tail.any? { |s| s[:kind] == "element_access" }
|
57
|
+
|
58
|
+
# Compute key_chain based on context
|
59
|
+
key_chain =
|
60
|
+
if !element_terminal && tail.empty? && !full_chain.empty?
|
61
|
+
# Non-element-terminal array reference (e.g., fn(:array_size, input.x))
|
62
|
+
# Use full property chain to load from root
|
63
|
+
full_chain
|
64
|
+
else
|
65
|
+
# Element access or other cases: collect from tail
|
66
|
+
collect_tail_props(tail)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Attach
|
70
|
+
node.instance_variable_set(:@fqn, plan.path_fqn.to_s)
|
71
|
+
node.instance_variable_set(:@base_sym, base_sym)
|
72
|
+
node.instance_variable_set(:@base_is_root, base_sym == :__root)
|
73
|
+
node.instance_variable_set(:@full_chain, full_chain)
|
74
|
+
node.instance_variable_set(:@key_chain, key_chain)
|
75
|
+
node.instance_variable_set(:@element_terminal, element_terminal)
|
76
|
+
|
77
|
+
return unless debug_enabled?
|
78
|
+
|
79
|
+
dbg_dump(
|
80
|
+
title: "InputRef #{plan.path_fqn}",
|
81
|
+
open_axis: plan.respond_to?(:open_axis) ? plan.open_axis : nil,
|
82
|
+
steps: steps,
|
83
|
+
tail: tail,
|
84
|
+
base_sym: base_sym,
|
85
|
+
full_chain: full_chain,
|
86
|
+
key_chain: key_chain,
|
87
|
+
element_terminal: element_terminal
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
# ---------- helpers ----------
|
92
|
+
|
93
|
+
def normalize_steps(raw)
|
94
|
+
Array(raw).map do |s|
|
95
|
+
{ kind: (s[:kind] || s["kind"]).to_s, key: s[:key] || s["key"] }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def array_loop?(s) = s && s[:kind] == "array_loop"
|
100
|
+
def property_access?(s) = s && s[:kind] == "property_access"
|
101
|
+
def element_access?(s) = s && s[:kind] == "element_access"
|
102
|
+
|
103
|
+
# base + full property chain
|
104
|
+
def detect_base_and_full_chain(steps)
|
105
|
+
return [:__root, []] if steps.empty?
|
106
|
+
|
107
|
+
first_loop_idx = steps.index { |s| array_loop?(s) } || steps.length
|
108
|
+
pre = steps[0...first_loop_idx]
|
109
|
+
|
110
|
+
base_sym =
|
111
|
+
if property_access?(pre.first)
|
112
|
+
pre.first[:key].to_sym
|
113
|
+
else
|
114
|
+
:__root
|
115
|
+
end
|
116
|
+
|
117
|
+
props = steps.select { |s| property_access?(s) }.map { |s| s[:key].to_sym }
|
118
|
+
props = [base_sym] + props if base_sym != :__root && props.first != base_sym
|
119
|
+
[base_sym, props]
|
120
|
+
end
|
121
|
+
|
122
|
+
# steps strictly after the last array_loop; if none, the entire steps
|
123
|
+
def tail_after_last_loop(steps)
|
124
|
+
last_loop_idx = steps.rindex { |s| array_loop?(s) } || -1
|
125
|
+
steps[(last_loop_idx + 1)..-1] || []
|
126
|
+
end
|
127
|
+
|
128
|
+
# property_access keys in tail:
|
129
|
+
# - if an element_access exists, collect properties AFTER the first element_access
|
130
|
+
# - otherwise collect all property_access in tail
|
131
|
+
def collect_tail_props(tail)
|
132
|
+
elem_idx = tail.index { |s| s && s[:kind] == "element_access" }
|
133
|
+
|
134
|
+
range =
|
135
|
+
if elem_idx
|
136
|
+
(elem_idx + 1)..-1 # after the element access
|
137
|
+
else
|
138
|
+
0..-1 # no element access, take all
|
139
|
+
end
|
140
|
+
|
141
|
+
tail[range].to_a
|
142
|
+
.select { |s| s[:kind] == "property_access" }
|
143
|
+
.map { |s| s[:key].to_sym }
|
144
|
+
end
|
145
|
+
|
146
|
+
# pretty trace
|
147
|
+
def dbg_dump(title:, open_axis:, steps:, tail:, base_sym:, full_chain:, key_chain:, element_terminal:)
|
148
|
+
puts "[AttachTerminalInfo] #{title}"
|
149
|
+
puts " open_axis: #{open_axis.inspect}"
|
150
|
+
puts " steps:"
|
151
|
+
steps.each_with_index { |s, i| puts " #{i}: #{fmt_step(s)}" }
|
152
|
+
puts " tail:"
|
153
|
+
tail.each_with_index { |s, i| puts " #{i}: #{fmt_step(s)}" }
|
154
|
+
puts " base_sym: #{base_sym.inspect}"
|
155
|
+
puts " full_chain: #{full_chain.inspect}"
|
156
|
+
puts " key_chain: #{key_chain.inspect}"
|
157
|
+
puts " element_terminal: #{element_terminal}"
|
158
|
+
# quick sanity checks
|
159
|
+
if key_chain.empty? && steps.any? { |s| property_access?(s) } && !element_terminal
|
160
|
+
puts " WARN: tail lost property keys? check last array_loop split"
|
161
|
+
end
|
162
|
+
if element_terminal && !steps.any? { |s| element_access?(s) }
|
163
|
+
puts " WARN: element_terminal=true but no element_access in steps"
|
164
|
+
end
|
165
|
+
puts
|
166
|
+
end
|
167
|
+
|
168
|
+
def fmt_step(s)
|
169
|
+
k = s[:kind]
|
170
|
+
case k
|
171
|
+
when "property_access" then "property_access(#{s[:key].inspect})"
|
172
|
+
when "element_access" then "element_access"
|
173
|
+
when "array_loop" then "array_loop(#{s[:key].inspect})"
|
174
|
+
else "#{k}(#{s[:key].inspect})"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "forwardable"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module Kumi
|
7
|
+
module Core
|
8
|
+
module Analyzer
|
9
|
+
module Passes
|
10
|
+
module Codegen
|
11
|
+
module Js
|
12
|
+
class DeclarationEmitter
|
13
|
+
extend Forwardable
|
14
|
+
|
15
|
+
def_delegators :@buffer, :write, :indent!, :dedent!, :last_line, :rewrite_line
|
16
|
+
|
17
|
+
def initialize(buffer, binds, kernels)
|
18
|
+
@buffer = buffer
|
19
|
+
@binds = binds
|
20
|
+
@kernels = kernels
|
21
|
+
@stack = []
|
22
|
+
@out_containers = []
|
23
|
+
@aliases = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
def emit(name, ops)
|
27
|
+
@ops = ops
|
28
|
+
@yield_depth = find_yield_depth(ops)
|
29
|
+
has_yield = @ops.any? { |op| op.opcode == :Yield }
|
30
|
+
@aliases.clear
|
31
|
+
|
32
|
+
# Exported, pure function per declaration
|
33
|
+
write "export function _#{name}(input) {"
|
34
|
+
indent!
|
35
|
+
|
36
|
+
write "let out = [];" if has_yield && @yield_depth.positive?
|
37
|
+
@out_containers = ["out"]
|
38
|
+
|
39
|
+
@ops.each_with_index { |ins, i| emit_ins(ins, i) }
|
40
|
+
|
41
|
+
write "return out;" if has_yield && @yield_depth.positive?
|
42
|
+
|
43
|
+
dedent!
|
44
|
+
write "}\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def emit_ins(ins, i)
|
50
|
+
emitter_method = "emit_#{ins.opcode.to_s.downcase}"
|
51
|
+
if respond_to?(emitter_method, true)
|
52
|
+
send(emitter_method, ins, i)
|
53
|
+
else
|
54
|
+
warn "No JS emitter found for opcode: #{ins.opcode}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# --- Loop and Yield Logic ---
|
59
|
+
|
60
|
+
def emit_loopstart(ins, i)
|
61
|
+
coll = areg(ins.inputs.first)
|
62
|
+
el = to_local(ins.attributes[:as_element])
|
63
|
+
ix = to_local(ins.attributes[:as_index])
|
64
|
+
|
65
|
+
write "#{coll}.forEach((#{el}, #{ix}) => {"
|
66
|
+
indent!
|
67
|
+
@stack.push({ el: el, ix: ix })
|
68
|
+
|
69
|
+
return unless loop_contain_yield?(i) && @stack.length < @yield_depth
|
70
|
+
|
71
|
+
container = "out_#{@stack.length}"
|
72
|
+
@out_containers.push(container)
|
73
|
+
write "let #{container} = [];"
|
74
|
+
end
|
75
|
+
|
76
|
+
def emit_loopend(ins, i)
|
77
|
+
start_index = find_loop_start_for_end(i)
|
78
|
+
is_yield_container_loop = @stack.length < @yield_depth && loop_contain_yield?(start_index)
|
79
|
+
|
80
|
+
if is_yield_container_loop
|
81
|
+
child = @out_containers.pop
|
82
|
+
parent = @out_containers.last
|
83
|
+
write "#{parent}.push(#{child});"
|
84
|
+
end
|
85
|
+
|
86
|
+
@stack.pop
|
87
|
+
dedent!
|
88
|
+
write "});"
|
89
|
+
end
|
90
|
+
|
91
|
+
def emit_yield(ins, i)
|
92
|
+
v = operands_for(ins).first
|
93
|
+
current_depth = calculate_depth_at(i)
|
94
|
+
|
95
|
+
if current_depth.zero?
|
96
|
+
# Optimization: if the last statement was the assignment,
|
97
|
+
# we can just make it a return statement.
|
98
|
+
if last_line&.strip&.match?(/^let #{v} = /)
|
99
|
+
new_line = last_line.sub("let #{v} = ", "return ")
|
100
|
+
rewrite_line(new_line.strip.chomp(";"))
|
101
|
+
else
|
102
|
+
write "return #{v};"
|
103
|
+
end
|
104
|
+
else
|
105
|
+
write "#{@out_containers.last}.push(#{v});"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def emit_kernelcall(ins, _i)
|
110
|
+
kernel = kernel_for(ins.result_register)
|
111
|
+
args = operands_for(ins)
|
112
|
+
|
113
|
+
if (template = kernel[:attrs]["js_inline"] || kernel[:attrs]["inline"])
|
114
|
+
inlined_code = _inline_kernel(template, args)
|
115
|
+
if template.start_with?("=") || template.include?("$0")
|
116
|
+
write "let #{vreg(ins)} #{inlined_code};"
|
117
|
+
else
|
118
|
+
write "#{vreg(ins)} #{inlined_code};"
|
119
|
+
end
|
120
|
+
else
|
121
|
+
fn_name = kernel_method_name(kernel[:fn_id])
|
122
|
+
write "let #{vreg(ins)} = #{fn_name}(#{args.join(', ')});"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def emit_fold(ins, _i)
|
127
|
+
kernel = kernel_for(ins.result_register)
|
128
|
+
args = operands_for(ins)
|
129
|
+
|
130
|
+
if (template = kernel[:attrs]["js_fold_inline"] || kernel[:attrs]["fold_inline"])
|
131
|
+
inlined_code = _inline_kernel(template, args)
|
132
|
+
write "let #{vreg(ins)} #{inlined_code};"
|
133
|
+
else
|
134
|
+
raise "JS Emitter: Can't fold - no 'js_fold_inline' or 'fold_inline' template defined for kernel #{kernel[:fn_id]}"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def emit_accumulate(ins, _i)
|
139
|
+
kernel = kernel_for(ins.result_register)
|
140
|
+
args = [vreg(ins), operands_for(ins).first]
|
141
|
+
|
142
|
+
if kernel[:attrs]["first_element"]
|
143
|
+
write "if (#{args[0]} === null || #{args[0]} === undefined) {"
|
144
|
+
indent!
|
145
|
+
write "#{args[0]} = #{args[1]};"
|
146
|
+
dedent!
|
147
|
+
write "} else {"
|
148
|
+
indent!
|
149
|
+
end
|
150
|
+
|
151
|
+
if (template = kernel[:attrs]["js_inline"] || kernel[:attrs]["inline"])
|
152
|
+
inlined_code = _inline_kernel(template, args)
|
153
|
+
write "#{args[0]} #{inlined_code};"
|
154
|
+
else
|
155
|
+
fn_name = kernel_method_name(kernel[:fn_id])
|
156
|
+
write "#{args[0]} = #{fn_name}(#{args.join(', ')});"
|
157
|
+
end
|
158
|
+
|
159
|
+
return unless kernel[:attrs]["first_element"]
|
160
|
+
|
161
|
+
dedent!
|
162
|
+
write "}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def emit_constant(ins, _i)
|
166
|
+
write "const #{vreg(ins)} = #{lit(ins.immediates.first)};"
|
167
|
+
end
|
168
|
+
|
169
|
+
def emit_loadinput(ins, _i)
|
170
|
+
key = imm_key(ins)
|
171
|
+
write "let #{vreg(ins)} = input[#{key.to_json}];"
|
172
|
+
end
|
173
|
+
|
174
|
+
def emit_loadfield(ins, _i)
|
175
|
+
obj = areg(ins.inputs.first)
|
176
|
+
key = imm_key(ins)
|
177
|
+
|
178
|
+
write "let #{vreg(ins)} = #{obj}[#{key.to_json}];"
|
179
|
+
end
|
180
|
+
|
181
|
+
def emit_select(ins, _i)
|
182
|
+
c, t, f = operands_for(ins)
|
183
|
+
write "let #{vreg(ins)} = #{c} ? #{t} : #{f};"
|
184
|
+
end
|
185
|
+
|
186
|
+
def emit_declareaccumulator(ins, _i)
|
187
|
+
kernel = kernel_for(ins.result_register)
|
188
|
+
identity_attrs = kernel[:attrs]["identity"]
|
189
|
+
identity = identity_attrs.is_a?(Hash) ? identity_attrs["integer"] || identity_attrs["any"] : identity_attrs
|
190
|
+
write "let #{vreg(ins)} = #{identity.to_json};"
|
191
|
+
end
|
192
|
+
|
193
|
+
def emit_loadaccumulator(ins, _i)
|
194
|
+
acc_reg = ins.inputs.first or raise "No accumulator bound"
|
195
|
+
# This is a no-op for codegen; it creates an alias that `areg` will resolve.
|
196
|
+
@aliases[vreg(ins)] = areg(acc_reg)
|
197
|
+
end
|
198
|
+
|
199
|
+
def emit_loaddeclaration(ins, _i)
|
200
|
+
write "let #{vreg(ins)} = _$#{ins.immediates.first.value}(input);"
|
201
|
+
end
|
202
|
+
|
203
|
+
def emit_maketuple(ins, _i)
|
204
|
+
elements = operands_for(ins).join(", ")
|
205
|
+
write "let #{vreg(ins)} = [#{elements}];"
|
206
|
+
end
|
207
|
+
|
208
|
+
def emit_makeobject(ins, _i)
|
209
|
+
values, keys = operands_for(ins, split: true)
|
210
|
+
write "let #{vreg(ins)} = {"
|
211
|
+
indent!
|
212
|
+
keys.each_with_index do |key, idx|
|
213
|
+
postfix = idx == keys.size - 1 ? "" : ","
|
214
|
+
# Keys in JS objects from variables don't need quotes if they are valid identifiers
|
215
|
+
write "#{key}: #{values[idx]}#{postfix}"
|
216
|
+
end
|
217
|
+
dedent!
|
218
|
+
write "};"
|
219
|
+
end
|
220
|
+
|
221
|
+
def emit_length(ins, _i)
|
222
|
+
arr = ins.inputs[0]
|
223
|
+
write "let #{vreg(ins)} = #{arr}.length;"
|
224
|
+
end
|
225
|
+
|
226
|
+
def emit_gather(ins, _)
|
227
|
+
arr = ins.inputs[0]
|
228
|
+
idx = ins.inputs[1]
|
229
|
+
write "let #{vreg(ins)} = #{arr}[#{idx}];"
|
230
|
+
end
|
231
|
+
|
232
|
+
def find_matching_loop_end(start_index)
|
233
|
+
depth = 1; (start_index + 1...@ops.length).each do |i|
|
234
|
+
op = @ops[i].opcode
|
235
|
+
depth += 1 if op == :LoopStart
|
236
|
+
depth -= 1 if op == :LoopEnd
|
237
|
+
return i if depth.zero?
|
238
|
+
end
|
239
|
+
raise "Unbalanced LoopStart at index #{start_index}"
|
240
|
+
end
|
241
|
+
|
242
|
+
def find_loop_start_for_end(end_index)
|
243
|
+
depth = 1; (end_index - 1).downto(0) do |i|
|
244
|
+
op = @ops[i].opcode
|
245
|
+
depth += 1 if op == :LoopEnd
|
246
|
+
depth -= 1 if op == :LoopStart
|
247
|
+
return i if depth.zero?
|
248
|
+
end
|
249
|
+
raise "Unbalanced LoopEnd at index #{end_index}"
|
250
|
+
end
|
251
|
+
|
252
|
+
def loop_contain_yield?(loop_start_index)
|
253
|
+
end_index = find_matching_loop_end(loop_start_index)
|
254
|
+
@ops[(loop_start_index + 1)...end_index].any? { |ins| ins.opcode == :Yield }
|
255
|
+
end
|
256
|
+
|
257
|
+
def calculate_depth_at(index)
|
258
|
+
depth = 0
|
259
|
+
@ops[0...index].each do |op|
|
260
|
+
depth += 1 if op.opcode == :LoopStart
|
261
|
+
depth -= 1 if op.opcode == :LoopEnd
|
262
|
+
end
|
263
|
+
depth
|
264
|
+
end
|
265
|
+
|
266
|
+
def find_yield_depth(ops)
|
267
|
+
yield_op_index = ops.index { _1.opcode == :Yield }
|
268
|
+
return 0 unless yield_op_index
|
269
|
+
|
270
|
+
calculate_depth_at(yield_op_index)
|
271
|
+
end
|
272
|
+
|
273
|
+
def operands_for(ins, split: false)
|
274
|
+
immediates = Array(ins.immediates).map { |imm| lit(imm) }
|
275
|
+
inputs = Array(ins.inputs).map do |input|
|
276
|
+
if input == :__immediate_placeholder__
|
277
|
+
immediates.shift
|
278
|
+
else
|
279
|
+
areg(input)
|
280
|
+
end
|
281
|
+
end
|
282
|
+
return [inputs, immediates] if split
|
283
|
+
|
284
|
+
inputs + immediates
|
285
|
+
end
|
286
|
+
|
287
|
+
def lit(l) = l.value.to_json
|
288
|
+
def imm_key(ins) = ins.immediates&.first&.value
|
289
|
+
def to_local(sym) = sym.to_s.delete("%:")
|
290
|
+
|
291
|
+
def areg(r)
|
292
|
+
return "null" if r.nil?
|
293
|
+
|
294
|
+
resolved = to_local(r)
|
295
|
+
# Follow the alias chain to find the original source register.
|
296
|
+
while (aliased_to = @aliases[resolved])
|
297
|
+
resolved = aliased_to
|
298
|
+
end
|
299
|
+
resolved
|
300
|
+
end
|
301
|
+
|
302
|
+
def vreg(ins) = to_local(ins.result_register)
|
303
|
+
def kernel_method_name(fn_id) = "__#{fn_id.tr('.', '_')}"
|
304
|
+
def kernel_for(reg) = @kernels.fetch(@binds.fetch(reg).fn_id)
|
305
|
+
|
306
|
+
def _inline_kernel(template, args)
|
307
|
+
inlined = template.dup
|
308
|
+
args.each_with_index { |arg, i| inlined.gsub!("$#{i}", arg.to_s) }
|
309
|
+
inlined
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|