mt-lang 0.3.25 → 0.3.26

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: f58e86ded14f2bb125795f1fb69dcc8b8cdf9efabefd16b0cadcea79abfa3e1c
4
- data.tar.gz: a12aa6d13c9b6984dad4490ee2fca6f2fab650a1230db8d8316c35e5a731c17b
3
+ metadata.gz: 95066d5ccb69388c431a7b4b963853211c3ef57d8e776de1f8468ecdc983899b
4
+ data.tar.gz: 83a55caa84c9d54eda5b104727ce0ee4615b4780270d14d0cea4d2001b2fe9fd
5
5
  SHA512:
6
- metadata.gz: 91f27e591ae0a185e9e6b8cc1a7d7b947bf75a36c9e032273f6651c362e9a925c633df2df1d85965ed17557a62786e344e6f470640d7f2865457a9f28664d5bc
7
- data.tar.gz: 6e61277967b9a06ce34f13b84ca5597318f2ebfd7143d1d697ef9eb67db7a6f027e3a53597b827e77e04b18720a65272aa13eb6a03efad78d715fa608913a992
6
+ metadata.gz: a6e8f3cf4ed18ec8cd2bdbfbb8ee458f7662546619f31c55bb00123d22bb9150888e405a692cbeea9c67b10bad2e3c82c621efae9992223e1d0c9bd51281f0a2
7
+ data.tar.gz: 7cb61c0021e8864897a5b23077dadf54586bf11b11a546ec9b19cbb59083dce4c60d7c8bd996c39380d1a80ea266a364008a1a3f2e3fba7f362ad57c2d97c1d0
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.25"
6
+ VERSION = "0.3.26"
7
7
 
8
8
  def self.root
9
9
  @root ||= Pathname.new(File.expand_path("../..", __dir__))
@@ -1099,10 +1099,9 @@ module MilkTea
1099
1099
 
1100
1100
  def c_local_name(name)
1101
1101
  return "value" unless name
1102
- identifier = sanitize_identifier(name)
1103
- return "#{identifier}_" if c_reserved_identifier?(identifier)
1102
+ return "#{name}_" if c_reserved_identifier?(name)
1104
1103
 
1105
- identifier
1104
+ name
1106
1105
  end
1107
1106
 
1108
1107
  def c_reserved_identifier?(identifier)
@@ -4,7 +4,7 @@ module MilkTea
4
4
  class CLI
5
5
  module CommandBindgen
6
6
  def bindgen_command
7
- BindgenCLI.start(@argv, out: @out, err: @err, help_printer: method(:print_bindgen_help))
7
+ BindgenCLI.start(@argv, out: @out, err: @err, help_printer: ->(io) { print_subcommand_help("bindgen", io) })
8
8
  end
9
9
  end
10
10
  end
@@ -19,10 +19,10 @@ module MilkTea
19
19
 
20
20
  resolution = extract_resolution_flags!
21
21
  input_paths = @argv.dup
22
- return 1 unless ensure_known_source_operands!("check", input_paths)
22
+ return 1 unless validate_source_operands("check", input_paths)
23
23
 
24
24
  paths = expand_source_paths(input_paths)
25
- return 0 if print_no_source_files_if_empty(paths, input_paths)
25
+ return 0 if warn_if_no_source_files(paths, input_paths)
26
26
 
27
27
  ensure_current_lockfiles!(paths) if resolution[:frozen]
28
28
 
@@ -38,12 +38,12 @@ module MilkTea
38
38
  diagnostics.each do |d|
39
39
  same_file = !d.respond_to?(:path) || d.path.nil? || File.expand_path(d.path) == main_abs
40
40
  source = same_file ? main_source : nil
41
- @err.puts(ErrorFormatter.format(d, source:, color: error_color?(@err)))
41
+ @err.puts(ErrorFormatter.format(d, source:, color: use_color?(@err)))
42
42
  end
43
43
  closure_errors.each do |d|
44
44
  same_file = !d.respond_to?(:path) || d.path.nil? || File.expand_path(d.path) == main_abs
45
45
  source = same_file ? main_source : nil
46
- @err.puts(ErrorFormatter.format(d, source:, color: error_color?(@err)))
46
+ @err.puts(ErrorFormatter.format(d, source:, color: use_color?(@err)))
47
47
  end
48
48
  all_diagnostics.concat(diagnostics)
49
49
  all_diagnostics.concat(closure_errors)
