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/toml.mt CHANGED
@@ -634,7 +634,8 @@ function parse_string(parser: ref[Parser]) -> Result[string.String, ParseError]:
634
634
  if not parser_consume_byte(parser, byte_quote):
635
635
  return Result[string.String, ParseError].failure(error= parse_error(parser, "expected string"))
636
636
 
637
- var result = string.String.create()
637
+ # Moved into the success result on every exit path.
638
+ var result = string.String.create() # lint: ignore(owning-release-leak)
638
639
  while true:
639
640
  match parser_peek_byte(parser):
640
641
  Option.none:
@@ -801,8 +802,7 @@ function parse_array(parser: ref[Parser]) -> Result[ptr[Array]?, ParseError]:
801
802
  return Result[ptr[Array]?, ParseError].failure(error= parse_error(parser, "expected array"))
802
803
 
803
804
  let array_ptr = heap.must_alloc[Array](1)
804
- unsafe:
805
- read(array_ptr) = Array.create()
805
+ read(array_ptr) = Array.create()
806
806
 
807
807
  parser_skip_inline_space(parser)
808
808
  if parser_consume_byte(parser, byte_right_bracket):
@@ -813,13 +813,11 @@ function parse_array(parser: ref[Parser]) -> Result[ptr[Array]?, ParseError]:
813
813
  let value_result = parse_value(parser)
814
814
  match value_result:
815
815
  Result.failure as payload:
816
- unsafe:
817
- read(array_ptr).release()
816
+ read(array_ptr).release()
818
817
  heap.release(array_ptr)
819
818
  return Result[ptr[Array]?, ParseError].failure(error= payload.error)
820
819
  Result.success as payload:
821
- unsafe:
822
- read(array_ptr).values.push(payload.value)
820
+ read(array_ptr).values.push(payload.value)
823
821
 
824
822
  parser_skip_inline_space(parser)
825
823
  if parser_consume_byte(parser, byte_comma):
@@ -827,8 +825,7 @@ function parse_array(parser: ref[Parser]) -> Result[ptr[Array]?, ParseError]:
827
825
  if parser_consume_byte(parser, byte_right_bracket):
828
826
  return Result[ptr[Array]?, ParseError].success(value= array_ptr)
829
827
 
830
- unsafe:
831
- read(array_ptr).release()
828
+ read(array_ptr).release()
832
829
  heap.release(array_ptr)
833
830
  return Result[ptr[Array]?, ParseError].failure(error= parse_error(parser, "expected ',' or ']'"))
834
831
 
