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.
- checksums.yaml +4 -4
- data/docs/index.html +4 -3
- data/lib/milk_tea/base.rb +1 -1
- data/std/asset_pack.mt +267 -0
- data/std/async/libuv_runtime.mt +539 -0
- data/std/async/mailbox.mt +191 -0
- data/std/async/runtime.mt +87 -0
- data/std/async.mt +87 -0
- data/std/base64.mt +185 -0
- data/std/behavior_tree.mt +396 -0
- data/std/binary.mt +314 -0
- data/std/binary_heap.mt +157 -0
- data/std/bitset.mt +239 -0
- data/std/box2d.mt +535 -0
- data/std/bytes.mt +46 -0
- data/std/c/box2d.mt +1254 -0
- data/std/c/cgltf.mt +647 -0
- data/std/c/cjson.mt +106 -0
- data/std/c/crypto.mt +11 -0
- data/std/c/crypto_support.h +51 -0
- data/std/c/ctype.mt +19 -0
- data/std/c/ctype_bindgen.h +29 -0
- data/std/c/curl.mt +1223 -0
- data/std/c/enet.mt +473 -0
- data/std/c/errno.mt +41 -0
- data/std/c/errno_bindgen.h +53 -0
- data/std/c/flecs.mt +2945 -0
- data/std/c/fs.linux.mt +43 -0
- data/std/c/fs.windows.mt +43 -0
- data/std/c/fs_support.h +954 -0
- data/std/c/gl.mt +2065 -0
- data/std/c/gl_registry_helpers.h +10748 -0
- data/std/c/glfw.mt +499 -0
- data/std/c/libc.mt +167 -0
- data/std/c/libuv.mt +1491 -0
- data/std/c/math.mt +22 -0
- data/std/c/math_bindgen.h +31 -0
- data/std/c/miniaudio.mt +3420 -0
- data/std/c/pcre2.mt +735 -0
- data/std/c/process.mt +58 -0
- data/std/c/process_support.h +1147 -0
- data/std/c/raygui.mt +1602 -0
- data/std/c/raylib.mt +1245 -0
- data/std/c/raymath.mt +163 -0
- data/std/c/rlgl.mt +434 -0
- data/std/c/rpng.mt +60 -0
- data/std/c/rres.mt +187 -0
- data/std/c/sdl3.mt +4132 -0
- data/std/c/sqlite3.mt +951 -0
- data/std/c/stb_image.mt +52 -0
- data/std/c/stb_image_resize2.mt +128 -0
- data/std/c/stb_image_write.mt +19 -0
- data/std/c/stb_rect_pack.mt +38 -0
- data/std/c/stb_truetype.mt +175 -0
- data/std/c/stb_vorbis.mt +31 -0
- data/std/c/stdio.mt +90 -0
- data/std/c/steamworks.h +5769 -0
- data/std/c/steamworks.mt +4771 -0
- data/std/c/string.mt +16 -0
- data/std/c/string_bindgen.h +36 -0
- data/std/c/sync.mt +33 -0
- data/std/c/sync_support.h +219 -0
- data/std/c/terminal.mt +24 -0
- data/std/c/terminal_support.h +408 -0
- data/std/c/time.mt +26 -0
- data/std/c/tls.mt +24 -0
- data/std/c/tls_support.h +626 -0
- data/std/c/tracy.mt +53 -0
- data/std/c/zlib.mt +20 -0
- data/std/c/zlib_support.h +239 -0
- data/std/c/zstd.mt +231 -0
- data/std/cell.mt +60 -0
- data/std/cgltf.mt +115 -0
- data/std/cjson.mt +90 -0
- data/std/cli.mt +768 -0
- data/std/cookie.mt +198 -0
- data/std/counter.mt +160 -0
- data/std/crypto.mt +74 -0
- data/std/cstring.mt +13 -0
- data/std/ctype.mt +52 -0
- data/std/curl/runtime.mt +261 -0
- data/std/curl.mt +38 -0
- data/std/deque.mt +348 -0
- data/std/encoding.mt +93 -0
- data/std/enet.mt +133 -0
- data/std/env.mt +41 -0
- data/std/errno.mt +47 -0
- data/std/flecs.mt +978 -0
- data/std/fmt.mt +271 -0
- data/std/fs.linux.mt +696 -0
- data/std/fs.windows.mt +711 -0
- data/std/fsm.mt +267 -0
- data/std/gl.mt +2062 -0
- data/std/glfw.mt +471 -0
- data/std/goap.mt +342 -0
- data/std/graph.mt +521 -0
- data/std/gzip.mt +77 -0
- data/std/hash.mt +429 -0
- data/std/http/server.mt +810 -0
- data/std/http.mt +1227 -0
- data/std/intern.mt +53 -0
- data/std/jobs.mt +288 -0
- data/std/json.mt +627 -0
- data/std/libc.mt +34 -0
- data/std/libuv.mt +554 -0
- data/std/linear_algebra.mt +243 -0
- data/std/linked_map.mt +372 -0
- data/std/linked_map_view.mt +49 -0
- data/std/linked_set.mt +117 -0
- data/std/log.mt +69 -0
- data/std/map.mt +418 -0
- data/std/math.mt +24 -0
- data/std/mem/arena.mt +137 -0
- data/std/mem/endian.mt +51 -0
- data/std/mem/heap.mt +298 -0
- data/std/mem/pool.mt +164 -0
- data/std/mem/stack.mt +47 -0
- data/std/mem/tracking.mt +119 -0
- data/std/miniaudio.mt +1299 -0
- data/std/multiset.mt +191 -0
- data/std/net/channel.mt +727 -0
- data/std/net/clock.mt +237 -0
- data/std/net/discovery.mt +277 -0
- data/std/net/lobby.mt +813 -0
- data/std/net/manager.mt +539 -0
- data/std/net/mux.mt +839 -0
- data/std/net/nat.mt +122 -0
- data/std/net/packet.mt +219 -0
- data/std/net/punch.mt +162 -0
- data/std/net/rpc.mt +119 -0
- data/std/net/session.mt +1157 -0
- data/std/net/stun.mt +252 -0
- data/std/net/sync.mt +183 -0
- data/std/net/turn.mt +459 -0
- data/std/net.mt +2944 -0
- data/std/oauth2.mt +408 -0
- data/std/option.mt +51 -0
- data/std/ordered_map.mt +497 -0
- data/std/ordered_set.mt +348 -0
- data/std/path.mt +368 -0
- data/std/pcre2/runtime.mt +35 -0
- data/std/pcre2.mt +78 -0
- data/std/priority_queue.mt +55 -0
- data/std/process.mt +837 -0
- data/std/queue.mt +55 -0
- data/std/random.mt +146 -0
- data/std/raygui.mt +99 -0
- data/std/raylib/debug_console.mt +71 -0
- data/std/raylib/easing.mt +388 -0
- data/std/raylib/packed_assets.mt +255 -0
- data/std/raylib/runtime.mt +30 -0
- data/std/raylib/tracy_gpu.mt +37 -0
- data/std/raylib.mt +1510 -0
- data/std/raymath.mt +153 -0
- data/std/result.mt +89 -0
- data/std/rlgl.mt +268 -0
- data/std/rpng.mt +46 -0
- data/std/rres.mt +36 -0
- data/std/sdl3/runtime.mt +54 -0
- data/std/sdl3.mt +1731 -0
- data/std/serialize.mt +68 -0
- data/std/set.mt +124 -0
- data/std/spatial.mt +176 -0
- data/std/sqlite3.mt +151 -0
- data/std/stack.mt +55 -0
- data/std/stb_image.mt +47 -0
- data/std/stb_image_resize2.mt +41 -0
- data/std/stb_image_write.mt +17 -0
- data/std/stb_rect_pack.mt +15 -0
- data/std/stb_truetype.mt +77 -0
- data/std/stb_vorbis.mt +16 -0
- data/std/stdio.mt +88 -0
- data/std/steamworks.mt +1542 -0
- data/std/str.mt +293 -0
- data/std/string.mt +234 -0
- data/std/sync.mt +194 -0
- data/std/tar.mt +704 -0
- data/std/terminal.mt +1002 -0
- data/std/testing.mt +266 -0
- data/std/thread.mt +120 -0
- data/std/time.mt +105 -0
- data/std/tls.mt +616 -0
- data/std/toml.mt +1310 -0
- data/std/tracy.mt +42 -0
- data/std/uri.mt +118 -0
- data/std/url.mt +372 -0
- data/std/vec.mt +433 -0
- data/std/zstd.mt +94 -0
- metadata +187 -2
data/std/fmt.mt
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import std.c.stdio as c
|
|
2
|
+
import std.str as text_ops
|
|
3
|
+
import std.string as string
|
|
4
|
+
|
|
5
|
+
const float_buffer_capacity: ptr_uint = 64
|
|
6
|
+
const integer_digit_buffer_capacity: ptr_uint = 64
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
public function append(output: ref[string.String], text: str) -> void:
|
|
10
|
+
output.append(text)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
public function format(text: str) -> string.String:
|
|
14
|
+
return string.String.from_str(text)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
public function append_format(output: ref[string.String], text: str) -> void:
|
|
18
|
+
output.append(text)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
public function assign_format(output: ref[string.String], text: str) -> void:
|
|
22
|
+
output.clear()
|
|
23
|
+
output.append(text)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
public function append_str(output: ref[string.String], text: str) -> void:
|
|
27
|
+
append(output, text)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
public function append_cstr(output: ref[string.String], c_text: cstr) -> void:
|
|
31
|
+
output.append(text_ops.cstr_as_str(c_text))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
public function append_bool(output: ref[string.String], bool_value: bool) -> void:
|
|
35
|
+
if bool_value:
|
|
36
|
+
output.append("true")
|
|
37
|
+
else:
|
|
38
|
+
output.append("false")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function append_formatted_float(output: ref[string.String], format: cstr, number: double) -> void:
|
|
42
|
+
var buffer = zero[array[char, 64]]
|
|
43
|
+
let written = c.snprintf(ptr_of(buffer[0]), float_buffer_capacity, format, number)
|
|
44
|
+
if written < 0 or ptr_uint<-written >= float_buffer_capacity:
|
|
45
|
+
fatal("fmt could not format float")
|
|
46
|
+
|
|
47
|
+
output.append(text_ops.chars_as_str(ptr_of(buffer[0])))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
public function append_float(output: ref[string.String], number: float) -> void:
|
|
51
|
+
append_formatted_float(output, c"%g", double<-number)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public function append_double(output: ref[string.String], number: double) -> void:
|
|
55
|
+
append_formatted_float(output, c"%g", number)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public function append_double_precision(output: ref[string.String], number: double, precision: int) -> void:
|
|
59
|
+
var buffer = zero[array[char, 64]]
|
|
60
|
+
let written = c.snprintf(ptr_of(buffer[0]), float_buffer_capacity, c"%.*f", precision, number)
|
|
61
|
+
if written < 0 or ptr_uint<-written >= float_buffer_capacity:
|
|
62
|
+
fatal("fmt could not format float with precision")
|
|
63
|
+
|
|
64
|
+
output.append(text_ops.chars_as_str(ptr_of(buffer[0])))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
function radix_digit_byte(digit: ulong, uppercase: bool) -> ubyte:
|
|
68
|
+
if digit < 10:
|
|
69
|
+
return ubyte<-(48ul + digit)
|
|
70
|
+
|
|
71
|
+
if uppercase:
|
|
72
|
+
return ubyte<-(65ul + (digit - 10))
|
|
73
|
+
|
|
74
|
+
return ubyte<-(97ul + (digit - 10))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
function append_ulong_radix(output: ref[string.String], number: ulong, base: ulong, uppercase: bool) -> void:
|
|
78
|
+
if number == 0:
|
|
79
|
+
output.push_byte(48)
|
|
80
|
+
return
|
|
81
|
+
|
|
82
|
+
var digits: array[ubyte, 64]
|
|
83
|
+
var count: ptr_uint = 0
|
|
84
|
+
var remaining = number
|
|
85
|
+
while remaining != 0:
|
|
86
|
+
let digit = remaining % base
|
|
87
|
+
digits[count] = radix_digit_byte(digit, uppercase)
|
|
88
|
+
remaining = remaining / base
|
|
89
|
+
count += 1
|
|
90
|
+
|
|
91
|
+
while count > 0:
|
|
92
|
+
count -= 1
|
|
93
|
+
output.push_byte(digits[count])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
public function append_ulong_hex(output: ref[string.String], number: ulong) -> void:
|
|
97
|
+
append_ulong_radix(output, number, 16, false)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
public function append_ulong_hex_upper(output: ref[string.String], number: ulong) -> void:
|
|
101
|
+
append_ulong_radix(output, number, 16, true)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
public function append_long_hex(output: ref[string.String], number: long) -> void:
|
|
105
|
+
if number < 0:
|
|
106
|
+
output.append("-")
|
|
107
|
+
append_ulong_hex(output, ulong<-(-(number + 1)) + 1)
|
|
108
|
+
return
|
|
109
|
+
|
|
110
|
+
append_ulong_hex(output, ulong<-number)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
public function append_long_hex_upper(output: ref[string.String], number: long) -> void:
|
|
114
|
+
if number < 0:
|
|
115
|
+
output.append("-")
|
|
116
|
+
append_ulong_hex_upper(output, ulong<-(-(number + 1)) + 1)
|
|
117
|
+
return
|
|
118
|
+
|
|
119
|
+
append_ulong_hex_upper(output, ulong<-number)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
public function append_ulong_oct(output: ref[string.String], number: ulong) -> void:
|
|
123
|
+
append_ulong_radix(output, number, 8, false)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
public function append_long_oct(output: ref[string.String], number: long) -> void:
|
|
127
|
+
if number < 0:
|
|
128
|
+
output.append("-")
|
|
129
|
+
append_ulong_oct(output, ulong<-(-(number + 1)) + 1)
|
|
130
|
+
return
|
|
131
|
+
|
|
132
|
+
append_ulong_oct(output, ulong<-number)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
public function append_ulong_bin(output: ref[string.String], number: ulong) -> void:
|
|
136
|
+
append_ulong_radix(output, number, 2, false)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
public function append_long_bin(output: ref[string.String], number: long) -> void:
|
|
140
|
+
if number < 0:
|
|
141
|
+
output.append("-")
|
|
142
|
+
append_ulong_bin(output, ulong<-(-(number + 1)) + 1)
|
|
143
|
+
return
|
|
144
|
+
|
|
145
|
+
append_ulong_bin(output, ulong<-number)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
public function append_ptr_uint(output: ref[string.String], number: ptr_uint) -> void:
|
|
149
|
+
if number == 0:
|
|
150
|
+
output.push_byte(48)
|
|
151
|
+
return
|
|
152
|
+
|
|
153
|
+
var digits: array[ubyte, 32]
|
|
154
|
+
var count: ptr_uint = 0
|
|
155
|
+
var remaining = number
|
|
156
|
+
while remaining != 0:
|
|
157
|
+
let digit = remaining % 10
|
|
158
|
+
digits[count] = ubyte<-(48z + digit)
|
|
159
|
+
remaining = remaining / 10
|
|
160
|
+
count += 1
|
|
161
|
+
|
|
162
|
+
while count > 0:
|
|
163
|
+
count -= 1
|
|
164
|
+
output.push_byte(digits[count])
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
public function append_ulong(output: ref[string.String], number: ulong) -> void:
|
|
168
|
+
if number == 0:
|
|
169
|
+
output.push_byte(48)
|
|
170
|
+
return
|
|
171
|
+
|
|
172
|
+
var digits: array[ubyte, 32]
|
|
173
|
+
var count: ptr_uint = 0
|
|
174
|
+
var remaining = number
|
|
175
|
+
while remaining != 0:
|
|
176
|
+
let digit = remaining % 10
|
|
177
|
+
digits[count] = ubyte<-(48ul + digit)
|
|
178
|
+
remaining = remaining / 10
|
|
179
|
+
count += 1
|
|
180
|
+
|
|
181
|
+
while count > 0:
|
|
182
|
+
count -= 1
|
|
183
|
+
output.push_byte(digits[count])
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
public function append_uint(output: ref[string.String], number: uint) -> void:
|
|
187
|
+
append_ptr_uint(output, ptr_uint<-number)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
public function append_long(output: ref[string.String], number: long) -> void:
|
|
191
|
+
if number < 0:
|
|
192
|
+
output.append("-")
|
|
193
|
+
append_ulong(output, ulong<-(-(number + 1)) + 1)
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
append_ulong(output, ulong<-number)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
public function append_int(output: ref[string.String], number: int) -> void:
|
|
200
|
+
if number < 0:
|
|
201
|
+
output.append("-")
|
|
202
|
+
append_ptr_uint(output, ptr_uint<-(-(long<-number)))
|
|
203
|
+
return
|
|
204
|
+
|
|
205
|
+
append_ptr_uint(output, ptr_uint<-number)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
public function to_string_ptr_uint(value: ptr_uint) -> string.String:
|
|
209
|
+
var result = string.String.create()
|
|
210
|
+
append_ptr_uint(ref_of(result), value)
|
|
211
|
+
return result
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
public function to_string_int(value: int) -> string.String:
|
|
215
|
+
var result = string.String.create()
|
|
216
|
+
append_int(ref_of(result), value)
|
|
217
|
+
return result
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
# Reflective debug formatter for any value. Scalars render directly; a struct
|
|
221
|
+
# renders as `{ field = value, ... }`, recursing into each field via its
|
|
222
|
+
# compile-time `field.type`. Types other than the listed primitives and structs
|
|
223
|
+
# of such fields are unsupported (they fail at specialization).
|
|
224
|
+
public function format_value[T](output: ref[string.String], value: const_ptr[T]) -> void:
|
|
225
|
+
unsafe:
|
|
226
|
+
inline if T == int:
|
|
227
|
+
append_int(output, read(ptr[int]<-value))
|
|
228
|
+
else if T == uint:
|
|
229
|
+
append_uint(output, read(ptr[uint]<-value))
|
|
230
|
+
else if T == long:
|
|
231
|
+
append_long(output, read(ptr[long]<-value))
|
|
232
|
+
else if T == ulong:
|
|
233
|
+
append_ulong(output, read(ptr[ulong]<-value))
|
|
234
|
+
else if T == ptr_uint:
|
|
235
|
+
append_ptr_uint(output, read(ptr[ptr_uint]<-value))
|
|
236
|
+
else if T == ptr_int:
|
|
237
|
+
append_long(output, long<-read(ptr[ptr_int]<-value))
|
|
238
|
+
else if T == byte:
|
|
239
|
+
append_int(output, int<-read(ptr[byte]<-value))
|
|
240
|
+
else if T == short:
|
|
241
|
+
append_int(output, int<-read(ptr[short]<-value))
|
|
242
|
+
else if T == ubyte:
|
|
243
|
+
append_uint(output, uint<-read(ptr[ubyte]<-value))
|
|
244
|
+
else if T == ushort:
|
|
245
|
+
append_uint(output, uint<-read(ptr[ushort]<-value))
|
|
246
|
+
else if T == char:
|
|
247
|
+
append_int(output, int<-read(ptr[char]<-value))
|
|
248
|
+
else if T == bool:
|
|
249
|
+
append_bool(output, read(ptr[bool]<-value))
|
|
250
|
+
else if T == float:
|
|
251
|
+
append_float(output, read(ptr[float]<-value))
|
|
252
|
+
else if T == double:
|
|
253
|
+
append_double(output, read(ptr[double]<-value))
|
|
254
|
+
else if T == str:
|
|
255
|
+
append_str(output, read(ptr[str]<-value))
|
|
256
|
+
else if T == cstr:
|
|
257
|
+
append_cstr(output, read(ptr[cstr]<-value))
|
|
258
|
+
else:
|
|
259
|
+
output.append("{ ")
|
|
260
|
+
var first = true
|
|
261
|
+
inline for field in fields_of(T):
|
|
262
|
+
if not first:
|
|
263
|
+
output.append(", ")
|
|
264
|
+
|
|
265
|
+
first = false
|
|
266
|
+
output.append(field.name)
|
|
267
|
+
output.append(" = ")
|
|
268
|
+
let offset = offset_of(T, field)
|
|
269
|
+
format_value[field.type](output, const_ptr[field.type]<-(ptr[ubyte]<-value + offset))
|
|
270
|
+
|
|
271
|
+
output.append(" }")
|