mt-lang 0.2.0 → 0.2.1

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 (189) hide show
  1. checksums.yaml +4 -4
  2. data/docs/index.html +4 -3
  3. data/lib/milk_tea/base.rb +1 -1
  4. data/std/asset_pack.mt +267 -0
  5. data/std/async/libuv_runtime.mt +539 -0
  6. data/std/async/mailbox.mt +191 -0
  7. data/std/async/runtime.mt +87 -0
  8. data/std/async.mt +87 -0
  9. data/std/base64.mt +185 -0
  10. data/std/behavior_tree.mt +396 -0
  11. data/std/binary.mt +314 -0
  12. data/std/binary_heap.mt +157 -0
  13. data/std/bitset.mt +239 -0
  14. data/std/box2d.mt +535 -0
  15. data/std/bytes.mt +46 -0
  16. data/std/c/box2d.mt +1254 -0
  17. data/std/c/cgltf.mt +647 -0
  18. data/std/c/cjson.mt +106 -0
  19. data/std/c/crypto.mt +11 -0
  20. data/std/c/crypto_support.h +51 -0
  21. data/std/c/ctype.mt +19 -0
  22. data/std/c/ctype_bindgen.h +29 -0
  23. data/std/c/curl.mt +1223 -0
  24. data/std/c/enet.mt +473 -0
  25. data/std/c/errno.mt +41 -0
  26. data/std/c/errno_bindgen.h +53 -0
  27. data/std/c/flecs.mt +2945 -0
  28. data/std/c/fs.linux.mt +43 -0
  29. data/std/c/fs.windows.mt +43 -0
  30. data/std/c/fs_support.h +954 -0
  31. data/std/c/gl.mt +2065 -0
  32. data/std/c/gl_registry_helpers.h +10748 -0
  33. data/std/c/glfw.mt +499 -0
  34. data/std/c/libc.mt +167 -0
  35. data/std/c/libuv.mt +1491 -0
  36. data/std/c/math.mt +22 -0
  37. data/std/c/math_bindgen.h +31 -0
  38. data/std/c/miniaudio.mt +3420 -0
  39. data/std/c/pcre2.mt +735 -0
  40. data/std/c/process.mt +58 -0
  41. data/std/c/process_support.h +1147 -0
  42. data/std/c/raygui.mt +1602 -0
  43. data/std/c/raylib.mt +1245 -0
  44. data/std/c/raymath.mt +163 -0
  45. data/std/c/rlgl.mt +434 -0
  46. data/std/c/rpng.mt +60 -0
  47. data/std/c/rres.mt +187 -0
  48. data/std/c/sdl3.mt +4132 -0
  49. data/std/c/sqlite3.mt +951 -0
  50. data/std/c/stb_image.mt +52 -0
  51. data/std/c/stb_image_resize2.mt +128 -0
  52. data/std/c/stb_image_write.mt +19 -0
  53. data/std/c/stb_rect_pack.mt +38 -0
  54. data/std/c/stb_truetype.mt +175 -0
  55. data/std/c/stb_vorbis.mt +31 -0
  56. data/std/c/stdio.mt +90 -0
  57. data/std/c/steamworks.h +5769 -0
  58. data/std/c/steamworks.mt +4771 -0
  59. data/std/c/string.mt +16 -0
  60. data/std/c/string_bindgen.h +36 -0
  61. data/std/c/sync.mt +33 -0
  62. data/std/c/sync_support.h +219 -0
  63. data/std/c/terminal.mt +24 -0
  64. data/std/c/terminal_support.h +408 -0
  65. data/std/c/time.mt +26 -0
  66. data/std/c/tls.mt +24 -0
  67. data/std/c/tls_support.h +626 -0
  68. data/std/c/tracy.mt +53 -0
  69. data/std/c/zlib.mt +20 -0
  70. data/std/c/zlib_support.h +239 -0
  71. data/std/c/zstd.mt +231 -0
  72. data/std/cell.mt +60 -0
  73. data/std/cgltf.mt +115 -0
  74. data/std/cjson.mt +90 -0
  75. data/std/cli.mt +768 -0
  76. data/std/cookie.mt +198 -0
  77. data/std/counter.mt +160 -0
  78. data/std/crypto.mt +74 -0
  79. data/std/cstring.mt +13 -0
  80. data/std/ctype.mt +52 -0
  81. data/std/curl/runtime.mt +261 -0
  82. data/std/curl.mt +38 -0
  83. data/std/deque.mt +348 -0
  84. data/std/encoding.mt +93 -0
  85. data/std/enet.mt +133 -0
  86. data/std/env.mt +41 -0
  87. data/std/errno.mt +47 -0
  88. data/std/flecs.mt +978 -0
  89. data/std/fmt.mt +271 -0
  90. data/std/fs.linux.mt +696 -0
  91. data/std/fs.windows.mt +711 -0
  92. data/std/fsm.mt +267 -0
  93. data/std/gl.mt +2062 -0
  94. data/std/glfw.mt +471 -0
  95. data/std/goap.mt +342 -0
  96. data/std/graph.mt +521 -0
  97. data/std/gzip.mt +77 -0
  98. data/std/hash.mt +429 -0
  99. data/std/http/server.mt +810 -0
  100. data/std/http.mt +1227 -0
  101. data/std/intern.mt +53 -0
  102. data/std/jobs.mt +288 -0
  103. data/std/json.mt +627 -0
  104. data/std/libc.mt +34 -0
  105. data/std/libuv.mt +554 -0
  106. data/std/linear_algebra.mt +243 -0
  107. data/std/linked_map.mt +372 -0
  108. data/std/linked_map_view.mt +49 -0
  109. data/std/linked_set.mt +117 -0
  110. data/std/log.mt +69 -0
  111. data/std/map.mt +418 -0
  112. data/std/math.mt +24 -0
  113. data/std/mem/arena.mt +137 -0
  114. data/std/mem/endian.mt +51 -0
  115. data/std/mem/heap.mt +298 -0
  116. data/std/mem/pool.mt +164 -0
  117. data/std/mem/stack.mt +47 -0
  118. data/std/mem/tracking.mt +119 -0
  119. data/std/miniaudio.mt +1299 -0
  120. data/std/multiset.mt +191 -0
  121. data/std/net/channel.mt +727 -0
  122. data/std/net/clock.mt +237 -0
  123. data/std/net/discovery.mt +277 -0
  124. data/std/net/lobby.mt +813 -0
  125. data/std/net/manager.mt +539 -0
  126. data/std/net/mux.mt +839 -0
  127. data/std/net/nat.mt +122 -0
  128. data/std/net/packet.mt +219 -0
  129. data/std/net/punch.mt +162 -0
  130. data/std/net/rpc.mt +119 -0
  131. data/std/net/session.mt +1157 -0
  132. data/std/net/stun.mt +252 -0
  133. data/std/net/sync.mt +183 -0
  134. data/std/net/turn.mt +459 -0
  135. data/std/net.mt +2944 -0
  136. data/std/oauth2.mt +408 -0
  137. data/std/option.mt +51 -0
  138. data/std/ordered_map.mt +497 -0
  139. data/std/ordered_set.mt +348 -0
  140. data/std/path.mt +368 -0
  141. data/std/pcre2/runtime.mt +35 -0
  142. data/std/pcre2.mt +78 -0
  143. data/std/priority_queue.mt +55 -0
  144. data/std/process.mt +837 -0
  145. data/std/queue.mt +55 -0
  146. data/std/random.mt +146 -0
  147. data/std/raygui.mt +99 -0
  148. data/std/raylib/debug_console.mt +71 -0
  149. data/std/raylib/easing.mt +388 -0
  150. data/std/raylib/packed_assets.mt +255 -0
  151. data/std/raylib/runtime.mt +30 -0
  152. data/std/raylib/tracy_gpu.mt +37 -0
  153. data/std/raylib.mt +1510 -0
  154. data/std/raymath.mt +153 -0
  155. data/std/result.mt +89 -0
  156. data/std/rlgl.mt +268 -0
  157. data/std/rpng.mt +46 -0
  158. data/std/rres.mt +36 -0
  159. data/std/sdl3/runtime.mt +54 -0
  160. data/std/sdl3.mt +1731 -0
  161. data/std/serialize.mt +68 -0
  162. data/std/set.mt +124 -0
  163. data/std/spatial.mt +176 -0
  164. data/std/sqlite3.mt +151 -0
  165. data/std/stack.mt +55 -0
  166. data/std/stb_image.mt +47 -0
  167. data/std/stb_image_resize2.mt +41 -0
  168. data/std/stb_image_write.mt +17 -0
  169. data/std/stb_rect_pack.mt +15 -0
  170. data/std/stb_truetype.mt +77 -0
  171. data/std/stb_vorbis.mt +16 -0
  172. data/std/stdio.mt +88 -0
  173. data/std/steamworks.mt +1542 -0
  174. data/std/str.mt +293 -0
  175. data/std/string.mt +234 -0
  176. data/std/sync.mt +194 -0
  177. data/std/tar.mt +704 -0
  178. data/std/terminal.mt +1002 -0
  179. data/std/testing.mt +266 -0
  180. data/std/thread.mt +120 -0
  181. data/std/time.mt +105 -0
  182. data/std/tls.mt +616 -0
  183. data/std/toml.mt +1310 -0
  184. data/std/tracy.mt +42 -0
  185. data/std/uri.mt +118 -0
  186. data/std/url.mt +372 -0
  187. data/std/vec.mt +433 -0
  188. data/std/zstd.mt +94 -0
  189. metadata +187 -2
