mt-lang 0.3.22 → 0.3.23

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: 6dc76fcf0acde63fa4060157d6c6864dedcc32b0f5c2cd60422e9948d9861dab
4
- data.tar.gz: 0b1bf5aee4d6be4d0f1968a7dacaf35e37557336a5911834a17324d23bd60ba3
3
+ metadata.gz: 7cfa07273d22ec7c182da079791513e546752f942e99e85d4ae68c3596a1dd96
4
+ data.tar.gz: 8ca9fb2fa55d9f2a7e9db9dd1f6935a0a82c8ad0f87f907b865007d5a27b68db
5
5
  SHA512:
6
- metadata.gz: 1b34537660a1c2424b3f829ff6ef18d35de4366fe76d0a0938216261b1f9c7c56d8fce2c8a0ac1162f17ddc8c1a2c565f9e08f2f5f0056624f4959d35833cabf
7
- data.tar.gz: 9b6b00b5b761ab3128c617acb8398c64b829df1e2d6984661bc6e8bfb2081b9fa408fd5e8774e1b540884a59caef4eef146c3a05f0d176cb62019471b4e28b88
6
+ metadata.gz: 0f8b9f5966a1bb53bfcf618293fdff445031610f97c316db745db6a06e3e32c50206fde9776b57ef205baab5c1ee240b11e0c003f9bed72d14f6f256d767b6d6
7
+ data.tar.gz: 50bd110c31a30966d1a25560c14e239ffee4f99e4991efd6a3029bb4dd6a05cea2d65c58e35dda94b917ec25ba1d7750e8d7e2d4578d1862b926dadfb4ab8f4b
data/lib/milk_tea/base.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require "pathname"
4
4
 
5
5
  module MilkTea
6
- VERSION = "0.3.22"
6
+ VERSION = "0.3.23"
7
7
 
8
8
  def self.root
9
9
  @root ||= Pathname.new(File.expand_path("../..", __dir__))
@@ -289,6 +289,31 @@ module MilkTea
289
289
  closest_dist <= max_distance ? closest : nil
290
290
  end
291
291
 
292
+ # Common std-library types that are usually used bare. When one of these
293
+ # names is unresolved, the compiler points at the module that exports it
294
+ # instead of leaving a generic "unknown name" diagnostic.
295
+ STD_TYPE_IMPORT_HINTS = {
296
+ "String" => "std.string",
297
+ "Vec" => "std.vec",
298
+ "Deque" => "std.deque",
299
+ "Map" => "std.map",
300
+ "Set" => "std.set",
301
+ "LinkedMap" => "std.linked_map",
302
+ "LinkedSet" => "std.linked_set",
303
+ "OrderedMap" => "std.ordered_map",
304
+ "OrderedSet" => "std.ordered_set",
305
+ "BinaryHeap" => "std.binary_heap",
306
+ "PriorityQueue" => "std.priority_queue",
307
+ "Counter" => "std.counter",
308
+ }.freeze
309
+
310
+ def import_hint_for_known_std_name(name)
311
+ module_path = STD_TYPE_IMPORT_HINTS[name.to_s]
312
+ return nil unless module_path
313
+
314
+ "type '#{name}' is available via 'import #{module_path}'"
315
+ end
316
+
292
317
  def levenshtein(s, t)
293
318
  m = s.length
294
319
  n = t.length
@@ -336,6 +336,9 @@ module MilkTea
336
336
  scoped_names = scopes.flat_map { |s| s.is_a?(Hash) ? s.keys : [] }.map(&:to_s)
337
337
  suggestion = suggest_name(expression.name, func_names + type_names + scoped_names)
338
338
  end
339
+ if (import_hint = import_hint_for_known_std_name(expression.name))
340
+ raise_sema_error("unknown name #{expression.name}; #{import_hint}")
341
+ end
339
342
  raise_sema_error("unknown name #{expression.name}", expression, suggestion: suggestion ? "did you mean '#{suggestion}'?" : nil)
340
343
  end
341
344
 
@@ -1505,6 +1508,9 @@ module MilkTea
1505
1508
  raise_sema_error("unsupported format spec #{part.format_spec.inspect}")
1506
1509
  end
1507
1510
  else
1511
+ if string_builder_type?(value_type)
1512
+ raise_sema_error("formatted string interpolation does not support #{value_type}; interpolate #{describe_expression(part.expression)}.as_str() instead, or append into it with .append_format(f\"...\")")
1513
+ end
1508
1514
  next if format_string_interpolation_supported?(value_type, context: "formatted string interpolation of #{value_type}")
1509
1515
  raise_sema_error("formatted string interpolation supports str, cstr, bool, numeric primitives, integer-backed enums/flags, and types implementing format_len()/append_format(output: ref[std.string.String]), got #{value_type}")
1510
1516
  end
@@ -365,6 +365,9 @@ module MilkTea
365
365
  unless suggestion
366
366
  suggestion = import_suggestion_for_type(name)
367
367
  end
368
+ unless suggestion
369
+ suggestion = import_hint_for_known_std_name(name)
370
+ end
368
371
  raise_sema_error("unknown type #{name}", type_ref, suggestion: suggestion ? "did you mean '#{suggestion}'?" : nil)
369
372
  end
370
373
  raise_sema_error("generic type #{name} requires type arguments", type_ref) if type.is_a?(Types::GenericStructDefinition) || type.is_a?(Types::GenericVariantDefinition)
