mt-lang 0.2.18 → 0.2.19

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: 35157666294e3aadb1c8106b1ccbacdf0d548f06a009b99c2a7799e76436e320
4
- data.tar.gz: acc6091f6f22e2bbe340ebba54f49dc0b195849294f6086959027751a6cbfee1
3
+ metadata.gz: '076938689f867b9d3d7f60eab7f4654c03a45ea69b429f1af17c86a3afef51a5'
4
+ data.tar.gz: 6f01bf9d070e1307666949acf47d99170d6b28c0048c868a6310663f2d55c919
5
5
  SHA512:
6
- metadata.gz: 831ed7f14aaef5be511434b7697f0f0d23896d78fd2cfd5ef6037fee9c9909dbce3cc6c51bd6d9b1c95dae2dbeb7990b1cece93f455990f3f7c4e911dc64e24a
7
- data.tar.gz: 6621e043744173fe77a457a3823a6b38032b4f12a71f96f707539154578bf9b7c95d8e688d36ba7d44404148ed4f85a47b55a3a00d81fb13e466fa86e9bc1be7
6
+ metadata.gz: 8141047ac65832b64b8eab1d565b5c3eb3bf8841b5541624605179a1e4bc0479f4dab16a92b3b7055e2eb844e37781aac7acab2aa812b348e53d9a151a16fe97
7
+ data.tar.gz: e5ead28d45b33a6c7fdb5c46f84cdd9a887e6bca593b841687a1d1124ba904f02ee09bdb1ef8dab87f2b8dcfcd6480190e94cea57e8b3b4853148d06d199f6e6
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.18"
6
+ VERSION = "0.2.19"
7
7
 
8
8
  def self.root
9
9
  @root ||= Pathname.new(File.expand_path("../..", __dir__))
@@ -237,6 +237,8 @@ module MilkTea
237
237
  true
238
238
  elsif (expr = extract_expr(stmt)) && own_struct_field_transfer?(expr, name)
239
239
  true
240
+ elsif stmt.is_a?(AST::Assignment) && stmt.value.is_a?(AST::Identifier) && stmt.value.name == name
241
+ true
240
242
  else
241
243
  false
242
244
  end
@@ -821,6 +821,7 @@ module MilkTea
821
821
  message: "every #{kind} branch returns a value; rewrite as `return #{kind} …` expression",
822
822
  )
823
823
  elsif stmts.all? { |s| s.is_a?(AST::Assignment) && s.operator == "=" } &&
824
+ stmts.all? { |s| s.target.respond_to?(:name) } &&
824
825
  stmts.map { |s| node_fingerprint(s.target) }.uniq.size == 1
825
826
  target_name = stmts.first.target.name
