mt-lang 0.2.0 → 0.2.2
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/README.md +12 -0
- data/Rakefile +1 -1
- data/docs/index.html +13 -3
- data/lib/milk_tea/base.rb +7 -2
- 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/sync.mt
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import std.c.sync as c
|
|
2
|
+
import std.libuv as libuv
|
|
3
|
+
import std.str as text
|
|
4
|
+
import std.string as string
|
|
5
|
+
|
|
6
|
+
public struct Error:
|
|
7
|
+
code: int
|
|
8
|
+
message: string.String
|
|
9
|
+
|
|
10
|
+
public struct Mutex:
|
|
11
|
+
handle: ptr[c.mt_mutex]?
|
|
12
|
+
|
|
13
|
+
public struct Condition:
|
|
14
|
+
handle: ptr[c.mt_condition]?
|
|
15
|
+
|
|
16
|
+
public struct Semaphore:
|
|
17
|
+
handle: ptr[c.mt_semaphore]?
|
|
18
|
+
|
|
19
|
+
public struct AtomicUint:
|
|
20
|
+
handle: ptr[c.mt_atomic_uint]?
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function libuv_error(code: int) -> Error:
|
|
24
|
+
return Error(code = code, message = string.String.from_str(text.cstr_as_str(libuv.strerror(code))))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
function mutex_handle(handle: ptr[c.mt_mutex]?) -> ptr[c.mt_mutex]:
|
|
28
|
+
let live_handle = handle else:
|
|
29
|
+
fatal(c"sync mutex is released")
|
|
30
|
+
|
|
31
|
+
return live_handle
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function condition_handle(handle: ptr[c.mt_condition]?) -> ptr[c.mt_condition]:
|
|
35
|
+
let live_handle = handle else:
|
|
36
|
+
fatal(c"sync condition is released")
|
|
37
|
+
|
|
38
|
+
return live_handle
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function semaphore_handle(handle: ptr[c.mt_semaphore]?) -> ptr[c.mt_semaphore]:
|
|
42
|
+
let live_handle = handle else:
|
|
43
|
+
fatal(c"sync semaphore is released")
|
|
44
|
+
|
|
45
|
+
return live_handle
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
public function create_mutex() -> Result[Mutex, Error]:
|
|
49
|
+
var handle: ptr[c.mt_mutex]? = null
|
|
50
|
+
let status_code = c.mt_mutex_create(handle)
|
|
51
|
+
if status_code != 0:
|
|
52
|
+
return Result[Mutex, Error].failure(error = libuv_error(status_code))
|
|
53
|
+
|
|
54
|
+
return Result[Mutex, Error].success(value = Mutex(handle = handle))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
public function create_recursive_mutex() -> Result[Mutex, Error]:
|
|
58
|
+
var handle: ptr[c.mt_mutex]? = null
|
|
59
|
+
let status_code = c.mt_mutex_create_recursive(handle)
|
|
60
|
+
if status_code != 0:
|
|
61
|
+
return Result[Mutex, Error].failure(error = libuv_error(status_code))
|
|
62
|
+
|
|
63
|
+
return Result[Mutex, Error].success(value = Mutex(handle = handle))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
public function create_condition() -> Result[Condition, Error]:
|
|
67
|
+
var handle: ptr[c.mt_condition]? = null
|
|
68
|
+
let status_code = c.mt_condition_create(handle)
|
|
69
|
+
if status_code != 0:
|
|
70
|
+
return Result[Condition, Error].failure(error = libuv_error(status_code))
|
|
71
|
+
|
|
72
|
+
return Result[Condition, Error].success(value = Condition(handle = handle))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
public function create_semaphore(initial_value: uint) -> Result[Semaphore, Error]:
|
|
76
|
+
var handle: ptr[c.mt_semaphore]? = null
|
|
77
|
+
let status_code = c.mt_semaphore_create(initial_value, handle)
|
|
78
|
+
if status_code != 0:
|
|
79
|
+
return Result[Semaphore, Error].failure(error = libuv_error(status_code))
|
|
80
|
+
|
|
81
|
+
return Result[Semaphore, Error].success(value = Semaphore(handle = handle))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
extending Error:
|
|
85
|
+
public editable function release() -> void:
|
|
86
|
+
this.message.release()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
extending Mutex:
|
|
90
|
+
public editable function release() -> void:
|
|
91
|
+
let handle = this.handle else:
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
c.mt_mutex_destroy(handle)
|
|
95
|
+
this.handle = null
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
public function lock() -> void:
|
|
99
|
+
c.mt_mutex_lock(mutex_handle(this.handle))
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
public function try_lock() -> bool:
|
|
103
|
+
return c.mt_mutex_try_lock(mutex_handle(this.handle)) == 0
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
public function unlock() -> void:
|
|
107
|
+
c.mt_mutex_unlock(mutex_handle(this.handle))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
extending Condition:
|
|
111
|
+
public editable function release() -> void:
|
|
112
|
+
let handle = this.handle else:
|
|
113
|
+
return
|
|
114
|
+
|
|
115
|
+
c.mt_condition_destroy(handle)
|
|
116
|
+
this.handle = null
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
public function signal() -> void:
|
|
120
|
+
c.mt_condition_signal(condition_handle(this.handle))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
public function broadcast() -> void:
|
|
124
|
+
c.mt_condition_broadcast(condition_handle(this.handle))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
public function wait(mutex: Mutex) -> void:
|
|
128
|
+
c.mt_condition_wait(condition_handle(this.handle), mutex_handle(mutex.handle))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
extending Semaphore:
|
|
132
|
+
public editable function release() -> void:
|
|
133
|
+
let handle = this.handle else:
|
|
134
|
+
return
|
|
135
|
+
|
|
136
|
+
c.mt_semaphore_destroy(handle)
|
|
137
|
+
this.handle = null
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
public function post() -> void:
|
|
141
|
+
c.mt_semaphore_post(semaphore_handle(this.handle))
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
public function wait() -> void:
|
|
145
|
+
c.mt_semaphore_wait(semaphore_handle(this.handle))
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
public function try_wait() -> bool:
|
|
149
|
+
return c.mt_semaphore_try_wait(semaphore_handle(this.handle)) == 0
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
public function create_atomic_uint(initial_value: uint) -> AtomicUint:
|
|
153
|
+
var handle: ptr[c.mt_atomic_uint]? = null
|
|
154
|
+
let status_code = c.mt_atomic_uint_create(handle, initial_value)
|
|
155
|
+
if status_code != 0:
|
|
156
|
+
fatal(c"sync.create_atomic_uint failed")
|
|
157
|
+
|
|
158
|
+
return AtomicUint(handle = handle)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
function atomic_handle(handle: ptr[c.mt_atomic_uint]?) -> ptr[c.mt_atomic_uint]:
|
|
162
|
+
let live_handle = handle else:
|
|
163
|
+
fatal(c"sync AtomicUint is released")
|
|
164
|
+
|
|
165
|
+
return live_handle
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
extending AtomicUint:
|
|
169
|
+
public editable function release() -> void:
|
|
170
|
+
let handle = this.handle else:
|
|
171
|
+
return
|
|
172
|
+
|
|
173
|
+
c.mt_atomic_uint_destroy(handle)
|
|
174
|
+
this.handle = null
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
public function load() -> uint:
|
|
178
|
+
return c.mt_atomic_uint_load(atomic_handle(this.handle))
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
public editable function store(new_value: uint) -> void:
|
|
182
|
+
c.mt_atomic_uint_store(atomic_handle(this.handle), new_value)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
public editable function fetch_add(delta: uint) -> uint:
|
|
186
|
+
return c.mt_atomic_uint_fetch_add(atomic_handle(this.handle), delta)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
public editable function fetch_sub(delta: uint) -> uint:
|
|
190
|
+
return c.mt_atomic_uint_fetch_sub(atomic_handle(this.handle), delta)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
public editable function compare_exchange(expected: ref[uint], desired: uint) -> bool:
|
|
194
|
+
return c.mt_atomic_uint_compare_exchange(atomic_handle(this.handle), ptr_of(expected), desired)
|