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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -8
- data/lib/milk_tea/base.rb +1 -1
- data/lib/milk_tea/core/control_flow/builder.rb +12 -0
- data/lib/milk_tea/core/types/layout.rb +90 -19
- data/lib/milk_tea/tooling/cli/commands/std.rb +84 -0
- data/lib/milk_tea/tooling/cli.rb +25 -0
- data/lib/milk_tea/tooling/linter/fix_engine.rb +100 -0
- data/lib/milk_tea/tooling/linter/release_rules.rb +69 -11
- data/lib/milk_tea/tooling/linter/visitors.rb +58 -31
- data/lib/milk_tea/tooling/linter.rb +8 -1
- data/lib/milk_tea/tooling/std_catalog.rb +277 -0
- data/lib/milk_tea/tooling.rb +1 -0
- data/std/async/libuv_runtime.mt +20 -23
- data/std/async/mailbox.mt +2 -2
- data/std/base64.mt +3 -6
- data/std/behavior_tree.mt +1 -6
- data/std/binary.mt +2 -5
- data/std/color.mt +20 -20
- data/std/cookie.mt +1 -4
- data/std/deque.mt +2 -8
- data/std/encoding.mt +1 -4
- data/std/fmt.mt +1 -4
- data/std/graph.mt +5 -1
- data/std/htn.mt +9 -1
- data/std/http/server.mt +1 -4
- data/std/http.mt +14 -17
- data/std/jobs.mt +9 -10
- data/std/json.mt +17 -28
- data/std/linked_map.mt +3 -9
- data/std/map.mt +1 -4
- data/std/net/channel.mt +6 -6
- data/std/net/lobby.mt +3 -3
- data/std/net/manager.mt +0 -1
- data/std/net/mux.mt +1 -1
- data/std/net/packet.mt +4 -1
- data/std/net/punch.mt +3 -2
- data/std/net/rpc.mt +1 -3
- data/std/net/session.mt +12 -25
- data/std/net/sync.mt +3 -3
- data/std/net/turn.mt +7 -3
- data/std/net.mt +145 -159
- data/std/noise.mt +11 -7
- data/std/ordered_map.mt +2 -8
- data/std/ordered_set.mt +3 -5
- data/std/path.mt +1 -4
- data/std/process.mt +7 -18
- data/std/random.mt +2 -2
- data/std/sdl3/runtime.mt +1 -1
- data/std/steering.mt +27 -4
- data/std/string.mt +1 -4
- data/std/tar.mt +8 -10
- data/std/terminal.mt +21 -40
- data/std/thread.mt +3 -4
- data/std/tls.mt +22 -29
- data/std/toml.mt +23 -31
- data/std/uri.mt +2 -1
- data/std/utility.mt +2 -2
- data/std/vec.mt +8 -17
- metadata +5 -3
data/std/noise.mt
CHANGED
|
@@ -51,8 +51,8 @@ function perlin2d_impl(perm: array[ubyte, 512], x: float, y: float) -> float:
|
|
|
51
51
|
let iy = int<-y
|
|
52
52
|
let X = ix & 255
|
|
53
53
|
let Y = iy & 255
|
|
54
|
-
let xf = x -
|
|
55
|
-
let yf = y -
|
|
54
|
+
let xf = x - ix - (ix & ~255)
|
|
55
|
+
let yf = y - iy - (iy & ~255)
|
|
56
56
|
|
|
57
57
|
let u = fade(if xf < 0.0: xf + 1.0 else: xf)
|
|
58
58
|
let v = fade(if yf < 0.0: yf + 1.0 else: yf)
|
|
@@ -77,9 +77,9 @@ function perlin3d_impl(perm: array[ubyte, 512], x: float, y: float, z: float) ->
|
|
|
77
77
|
let X = ix & 255
|
|
78
78
|
let Y = iy & 255
|
|
79
79
|
let Z = iz & 255
|
|
80
|
-
let xf = x -
|
|
81
|
-
let yf = y -
|
|
82
|
-
let zf = z -
|
|
80
|
+
let xf = x - ix - (ix & ~255)
|
|
81
|
+
let yf = y - iy - (iy & ~255)
|
|
82
|
+
let zf = z - iz - (iz & ~255)
|
|
83
83
|
|
|
84
84
|
let u = fade(if xf < 0.0: xf + 1.0 else: xf)
|
|
85
85
|
let v = fade(if yf < 0.0: yf + 1.0 else: yf)
|
|
@@ -97,7 +97,11 @@ function perlin3d_impl(perm: array[ubyte, 512], x: float, y: float, z: float) ->
|
|
|
97
97
|
let y1 = lerp(x1, x2, v)
|
|
98
98
|
|
|
99
99
|
let x3 = lerp(grad3d(int<-perm[AA + 1], xf, yf, zf - 1.0), grad3d(int<-perm[BA + 1], xf - 1.0, yf, zf - 1.0), u)
|
|
100
|
-
let x4 = lerp(
|
|
100
|
+
let x4 = lerp(
|
|
101
|
+
grad3d(int<-perm[AB + 1], xf, yf - 1.0, zf - 1.0),
|
|
102
|
+
grad3d(int<-perm[BB + 1], xf - 1.0, yf - 1.0, zf - 1.0),
|
|
103
|
+
u
|
|
104
|
+
)
|
|
101
105
|
let y2 = lerp(x3, x4, v)
|
|
102
106
|
|
|
103
107
|
return lerp(y1, y2, w)
|
|
@@ -107,7 +111,7 @@ function perlin3d_impl(perm: array[ubyte, 512], x: float, y: float, z: float) ->
|
|
|
107
111
|
|
|
108
112
|
function floor_f(x: float) -> int:
|
|
109
113
|
let i = int<-x
|
|
110
|
-
if x < 0.0 and
|
|
114
|
+
if x < 0.0 and i != x:
|
|
111
115
|
return i - 1
|
|
112
116
|
return i
|
|
113
117
|
|
data/std/ordered_map.mt
CHANGED
|
@@ -368,10 +368,7 @@ extending OrderedMap[K, V]:
|
|
|
368
368
|
else:
|
|
369
369
|
unsafe:
|
|
370
370
|
let parent_ptr = ptr[Node[K, V]]<-parent
|
|
371
|
-
if location.compare < 0:
|
|
372
|
-
read(parent_ptr).left = node
|
|
373
|
-
else:
|
|
374
|
-
read(parent_ptr).right = node
|
|
371
|
+
if location.compare < 0: read(parent_ptr).left = node else: read(parent_ptr).right = node
|
|
375
372
|
|
|
376
373
|
this.len += 1
|
|
377
374
|
OrderedMap[K, V].rebalance(this, parent)
|
|
@@ -404,10 +401,7 @@ extending OrderedMap[K, V]:
|
|
|
404
401
|
else:
|
|
405
402
|
unsafe:
|
|
406
403
|
let parent_ptr = ptr[Node[K, V]]<-parent
|
|
407
|
-
if location.compare < 0:
|
|
408
|
-
read(parent_ptr).left = node
|
|
409
|
-
else:
|
|
410
|
-
read(parent_ptr).right = node
|
|
404
|
+
if location.compare < 0: read(parent_ptr).left = node else: read(parent_ptr).right = node
|
|
411
405
|
|
|
412
406
|
this.len += 1
|
|
413
407
|
OrderedMap[K, V].rebalance(this, parent)
|
data/std/ordered_set.mt
CHANGED
|
@@ -50,7 +50,8 @@ extending OrderedSet[T]:
|
|
|
50
50
|
return 0
|
|
51
51
|
|
|
52
52
|
unsafe:
|
|
53
|
-
return OrderedSet[T].height(read(ptr[Node[T]]<-node).left) -
|
|
53
|
+
return OrderedSet[T].height(read(ptr[Node[T]]<-node).left) -
|
|
54
|
+
OrderedSet[T].height(read(ptr[Node[T]]<-node).right)
|
|
54
55
|
|
|
55
56
|
|
|
56
57
|
static function minimum(node: ptr[Node[T]]?) -> ptr[Node[T]]?:
|
|
@@ -309,10 +310,7 @@ extending OrderedSet[T]:
|
|
|
309
310
|
else:
|
|
310
311
|
unsafe:
|
|
311
312
|
let parent_ptr = ptr[Node[T]]<-parent
|
|
312
|
-
if location.compare < 0:
|
|
313
|
-
read(parent_ptr).left = node
|
|
314
|
-
else:
|
|
315
|
-
read(parent_ptr).right = node
|
|
313
|
+
if location.compare < 0: read(parent_ptr).left = node else: read(parent_ptr).right = node
|
|
316
314
|
|
|
317
315
|
this.len += 1
|
|
318
316
|
OrderedSet[T].rebalance(this, parent)
|
data/std/path.mt
CHANGED
|
@@ -17,10 +17,7 @@ public function normalize_separators(path: str) -> string.String:
|
|
|
17
17
|
var index: ptr_uint = 0
|
|
18
18
|
while index < path.len:
|
|
19
19
|
let value = path.byte_at(index)
|
|
20
|
-
if value == 92:
|
|
21
|
-
result.push_byte(47)
|
|
22
|
-
else:
|
|
23
|
-
result.push_byte(value)
|
|
20
|
+
if value == 92: result.push_byte(47) else: result.push_byte(value)
|
|
24
21
|
index += 1
|
|
25
22
|
|
|
26
23
|
return result
|
data/std/process.mt
CHANGED
|
@@ -89,23 +89,12 @@ public function parent_environment() -> vec.Vec[EnvironmentEntry]:
|
|
|
89
89
|
if eq_pos == 0 or eq_pos >= len:
|
|
90
90
|
i += 1
|
|
91
91
|
continue
|
|
92
|
-
var nname = string.String.create()
|
|
93
|
-
nname.reserve(eq_pos)
|
|
94
|
-
var ni: ptr_uint = 0
|
|
95
|
-
while ni < eq_pos:
|
|
96
|
-
nname.push_byte(ubyte<-read(entry_cstr + ni))
|
|
97
|
-
ni += 1
|
|
98
|
-
var nvalue = string.String.create()
|
|
99
92
|
let vlen = len - eq_pos - 1
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var vi: ptr_uint = 0
|
|
103
|
-
while vi < vlen:
|
|
104
|
-
nvalue.push_byte(ubyte<-read(entry_cstr + eq_pos + 1 + vi))
|
|
105
|
-
vi += 1
|
|
93
|
+
let name_view = unsafe: str(data = entry_cstr, len = eq_pos)
|
|
94
|
+
let value_view = unsafe: str(data = entry_cstr + eq_pos + 1, len = vlen)
|
|
106
95
|
result.push(EnvironmentEntry(
|
|
107
|
-
name =
|
|
108
|
-
value =
|
|
96
|
+
name = name_view,
|
|
97
|
+
value = value_view
|
|
109
98
|
))
|
|
110
99
|
i += 1
|
|
111
100
|
return result
|
|
@@ -263,7 +252,7 @@ function prepare_command(
|
|
|
263
252
|
let allocated_args = storage.alloc[ptr[char]](command.len + 1) else:
|
|
264
253
|
fatal(c"process args storage exhausted")
|
|
265
254
|
|
|
266
|
-
let args_ptr =
|
|
255
|
+
let args_ptr = allocated_args
|
|
267
256
|
|
|
268
257
|
var env_ptr: ptr[ptr[char]]? = null
|
|
269
258
|
var env_storage: ptr[ptr[char]]? = null
|
|
@@ -271,7 +260,7 @@ function prepare_command(
|
|
|
271
260
|
let allocated = storage.alloc[ptr[char]](env.len + 1) else:
|
|
272
261
|
fatal(c"process env pointer storage exhausted")
|
|
273
262
|
|
|
274
|
-
let allocated_ptr =
|
|
263
|
+
let allocated_ptr = allocated
|
|
275
264
|
env_ptr = allocated_ptr
|
|
276
265
|
env_storage = allocated_ptr
|
|
277
266
|
|
|
@@ -287,7 +276,7 @@ function prepare_command(
|
|
|
287
276
|
let allocated_ptr = env_storage else:
|
|
288
277
|
fatal(c"process env pointer storage missing")
|
|
289
278
|
|
|
290
|
-
let env_storage_ptr =
|
|
279
|
+
let env_storage_ptr = allocated_ptr
|
|
291
280
|
index = 0
|
|
292
281
|
while index < env.len:
|
|
293
282
|
let entry = unsafe: read(env.data + index)
|
data/std/random.mt
CHANGED
|
@@ -43,12 +43,12 @@ extending Rng:
|
|
|
43
43
|
|
|
44
44
|
public editable function next_double() -> double:
|
|
45
45
|
let val = this.next_uint()
|
|
46
|
-
return
|
|
46
|
+
return val / 4294967296.0
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
public editable function next_float() -> float:
|
|
50
50
|
let val = this.next_uint()
|
|
51
|
-
return
|
|
51
|
+
return val / 4294967296.0
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
public editable function next_ubyte() -> ubyte:
|
data/std/sdl3/runtime.mt
CHANGED
|
@@ -9,7 +9,7 @@ function run_app_no_args_uninitialized() -> int:
|
|
|
9
9
|
var run_app_no_args_slot: array[fn() -> int, 1] = array[fn() -> int, 1](run_app_no_args_uninitialized)
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
function run_app_no_args_trampoline(
|
|
12
|
+
function run_app_no_args_trampoline(_argc: int, _argv: ptr[ptr[char]]) -> int:
|
|
13
13
|
let callback = run_app_no_args_slot[0]
|
|
14
14
|
return callback()
|
|
15
15
|
|
data/std/steering.mt
CHANGED
|
@@ -44,7 +44,13 @@ extending vec2:
|
|
|
44
44
|
return desired_vel - velocity
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
public static function arrive(
|
|
47
|
+
public static function arrive(
|
|
48
|
+
position: vec2,
|
|
49
|
+
velocity: vec2,
|
|
50
|
+
target: vec2,
|
|
51
|
+
max_speed: float,
|
|
52
|
+
slowing_distance: float
|
|
53
|
+
) -> vec2:
|
|
48
54
|
let offset = target - position
|
|
49
55
|
let distance = offset.length()
|
|
50
56
|
if distance < 0.001:
|
|
@@ -54,7 +60,13 @@ extending vec2:
|
|
|
54
60
|
return desired_vel - velocity
|
|
55
61
|
|
|
56
62
|
|
|
57
|
-
public static function pursuit(
|
|
63
|
+
public static function pursuit(
|
|
64
|
+
position: vec2,
|
|
65
|
+
velocity: vec2,
|
|
66
|
+
target_pos: vec2,
|
|
67
|
+
target_vel: vec2,
|
|
68
|
+
max_speed: float
|
|
69
|
+
) -> vec2:
|
|
58
70
|
let offset = target_pos - position
|
|
59
71
|
let distance = offset.length()
|
|
60
72
|
let my_speed = velocity.length()
|
|
@@ -65,7 +77,13 @@ extending vec2:
|
|
|
65
77
|
return vec2.seek(position, velocity, future, max_speed)
|
|
66
78
|
|
|
67
79
|
|
|
68
|
-
public static function evade(
|
|
80
|
+
public static function evade(
|
|
81
|
+
position: vec2,
|
|
82
|
+
velocity: vec2,
|
|
83
|
+
threat_pos: vec2,
|
|
84
|
+
threat_vel: vec2,
|
|
85
|
+
max_speed: float
|
|
86
|
+
) -> vec2:
|
|
69
87
|
let offset = threat_pos - position
|
|
70
88
|
let distance = offset.length()
|
|
71
89
|
let my_speed = velocity.length()
|
|
@@ -76,7 +94,12 @@ extending vec2:
|
|
|
76
94
|
return vec2.flee(position, velocity, future, max_speed)
|
|
77
95
|
|
|
78
96
|
|
|
79
|
-
public static function wander(
|
|
97
|
+
public static function wander(
|
|
98
|
+
velocity: vec2,
|
|
99
|
+
wander_angle: float,
|
|
100
|
+
wander_distance: float,
|
|
101
|
+
wander_radius: float
|
|
102
|
+
) -> vec2:
|
|
80
103
|
if velocity.length() < 0.001:
|
|
81
104
|
return zero[vec2]
|
|
82
105
|
let forward = set_magnitude(velocity, 1.0)
|
data/std/string.mt
CHANGED
|
@@ -121,10 +121,7 @@ extending String:
|
|
|
121
121
|
new_capacity = 4
|
|
122
122
|
|
|
123
123
|
while new_capacity < min_capacity:
|
|
124
|
-
if new_capacity > heap.ptr_uint_max / 2:
|
|
125
|
-
new_capacity = min_capacity
|
|
126
|
-
else:
|
|
127
|
-
new_capacity *= 2
|
|
124
|
+
if new_capacity > heap.ptr_uint_max / 2: new_capacity = min_capacity else: new_capacity *= 2
|
|
128
125
|
|
|
129
126
|
let resized = heap.resize[ubyte](this.data, new_capacity) else:
|
|
130
127
|
fatal(c"string.reserve out of memory")
|
data/std/tar.mt
CHANGED
|
@@ -119,10 +119,7 @@ function sort_string_values(values: ref[vec.Vec[string.String]]) -> void:
|
|
|
119
119
|
var should_swap = false
|
|
120
120
|
unsafe:
|
|
121
121
|
should_swap = compare_text(read(previous_ptr).as_str(), read(current_ptr).as_str()) > 0
|
|
122
|
-
if should_swap:
|
|
123
|
-
values.swap(current - 1, current)
|
|
124
|
-
else:
|
|
125
|
-
break
|
|
122
|
+
if should_swap: values.swap(current - 1, current) else: break
|
|
126
123
|
|
|
127
124
|
current -= 1
|
|
128
125
|
|
|
@@ -318,10 +315,7 @@ function append_header(
|
|
|
318
315
|
header[checksum_index] = space_byte
|
|
319
316
|
checksum_index += 1
|
|
320
317
|
|
|
321
|
-
if kind == EntryKind.directory:
|
|
322
|
-
header[156] = directory_type_flag
|
|
323
|
-
else:
|
|
324
|
-
header[156] = file_type_flag
|
|
318
|
+
if kind == EntryKind.directory: header[156] = directory_type_flag else: header[156] = file_type_flag
|
|
325
319
|
|
|
326
320
|
header[257] = 117
|
|
327
321
|
header[258] = 115
|
|
@@ -592,7 +586,9 @@ function checked_destination_path(destination_root: str, relative_path: str) ->
|
|
|
592
586
|
var normalized = payload.value
|
|
593
587
|
defer: normalized.release()
|
|
594
588
|
let normalized_path = normalized.as_str()
|
|
595
|
-
let escapes_parent = normalized_path.len == 2 and
|
|
589
|
+
let escapes_parent = normalized_path.len == 2 and
|
|
590
|
+
normalized_path.byte_at(0) == 46 and
|
|
591
|
+
normalized_path.byte_at(1) == 46
|
|
596
592
|
if escapes_parent or normalized_path.starts_with("../"):
|
|
597
593
|
destination_path.release()
|
|
598
594
|
return Result[
|
|
@@ -626,7 +622,9 @@ public function archive_directory(
|
|
|
626
622
|
if archive_root_name.len != 0 and path_ops.is_absolute(archive_root_name):
|
|
627
623
|
return Result[bytes.Bytes, Error].failure(error = error_message("tar archive root name must be relative"))
|
|
628
624
|
|
|
629
|
-
|
|
625
|
+
# Consumed by take_vec_bytes below; the flow heuristic cannot see
|
|
626
|
+
# through the loop above.
|
|
627
|
+
var output = vec.Vec[ubyte].create() # lint: ignore(owning-release-leak)
|
|
630
628
|
match append_directory_tree(root_path, archive_root_name, include_hidden, ref_of(output)):
|
|
631
629
|
Result.failure as payload:
|
|
632
630
|
output.release()
|
data/std/terminal.mt
CHANGED
|
@@ -288,9 +288,8 @@ function read_stdin(timeout_ms: int) -> Result[vec.Vec[ubyte], Error]:
|
|
|
288
288
|
|
|
289
289
|
var result = vec.Vec[ubyte].with_capacity(read_count)
|
|
290
290
|
if read_count != 0:
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
result.append_span(read_span)
|
|
291
|
+
let read_span = span[ubyte](data = ptr_of(buffer[0]), len = read_count)
|
|
292
|
+
result.append_span(read_span)
|
|
294
293
|
|
|
295
294
|
return Result[vec.Vec[ubyte], Error].success(value= result)
|
|
296
295
|
|
|
@@ -324,10 +323,9 @@ function apply_modifier(key: ref[KeyEvent], modifier: int) -> void:
|
|
|
324
323
|
return
|
|
325
324
|
|
|
326
325
|
let modifier_bits = modifier - 1
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
read(key).ctrl = (modifier_bits & 4) != 0
|
|
326
|
+
read(key).shifted = (modifier_bits & 1) != 0
|
|
327
|
+
read(key).alt = (modifier_bits & 2) != 0
|
|
328
|
+
read(key).ctrl = (modifier_bits & 4) != 0
|
|
331
329
|
|
|
332
330
|
|
|
333
331
|
function get_byte(buffer: vec.Vec[ubyte], index: ptr_uint) -> Option[ubyte]:
|
|
@@ -402,35 +400,24 @@ function parse_ss3_event(buffer: ref[vec.Vec[ubyte]]) -> Option[Event]:
|
|
|
402
400
|
match get_ref_byte(buffer, 2):
|
|
403
401
|
Option.some as payload:
|
|
404
402
|
consume_bytes(buffer, 3)
|
|
405
|
-
match payload.value:
|
|
406
|
-
80:
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
return Option[Event].some(value = key_event(KeyCode.function_4, 0, false, false, false, false))
|
|
414
|
-
72:
|
|
415
|
-
return Option[Event].some(value = key_event(KeyCode.home, 0, false, false, false, false))
|
|
416
|
-
70:
|
|
417
|
-
return Option[Event].some(value = key_event(KeyCode.end, 0, false, false, false, false))
|
|
418
|
-
_:
|
|
419
|
-
return Option[Event].some(value = key_event(KeyCode.unknown, 0, false, false, false, false))
|
|
403
|
+
return match payload.value:
|
|
404
|
+
80: Option[Event].some(value = key_event(KeyCode.function_1, 0, false, false, false, false))
|
|
405
|
+
81: Option[Event].some(value = key_event(KeyCode.function_2, 0, false, false, false, false))
|
|
406
|
+
82: Option[Event].some(value = key_event(KeyCode.function_3, 0, false, false, false, false))
|
|
407
|
+
83: Option[Event].some(value = key_event(KeyCode.function_4, 0, false, false, false, false))
|
|
408
|
+
72: Option[Event].some(value = key_event(KeyCode.home, 0, false, false, false, false))
|
|
409
|
+
70: Option[Event].some(value = key_event(KeyCode.end, 0, false, false, false, false))
|
|
410
|
+
_: Option[Event].some(value = key_event(KeyCode.unknown, 0, false, false, false, false))
|
|
420
411
|
Option.none:
|
|
421
412
|
return Option[Event].none
|
|
422
413
|
|
|
423
414
|
|
|
424
415
|
function decode_mouse_button(code: int) -> MouseButton:
|
|
425
|
-
match code & 3:
|
|
426
|
-
0:
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
2:
|
|
431
|
-
return MouseButton.right
|
|
432
|
-
_:
|
|
433
|
-
return MouseButton.none
|
|
416
|
+
return match code & 3:
|
|
417
|
+
0: MouseButton.left
|
|
418
|
+
1: MouseButton.middle
|
|
419
|
+
2: MouseButton.right
|
|
420
|
+
_: MouseButton.none
|
|
434
421
|
|
|
435
422
|
|
|
436
423
|
function parse_mouse_event(buffer: ref[vec.Vec[ubyte]]) -> Option[Event]:
|
|
@@ -534,7 +521,7 @@ function parse_mouse_event(buffer: ref[vec.Vec[ubyte]]) -> Option[Event]:
|
|
|
534
521
|
return Option[Event].none
|
|
535
522
|
|
|
536
523
|
|
|
537
|
-
function parse_csi_letter(
|
|
524
|
+
function parse_csi_letter(_buffer: ref[vec.Vec[ubyte]], final_byte: ubyte, modifier: int) -> Event:
|
|
538
525
|
var event_ = key_event(KeyCode.unknown, 0, false, false, false, false)
|
|
539
526
|
if final_byte == 65:
|
|
540
527
|
event_ = key_event(KeyCode.up, 0, false, false, false, false)
|
|
@@ -812,20 +799,14 @@ public function set_rgb_background(red: int, green: int, blue: int) -> Result[bo
|
|
|
812
799
|
public function set_bold(enabled: bool) -> Result[bool, Error]:
|
|
813
800
|
var sequence = string.String.with_capacity(6)
|
|
814
801
|
defer: sequence.release()
|
|
815
|
-
if enabled:
|
|
816
|
-
append_csi(ref_of(sequence), "1m")
|
|
817
|
-
else:
|
|
818
|
-
append_csi(ref_of(sequence), "22m")
|
|
802
|
+
if enabled: append_csi(ref_of(sequence), "1m") else: append_csi(ref_of(sequence), "22m")
|
|
819
803
|
return write_stdout_sequence(sequence, "terminal bold styling failed")
|
|
820
804
|
|
|
821
805
|
|
|
822
806
|
public function set_underline(enabled: bool) -> Result[bool, Error]:
|
|
823
807
|
var sequence = string.String.with_capacity(6)
|
|
824
808
|
defer: sequence.release()
|
|
825
|
-
if enabled:
|
|
826
|
-
append_csi(ref_of(sequence), "4m")
|
|
827
|
-
else:
|
|
828
|
-
append_csi(ref_of(sequence), "24m")
|
|
809
|
+
if enabled: append_csi(ref_of(sequence), "4m") else: append_csi(ref_of(sequence), "24m")
|
|
829
810
|
return write_stdout_sequence(sequence, "terminal underline styling failed")
|
|
830
811
|
|
|
831
812
|
|
data/std/thread.mt
CHANGED
|
@@ -49,9 +49,8 @@ function thread_entry_void(frame: ptr[void]) -> void:
|
|
|
49
49
|
public function spawn_raw(entry: fn(arg: ptr[void]) -> void, arg: ptr[void]) -> Result[Thread, Error]:
|
|
50
50
|
let handle = heap.must_alloc_zeroed[NativeThreadHandle](1)
|
|
51
51
|
let state = heap.must_alloc_zeroed[RawStartState](1)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
state.arg = arg
|
|
52
|
+
state.entry = entry
|
|
53
|
+
state.arg = arg
|
|
55
54
|
|
|
56
55
|
let status_code = libuv.thread_create(handle, thread_entry_raw, unsafe: ptr[void]<-state)
|
|
57
56
|
if status_code != 0:
|
|
@@ -65,7 +64,7 @@ public function spawn_raw(entry: fn(arg: ptr[void]) -> void, arg: ptr[void]) ->
|
|
|
65
64
|
public function spawn(run: fn() -> void) -> Result[Thread, Error]:
|
|
66
65
|
let handle = heap.must_alloc_zeroed[NativeThreadHandle](1)
|
|
67
66
|
let state = heap.must_alloc_zeroed[VoidStartState](1)
|
|
68
|
-
|
|
67
|
+
state.run = run
|
|
69
68
|
|
|
70
69
|
let status_code = libuv.thread_create(handle, thread_entry_void, unsafe: ptr[void]<-state)
|
|
71
70
|
if status_code != 0:
|
data/std/tls.mt
CHANGED
|
@@ -115,8 +115,8 @@ function handle_as_poll(handle: ptr[NativeHandle]) -> ptr[NativePollHandle]:
|
|
|
115
115
|
return unsafe: ptr[NativePollHandle]<-handle
|
|
116
116
|
|
|
117
117
|
|
|
118
|
-
function noop_waiter(
|
|
119
|
-
|
|
118
|
+
function noop_waiter(_frame: ptr[void]) -> void:
|
|
119
|
+
pass
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
function poll_task(state: ptr[PollState]) -> Task[Result[int, Error]]:
|
|
@@ -271,19 +271,18 @@ function poll_on(runtime: aio.Runtime, fd: int, events: int) -> Task[Result[int,
|
|
|
271
271
|
let state = heap.must_alloc_zeroed[PollState](1)
|
|
272
272
|
let poll = alloc_poll_handle()
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
state.released = false
|
|
274
|
+
state.ready = false
|
|
275
|
+
state.status_code = 0
|
|
276
|
+
state.revents = 0
|
|
277
|
+
state.error = empty_error()
|
|
278
|
+
state.error_owned = false
|
|
279
|
+
state.waiter_frame = null
|
|
280
|
+
state.waiter = noop_waiter
|
|
281
|
+
state.waiter_registered = false
|
|
282
|
+
state.handle = poll
|
|
283
|
+
state.closing = false
|
|
284
|
+
state.closed = false
|
|
285
|
+
state.released = false
|
|
287
286
|
|
|
288
287
|
let init_status = libuv.poll_init(loop, poll, fd)
|
|
289
288
|
if init_status != 0:
|
|
@@ -416,7 +415,7 @@ async function read_once_on(
|
|
|
416
415
|
let buffer = heap.must_alloc[ubyte](max_bytes)
|
|
417
416
|
while true:
|
|
418
417
|
let client = unsafe: read(state).client else:
|
|
419
|
-
|
|
418
|
+
heap.release(buffer)
|
|
420
419
|
return Result[bytes.Bytes, Error].failure(error = tls_error("tls stream is released"))
|
|
421
420
|
|
|
422
421
|
var transferred: ptr_uint = 0
|
|
@@ -481,10 +480,8 @@ public async function connect_on(runtime: aio.Runtime, host: str, port: int) ->
|
|
|
481
480
|
defer: release_socket_addresses(ref_of(addresses))
|
|
482
481
|
|
|
483
482
|
var last_error = tls_error("tls connect failed")
|
|
484
|
-
var last_error_owned = true
|
|
485
483
|
defer:
|
|
486
|
-
|
|
487
|
-
last_error.release()
|
|
484
|
+
last_error.release()
|
|
488
485
|
|
|
489
486
|
var index: ptr_uint = 0
|
|
490
487
|
while index < addresses.len:
|
|
@@ -494,13 +491,10 @@ public async function connect_on(runtime: aio.Runtime, host: str, port: int) ->
|
|
|
494
491
|
let connect_result = await net.connect_on(runtime, unsafe: read(current))
|
|
495
492
|
match connect_result:
|
|
496
493
|
Result.failure as connect_error_payload:
|
|
497
|
-
|
|
498
|
-
last_error.release()
|
|
494
|
+
last_error.release()
|
|
499
495
|
last_error = take_net_error(connect_error_payload.error)
|
|
500
|
-
last_error_owned = true
|
|
501
496
|
Result.success as connect_payload:
|
|
502
|
-
|
|
503
|
-
last_error.release()
|
|
497
|
+
last_error.release()
|
|
504
498
|
return await client_on(runtime, host, connect_payload.value)
|
|
505
499
|
|
|
506
500
|
index += 1
|
|
@@ -536,11 +530,10 @@ public async function client_on(runtime: aio.Runtime, host: str, transport: net.
|
|
|
536
530
|
return Result[Stream, Error].failure(error = tls_error("tls connect failed"))
|
|
537
531
|
|
|
538
532
|
let state = heap.must_alloc_zeroed[StreamState](1)
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
state.pending_operation = false
|
|
533
|
+
state.client = live_client
|
|
534
|
+
state.tcp = owned_transport
|
|
535
|
+
state.fd = payload.value
|
|
536
|
+
state.pending_operation = false
|
|
544
537
|
|
|
545
538
|
var stream = Stream(state = state)
|
|
546
539
|
let handshake_result = await handshake_on(runtime, state)
|