mt-lang 0.4.23 → 0.4.25

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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +8 -8
  5. data/lib/milk_tea/base.rb +1 -1
  6. data/lib/milk_tea/core/control_flow/builder.rb +12 -0
  7. data/lib/milk_tea/core/types/layout.rb +90 -19
  8. data/lib/milk_tea/tooling/cli/commands/std.rb +84 -0
  9. data/lib/milk_tea/tooling/cli.rb +25 -0
  10. data/lib/milk_tea/tooling/linter/fix_engine.rb +100 -0
  11. data/lib/milk_tea/tooling/linter/release_rules.rb +69 -11
  12. data/lib/milk_tea/tooling/linter/visitors.rb +58 -31
  13. data/lib/milk_tea/tooling/linter.rb +8 -1
  14. data/lib/milk_tea/tooling/std_catalog.rb +277 -0
  15. data/lib/milk_tea/tooling.rb +1 -0
  16. data/std/async/libuv_runtime.mt +20 -23
  17. data/std/async/mailbox.mt +2 -2
  18. data/std/base64.mt +3 -6
  19. data/std/behavior_tree.mt +1 -6
  20. data/std/binary.mt +2 -5
  21. data/std/color.mt +20 -20
  22. data/std/cookie.mt +1 -4
  23. data/std/deque.mt +2 -8
  24. data/std/encoding.mt +1 -4
  25. data/std/fmt.mt +1 -4
  26. data/std/graph.mt +5 -1
  27. data/std/htn.mt +9 -1
  28. data/std/http/server.mt +1 -4
  29. data/std/http.mt +14 -17
  30. data/std/jobs.mt +9 -10
  31. data/std/json.mt +17 -28
  32. data/std/linked_map.mt +3 -9
  33. data/std/map.mt +1 -4
  34. data/std/net/channel.mt +6 -6
  35. data/std/net/lobby.mt +3 -3
  36. data/std/net/manager.mt +0 -1
  37. data/std/net/mux.mt +1 -1
  38. data/std/net/packet.mt +4 -1
  39. data/std/net/punch.mt +3 -2
  40. data/std/net/rpc.mt +1 -3
  41. data/std/net/session.mt +12 -25
  42. data/std/net/sync.mt +3 -3
  43. data/std/net/turn.mt +7 -3
  44. data/std/net.mt +145 -159
  45. data/std/noise.mt +11 -7
  46. data/std/ordered_map.mt +2 -8
  47. data/std/ordered_set.mt +3 -5
  48. data/std/path.mt +1 -4
  49. data/std/process.mt +7 -18
  50. data/std/random.mt +2 -2
  51. data/std/sdl3/runtime.mt +1 -1
  52. data/std/steering.mt +27 -4
  53. data/std/string.mt +1 -4
  54. data/std/tar.mt +8 -10
  55. data/std/terminal.mt +21 -40
  56. data/std/thread.mt +3 -4
  57. data/std/tls.mt +22 -29
  58. data/std/toml.mt +23 -31
  59. data/std/uri.mt +2 -1
  60. data/std/utility.mt +2 -2
  61. data/std/vec.mt +8 -17
  62. metadata +5 -3
data/std/color.mt CHANGED
@@ -51,7 +51,7 @@ function fmod(x: float, m: float) -> float:
51
51
  # x - floor(x / m) * m
52
52
  let div = x / m
53
53
  let fl = float<-(int<-div)
54
- if div < 0.0 and float<-(int<-div) != div:
54
+ if div < 0.0 and (int<-div) != div:
55
55
  return x - (fl - 1.0) * m
56
56
  return x - fl * m
57
57
 
@@ -143,9 +143,9 @@ extending Color:
143
143
 
144
144
 
145
145
  public function to_hsl() -> (float, float, float):
