konpeito 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +645 -0
- data/CHANGELOG.md +37 -0
- data/Justfile +107 -0
- data/README.md +143 -43
- data/konpeito.gemspec +3 -2
- data/lib/konpeito/cli/build_command.rb +21 -3
- data/lib/konpeito/cli/completion_command.rb +298 -0
- data/lib/konpeito/cli/deps_command.rb +129 -21
- data/lib/konpeito/cli/fmt_command.rb +24 -132
- data/lib/konpeito/cli/run_command.rb +29 -3
- data/lib/konpeito/cli.rb +45 -14
- data/lib/konpeito/codegen/builtin_methods.rb +16 -0
- data/lib/konpeito/codegen/cruby_backend.rb +76 -6
- data/lib/konpeito/codegen/jvm_generator.rb +100 -9
- data/lib/konpeito/codegen/llvm_generator.rb +907 -195
- data/lib/konpeito/dependency_resolver.rb +32 -9
- data/lib/konpeito/hir/builder.rb +369 -57
- data/lib/konpeito/hir/nodes.rb +25 -5
- data/lib/konpeito/type_checker/rbs_loader.rb +3 -2
- data/lib/konpeito/ui/app.rb +1 -1
- data/lib/konpeito/version.rb +1 -1
- data/lib/konpeito.rb +0 -7
- data/tools/konpeito-asm/src/konpeito/runtime/RubyDispatch.java +32 -0
- metadata +6 -23
- data/lib/konpeito/cli/lsp_command.rb +0 -40
- data/lib/konpeito/formatter/formatter.rb +0 -1214
- data/lib/konpeito/lsp/document_manager.rb +0 -820
- data/lib/konpeito/lsp/server.rb +0 -183
- data/lib/konpeito/lsp/transport.rb +0 -38
- data/test_native_array.rb +0 -172
- data/test_native_array_class.rb +0 -197
- data/test_native_class.rb +0 -151
data/lib/konpeito/hir/nodes.rb
CHANGED
|
@@ -38,6 +38,7 @@ module Konpeito
|
|
|
38
38
|
class Program < Node
|
|
39
39
|
attr_reader :functions, :classes, :modules
|
|
40
40
|
attr_accessor :toplevel_constants # Array of [name, literal_node] for top-level constants
|
|
41
|
+
attr_accessor :toplevel_includes # Array of module names included at top level
|
|
41
42
|
|
|
42
43
|
def initialize(functions: [], classes: [], modules: [])
|
|
43
44
|
super(type: TypeChecker::Types::NIL)
|
|
@@ -45,6 +46,7 @@ module Konpeito
|
|
|
45
46
|
@classes = classes
|
|
46
47
|
@modules = modules
|
|
47
48
|
@toplevel_constants = []
|
|
49
|
+
@toplevel_includes = []
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
@@ -87,6 +89,8 @@ module Konpeito
|
|
|
87
89
|
# Module definition
|
|
88
90
|
class ModuleDef < Node
|
|
89
91
|
attr_reader :name, :methods, :singleton_methods, :constants
|
|
92
|
+
attr_accessor :module_function_methods # Array of method names registered via module_function
|
|
93
|
+
attr_accessor :private_methods # Set of private method names
|
|
90
94
|
|
|
91
95
|
def initialize(name:, methods: [], singleton_methods: [], constants: {})
|
|
92
96
|
super(type: TypeChecker::Types::NIL)
|
|
@@ -94,6 +98,8 @@ module Konpeito
|
|
|
94
98
|
@methods = methods
|
|
95
99
|
@singleton_methods = singleton_methods
|
|
96
100
|
@constants = constants # Hash of name -> value
|
|
101
|
+
@module_function_methods = []
|
|
102
|
+
@private_methods = Set.new
|
|
97
103
|
end
|
|
98
104
|
end
|
|
99
105
|
|
|
@@ -389,20 +395,21 @@ module Konpeito
|
|
|
389
395
|
|
|
390
396
|
# Method call
|
|
391
397
|
class Call < Instruction
|
|
392
|
-
attr_reader :receiver, :method_name, :args, :block, :keyword_args, :safe_navigation
|
|
398
|
+
attr_reader :receiver, :method_name, :args, :block, :keyword_args, :keyword_splat, :safe_navigation
|
|
393
399
|
|
|
394
|
-
def initialize(receiver:, method_name:, args: [], block: nil, keyword_args: {}, type: TypeChecker::Types::UNTYPED, result_var: nil, safe_navigation: false)
|
|
400
|
+
def initialize(receiver:, method_name:, args: [], block: nil, keyword_args: {}, keyword_splat: nil, type: TypeChecker::Types::UNTYPED, result_var: nil, safe_navigation: false)
|
|
395
401
|
super(type: type, result_var: result_var)
|
|
396
402
|
@receiver = receiver
|
|
397
403
|
@method_name = method_name
|
|
398
404
|
@args = args
|
|
399
405
|
@block = block
|
|
400
406
|
@keyword_args = keyword_args # Hash of { keyword_name => HIR instruction }
|
|
407
|
+
@keyword_splat = keyword_splat # HIR instruction for **hash at call site
|
|
401
408
|
@safe_navigation = safe_navigation
|
|
402
409
|
end
|
|
403
410
|
|
|
404
411
|
def has_keyword_args?
|
|
405
|
-
!@keyword_args.empty?
|
|
412
|
+
!@keyword_args.empty? || !@keyword_splat.nil?
|
|
406
413
|
end
|
|
407
414
|
end
|
|
408
415
|
|
|
@@ -1093,12 +1100,13 @@ module Konpeito
|
|
|
1093
1100
|
end
|
|
1094
1101
|
|
|
1095
1102
|
class BeginRescue < Instruction
|
|
1096
|
-
attr_reader :try_blocks, :rescue_clauses, :else_blocks, :ensure_blocks
|
|
1103
|
+
attr_reader :try_blocks, :try_hir_blocks, :rescue_clauses, :else_blocks, :ensure_blocks
|
|
1097
1104
|
attr_accessor :non_try_instruction_ids
|
|
1098
1105
|
|
|
1099
|
-
def initialize(try_blocks:, rescue_clauses: [], else_blocks: [], ensure_blocks: [], type: TypeChecker::Types::UNTYPED, result_var: nil)
|
|
1106
|
+
def initialize(try_blocks:, try_hir_blocks: nil, rescue_clauses: [], else_blocks: [], ensure_blocks: [], type: TypeChecker::Types::UNTYPED, result_var: nil)
|
|
1100
1107
|
super(type: type, result_var: result_var)
|
|
1101
1108
|
@try_blocks = try_blocks
|
|
1109
|
+
@try_hir_blocks = try_hir_blocks # Array<BasicBlock> for structured try body (with control flow)
|
|
1102
1110
|
@rescue_clauses = rescue_clauses # Array of RescueClause
|
|
1103
1111
|
@else_blocks = else_blocks # Array of BasicBlock (runs if no exception)
|
|
1104
1112
|
@ensure_blocks = ensure_blocks # Array of BasicBlock (always runs)
|
|
@@ -1140,6 +1148,18 @@ module Konpeito
|
|
|
1140
1148
|
end
|
|
1141
1149
|
end
|
|
1142
1150
|
|
|
1151
|
+
# Case equality check: condition === predicate (for case/when dispatch)
|
|
1152
|
+
class CaseEqualityCheck < Instruction
|
|
1153
|
+
attr_reader :condition # HIR node for the when condition value
|
|
1154
|
+
attr_reader :predicate # HIR node for the case predicate (nil for case without predicate)
|
|
1155
|
+
|
|
1156
|
+
def initialize(condition:, predicate:, type: TypeChecker::Types::BOOL, result_var: nil)
|
|
1157
|
+
super(type: type, result_var: result_var)
|
|
1158
|
+
@condition = condition
|
|
1159
|
+
@predicate = predicate
|
|
1160
|
+
end
|
|
1161
|
+
end
|
|
1162
|
+
|
|
1143
1163
|
# ========================================
|
|
1144
1164
|
# Pattern Matching (case/in)
|
|
1145
1165
|
# Ruby 3.0+ pattern matching support
|
|
@@ -623,8 +623,9 @@ module Konpeito
|
|
|
623
623
|
end
|
|
624
624
|
end
|
|
625
625
|
|
|
626
|
-
# Create NativeClassType if has
|
|
627
|
-
|
|
626
|
+
# Create NativeClassType only if has explicit field declarations OR explicit native/struct annotation.
|
|
627
|
+
# Method-only classes (e.g. framework classes with rbs_inline headers) must NOT become NativeClass.
|
|
628
|
+
return if fields.empty? && !native_ann && !is_struct
|
|
628
629
|
|
|
629
630
|
native_type = Types::NativeClassType.new(
|
|
630
631
|
class_name,
|
data/lib/konpeito/ui/app.rb
CHANGED
data/lib/konpeito/version.rb
CHANGED
data/lib/konpeito.rb
CHANGED
|
@@ -40,7 +40,6 @@ module Konpeito
|
|
|
40
40
|
autoload :BaseCommand, "konpeito/cli/base_command"
|
|
41
41
|
autoload :BuildCommand, "konpeito/cli/build_command"
|
|
42
42
|
autoload :CheckCommand, "konpeito/cli/check_command"
|
|
43
|
-
autoload :LspCommand, "konpeito/cli/lsp_command"
|
|
44
43
|
autoload :InitCommand, "konpeito/cli/init_command"
|
|
45
44
|
autoload :FmtCommand, "konpeito/cli/fmt_command"
|
|
46
45
|
autoload :TestCommand, "konpeito/cli/test_command"
|
|
@@ -86,12 +85,6 @@ module Konpeito
|
|
|
86
85
|
autoload :LoopOptimizer, "konpeito/codegen/loop_optimizer"
|
|
87
86
|
end
|
|
88
87
|
|
|
89
|
-
module LSP
|
|
90
|
-
autoload :Server, "konpeito/lsp/server"
|
|
91
|
-
autoload :Transport, "konpeito/lsp/transport"
|
|
92
|
-
autoload :DocumentManager, "konpeito/lsp/document_manager"
|
|
93
|
-
end
|
|
94
|
-
|
|
95
88
|
module RBSInline
|
|
96
89
|
autoload :Preprocessor, "konpeito/rbs_inline/preprocessor"
|
|
97
90
|
end
|
|
@@ -2911,6 +2911,38 @@ public class RubyDispatch {
|
|
|
2911
2911
|
return true;
|
|
2912
2912
|
}
|
|
2913
2913
|
|
|
2914
|
+
/**
|
|
2915
|
+
* Ruby case/when equality check: condition === predicate.
|
|
2916
|
+
* In Ruby, `case x when 10` checks `10 === x`.
|
|
2917
|
+
* Here `condition` is the when-value and `predicate` is the case expression.
|
|
2918
|
+
*
|
|
2919
|
+
* Rules:
|
|
2920
|
+
* - If condition is a Class/Module name (String from ConstantLookup), check instanceof.
|
|
2921
|
+
* - Otherwise use Java equals() for value comparison.
|
|
2922
|
+
*/
|
|
2923
|
+
public static boolean caseEqual(Object condition, Object predicate) {
|
|
2924
|
+
if (condition == null && predicate == null) return true;
|
|
2925
|
+
if (condition == null || predicate == null) return false;
|
|
2926
|
+
// Class name check: condition is a String representing a Ruby class name
|
|
2927
|
+
if (condition instanceof String) {
|
|
2928
|
+
String className = (String) condition;
|
|
2929
|
+
switch (className) {
|
|
2930
|
+
case "Integer": return predicate instanceof Long || predicate instanceof java.math.BigInteger;
|
|
2931
|
+
case "Float": return predicate instanceof Double;
|
|
2932
|
+
case "String": return predicate instanceof String;
|
|
2933
|
+
case "Symbol": return predicate instanceof String && ((String)predicate).startsWith(":");
|
|
2934
|
+
case "Array": return predicate instanceof KArray;
|
|
2935
|
+
case "Hash": return predicate instanceof KHash;
|
|
2936
|
+
case "NilClass": return predicate == null;
|
|
2937
|
+
case "TrueClass": return Boolean.TRUE.equals(predicate);
|
|
2938
|
+
case "FalseClass": return Boolean.FALSE.equals(predicate);
|
|
2939
|
+
case "Numeric": return predicate instanceof Long || predicate instanceof Double;
|
|
2940
|
+
case "Object": case "BasicObject": return true;
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
return condition.equals(predicate);
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2914
2946
|
/**
|
|
2915
2947
|
* GCD helper for Integer#gcd.
|
|
2916
2948
|
*/
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: konpeito
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yasushi Itoh
|
|
@@ -37,20 +37,6 @@ dependencies:
|
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
39
|
version: '0'
|
|
40
|
-
- !ruby/object:Gem::Dependency
|
|
41
|
-
name: language_server-protocol
|
|
42
|
-
requirement: !ruby/object:Gem::Requirement
|
|
43
|
-
requirements:
|
|
44
|
-
- - "~>"
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: '3.17'
|
|
47
|
-
type: :runtime
|
|
48
|
-
prerelease: false
|
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
-
requirements:
|
|
51
|
-
- - "~>"
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: '3.17'
|
|
54
40
|
description: Konpeito is a gradually typed ahead-of-time compiler for Ruby with Hindley-Milner
|
|
55
41
|
type inference and dual LLVM/JVM backends. Compile Ruby to CRuby C extensions (.so)
|
|
56
42
|
or standalone JARs with seamless Java interop. Includes Castella UI, a reactive
|
|
@@ -62,9 +48,11 @@ executables:
|
|
|
62
48
|
extensions: []
|
|
63
49
|
extra_rdoc_files: []
|
|
64
50
|
files:
|
|
51
|
+
- ".rubocop.yml"
|
|
65
52
|
- ".ruby-version"
|
|
66
53
|
- CHANGELOG.md
|
|
67
54
|
- CONTRIBUTING.md
|
|
55
|
+
- Justfile
|
|
68
56
|
- LICENSE
|
|
69
57
|
- README.md
|
|
70
58
|
- Rakefile
|
|
@@ -80,12 +68,12 @@ files:
|
|
|
80
68
|
- lib/konpeito/cli/base_command.rb
|
|
81
69
|
- lib/konpeito/cli/build_command.rb
|
|
82
70
|
- lib/konpeito/cli/check_command.rb
|
|
71
|
+
- lib/konpeito/cli/completion_command.rb
|
|
83
72
|
- lib/konpeito/cli/config.rb
|
|
84
73
|
- lib/konpeito/cli/deps_command.rb
|
|
85
74
|
- lib/konpeito/cli/doctor_command.rb
|
|
86
75
|
- lib/konpeito/cli/fmt_command.rb
|
|
87
76
|
- lib/konpeito/cli/init_command.rb
|
|
88
|
-
- lib/konpeito/cli/lsp_command.rb
|
|
89
77
|
- lib/konpeito/cli/run_command.rb
|
|
90
78
|
- lib/konpeito/cli/test_command.rb
|
|
91
79
|
- lib/konpeito/cli/watch_command.rb
|
|
@@ -105,12 +93,8 @@ files:
|
|
|
105
93
|
- lib/konpeito/diagnostics/collector.rb
|
|
106
94
|
- lib/konpeito/diagnostics/diagnostic.rb
|
|
107
95
|
- lib/konpeito/diagnostics/renderer.rb
|
|
108
|
-
- lib/konpeito/formatter/formatter.rb
|
|
109
96
|
- lib/konpeito/hir/builder.rb
|
|
110
97
|
- lib/konpeito/hir/nodes.rb
|
|
111
|
-
- lib/konpeito/lsp/document_manager.rb
|
|
112
|
-
- lib/konpeito/lsp/server.rb
|
|
113
|
-
- lib/konpeito/lsp/transport.rb
|
|
114
98
|
- lib/konpeito/parser/prism_adapter.rb
|
|
115
99
|
- lib/konpeito/platform.rb
|
|
116
100
|
- lib/konpeito/profile/report.rb
|
|
@@ -204,9 +188,6 @@ files:
|
|
|
204
188
|
- lib/konpeito/ui/widgets/tree.rb
|
|
205
189
|
- lib/konpeito/version.rb
|
|
206
190
|
- scripts/setup_vendor.sh
|
|
207
|
-
- test_native_array.rb
|
|
208
|
-
- test_native_array_class.rb
|
|
209
|
-
- test_native_class.rb
|
|
210
191
|
- tools/konpeito-asm/build.sh
|
|
211
192
|
- tools/konpeito-asm/lib/asm-9.7.1.jar
|
|
212
193
|
- tools/konpeito-asm/src/ClassIntrospector.java
|
|
@@ -236,6 +217,8 @@ metadata:
|
|
|
236
217
|
homepage_uri: https://github.com/i2y/konpeito
|
|
237
218
|
changelog_uri: https://github.com/i2y/konpeito/blob/main/CHANGELOG.md
|
|
238
219
|
bug_tracker_uri: https://github.com/i2y/konpeito/issues
|
|
220
|
+
source_code_uri: https://github.com/i2y/konpeito
|
|
221
|
+
documentation_uri: https://github.com/i2y/konpeito/blob/main/docs/getting-started.md
|
|
239
222
|
rdoc_options: []
|
|
240
223
|
require_paths:
|
|
241
224
|
- lib
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Konpeito
|
|
4
|
-
module Commands
|
|
5
|
-
# LSP command - starts the Language Server Protocol server
|
|
6
|
-
class LspCommand < BaseCommand
|
|
7
|
-
def self.command_name
|
|
8
|
-
"lsp"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def self.description
|
|
12
|
-
"Start Language Server Protocol server for IDE integration"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def run
|
|
16
|
-
parse_options!
|
|
17
|
-
start_lsp_server
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
protected
|
|
21
|
-
|
|
22
|
-
def setup_option_parser(opts)
|
|
23
|
-
super
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def banner
|
|
27
|
-
"Usage: konpeito lsp [options]"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
def start_lsp_server
|
|
33
|
-
puts_verbose "Starting LSP server..."
|
|
34
|
-
require_relative "../lsp/server"
|
|
35
|
-
server = LSP::Server.new
|
|
36
|
-
server.start
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|