kumi 0.0.8 → 0.0.10

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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CLAUDE.md +28 -44
  3. data/README.md +188 -108
  4. data/docs/AST.md +8 -1
  5. data/docs/FUNCTIONS.md +52 -8
  6. data/docs/compiler_design_principles.md +86 -0
  7. data/docs/features/README.md +22 -2
  8. data/docs/features/hierarchical-broadcasting.md +349 -0
  9. data/docs/features/javascript-transpiler.md +148 -0
  10. data/docs/features/performance.md +1 -3
  11. data/docs/features/s-expression-printer.md +77 -0
  12. data/docs/schema_metadata.md +7 -7
  13. data/examples/game_of_life.rb +2 -4
  14. data/lib/kumi/analyzer.rb +0 -2
  15. data/lib/kumi/compiler.rb +6 -275
  16. data/lib/kumi/core/analyzer/passes/broadcast_detector.rb +600 -42
  17. data/lib/kumi/core/analyzer/passes/input_collector.rb +4 -2
  18. data/lib/kumi/core/analyzer/passes/semantic_constraint_validator.rb +27 -0
  19. data/lib/kumi/core/analyzer/passes/type_checker.rb +6 -2
  20. data/lib/kumi/core/analyzer/passes/unsat_detector.rb +90 -46
  21. data/lib/kumi/core/cascade_executor_builder.rb +132 -0
  22. data/lib/kumi/core/compiler/expression_compiler.rb +146 -0
  23. data/lib/kumi/core/compiler/function_invoker.rb +55 -0
  24. data/lib/kumi/core/compiler/path_traversal_compiler.rb +158 -0
  25. data/lib/kumi/core/compiler/reference_compiler.rb +46 -0
  26. data/lib/kumi/core/compiler_base.rb +137 -0
  27. data/lib/kumi/core/explain.rb +2 -2
  28. data/lib/kumi/core/function_registry/collection_functions.rb +86 -3
  29. data/lib/kumi/core/function_registry/function_builder.rb +5 -3
  30. data/lib/kumi/core/function_registry/logical_functions.rb +171 -1
  31. data/lib/kumi/core/function_registry/stat_functions.rb +156 -0
  32. data/lib/kumi/core/function_registry.rb +32 -10
  33. data/lib/kumi/core/nested_structure_utils.rb +78 -0
  34. data/lib/kumi/core/ruby_parser/dsl_cascade_builder.rb +2 -2
  35. data/lib/kumi/core/ruby_parser/input_builder.rb +61 -8
  36. data/lib/kumi/core/schema_instance.rb +4 -0
  37. data/lib/kumi/core/vectorized_function_builder.rb +88 -0
  38. data/lib/kumi/errors.rb +2 -0
  39. data/lib/kumi/js/compiler.rb +878 -0
  40. data/lib/kumi/js/function_registry.rb +333 -0
  41. data/lib/kumi/js.rb +23 -0
  42. data/lib/kumi/registry.rb +61 -1
  43. data/lib/kumi/schema.rb +1 -1
  44. data/lib/kumi/support/s_expression_printer.rb +162 -0
  45. data/lib/kumi/syntax/array_expression.rb +6 -6
  46. data/lib/kumi/syntax/call_expression.rb +4 -4
  47. data/lib/kumi/syntax/cascade_expression.rb +4 -4
  48. data/lib/kumi/syntax/case_expression.rb +4 -4
  49. data/lib/kumi/syntax/declaration_reference.rb +4 -4
  50. data/lib/kumi/syntax/hash_expression.rb +4 -4
  51. data/lib/kumi/syntax/input_declaration.rb +6 -5
  52. data/lib/kumi/syntax/input_element_reference.rb +5 -5
  53. data/lib/kumi/syntax/input_reference.rb +5 -5
  54. data/lib/kumi/syntax/literal.rb +4 -4
  55. data/lib/kumi/syntax/node.rb +34 -34
  56. data/lib/kumi/syntax/root.rb +6 -6
  57. data/lib/kumi/syntax/trait_declaration.rb +4 -4
  58. data/lib/kumi/syntax/value_declaration.rb +4 -4
  59. data/lib/kumi/version.rb +1 -1
  60. data/lib/kumi.rb +1 -1
  61. data/scripts/analyze_broadcast_methods.rb +68 -0
  62. data/scripts/analyze_cascade_methods.rb +74 -0
  63. data/scripts/check_broadcasting_coverage.rb +51 -0
  64. data/scripts/find_dead_code.rb +114 -0
  65. metadata +22 -4
  66. data/docs/features/array-broadcasting.md +0 -170
  67. data/lib/kumi/cli.rb +0 -449
  68. data/lib/kumi/core/vectorization_metadata.rb +0 -110