146
- let rf = float<-this.r / 255.0
147
- let gf = float<-this.g / 255.0
148
- let bf = float<-this.b / 255.0
146
+ let rf = this.r / 255.0
147
+ let gf = this.g / 255.0
148
+ let bf = this.b / 255.0
149
149
 
150
150
  let mx = fmax(fmax(rf, gf), bf)
151
151
  let mn = fmin(fmin(rf, gf), bf)
@@ -171,9 +171,9 @@ extending Color:
171
171
 
172
172
 
173
173
  public function to_hsv() -> (float, float, float):
174
- let rf = float<-this.r / 255.0
175
- let gf = float<-this.g / 255.0
176
- let bf = float<-this.b / 255.0
174
+ let rf = this.r / 255.0
175
+ let gf = this.g / 255.0
176
+ let bf = this.b / 255.0
177
177
 
178
178
  let mx = fmax(fmax(rf, gf), bf)
179
179
  let mn = fmin(fmin(rf, gf), bf)
@@ -198,10 +198,10 @@ extending Color:
198
198
 
199
199
 
200
200
  public function lerp(target: Color, t: float) -> Color:
201
- let r = float<-this.r + (float<-target.r - float<-this.r) * t
202
- let g = float<-this.g + (float<-target.g - float<-this.g) * t
203
- let b = float<-this.b + (float<-target.b - float<-this.b) * t
204
- let a = float<-this.a + (float<-target.a - float<-this.a) * t
201
+ let r = this.r + (float<-target.r - float<-this.r) * t
202
+ let g = this.g + (float<-target.g - float<-this.g) * t
203
+ let b = this.b + (float<-target.b - float<-this.b) * t
204
+ let a = this.a + (float<-target.a - float<-this.a) * t
205
205
  return Color(r = ubyte<-r, g = ubyte<-g, b = ubyte<-b, a = ubyte<-a)
206
206
 
207
207
 
@@ -211,12 +211,12 @@ extending Color:
211
211
  if this.a == 255:
212
212
  return this
213
213
 
214
- let sa = float<-this.a / 255.0
215
- let da = float<-background.a / 255.0
214
+ let sa = this.a / 255.0
215
+ let da = background.a / 255.0
216
216
 
217
- let r_out = float<-this.r * sa + float<-background.r * da * (1.0 - sa)
218
- let g_out = float<-this.g * sa + float<-background.g * da * (1.0 - sa)
219
- let b_out = float<-this.b * sa + float<-background.b * da * (1.0 - sa)
217
+ let r_out = this.r * sa + background.r * da * (1.0 - sa)
218
+ let g_out = this.g * sa + background.g * da * (1.0 - sa)
219
+ let b_out = this.b * sa + background.b * da * (1.0 - sa)
220
220
  let a_out = sa + da * (1.0 - sa)
221
221
 
