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/curl/runtime.mt
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import std.bytes as bytes
|
|
2
|
+
import std.curl as curl
|
|
3
|
+
import std.c.curl as c
|
|
4
|
+
import std.mem.arena as arena
|
|
5
|
+
import std.mem.heap as heap
|
|
6
|
+
import std.str as text
|
|
7
|
+
import std.string as string
|
|
8
|
+
import std.vec as vec
|
|
9
|
+
|
|
10
|
+
const CURLE_OK_CODE: int = 0
|
|
11
|
+
const CURLE_FAILED_INIT_CODE: int = 2
|
|
12
|
+
const CURLE_URL_MALFORMAT_CODE: int = 3
|
|
13
|
+
|
|
14
|
+
foreign function easy_setopt_writedata(curl_handle: ptr[c.CURL], user_data: ptr[void]) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-10001, user_data)
|
|
15
|
+
foreign function easy_setopt_url(curl_handle: ptr[c.CURL], url: cstr) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-10002, url)
|
|
16
|
+
foreign function easy_setopt_writefunction(curl_handle: ptr[c.CURL], write_callback: c.curl_write_callback) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-20011, write_callback)
|
|
17
|
+
foreign function easy_setopt_followlocation(curl_handle: ptr[c.CURL], follow: ptr_int) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-52, follow)
|
|
18
|
+
foreign function easy_setopt_timeout(curl_handle: ptr[c.CURL], timeout: int) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-13, timeout)
|
|
19
|
+
foreign function easy_setopt_postfields(curl_handle: ptr[c.CURL], body: cstr) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-10015, body)
|
|
20
|
+
foreign function easy_setopt_customrequest(curl_handle: ptr[c.CURL], method: cstr) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-10036, method)
|
|
21
|
+
foreign function easy_setopt_nobody(curl_handle: ptr[c.CURL]) -> c.CURLcode = c.curl_easy_setopt(curl_handle, c.CURLoption<-44, 1)
|
|
22
|
+
foreign function easy_getinfo_long(curl_handle: ptr[c.CURL], value: ptr[int]) -> c.CURLcode = c.curl_easy_getinfo(curl_handle, c.CURLINFO<-2097154, value)
|
|
23
|
+
|
|
24
|
+
public struct HttpError:
|
|
25
|
+
code: curl.Code
|
|
26
|
+
message: string.String
|
|
27
|
+
|
|
28
|
+
public struct HttpResponse:
|
|
29
|
+
status_code: int
|
|
30
|
+
body: bytes.Bytes
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
extending HttpError:
|
|
34
|
+
public editable function release() -> void:
|
|
35
|
+
this.message.release()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
extending HttpResponse:
|
|
39
|
+
public editable function release() -> void:
|
|
40
|
+
this.body.release()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
public function body_as_str() -> Option[str]:
|
|
44
|
+
return this.body.as_str()
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
function write_response_chunk(data: ptr[char], size: ptr_uint, count: ptr_uint, user_data: ptr[void]) -> ptr_uint:
|
|
48
|
+
if size != 0 and count > heap.ptr_uint_max / size:
|
|
49
|
+
return 0
|
|
50
|
+
|
|
51
|
+
let total = size * count
|
|
52
|
+
if total == 0:
|
|
53
|
+
return 0
|
|
54
|
+
|
|
55
|
+
unsafe:
|
|
56
|
+
let buffer = ptr[vec.Vec[ubyte]]<-user_data
|
|
57
|
+
let chunk = span[ubyte](data = ptr[ubyte]<-data, len = total)
|
|
58
|
+
read(buffer).append_span(chunk)
|
|
59
|
+
|
|
60
|
+
return total
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
public function code_message(code: curl.Code) -> str:
|
|
64
|
+
return text.cstr_as_str(curl.easy_strerror(code))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
public function get_bytes(url: str) -> Result[bytes.Bytes, curl.Code]:
|
|
68
|
+
if url.len == heap.ptr_uint_max:
|
|
69
|
+
return Result[bytes.Bytes, curl.Code].failure(error= curl.Code<-CURLE_URL_MALFORMAT_CODE)
|
|
70
|
+
|
|
71
|
+
var scratch = arena.create(url.len + 1)
|
|
72
|
+
defer scratch.release()
|
|
73
|
+
|
|
74
|
+
let url_cstr = scratch.to_cstr(url)
|
|
75
|
+
|
|
76
|
+
let global_status = curl.global_init(curl.CURL_GLOBAL_NOTHING)
|
|
77
|
+
if int<-global_status != CURLE_OK_CODE:
|
|
78
|
+
return Result[bytes.Bytes, curl.Code].failure(error= global_status)
|
|
79
|
+
defer curl.global_cleanup()
|
|
80
|
+
|
|
81
|
+
let handle = curl.easy_init() else:
|
|
82
|
+
return Result[bytes.Bytes, curl.Code].failure(error= curl.Code<-CURLE_FAILED_INIT_CODE)
|
|
83
|
+
defer curl.easy_cleanup(handle)
|
|
84
|
+
|
|
85
|
+
var body = vec.Vec[ubyte].create()
|
|
86
|
+
defer body.release()
|
|
87
|
+
|
|
88
|
+
let write_function_status = easy_setopt_writefunction(handle, write_response_chunk)
|
|
89
|
+
if int<-write_function_status != CURLE_OK_CODE:
|
|
90
|
+
return Result[bytes.Bytes, curl.Code].failure(error= write_function_status)
|
|
91
|
+
|
|
92
|
+
let write_data_status = easy_setopt_writedata(handle, unsafe: ptr[void]<-ptr_of(body))
|
|
93
|
+
if int<-write_data_status != CURLE_OK_CODE:
|
|
94
|
+
return Result[bytes.Bytes, curl.Code].failure(error= write_data_status)
|
|
95
|
+
|
|
96
|
+
let url_status = easy_setopt_url(handle, url_cstr)
|
|
97
|
+
if int<-url_status != CURLE_OK_CODE:
|
|
98
|
+
return Result[bytes.Bytes, curl.Code].failure(error= url_status)
|
|
99
|
+
|
|
100
|
+
let follow_status = easy_setopt_followlocation(handle, 1)
|
|
101
|
+
if int<-follow_status != CURLE_OK_CODE:
|
|
102
|
+
return Result[bytes.Bytes, curl.Code].failure(error= follow_status)
|
|
103
|
+
|
|
104
|
+
let perform_status = curl.easy_perform(handle)
|
|
105
|
+
if int<-perform_status != CURLE_OK_CODE:
|
|
106
|
+
return Result[bytes.Bytes, curl.Code].failure(error= perform_status)
|
|
107
|
+
|
|
108
|
+
return Result[bytes.Bytes, curl.Code].success(value= bytes.Bytes.copy(body.as_span()))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
function http_error(code: curl.Code) -> HttpError:
|
|
112
|
+
let detail = text.cstr_as_str(curl.easy_strerror(code))
|
|
113
|
+
return HttpError(code = code, message = string.String.from_str(detail))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
public function get(url: str) -> Result[HttpResponse, HttpError]:
|
|
117
|
+
return do_request("GET", url, Option[str].none, 0)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
public function get_with_timeout(url: str, timeout_seconds: int) -> Result[HttpResponse, HttpError]:
|
|
121
|
+
return do_request("GET", url, Option[str].none, timeout_seconds)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
public function head(url: str) -> Result[HttpResponse, HttpError]:
|
|
125
|
+
return do_request("HEAD", url, Option[str].none, 0)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
public function head_with_timeout(url: str, timeout_seconds: int) -> Result[HttpResponse, HttpError]:
|
|
129
|
+
return do_request("HEAD", url, Option[str].none, timeout_seconds)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
public function delete(url: str) -> Result[HttpResponse, HttpError]:
|
|
133
|
+
return do_request("DELETE", url, Option[str].none, 0)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
public function delete_with_timeout(url: str, timeout_seconds: int) -> Result[HttpResponse, HttpError]:
|
|
137
|
+
return do_request("DELETE", url, Option[str].none, timeout_seconds)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
public function options(url: str) -> Result[HttpResponse, HttpError]:
|
|
141
|
+
return do_request("OPTIONS", url, Option[str].none, 0)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
public function options_with_timeout(url: str, timeout_seconds: int) -> Result[HttpResponse, HttpError]:
|
|
145
|
+
return do_request("OPTIONS", url, Option[str].none, timeout_seconds)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
public function post(url: str, body: str) -> Result[HttpResponse, HttpError]:
|
|
149
|
+
return do_request("POST", url, Option[str].some(value = body), 0)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
public function post_with_timeout(
|
|
153
|
+
url: str,
|
|
154
|
+
body: str,
|
|
155
|
+
timeout_seconds: int
|
|
156
|
+
) -> Result[HttpResponse, HttpError]:
|
|
157
|
+
return do_request("POST", url, Option[str].some(value = body), timeout_seconds)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
public function put(url: str, body: str) -> Result[HttpResponse, HttpError]:
|
|
161
|
+
return do_request("PUT", url, Option[str].some(value = body), 0)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
public function put_with_timeout(
|
|
165
|
+
url: str,
|
|
166
|
+
body: str,
|
|
167
|
+
timeout_seconds: int
|
|
168
|
+
) -> Result[HttpResponse, HttpError]:
|
|
169
|
+
return do_request("PUT", url, Option[str].some(value = body), timeout_seconds)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
public function patch(url: str, body: str) -> Result[HttpResponse, HttpError]:
|
|
173
|
+
return do_request("PATCH", url, Option[str].some(value = body), 0)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
public function patch_with_timeout(
|
|
177
|
+
url: str,
|
|
178
|
+
body: str,
|
|
179
|
+
timeout_seconds: int
|
|
180
|
+
) -> Result[HttpResponse, HttpError]:
|
|
181
|
+
return do_request("PATCH", url, Option[str].some(value = body), timeout_seconds)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
public function request(
|
|
185
|
+
method: str,
|
|
186
|
+
url: str,
|
|
187
|
+
body: Option[str],
|
|
188
|
+
timeout: int
|
|
189
|
+
) -> Result[HttpResponse, HttpError]:
|
|
190
|
+
return do_request(method, url, body, timeout)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
function do_request(
|
|
194
|
+
method: str,
|
|
195
|
+
url: str,
|
|
196
|
+
body: Option[str],
|
|
197
|
+
timeout: int
|
|
198
|
+
) -> Result[HttpResponse, HttpError]:
|
|
199
|
+
let global_status = curl.global_init(curl.CURL_GLOBAL_NOTHING)
|
|
200
|
+
if int<-global_status != CURLE_OK_CODE:
|
|
201
|
+
return Result[HttpResponse, HttpError].failure(error = http_error(global_status))
|
|
202
|
+
defer curl.global_cleanup()
|
|
203
|
+
|
|
204
|
+
let handle = curl.easy_init() else:
|
|
205
|
+
return Result[HttpResponse, HttpError].failure(
|
|
206
|
+
error = HttpError(
|
|
207
|
+
code = curl.Code<-CURLE_FAILED_INIT_CODE,
|
|
208
|
+
message = string.String.from_str("curl_easy_init failed")
|
|
209
|
+
)
|
|
210
|
+
)
|
|
211
|
+
defer curl.easy_cleanup(handle)
|
|
212
|
+
|
|
213
|
+
var buffer = vec.Vec[ubyte].create()
|
|
214
|
+
defer buffer.release()
|
|
215
|
+
|
|
216
|
+
let _wfn = easy_setopt_writefunction(handle, write_response_chunk)
|
|
217
|
+
let _wdata = easy_setopt_writedata(handle, unsafe: ptr[void]<-ptr_of(buffer))
|
|
218
|
+
|
|
219
|
+
if url.len == heap.ptr_uint_max:
|
|
220
|
+
return Result[HttpResponse, HttpError].failure(
|
|
221
|
+
error = HttpError(
|
|
222
|
+
code = curl.Code<-CURLE_URL_MALFORMAT_CODE,
|
|
223
|
+
message = string.String.from_str("url too long")
|
|
224
|
+
)
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
var scratch = arena.create(url.len + 1)
|
|
228
|
+
defer scratch.release()
|
|
229
|
+
|
|
230
|
+
let url_cstr = scratch.to_cstr(url)
|
|
231
|
+
let _url = easy_setopt_url(handle, url_cstr)
|
|
232
|
+
let _follow = easy_setopt_followlocation(handle, 1)
|
|
233
|
+
|
|
234
|
+
if timeout > 0:
|
|
235
|
+
let _timeout = easy_setopt_timeout(handle, timeout)
|
|
236
|
+
|
|
237
|
+
if body.is_some():
|
|
238
|
+
let body_content = body.unwrap()
|
|
239
|
+
var body_scratch = arena.create(body_content.len + 1)
|
|
240
|
+
defer body_scratch.release()
|
|
241
|
+
let _pf = easy_setopt_postfields(handle, body_scratch.to_cstr(body_content))
|
|
242
|
+
|
|
243
|
+
if method.len > 0 and not method.starts_with("GET"):
|
|
244
|
+
var method_scratch = arena.create(method.len + 1)
|
|
245
|
+
defer method_scratch.release()
|
|
246
|
+
let _method = easy_setopt_customrequest(handle, method_scratch.to_cstr(method))
|
|
247
|
+
|
|
248
|
+
if method.starts_with("HEAD"):
|
|
249
|
+
let _nobody = easy_setopt_nobody(handle)
|
|
250
|
+
|
|
251
|
+
let code = curl.easy_perform(handle)
|
|
252
|
+
if int<-code != CURLE_OK_CODE:
|
|
253
|
+
return Result[HttpResponse, HttpError].failure(error = http_error(code))
|
|
254
|
+
|
|
255
|
+
var status: int = 0
|
|
256
|
+
let _info = easy_getinfo_long(handle, ptr_of(status))
|
|
257
|
+
|
|
258
|
+
let response_body = bytes.Bytes.copy(buffer.as_span())
|
|
259
|
+
return Result[HttpResponse, HttpError].success(
|
|
260
|
+
value = HttpResponse(status_code = status, body = response_body)
|
|
261
|
+
)
|
data/std/curl.mt
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# generated by mtc imported-bindings from std.c.curl using bindings/imported/curl.binding.json
|
|
2
|
+
|
|
3
|
+
import std.c.curl as c
|
|
4
|
+
|
|
5
|
+
public type EasyHandle = c.CURL
|
|
6
|
+
public type ShareHandle = c.CURLSH
|
|
7
|
+
public type Code = c.CURLcode
|
|
8
|
+
public type CurlOption = c.CURLoption
|
|
9
|
+
public type SList = c.curl_slist
|
|
10
|
+
public type Info = c.CURLINFO
|
|
11
|
+
|
|
12
|
+
public const CURLE_ALREADY_COMPLETE: int = c.CURLE_ALREADY_COMPLETE
|
|
13
|
+
public const CURLOPT_OBSOLETE72: int = c.CURLOPT_OBSOLETE72
|
|
14
|
+
public const CURLOPT_OBSOLETE40: int = c.CURLOPT_OBSOLETE40
|
|
15
|
+
public const CURLINFO_STRING: int = c.CURLINFO_STRING
|
|
16
|
+
public const CURLINFO_LONG: int = c.CURLINFO_LONG
|
|
17
|
+
public const CURLINFO_DOUBLE: int = c.CURLINFO_DOUBLE
|
|
18
|
+
public const CURLINFO_SLIST: int = c.CURLINFO_SLIST
|
|
19
|
+
public const CURLINFO_PTR: int = c.CURLINFO_PTR
|
|
20
|
+
public const CURLINFO_SOCKET: int = c.CURLINFO_SOCKET
|
|
21
|
+
public const CURLINFO_OFF_T: int = c.CURLINFO_OFF_T
|
|
22
|
+
public const CURLINFO_MASK: int = c.CURLINFO_MASK
|
|
23
|
+
public const CURLINFO_TYPEMASK: int = c.CURLINFO_TYPEMASK
|
|
24
|
+
public const CURL_GLOBAL_NOTHING: int = c.CURL_GLOBAL_NOTHING
|
|
25
|
+
|
|
26
|
+
public foreign function easy_escape(curl: ptr[EasyHandle], string: str as cstr, length: int) -> ptr[char]? = c.curl_easy_escape
|
|
27
|
+
public foreign function free(p: ptr[void]) -> void = c.curl_free
|
|
28
|
+
public foreign function global_init(flag_bits: ptr_int) -> Code = c.curl_global_init
|
|
29
|
+
public foreign function global_cleanup() -> void = c.curl_global_cleanup
|
|
30
|
+
public foreign function slist_append(list: ptr[SList], data: str as cstr) -> ptr[SList] = c.curl_slist_append
|
|
31
|
+
public foreign function slist_free_all(list: ptr[SList]) -> void = c.curl_slist_free_all
|
|
32
|
+
public foreign function easy_strerror(error: Code) -> cstr = c.curl_easy_strerror
|
|
33
|
+
public foreign function easy_pause(curl: ptr[EasyHandle], action: int) -> Code = c.curl_easy_pause
|
|
34
|
+
public foreign function easy_init() -> ptr[EasyHandle]? = c.curl_easy_init
|
|
35
|
+
public foreign function easy_perform(curl: ptr[EasyHandle]) -> Code = c.curl_easy_perform
|
|
36
|
+
public foreign function easy_cleanup(curl: ptr[EasyHandle]) -> void = c.curl_easy_cleanup
|
|
37
|
+
public foreign function easy_duphandle(curl: ptr[EasyHandle]) -> ptr[EasyHandle]? = c.curl_easy_duphandle
|
|
38
|
+
public foreign function easy_reset(curl: ptr[EasyHandle]) -> void = c.curl_easy_reset
|
data/std/deque.mt
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import std.mem.heap as heap
|
|
2
|
+
|
|
3
|
+
public struct Deque[T]:
|
|
4
|
+
data: own[T]?
|
|
5
|
+
head: ptr_uint
|
|
6
|
+
len: ptr_uint
|
|
7
|
+
capacity: ptr_uint
|
|
8
|
+
|
|
9
|
+
public struct Iter[T]:
|
|
10
|
+
data: ptr[T]?
|
|
11
|
+
head: ptr_uint
|
|
12
|
+
len: ptr_uint
|
|
13
|
+
capacity: ptr_uint
|
|
14
|
+
index: ptr_uint
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
extending Deque[T]:
|
|
18
|
+
public static function create() -> Deque[T]:
|
|
19
|
+
return Deque[T](data = null, head = 0, len = 0, capacity = 0)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
public static function with_capacity(capacity: ptr_uint) -> Deque[T]:
|
|
23
|
+
var result = Deque[T].create()
|
|
24
|
+
result.reserve(capacity)
|
|
25
|
+
return result
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
static function physical_index(head: ptr_uint, capacity: ptr_uint, index: ptr_uint) -> ptr_uint:
|
|
29
|
+
let raw = head + index
|
|
30
|
+
if raw >= capacity:
|
|
31
|
+
return raw - capacity
|
|
32
|
+
|
|
33
|
+
return raw
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
static function next_index(index: ptr_uint, capacity: ptr_uint) -> ptr_uint:
|
|
37
|
+
if index + 1 == capacity:
|
|
38
|
+
return 0
|
|
39
|
+
|
|
40
|
+
return index + 1
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
static function previous_index(index: ptr_uint, capacity: ptr_uint) -> ptr_uint:
|
|
44
|
+
if index == 0:
|
|
45
|
+
return capacity - 1
|
|
46
|
+
|
|
47
|
+
return index - 1
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
public function len() -> ptr_uint:
|
|
51
|
+
return this.len
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
public function capacity() -> ptr_uint:
|
|
55
|
+
return this.capacity
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
public function is_empty() -> bool:
|
|
59
|
+
return this.len == 0
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
public function iter() -> Iter[T]:
|
|
63
|
+
return Iter[T](data = this.data, head = this.head, len = this.len, capacity = this.capacity, index = 0)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
public function get(index: ptr_uint) -> ptr[T]?:
|
|
67
|
+
if index >= this.len:
|
|
68
|
+
return null
|
|
69
|
+
|
|
70
|
+
let data = this.data else:
|
|
71
|
+
fatal(c"deque.Deque.get missing storage")
|
|
72
|
+
|
|
73
|
+
return unsafe: ptr[T]<-data + Deque[T].physical_index(this.head, this.capacity, index)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
public function at(index: ptr_uint) -> Option[T]:
|
|
77
|
+
let p = this.get(index) else:
|
|
78
|
+
return Option[T].none
|
|
79
|
+
|
|
80
|
+
unsafe:
|
|
81
|
+
return Option[T].some(value = read(p))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
public function first() -> ptr[T]?:
|
|
85
|
+
return this.get(0)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
public function last() -> ptr[T]?:
|
|
89
|
+
if this.len == 0:
|
|
90
|
+
return null
|
|
91
|
+
|
|
92
|
+
return this.get(this.len - 1)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
public editable function clear() -> void:
|
|
96
|
+
this.head = 0
|
|
97
|
+
this.len = 0
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
public editable function release() -> void:
|
|
101
|
+
heap.release(this.data)
|
|
102
|
+
this.data = null
|
|
103
|
+
this.head = 0
|
|
104
|
+
this.len = 0
|
|
105
|
+
this.capacity = 0
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
public editable function reserve(min_capacity: ptr_uint) -> void:
|
|
109
|
+
if min_capacity <= this.capacity:
|
|
110
|
+
return
|
|
111
|
+
|
|
112
|
+
var new_capacity = this.capacity
|
|
113
|
+
if new_capacity == 0:
|
|
114
|
+
new_capacity = 4
|
|
115
|
+
|
|
116
|
+
while new_capacity < min_capacity:
|
|
117
|
+
if new_capacity > heap.ptr_uint_max / 2:
|
|
118
|
+
new_capacity = min_capacity
|
|
119
|
+
else:
|
|
120
|
+
new_capacity *= 2
|
|
121
|
+
|
|
122
|
+
let new_data = heap.must_alloc[T](new_capacity)
|
|
123
|
+
let old_data = this.data
|
|
124
|
+
if this.len != 0:
|
|
125
|
+
if old_data == null:
|
|
126
|
+
fatal(c"deque.reserve missing storage")
|
|
127
|
+
|
|
128
|
+
unsafe:
|
|
129
|
+
let old_ptr = ptr[T]<-old_data
|
|
130
|
+
let new_ptr = ptr[T]<-new_data
|
|
131
|
+
var index: ptr_uint = 0
|
|
132
|
+
while index < this.len:
|
|
133
|
+
let source_index = Deque[T].physical_index(this.head, this.capacity, index)
|
|
134
|
+
read(new_ptr + index) = read(old_ptr + source_index)
|
|
135
|
+
index += 1
|
|
136
|
+
|
|
137
|
+
heap.release(old_data)
|
|
138
|
+
this.data = new_data
|
|
139
|
+
this.head = 0
|
|
140
|
+
this.capacity = new_capacity
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
public editable function push_back(value: T) -> void:
|
|
144
|
+
if this.len == this.capacity:
|
|
145
|
+
this.reserve(this.len + 1)
|
|
146
|
+
|
|
147
|
+
let data = this.data else:
|
|
148
|
+
fatal(c"deque.push_back missing storage")
|
|
149
|
+
|
|
150
|
+
let tail_index = Deque[T].physical_index(this.head, this.capacity, this.len)
|
|
151
|
+
unsafe:
|
|
152
|
+
let data_ptr = ptr[T]<-data
|
|
153
|
+
read(data_ptr + tail_index) = value
|
|
154
|
+
|
|
155
|
+
this.len += 1
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
public editable function push_front(value: T) -> void:
|
|
159
|
+
if this.len == this.capacity:
|
|
160
|
+
this.reserve(this.len + 1)
|
|
161
|
+
|
|
162
|
+
let data = this.data else:
|
|
163
|
+
fatal(c"deque.push_front missing storage")
|
|
164
|
+
|
|
165
|
+
if this.len == 0:
|
|
166
|
+
this.head = 0
|
|
167
|
+
else:
|
|
168
|
+
this.head = Deque[T].previous_index(this.head, this.capacity)
|
|
169
|
+
|
|
170
|
+
unsafe:
|
|
171
|
+
let data_ptr = ptr[T]<-data
|
|
172
|
+
read(data_ptr + this.head) = value
|
|
173
|
+
|
|
174
|
+
this.len += 1
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
public editable function insert(index: ptr_uint, value: T) -> bool:
|
|
178
|
+
if index > this.len:
|
|
179
|
+
return false
|
|
180
|
+
|
|
181
|
+
if index == 0:
|
|
182
|
+
this.push_front(value)
|
|
183
|
+
return true
|
|
184
|
+
|
|
185
|
+
if index == this.len:
|
|
186
|
+
this.push_back(value)
|
|
187
|
+
return true
|
|
188
|
+
|
|
189
|
+
if this.len == this.capacity:
|
|
190
|
+
this.reserve(this.len + 1)
|
|
191
|
+
|
|
192
|
+
let data = this.data else:
|
|
193
|
+
fatal(c"deque.insert missing storage")
|
|
194
|
+
|
|
195
|
+
unsafe:
|
|
196
|
+
let data_ptr = ptr[T]<-data
|
|
197
|
+
if index < this.len - index:
|
|
198
|
+
let old_head = this.head
|
|
199
|
+
let new_head = Deque[T].previous_index(old_head, this.capacity)
|
|
200
|
+
var current: ptr_uint = 0
|
|
201
|
+
while current < index:
|
|
202
|
+
let destination = Deque[T].physical_index(new_head, this.capacity, current)
|
|
203
|
+
let source = Deque[T].physical_index(old_head, this.capacity, current)
|
|
204
|
+
read(data_ptr + destination) = read(data_ptr + source)
|
|
205
|
+
current += 1
|
|
206
|
+
this.head = new_head
|
|
207
|
+
else:
|
|
208
|
+
var current = this.len
|
|
209
|
+
while current > index:
|
|
210
|
+
let destination = Deque[T].physical_index(this.head, this.capacity, current)
|
|
211
|
+
let source = Deque[T].physical_index(this.head, this.capacity, current - 1)
|
|
212
|
+
read(data_ptr + destination) = read(data_ptr + source)
|
|
213
|
+
current -= 1
|
|
214
|
+
|
|
215
|
+
let target = Deque[T].physical_index(this.head, this.capacity, index)
|
|
216
|
+
read(data_ptr + target) = value
|
|
217
|
+
|
|
218
|
+
this.len += 1
|
|
219
|
+
return true
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
public editable function pop_back() -> Option[T]:
|
|
223
|
+
if this.len == 0:
|
|
224
|
+
return Option[T].none
|
|
225
|
+
|
|
226
|
+
let data = this.data else:
|
|
227
|
+
fatal(c"deque.pop_back missing storage")
|
|
228
|
+
|
|
229
|
+
let tail_index = Deque[T].physical_index(this.head, this.capacity, this.len - 1)
|
|
230
|
+
unsafe:
|
|
231
|
+
let data_ptr = ptr[T]<-data
|
|
232
|
+
let value = read(data_ptr + tail_index)
|
|
233
|
+
if this.len == 1:
|
|
234
|
+
this.head = 0
|
|
235
|
+
this.len = 0
|
|
236
|
+
else:
|
|
237
|
+
this.len -= 1
|
|
238
|
+
return Option[T].some(value = value)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
public editable function pop_front() -> Option[T]:
|
|
242
|
+
if this.len == 0:
|
|
243
|
+
return Option[T].none
|
|
244
|
+
|
|
245
|
+
let data = this.data else:
|
|
246
|
+
fatal(c"deque.pop_front missing storage")
|
|
247
|
+
|
|
248
|
+
unsafe:
|
|
249
|
+
let data_ptr = ptr[T]<-data
|
|
250
|
+
let value = read(data_ptr + this.head)
|
|
251
|
+
if this.len == 1:
|
|
252
|
+
this.head = 0
|
|
253
|
+
this.len = 0
|
|
254
|
+
else:
|
|
255
|
+
this.len -= 1
|
|
256
|
+
this.head = Deque[T].next_index(this.head, this.capacity)
|
|
257
|
+
return Option[T].some(value = value)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
public editable function remove(index: ptr_uint) -> Option[T]:
|
|
261
|
+
if index >= this.len:
|
|
262
|
+
return Option[T].none
|
|
263
|
+
|
|
264
|
+
if index == 0:
|
|
265
|
+
return this.pop_front()
|
|
266
|
+
|
|
267
|
+
if index + 1 == this.len:
|
|
268
|
+
return this.pop_back()
|
|
269
|
+
|
|
270
|
+
let data = this.data else:
|
|
271
|
+
fatal(c"deque.remove missing storage")
|
|
272
|
+
|
|
273
|
+
unsafe:
|
|
274
|
+
let data_ptr = ptr[T]<-data
|
|
275
|
+
let removed_index = Deque[T].physical_index(this.head, this.capacity, index)
|
|
276
|
+
let removed = read(data_ptr + removed_index)
|
|
277
|
+
|
|
278
|
+
if index < this.len / 2:
|
|
279
|
+
var current = index
|
|
280
|
+
while current > 0:
|
|
281
|
+
let destination = Deque[T].physical_index(this.head, this.capacity, current)
|
|
282
|
+
let source = Deque[T].physical_index(this.head, this.capacity, current - 1)
|
|
283
|
+
read(data_ptr + destination) = read(data_ptr + source)
|
|
284
|
+
current -= 1
|
|
285
|
+
this.head = Deque[T].next_index(this.head, this.capacity)
|
|
286
|
+
else:
|
|
287
|
+
var current = index
|
|
288
|
+
while current + 1 < this.len:
|
|
289
|
+
let destination = Deque[T].physical_index(this.head, this.capacity, current)
|
|
290
|
+
let source = Deque[T].physical_index(this.head, this.capacity, current + 1)
|
|
291
|
+
read(data_ptr + destination) = read(data_ptr + source)
|
|
292
|
+
current += 1
|
|
293
|
+
|
|
294
|
+
this.len -= 1
|
|
295
|
+
return Option[T].some(value = removed)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
public editable function rotate_left(amount: ptr_uint) -> void:
|
|
299
|
+
if this.len <= 1:
|
|
300
|
+
return
|
|
301
|
+
|
|
302
|
+
let shift = amount % this.len
|
|
303
|
+
if shift == 0:
|
|
304
|
+
return
|
|
305
|
+
|
|
306
|
+
if shift > this.len - shift:
|
|
307
|
+
this.rotate_right(this.len - shift)
|
|
308
|
+
return
|
|
309
|
+
|
|
310
|
+
var remaining = shift
|
|
311
|
+
while remaining != 0:
|
|
312
|
+
this.push_back(this.pop_front().expect("deque rotate_left missing front value"))
|
|
313
|
+
remaining -= 1
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
public editable function rotate_right(amount: ptr_uint) -> void:
|
|
317
|
+
if this.len <= 1:
|
|
318
|
+
return
|
|
319
|
+
|
|
320
|
+
let shift = amount % this.len
|
|
321
|
+
if shift == 0:
|
|
322
|
+
return
|
|
323
|
+
|
|
324
|
+
if shift > this.len - shift:
|
|
325
|
+
this.rotate_left(this.len - shift)
|
|
326
|
+
return
|
|
327
|
+
|
|
328
|
+
var remaining = shift
|
|
329
|
+
while remaining != 0:
|
|
330
|
+
this.push_front(this.pop_back().expect("deque rotate_right missing back value"))
|
|
331
|
+
remaining -= 1
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
extending Iter[T]:
|
|
335
|
+
public function iter() -> Iter[T]:
|
|
336
|
+
return this
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
public editable function next() -> ptr[T]?:
|
|
340
|
+
if this.index >= this.len:
|
|
341
|
+
return null
|
|
342
|
+
|
|
343
|
+
let data = this.data else:
|
|
344
|
+
fatal(c"deque.Iter.next missing storage")
|
|
345
|
+
|
|
346
|
+
let current_index = this.index
|
|
347
|
+
this.index += 1
|
|
348
|
+
return unsafe: ptr[T]<-data + Deque[T].physical_index(this.head, this.capacity, current_index)
|