@@ -838,8 +835,7 @@ function parse_inline_object(parser: ref[Parser]) -> Result[ptr[Object]?, ParseE
838
835
  return Result[ptr[Object]?, ParseError].failure(error= parse_error(parser, "expected inline table"))
839
836
 
840
837
  let object_ptr = heap.must_alloc[Object](1)
841
- unsafe:
842
- read(object_ptr) = Object.create()
838
+ read(object_ptr) = Object.create()
843
839
 
844
840
  parser_skip_inline_space(parser)
845
841
  if parser_consume_byte(parser, byte_right_brace):
@@ -850,8 +846,7 @@ function parse_inline_object(parser: ref[Parser]) -> Result[ptr[Object]?, ParseE
850
846
  let key_result = parse_key(parser)
851
847
  match key_result:
852
848
  Result.failure as payload:
853
- unsafe:
854
- read(object_ptr).release()
849
+ read(object_ptr).release()
855
850
  heap.release(object_ptr)
856
851
  return Result[ptr[Object]?, ParseError].failure(error= payload.error)
857
852
  Result.success as key_payload:
@@ -859,8 +854,7 @@ function parse_inline_object(parser: ref[Parser]) -> Result[ptr[Object]?, ParseE
859
854
  parser_skip_inline_space(parser)
860
855
  if not parser_consume_byte(parser, byte_equal):
861
856
  key.release()
862
- unsafe:
863
- read(object_ptr).release()
857
+ read(object_ptr).release()
864
858
  heap.release(object_ptr)
865
859
  return Result[ptr[Object]?, ParseError].failure(error= parse_error(parser, "expected '='"))
866
860
 
@@ -869,22 +863,19 @@ function parse_inline_object(parser: ref[Parser]) -> Result[ptr[Object]?, ParseE
869
863
  match value_result:
870
864
  Result.failure as payload:
871
865
  key.release()
872
- unsafe:
873
- read(object_ptr).release()
866
+ read(object_ptr).release()
874
867
  heap.release(object_ptr)
875
868
  return Result[ptr[Object]?, ParseError].failure(error= payload.error)
876
869
  Result.success as value_payload:
877
870
  let key_text = key.as_str()
878
- if unsafe: read(object_ptr).contains(key_text):
871
+ if read(object_ptr).contains(key_text):
879
872
  key.release()
880
873
  release_value(value_payload.value)
881
- unsafe:
882
- read(object_ptr).release()
874
+ read(object_ptr).release()
883
875
  heap.release(object_ptr)
884
876
  return Result[ptr[Object]?, ParseError].failure(error= parse_error(parser, "duplicate key"))
885
877
 
886
- unsafe:
887
- read(object_ptr).entries.push(Entry(key = key, value = value_payload.value))
878
+ read(object_ptr).entries.push(Entry(key = key, value = value_payload.value))
888
879
 
889
880
  parser_skip_inline_space(parser)
890
881
  if parser_consume_byte(parser, byte_comma):
@@ -892,8 +883,7 @@ function parse_inline_object(parser: ref[Parser]) -> Result[ptr[Object]?, ParseE
892
883
  if parser_consume_byte(parser, byte_right_brace):
893
884
  return Result[ptr[Object]?, ParseError].success(value= object_ptr)
894
885
 
895
- unsafe:
896
- read(object_ptr).release()
886
+ read(object_ptr).release()
897
887
  heap.release(object_ptr)
898
888
  return Result[ptr[Object]?, ParseError].failure(error= parse_error(parser, "expected ',' or '}'"))
899
889
 
@@ -948,11 +938,15 @@ function parse_value(parser: ref[Parser]) -> Result[Value, ParseError]:
948
938
 
949
939
 
950
940
  function document_find_table_index(document: ref[Document], name: str) -> Option[ptr_uint]:
951
- return document.tables.find_index(proc(table_ptr: ptr[Table]) -> bool: unsafe: read(table_ptr).name.as_str().equal(name))
941
+ return document.tables.find_index(
942
+ proc(table_ptr: ptr[Table]) -> bool: unsafe: read(table_ptr).name.as_str().equal(name)
943
+ )
952
944
 
953
945
 
954
946
  function document_find_array_table_index(document: ref[Document], name: str) -> Option[ptr_uint]:
955
- return document.array_tables.find_index(proc(table_ptr: ptr[ArrayTable]) -> bool: unsafe: read(table_ptr).name.as_str().equal(name))
947
+ return document.array_tables.find_index(
948
+ proc(table_ptr: ptr[ArrayTable]) -> bool: unsafe: read(table_ptr).name.as_str().equal(name)
949
+ )
956
950
 
957
951
 
958
952
  function current_object_contains(document: ref[Document], cursor: Cursor, key: str) -> bool:
@@ -1107,7 +1101,8 @@ function parse_header(document: ref[Document], cursor: ref[Cursor], parser: ref[
1107
1101
 
1108
1102
  public function parse(text_value: str) -> Result[Document, ParseError]:
1109
1103
  var parser = Parser(text_value = text_value, index = 0, line = 1, column = 1)
1110
- var document = Document.create()
1104
+ # Moved into the success result; released on every failure return.
1105
+ var document = Document.create() # lint: ignore(owning-release-leak)
1111
1106
  var cursor = Cursor(kind = SectionKind.root, table_index = 0, array_table_index = 0, array_item_index = 0)
1112
1107
 
1113
1108
  while true:
@@ -1177,10 +1172,7 @@ function bare_header_name(text_value: str) -> bool:
1177
1172
 
1178
1173
 
1179
1174
  function append_header_name(output: ref[string.String], name: str) -> void:
1180
- if bare_header_name(name):
1181
- output.append(name)
1182
- else:
1183
- append_quoted_string(output, name)
1175
+ if bare_header_name(name): output.append(name) else: append_quoted_string(output, name)
1184
1176
 
1185
1177
 
1186
1178
  function append_entry_key(output: ref[string.String], key: str) -> void:
data/std/uri.mt CHANGED
@@ -111,7 +111,8 @@ function ascii_digit(value: ubyte) -> bool:
111
111
 
112
112
 
113
113
  function leading_slash_drive_path(path_text: str) -> bool:
114
- return path_text.len >= 3 and path_text.byte_at(0) == 47 and ascii_letter(path_text.byte_at(1)) and path_text.byte_at(2) == 58
114
+ return path_text.len >= 3 and path_text.byte_at(0) == 47 and
115
+ ascii_letter(path_text.byte_at(1)) and path_text.byte_at(2) == 58
115
116
 
116
117
 
117
118
  function owned_utf8_view(value: string.String) -> Option[str]:
data/std/utility.mt CHANGED
@@ -64,7 +64,7 @@ function combine_scores(mode: CombineMode, scores: ref[vec.Vec[float]]) -> float
64
64
  return 0.0
65
65
  product = product * s
66
66
  i += 1
67
- let exponent = 1.0 / float<-n
67
+ let exponent = 1.0 / n
68
68
  return float<-math.pow(double<-product, double<-exponent)
69
69
 
70
70
  if mode == CombineMode.multiplicative:
@@ -88,7 +88,7 @@ function combine_scores(mode: CombineMode, scores: ref[vec.Vec[float]]) -> float
88
88
  break
89
89
  sum = sum + unsafe: read(s_ptr)
90
90
  i += 1
91
- return sum / float<-n
91
+ return sum / n
92
92
 
93
93
  if mode == CombineMode.minimum:
94
94
  var best: float = 1.0
data/std/vec.mt CHANGED
@@ -105,10 +105,7 @@ extending Vec[T]:
105
105
  new_capacity = 4
106
106
 
107
107
  while new_capacity < min_capacity:
108
- if new_capacity > heap.ptr_uint_max / 2:
109
- new_capacity = min_capacity
110
- else:
111
- new_capacity *= 2
108
+ if new_capacity > heap.ptr_uint_max / 2: new_capacity = min_capacity else: new_capacity *= 2
112
109
 
113
110
  let resized = heap.resize[T](this.data, new_capacity) else:
114
111
  fatal(c"vec.reserve out of memory")
@@ -348,6 +345,7 @@ extending Iter[T]:
348
345
  total += 1
349
346
 
350
347
 
348
+ extending Vec[T]:
351
349
  public editable function sort() -> void:
352
350
  if this.len <= 1:
353
351
  return
@@ -419,17 +417,15 @@ extending Iter[T]:
419
417
  while low < high:
420
418
  let mid = low + (high - low) / 2
421
419
  let cmp = order[T](target, data_ptr + mid)
422
- if cmp < 0:
423
- high = mid
424
- else if cmp > 0:
425
- low = mid + 1
426
- else:
427
- return Option[ptr_uint].some(value = mid)
420
+ if cmp < 0: high = mid else if cmp > 0: low = mid + 1 else: return Option[ptr_uint].some(value = mid)
428
421
 
429
422
  return Option[ptr_uint].none
430
423
 
431
424
 
432
- public function binary_search_by(target: ptr[T], comparator: proc(target: ptr[T], element: ptr[T]) -> int) -> Option[ptr_uint]:
425
+ public function binary_search_by(
426
+ target: ptr[T],
427
+ comparator: proc(target: ptr[T], element: ptr[T]) -> int
428
+ ) -> Option[ptr_uint]:
433
429
  let data = this.data else:
434
430
  fatal(c"vec.binary_search_by missing storage")
435
431
 
@@ -440,11 +436,6 @@ extending Iter[T]:
440
436
  while low < high:
441
437
  let mid = low + (high - low) / 2
442
438
  let cmp = comparator(target, data_ptr + mid)
443
- if cmp < 0:
444
- high = mid
445
- else if cmp > 0:
446
- low = mid + 1
447
- else:
448
- return Option[ptr_uint].some(value = mid)
439
+ if cmp < 0: high = mid else if cmp > 0: low = mid + 1 else: return Option[ptr_uint].some(value = mid)
449
440
 
450
441
  return Option[ptr_uint].none
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.4.23
4
+ version: 0.4.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Long (Teefan) Tran
@@ -387,6 +387,7 @@ files:
387
387
  - lib/milk_tea/tooling/cli/commands/parse.rb
388
388
  - lib/milk_tea/tooling/cli/commands/run.rb
389
389
  - lib/milk_tea/tooling/cli/commands/snapshot.rb
390
+ - lib/milk_tea/tooling/cli/commands/std.rb
390
391
  - lib/milk_tea/tooling/cli/commands/test.rb
391
392
  - lib/milk_tea/tooling/cli/commands/toolchain.rb
392
393
  - lib/milk_tea/tooling/debug_info_formatter.rb
@@ -411,6 +412,7 @@ files:
411
412
  - lib/milk_tea/tooling/run.rb
412
413
  - lib/milk_tea/tooling/sexpr_dumper.rb
413
414
  - lib/milk_tea/tooling/sexpr_parser.rb
415
+ - lib/milk_tea/tooling/std_catalog.rb
414
416
  - lib/milk_tea/tooling/templates/wasm_shell.html
415
417
  - lib/milk_tea/tooling/toolchain_cli.rb
416
418
  - lib/milk_tea/tooling/views/404.erb
@@ -630,7 +632,7 @@ metadata:
630
632
  homepage_uri: https://teefan.github.io/mt-lang/
631
633
  source_code_uri: https://github.com/teefan/mt-lang
632
634
  post_install_message: |
633
- Milk Tea 0.4.23 installed!
635
+ Milk Tea 0.4.25 installed!
634
636
 
635
637
  System requirements:
636
638
  - A C compiler (gcc or clang) must be available on PATH
@@ -652,7 +654,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
652
654
  - !ruby/object:Gem::Version
653
655
  version: '0'
654
656
  requirements: []
655
- rubygems_version: 4.0.18
657
+ rubygems_version: 4.0.16
656
658
  specification_version: 4
657
659
  summary: The Milk Tea programming language compiler toolchain
658
660
  test_files: []