konpeito 0.1.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.
Files changed (180) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +75 -0
  4. data/CONTRIBUTING.md +123 -0
  5. data/LICENSE +21 -0
  6. data/README.md +257 -0
  7. data/Rakefile +11 -0
  8. data/bin/konpeito +6 -0
  9. data/konpeito.gemspec +43 -0
  10. data/lib/konpeito/ast/typed_ast.rb +620 -0
  11. data/lib/konpeito/ast/visitor.rb +78 -0
  12. data/lib/konpeito/cache/cache_manager.rb +230 -0
  13. data/lib/konpeito/cache/dependency_graph.rb +192 -0
  14. data/lib/konpeito/cache.rb +8 -0
  15. data/lib/konpeito/cli/base_command.rb +187 -0
  16. data/lib/konpeito/cli/build_command.rb +220 -0
  17. data/lib/konpeito/cli/check_command.rb +104 -0
  18. data/lib/konpeito/cli/config.rb +231 -0
  19. data/lib/konpeito/cli/deps_command.rb +128 -0
  20. data/lib/konpeito/cli/doctor_command.rb +340 -0
  21. data/lib/konpeito/cli/fmt_command.rb +199 -0
  22. data/lib/konpeito/cli/init_command.rb +312 -0
  23. data/lib/konpeito/cli/lsp_command.rb +40 -0
  24. data/lib/konpeito/cli/run_command.rb +150 -0
  25. data/lib/konpeito/cli/test_command.rb +248 -0
  26. data/lib/konpeito/cli/watch_command.rb +212 -0
  27. data/lib/konpeito/cli.rb +301 -0
  28. data/lib/konpeito/codegen/builtin_methods.rb +229 -0
  29. data/lib/konpeito/codegen/cruby_backend.rb +1090 -0
  30. data/lib/konpeito/codegen/debug_info.rb +352 -0
  31. data/lib/konpeito/codegen/inliner.rb +486 -0
  32. data/lib/konpeito/codegen/jvm_backend.rb +197 -0
  33. data/lib/konpeito/codegen/jvm_generator.rb +13412 -0
  34. data/lib/konpeito/codegen/llvm_generator.rb +13191 -0
  35. data/lib/konpeito/codegen/loop_optimizer.rb +363 -0
  36. data/lib/konpeito/codegen/monomorphizer.rb +359 -0
  37. data/lib/konpeito/codegen/profile_runtime.c +341 -0
  38. data/lib/konpeito/codegen/profiler.rb +99 -0
  39. data/lib/konpeito/compiler.rb +592 -0
  40. data/lib/konpeito/dependency_resolver.rb +296 -0
  41. data/lib/konpeito/diagnostics/collector.rb +127 -0
  42. data/lib/konpeito/diagnostics/diagnostic.rb +237 -0
  43. data/lib/konpeito/diagnostics/renderer.rb +144 -0
  44. data/lib/konpeito/formatter/formatter.rb +1214 -0
  45. data/lib/konpeito/hir/builder.rb +7167 -0
  46. data/lib/konpeito/hir/nodes.rb +2465 -0
  47. data/lib/konpeito/lsp/document_manager.rb +820 -0
  48. data/lib/konpeito/lsp/server.rb +183 -0
  49. data/lib/konpeito/lsp/transport.rb +38 -0
  50. data/lib/konpeito/parser/prism_adapter.rb +65 -0
  51. data/lib/konpeito/platform.rb +103 -0
  52. data/lib/konpeito/profile/report.rb +136 -0
  53. data/lib/konpeito/rbs_inline/preprocessor.rb +199 -0
  54. data/lib/konpeito/stdlib/compression/compression.rb +72 -0
  55. data/lib/konpeito/stdlib/compression/compression.rbs +60 -0
  56. data/lib/konpeito/stdlib/compression/compression_native.c +415 -0
  57. data/lib/konpeito/stdlib/compression/extconf.rb +19 -0
  58. data/lib/konpeito/stdlib/crypto/crypto.rb +85 -0
  59. data/lib/konpeito/stdlib/crypto/crypto.rbs +74 -0
  60. data/lib/konpeito/stdlib/crypto/crypto_native.c +312 -0
  61. data/lib/konpeito/stdlib/crypto/extconf.rb +40 -0
  62. data/lib/konpeito/stdlib/http/extconf.rb +19 -0
  63. data/lib/konpeito/stdlib/http/http.rb +125 -0
  64. data/lib/konpeito/stdlib/http/http.rbs +57 -0
  65. data/lib/konpeito/stdlib/http/http_native.c +440 -0
  66. data/lib/konpeito/stdlib/json/extconf.rb +17 -0
  67. data/lib/konpeito/stdlib/json/json.rb +44 -0
  68. data/lib/konpeito/stdlib/json/json.rbs +33 -0
  69. data/lib/konpeito/stdlib/json/json_native.c +286 -0
  70. data/lib/konpeito/stdlib/ui/extconf.rb +216 -0
  71. data/lib/konpeito/stdlib/ui/konpeito_ui_native.cpp +1625 -0
  72. data/lib/konpeito/stdlib/ui/konpeito_ui_native.h +162 -0
  73. data/lib/konpeito/stdlib/ui/ui.rb +318 -0
  74. data/lib/konpeito/stdlib/ui/ui.rbs +247 -0
  75. data/lib/konpeito/type_checker/annotation_parser.rb +67 -0
  76. data/lib/konpeito/type_checker/hm_inferrer.rb +2565 -0
  77. data/lib/konpeito/type_checker/inferrer.rb +565 -0
  78. data/lib/konpeito/type_checker/rbs_loader.rb +1621 -0
  79. data/lib/konpeito/type_checker/type_resolver.rb +276 -0
  80. data/lib/konpeito/type_checker/types.rb +1434 -0
  81. data/lib/konpeito/type_checker/unification.rb +323 -0
  82. data/lib/konpeito/ui/animation/animated_state.rb +80 -0
  83. data/lib/konpeito/ui/animation/easing.rb +59 -0
  84. data/lib/konpeito/ui/animation/value_tween.rb +66 -0
  85. data/lib/konpeito/ui/app.rb +379 -0
  86. data/lib/konpeito/ui/box.rb +38 -0
  87. data/lib/konpeito/ui/castella.rb +70 -0
  88. data/lib/konpeito/ui/castella_native.rb +76 -0
  89. data/lib/konpeito/ui/chart/area_chart.rb +305 -0
  90. data/lib/konpeito/ui/chart/bar_chart.rb +288 -0
  91. data/lib/konpeito/ui/chart/base_chart.rb +210 -0
  92. data/lib/konpeito/ui/chart/chart_helpers.rb +79 -0
  93. data/lib/konpeito/ui/chart/gauge_chart.rb +171 -0
  94. data/lib/konpeito/ui/chart/heatmap_chart.rb +222 -0
  95. data/lib/konpeito/ui/chart/line_chart.rb +289 -0
  96. data/lib/konpeito/ui/chart/pie_chart.rb +219 -0
  97. data/lib/konpeito/ui/chart/scales.rb +77 -0
  98. data/lib/konpeito/ui/chart/scatter_chart.rb +303 -0
  99. data/lib/konpeito/ui/chart/stacked_bar_chart.rb +276 -0
  100. data/lib/konpeito/ui/column.rb +271 -0
  101. data/lib/konpeito/ui/core.rb +2199 -0
  102. data/lib/konpeito/ui/dsl.rb +443 -0
  103. data/lib/konpeito/ui/frame.rb +171 -0
  104. data/lib/konpeito/ui/frame_native.rb +494 -0
  105. data/lib/konpeito/ui/markdown/ast.rb +124 -0
  106. data/lib/konpeito/ui/markdown/mermaid/layout.rb +387 -0
  107. data/lib/konpeito/ui/markdown/mermaid/models.rb +232 -0
  108. data/lib/konpeito/ui/markdown/mermaid/parser.rb +519 -0
  109. data/lib/konpeito/ui/markdown/mermaid/renderer.rb +336 -0
  110. data/lib/konpeito/ui/markdown/parser.rb +805 -0
  111. data/lib/konpeito/ui/markdown/renderer.rb +639 -0
  112. data/lib/konpeito/ui/markdown/theme.rb +165 -0
  113. data/lib/konpeito/ui/render_node.rb +260 -0
  114. data/lib/konpeito/ui/row.rb +207 -0
  115. data/lib/konpeito/ui/spacer.rb +18 -0
  116. data/lib/konpeito/ui/style.rb +799 -0
  117. data/lib/konpeito/ui/theme.rb +563 -0
  118. data/lib/konpeito/ui/themes/material.rb +35 -0
  119. data/lib/konpeito/ui/themes/tokyo_night.rb +6 -0
  120. data/lib/konpeito/ui/widgets/button.rb +103 -0
  121. data/lib/konpeito/ui/widgets/calendar.rb +1034 -0
  122. data/lib/konpeito/ui/widgets/checkbox.rb +119 -0
  123. data/lib/konpeito/ui/widgets/container.rb +91 -0
  124. data/lib/konpeito/ui/widgets/data_table.rb +667 -0
  125. data/lib/konpeito/ui/widgets/divider.rb +29 -0
  126. data/lib/konpeito/ui/widgets/image.rb +105 -0
  127. data/lib/konpeito/ui/widgets/input.rb +485 -0
  128. data/lib/konpeito/ui/widgets/markdown.rb +57 -0
  129. data/lib/konpeito/ui/widgets/modal.rb +163 -0
  130. data/lib/konpeito/ui/widgets/multiline_input.rb +968 -0
  131. data/lib/konpeito/ui/widgets/multiline_text.rb +180 -0
  132. data/lib/konpeito/ui/widgets/net_image.rb +100 -0
  133. data/lib/konpeito/ui/widgets/progress_bar.rb +70 -0
  134. data/lib/konpeito/ui/widgets/radio_buttons.rb +93 -0
  135. data/lib/konpeito/ui/widgets/slider.rb +133 -0
  136. data/lib/konpeito/ui/widgets/switch.rb +84 -0
  137. data/lib/konpeito/ui/widgets/tabs.rb +157 -0
  138. data/lib/konpeito/ui/widgets/text.rb +110 -0
  139. data/lib/konpeito/ui/widgets/tree.rb +426 -0
  140. data/lib/konpeito/version.rb +5 -0
  141. data/lib/konpeito.rb +109 -0
  142. data/test_native_array.rb +172 -0
  143. data/test_native_array_class.rb +197 -0
  144. data/test_native_class.rb +151 -0
  145. data/tools/konpeito-asm/build.sh +65 -0
  146. data/tools/konpeito-asm/lib/asm-9.7.1.jar +0 -0
  147. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KArray.class +0 -0
  148. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KCompression.class +0 -0
  149. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KConditionVariable.class +0 -0
  150. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KCrypto.class +0 -0
  151. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KFile.class +0 -0
  152. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KHTTP.class +0 -0
  153. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KHash.class +0 -0
  154. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KJSON$Parser.class +0 -0
  155. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KJSON.class +0 -0
  156. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KMath.class +0 -0
  157. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KRactor.class +0 -0
  158. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KRactorPort.class +0 -0
  159. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KSizedQueue.class +0 -0
  160. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KThread.class +0 -0
  161. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/KTime.class +0 -0
  162. data/tools/konpeito-asm/runtime-classes/konpeito/runtime/RubyDispatch.class +0 -0
  163. data/tools/konpeito-asm/src/ClassIntrospector.java +312 -0
  164. data/tools/konpeito-asm/src/KonpeitoAssembler.java +659 -0
  165. data/tools/konpeito-asm/src/konpeito/runtime/KArray.java +390 -0
  166. data/tools/konpeito-asm/src/konpeito/runtime/KCompression.java +168 -0
  167. data/tools/konpeito-asm/src/konpeito/runtime/KConditionVariable.java +48 -0
  168. data/tools/konpeito-asm/src/konpeito/runtime/KCrypto.java +151 -0
  169. data/tools/konpeito-asm/src/konpeito/runtime/KFile.java +100 -0
  170. data/tools/konpeito-asm/src/konpeito/runtime/KHTTP.java +113 -0
  171. data/tools/konpeito-asm/src/konpeito/runtime/KHash.java +228 -0
  172. data/tools/konpeito-asm/src/konpeito/runtime/KJSON.java +405 -0
  173. data/tools/konpeito-asm/src/konpeito/runtime/KMath.java +54 -0
  174. data/tools/konpeito-asm/src/konpeito/runtime/KRactor.java +244 -0
  175. data/tools/konpeito-asm/src/konpeito/runtime/KRactorPort.java +53 -0
  176. data/tools/konpeito-asm/src/konpeito/runtime/KSizedQueue.java +49 -0
  177. data/tools/konpeito-asm/src/konpeito/runtime/KThread.java +49 -0
  178. data/tools/konpeito-asm/src/konpeito/runtime/KTime.java +53 -0
  179. data/tools/konpeito-asm/src/konpeito/runtime/RubyDispatch.java +416 -0
  180. metadata +267 -0