@@ -1,110 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kumi
4
- module Core
5
- # Metadata system for vectorization detection and handling
6
- module VectorizationMetadata
7
- # Tracks which declarations are arrays with children (vectorizable)
8
- class ArrayDeclarationTracker
9
- def initialize
10
- @array_declarations = {}
11
- end
12
-
13
- def register_array(name, children)
14
- @array_declarations[name] = children.map(&:name)
15
- end
16
-
17
- def array_declaration?(name)
18
- @array_declarations.key?(name)
19
- end
20
-
21
- def array_children(name)
22
- @array_declarations[name] || []
23
- end
24
-
25
- def all_arrays
26
- @array_declarations.keys
27
- end
28
- end
29
-
30
- # Detects vectorized operations in expressions
31
- class VectorizationDetector
32
- def initialize(array_tracker)
33
- @array_tracker = array_tracker
34
- end
35
-
36
- # Check if an expression should be vectorized
37
- def vectorized_expression?(expression)
38
- case expression
39
- when Kumi::Syntax::CallExpression
40
- vectorized_call?(expression)
41
- when Kumi::Syntax::InputElementReference
42
- vectorized_element_reference?(expression)
43
- else
44
- false
45
- end
46
- end
47
-
48
- # Check if a function call should be treated as a reducer
49
- def reducer_function?(fn_name, args)
50
- REDUCER_FUNCTIONS.include?(fn_name) &&
51
- args.any? { |arg| vectorized_expression?(arg) }
52
- end
53
-
54
- private
55
-
56
- REDUCER_FUNCTIONS = %i[sum min max size length first last].freeze
57
-
58
- def vectorized_call?(call_expr)
59
- # Arithmetic operations between array elements are vectorized
60
- ARITHMETIC_OPERATIONS.include?(call_expr.fn_name) &&
61
- call_expr.args.any? { |arg| vectorized_expression?(arg) }
62
- end
63
-
64
- def vectorized_element_reference?(elem_ref)
65
- return false unless elem_ref.path.size >= 2
66
-
67
- array_name, _field_name = elem_ref.path
68
- @array_tracker.array_declaration?(array_name)
69
- end
70
-
71
- ARITHMETIC_OPERATIONS = %i[add subtract multiply divide modulo power].freeze
72
- end
73
-
74
- # Metadata about how values should be computed
75
- class ComputationMetadata
76
- attr_reader :vectorized_values, :reducer_values, :scalar_values
77
-
78
- def initialize
79
- @vectorized_values = Set.new
80
- @reducer_values = Set.new
81
- @scalar_values = Set.new
82
- end
83
-
84
- def mark_vectorized(name)
85
- @vectorized_values.add(name)
86
- end
87
-
88
- def mark_reducer(name)
89
- @reducer_values.add(name)
90
- end
91
-
92
- def mark_scalar(name)
93
- @scalar_values.add(name)
94
- end
95
-
96
- def vectorized?(name)
97
- @vectorized_values.include?(name)
98
- end
99
-
100
- def reducer?(name)
101
- @reducer_values.include?(name)
102
- end
103
-
104
- def scalar?(name)
105
- @scalar_values.include?(name)
106
- end
107
- end
108
- end
109
- end
110
- end