t-ruby 0.0.37 → 0.0.39

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.
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TRuby
4
+ # TypeEnv - 타입 환경 (스코프 체인)
5
+ # TypeScript의 Checker에서 심볼 타입을 추적하는 방식을 참고
6
+ class TypeEnv
7
+ attr_reader :parent, :bindings, :instance_vars
8
+
9
+ def initialize(parent = nil)
10
+ @parent = parent
11
+ @bindings = {} # 지역 변수 { name => type }
12
+ @instance_vars = {} # 인스턴스 변수 { name => type }
13
+ @class_vars = {} # 클래스 변수 { name => type }
14
+ end
15
+
16
+ # 지역 변수 타입 정의
17
+ # @param name [String] 변수 이름
18
+ # @param type [IR::TypeNode, String] 타입
19
+ def define(name, type)
20
+ @bindings[name] = type
21
+ end
22
+
23
+ # 변수 타입 조회 (스코프 체인 탐색)
24
+ # @param name [String] 변수 이름
25
+ # @return [IR::TypeNode, String, nil] 타입 또는 nil
26
+ def lookup(name)
27
+ # 인스턴스 변수
28
+ if name.start_with?("@") && !name.start_with?("@@")
29
+ return lookup_instance_var(name)
30
+ end
31
+
32
+ # 클래스 변수
33
+ if name.start_with?("@@")
34
+ return lookup_class_var(name)
35
+ end
36
+
37
+ # 지역 변수 또는 메서드 파라미터
38
+ return @bindings[name] if @bindings.key?(name)
39
+
40
+ # 부모 스코프에서 검색
41
+ @parent&.lookup(name)
42
+ end
43
+
44
+ # 인스턴스 변수 타입 정의
45
+ # @param name [String] 변수 이름 (@포함)
46
+ # @param type [IR::TypeNode, String] 타입
47
+ def define_instance_var(name, type)
48
+ # @ 접두사 정규화
49
+ normalized = name.start_with?("@") ? name : "@#{name}"
50
+ @instance_vars[normalized] = type
51
+ end
52
+
53
+ # 인스턴스 변수 타입 조회
54
+ # @param name [String] 변수 이름 (@포함)
55
+ # @return [IR::TypeNode, String, nil] 타입 또는 nil
56
+ def lookup_instance_var(name)
57
+ normalized = name.start_with?("@") ? name : "@#{name}"
58
+ return @instance_vars[normalized] if @instance_vars.key?(normalized)
59
+
60
+ @parent&.lookup_instance_var(normalized)
61
+ end
62
+
63
+ # 클래스 변수 타입 정의
64
+ # @param name [String] 변수 이름 (@@포함)
65
+ # @param type [IR::TypeNode, String] 타입
66
+ def define_class_var(name, type)
67
+ normalized = name.start_with?("@@") ? name : "@@#{name}"
68
+ @class_vars[normalized] = type
69
+ end
70
+
71
+ # 클래스 변수 타입 조회
72
+ # @param name [String] 변수 이름 (@@포함)
73
+ # @return [IR::TypeNode, String, nil] 타입 또는 nil
74
+ def lookup_class_var(name)
75
+ normalized = name.start_with?("@@") ? name : "@@#{name}"
76
+ return @class_vars[normalized] if @class_vars.key?(normalized)
77
+
78
+ @parent&.lookup_class_var(normalized)
79
+ end
80
+
81
+ # 자식 스코프 생성 (블록, 람다 등)
82
+ # @return [TypeEnv] 새 자식 스코프
83
+ def child_scope
84
+ TypeEnv.new(self)
85
+ end
86
+
87
+ # 현재 스코프에서 정의된 모든 변수 이름
88
+ # @return [Array<String>] 변수 이름 배열
89
+ def local_names
90
+ @bindings.keys
91
+ end
92
+
93
+ # 현재 스코프에서 정의된 모든 인스턴스 변수 이름
94
+ # @return [Array<String>] 인스턴스 변수 이름 배열
95
+ def instance_var_names
96
+ @instance_vars.keys
97
+ end
98
+
99
+ # 변수가 현재 스코프에 정의되어 있는지 확인
100
+ # @param name [String] 변수 이름
101
+ # @return [Boolean]
102
+ def defined_locally?(name)
103
+ @bindings.key?(name)
104
+ end
105
+
106
+ # 스코프 깊이 (디버깅용)
107
+ # @return [Integer] 스코프 깊이
108
+ def depth
109
+ @parent ? @parent.depth + 1 : 0
110
+ end
111
+
112
+ # 스코프 체인에서 모든 변수 수집
113
+ # @return [Hash] 모든 변수의 { name => type }
114
+ def all_bindings
115
+ parent_bindings = @parent ? @parent.all_bindings : {}
116
+ parent_bindings.merge(@bindings)
117
+ end
118
+
119
+ # 디버그 출력
120
+ def to_s
121
+ parts = ["TypeEnv(depth=#{depth})"]
122
+ parts << " locals: #{@bindings.keys.join(", ")}" if @bindings.any?
123
+ parts << " ivars: #{@instance_vars.keys.join(", ")}" if @instance_vars.any?
124
+ parts.join("\n")
125
+ end
126
+ end
127
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TRuby
4
- VERSION = "0.0.37"
4
+ VERSION = "0.0.39"
5
5
  end
@@ -3,6 +3,7 @@
3
3
  require "net/http"
4
4
  require "json"
5
5
  require "uri"
6
+ require "openssl"
6
7
 
7
8
  module TRuby
8
9
  class VersionChecker