@@ -0,0 +1,247 @@
1
+ # KonpeitoUI - Native UI runtime module (SDL3 + Skia)
2
+ #
3
+ # All methods take a handle (Integer) as the first argument,
4
+ # which is the opaque pointer to the KUIContext C struct.
5
+
6
+ %a{ffi: "konpeito_ui"}
7
+ module KonpeitoUI
8
+ # --- Event type constants ---
9
+ EVENT_NONE: Integer # 0
10
+ EVENT_MOUSE_DOWN: Integer # 1
11
+ EVENT_MOUSE_UP: Integer # 2
12
+ EVENT_MOUSE_MOVE: Integer # 3
13
+ EVENT_MOUSE_WHEEL: Integer # 4
14
+ EVENT_KEY_DOWN: Integer # 5
15
+ EVENT_KEY_UP: Integer # 6
16
+ EVENT_TEXT_INPUT: Integer # 7
17
+ EVENT_RESIZE: Integer # 8
18
+ EVENT_IME_PREEDIT: Integer # 9
19
+ EVENT_QUIT: Integer # 10
20
+
21
+ # --- Modifier constants ---
22
+ MOD_SHIFT: Integer # 1
23
+ MOD_CONTROL: Integer # 2
24
+ MOD_ALT: Integer # 4
25
+ MOD_SUPER: Integer # 8
26
+
27
+ # --- Window management ---
28
+ %a{cfunc: "kui_create_window"}
29
+ def self.create_window: (String title, Integer width, Integer height) -> Integer
30
+
31
+ %a{cfunc: "kui_destroy_window"}
32
+ def self.destroy_window: (Integer handle) -> void
33
+
34
+ %a{cfunc: "kui_step"}
35
+ def self.step: (Integer handle) -> void
36
+
37
+ # --- Event access ---
38
+ %a{cfunc: "kui_has_event"}
39
+ def self.has_event: (Integer handle) -> bool
40
+
41
+ %a{cfunc: "kui_event_type"}
42
+ def self.event_type: (Integer handle) -> Integer
43
+
44
+ %a{cfunc: "kui_event_x"}
45
+ def self.event_x: (Integer handle) -> Float
46
+
47
+ %a{cfunc: "kui_event_y"}
48
+ def self.event_y: (Integer handle) -> Float
49
+
50
+ %a{cfunc: "kui_event_dx"}
51
+ def self.event_dx: (Integer handle) -> Float
52
+
53
+ %a{cfunc: "kui_event_dy"}
54
+ def self.event_dy: (Integer handle) -> Float
55
+
56
+ %a{cfunc: "kui_event_button"}
57
+ def self.event_button: (Integer handle) -> Integer
58
+
59
+ %a{cfunc: "kui_event_key_code"}
60
+ def self.event_key_code: (Integer handle) -> Integer
61
+
62
+ %a{cfunc: "kui_event_modifiers"}
63
+ def self.event_modifiers: (Integer handle) -> Integer
64
+
65
+ %a{cfunc: "kui_event_text"}
66
+ def self.event_text: (Integer handle) -> String
67
+
68
+ %a{cfunc: "kui_event_ime_sel_start"}
69
+ def self.event_ime_sel_start: (Integer handle) -> Integer
70
+
71
+ %a{cfunc: "kui_event_ime_sel_end"}
72
+ def self.event_ime_sel_end: (Integer handle) -> Integer
73
+
74
+ %a{cfunc: "kui_consume_event"}
75
+ def self.consume_event: (Integer handle) -> void
76
+
77
+ # --- Frame management ---
78
+ %a{cfunc: "kui_begin_frame"}
79
+ def self.begin_frame: (Integer handle) -> void
80
+
81
+ %a{cfunc: "kui_end_frame"}
82
+ def self.end_frame: (Integer handle) -> void
83
+
84
+ # --- Drawing primitives ---
85
+ %a{cfunc: "kui_clear"}
86
+ def self.clear: (Integer handle, Integer color) -> void
87
+
88
+ %a{cfunc: "kui_fill_rect"}
89
+ def self.fill_rect: (Integer handle, Float x, Float y, Float w, Float h, Integer color) -> void
90
+
91
+ %a{cfunc: "kui_stroke_rect"}
92
+ def self.stroke_rect: (Integer handle, Float x, Float y, Float w, Float h, Integer color, Float stroke_width) -> void
93
+
94
+ %a{cfunc: "kui_fill_round_rect"}
95
+ def self.fill_round_rect: (Integer handle, Float x, Float y, Float w, Float h, Float r, Integer color) -> void
96
+
97
+ %a{cfunc: "kui_stroke_round_rect"}
98
+ def self.stroke_round_rect: (Integer handle, Float x, Float y, Float w, Float h, Float r, Integer color, Float stroke_width) -> void
99
+
100
+ %a{cfunc: "kui_fill_circle"}
101
+ def self.fill_circle: (Integer handle, Float cx, Float cy, Float r, Integer color) -> void
102
+
103
+ %a{cfunc: "kui_stroke_circle"}
104
+ def self.stroke_circle: (Integer handle, Float cx, Float cy, Float r, Integer color, Float stroke_width) -> void
105
+
106
+ %a{cfunc: "kui_draw_line"}
107
+ def self.draw_line: (Integer handle, Float x1, Float y1, Float x2, Float y2, Integer color, Float width) -> void
108
+
109
+ %a{cfunc: "kui_fill_arc"}
110
+ def self.fill_arc: (Integer handle, Float cx, Float cy, Float r, Float start_angle, Float sweep_angle, Integer color) -> void
111
+
112
+ %a{cfunc: "kui_stroke_arc"}
113
+ def self.stroke_arc: (Integer handle, Float cx, Float cy, Float r, Float start_angle, Float sweep_angle, Integer color, Float stroke_width) -> void
114
+
115
+ %a{cfunc: "kui_fill_triangle"}
116
+ def self.fill_triangle: (Integer handle, Float x1, Float y1, Float x2, Float y2, Float x3, Float y3, Integer color) -> void
117
+
118
+ # --- Text ---
119
+ %a{cfunc: "kui_draw_text"}
120
+ def self.draw_text: (Integer handle, String text, Float x, Float y, String font_family, Float font_size, Integer color) -> void
121
+
122
+ %a{cfunc: "kui_draw_text_styled"}
123
+ def self.draw_text_styled: (Integer handle, String text, Float x, Float y, String font_family, Float font_size, Integer color, Integer weight, Integer slant) -> void
124
+
125
+ %a{cfunc: "kui_measure_text_width"}
126
+ def self.measure_text_width: (Integer handle, String text, String font_family, Float font_size) -> Float
127
+
128
+ %a{cfunc: "kui_measure_text_height"}
129
+ def self.measure_text_height: (Integer handle, String font_family, Float font_size) -> Float
130
+
131
+ %a{cfunc: "kui_get_text_ascent"}
132
+ def self.get_text_ascent: (Integer handle, String font_family, Float font_size) -> Float
133
+
134
+ # --- Path drawing ---
135
+ %a{cfunc: "kui_begin_path"}
136
+ def self.begin_path: (Integer handle) -> void
137
+
138
+ %a{cfunc: "kui_path_move_to"}
139
+ def self.path_move_to: (Integer handle, Float x, Float y) -> void
140
+
141
+ %a{cfunc: "kui_path_line_to"}
142
+ def self.path_line_to: (Integer handle, Float x, Float y) -> void
143
+
144
+ %a{cfunc: "kui_close_fill_path"}
145
+ def self.close_fill_path: (Integer handle, Integer color) -> void
146
+
147
+ %a{cfunc: "kui_fill_path"}
148
+ def self.fill_path: (Integer handle, Integer color) -> void
149
+
150
+ # --- Canvas state ---
151
+ %a{cfunc: "kui_save"}
152
+ def self.save: (Integer handle) -> void
153
+
154
+ %a{cfunc: "kui_restore"}
155
+ def self.restore: (Integer handle) -> void
156
+
157
+ %a{cfunc: "kui_translate"}
158
+ def self.translate: (Integer handle, Float dx, Float dy) -> void
159
+
160
+ %a{cfunc: "kui_clip_rect"}
161
+ def self.clip_rect: (Integer handle, Float x, Float y, Float w, Float h) -> void
162
+
163
+ # --- Image operations ---
164
+ %a{cfunc: "kui_load_image"}
165
+ def self.load_image: (Integer handle, String path) -> Integer
166
+
167
+ %a{cfunc: "kui_load_net_image"}
168
+ def self.load_net_image: (Integer handle, String url) -> Integer
169
+
170
+ %a{cfunc: "kui_draw_image"}
171
+ def self.draw_image: (Integer handle, Integer image_id, Float x, Float y, Float w, Float h) -> void
172
+
173
+ %a{cfunc: "kui_get_image_width"}
174
+ def self.get_image_width: (Integer handle, Integer image_id) -> Float
175
+
176
+ %a{cfunc: "kui_get_image_height"}
177
+ def self.get_image_height: (Integer handle, Integer image_id) -> Float
178
+
179
+ # --- Color utilities ---
180
+ %a{cfunc: "kui_interpolate_color"}
181
+ def self.interpolate_color: (Integer c1, Integer c2, Float t) -> Integer
182
+
183
+ %a{cfunc: "kui_with_alpha"}
184
+ def self.with_alpha: (Integer color, Integer alpha) -> Integer
185
+
186
+ %a{cfunc: "kui_lighten_color"}
187
+ def self.lighten_color: (Integer color, Float amount) -> Integer
188
+
189
+ %a{cfunc: "kui_darken_color"}
190
+ def self.darken_color: (Integer color, Float amount) -> Integer
191
+
192
+ # --- Window queries ---
193
+ %a{cfunc: "kui_get_width"}
194
+ def self.get_width: (Integer handle) -> Float
195
+
196
+ %a{cfunc: "kui_get_height"}
197
+ def self.get_height: (Integer handle) -> Float
198
+
199
+ %a{cfunc: "kui_get_scale"}
200
+ def self.get_scale: (Integer handle) -> Float
201
+
202
+ %a{cfunc: "kui_is_dark_mode"}
203
+ def self.is_dark_mode: (Integer handle) -> bool
204
+
205
+ %a{cfunc: "kui_request_frame"}
206
+ def self.request_frame: (Integer handle) -> void
207
+
208
+ %a{cfunc: "kui_mark_dirty"}
209
+ def self.mark_dirty: (Integer handle) -> void
210
+
211
+ # --- IME / Text Input ---
212
+ %a{cfunc: "kui_set_text_input_enabled"}
213
+ def self.set_text_input_enabled: (Integer handle, bool enabled) -> void
214
+
215
+ %a{cfunc: "kui_set_text_input_rect"}
216
+ def self.set_text_input_rect: (Integer handle, Integer x, Integer y, Integer w, Integer h) -> void
217
+
218
+ # --- Clipboard ---
219
+ %a{cfunc: "kui_get_clipboard_text"}
220
+ def self.get_clipboard_text: (Integer handle) -> String
221
+
222
+ %a{cfunc: "kui_set_clipboard_text"}
223
+ def self.set_clipboard_text: (Integer handle, String text) -> void
224
+
225
+ # --- Utilities ---
226
+ %a{cfunc: "kui_current_time_millis"}
227
+ def self.current_time_millis: () -> Integer
228
+
229
+ %a{cfunc: "kui_number_to_string"}
230
+ def self.number_to_string: (Float value) -> String
231
+
232
+ # --- Math helpers ---
233
+ %a{cfunc: "kui_math_cos"}
234
+ def self.math_cos: (Float radians) -> Float
235
+
236
+ %a{cfunc: "kui_math_sin"}
237
+ def self.math_sin: (Float radians) -> Float
238
+
239
+ %a{cfunc: "kui_math_sqrt"}
240
+ def self.math_sqrt: (Float value) -> Float
241
+
242
+ %a{cfunc: "kui_math_atan2"}
243
+ def self.math_atan2: (Float y, Float x) -> Float
244
+
245
+ %a{cfunc: "kui_math_abs"}
246
+ def self.math_abs: (Float value) -> Float
247
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Konpeito
4
+ module TypeChecker
5
+ # Parses %a{...} RBS annotations into structured data
6
+ module AnnotationParser
7
+ module_function
8
+
9
+ # Parse a single annotation string into a structured hash
10
+ # @param ann_string [String] The annotation content (without %a{})
11
+ # @return [Hash] Parsed annotation data with :type key
12
+ def parse(ann_string)
13
+ case ann_string.strip
14
+ when /\Anative\z/
15
+ { type: :native }
16
+ when /\Anative:\s*vtable\z/
17
+ { type: :native, vtable: true }
18
+ when /\Aextern\z/
19
+ { type: :extern }
20
+ when /\Aboxed\z/
21
+ { type: :boxed }
22
+ when /\Astruct\z/
23
+ { type: :struct }
24
+ when /\Asimd\z/
25
+ { type: :simd }
26
+ when /\Affi:\s*"([^"]+)"\z/
27
+ { type: :ffi, library: ::Regexp.last_match(1) }
28
+ when /\Acfunc:\s*"([^"]+)"\z/
29
+ { type: :cfunc, c_name: ::Regexp.last_match(1) }
30
+ when /\Acfunc\z/
31
+ { type: :cfunc }
32
+ when /\Ajvm_static:\s*"([^"]+)"\z/
33
+ { type: :jvm_static, java_class: ::Regexp.last_match(1) }
34
+ when /\Acallback:\s*"([^"]+)"\s+descriptor:\s*"([^"]+)"\z/
35
+ { type: :callback, interface: ::Regexp.last_match(1), descriptor: ::Regexp.last_match(2) }
36
+ when /\Acallback:\s*"([^"]+)"\z/
37
+ { type: :callback, interface: ::Regexp.last_match(1) }
38
+ else
39
+ { type: :unknown, raw: ann_string }
40
+ end
41
+ end
42
+
43
+ # Parse all annotations from an array of RBS::AST::Annotation
44
+ # @param annotations [Array<RBS::AST::Annotation>] RBS annotations
45
+ # @return [Array<Hash>] Parsed annotation data
46
+ def parse_all(annotations)
47
+ annotations.map { |ann| parse(ann.string) }
48
+ end
49
+
50
+ # Find a specific annotation type from parsed annotations
51
+ # @param parsed [Array<Hash>] Parsed annotations
52
+ # @param type [Symbol] Annotation type to find
53
+ # @return [Hash, nil] The found annotation or nil
54
+ def find(parsed, type)
55
+ parsed.find { |ann| ann[:type] == type }
56
+ end
57
+
58
+ # Check if annotations contain a specific type
59
+ # @param parsed [Array<Hash>] Parsed annotations
60
+ # @param type [Symbol] Annotation type to check
61
+ # @return [Boolean]
62
+ def has?(parsed, type)
63
+ !find(parsed, type).nil?
64
+ end
65
+ end
66
+ end
67
+ end