mt-lang 0.2.21 → 0.2.22
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/lib/milk_tea/base.rb +1 -1
- data/std/asset_pack.mt +13 -13
- data/std/binary.mt +1 -1
- data/std/hash.mt +11 -11
- data/std/net/session.mt +5 -5
- data/std/random.mt +23 -31
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a2ffe49a95d73789f46660b0bf1ccdd0e8cca26846d19a33352751c93371531a
|
|
4
|
+
data.tar.gz: 75be2b9035d9271b691849b98769073d875f3a81aeb656feafab63b5998ca371
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a52f4fe111b80f9ea19dd24b1df46356a1450134a3bd01fce0abd50d482e4b670ad9462d4884384a09447ab1483f6c49e37175191da86abb8143fc7446109f5a
|
|
7
|
+
data.tar.gz: 75be516db3258f9c705fcf6d9f4d3a84995e2fb2c91dddbc8899cf7ac3f79fdc1054b7068567654aef88c29637e5dff136894b1ceed50b4436354525e3298d53
|
data/lib/milk_tea/base.rb
CHANGED
data/std/asset_pack.mt
CHANGED
|
@@ -50,18 +50,18 @@ public function open(path: str) -> Result[Reader, Error]:
|
|
|
50
50
|
stdio.file_close(file)
|
|
51
51
|
return Result[Reader, Error].failure(error= Error.invalid_magic)
|
|
52
52
|
|
|
53
|
-
let version =
|
|
53
|
+
let version = decode_ushort_le(unsafe: header_ptr + 4)
|
|
54
54
|
if version != VERSION:
|
|
55
55
|
stdio.file_close(file)
|
|
56
56
|
return Result[Reader, Error].failure(error= Error.unsupported_version)
|
|
57
57
|
|
|
58
|
-
let header_bits =
|
|
58
|
+
let header_bits = decode_ushort_le(unsafe: header_ptr + 6)
|
|
59
59
|
if header_bits != HEADER_FLAGS:
|
|
60
60
|
stdio.file_close(file)
|
|
61
61
|
return Result[Reader, Error].failure(error= Error.unsupported_flags)
|
|
62
62
|
|
|
63
|
-
let entry_count =
|
|
64
|
-
let index_size_result =
|
|
63
|
+
let entry_count = decode_uint_le(unsafe: header_ptr + 8)
|
|
64
|
+
let index_size_result = decode_ulong_le(unsafe: header_ptr + 12)
|
|
65
65
|
var index_size: ptr_uint
|
|
66
66
|
match index_size_result:
|
|
67
67
|
Result.failure as payload:
|
|
@@ -70,7 +70,7 @@ public function open(path: str) -> Result[Reader, Error]:
|
|
|
70
70
|
Result.success as index_payload:
|
|
71
71
|
index_size = index_payload.value
|
|
72
72
|
|
|
73
|
-
let data_offset_result =
|
|
73
|
+
let data_offset_result = decode_ulong_le(unsafe: header_ptr + 20)
|
|
74
74
|
var data_offset: ptr_uint
|
|
75
75
|
match data_offset_result:
|
|
76
76
|
Result.failure as payload:
|
|
@@ -147,12 +147,12 @@ function read_entry_metadata(file: stdio.File?) -> Result[EntryMetadata, Error]:
|
|
|
147
147
|
if not read_exact(file, prefix_ptr, ENTRY_PREFIX_SIZE_BYTES):
|
|
148
148
|
return Result[EntryMetadata, Error].failure(error= Error.malformed_index)
|
|
149
149
|
|
|
150
|
-
let path_length = ptr_uint<-
|
|
150
|
+
let path_length = ptr_uint<-decode_uint_le(prefix_ptr)
|
|
151
151
|
if path_length == 0:
|
|
152
152
|
return Result[EntryMetadata, Error].failure(error= Error.malformed_index)
|
|
153
153
|
|
|
154
|
-
let entry_bits =
|
|
155
|
-
let data_offset_result =
|
|
154
|
+
let entry_bits = decode_uint_le(unsafe: prefix_ptr + 4)
|
|
155
|
+
let data_offset_result = decode_ulong_le(unsafe: prefix_ptr + 8)
|
|
156
156
|
var data_offset: ptr_uint
|
|
157
157
|
match data_offset_result:
|
|
158
158
|
Result.failure as payload:
|
|
@@ -160,7 +160,7 @@ function read_entry_metadata(file: stdio.File?) -> Result[EntryMetadata, Error]:
|
|
|
160
160
|
Result.success as data_offset_payload:
|
|
161
161
|
data_offset = data_offset_payload.value
|
|
162
162
|
|
|
163
|
-
let stored_size_result =
|
|
163
|
+
let stored_size_result = decode_ulong_le(unsafe: prefix_ptr + 16)
|
|
164
164
|
var stored_size: ptr_uint
|
|
165
165
|
match stored_size_result:
|
|
166
166
|
Result.failure as payload:
|
|
@@ -168,7 +168,7 @@ function read_entry_metadata(file: stdio.File?) -> Result[EntryMetadata, Error]:
|
|
|
168
168
|
Result.success as stored_size_payload:
|
|
169
169
|
stored_size = stored_size_payload.value
|
|
170
170
|
|
|
171
|
-
let unpacked_size_result =
|
|
171
|
+
let unpacked_size_result = decode_ulong_le(unsafe: prefix_ptr + 24)
|
|
172
172
|
var unpacked_size: ptr_uint
|
|
173
173
|
match unpacked_size_result:
|
|
174
174
|
Result.failure as payload:
|
|
@@ -228,12 +228,12 @@ function bytes_equal_str(left: ptr[ubyte], left_len: ptr_uint, right: str) -> bo
|
|
|
228
228
|
return true
|
|
229
229
|
|
|
230
230
|
|
|
231
|
-
function
|
|
231
|
+
function decode_ushort_le(bytes: ptr[ubyte]) -> uint:
|
|
232
232
|
unsafe:
|
|
233
233
|
return uint<-read(bytes + 0) | (uint<-read(bytes + 1) << 8)
|
|
234
234
|
|
|
235
235
|
|
|
236
|
-
function
|
|
236
|
+
function decode_uint_le(bytes: ptr[ubyte]) -> uint:
|
|
237
237
|
unsafe:
|
|
238
238
|
return (
|
|
239
239
|
uint<-read(bytes + 0) |
|
|
@@ -243,7 +243,7 @@ function decode_u32_le(bytes: ptr[ubyte]) -> uint:
|
|
|
243
243
|
)
|
|
244
244
|
|
|
245
245
|
|
|
246
|
-
function
|
|
246
|
+
function decode_ulong_le(bytes: ptr[ubyte]) -> Result[ptr_uint, Error]:
|
|
247
247
|
if size_of(ptr[void]) < 8:
|
|
248
248
|
var upper_index: ptr_uint = 4
|
|
249
249
|
while upper_index < 8:
|
data/std/binary.mt
CHANGED
|
@@ -114,7 +114,7 @@ extending Writer:
|
|
|
114
114
|
public editable function write_uint_at(position: ptr_uint, value: uint) -> void:
|
|
115
115
|
let buffer_span = this.buffer.as_span()
|
|
116
116
|
if position + 4 > buffer_span.len:
|
|
117
|
-
fatal(c"binary.
|
|
117
|
+
fatal(c"binary.write_uint_at position out of bounds")
|
|
118
118
|
unsafe:
|
|
119
119
|
read(buffer_span.data + position) = ubyte<-(value & 0xFF)
|
|
120
120
|
read(buffer_span.data + position + 1) = ubyte<-((value >> 8) & 0xFF)
|
data/std/hash.mt
CHANGED
|
@@ -189,7 +189,7 @@ extending char:
|
|
|
189
189
|
# hash mixes the value's bytes (FNV-1a); equal/order use native operators.
|
|
190
190
|
# ---------------------------------------------------------------------------
|
|
191
191
|
|
|
192
|
-
function
|
|
192
|
+
function hash_uint(value: uint) -> uint:
|
|
193
193
|
let fnv: uint = 0x811C9DC5
|
|
194
194
|
let prime: uint = 0x01000193
|
|
195
195
|
var h = fnv
|
|
@@ -200,14 +200,14 @@ function hash_u32(value: uint) -> uint:
|
|
|
200
200
|
return h
|
|
201
201
|
|
|
202
202
|
|
|
203
|
-
function
|
|
204
|
-
return
|
|
203
|
+
function hash_ulong(value: ulong) -> uint:
|
|
204
|
+
return hash_uint(uint<-((value >> uint<-(32)) ^ value))
|
|
205
205
|
|
|
206
206
|
|
|
207
207
|
extending byte:
|
|
208
208
|
public static function hash(value: const_ptr[byte]) -> uint:
|
|
209
209
|
unsafe:
|
|
210
|
-
return
|
|
210
|
+
return hash_uint(uint<-(int<-read(ptr[byte]<-value)))
|
|
211
211
|
|
|
212
212
|
|
|
213
213
|
public static function equal(a: const_ptr[byte], b: const_ptr[byte]) -> bool:
|
|
@@ -229,7 +229,7 @@ extending byte:
|
|
|
229
229
|
extending ubyte:
|
|
230
230
|
public static function hash(value: const_ptr[ubyte]) -> uint:
|
|
231
231
|
unsafe:
|
|
232
|
-
return
|
|
232
|
+
return hash_uint(uint<-read(ptr[ubyte]<-value))
|
|
233
233
|
|
|
234
234
|
|
|
235
235
|
public static function equal(a: const_ptr[ubyte], b: const_ptr[ubyte]) -> bool:
|
|
@@ -251,7 +251,7 @@ extending ubyte:
|
|
|
251
251
|
extending short:
|
|
252
252
|
public static function hash(value: const_ptr[short]) -> uint:
|
|
253
253
|
unsafe:
|
|
254
|
-
return
|
|
254
|
+
return hash_uint(uint<-(int<-read(ptr[short]<-value)))
|
|
255
255
|
|
|
256
256
|
|
|
257
257
|
public static function equal(a: const_ptr[short], b: const_ptr[short]) -> bool:
|
|
@@ -273,7 +273,7 @@ extending short:
|
|
|
273
273
|
extending ushort:
|
|
274
274
|
public static function hash(value: const_ptr[ushort]) -> uint:
|
|
275
275
|
unsafe:
|
|
276
|
-
return
|
|
276
|
+
return hash_uint(uint<-read(ptr[ushort]<-value))
|
|
277
277
|
|
|
278
278
|
|
|
279
279
|
public static function equal(a: const_ptr[ushort], b: const_ptr[ushort]) -> bool:
|
|
@@ -295,7 +295,7 @@ extending ushort:
|
|
|
295
295
|
extending long:
|
|
296
296
|
public static function hash(value: const_ptr[long]) -> uint:
|
|
297
297
|
unsafe:
|
|
298
|
-
return
|
|
298
|
+
return hash_ulong(ulong<-read(ptr[long]<-value))
|
|
299
299
|
|
|
300
300
|
|
|
301
301
|
public static function equal(a: const_ptr[long], b: const_ptr[long]) -> bool:
|
|
@@ -317,7 +317,7 @@ extending long:
|
|
|
317
317
|
extending ulong:
|
|
318
318
|
public static function hash(value: const_ptr[ulong]) -> uint:
|
|
319
319
|
unsafe:
|
|
320
|
-
return
|
|
320
|
+
return hash_ulong(read(ptr[ulong]<-value))
|
|
321
321
|
|
|
322
322
|
|
|
323
323
|
public static function equal(a: const_ptr[ulong], b: const_ptr[ulong]) -> bool:
|
|
@@ -339,7 +339,7 @@ extending ulong:
|
|
|
339
339
|
extending ptr_int:
|
|
340
340
|
public static function hash(value: const_ptr[ptr_int]) -> uint:
|
|
341
341
|
unsafe:
|
|
342
|
-
return
|
|
342
|
+
return hash_ulong(ulong<-read(ptr[ptr_int]<-value))
|
|
343
343
|
|
|
344
344
|
|
|
345
345
|
public static function equal(a: const_ptr[ptr_int], b: const_ptr[ptr_int]) -> bool:
|
|
@@ -410,7 +410,7 @@ public function order_struct[T](a: const_ptr[T], b: const_ptr[T]) -> int:
|
|
|
410
410
|
extending ptr_uint:
|
|
411
411
|
public static function hash(value: const_ptr[ptr_uint]) -> uint:
|
|
412
412
|
unsafe:
|
|
413
|
-
return
|
|
413
|
+
return hash_ulong(ulong<-read(ptr[ptr_uint]<-value))
|
|
414
414
|
|
|
415
415
|
|
|
416
416
|
public static function equal(a: const_ptr[ptr_uint], b: const_ptr[ptr_uint]) -> bool:
|
data/std/net/session.mt
CHANGED
|
@@ -167,7 +167,7 @@ function generate_handshake_key() -> Result[ulong, net.Error]:
|
|
|
167
167
|
return Result[ulong, net.Error].success(value = value)
|
|
168
168
|
|
|
169
169
|
|
|
170
|
-
function
|
|
170
|
+
function decode_uint_at(data: span[ubyte], offset: ptr_uint) -> uint:
|
|
171
171
|
unsafe:
|
|
172
172
|
return uint<-read(data.data + offset) | (uint<-read(data.data + offset + 1) << 8) | (uint<-read(data.data + offset + 2) << 16) | (uint<-read(data.data + offset + 3) << 24)
|
|
173
173
|
|
|
@@ -536,7 +536,7 @@ function handle_incoming_conn(conn: ref[Connection], msg: ref[chan.Message]) ->
|
|
|
536
536
|
conn.frame_since_last_recv = 0
|
|
537
537
|
let hb_span = unsafe: span[ubyte](data = span.data + 1, len = span.len - 1)
|
|
538
538
|
if hb_span.len >= 4:
|
|
539
|
-
let echoed =
|
|
539
|
+
let echoed = decode_uint_at(hb_span, 0)
|
|
540
540
|
var ack = build_heartbeat_ack(echoed)
|
|
541
541
|
let peer_addr_result = conn.channel.peer_address()
|
|
542
542
|
match peer_addr_result:
|
|
@@ -555,7 +555,7 @@ function handle_incoming_conn(conn: ref[Connection], msg: ref[chan.Message]) ->
|
|
|
555
555
|
conn.frame_since_last_recv = 0
|
|
556
556
|
let echo_span = unsafe: span[ubyte](data = span.data + 1, len = span.len - 1)
|
|
557
557
|
if echo_span.len >= 4:
|
|
558
|
-
let echoed =
|
|
558
|
+
let echoed = decode_uint_at(echo_span, 0)
|
|
559
559
|
if conn.last_heartbeat_sent > echoed:
|
|
560
560
|
conn.ping_rtt_frames = conn.last_heartbeat_sent - echoed
|
|
561
561
|
msg.release()
|
|
@@ -920,7 +920,7 @@ function handle_incoming_session(session: ref[Session], msg: ref[chan.HostMessag
|
|
|
920
920
|
update_peer_last_recv(session, peer_payload.value)
|
|
921
921
|
let hb_span = unsafe: span[ubyte](data = span.data + 1, len = span.len - 1)
|
|
922
922
|
if hb_span.len >= 4:
|
|
923
|
-
let echoed =
|
|
923
|
+
let echoed = decode_uint_at(hb_span, 0)
|
|
924
924
|
var ack = build_heartbeat_ack(echoed)
|
|
925
925
|
let addr_result = msg.source.copy()
|
|
926
926
|
match addr_result:
|
|
@@ -973,7 +973,7 @@ function handle_connect_request(session: ref[Session], msg: ref[chan.HostMessage
|
|
|
973
973
|
msg.release()
|
|
974
974
|
return
|
|
975
975
|
|
|
976
|
-
let client_version =
|
|
976
|
+
let client_version = decode_uint_at(req_span, 0)
|
|
977
977
|
if client_version != session.config.protocol_version:
|
|
978
978
|
var reject = build_connect_reject(reject_reason_version)
|
|
979
979
|
let addr_result = msg.source.copy()
|
data/std/random.mt
CHANGED
|
@@ -9,9 +9,9 @@ public struct Rng:
|
|
|
9
9
|
|
|
10
10
|
public function from_seed(seed: ulong) -> Rng:
|
|
11
11
|
var rng = Rng(state = 0ul, increment = (seed << 1ul) | 1ul)
|
|
12
|
-
rng.
|
|
12
|
+
rng.next_uint()
|
|
13
13
|
rng.state = rng.state + seed
|
|
14
|
-
rng.
|
|
14
|
+
rng.next_uint()
|
|
15
15
|
return rng
|
|
16
16
|
|
|
17
17
|
|
|
@@ -27,7 +27,7 @@ public function from_seed_str(seed_str: str) -> Rng:
|
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
extending Rng:
|
|
30
|
-
public editable function
|
|
30
|
+
public editable function next_uint() -> uint:
|
|
31
31
|
let oldstate = this.state
|
|
32
32
|
this.state = oldstate * pcg_multiplier + this.increment
|
|
33
33
|
let xorshifted = uint<-(((oldstate >> 18ul) ^ oldstate) >> 27ul)
|
|
@@ -35,67 +35,59 @@ extending Rng:
|
|
|
35
35
|
return (xorshifted >> rot) | (xorshifted << (32u - rot))
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
public editable function
|
|
39
|
-
let hi = ulong<-this.
|
|
40
|
-
let lo = ulong<-this.
|
|
38
|
+
public editable function next_ulong() -> ulong:
|
|
39
|
+
let hi = ulong<-this.next_uint()
|
|
40
|
+
let lo = ulong<-this.next_uint()
|
|
41
41
|
return (hi << 32ul) | lo
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
public editable function
|
|
45
|
-
let val = this.
|
|
44
|
+
public editable function next_double() -> double:
|
|
45
|
+
let val = this.next_uint()
|
|
46
46
|
return double<-val / 4294967296.0
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
public editable function
|
|
50
|
-
let val = this.
|
|
49
|
+
public editable function next_float() -> float:
|
|
50
|
+
let val = this.next_uint()
|
|
51
51
|
return float<-val / 4294967296.0
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
public editable function next_ubyte() -> ubyte:
|
|
55
|
-
let val = this.
|
|
55
|
+
let val = this.next_uint()
|
|
56
56
|
return ubyte<-(val & 0xFFu)
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
public editable function next_bool() -> bool:
|
|
60
|
-
let val = this.
|
|
60
|
+
let val = this.next_uint()
|
|
61
61
|
return (val & 1u) != 0u
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
public editable function next_uint() -> uint:
|
|
65
|
-
return this.next_u32()
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
public editable function next_ulong() -> ulong:
|
|
69
|
-
return this.next_u64()
|
|
70
|
-
|
|
71
|
-
|
|
72
64
|
public editable function next_uint_range(min: uint, max: uint) -> uint:
|
|
73
65
|
if min >= max:
|
|
74
66
|
return min
|
|
75
67
|
let range = max - min
|
|
76
|
-
return min + (this.
|
|
68
|
+
return min + (this.next_uint() % range)
|
|
77
69
|
|
|
78
70
|
|
|
79
71
|
public editable function next_int_range(min: int, max: int) -> int:
|
|
80
72
|
if min >= max:
|
|
81
73
|
return min
|
|
82
74
|
let range = uint<-(max - min)
|
|
83
|
-
let offset = this.
|
|
75
|
+
let offset = this.next_uint() % range
|
|
84
76
|
return min + int<-offset
|
|
85
77
|
|
|
86
78
|
|
|
87
|
-
public editable function
|
|
88
|
-
let t = this.
|
|
79
|
+
public editable function next_double_range(min: double, max: double) -> double:
|
|
80
|
+
let t = this.next_double()
|
|
89
81
|
return min + (max - min) * t
|
|
90
82
|
|
|
91
83
|
|
|
92
|
-
public editable function
|
|
93
|
-
let t = this.
|
|
84
|
+
public editable function next_float_range(min: float, max: float) -> float:
|
|
85
|
+
let t = this.next_float()
|
|
94
86
|
return min + (max - min) * t
|
|
95
87
|
|
|
96
88
|
|
|
97
89
|
public editable function chance(probability: double) -> bool:
|
|
98
|
-
return this.
|
|
90
|
+
return this.next_double() < probability
|
|
99
91
|
|
|
100
92
|
|
|
101
93
|
public editable function pick_ref[T](items: span[T]) -> ptr[T]?:
|
|
@@ -130,17 +122,17 @@ extending Rng:
|
|
|
130
122
|
public editable function skip(count: ptr_uint) -> void:
|
|
131
123
|
var i: ptr_uint = 0
|
|
132
124
|
while i < count:
|
|
133
|
-
this.
|
|
125
|
+
this.next_uint()
|
|
134
126
|
i += 1
|
|
135
127
|
|
|
136
128
|
|
|
137
129
|
public editable function fork() -> Rng:
|
|
138
|
-
let seed = this.
|
|
130
|
+
let seed = this.next_ulong()
|
|
139
131
|
return from_seed(seed)
|
|
140
132
|
|
|
141
133
|
|
|
142
134
|
public editable function seeds() -> array[ulong, 4]:
|
|
143
135
|
return array[ulong, 4](
|
|
144
|
-
this.
|
|
145
|
-
this.
|
|
136
|
+
this.next_ulong(), this.next_ulong(),
|
|
137
|
+
this.next_ulong(), this.next_ulong()
|
|
146
138
|
)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mt-lang
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.22
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Long (Teefan) Tran
|
|
@@ -586,7 +586,7 @@ metadata:
|
|
|
586
586
|
homepage_uri: https://teefan.github.io/mt-lang/
|
|
587
587
|
source_code_uri: https://github.com/teefan/mt-lang
|
|
588
588
|
post_install_message: |
|
|
589
|
-
Milk Tea 0.2.
|
|
589
|
+
Milk Tea 0.2.22 installed!
|
|
590
590
|
|
|
591
591
|
System requirements:
|
|
592
592
|
- A C compiler (gcc or clang) must be available on PATH
|