@@ -638,6 +641,7 @@ module MilkTea
638
641
  def infer_layout_query_type(type_ref, context:)
639
642
  type = resolve_type_ref(type_ref)
640
643
  return type if sized_layout_type?(type)
644
+ return type if vector_type?(type) || matrix_type?(type) || quaternion_type?(type) || simd_type?(type)
641
645
 
642
646
  raise_sema_error("#{context} requires a concrete sized type, got #{type_ref}")
643
647
  end
@@ -266,6 +266,7 @@ module MilkTea
266
266
 
267
267
  def simd_bitwise_result(left_type, right_type)
268
268
  return nil unless simd_type?(left_type) && simd_type?(right_type) && left_type == right_type
269
+ return nil unless left_type.element_type.integer?
269
270
 
270
271
  left_type
271
272
  end
@@ -286,15 +287,16 @@ module MilkTea
286
287
 
287
288
  def vector_op_result(operator, left_type, right_type)
288
289
  if vector_type?(left_type) && vector_type?(right_type) && left_type.element_type == right_type.element_type
290
+ return nil unless left_type.width == right_type.width
289
291
  return left_type if operator == "+" || operator == "-"
290
292
  return left_type if operator == "*"
291
293
  end
292
294
 
293
- if vector_type?(left_type) && right_type.numeric?
295
+ if vector_type?(left_type) && primitive_numeric_type?(right_type)
294
296
  return left_type if operator == "*" || operator == "/"
295
297
  end
296
298
 
297
- if left_type.numeric? && vector_type?(right_type) && operator == "*"
299
+ if primitive_numeric_type?(left_type) && vector_type?(right_type) && operator == "*"
298
300
  return right_type
299
301
  end
300
302
 
@@ -307,11 +309,7 @@ module MilkTea
307
309
  return left_type if operator == "*"
308
310
  end
309
311
 
310
- if matrix_type?(left_type) && vector_type?(right_type) && left_type.dim == right_type.width && right_type.element_type == Types::BUILTIN_VECTOR_ELEMENT
311
- return Types::Vector.new(right_type.name, element_type: right_type.element_type, width: right_type.width) if operator == "*"
312
- end
313
-
314
- if matrix_type?(left_type) && right_type.numeric?
312
+ if matrix_type?(left_type) && primitive_numeric_type?(right_type)
315
313
  return left_type if operator == "*" || operator == "/"
316
314
  end
317
315
 
@@ -324,13 +322,13 @@ module MilkTea
324
322
  return left_type if operator == "*"
325
323
  end
326
324
 
327
- if quaternion_type?(left_type) && vector_type?(right_type) && right_type.width == 3 && right_type.element_type == Types::BUILTIN_VECTOR_ELEMENT
328
- return right_type if operator == "*"
329
- end
330
-
331
325
  nil
332
326
  end
333
327
 
328
+ def primitive_numeric_type?(type)
329
+ type.is_a?(Types::Primitive) && type.numeric?
330
+ end
331
+
334
332
  def pointer_cast?(source_type, target_type)
335
333
  pointer_cast_type?(source_type) && pointer_cast_type?(target_type)
336
334
  end
@@ -76,6 +76,21 @@ module MilkTea
76
76
  total = element_layout.first * type.lane_count
77
77
  alignment = total > 16 ? 32 : 16
78
78
  [total, alignment]
79
+ when Types::Vector
80
+ element_layout = size_and_alignment(type.element_type, stack)
81
+ return unless element_layout
82
+
83
+ [element_layout.first * type.width, element_layout.last]
84
+ when Types::Matrix
85
+ element_layout = size_and_alignment(Types::BUILTIN_VECTOR_ELEMENT, stack)
86
+ return unless element_layout
87
+
88
+ [element_layout.first * type.dim * type.dim, element_layout.last]
89
+ when Types::Quaternion
90
+ element_layout = size_and_alignment(Types::BUILTIN_VECTOR_ELEMENT, stack)
91
+ return unless element_layout
92
+
93
+ [element_layout.first * 4, element_layout.last]
79
94
  else
80
95
  nil
81
96
  end
@@ -100,9 +100,14 @@ module MilkTea
100
100
  return value.abs <= (1 << 24) if value.is_a?(Integer)
101
101
 
102
102
  exactly_representable_float32?(value.to_f)
103
- else
104
- return true if expected_type.name == "double"
103
+ elsif expected_type.name == "double"
104
+ # Every integer with magnitude <= 2^53 is exactly representable in
105
+ # double precision; larger integer constants would lose precision, so
106
+ # they require an explicit cast instead.
107
+ return value.abs <= (1 << 53) if value.is_a?(Integer)
105
108
 
109
+ true
110
+ else
106
111
  false
107
112
  end
108
113
  end
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.3.22
4
+ version: 0.3.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Long (Teefan) Tran
@@ -625,7 +625,7 @@ metadata:
625
625
  homepage_uri: https://teefan.github.io/mt-lang/
626
626
  source_code_uri: https://github.com/teefan/mt-lang
627
627
  post_install_message: |
628
- Milk Tea 0.3.22 installed!
628
+ Milk Tea 0.3.23 installed!
629
629
 
630
630
  System requirements:
631
631
  - A C compiler (gcc or clang) must be available on PATH