@@ -74,7 +74,7 @@ module MilkTea
74
74
  end
75
75
 
76
76
  def check_single_reporting_all(path, locked: false)
77
- loader = make_module_loader(path, locked:, platform: ModuleLoader.default_host_platform)
77
+ loader = create_module_loader(path, locked:, platform: ModuleLoader.default_host_platform)
78
78
  resolved_path = File.expand_path(path)
79
79
 
80
80
  result = loader.check_program_collecting(path)
@@ -12,7 +12,7 @@ module MilkTea
12
12
 
13
13
  resolution = extract_resolution_flags!
14
14
  input_paths = @argv.dup
15
- return 1 unless ensure_known_source_operands!("debug", input_paths)
15
+ return 1 unless validate_source_operands("debug", input_paths)
16
16
 
17
17
  path = expand_source_paths(input_paths).first
18
18
  unless path
@@ -37,7 +37,7 @@ module MilkTea
37
37
 
38
38
  if ast && parse_errors.empty?
39
39
  begin
40
- loader = make_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform)
40
+ loader = create_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform)
41
41
  loader_ast = loader.load_file(resolved_path)
42
42
 
43
43
  import_result = loader.send(:imported_modules_for_ast_collecting_errors, loader_ast, importer_path: resolved_path)
@@ -69,7 +69,7 @@ module MilkTea
69
69
  @out.puts(text)
70
70
  0
71
71
  rescue MilkTea::LexError => e
72
- @err.puts(ErrorFormatter.format(e, color: error_color?(@err)))
72
+ @err.puts(ErrorFormatter.format(e, color: use_color?(@err)))
73
73
  1
74
74
  end
75
75
  end
@@ -8,7 +8,7 @@ module MilkTea
8
8
  @argv,
9
9
  out: @out,
10
10
  err: @err,
11
- help_printer: method(:print_deps_help),
11
+ help_printer: ->(io) { print_subcommand_help("deps", io) },
12
12
  services: package_services,
13
13
  )
14
14
  end
@@ -19,7 +19,7 @@ module MilkTea
19
19
 
20
20
  resolution = extract_resolution_flags!
21
21
  input_paths = @argv.dup
22
- return 1 unless ensure_known_source_operands!("emit-c", input_paths)
22
+ return 1 unless validate_source_operands("emit-c", input_paths)
23
23
 
24
24
  program_paths = input_paths.map { |p| resolve_program_path(p) }
25
25
  return 1 if program_paths.include?(nil)
@@ -28,7 +28,7 @@ module MilkTea
28
28
 
29
29
  multiple = program_paths.length > 1
30
30
  program_paths.each_with_index do |path, index|
31
- program = make_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform).check_program(path)
31
+ program = create_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform).check_program(path)
32
32
  if multiple
33
33
  @out.puts("/* --- #{path} --- */")
34
34
  end
@@ -17,7 +17,7 @@ module MilkTea
17
17
  end
18
18
 
19
19
  paths = expand_source_paths(input_paths)
20
- return 0 if print_no_source_files_if_empty(paths, input_paths)
20
+ return 0 if warn_if_no_source_files(paths, input_paths)
21
21
 
22
22
  multiple_sources = input_paths.length > 1 || input_paths.any? { |path| File.directory?(path) }
23
23
  if multiple_sources
@@ -39,7 +39,7 @@ module MilkTea
39
39
  elapsed_ms = start_time ? ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000.0).round(1) : nil
40
40
 
41
41
  rc = if options[:check]
42
- announce_file_action(path, "format-check")
42
+ log_action(path, "format-check")
43
43
  if result.changed
44
44
  info("needs formatting #{path}")
45
45
  1
@@ -48,7 +48,7 @@ module MilkTea
48
48
  0
49
49
  end
50
50
  elsif options[:write]
51
- announce_file_action(path, "format-write")
51
+ log_action(path, "format-write")
52
52
  if result.changed
53
53
  File.write(path, result.formatted_source)
54
54
  info("formatted #{path}")
@@ -70,7 +70,7 @@ module MilkTea
70
70
  if options[:check]
71
71
  needs_fmt = []
72
72
  paths.each do |p|
73
- announce_file_action(p, "format-check")
73
+ log_action(p, "format-check")
74
74
  format_profile = options[:profile] ? Linter::Profile.new : nil
75
75
  start_time = options[:profile] ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : nil
