mt-lang 0.3.6 → 0.3.7
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 +4 -4
- data/lib/milk_tea/base.rb +1 -1
- data/lib/milk_tea/core/c_backend/aggregate_utils.rb +1 -1
- data/lib/milk_tea/core/c_backend/expressions.rb +3 -3
- data/lib/milk_tea/core/c_backend/statements.rb +5 -5
- data/lib/milk_tea/core/c_backend/type_system.rb +8 -8
- data/lib/milk_tea/core/lowering/async/lowering.rb +12 -12
- data/lib/milk_tea/core/lowering/async/normalization.rb +5 -5
- data/lib/milk_tea/core/lowering/async.rb +4 -2
- data/lib/milk_tea/core/lowering/block.rb +41 -21
- data/lib/milk_tea/core/lowering/calls.rb +25 -25
- data/lib/milk_tea/core/lowering/declarations.rb +2 -2
- data/lib/milk_tea/core/lowering/dyn.rb +2 -1
- data/lib/milk_tea/core/lowering/events.rb +1 -1
- data/lib/milk_tea/core/lowering/expressions.rb +26 -26
- data/lib/milk_tea/core/lowering/foreign_cstr.rb +2 -2
- data/lib/milk_tea/core/lowering/functions.rb +1 -1
- data/lib/milk_tea/core/lowering/loops.rb +6 -6
- data/lib/milk_tea/core/lowering/proc.rb +3 -3
- data/lib/milk_tea/core/lowering/resolve.rb +81 -81
- data/lib/milk_tea/core/lowering/str_buffer.rb +1 -1
- data/lib/milk_tea/core/lowering/utils.rb +22 -22
- data/lib/milk_tea/core/lowering.rb +4 -2
- data/std/parse.mt +13 -0
- metadata +3 -2
|
@@ -132,7 +132,7 @@ module MilkTea
|
|
|
132
132
|
return referenced_type(handle_type) if ref_type?(handle_type)
|
|
133
133
|
return pointee_type(handle_type) if pointer_type?(handle_type)
|
|
134
134
|
|
|
135
|
-
raise LoweringError
|
|
135
|
+
raise LoweringError.new("read expects ref[...] or ptr[...], got #{handle_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
def infer_method_receiver_type(receiver_expression, env:, member_name: nil)
|
|
@@ -213,7 +213,7 @@ module MilkTea
|
|
|
213
213
|
end
|
|
214
214
|
end
|
|
215
215
|
|
|
216
|
-
raise LoweringError
|
|
216
|
+
raise LoweringError.new("range bounds must use matching integer types, got #{start_type} and #{stop_type}", line: 0, column: 0, path: @ctx.current_analysis_path) unless start_type == stop_type
|
|
217
217
|
|
|
218
218
|
start_type
|
|
219
219
|
end
|
|
@@ -223,7 +223,7 @@ module MilkTea
|
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
def infer_index_result_type(receiver_type, index_type)
|
|
226
|
-
raise LoweringError
|
|
226
|
+
raise LoweringError.new("index must be an integer type, got #{index_type}", line: 0, column: 0, path: @ctx.current_analysis_path) unless integer_type?(index_type)
|
|
227
227
|
|
|
228
228
|
receiver_type = referenced_type(receiver_type) if ref_type?(receiver_type)
|
|
229
229
|
|
|
@@ -247,7 +247,7 @@ module MilkTea
|
|
|
247
247
|
return pointee_type(receiver_type)
|
|
248
248
|
end
|
|
249
249
|
|
|
250
|
-
raise LoweringError
|
|
250
|
+
raise LoweringError.new("cannot index #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
251
251
|
end
|
|
252
252
|
|
|
253
253
|
def contains_type_var?(type)
|
|
@@ -367,7 +367,7 @@ module MilkTea
|
|
|
367
367
|
else
|
|
368
368
|
nil
|
|
369
369
|
end
|
|
370
|
-
raise LoweringError
|
|
370
|
+
raise LoweringError.new("unsupported compile-time builtin #{name}", line: 0, column: 0, path: @ctx.current_analysis_path) unless return_type
|
|
371
371
|
|
|
372
372
|
Types::Registry.function(name, params: [], return_type: return_type)
|
|
373
373
|
end
|
|
@@ -522,7 +522,7 @@ module MilkTea
|
|
|
522
522
|
return scope unless scope.is_a?(FlowScope)
|
|
523
523
|
end
|
|
524
524
|
|
|
525
|
-
raise LoweringError
|
|
525
|
+
raise LoweringError.new("missing lexical scope", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
526
526
|
end
|
|
527
527
|
|
|
528
528
|
def env_with_refinements(env, refinements)
|
|
@@ -731,7 +731,7 @@ module MilkTea
|
|
|
731
731
|
|
|
732
732
|
IR::GotoStmt.new(label: target[:label])
|
|
733
733
|
else
|
|
734
|
-
raise LoweringError
|
|
734
|
+
raise LoweringError.new("unsupported loop exit target #{target.inspect}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
735
735
|
end
|
|
736
736
|
end
|
|
737
737
|
|
|
@@ -741,7 +741,7 @@ module MilkTea
|
|
|
741
741
|
[loop_exit_statement(target, local_defers:, outer_defers:)]
|
|
742
742
|
else
|
|
743
743
|
label = target[:label]
|
|
744
|
-
raise LoweringError
|
|
744
|
+
raise LoweringError.new("structured loop exits with cleanup are unsupported", line: 0, column: 0, path: @ctx.current_analysis_path) unless label
|
|
745
745
|
|
|
746
746
|
cleanup + [IR::GotoStmt.new(label:)]
|
|
747
747
|
end
|
|
@@ -899,7 +899,7 @@ module MilkTea
|
|
|
899
899
|
)
|
|
900
900
|
end
|
|
901
901
|
|
|
902
|
-
raise LoweringError
|
|
902
|
+
raise LoweringError.new("unsupported let-else storage type #{storage_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
903
903
|
end
|
|
904
904
|
|
|
905
905
|
def lower_bound_identifier(binding, expected_type: nil)
|
|
@@ -963,27 +963,27 @@ module MilkTea
|
|
|
963
963
|
elsif option_let_else_type?(storage_type)
|
|
964
964
|
infer_option_propagation_details(storage_type, env:, allow_void_success:)
|
|
965
965
|
else
|
|
966
|
-
raise LoweringError
|
|
966
|
+
raise LoweringError.new("propagation expects Result[T, E] or Option[T], got #{storage_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
967
967
|
end
|
|
968
968
|
end
|
|
969
969
|
|
|
970
970
|
def infer_result_propagation_details(storage_type, env:, allow_void_success:)
|
|
971
971
|
success_type = let_else_success_type(storage_type)
|
|
972
972
|
error_type = let_else_error_type(storage_type)
|
|
973
|
-
raise LoweringError
|
|
973
|
+
raise LoweringError.new("propagation requires a non-void Result success type", line: 0, column: 0, path: @ctx.current_analysis_path) if success_type == @ctx.types.fetch("void") && !allow_void_success
|
|
974
974
|
|
|
975
975
|
context = env[:return_context]
|
|
976
|
-
raise LoweringError
|
|
977
|
-
raise LoweringError
|
|
976
|
+
raise LoweringError.new("propagation is only allowed inside function and proc bodies", line: 0, column: 0, path: @ctx.current_analysis_path) unless context
|
|
977
|
+
raise LoweringError.new("propagation is not allowed inside defer blocks", line: 0, column: 0, path: @ctx.current_analysis_path) unless context[:allow_return]
|
|
978
978
|
|
|
979
979
|
return_type = context[:return_type]
|
|
980
980
|
unless result_let_else_type?(return_type)
|
|
981
|
-
raise LoweringError
|
|
981
|
+
raise LoweringError.new("propagation requires enclosing function/proc to return Result[_, #{error_type}], got #{return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
982
982
|
end
|
|
983
983
|
|
|
984
984
|
return_error_type = let_else_error_type(return_type)
|
|
985
985
|
unless return_error_type == error_type
|
|
986
|
-
raise LoweringError
|
|
986
|
+
raise LoweringError.new("propagation error type #{error_type} must match enclosing Result error type #{return_error_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
987
987
|
end
|
|
988
988
|
|
|
989
989
|
[storage_type, success_type, return_type, error_type]
|
|
@@ -991,15 +991,15 @@ module MilkTea
|
|
|
991
991
|
|
|
992
992
|
def infer_option_propagation_details(storage_type, env:, allow_void_success:)
|
|
993
993
|
success_type = let_else_success_type(storage_type)
|
|
994
|
-
raise LoweringError
|
|
994
|
+
raise LoweringError.new("propagation requires a non-void Option success type", line: 0, column: 0, path: @ctx.current_analysis_path) if success_type == @ctx.types.fetch("void") && !allow_void_success
|
|
995
995
|
|
|
996
996
|
context = env[:return_context]
|
|
997
|
-
raise LoweringError
|
|
998
|
-
raise LoweringError
|
|
997
|
+
raise LoweringError.new("propagation is only allowed inside function and proc bodies", line: 0, column: 0, path: @ctx.current_analysis_path) unless context
|
|
998
|
+
raise LoweringError.new("propagation is not allowed inside defer blocks", line: 0, column: 0, path: @ctx.current_analysis_path) unless context[:allow_return]
|
|
999
999
|
|
|
1000
1000
|
return_type = context[:return_type]
|
|
1001
1001
|
unless option_let_else_type?(return_type)
|
|
1002
|
-
raise LoweringError
|
|
1002
|
+
raise LoweringError.new("propagation requires enclosing function/proc to return Option[_], got #{return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
1003
1003
|
end
|
|
1004
1004
|
|
|
1005
1005
|
[storage_type, success_type, return_type, nil]
|
|
@@ -1049,7 +1049,7 @@ module MilkTea
|
|
|
1049
1049
|
end
|
|
1050
1050
|
|
|
1051
1051
|
def validate_generic_type!(name, arguments)
|
|
1052
|
-
super(name, arguments) { |msg| raise LoweringError,
|
|
1052
|
+
super(name, arguments) { |msg| raise LoweringError.new(msg, line: 0, column: 0, path: @ctx.current_analysis_path) }
|
|
1053
1053
|
end
|
|
1054
1054
|
|
|
1055
1055
|
def integer_type_argument?(argument)
|
|
@@ -1207,9 +1207,9 @@ module MilkTea
|
|
|
1207
1207
|
return IR::Unary.new(operator: "*", operand:, type:)
|
|
1208
1208
|
end
|
|
1209
1209
|
|
|
1210
|
-
raise LoweringError
|
|
1210
|
+
raise LoweringError.new("unsupported assignment target #{expression.class.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
1211
1211
|
else
|
|
1212
|
-
raise LoweringError
|
|
1212
|
+
raise LoweringError.new("unsupported assignment target #{expression.class.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
1213
1213
|
end
|
|
1214
1214
|
end
|
|
1215
1215
|
|
|
@@ -114,7 +114,8 @@ module MilkTea
|
|
|
114
114
|
|
|
115
115
|
def lower_modules(cached: nil, cached_synthetics: nil)
|
|
116
116
|
if @program.root_analysis.module_kind == :raw_module
|
|
117
|
-
raise LoweringError
|
|
117
|
+
raise LoweringError.new("cannot emit C for external file #{@program.root_analysis.module_name}",
|
|
118
|
+
line: 0, column: 0, path: @program.root_path)
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
per_module_synthetics = {}
|
|
@@ -228,7 +229,8 @@ module MilkTea
|
|
|
228
229
|
|
|
229
230
|
def assemble_modules(modules)
|
|
230
231
|
if @program.root_analysis.module_kind == :raw_module
|
|
231
|
-
raise LoweringError
|
|
232
|
+
raise LoweringError.new("cannot emit C for external file #{@program.root_analysis.module_name}",
|
|
233
|
+
line: 0, column: 0, path: @program.root_path)
|
|
232
234
|
end
|
|
233
235
|
|
|
234
236
|
regenerate_cross_module_synthetics
|
data/std/parse.mt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## std/parse.mt — Numeric string parsing utilities via C FFI
|
|
2
|
+
##
|
|
3
|
+
## Wraps C's strtol / atof behind a clean str-based API.
|
|
4
|
+
|
|
5
|
+
import std.libc as c
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
public function parse_int(text: str, base: int) -> int:
|
|
9
|
+
return int<-(c.parse_long_to_end(text, null, base))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
public function parse_float(text: str) -> float:
|
|
13
|
+
return float<-(c.parse_double(text))
|
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.
|
|
4
|
+
version: 0.3.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Long (Teefan) Tran
|
|
@@ -537,6 +537,7 @@ files:
|
|
|
537
537
|
- std/option.mt
|
|
538
538
|
- std/ordered_map.mt
|
|
539
539
|
- std/ordered_set.mt
|
|
540
|
+
- std/parse.mt
|
|
540
541
|
- std/path.mt
|
|
541
542
|
- std/pcre2.mt
|
|
542
543
|
- std/pcre2/runtime.mt
|
|
@@ -602,7 +603,7 @@ metadata:
|
|
|
602
603
|
homepage_uri: https://teefan.github.io/mt-lang/
|
|
603
604
|
source_code_uri: https://github.com/teefan/mt-lang
|
|
604
605
|
post_install_message: |
|
|
605
|
-
Milk Tea 0.3.
|
|
606
|
+
Milk Tea 0.3.7 installed!
|
|
606
607
|
|
|
607
608
|
System requirements:
|
|
608
609
|
- A C compiler (gcc or clang) must be available on PATH
|