@@ -0,0 +1,157 @@
1
+ import std.vec as vec
2
+
3
+ public struct BinaryHeap[T]:
4
+ values: vec.Vec[T]
5
+
6
+ public struct Iter[T]:
7
+ data: ptr[T]?
8
+ index: ptr_uint
9
+ len: ptr_uint
10
+
11
+
12
+ extending BinaryHeap[T]:
13
+ public static function create() -> BinaryHeap[T]:
14
+ return BinaryHeap[T](values = vec.Vec[T].create())
15
+
16
+
17
+ public static function with_capacity(capacity: ptr_uint) -> BinaryHeap[T]:
18
+ var result = BinaryHeap[T].create()
19
+ result.reserve(capacity)
20
+ return result
21
+
22
+
23
+ static function parent_index(index: ptr_uint) -> ptr_uint:
24
+ return (index - 1) / 2
25
+
26
+
27
+ static function left_child_index(index: ptr_uint) -> ptr_uint:
28
+ return (index * 2) + 1
29
+
30
+
31
+ static function right_child_index(index: ptr_uint) -> ptr_uint:
32
+ return (index * 2) + 2
33
+
34
+
35
+ static function slot(current: ref[BinaryHeap[T]], index: ptr_uint) -> ptr[T]:
36
+ let value = current.values.get(index) else:
37
+ fatal(c"binary_heap.BinaryHeap.slot missing value")
38
+
39
+ return unsafe: ptr[T]<-value
40
+
41
+
42
+ static function swap(current: ref[BinaryHeap[T]], left_index: ptr_uint, right_index: ptr_uint) -> void:
43
+ current.values.swap(left_index, right_index)
44
+
45
+
46
+ static function sift_up(current: ref[BinaryHeap[T]], start_index: ptr_uint) -> void:
47
+ var child = start_index
48
+ while child != 0:
49
+ let parent = BinaryHeap[T].parent_index(child)
50
+ let child_value = BinaryHeap[T].slot(current, child)
51
+ let parent_value = BinaryHeap[T].slot(current, parent)
52
+ if order[T](child_value, parent_value) <= 0:
53
+ break
54
+
55
+ BinaryHeap[T].swap(current, child, parent)
56
+ child = parent
57
+
58
+
59
+ static function sift_down(current: ref[BinaryHeap[T]], start_index: ptr_uint) -> void:
60
+ let length = current.values.len()
61
+ if length <= 1:
62
+ return
63
+
64
+ var parent = start_index
65
+ while true:
66
+ let left = BinaryHeap[T].left_child_index(parent)
67
+ if left >= length:
68
+ break
69
+
70
+ var candidate = left
71
+ let right = BinaryHeap[T].right_child_index(parent)
72
+ if right < length:
73
+ let left_value = BinaryHeap[T].slot(current, left)
74
+ let right_value = BinaryHeap[T].slot(current, right)
75
+ if order[T](right_value, left_value) > 0:
76
+ candidate = right
77
+
78
+ let parent_value = BinaryHeap[T].slot(current, parent)
79
+ let candidate_value = BinaryHeap[T].slot(current, candidate)
80
+ if order[T](candidate_value, parent_value) <= 0:
81
+ break
82
+
83
+ BinaryHeap[T].swap(current, parent, candidate)
84
+ parent = candidate
85
+
86
+
87
+ public function len() -> ptr_uint:
88
+ return this.values.len()
89
+
90
+
91
+ public function capacity() -> ptr_uint:
92
+ return this.values.capacity()
93
+
94
+
95
+ public function is_empty() -> bool:
96
+ return this.values.is_empty()
97
+
98
+
99
+ public function iter() -> Iter[T]:
100
+ let view = this.values.as_span()
101
+ return Iter[T](data = view.data, index = 0, len = view.len)
102
+
103
+
104
+ public function peek() -> const_ptr[T]?:
105
+ let current = this.values.get(0) else:
106
+ return null
107
+
108
+ unsafe:
109
+ return const_ptr_of(read(ptr[T]<-current))
110
+
111
+
112
+ public editable function clear() -> void:
113
+ this.values.clear()
114
+
115
+
116
+ public editable function release() -> void:
117
+ this.values.release()
118
+
119
+
120
+ public editable function reserve(min_capacity: ptr_uint) -> void:
121
+ this.values.reserve(min_capacity)
122
+
123
+
124
+ public editable function push(value: T) -> void:
125
+ this.values.push(value)
126
+ BinaryHeap[T].sift_up(this, this.values.len() - 1)
127
+
128
+
129
+ public editable function pop() -> Option[T]:
130
+ let removed = this.values.swap_remove(0)
131
+ match removed:
132
+ Option.none:
133
+ return Option[T].none
134
+ Option.some as payload:
135
+ if not this.values.is_empty():
136
+ BinaryHeap[T].sift_down(this, 0)
137
+ return Option[T].some(value = payload.value)
138
+
139
+
140
+ extending Iter[T]:
141
+ public function iter() -> Iter[T]:
142
+ return this
143
+
144
+
145
+ public editable function next() -> const_ptr[T]?:
146
+ if this.index >= this.len:
147
+ return null
148
+
149
+ let data = this.data else:
150
+ fatal(c"binary_heap.Iter.next missing storage")
151
+
152
+ let current_index = this.index
153
+ this.index += 1
154
+
155
+ unsafe:
156
+ let current = ptr[T]<-data + current_index
157
+ return const_ptr_of(read(current))
data/std/bitset.mt ADDED
@@ -0,0 +1,239 @@
1
+ import std.mem.heap as heap
2
+
3
+ public struct Bitset:
4
+ words: ptr[ptr_uint]?
5
+ word_count: ptr_uint
6
+ bit_count: ptr_uint
7
+
8
+ const WORD_BITS: ptr_uint = 8 * size_of(ptr_uint)
9
+
10
+
11
+ function word_index(bit_index: ptr_uint) -> ptr_uint:
12
+ return bit_index / WORD_BITS
13
+
14
+
15
+ function bit_offset(bit_index: ptr_uint) -> ptr_uint:
16
+ return bit_index % WORD_BITS
17
+
18
+
19
+ function popcount_word(word: ptr_uint) -> ptr_uint:
20
+ var count: ptr_uint = 0
21
+ var value = word
22
+ while value != 0:
23
+ count += 1
24
+ value = value & value - 1
25
+ return count
26
+
27
+
28
+ function find_first_set_in_word(word: ptr_uint) -> Option[ptr_uint]:
29
+ if word == 0:
30
+ return Option[ptr_uint].none
31
+ var index: ptr_uint = 0
32
+ var value = word
33
+ while (value & ptr_uint<-1) == 0:
34
+ value = value >> ptr_uint<-1
35
+ index += 1
36
+ return Option[ptr_uint].some(value = index)
37
+
38
+
39
+ public function create() -> Bitset:
40
+ return Bitset(words = null, word_count = 0, bit_count = 0)
41
+
42
+
43
+ public function with_capacity(min_bits: ptr_uint) -> Bitset:
44
+ var result = create()
45
+ result.reserve(min_bits)
46
+ return result
47
+
48
+
49
+ extending Bitset:
50
+ public function len() -> ptr_uint:
51
+ return this.bit_count
52
+
53
+
54
+ public function is_empty() -> bool:
55
+ return this.bit_count == 0
56
+
57
+
58
+ public editable function set(index: ptr_uint) -> void:
59
+ let wi = word_index(index)
60
+ if wi >= this.word_count:
61
+ this.reserve(index + 1)
62
+ let words = this.words else:
63
+ fatal(c"bitset.set missing storage")
64
+ let bit = bit_offset(index)
65
+ unsafe:
66
+ let word_ptr = words + wi
67
+ read(word_ptr) = read(word_ptr) | ptr_uint<-1 << bit
68
+
69
+
70
+ public editable function clear(index: ptr_uint) -> void:
71
+ let wi = word_index(index)
72
+ if wi >= this.word_count:
73
+ return
74
+ let words = this.words else:
75
+ return
76
+ let bit = bit_offset(index)
77
+ unsafe:
78
+ let word_ptr = words + wi
79
+ read(word_ptr) = read(word_ptr) & ~(ptr_uint<-1 << bit)
80
+
81
+
82
+ public function test(index: ptr_uint) -> bool:
83
+ let wi = word_index(index)
84
+ if wi >= this.word_count:
85
+ return false
86
+ let words = this.words else:
87
+ return false
88
+ let bit = bit_offset(index)
89
+ unsafe:
90
+ let word_ptr = words + wi
91
+ return (read(word_ptr) >> bit & ptr_uint<-1) != 0
92
+
93
+
94
+ public editable function toggle(index: ptr_uint) -> void:
95
+ let wi = word_index(index)
96
+ if wi >= this.word_count:
97
+ this.reserve(index + 1)
98
+ let words = this.words else:
99
+ fatal(c"bitset.toggle missing storage")
100
+ let bit = bit_offset(index)
101
+ unsafe:
102
+ let word_ptr = words + wi
103
+ read(word_ptr) = read(word_ptr) ^ ptr_uint<-1 << bit
104
+
105
+
106
+ public function count() -> ptr_uint:
107
+ if this.words == null:
108
+ return 0
109
+ var total: ptr_uint = 0
110
+ unsafe:
111
+ var wi: ptr_uint = 0
112
+ while wi < this.word_count:
113
+ let w = read(ptr[ptr_uint]<-this.words + wi)
114
+ total += popcount_word(w)
115
+ wi += 1
116
+ return total
117
+
118
+
119
+ public function any() -> bool:
120
+ if this.words == null:
121
+ return false
122
+ unsafe:
123
+ var wi: ptr_uint = 0
124
+ while wi < this.word_count:
125
+ let w = read(ptr[ptr_uint]<-this.words + wi)
126
+ if w != 0:
127
+ return true
128
+ wi += 1
129
+ return false
130
+
131
+
132
+ public function all() -> bool:
133
+ if this.bit_count == 0:
134
+ return false
135
+ if this.words == null:
136
+ return false
137
+ let full_words = this.word_count - 1
138
+ let remaining_bits = this.bit_count - full_words * WORD_BITS
139
+ unsafe:
140
+ var wi: ptr_uint = 0
141
+ while wi < full_words:
142
+ let w = read(ptr[ptr_uint]<-this.words + wi)
143
+ if w != ~ptr_uint<-0:
144
+ return false
145
+ wi += 1
146
+ if remaining_bits > 0:
147
+ let last = read(ptr[ptr_uint]<-this.words + full_words)
148
+ let mask = (ptr_uint<-1 << remaining_bits) - ptr_uint<-1
149
+ if last != mask:
150
+ return false
151
+ return true
152
+
153
+
154
+ public function none() -> bool:
155
+ return not this.any()
156
+
157
+
158
+ public function find_first_set() -> Option[ptr_uint]:
159
+ if this.words == null:
160
+ return Option[ptr_uint].none
161
+ unsafe:
162
+ var wi: ptr_uint = 0
163
+ while wi < this.word_count:
164
+ let w = read(ptr[ptr_uint]<-this.words + wi)
165
+ let found = find_first_set_in_word(w)
166
+ match found:
167
+ Option.some as payload:
168
+ return Option[ptr_uint].some(value = wi * WORD_BITS + payload.value)
169
+ Option.none:
170
+ pass
171
+ wi += 1
172
+ return Option[ptr_uint].none
173
+
174
+
175
+ public function find_first_clear() -> Option[ptr_uint]:
176
+ if this.bit_count == 0:
177
+ return Option[ptr_uint].some(value = 0)
178
+ if this.words == null:
179
+ return Option[ptr_uint].some(value = 0)
180
+ let full_words = this.word_count - 1
181
+ let remaining_bits = this.bit_count - full_words * WORD_BITS
182
+ unsafe:
183
+ var wi: ptr_uint = 0
184
+ while wi < full_words:
185
+ let w = read(ptr[ptr_uint]<-this.words + wi)
186
+ if w != ~ptr_uint<-0:
187
+ let inverted = ~w
188
+ let found = find_first_set_in_word(inverted)
189
+ match found:
190
+ Option.some as payload:
191
+ return Option[ptr_uint].some(value = wi * WORD_BITS + payload.value)
192
+ Option.none:
193
+ pass
194
+ wi += 1
195
+ if remaining_bits > 0:
196
+ let last = read(ptr[ptr_uint]<-this.words + full_words)
197
+ let mask = (ptr_uint<-1 << remaining_bits) - ptr_uint<-1
198
+ if last != mask:
199
+ let inverted = ~last & mask
200
+ let found = find_first_set_in_word(inverted)
201
+ match found:
202
+ Option.some as payload:
203
+ return Option[ptr_uint].some(value = full_words * WORD_BITS + payload.value)
204
+ Option.none:
205
+ pass
206
+ return Option[ptr_uint].some(value = this.bit_count)
207
+
208
+
209
+ public editable function clear_all() -> void:
210
+ if this.words == null:
211
+ return
212
+ unsafe:
213
+ var wi: ptr_uint = 0
214
+ while wi < this.word_count:
215
+ read(ptr[ptr_uint]<-this.words + wi) = 0
216
+ wi += 1
217
+
218
+
219
+ public editable function reserve(min_bits: ptr_uint) -> void:
220
+ if min_bits <= this.bit_count:
221
+ return
222
+ let new_word_count = word_index(min_bits + WORD_BITS - 1)
223
+ let resized = heap.resize[ptr_uint](this.words, new_word_count) else:
224
+ fatal(c"bitset.reserve out of memory")
225
+ this.words = resized
226
+ unsafe:
227
+ var wi = this.word_count
228
+ while wi < new_word_count:
229
+ read(ptr[ptr_uint]<-this.words + wi) = 0
230
+ wi += 1
231
+ this.word_count = new_word_count
232
+ this.bit_count = new_word_count * WORD_BITS
233
+
234
+
235
+ public editable function release() -> void:
236
+ heap.release(this.words)
237
+ this.words = null
238
+ this.word_count = 0
239
+ this.bit_count = 0