76
76
  result = Formatter.check_source(read_source_file(p), path: p, mode: options[:mode], max_line_length: options[:max_line_length], profile: format_profile)
@@ -91,7 +91,7 @@ module MilkTea
91
91
  # --write
92
92
  changed = 0
93
93
  paths.each do |p|
94
- announce_file_action(p, "format-write")
94
+ log_action(p, "format-write")
95
95
  format_profile = options[:profile] ? Linter::Profile.new : nil
96
96
  start_time = options[:profile] ? Process.clock_gettime(Process::CLOCK_MONOTONIC) : nil
97
97
  result = Formatter.check_source(read_source_file(p), path: p, mode: options[:mode], max_line_length: options[:max_line_length], profile: format_profile)
@@ -136,7 +136,7 @@ module MilkTea
136
136
  options[:mode] = :tidy
137
137
  when "--max-line-length"
138
138
  value = @argv.shift
139
- return missing_option_value(option) unless value
139
+ return reject_missing_option_value(option) unless value
140
140
 
141
141
  line_length = Integer(value, exception: false)
142
142
  unless line_length && line_length.positive?
@@ -91,7 +91,7 @@ module MilkTea
91
91
  if fix
92
92
  lint_profiles = []
93
93
  paths.each do |p|
94
- announce_file_action(p, "lint-fix")
94
+ log_action(p, "lint-fix")
95
95
  source = read_source_file(p)
96
96
  if ignore_generated && generated_source?(source)
97
97
  @out.puts("ignored generated #{p}")
@@ -124,7 +124,7 @@ module MilkTea
124
124
 
125
125
  lint_profiles = []
126
126
  all_warnings = paths.flat_map do |p|
127
- announce_file_action(p, "lint")
127
+ log_action(p, "lint")
128
128
  source = read_source_file(p)
129
129
  next [] if ignore_generated && generated_source?(source)
130
130
 
@@ -238,7 +238,7 @@ module MilkTea
238
238
 
239
239
  def lint_sema_facts_for(source, path, locked: false)
240
240
  ast = Parser.parse(source, path: path)
241
- imported_modules = make_module_loader(path, locked:, platform: ModuleLoader.default_host_platform).imported_modules_for_ast(ast, importer_path: path)
241
+ imported_modules = create_module_loader(path, locked:, platform: ModuleLoader.default_host_platform).imported_modules_for_ast(ast, importer_path: path)
242
242
  SemanticAnalyzer.tooling_snapshot(ast, imported_modules: imported_modules, path: path).facts
243
243
  rescue MilkTea::LexError, MilkTea::ParseError, SemanticError, ModuleLoadError
244
244
  nil
@@ -24,16 +24,16 @@ module MilkTea
24
24
 
25
25
  resolution = extract_resolution_flags!
26
26
  input_paths = @argv.dup
27
- return 1 unless ensure_known_source_operands!("lower", input_paths)
27
+ return 1 unless validate_source_operands("lower", input_paths)
28
28
 
29
29
  paths = expand_source_paths(input_paths)
30
- return 0 if print_no_source_files_if_empty(paths, input_paths)
30
+ return 0 if warn_if_no_source_files(paths, input_paths)
31
31
 
32
32
  ensure_current_lockfiles!(paths) if resolution[:frozen]
33
33
 
34
34
  multiple = paths.length > 1
35
35
  paths.each_with_index do |path, index|
36
- program = make_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform).check_program(path)
36
+ program = create_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform).check_program(path)
37
37
  if multiple
38
38
  @out.puts("# --- #{path} ---") unless sexpr
39
39
  end
@@ -24,16 +24,16 @@ module MilkTea
24
24
 
25
25
  resolution = extract_resolution_flags!
26
26
  input_paths = @argv.dup
27
- return 1 unless ensure_known_source_operands!("parse", input_paths)
27
+ return 1 unless validate_source_operands("parse", input_paths)
28
28
 
29
29
  paths = expand_source_paths(input_paths)
30
- return 0 if print_no_source_files_if_empty(paths, input_paths)
30
+ return 0 if warn_if_no_source_files(paths, input_paths)
31
31
 
32
32
  ensure_current_lockfiles!(paths) if resolution[:frozen]
33
33
 
34
34
  multiple = paths.length > 1
35
35
  paths.each_with_index do |path, index|
36
- ast = make_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform).load_file(path)
36
+ ast = create_module_loader(path, locked: resolution[:locked], platform: ModuleLoader.default_host_platform).load_file(path)
37
37
  if multiple