222
222
  return Color(
@@ -228,9 +228,9 @@ extending Color:
228
228
 
229
229
 
230
230
  public function scale(factor: float) -> Color:
231
- let r = fmin(fmax(float<-this.r * factor, 0.0), 255.0)
232
- let g = fmin(fmax(float<-this.g * factor, 0.0), 255.0)
233
- let b = fmin(fmax(float<-this.b * factor, 0.0), 255.0)
231
+ let r = fmin(fmax(this.r * factor, 0.0), 255.0)
232
+ let g = fmin(fmax(this.g * factor, 0.0), 255.0)
233
+ let b = fmin(fmax(this.b * factor, 0.0), 255.0)
234
234
  return Color(r = ubyte<-r, g = ubyte<-g, b = ubyte<-b, a = this.a)
235
235
 
236
236
 
@@ -242,4 +242,4 @@ extending Color:
242
242
 
243
243
 
244
244
  public function with_alpha(a: ubyte) -> Color:
245
- return Color(r = this.r, g = this.g, b = this.b, a = a)
245
+ return this.with(a = a)
data/std/cookie.mt CHANGED
@@ -138,10 +138,7 @@ function ascii_lower(text_value: str) -> string.String:
138
138
  var index: ptr_uint = 0
139
139
  while index < text_value.len:
140
140
  let value = text_value.byte_at(index)
141
- if value >= 65 and value <= 90:
142
- result.push_byte(value + 32)
143
- else:
144
- result.push_byte(value)
141
+ if value >= 65 and value <= 90: result.push_byte(value + 32) else: result.push_byte(value)
145
142
  index += 1
146
143
 
147
144
  return result
data/std/deque.mt CHANGED
@@ -114,10 +114,7 @@ extending Deque[T]:
114
114
  new_capacity = 4
115
115
 
116
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
117
+ if new_capacity > heap.ptr_uint_max / 2: new_capacity = min_capacity else: new_capacity *= 2
121
118
 
122
119
  let new_data = heap.must_alloc[T](new_capacity)
123
120
  let old_data = this.data
@@ -191,10 +188,7 @@ extending Deque[T]:
191
188
  let data = this.data else:
192
189
  fatal(c"deque.push_front missing storage")
193
190
 
194
- if this.len == 0:
195
- this.head = 0
196
- else:
197
- this.head = Deque[T].previous_index(this.head, this.capacity)
191
+ if this.len == 0: this.head = 0 else: this.head = Deque[T].previous_index(this.head, this.capacity)
198
192
 
199
193
  unsafe:
200
194
  let data_ptr = ptr[T]<-data
data/std/encoding.mt CHANGED
@@ -26,10 +26,7 @@ public function utf8_codepoint_count(text: str) -> ptr_uint:
26
26
  while index < text.len:
27
27
  let b = text.byte_at(index)
28
28
  let len = utf8_codepoint_length(b)
29
- if len == 0:
30
- index += 1
31
- else:
32
- index += len
29
+ if len == 0: index += 1 else: index += len
33
30
  count += 1
34
31
 
35
32
  if index != text.len:
data/std/fmt.mt CHANGED
@@ -32,10 +32,7 @@ public function append_cstr(output: ref[string.String], c_text: cstr) -> void:
32
32
 
33
33
 
34
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")
35
+ if bool_value: output.append("true") else: output.append("false")
39
36
 
40
37
 
41
38
  function append_formatted_float(output: ref[string.String], format: cstr, number: double) -> void:
data/std/graph.mt CHANGED
@@ -612,7 +612,11 @@ extending DenseGraph[T]:
612
612
  return ShortestPaths(dist = dist, prev = prev)
613
613
 
614
614
 
615
- public function astar(source: ptr_uint, target: ptr_uint, heuristic: fn(node: ptr_uint) -> float) -> vec.Vec[ptr_uint]:
615
+ public function astar(
616
+ source: ptr_uint,
617
+ target: ptr_uint,
618
+ heuristic: fn(node: ptr_uint) -> float
619
+ ) -> vec.Vec[ptr_uint]:
616
620
  var path = vec.Vec[ptr_uint].create()
617
621
  let n = this.node_count()
618
622
  if n == 0 or source >= n or target >= n:
data/std/htn.mt CHANGED
@@ -110,7 +110,15 @@ function plan_task[World, Context](
110
110
 
111
111
  for subtask_name_ptr in method.subtasks:
112
112
  let subtask_name = unsafe: read(subtask_name_ptr)
113
- let sub_plan = plan_task(planner, context, current_world, subtask_name, depth + 1, iterations, reason)
113
+ let sub_plan = plan_task(
114
+ planner,
115
+ context,
116
+ current_world,
117
+ subtask_name,
118
+ depth + 1,
119
+ iterations,
120
+ reason
121
+ )
114
122
  match sub_plan:
115
123
  Option.none:
116
124
  success = false
data/std/http/server.mt CHANGED
@@ -69,10 +69,7 @@ public function request_query_param(request: Request, key: str) -> Option[str]:
69
69
 
70
70
  return Option[str].some(value = decoded.as_str())
71
71
 
72
- if amp >= query_str.len:
73
- start = query_str.len
74
- else:
75
- start = amp + 1
72
+ if amp >= query_str.len: start = query_str.len else: start = amp + 1
76
73
 
77
74
  return Option[str].none
78
75
 
data/std/http.mt CHANGED
@@ -530,12 +530,10 @@ function discard_buffer_prefix(buffer: ref[vec.Vec[ubyte]], count: ptr_uint) ->
530
530
  fatal(c"http.discard_buffer_prefix missing storage")
531
531
 
532
532
  let remaining = buffer.len - count
533
- unsafe:
534
- let data_ptr = data
535
- var index: ptr_uint = 0
536
- while index < remaining:
537
- read(data_ptr + index) = read(data_ptr + count + index)
538
- index += 1
533
+ var index: ptr_uint = 0
534
+ while index < remaining:
535
+ read(data + index) = read(data + count + index)
536
+ index += 1
539
537
 
540
538
  buffer.len = remaining
541
539
 
@@ -572,14 +570,14 @@ function parse_response_head(header_text: str) -> Result[ResponseHead, Error]:
572
570
  Option.some as payload:
573
571
  status_code = int<-payload.value
574
572
 
573
+ if first_space + 4 < status_line.len and status_line.byte_at(first_space + 4) != 32:
574
+ return Result[
575
+ ResponseHead,
576
+ Error
577
+ ].failure(error = response_error("status line must separate code and reason with a space"))
578
+
575
579
  var reason = string.String.create()
576
580
  if first_space + 4 < status_line.len:
577
- if status_line.byte_at(first_space + 4) != 32:
578
- return Result[
579
- ResponseHead,
580
- Error
581
- ].failure(error = response_error("status line must separate code and reason with a space"))
582
-
583
581
  let reason_start = first_space + 5
584
582
  reason = string.String.from_str(status_line.slice(reason_start, status_line.len - reason_start))
585
583
 
@@ -641,10 +639,7 @@ function parse_response_head(header_text: str) -> Result[ResponseHead, Error]:
641
639
  head.release()
642
640
  return Result[ResponseHead, Error].failure(error = response_error("unsupported Transfer-Encoding"))
643
641
 
644
- if next_line_end == header_text.len:
645
- index = header_text.len
646
- else:
647
- index = next_line_end + 2
642
+ if next_line_end == header_text.len: index = header_text.len else: index = next_line_end + 2
648
643
 
649
644
  if head.chunked:
650
645
  head.content_length = Option[ptr_uint].none
@@ -844,7 +839,9 @@ async function read_chunked_body(stream: net.TcpStream, prefix: span[ubyte]) ->
844
839
  return Result[
845
840
  bytes.Bytes,
846
841
  Error
847
- ].failure(error = response_error("chunked response ended before trailers were complete"))
842
+ ].failure(error = response_error(
843
+ "chunked response ended before trailers were complete"
844
+ ))
848
845
 
849
846
  buffer.append_span(chunk.as_span())
850
847
  chunk.release()
data/std/jobs.mt CHANGED
@@ -46,8 +46,8 @@ function error_from_mailbox(source: aio_mailbox.Error) -> Error:
46
46
  return Error(code = source.code, message = source.message)
47
47
 
48
48
 
49
- function noop_completion(arg: ptr[void]) -> void:
50
- unsafe: arg
49
+ function noop_completion(_arg: ptr[void]) -> void:
50
+ pass
51
51
 
52
52
 
53
53
  function stop_pool_state(state: ptr[PoolState]) -> void:
@@ -163,14 +163,13 @@ public function create_on(runtime: aio.Runtime, worker_count: ptr_uint) -> Resul
163
163
  return Result[Pool, Error].failure(error = error_from_mailbox(payload.error))
164
164
  Result.success as mailbox_payload:
165
165
  let state = heap.must_alloc_zeroed[PoolState](1)
166
- unsafe:
167
- state.mutex = mutex_payload.value
168
- state.condition = condition_payload.value
169
- state.queue = deque.Deque[WorkItem].create()
170
- state.queued_jobs = 0
171
- state.running_jobs = 0
172
- state.stopping = false
173
- state.completions = mailbox_payload.value
166
+ state.mutex = mutex_payload.value
167
+ state.condition = condition_payload.value
168
+ state.queue = deque.Deque[WorkItem].create()
169
+ state.queued_jobs = 0
170
+ state.running_jobs = 0
171
+ state.stopping = false
172
+ state.completions = mailbox_payload.value
174
173
 
175
174
  var workers = vec.Vec[thread.Thread].with_capacity(worker_count)
176
175
  var index: ptr_uint = 0
data/std/json.mt CHANGED
@@ -112,15 +112,13 @@ public function object_value(value: ptr[Object]?) -> Value:
112
112
 
113
113
  public function create_array_value() -> Value:
114
114
  let array_ptr = heap.must_alloc[Array](1)
115
- unsafe:
116
- read(array_ptr) = Array.create()
115
+ read(array_ptr) = Array.create()
117
116
  return array_value(array_ptr)
118
117
 
119
118
 
120
119
  public function create_object_value() -> Value:
121
120
  let object_ptr = heap.must_alloc[Object](1)
122
- unsafe:
123
- read(object_ptr) = Object.create()
121
+ read(object_ptr) = Object.create()
124
122
  return object_value(object_ptr)
125
123
 
126
124
 
@@ -178,33 +176,28 @@ function value_as_object(value: Value) -> ptr[Object]?:
178
176
 
179
177
  function convert_raw_array(item: ptr[cjson.JSON]) -> Result[Value, Error]:
180
178
  let array_ptr = heap.must_alloc[Array](1)
181
- unsafe:
182
- read(array_ptr) = Array.create()
179
+ read(array_ptr) = Array.create()
183
180
 
184
181
  let count = cjson.get_array_size(item)
185
182
  if count < 0:
186
- unsafe:
187
- read(array_ptr).release()
183
+ read(array_ptr).release()
188
184
  heap.release(array_ptr)
189
185
  return Result[Value, Error].failure(error = error_message("json array size failed"))
190
186
 
191
187
  var index: int = 0
192
188
  while index < count:
193
189
  let child = cjson.get_array_item(item, index) else:
194
- unsafe:
195
- read(array_ptr).release()
190
+ read(array_ptr).release()
196
191
  heap.release(array_ptr)
197
192
  return Result[Value, Error].failure(error = error_message("json array item missing"))
198
193
 
199
194
  match convert_raw_value(child):
200
195
  Result.failure as payload:
201
- unsafe:
202
- read(array_ptr).release()
196
+ read(array_ptr).release()
203
197
  heap.release(array_ptr)
204
198
  return Result[Value, Error].failure(error = payload.error)
205
199
  Result.success as payload:
206
- unsafe:
207
- read(array_ptr).values.push(payload.value)
200
+ read(array_ptr).values.push(payload.value)
208
201
 
209
202
  index += 1
210
203
 
@@ -213,30 +206,26 @@ function convert_raw_array(item: ptr[cjson.JSON]) -> Result[Value, Error]:
213
206
 
214
207
  function convert_raw_object(item: ptr[cjson.JSON]) -> Result[Value, Error]:
215
208
  let object_ptr = heap.must_alloc[Object](1)
216
- unsafe:
217
- read(object_ptr) = Object.create()
209
+ read(object_ptr) = Object.create()
218
210
 
219
211
  var child = unsafe: ptr[cjson.JSON]?<-read(item).child
220
212
  while child != null:
221
- let current = unsafe: child
213
+ let current = child
222
214
  let key_ptr = unsafe: ptr[char]?<-read(current).string else:
223
- unsafe:
224
- read(object_ptr).release()
215
+ read(object_ptr).release()
225
216
  heap.release(object_ptr)
226
217
  return Result[Value, Error].failure(error = error_message("json object key missing"))
227
218
 
228
219
  match convert_raw_value(current):
229
220
  Result.failure as payload:
230
- unsafe:
231
- read(object_ptr).release()
221
+ read(object_ptr).release()
232
222
  heap.release(object_ptr)
233
223
  return Result[Value, Error].failure(error = payload.error)
234
224
  Result.success as payload:
235
- unsafe:
236
- read(object_ptr).entries.push(Entry(
237
- key = string.String.from_str(text.chars_as_str(key_ptr)),
238
- value = payload.value
239
- ))
225
+ read(object_ptr).entries.push(Entry(
226
+ key = string.String.from_str(text.chars_as_str(key_ptr)),
227
+ value = payload.value
228
+ ))
240
229
 
241
230
  child = unsafe: ptr[cjson.JSON]?<-read(current).next
242
231
 
@@ -380,7 +369,7 @@ function render_with_mode(value: Value, pretty: bool) -> Result[string.String, E
380
369
  if pretty:
381
370
  let rendered_ptr = cjson.print(raw_value) else:
382
371
  return Result[string.String, Error].failure(error = error_message("json print failed"))
383
- defer: raw.cJSON_free(unsafe: rendered_ptr)
372
+ defer: raw.cJSON_free(rendered_ptr)
384
373
  return Result[
385
374
  string.String,
386
375
  Error
@@ -388,7 +377,7 @@ function render_with_mode(value: Value, pretty: bool) -> Result[string.String, E
388
377
 
389
378
  let rendered_ptr = cjson.print_unformatted(raw_value) else:
390
379
  return Result[string.String, Error].failure(error = error_message("json print failed"))
391
- defer: raw.cJSON_free(unsafe: rendered_ptr)
380
+ defer: raw.cJSON_free(rendered_ptr)
392
381
  return Result[string.String, Error].success(value = string.String.from_str(text.chars_as_str(rendered_ptr)))
393
382
 
394
383
 
data/std/linked_map.mt CHANGED
@@ -188,10 +188,7 @@ extending LinkedMap[K, V]:
188
188
  new_capacity = 8
189
189
 
190
190
  while new_capacity < min_capacity:
191
- if new_capacity > heap.ptr_uint_max / 2:
192
- new_capacity = min_capacity
193
- else:
194
- new_capacity *= 2
191
+ if new_capacity > heap.ptr_uint_max / 2: new_capacity = min_capacity else: new_capacity *= 2
195
192
 
196
193
  let new_buckets = heap.must_alloc_zeroed[ptr[Node[K, V]]?](new_capacity)
197
194
  let old_buckets = this.buckets
@@ -243,10 +240,7 @@ extending LinkedMap[K, V]:
243
240
  )
244
241
  read(bucket_ptr + index) = node
245
242
 
246
- if tail == null:
247
- this.head = node
248
- else:
249
- read(ptr[Node[K, V]]<-tail).order_next = node
243
+ if tail == null: this.head = node else: read(ptr[Node[K, V]]<-tail).order_next = node
250
244
  this.tail = node
251
245
 
252
246
  this.len += 1
@@ -267,7 +261,7 @@ extending LinkedMap[K, V]:
267
261
  fatal(c"linked_map.LinkedMap.get_or_insert missing inserted value")
268
262
  unsafe:
269
263
  return ptr_of(read(ptr[Node[K, V]]<-current).value)
270
- Option.some as ignored_payload:
264
+ Option.some:
271
265
  fatal(c"linked_map.LinkedMap.get_or_insert replaced unexpectedly")
272
266
 
273
267
 
data/std/map.mt CHANGED
@@ -181,10 +181,7 @@ extending Map[K, V]:
181
181
  new_capacity = 8
182
182
 
183
183
  while new_capacity < min_capacity:
184
- if new_capacity > heap.ptr_uint_max / 2:
185
- new_capacity = min_capacity
186
- else:
187
- new_capacity *= 2
184
+ if new_capacity > heap.ptr_uint_max / 2: new_capacity = min_capacity else: new_capacity *= 2
188
185
 
189
186
  let new_buckets = heap.must_alloc_zeroed[ptr[Node[K, V]]?](new_capacity)
190
187
  let old_buckets = this.buckets
data/std/net/channel.mt CHANGED
@@ -418,7 +418,7 @@ extending HostMessage:
418
418
 
419
419
  extending Channel:
420
420
  public editable function release() -> void:
421
- let protocol = unsafe: ptr_of(this.protocol)
421
+ let protocol = ptr_of(this.protocol)
422
422
  release_protocol_state(protocol)
423
423
  this.socket.release()
424
424
 
@@ -442,7 +442,7 @@ extending Channel:
442
442
  message = string.String.from_str("udp channel payload exceeds configured maximum")
443
443
  ))
444
444
 
445
- let protocol = unsafe: ptr_of(this.protocol)
445
+ let protocol = ptr_of(this.protocol)
446
446
  let sequence = allocate_sequence(protocol)
447
447
  (await send_connected_packet(this.socket, protocol, sequence, 0, content))?
448
448
  return Result[uint, net.Error].success(value = sequence)
@@ -455,7 +455,7 @@ extending Channel:
455
455
  message = string.String.from_str("udp channel payload exceeds configured maximum")
456
456
  ))