826
827
  emit_conciseness_hint(
@@ -247,7 +247,7 @@ public function sleep_release(frame: ptr[void]) -> void:
247
247
 
248
248
  if not state.closing:
249
249
  state.closing = true
250
- let handle = timer_as_handle(unsafe: ptr[NativeTimerHandle]<-state.timer)
250
+ let handle = timer_as_handle(ptr[NativeTimerHandle]<-state.timer)
251
251
  libuv.close(handle, sleep_timer_close)
252
252
 
253
253
 
@@ -323,7 +323,7 @@ public function work_release[T](frame: ptr[void]) -> void:
323
323
 
324
324
  state.released = true
325
325
  if state.queued and state.work != null:
326
- libuv.cancel(work_as_req(unsafe: ptr[NativeWorkRequest]<-state.work))
326
+ libuv.cancel(work_as_req(ptr[NativeWorkRequest]<-state.work))
327
327
 
328
328
 
329
329
  public function work_take_result[T](frame: ptr[void]) -> T:
data/std/behavior_tree.mt CHANGED
@@ -128,7 +128,7 @@ function tick_node[Context](tree: ref[Tree[Context]], node_id: ptr_uint, context
128
128
 
129
129
  var saw_running = false
130
130
  for child_ptr in read(node).children:
131
- let child_status = tick_node(tree, unsafe: read(child_ptr), context)
131
+ let child_status = tick_node(tree, read(child_ptr), context)
132
132
  match child_status:
133
133
  Status.success:
134
134
  pass
@@ -148,7 +148,7 @@ function tick_node[Context](tree: ref[Tree[Context]], node_id: ptr_uint, context
148
148
 
149
149
  var saw_running = false
150
150
  for child_ptr in read(node).children:
151
- let child_status = tick_node(tree, unsafe: read(child_ptr), context)
151
+ let child_status = tick_node(tree, read(child_ptr), context)
152
152
  match child_status:
153
153
  Status.success:
154
154
  return Status.success
data/std/deque.mt CHANGED
@@ -140,6 +140,35 @@ extending Deque[T]:
140
140
  this.capacity = new_capacity
141
141
 
142
142
 
143
+ public editable function shrink_to_fit() -> void:
144
+ if this.len == 0:
145
+ heap.release(this.data)
146
+ this.data = null
147
+ this.head = 0
148
+ this.capacity = 0
149
+ return
150
+
151
+ if this.len == this.capacity:
152
+ return
153
+
154
+ let new_data = heap.must_alloc[T](this.len)
155
+ let old_data = this.data
156
+ if old_data != null:
157
+ unsafe:
158
+ let old_ptr = ptr[T]<-old_data
159
+ let new_ptr = ptr[T]<-new_data
160
+ var index: ptr_uint = 0
161
+ while index < this.len:
162
+ let source_index = Deque[T].physical_index(this.head, this.capacity, index)
163
+ read(new_ptr + index) = read(old_ptr + source_index)
164
+ index += 1
165
+
166
+ heap.release(old_data)
167
+ this.data = new_data
168
+ this.head = 0
169
+ this.capacity = this.len
170
+
171
+
143
172
  public editable function push_back(value: T) -> void:
144
173
  if this.len == this.capacity:
145
174
  this.reserve(this.len + 1)
data/std/goap.mt CHANGED
@@ -323,13 +323,12 @@ extending Planner[World, Goal, Context]:
323
323
  action_index += 1
324
324
  continue
325
325
 
326
- if next_cost < unsafe: read(existing_ptr).cost_so_far:
327
- unsafe:
328
- read(existing_ptr).parent_index = current_index
329
- read(existing_ptr).has_parent = true
330
- read(existing_ptr).action_index = action_index
331
- read(existing_ptr).cost_so_far = next_cost
332
- read(existing_ptr).closed = false
326
+ if next_cost < read(existing_ptr).cost_so_far:
327
+ read(existing_ptr).parent_index = current_index
328
+ read(existing_ptr).has_parent = true
329
+ read(existing_ptr).action_index = action_index
330
+ read(existing_ptr).cost_so_far = next_cost
331
+ read(existing_ptr).closed = false
333
332
  if not open_list_contains(ref_of(open_list), existing_payload.value):
334
333
  open_list.push(existing_payload.value)
335
334
  action_index += 1
data/std/net/manager.mt CHANGED
@@ -331,7 +331,7 @@ public function create_server(
331
331
  is_server = true,
332
332
  max_players = config.max_players,
333
333
  mux_session = session_p.value,
334
- mux_connection = unsafe: zero[mux.MuxedConnection],
334
+ mux_connection = zero[mux.MuxedConnection],
335
335
  local_player_id = 0u,
336
336
  players = vec.Vec[PlayerState].create(),
337
337
  next_player_id = 1u,
@@ -357,7 +357,7 @@ public function create_client(
357
357
  let client_mgr = NetworkManager(
358
358
  is_server = false,
359
359
  max_players = config.max_players,
360
- mux_session = unsafe: zero[mux.MuxedSession],
360
+ mux_session = zero[mux.MuxedSession],
361
361
  mux_connection = mux_conn_p.value,
362
362
  local_player_id = 0u,
363
363
  players = vec.Vec[PlayerState].create(),
data/std/net/packet.mt CHANGED
@@ -164,7 +164,7 @@ extending Stream:
164
164
  Result.failure as error_payload:
165
165
  return Result[ptr_uint, Error].failure(error = error_from_net(error_payload.error))
166
166
  Result.success as write_payload:
167
- unsafe: write_payload.value
167
+ write_payload.value
168
168
  return Result[ptr_uint, Error].success(value = content.len)
169
169
 
170
170
 
@@ -183,7 +183,7 @@ extending Stream:
183
183
  Result.failure as discard_payload:
184
184
  return Result[bytes.Bytes, Error].failure(error = discard_payload.error)
185
185
  Result.success as discard_payload:
186
- unsafe: discard_payload.value
186
+ discard_payload.value
187
187
  return Result[bytes.Bytes, Error].failure(error = packet_error(
188
188
  -2,
189
189
  "packet exceeds configured maximum"
data/std/net.mt CHANGED
@@ -736,7 +736,7 @@ function connect_cleanup_and_release(state: ptr[ConnectState]) -> void:
736
736
  read(state).result_owned = false
737
737
 
738
738
  if read(state).handle != null[ptr[NativeTcpHandle]]:
739
- close_tcp_handle(unsafe: ptr[NativeTcpHandle]<-read(state).handle)
739
+ close_tcp_handle(ptr[NativeTcpHandle]<-read(state).handle)
740
740
  read(state).handle = null
741
741
 
742
742
  heap.release(state)
data/std/process.mt CHANGED
@@ -94,7 +94,7 @@ public function parent_environment() -> vec.Vec[EnvironmentEntry]:
94
94
  nname.reserve(eq_pos)
95
95
  var ni: ptr_uint = 0
96
96
  while ni < eq_pos:
97
- nname.push_byte(ubyte<-(unsafe: read(entry_cstr + ni)))
97
+ nname.push_byte(ubyte<-(read(entry_cstr + ni)))
98
98
  ni += 1
99
99
  var nvalue = string.String.create()
100
100
  let vlen = len - eq_pos - 1
@@ -102,7 +102,7 @@ public function parent_environment() -> vec.Vec[EnvironmentEntry]:
102
102
  nvalue.reserve(vlen)
103
103
  var vi: ptr_uint = 0
104
104
  while vi < vlen:
105
- nvalue.push_byte(ubyte<-(unsafe: read(entry_cstr + eq_pos + 1 + vi)))
105
+ nvalue.push_byte(ubyte<-(read(entry_cstr + eq_pos + 1 + vi)))
106
106
  vi += 1
107
107
  result.push(EnvironmentEntry(
108
108
  name = nname.as_str(),
data/std/queue.mt CHANGED
@@ -47,6 +47,10 @@ extending Queue[T]:
47
47
  this.values.reserve(min_capacity)
48
48
 
49
49
 
50
+ public editable function shrink_to_fit() -> void:
51
+ this.values.shrink_to_fit()
52
+
53
+
50
54
  public editable function enqueue(value: T) -> void:
51
55
  this.values.push_back(value)
52
56
 
data/std/serialize.mt CHANGED
@@ -25,7 +25,7 @@ public function unpack[T](source: span[ubyte]) -> Result[T, bin.Error]:
25
25
  error = raw_unpack_error("source too short for target type")
26
26
  )
27
27
 
28
- var result = unsafe: zero[T]
28
+ var result = zero[T]
29
29
  var dest = unsafe: ptr[ubyte]<-ptr_of(result)
30
30
  var i: ptr_uint = 0
31
31
  while i < total:
@@ -59,7 +59,7 @@ extending bin.Reader:
59
59
  error = raw_unpack_error("reader returned empty data")
60
60
  )
61
61
 
62
- var result = unsafe: zero[T]
62
+ var result = zero[T]
63
63
  var dest = unsafe: ptr[ubyte]<-ptr_of(result)
64
64
  var i: ptr_uint = 0
65
65
  while i < total:
data/std/sparse_set.mt CHANGED
@@ -93,6 +93,12 @@ extending SparseSet[T]:
93
93
  this.keys.reserve(min_capacity)
94
94
 
95
95
 
96
+ public editable function shrink_to_fit() -> void:
97
+ this.sparse.shrink_to_fit()
98
+ this.dense.shrink_to_fit()
99
+ this.keys.shrink_to_fit()
100
+
101
+
96
102
  public editable function insert(key: ptr_uint, value: T) -> bool:
97
103
  while key >= this.sparse.len():
98
104
  this.sparse.push(SPARSE_EMPTY)
data/std/stack.mt CHANGED
@@ -47,6 +47,10 @@ extending Stack[T]:
47
47
  this.values.reserve(min_capacity)
48
48
 
49
49
 
50
+ public editable function shrink_to_fit() -> void:
51
+ this.values.shrink_to_fit()
52
+
53
+
50
54
  public editable function push(value: T) -> void:
51
55
  this.values.push_back(value)
52
56
 
data/std/string.mt CHANGED
@@ -133,6 +133,26 @@ extending String:
133
133
  this.capacity = new_capacity
134
134
 
135
135
 
136
+ public editable function shrink_to_fit() -> void:
137
+ if not this.owns_storage:
138
+ return
139
+
140
+ if this.len == 0:
141
+ heap.release(this.data)
142
+ this.data = null
143
+ this.capacity = 0
144
+ return
145
+
146
+ if this.len == this.capacity:
147
+ return
148
+
149
+ let resized = heap.resize[ubyte](this.data, this.len) else:
150
+ fatal(c"string.shrink_to_fit out of memory")
151
+
152
+ this.data = resized
153
+ this.capacity = this.len
154
+
155
+
136
156
  public editable function push_byte(value: ubyte) -> void:
137
157
  if this.len == this.capacity:
138
158
  this.reserve(this.len + 1)
data/std/toml.mt CHANGED
@@ -1214,7 +1214,7 @@ function append_value(output: ref[string.String], value: Value) -> void:
1214
1214
  let item = values.values.get(index) else:
1215
1215
  fatal(c"toml.append_value missing array item")
1216
1216
 
1217
- append_value(output, unsafe: read(item))
1217
+ append_value(output, read(item))
1218
1218
  index += 1
1219
1219
 
1220
1220
  output.push_byte(byte_right_bracket)
@@ -1233,7 +1233,7 @@ function append_value(output: ref[string.String], value: Value) -> void:
1233
1233
  let entry = object_entries.entries.get(index) else:
1234
1234
  fatal(c"toml.append_value missing object entry")
1235
1235
 
1236
- let current = unsafe: read(entry)
1236
+ let current = read(entry)
1237
1237
  append_entry_key(output, current.key.as_str())
1238
1238
  output.append(" = ")
1239
1239
  append_value(output, current.value)
data/std/vec.mt CHANGED
@@ -117,6 +117,23 @@ extending Vec[T]:
117
117
  this.capacity = new_capacity
118
118
 
119
119
 
120
+ public editable function shrink_to_fit() -> void:
121
+ if this.len == 0:
122
+ heap.release(this.data)
123
+ this.data = null
124
+ this.capacity = 0
125
+ return
126
+
127
+ if this.len == this.capacity:
128
+ return
129
+
130
+ let resized = heap.resize[T](this.data, this.len) else:
131
+ fatal(c"vec.shrink_to_fit out of memory")
132
+
133
+ this.data = resized
134
+ this.capacity = this.len
135
+
136
+
120
137
  public editable function append_span(values: span[T]) -> void:
121
138
  if values.len == 0:
122
139
  return
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.18
4
+ version: 0.2.19
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.18 installed!
589
+ Milk Tea 0.2.19 installed!
590
590
 
591
591
  System requirements:
592
592
  - A C compiler (gcc or clang) must be available on PATH