38
38
  @out.puts("# --- #{path} ---") unless sexpr
39
39
  end
@@ -263,7 +263,7 @@ module MilkTea
263
263
  .select { |diagnostic| !diagnostic.respond_to?(:severity) || diagnostic.severity == :error }
264
264
  .map { |diagnostic| ErrorFormatter.format(diagnostic, color: false) }
265
265
  rescue StandardError => e
266
- raise unless handled_cli_error?(e)
266
+ raise unless known_cli_error?(e)
267
267
 
268
268
  [ErrorFormatter.format(e, color: false)]
269
269
  end
@@ -271,10 +271,10 @@ module MilkTea
271
271
  def run_test_file_guarded(file, options:, locked:)
272
272
  run_test_file(file, options:, locked:)
273
273
  rescue StandardError => e
274
- raise unless handled_cli_error?(e)
274
+ raise unless known_cli_error?(e)
275
275
 
276
276
  @err.puts("FAILED - #{file} (build error)")
277
- @err.puts(ErrorFormatter.format(e, color: error_color?(@err)))
277
+ @err.puts(ErrorFormatter.format(e, color: use_color?(@err)))
278
278
  1
279
279
  end
280
280
 
@@ -8,7 +8,7 @@ module MilkTea
8
8
  @argv,
9
9
  out: @out,
10
10
  err: @err,
11
- help_printer: method(:print_toolchain_help),
11
+ help_printer: ->(io) { print_subcommand_help("toolchain", io) },
12
12
  )
13
13
  end
14
14
  end
@@ -140,9 +140,9 @@ module MilkTea
140
140
  1
141
141
  end
142
142
  rescue StandardError => e
143
- raise unless handled_cli_error?(e)
143
+ raise unless known_cli_error?(e)
144
144
 
145
- @err.puts(ErrorFormatter.format(e, color: error_color?(@err)))
145
+ @err.puts(ErrorFormatter.format(e, color: use_color?(@err)))
146
146
  1
147
147
  end
148
148
 
@@ -231,13 +231,13 @@ module MilkTea
231
231
  i += 1
232
232
  when "--color"
233
233
  value = @argv[i + 1]
234
- return invalid_color(value) unless valid_color?(value)
234
+ return reject_invalid_color(value) unless valid_color?(value)
235
235
 
236
236
  @color = value.to_sym
237
237
  i += 2
238
238
  when /\A--color=(.*)\z/
239
239
  value = ::Regexp.last_match(1)
240
- return invalid_color(value) unless valid_color?(value)
240
+ return reject_invalid_color(value) unless valid_color?(value)
241
241
 
242
242
  @color = value.to_sym
243
243
  i += 1
@@ -254,12 +254,12 @@ module MilkTea
254
254
  %w[auto always never].include?(value)
255
255
  end
256
256
 