457
457
 
458
- let protocol = unsafe: ptr_of(this.protocol)
458
+ let protocol = ptr_of(this.protocol)
459
459
  let pending_len = unsafe: read(protocol).pending_reliable.len()
460
460
  if pending_len >= pending_window_limit(this.config):
461
461
  return Result[uint, net.Error].failure(error = net.Error(
@@ -478,7 +478,7 @@ extending Channel:
478
478
  defer: packet.release()
479
479
 
480
480
  let header = decode_header(packet)?
481
- let protocol = unsafe: ptr_of(this.protocol)
481
+ let protocol = ptr_of(this.protocol)
482
482
  remove_acked_pending(protocol, header.ack, header.ack_bits)
483
483
  let is_new = mark_received(protocol, header.sequence)
484
484
  let is_reliable = (header.packet_flags & reliable_flag) != 0
@@ -499,7 +499,7 @@ extending Channel:
499
499
 
500
500
 
501
501
  public async editable function tick(frame: uint) -> Result[ptr_uint, net.Error]:
502
- let protocol = unsafe: ptr_of(this.protocol)
502
+ let protocol = ptr_of(this.protocol)
503
503
  var resent: ptr_uint = 0
504
504
  var index: ptr_uint = 0
505
505
  while true:
@@ -537,7 +537,7 @@ extending Host:
537
537
  if removed.is_none():
538
538
  break
539
539
  var peer = removed.unwrap()
540
- let peer_ptr = unsafe: ptr_of(peer)
540
+ let peer_ptr = ptr_of(peer)
541
541
  release_peer_state(peer_ptr)
542
542
 
543
543
  this.peers.release()
data/std/net/lobby.mt CHANGED
@@ -263,8 +263,7 @@ public async function discover_lobbies_on(
263
263
  Result.success:
264
264
  pass
265
265
 
266
- let empty = bytes.Bytes.empty()
267
- let _ = await conn.mux_send(lobby_channel, type_discover_request, empty.as_span(), mux.flag_reliable)
266
+ let _ = await conn.mux_send(lobby_channel, type_discover_request, zero[span[ubyte]], mux.flag_reliable)
268
267
 
269
268
  var frame: uint = 0
270
269
  var result = vec.Vec[LobbyInfo].create()
@@ -714,7 +713,8 @@ public function build_beacon_probe() -> bytes.Bytes:
714
713
  public function is_beacon_probe(data: span[ubyte]) -> bool:
715
714
  if data.len < beacon_probe_len:
716
715
  return false
717
- return data[0] == beacon_magic[0] and data[1] == beacon_magic[1] and data[2] == beacon_magic[2] and data[3] == beacon_magic[3]
716
+ return data[0] == beacon_magic[0] and data[1] == beacon_magic[1] and
717
+ data[2] == beacon_magic[2] and data[3] == beacon_magic[3]
718
718
 
719
719
 
720
720
  public function build_beacon_response(info: ref[LobbyInfo]) -> bytes.Bytes:
data/std/net/manager.mt CHANGED
@@ -5,7 +5,6 @@ import std.net as net
5
5
  import std.net.clock as clock
6
6
  import std.net.mux as mux
7
7
  import std.net.session as sess
8
- import std.string as string
9
8
  import std.vec as vec
10
9
 
11
10
  const channel_system: ubyte = 0
data/std/net/mux.mt CHANGED
@@ -728,7 +728,7 @@ function assemble_fragment(
728
728
  let buf_data = heap.must_alloc[ubyte](full_size)
729
729
  var fill: ptr_uint = 0
730
730
  while fill < full_size:
731
- unsafe: read(buf_data + fill) = 0
731
+ read(buf_data + fill) = 0
732
732
  fill += 1
733
733
  buf = bytes.Bytes(data = buf_data, len = full_size)
734
734
  buffers.push(FragBuffer(
data/std/net/packet.mt CHANGED
@@ -44,7 +44,10 @@ function decode_packet_length(header: bytes.Bytes) -> ptr_uint:
44
44
  fatal(c"packet frame header length mismatch")
45
45
 
46
46
  let header_span = header.as_span()
47
- let length = ((uint<-header_span[0]) << 24) | ((uint<-header_span[1]) << 16) | ((uint<-header_span[2]) << 8) | (uint<-header_span[3])
47
+ let length = ((uint<-header_span[0]) << 24) |
48
+ ((uint<-header_span[1]) << 16) |
49
+ ((uint<-header_span[2]) << 8) |
50
+ (uint<-header_span[3])
48
51
  return length
49
52
 
50
53
 
data/std/net/punch.mt CHANGED
@@ -72,7 +72,8 @@ public function build_punch_probe() -> bytes.Bytes:
72
72
  public function is_punch_probe(data: span[ubyte]) -> bool:
73
73
  if data.len < 4z:
74
74
  return false
75
- return data[0] == punch_magic[0] and data[1] == punch_magic[1] and data[2] == punch_magic[2] and data[3] == punch_magic[3]
75
+ return data[0] == punch_magic[0] and data[1] == punch_magic[1] and
76
+ data[2] == punch_magic[2] and data[3] == punch_magic[3]
76
77
 
77
78
 
78
79
  function result_from_datagram(
@@ -125,7 +126,7 @@ public async function punch(
125
126
  break
126
127
  let send_result = await socket.send_to(probe.as_span(), unsafe: read(cand_ptr).address)
127
128
  match send_result:
128
- Result.failure as sp:
129
+ Result.failure:
129
130
  return Result[PunchResult, Error].failure(
130
131
  error = punch_error(err_send_failed, "burst send failed")
131
132
  )
data/std/net/rpc.mt CHANGED
@@ -47,9 +47,7 @@ public function parse_request_id(data: span[ubyte]) -> Result[uint, Error]:
47
47
 
48
48
  public function payload_after_header(data: span[ubyte]) -> span[ubyte]:
49
49
  if data.len <= header_bytes:
50
- let empty = bytes.Bytes.empty()
51
- let result = empty.as_span()
52
- return result
50
+ return zero[span[ubyte]]
53
51
  unsafe:
54
52
  return span[ubyte](data = data.data + header_bytes, len = data.len - header_bytes)
55
53