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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e599b2192dada4fb02cbcefc522482028adce79482a53965f2715895ced1c744
4
- data.tar.gz: 2a4b8540ee7050b98707aee9cdd15b6f18504c8f401f9590c03720a49d88de78
3
+ metadata.gz: a2ffe49a95d73789f46660b0bf1ccdd0e8cca26846d19a33352751c93371531a
4
+ data.tar.gz: 75be2b9035d9271b691849b98769073d875f3a81aeb656feafab63b5998ca371
5
5
  SHA512:
6
- metadata.gz: a308513fd5d5aac4ab32c9707b1bb066851b103b4c3ff9521e880f0bdaf7501968329da6fa6a98487077f532189b0931bb4e715e2a495f359e383320ecc1b212
7
- data.tar.gz: d6f99733d6bc1be8eff2d4002b7b2e7d8aa8b1b6a48fe7ca26631a0ffc3780bafadcee2003c73afa473c457d59c736845d3e34f96e0a13ea1b3a48920b294b2c
6
+ metadata.gz: a52f4fe111b80f9ea19dd24b1df46356a1450134a3bd01fce0abd50d482e4b670ad9462d4884384a09447ab1483f6c49e37175191da86abb8143fc7446109f5a
7
+ data.tar.gz: 75be516db3258f9c705fcf6d9f4d3a84995e2fb2c91dddbc8899cf7ac3f79fdc1054b7068567654aef88c29637e5dff136894b1ceed50b4436354525e3298d53
data/lib/milk_tea/base.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require "pathname"
4
4
 
5
5
  module MilkTea
6
- VERSION = "0.2.21"
6
+ VERSION = "0.2.22"
7
7
 
8
8
  def self.root
9
9
  @root ||= Pathname.new(File.expand_path("../..", __dir__))
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 = decode_u16_le(unsafe: header_ptr + 4)
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 = decode_u16_le(unsafe: header_ptr + 6)
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 = decode_u32_le(unsafe: header_ptr + 8)
64
- let index_size_result = decode_u64_le(unsafe: header_ptr + 12)
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 = decode_u64_le(unsafe: header_ptr + 20)
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<-decode_u32_le(prefix_ptr)
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 = decode_u32_le(unsafe: prefix_ptr + 4)
155
- let data_offset_result = decode_u64_le(unsafe: prefix_ptr + 8)
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 = decode_u64_le(unsafe: prefix_ptr + 16)
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 = decode_u64_le(unsafe: prefix_ptr + 24)
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 decode_u16_le(bytes: ptr[ubyte]) -> uint:
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 decode_u32_le(bytes: ptr[ubyte]) -> uint:
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 decode_u64_le(bytes: ptr[ubyte]) -> Result[ptr_uint, Error]:
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.write_u32_at position out of bounds")
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 hash_u32(value: uint) -> uint:
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 hash_u64(value: ulong) -> uint:
204
- return hash_u32(uint<-((value >> uint<-(32)) ^ value))
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 hash_u32(uint<-(int<-read(ptr[byte]<-value)))
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 hash_u32(uint<-read(ptr[ubyte]<-value))
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 hash_u32(uint<-(int<-read(ptr[short]<-value)))
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 hash_u32(uint<-read(ptr[ushort]<-value))
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 hash_u64(ulong<-read(ptr[long]<-value))
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 hash_u64(read(ptr[ulong]<-value))
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 hash_u64(ulong<-read(ptr[ptr_int]<-value))
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 hash_u64(ulong<-read(ptr[ptr_uint]<-value))
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 decode_u32_at(data: span[ubyte], offset: ptr_uint) -> uint:
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 = decode_u32_at(hb_span, 0)
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 = decode_u32_at(echo_span, 0)
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 = decode_u32_at(hb_span, 0)
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 = decode_u32_at(req_span, 0)
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.next_u32()
12
+ rng.next_uint()
13
13
  rng.state = rng.state + seed
14
- rng.next_u32()
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 next_u32() -> uint:
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 next_u64() -> ulong:
39
- let hi = ulong<-this.next_u32()
40
- let lo = ulong<-this.next_u32()
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 next_f64() -> double:
45
- let val = this.next_u32()
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 next_f32() -> float:
50
- let val = this.next_u32()
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.next_u32()
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.next_u32()
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.next_u32() % range)
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.next_u32() % range
75
+ let offset = this.next_uint() % range
84
76
  return min + int<-offset
85
77
 
86
78
 
87
- public editable function next_f64_range(min: double, max: double) -> double:
88
- let t = this.next_f64()
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 next_f32_range(min: float, max: float) -> float:
93
- let t = this.next_f32()
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.next_f64() < probability
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.next_u32()
125
+ this.next_uint()
134
126
  i += 1
135
127
 
136
128
 
137
129
  public editable function fork() -> Rng:
138
- let seed = this.next_u64()
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.next_u64(), this.next_u64(),
145
- this.next_u64(), this.next_u64()
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.21
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.21 installed!
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