@@ -37,7 +38,16 @@ module TRuby
37
38
 
38
39
  def fetch_latest_version
39
40
  uri = URI(RUBYGEMS_API)
40
- response = Net::HTTP.get_response(uri)
41
+
42
+ http = Net::HTTP.new(uri.host, uri.port)
43
+ http.use_ssl = true
44
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
45
+ http.verify_callback = ->(_preverify_ok, _store_ctx) { true } # Skip CRL check
46
+ http.open_timeout = 3
47
+ http.read_timeout = 3
48
+
49
+ request = Net::HTTP::Get.new(uri)
50
+ response = http.request(request)
41
51
 
42
52
  return nil unless response.is_a?(Net::HTTPSuccess)
43
53
 
@@ -80,14 +80,18 @@ module TRuby
80
80
 
81
81
  private
82
82
 
83
+ def watch_directory(path)
84
+ File.directory?(path) ? path : File.dirname(path)
85
+ end
86
+
83
87
  def watch_directories
84
- @paths.map do |path|
85
- if File.directory?(path)
86
- path
87
- else
88
- File.dirname(path)
89
- end
90
- end.uniq
88
+ if @paths == [File.expand_path(".")]
89
+ # Default case: only watch source_include directories from config
90
+ @config.source_include.map { |dir| File.expand_path(dir) }.select { |dir| Dir.exist?(dir) }
91
+ else
92
+ # Specific paths provided: watch those paths
93
+ @paths.map { |path| watch_directory(path) }.uniq
94
+ end
91
95
  end
92
96
 
93
97
  def handle_changes(modified, added, removed)
@@ -243,20 +247,21 @@ module TRuby
243
247
  def find_source_files_by_extension(ext)
244
248
  files = []
245
249
 
246
- # If watching specific paths, use those paths
247
- # Otherwise, use Config's find_source_files which respects include/exclude patterns
248
- if @paths == [File.expand_path(".")]
249
- # Default case: use config's src_dir with include/exclude patterns
250
- files = @config.find_source_files.select { |f| f.end_with?(ext) }
251
- else
252
- # Specific paths provided: search in those paths but still apply exclude patterns
253
- @paths.each do |path|
254
- if File.directory?(path)
255
- Dir.glob(File.join(path, "**", "*#{ext}")).each do |file|
256
- files << file unless @config.excluded?(file)
257
- end
258
- elsif File.file?(path) && path.end_with?(ext) && !@config.excluded?(path)
259
- files << path
250
+ # Always search in source_include directories only
251
+ source_paths = if @paths == [File.expand_path(".")]
252
+ @config.source_include.map { |dir| File.expand_path(dir) }
253
+ else
254
+ @paths.map { |path| File.expand_path(path) }
255
+ end
256
+
257
+ source_paths.each do |path|
258
+ if File.file?(path)
259
+ # Handle single file path
260
+ files << path if path.end_with?(ext) && !@config.excluded?(path)
261
+ elsif Dir.exist?(path)
262
+ # Handle directory path
263
+ Dir.glob(File.join(path, "**", "*#{ext}")).each do |file|
264
+ files << file unless @config.excluded?(file)
260
265
  end
261
266
  end
262
267
  end
data/lib/t_ruby.rb CHANGED
@@ -11,6 +11,7 @@ require_relative "t_ruby/smt_solver"
11
11
 
12
12
  # Basic components
13
13
  require_relative "t_ruby/type_alias_registry"
14
+ require_relative "t_ruby/body_parser"
14
15
  require_relative "t_ruby/parser"
15
16
  require_relative "t_ruby/union_type_parser"
16
17
  require_relative "t_ruby/generic_type_parser"
@@ -29,6 +30,8 @@ require_relative "t_ruby/constraint_checker"
29
30
  require_relative "t_ruby/type_inferencer"
30
31
  require_relative "t_ruby/runtime_validator"
31
32
  require_relative "t_ruby/type_checker"
33
+ require_relative "t_ruby/type_env"
34
+ require_relative "t_ruby/ast_type_inferrer"
32
35
  require_relative "t_ruby/cache"
33
36
  require_relative "t_ruby/package_manager"
34
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.37
4
+ version: 0.0.39
5
5
  platform: ruby
6
6
  authors:
7
7
  - Y. Fred Kim
@@ -36,7 +36,9 @@ files:
36
36
  - README.md
37
37
  - bin/trc
38
38
  - lib/t_ruby.rb
39
+ - lib/t_ruby/ast_type_inferrer.rb
39
40
  - lib/t_ruby/benchmark.rb
41
+ - lib/t_ruby/body_parser.rb
40
42
  - lib/t_ruby/bundler_integration.rb
41
43
  - lib/t_ruby/cache.rb
42
44
  - lib/t_ruby/cli.rb
@@ -61,6 +63,7 @@ files:
61
63
  - lib/t_ruby/smt_solver.rb
62
64
  - lib/t_ruby/type_alias_registry.rb
63
65
  - lib/t_ruby/type_checker.rb
66
+ - lib/t_ruby/type_env.rb
64
67
  - lib/t_ruby/type_erasure.rb
65
68
  - lib/t_ruby/type_inferencer.rb
66
69
  - lib/t_ruby/union_type_parser.rb
@@ -69,7 +72,7 @@ files:
69
72
  - lib/t_ruby/watcher.rb
70
73
  homepage: https://type-ruby.github.io
71
74
  licenses:
72
- - MIT
75
+ - BSD-2-Clause
73
76
  metadata:
74
77
  rubygems_mfa_required: 'true'
75
78
  rdoc_options: []