257
- def invalid_color(value)
257
+ def reject_invalid_color(value)
258
258
  @err.puts("--color must be auto, always, or never#{value ? " (got #{value})" : ''}")
259
259
  false
260
260
  end
261
261
 
262
- def error_color?(io)
262
+ def use_color?(io)
263
263
  case @color
264
264
  when :always then true
265
265
  when :never then false
@@ -296,27 +296,27 @@ module MilkTea
296
296
  case option
297
297
  when "-o", "--output"
298
298
  value = @argv.shift
299
- return missing_option_value(option) unless value
299
+ return reject_missing_option_value(option) unless value
300
300
 
301
301
  options[:output_path] = value
302
302
  when "--cc"
303
303
  value = @argv.shift
304
- return missing_option_value(option) unless value
304
+ return reject_missing_option_value(option) unless value
305
305
 
306
306
  options[:cc] = value
307
307
  when "--keep-c"
308
308
  value = @argv.shift
309
- return missing_option_value(option) unless value
309
+ return reject_missing_option_value(option) unless value
310
310
 
311
311
  options[:keep_c_path] = value
312
312
  when "--profile"
313
313
  value = @argv.shift
314
- return missing_option_value(option) unless value
314
+ return reject_missing_option_value(option) unless value
315
315
 
316
316
  options[:profile] = value
317
317
  when "--platform"
318
318
  value = @argv.shift
319
- return missing_option_value(option) unless value
319
+ return reject_missing_option_value(option) unless value
320
320
 
321
321
  options[:platform] = value
322
322
  when "--bundle"
@@ -339,7 +339,7 @@ module MilkTea
339
339
  options[:timings] = true
340
340
  when "--kind"
341
341
  value = @argv.shift
342
- return missing_option_value(option) unless value
342
+ return reject_missing_option_value(option) unless value
343
343
 
344
344
  options[:kind] = case value
345
345
  when "executable", "exe", "bin" then :executable
@@ -375,7 +375,7 @@ module MilkTea
375
375
  options
376
376
  end
377
377
 
378
- def ensure_known_source_operands!(command, operands)
378
+ def validate_source_operands(command, operands)
379
379
  return true unless operands.any? { |arg| arg.start_with?("-") }
380
380
 
381
381
  @err.puts("unexpected argument(s) for #{command}: #{operands.join(' ')}")
@@ -393,7 +393,7 @@ module MilkTea
393
393
  end.uniq
394
394
  end
395
395
 
396
- def print_no_source_files_if_empty(paths, input_paths)
396
+ def warn_if_no_source_files(paths, input_paths)
397
397
  return false unless paths.empty?
398
398
 
399
399
  label = input_paths.length == 1 ? input_paths.first : input_paths.join(", ")
@@ -401,17 +401,17 @@ module MilkTea
401
401
  true
402
402
  end
403
403
 
404
- def missing_option_value(option)
404
+ def reject_missing_option_value(option)
405
405
  @err.puts("missing value for #{option}")
406
406
  print_usage(@err)
407
407
  nil
408
408
  end
409
409
 
410
- def handled_cli_error?(error)
411
- handled_error_classes.any? { |klass| error.is_a?(klass) }
410
+ def known_cli_error?(error)
411
+ known_error_classes.any? { |klass| error.is_a?(klass) }
412
412
  end
413
413
 
414
- def handled_error_classes
414
+ def known_error_classes
415
415
  classes = [LexError, ParseError, ModuleLoadError, SemanticError, LoweringError, CBackendError, BuildError, RunError, FormatterError, PackageManifestError, PackageManifestEditorError, PackageGraphError, PackageLockError, PackageSourceResolverError, PackageSourceFetcherError, PackageRegistryStoreError, PackageRegistryMetadataProviderError, PackageDependencySolverError, PackageVersionError, ProjectScaffoldError]
416
416
  classes << BindgenError if MilkTea.const_defined?(:BindgenError, false)
417
417
  classes << UpstreamSources::Error if MilkTea.const_defined?(:UpstreamSources, false)
@@ -438,13 +438,13 @@ module MilkTea
438
438
  "lint-fix" => "fixing",
439
439
  }.freeze
440
440
 
441
- def announce_file_action(path, action)
441
+ def log_action(path, action)
442
442
  return unless @verbose
443
443
 
444
444
  @out.puts("#{ACTION_LABELS.fetch(action, action)} #{path}")
445
445
  end
446
446
 
447
- def make_module_loader(path = nil, locked: false, platform: nil)
447
+ def create_module_loader(path = nil, locked: false, platform: nil)
448
448
  ModuleLoader.new(module_roots: module_roots_for(path, locked:), package_graph: package_graph_for(path, locked:), source_overrides: @source_overrides, platform:)
449
449
  end
450
450
 
@@ -858,20 +858,8 @@ module MilkTea
858
858
  end
859
859
  end
860
860
 
861
- def print_toolchain_help(io)
862
- print_command_help("toolchain", io)
863
- end
864
-
865
- def print_deps_help(io)
866
- print_command_help("deps", io)
867
- end
868
-
869
- def print_bindgen_help(io)
870
- print_command_help("bindgen", io)
871
- end
872
-
873
- def print_cache_help(io)
874
- print_command_help("cache", io)
861
+ def print_subcommand_help(subcommand, io)
862
+ print_command_help(subcommand, io)
875
863
  end
876
864
 
877
865
  def print_usage(io)
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.25
4
+ version: 0.3.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Long (Teefan) Tran
@@ -624,7 +624,7 @@ metadata:
624
624
  homepage_uri: https://teefan.github.io/mt-lang/
625
625
  source_code_uri: https://github.com/teefan/mt-lang
626
626
  post_install_message: |
627
- Milk Tea 0.3.25 installed!
627
+ Milk Tea 0.3.26 installed!
628
628
 
629
629
  System requirements:
630
630
  - A C compiler (gcc or clang) must be available on PATH