kumi 0.0.12 → 0.0.14
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/.rspec +0 -1
- data/BACKLOG.md +34 -0
- data/CHANGELOG.md +15 -0
- data/CLAUDE.md +4 -6
- data/README.md +0 -18
- data/config/functions.yaml +352 -0
- data/docs/dev/analyzer-debug.md +52 -0
- data/docs/dev/parse-command.md +64 -0
- data/docs/functions/analyzer_integration.md +199 -0
- data/docs/functions/signatures.md +171 -0
- data/examples/hash_objects_demo.rb +138 -0
- data/golden/array_operations/schema.kumi +17 -0
- data/golden/cascade_logic/schema.kumi +16 -0
- data/golden/mixed_nesting/schema.kumi +42 -0
- data/golden/simple_math/schema.kumi +10 -0
- data/lib/kumi/analyzer.rb +72 -21
- data/lib/kumi/core/analyzer/checkpoint.rb +72 -0
- data/lib/kumi/core/analyzer/debug.rb +167 -0
- data/lib/kumi/core/analyzer/passes/broadcast_detector.rb +1 -3
- data/lib/kumi/core/analyzer/passes/function_signature_pass.rb +199 -0
- data/lib/kumi/core/analyzer/passes/load_input_cse.rb +120 -0
- data/lib/kumi/core/analyzer/passes/lower_to_ir_pass.rb +99 -151
- data/lib/kumi/core/analyzer/passes/toposorter.rb +37 -1
- data/lib/kumi/core/analyzer/state_serde.rb +64 -0
- data/lib/kumi/core/analyzer/structs/access_plan.rb +12 -10
- data/lib/kumi/core/compiler/access_planner.rb +3 -2
- data/lib/kumi/core/function_registry/collection_functions.rb +3 -1
- data/lib/kumi/core/functions/dimension.rb +98 -0
- data/lib/kumi/core/functions/dtypes.rb +20 -0
- data/lib/kumi/core/functions/errors.rb +11 -0
- data/lib/kumi/core/functions/kernel_adapter.rb +45 -0
- data/lib/kumi/core/functions/loader.rb +119 -0
- data/lib/kumi/core/functions/registry_v2.rb +68 -0
- data/lib/kumi/core/functions/shape.rb +70 -0
- data/lib/kumi/core/functions/signature.rb +122 -0
- data/lib/kumi/core/functions/signature_parser.rb +86 -0
- data/lib/kumi/core/functions/signature_resolver.rb +272 -0
- data/lib/kumi/core/ir/execution_engine/interpreter.rb +98 -7
- data/lib/kumi/core/ir/execution_engine/profiler.rb +202 -0
- data/lib/kumi/core/ir/execution_engine.rb +30 -1
- data/lib/kumi/dev/ir.rb +75 -0
- data/lib/kumi/dev/parse.rb +105 -0
- data/lib/kumi/dev/runner.rb +83 -0
- data/lib/kumi/frontends/ruby.rb +28 -0
- data/lib/kumi/frontends/text.rb +46 -0
- data/lib/kumi/frontends.rb +29 -0
- data/lib/kumi/kernels/ruby/aggregate_core.rb +105 -0
- data/lib/kumi/kernels/ruby/datetime_scalar.rb +21 -0
- data/lib/kumi/kernels/ruby/mask_scalar.rb +15 -0
- data/lib/kumi/kernels/ruby/scalar_core.rb +63 -0
- data/lib/kumi/kernels/ruby/string_scalar.rb +19 -0
- data/lib/kumi/kernels/ruby/vector_struct.rb +39 -0
- data/lib/kumi/runtime/executable.rb +63 -20
- data/lib/kumi/schema.rb +4 -4
- data/lib/kumi/support/diff.rb +22 -0
- data/lib/kumi/support/ir_render.rb +61 -0
- data/lib/kumi/version.rb +1 -1
- data/lib/kumi.rb +2 -0
- data/performance_results.txt +63 -0
- data/scripts/test_mixed_nesting_performance.rb +206 -0
- metadata +45 -5
- data/docs/features/javascript-transpiler.md +0 -148
- data/lib/kumi/js.rb +0 -23
- data/lib/kumi/support/ir_dump.rb +0 -491
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kumi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Muta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-08-
|
11
|
+
date: 2025-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zeitwerk
|
@@ -33,17 +33,21 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".rspec"
|
35
35
|
- ".rubocop.yml"
|
36
|
+
- BACKLOG.md
|
36
37
|
- CHANGELOG.md
|
37
38
|
- CLAUDE.md
|
38
39
|
- LICENSE.txt
|
39
40
|
- README.md
|
40
41
|
- Rakefile
|
42
|
+
- config/functions.yaml
|
41
43
|
- docs/AST.md
|
42
44
|
- docs/DSL.md
|
43
45
|
- docs/FUNCTIONS.md
|
44
46
|
- docs/SYNTAX.md
|
45
47
|
- docs/VECTOR_SEMANTICS.md
|
46
48
|
- docs/compiler_design_principles.md
|
49
|
+
- docs/dev/analyzer-debug.md
|
50
|
+
- docs/dev/parse-command.md
|
47
51
|
- docs/development/README.md
|
48
52
|
- docs/development/error-reporting.md
|
49
53
|
- docs/features/README.md
|
@@ -52,9 +56,10 @@ files:
|
|
52
56
|
- docs/features/analysis-unsat-detection.md
|
53
57
|
- docs/features/hierarchical-broadcasting.md
|
54
58
|
- docs/features/input-declaration-system.md
|
55
|
-
- docs/features/javascript-transpiler.md
|
56
59
|
- docs/features/performance.md
|
57
60
|
- docs/features/s-expression-printer.md
|
61
|
+
- docs/functions/analyzer_integration.md
|
62
|
+
- docs/functions/signatures.md
|
58
63
|
- docs/schema_metadata.md
|
59
64
|
- docs/schema_metadata/broadcasts.md
|
60
65
|
- docs/schema_metadata/cascades.md
|
@@ -67,20 +72,29 @@ files:
|
|
67
72
|
- examples/deep_schema_compilation_and_evaluation_benchmark.rb
|
68
73
|
- examples/federal_tax_calculator_2024.rb
|
69
74
|
- examples/game_of_life.rb
|
75
|
+
- examples/hash_objects_demo.rb
|
70
76
|
- examples/simple_rpg_game.rb
|
71
77
|
- examples/static_analysis_errors.rb
|
72
78
|
- examples/wide_schema_compilation_and_evaluation_benchmark.rb
|
79
|
+
- golden/array_operations/schema.kumi
|
80
|
+
- golden/cascade_logic/schema.kumi
|
81
|
+
- golden/mixed_nesting/schema.kumi
|
82
|
+
- golden/simple_math/schema.kumi
|
73
83
|
- lib/kumi.rb
|
74
84
|
- lib/kumi/analyzer.rb
|
75
85
|
- lib/kumi/compiler.rb
|
76
86
|
- lib/kumi/core/analyzer/analysis_state.rb
|
87
|
+
- lib/kumi/core/analyzer/checkpoint.rb
|
77
88
|
- lib/kumi/core/analyzer/constant_evaluator.rb
|
89
|
+
- lib/kumi/core/analyzer/debug.rb
|
78
90
|
- lib/kumi/core/analyzer/passes/broadcast_detector.rb
|
79
91
|
- lib/kumi/core/analyzer/passes/declaration_validator.rb
|
80
92
|
- lib/kumi/core/analyzer/passes/dependency_resolver.rb
|
93
|
+
- lib/kumi/core/analyzer/passes/function_signature_pass.rb
|
81
94
|
- lib/kumi/core/analyzer/passes/input_access_planner_pass.rb
|
82
95
|
- lib/kumi/core/analyzer/passes/input_collector.rb
|
83
96
|
- lib/kumi/core/analyzer/passes/join_reduce_planning_pass.rb
|
97
|
+
- lib/kumi/core/analyzer/passes/load_input_cse.rb
|
84
98
|
- lib/kumi/core/analyzer/passes/lower_to_ir_pass.rb
|
85
99
|
- lib/kumi/core/analyzer/passes/name_indexer.rb
|
86
100
|
- lib/kumi/core/analyzer/passes/pass_base.rb
|
@@ -93,6 +107,7 @@ files:
|
|
93
107
|
- lib/kumi/core/analyzer/passes/unsat_detector.rb
|
94
108
|
- lib/kumi/core/analyzer/passes/visitor_pass.rb
|
95
109
|
- lib/kumi/core/analyzer/plans.rb
|
110
|
+
- lib/kumi/core/analyzer/state_serde.rb
|
96
111
|
- lib/kumi/core/analyzer/structs/access_plan.rb
|
97
112
|
- lib/kumi/core/analyzer/structs/input_meta.rb
|
98
113
|
- lib/kumi/core/atom_unsat_solver.rb
|
@@ -130,6 +145,16 @@ files:
|
|
130
145
|
- lib/kumi/core/function_registry/stat_functions.rb
|
131
146
|
- lib/kumi/core/function_registry/string_functions.rb
|
132
147
|
- lib/kumi/core/function_registry/type_functions.rb
|
148
|
+
- lib/kumi/core/functions/dimension.rb
|
149
|
+
- lib/kumi/core/functions/dtypes.rb
|
150
|
+
- lib/kumi/core/functions/errors.rb
|
151
|
+
- lib/kumi/core/functions/kernel_adapter.rb
|
152
|
+
- lib/kumi/core/functions/loader.rb
|
153
|
+
- lib/kumi/core/functions/registry_v2.rb
|
154
|
+
- lib/kumi/core/functions/shape.rb
|
155
|
+
- lib/kumi/core/functions/signature.rb
|
156
|
+
- lib/kumi/core/functions/signature_parser.rb
|
157
|
+
- lib/kumi/core/functions/signature_resolver.rb
|
133
158
|
- lib/kumi/core/input/type_matcher.rb
|
134
159
|
- lib/kumi/core/input/validator.rb
|
135
160
|
- lib/kumi/core/input/violation_creator.rb
|
@@ -137,6 +162,7 @@ files:
|
|
137
162
|
- lib/kumi/core/ir/execution_engine.rb
|
138
163
|
- lib/kumi/core/ir/execution_engine/combinators.rb
|
139
164
|
- lib/kumi/core/ir/execution_engine/interpreter.rb
|
165
|
+
- lib/kumi/core/ir/execution_engine/profiler.rb
|
140
166
|
- lib/kumi/core/ir/execution_engine/values.rb
|
141
167
|
- lib/kumi/core/json_schema.rb
|
142
168
|
- lib/kumi/core/json_schema/generator.rb
|
@@ -162,13 +188,25 @@ files:
|
|
162
188
|
- lib/kumi/core/types/inference.rb
|
163
189
|
- lib/kumi/core/types/normalizer.rb
|
164
190
|
- lib/kumi/core/types/validator.rb
|
191
|
+
- lib/kumi/dev/ir.rb
|
192
|
+
- lib/kumi/dev/parse.rb
|
193
|
+
- lib/kumi/dev/runner.rb
|
165
194
|
- lib/kumi/errors.rb
|
166
|
-
- lib/kumi/
|
195
|
+
- lib/kumi/frontends.rb
|
196
|
+
- lib/kumi/frontends/ruby.rb
|
197
|
+
- lib/kumi/frontends/text.rb
|
198
|
+
- lib/kumi/kernels/ruby/aggregate_core.rb
|
199
|
+
- lib/kumi/kernels/ruby/datetime_scalar.rb
|
200
|
+
- lib/kumi/kernels/ruby/mask_scalar.rb
|
201
|
+
- lib/kumi/kernels/ruby/scalar_core.rb
|
202
|
+
- lib/kumi/kernels/ruby/string_scalar.rb
|
203
|
+
- lib/kumi/kernels/ruby/vector_struct.rb
|
167
204
|
- lib/kumi/registry.rb
|
168
205
|
- lib/kumi/runtime/executable.rb
|
169
206
|
- lib/kumi/schema.rb
|
170
207
|
- lib/kumi/schema_metadata.rb
|
171
|
-
- lib/kumi/support/
|
208
|
+
- lib/kumi/support/diff.rb
|
209
|
+
- lib/kumi/support/ir_render.rb
|
172
210
|
- lib/kumi/support/s_expression_printer.rb
|
173
211
|
- lib/kumi/syntax/array_expression.rb
|
174
212
|
- lib/kumi/syntax/call_expression.rb
|
@@ -186,11 +224,13 @@ files:
|
|
186
224
|
- lib/kumi/syntax/trait_declaration.rb
|
187
225
|
- lib/kumi/syntax/value_declaration.rb
|
188
226
|
- lib/kumi/version.rb
|
227
|
+
- performance_results.txt
|
189
228
|
- scripts/analyze_broadcast_methods.rb
|
190
229
|
- scripts/analyze_cascade_methods.rb
|
191
230
|
- scripts/check_broadcasting_coverage.rb
|
192
231
|
- scripts/find_dead_code.rb
|
193
232
|
- scripts/generate_function_docs.rb
|
233
|
+
- scripts/test_mixed_nesting_performance.rb
|
194
234
|
homepage: https://github.com/amuta/kumi
|
195
235
|
licenses:
|
196
236
|
- MIT
|
@@ -1,148 +0,0 @@
|
|
1
|
-
# JavaScript Transpiler
|
2
|
-
|
3
|
-
Transpiles compiled schemas to standalone JavaScript code.
|
4
|
-
|
5
|
-
## Usage
|
6
|
-
|
7
|
-
### Export Schema
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
class TaxCalculator
|
11
|
-
extend Kumi::Schema
|
12
|
-
|
13
|
-
schema do
|
14
|
-
input do
|
15
|
-
float :income
|
16
|
-
string :filing_status
|
17
|
-
end
|
18
|
-
|
19
|
-
trait :single, input.filing_status == "single"
|
20
|
-
|
21
|
-
value :std_deduction do
|
22
|
-
on single, 14_600
|
23
|
-
base 29_200
|
24
|
-
end
|
25
|
-
|
26
|
-
value :taxable_income, fn(:max, [input.income - std_deduction, 0])
|
27
|
-
value :tax_owed, taxable_income * 0.22
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Kumi::Js.export_to_file(TaxCalculator, "tax-calculator.js")
|
32
|
-
```
|
33
|
-
|
34
|
-
### Use in JavaScript
|
35
|
-
|
36
|
-
```javascript
|
37
|
-
const { schema } = require('./tax-calculator.js');
|
38
|
-
|
39
|
-
const taxpayer = {
|
40
|
-
income: 75000,
|
41
|
-
filing_status: "single"
|
42
|
-
};
|
43
|
-
|
44
|
-
const calculator = schema.from(taxpayer);
|
45
|
-
console.log(calculator.fetch('tax_owed'));
|
46
|
-
|
47
|
-
const results = calculator.slice('taxable_income', 'tax_owed');
|
48
|
-
```
|
49
|
-
|
50
|
-
## Export Methods
|
51
|
-
|
52
|
-
### Command Line
|
53
|
-
|
54
|
-
```bash
|
55
|
-
bundle exec kumi --export-js output.js SchemaClass
|
56
|
-
```
|
57
|
-
|
58
|
-
### Programmatic
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
Kumi::Js.export_to_file(MySchema, "schema.js")
|
62
|
-
|
63
|
-
js_code = Kumi::Js.compile(MySchema)
|
64
|
-
File.write("output.js", js_code)
|
65
|
-
```
|
66
|
-
|
67
|
-
## JavaScript API
|
68
|
-
|
69
|
-
### schema.from(input)
|
70
|
-
|
71
|
-
Creates runner instance.
|
72
|
-
|
73
|
-
```javascript
|
74
|
-
const runner = schema.from({ income: 50000, status: "single" });
|
75
|
-
```
|
76
|
-
|
77
|
-
### runner.fetch(key)
|
78
|
-
|
79
|
-
Returns computed value. Results are cached.
|
80
|
-
|
81
|
-
```javascript
|
82
|
-
const tax = runner.fetch('tax_owed');
|
83
|
-
```
|
84
|
-
|
85
|
-
### runner.slice(...keys)
|
86
|
-
|
87
|
-
Returns multiple values.
|
88
|
-
|
89
|
-
```javascript
|
90
|
-
const results = runner.slice('taxable_income', 'tax_owed');
|
91
|
-
// Returns: { taxable_income: 35400, tax_owed: 7788 }
|
92
|
-
```
|
93
|
-
|
94
|
-
### runner.functionsUsed
|
95
|
-
|
96
|
-
Array of functions used by the schema.
|
97
|
-
|
98
|
-
```javascript
|
99
|
-
console.log(runner.functionsUsed); // ["max", "subtract", "multiply"]
|
100
|
-
```
|
101
|
-
|
102
|
-
## Function Optimization
|
103
|
-
|
104
|
-
The transpiler only includes functions actually used by the schema.
|
105
|
-
|
106
|
-
Example schema using 4 functions generates ~3 KB instead of ~8 KB with all 67 functions.
|
107
|
-
|
108
|
-
## Browser Compatibility
|
109
|
-
|
110
|
-
- ES6+ (Chrome 60+, Firefox 55+, Safari 10+)
|
111
|
-
- Modern bundlers (Webpack, Rollup, Vite)
|
112
|
-
- Node.js 12+
|
113
|
-
|
114
|
-
## Limitations
|
115
|
-
|
116
|
-
- No `explain()` method (Ruby only)
|
117
|
-
- Custom Ruby functions need JavaScript equivalents
|
118
|
-
|
119
|
-
## Module Formats
|
120
|
-
|
121
|
-
Generated JavaScript supports:
|
122
|
-
- CommonJS (`require()`)
|
123
|
-
- ES Modules (`import`)
|
124
|
-
- Global variables (browser)
|
125
|
-
|
126
|
-
## Minification
|
127
|
-
|
128
|
-
Use production minifiers like Terser or UglifyJS for smaller bundles.
|
129
|
-
|
130
|
-
## Dual Mode Validation
|
131
|
-
|
132
|
-
Set `KUMI_DUAL_MODE=true` to automatically execute both Ruby and JavaScript versions and validate they produce identical results:
|
133
|
-
|
134
|
-
```bash
|
135
|
-
KUMI_DUAL_MODE=true ruby my_script.rb
|
136
|
-
```
|
137
|
-
|
138
|
-
Every calculation is validated in real-time. Mismatches throw detailed error reports with both results for debugging.
|
139
|
-
|
140
|
-
## Error Handling
|
141
|
-
|
142
|
-
```javascript
|
143
|
-
try {
|
144
|
-
const runner = schema.from({ invalid: "data" });
|
145
|
-
} catch (error) {
|
146
|
-
console.error(error.message);
|
147
|
-
}
|
148
|
-
```
|
data/lib/kumi/js.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Kumi
|
4
|
-
module Js
|
5
|
-
# JavaScript transpiler for Kumi schemas
|
6
|
-
# Extends the existing compiler architecture to output JavaScript instead of Ruby lambdas
|
7
|
-
|
8
|
-
# Export a compiled schema to JavaScript
|
9
|
-
def self.compile(schema_class, **options)
|
10
|
-
syntax_tree = schema_class.__syntax_tree__
|
11
|
-
analyzer_result = schema_class.__analyzer_result__
|
12
|
-
|
13
|
-
compiler = Compiler.new(syntax_tree, analyzer_result)
|
14
|
-
compiler.compile(**options)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Export to JavaScript file
|
18
|
-
def self.export_to_file(schema_class, filename, **options)
|
19
|
-
js_code = compile(schema_class, **options)
|
20
|
-
File.write(filename, js_code)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|