mt-lang 0.3.23 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/milk_tea/base.rb +1 -1
- data/lib/milk_tea/core/bindings/attribute_binding.rb +51 -49
- data/lib/milk_tea/core/bindings/function_binding.rb +3 -1
- data/lib/milk_tea/core/bindings/module_binding.rb +42 -40
- data/lib/milk_tea/core/bindings/value_binding.rb +16 -14
- data/lib/milk_tea/core/bindings.rb +4 -9
- data/lib/milk_tea/core/c_backend/control_flow_emission.rb +11 -11
- data/lib/milk_tea/core/c_backend/expressions.rb +11 -11
- data/lib/milk_tea/core/c_backend/feature_detection.rb +15 -19
- data/lib/milk_tea/core/c_backend/format_helpers.rb +1 -1
- data/lib/milk_tea/core/c_backend/reinterpret.rb +10 -10
- data/lib/milk_tea/core/c_backend/runtime_helpers.rb +1 -1
- data/lib/milk_tea/core/c_backend/statements.rb +20 -20
- data/lib/milk_tea/core/c_backend/type_declaration.rb +4 -4
- data/lib/milk_tea/core/c_backend/type_system.rb +2 -1
- data/lib/milk_tea/core/c_backend.rb +3 -3
- data/lib/milk_tea/core/compile_time.rb +41 -70
- data/lib/milk_tea/core/control_flow/builder.rb +3 -3
- data/lib/milk_tea/core/control_flow/constant_propagation.rb +1 -1
- data/lib/milk_tea/core/control_flow/graph.rb +1 -1
- data/lib/milk_tea/core/control_flow/termination.rb +1 -1
- data/lib/milk_tea/core/cst.rb +16 -0
- data/lib/milk_tea/core/flow_scope.rb +13 -0
- data/lib/milk_tea/core/lexer/character_classes.rb +2 -2
- data/lib/milk_tea/core/lexer/format_strings.rb +5 -5
- data/lib/milk_tea/core/lexer/heredocs.rb +6 -6
- data/lib/milk_tea/core/lexer/indentation.rb +4 -4
- data/lib/milk_tea/core/lexer/numbers.rb +1 -1
- data/lib/milk_tea/core/lexer/strings.rb +4 -4
- data/lib/milk_tea/core/lexer/symbols.rb +3 -3
- data/lib/milk_tea/core/lexer/trivia.rb +4 -4
- data/lib/milk_tea/core/lexer.rb +17 -17
- data/lib/milk_tea/core/lowering/async/analysis.rb +210 -208
- data/lib/milk_tea/core/lowering/async/async_lowering.rb +1406 -0
- data/lib/milk_tea/core/lowering/async/frame_builder.rb +615 -613
- data/lib/milk_tea/core/lowering/async/normalization.rb +410 -408
- data/lib/milk_tea/core/lowering/block.rb +982 -980
- data/lib/milk_tea/core/lowering/calls.rb +1360 -1358
- data/lib/milk_tea/core/lowering/declarations.rb +175 -173
- data/lib/milk_tea/core/lowering/dyn.rb +171 -169
- data/lib/milk_tea/core/lowering/events.rb +946 -944
- data/lib/milk_tea/core/lowering/expressions.rb +1514 -1512
- data/lib/milk_tea/core/lowering/foreign_cstr.rb +180 -178
- data/lib/milk_tea/core/lowering/functions.rb +186 -184
- data/lib/milk_tea/core/lowering/loops.rb +1004 -1002
- data/lib/milk_tea/core/lowering/lowering_context.rb +1 -1
- data/lib/milk_tea/core/lowering/proc.rb +355 -353
- data/lib/milk_tea/core/lowering/resolve.rb +2127 -2125
- data/lib/milk_tea/core/lowering/scans.rb +162 -168
- data/lib/milk_tea/core/lowering/str_buffer.rb +104 -102
- data/lib/milk_tea/core/lowering/utils.rb +965 -963
- data/lib/milk_tea/core/lowering.rb +22 -22
- data/lib/milk_tea/core/module_binder.rb +1 -1
- data/lib/milk_tea/core/module_loader.rb +2 -2
- data/lib/milk_tea/core/parser/attributes.rb +1 -1
- data/lib/milk_tea/core/parser/blocks.rb +2 -2
- data/lib/milk_tea/core/parser/declarations.rb +15 -15
- data/lib/milk_tea/core/parser/expressions.rb +20 -20
- data/lib/milk_tea/core/parser/recovery.rb +1 -1
- data/lib/milk_tea/core/parser/statements.rb +3 -3
- data/lib/milk_tea/core/parser/types.rb +4 -4
- data/lib/milk_tea/core/parser.rb +39 -21
- data/lib/milk_tea/core/pretty_printer/ast_formatter.rb +6 -6
- data/lib/milk_tea/core/pretty_printer/ir_formatter.rb +5 -5
- data/lib/milk_tea/core/semantic_analyzer/analysis_context.rb +2 -2
- data/lib/milk_tea/core/semantic_analyzer/calls.rb +1 -1
- data/lib/milk_tea/core/semantic_analyzer/expressions.rb +4 -4
- data/lib/milk_tea/core/semantic_analyzer/flow_refinement.rb +37 -37
- data/lib/milk_tea/core/semantic_analyzer/foreign_functions.rb +4 -4
- data/lib/milk_tea/core/semantic_analyzer/function_binding.rb +4 -4
- data/lib/milk_tea/core/semantic_analyzer/generics.rb +4 -4
- data/lib/milk_tea/core/semantic_analyzer/name_resolution.rb +7 -7
- data/lib/milk_tea/core/semantic_analyzer/nullability.rb +59 -59
- data/lib/milk_tea/core/semantic_analyzer/statements.rb +3 -3
- data/lib/milk_tea/core/semantic_analyzer/top_level.rb +1 -1
- data/lib/milk_tea/core/semantic_analyzer/type_declaration.rb +12 -12
- data/lib/milk_tea/core/types/layout.rb +3 -1
- data/lib/milk_tea/core/types/visitor.rb +351 -349
- data/lib/milk_tea/core.rb +0 -2
- data/lib/milk_tea/tooling/linter/flow_rules.rb +3 -3
- metadata +4 -5
- data/lib/milk_tea/core/cst_builder.rb +0 -19
- data/lib/milk_tea/core/lowering/async/lowering.rb +0 -1404
- data/lib/milk_tea/core/token_stream.rb +0 -30
|
@@ -4,210 +4,228 @@ require_relative "resolve"
|
|
|
4
4
|
require_relative "utils"
|
|
5
5
|
require_relative "block"
|
|
6
6
|
require_relative "async/normalization"
|
|
7
|
-
require_relative "async/
|
|
7
|
+
require_relative "async/async_lowering"
|
|
8
8
|
|
|
9
9
|
module MilkTea
|
|
10
|
-
module
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
binding.instances.values.sort_by { |instance| instance.type_arguments.map(&:to_s).join(",") }.each do |instance|
|
|
24
|
-
linkage_name = function_binding_c_name(instance, module_name: @ctx.module_name)
|
|
25
|
-
next if @artifacts.lowered_function_linkage_names[linkage_name]
|
|
26
|
-
|
|
27
|
-
lowered << lower_function_decl(instance)
|
|
28
|
-
@artifacts.lowered_function_linkage_names[linkage_name] = true
|
|
29
|
-
end
|
|
30
|
-
else
|
|
31
|
-
linkage_name = function_binding_c_name(binding, module_name: @ctx.module_name)
|
|
32
|
-
next if @artifacts.lowered_function_linkage_names[linkage_name]
|
|
33
|
-
|
|
34
|
-
lowered << lower_function_decl(binding)
|
|
35
|
-
@artifacts.lowered_function_linkage_names[linkage_name] = true
|
|
36
|
-
if @ctx.module_name.to_s == @program.root_analysis.module_name.to_s
|
|
37
|
-
if (entrypoint = build_root_main_entrypoint(binding))
|
|
38
|
-
next if @artifacts.lowered_function_linkage_names[entrypoint.linkage_name]
|
|
39
|
-
|
|
40
|
-
lowered << entrypoint
|
|
41
|
-
@artifacts.lowered_function_linkage_names[entrypoint.linkage_name] = true
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
when AST::ExtendingBlock
|
|
46
|
-
receiver_type = resolve_extending_receiver_type(@ctx.analysis, decl.type_name)
|
|
47
|
-
methods_hash = @ctx.methods[receiver_type]
|
|
48
|
-
unless methods_hash
|
|
49
|
-
methods_hash = @ctx.methods.find { |k, _| k.to_s == receiver_type.to_s }&.last
|
|
50
|
-
end
|
|
51
|
-
next unless methods_hash
|
|
52
|
-
decl.methods.each do |method|
|
|
53
|
-
binding = methods_hash[method.kind == :static ? "static:#{method.name}" : method.name]
|
|
54
|
-
next unless binding
|
|
10
|
+
module Lowering
|
|
11
|
+
module Functions
|
|
12
|
+
def lower_functions
|
|
13
|
+
lowered = []
|
|
14
|
+
cursor = 0
|
|
15
|
+
declarations = @ctx.ast.declarations
|
|
16
|
+
|
|
17
|
+
while cursor < declarations.length
|
|
18
|
+
expanded_declarations.each do |decl|
|
|
19
|
+
case decl
|
|
20
|
+
when AST::FunctionDef
|
|
21
|
+
binding = @ctx.functions.fetch(decl.name)
|
|
22
|
+
next if binding.body_return_type == Types::BUILTIN_TYPE_META_TYPE
|
|
55
23
|
if binding.type_params.any?
|
|
56
24
|
binding.instances.values.sort_by { |instance| instance.type_arguments.map(&:to_s).join(",") }.each do |instance|
|
|
57
|
-
linkage_name = function_binding_c_name(instance, module_name: @ctx.module_name
|
|
25
|
+
linkage_name = function_binding_c_name(instance, module_name: @ctx.module_name)
|
|
58
26
|
next if @artifacts.lowered_function_linkage_names[linkage_name]
|
|
59
27
|
|
|
60
|
-
lowered << lower_function_decl(instance
|
|
28
|
+
lowered << lower_function_decl(instance)
|
|
61
29
|
@artifacts.lowered_function_linkage_names[linkage_name] = true
|
|
62
30
|
end
|
|
63
31
|
else
|
|
64
|
-
linkage_name = function_binding_c_name(binding, module_name: @ctx.module_name
|
|
32
|
+
linkage_name = function_binding_c_name(binding, module_name: @ctx.module_name)
|
|
65
33
|
next if @artifacts.lowered_function_linkage_names[linkage_name]
|
|
66
34
|
|
|
67
|
-
lowered << lower_function_decl(binding
|
|
35
|
+
lowered << lower_function_decl(binding)
|
|
68
36
|
@artifacts.lowered_function_linkage_names[linkage_name] = true
|
|
37
|
+
if @ctx.module_name.to_s == @program.root_analysis.module_name.to_s
|
|
38
|
+
if (entrypoint = build_root_main_entrypoint(binding))
|
|
39
|
+
next if @artifacts.lowered_function_linkage_names[entrypoint.linkage_name]
|
|
40
|
+
|
|
41
|
+
lowered << entrypoint
|
|
42
|
+
@artifacts.lowered_function_linkage_names[entrypoint.linkage_name] = true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
when AST::ExtendingBlock
|
|
47
|
+
receiver_type = resolve_extending_receiver_type(@ctx.analysis, decl.type_name)
|
|
48
|
+
methods_hash = @ctx.methods[receiver_type]
|
|
49
|
+
unless methods_hash
|
|
50
|
+
methods_hash = @ctx.methods.find { |k, _| k.to_s == receiver_type.to_s }&.last
|
|
51
|
+
end
|
|
52
|
+
next unless methods_hash
|
|
53
|
+
decl.methods.each do |method|
|
|
54
|
+
binding = methods_hash[method.kind == :static ? "static:#{method.name}" : method.name]
|
|
55
|
+
next unless binding
|
|
56
|
+
if binding.type_params.any?
|
|
57
|
+
binding.instances.values.sort_by { |instance| instance.type_arguments.map(&:to_s).join(",") }.each do |instance|
|
|
58
|
+
linkage_name = function_binding_c_name(instance, module_name: @ctx.module_name, receiver_type:)
|
|
59
|
+
next if @artifacts.lowered_function_linkage_names[linkage_name]
|
|
60
|
+
|
|
61
|
+
lowered << lower_function_decl(instance, receiver_type:)
|
|
62
|
+
@artifacts.lowered_function_linkage_names[linkage_name] = true
|
|
63
|
+
end
|
|
64
|
+
else
|
|
65
|
+
linkage_name = function_binding_c_name(binding, module_name: @ctx.module_name, receiver_type:)
|
|
66
|
+
next if @artifacts.lowered_function_linkage_names[linkage_name]
|
|
67
|
+
|
|
68
|
+
lowered << lower_function_decl(binding, receiver_type:)
|
|
69
|
+
@artifacts.lowered_function_linkage_names[linkage_name] = true
|
|
70
|
+
end
|
|
69
71
|
end
|
|
70
72
|
end
|
|
71
73
|
end
|
|
74
|
+
|
|
75
|
+
cursor = declarations.length
|
|
72
76
|
end
|
|
73
77
|
|
|
74
|
-
|
|
78
|
+
lowered
|
|
75
79
|
end
|
|
76
80
|
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
def resolve_extending_receiver_type(analysis, type_name)
|
|
82
|
+
if type_name.is_a?(AST::TypeRef)
|
|
83
|
+
generic_type = resolve_named_generic_type_for_analysis(analysis, type_name.name.parts)
|
|
84
|
+
if generic_type.is_a?(Types::GenericStructDefinition) || generic_type.is_a?(Types::GenericVariantDefinition)
|
|
85
|
+
validate_methods_receiver_type_arguments!(type_name, generic_type)
|
|
86
|
+
return generic_type
|
|
87
|
+
end
|
|
79
88
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return generic_type
|
|
86
|
-
end
|
|
89
|
+
begin
|
|
90
|
+
return method_dispatch_receiver_type(resolve_type_ref_for_analysis(type_name, analysis))
|
|
91
|
+
rescue LoweringError => error
|
|
92
|
+
receiver_type_param_names = methods_receiver_type_argument_names!(type_name)
|
|
93
|
+
raise error if receiver_type_param_names.empty?
|
|
87
94
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
receiver_type_params = receiver_type_param_names.to_h { |name| [name, Types::TypeVar.new(name)] }
|
|
96
|
+
receiver_type = resolve_type_ref_for_analysis(type_name, analysis, type_params: receiver_type_params)
|
|
97
|
+
return method_dispatch_receiver_type(receiver_type)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
101
|
+
parts = type_name.name.parts
|
|
102
|
+
if parts.length == 1
|
|
103
|
+
return types_for_module(analysis.module_name).fetch(parts.first)
|
|
97
104
|
end
|
|
98
|
-
end
|
|
99
105
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
106
|
+
if parts.length == 2
|
|
107
|
+
imported_module = imports_for_module(analysis.module_name).fetch(parts.first)
|
|
108
|
+
return imported_module.types.fetch(parts.last)
|
|
109
|
+
end
|
|
104
110
|
|
|
105
|
-
|
|
106
|
-
imported_module = imports_for_module(analysis.module_name).fetch(parts.first)
|
|
107
|
-
return imported_module.types.fetch(parts.last)
|
|
111
|
+
raise LoweringError.new("unsupported extending target #{type_name}", line: 0, column: 0, path: @ctx.current_analysis_path)
|
|
108
112
|
end
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
def lower_function_decl(binding, receiver_type: nil)
|
|
115
|
+
decl = binding.ast
|
|
116
|
+
params = []
|
|
117
|
+
env = empty_env
|
|
118
|
+
parameter_setup = []
|
|
119
|
+
previous_type_substitutions = @ctx.current_type_substitutions
|
|
120
|
+
@ctx.current_type_substitutions = binding.type_substitutions
|
|
112
121
|
|
|
113
|
-
|
|
114
|
-
decl = binding.ast
|
|
115
|
-
params = []
|
|
116
|
-
env = empty_env
|
|
117
|
-
parameter_setup = []
|
|
118
|
-
previous_type_substitutions = @ctx.current_type_substitutions
|
|
119
|
-
@ctx.current_type_substitutions = binding.type_substitutions
|
|
120
|
-
|
|
121
|
-
return lower_async_function_decl(binding, receiver_type:) if binding.async
|
|
122
|
-
|
|
123
|
-
receiver_by_pointer = pointer_lowered_sync_method_receiver?(binding)
|
|
124
|
-
|
|
125
|
-
body_params = binding.body_params.dup
|
|
126
|
-
if binding.type.receiver_type
|
|
127
|
-
receiver_binding = body_params.shift
|
|
128
|
-
linkage_name = c_local_name(receiver_binding.name)
|
|
129
|
-
env[:scopes].last[receiver_binding.name] = local_binding(
|
|
130
|
-
type: receiver_binding.type,
|
|
131
|
-
linkage_name:,
|
|
132
|
-
mutable: receiver_binding.mutable,
|
|
133
|
-
pointer: receiver_by_pointer,
|
|
134
|
-
)
|
|
135
|
-
params << IR::Param.new(
|
|
136
|
-
name: receiver_binding.name,
|
|
137
|
-
linkage_name:,
|
|
138
|
-
type: receiver_binding.type,
|
|
139
|
-
pointer: receiver_by_pointer,
|
|
140
|
-
)
|
|
141
|
-
end
|
|
122
|
+
return lower_async_function_decl(binding, receiver_type:) if binding.async
|
|
142
123
|
|
|
143
|
-
|
|
144
|
-
type = param_binding.type
|
|
124
|
+
receiver_by_pointer = pointer_lowered_sync_method_receiver?(binding)
|
|
145
125
|
|
|
146
|
-
|
|
147
|
-
if
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
env[:scopes].last[
|
|
151
|
-
|
|
152
|
-
|
|
126
|
+
body_params = binding.body_params.dup
|
|
127
|
+
if binding.type.receiver_type
|
|
128
|
+
receiver_binding = body_params.shift
|
|
129
|
+
linkage_name = c_local_name(receiver_binding.name)
|
|
130
|
+
env[:scopes].last[receiver_binding.name] = local_binding(
|
|
131
|
+
type: receiver_binding.type,
|
|
132
|
+
linkage_name:,
|
|
133
|
+
mutable: receiver_binding.mutable,
|
|
134
|
+
pointer: receiver_by_pointer,
|
|
135
|
+
)
|
|
136
|
+
params << IR::Param.new(
|
|
137
|
+
name: receiver_binding.name,
|
|
153
138
|
linkage_name:,
|
|
154
|
-
type
|
|
155
|
-
|
|
139
|
+
type: receiver_binding.type,
|
|
140
|
+
pointer: receiver_by_pointer,
|
|
156
141
|
)
|
|
157
|
-
else
|
|
158
|
-
env[:scopes].last[param_binding.name] = local_binding(type:, linkage_name:, mutable: false, pointer: false)
|
|
159
|
-
params << IR::Param.new(name: param_binding.name, linkage_name:, type:, pointer: false)
|
|
160
142
|
end
|
|
143
|
+
|
|
144
|
+
body_params.each_with_index do |param_binding, index|
|
|
145
|
+
type = param_binding.type
|
|
146
|
+
|
|
147
|
+
linkage_name = c_local_name(param_binding.name)
|
|
148
|
+
if array_type?(type)
|
|
149
|
+
input_linkage_name = "#{linkage_name}_input"
|
|
150
|
+
params << IR::Param.new(name: param_binding.name, linkage_name: input_linkage_name, type:, pointer: false)
|
|
151
|
+
env[:scopes].last[param_binding.name] = local_binding(type:, linkage_name:, mutable: false, pointer: false)
|
|
152
|
+
parameter_setup << IR::LocalDecl.new(
|
|
153
|
+
name: param_binding.name,
|
|
154
|
+
linkage_name:,
|
|
155
|
+
type:,
|
|
156
|
+
value: IR::Name.new(name: input_linkage_name, type:, pointer: false),
|
|
157
|
+
)
|
|
158
|
+
else
|
|
159
|
+
env[:scopes].last[param_binding.name] = local_binding(type:, linkage_name:, mutable: false, pointer: false)
|
|
160
|
+
params << IR::Param.new(name: param_binding.name, linkage_name:, type:, pointer: false)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
return_type = binding.type.return_type
|
|
165
|
+
body = lower_block(decl.body, env:, active_defers: [], return_type:, loop_flow: nil, allow_return: true)
|
|
166
|
+
body = parameter_setup + body
|
|
167
|
+
|
|
168
|
+
IR::Function.new(
|
|
169
|
+
name: decl.name,
|
|
170
|
+
linkage_name: function_binding_c_name(binding, module_name: @ctx.module_name, receiver_type:),
|
|
171
|
+
params:,
|
|
172
|
+
return_type:,
|
|
173
|
+
body:,
|
|
174
|
+
entry_point: false,
|
|
175
|
+
method_receiver_param: !binding.type.receiver_type.nil?,
|
|
176
|
+
)
|
|
177
|
+
ensure
|
|
178
|
+
@ctx.current_type_substitutions = previous_type_substitutions
|
|
161
179
|
end
|
|
162
180
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
181
|
+
def lower_async_function_decl(binding, receiver_type: nil)
|
|
182
|
+
decl = binding.ast
|
|
183
|
+
normalized_statements = normalize_async_body(binding, decl.body)
|
|
184
|
+
constructor_linkage_name = function_binding_c_name(binding, module_name: @ctx.module_name, receiver_type:)
|
|
185
|
+
frame_linkage_name = "#{constructor_linkage_name}__frame"
|
|
186
|
+
resume_linkage_name = "#{constructor_linkage_name}__resume"
|
|
187
|
+
ready_linkage_name = "#{constructor_linkage_name}__ready"
|
|
188
|
+
set_waiter_linkage_name = "#{constructor_linkage_name}__set_waiter"
|
|
189
|
+
release_linkage_name = "#{constructor_linkage_name}__release"
|
|
190
|
+
take_result_linkage_name = "#{constructor_linkage_name}__take_result"
|
|
191
|
+
cancel_linkage_name = "#{constructor_linkage_name}__cancel"
|
|
192
|
+
|
|
193
|
+
async_info = analyze_async_function(binding, normalized_statements)
|
|
194
|
+
frame_type = build_async_frame_type(frame_linkage_name, async_info)
|
|
195
|
+
|
|
196
|
+
@artifacts.synthetic_structs << IR::StructDecl.new(
|
|
197
|
+
name: frame_linkage_name,
|
|
198
|
+
linkage_name: frame_linkage_name,
|
|
199
|
+
fields: frame_type.fields.map { |field_name, field_type| IR::Field.new(name: field_name, type: field_type) },
|
|
200
|
+
packed: false,
|
|
201
|
+
alignment: nil,
|
|
202
|
+
)
|
|
203
|
+
@artifacts.synthetic_functions << build_async_resume_function(binding, normalized_statements, frame_type, resume_linkage_name, async_info)
|
|
204
|
+
@artifacts.synthetic_functions << build_async_ready_function(frame_type, ready_linkage_name, async_info)
|
|
205
|
+
@artifacts.synthetic_functions << build_async_set_waiter_function(frame_type, set_waiter_linkage_name, async_info)
|
|
206
|
+
@artifacts.synthetic_functions << build_async_release_function(frame_type, release_linkage_name, async_info)
|
|
207
|
+
@artifacts.synthetic_functions << build_async_take_result_function(frame_type, take_result_linkage_name, async_info)
|
|
208
|
+
@artifacts.synthetic_functions << build_async_cancel_function(frame_type, cancel_linkage_name, async_info)
|
|
209
|
+
|
|
210
|
+
if root_main_entrypoint_signature(binding)
|
|
211
|
+
@artifacts.synthetic_functions << build_async_constructor_function(
|
|
212
|
+
binding,
|
|
213
|
+
decl,
|
|
214
|
+
frame_type,
|
|
215
|
+
constructor_linkage_name,
|
|
216
|
+
resume_linkage_name,
|
|
217
|
+
ready_linkage_name,
|
|
218
|
+
set_waiter_linkage_name,
|
|
219
|
+
release_linkage_name,
|
|
220
|
+
take_result_linkage_name,
|
|
221
|
+
cancel_linkage_name,
|
|
222
|
+
async_info,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
return build_async_main_entrypoint(binding, constructor_linkage_name, async_info)
|
|
226
|
+
end
|
|
179
227
|
|
|
180
|
-
|
|
181
|
-
decl = binding.ast
|
|
182
|
-
normalized_statements = normalize_async_body(binding, decl.body)
|
|
183
|
-
constructor_linkage_name = function_binding_c_name(binding, module_name: @ctx.module_name, receiver_type:)
|
|
184
|
-
frame_linkage_name = "#{constructor_linkage_name}__frame"
|
|
185
|
-
resume_linkage_name = "#{constructor_linkage_name}__resume"
|
|
186
|
-
ready_linkage_name = "#{constructor_linkage_name}__ready"
|
|
187
|
-
set_waiter_linkage_name = "#{constructor_linkage_name}__set_waiter"
|
|
188
|
-
release_linkage_name = "#{constructor_linkage_name}__release"
|
|
189
|
-
take_result_linkage_name = "#{constructor_linkage_name}__take_result"
|
|
190
|
-
cancel_linkage_name = "#{constructor_linkage_name}__cancel"
|
|
191
|
-
|
|
192
|
-
async_info = analyze_async_function(binding, normalized_statements)
|
|
193
|
-
frame_type = build_async_frame_type(frame_linkage_name, async_info)
|
|
194
|
-
|
|
195
|
-
@artifacts.synthetic_structs << IR::StructDecl.new(
|
|
196
|
-
name: frame_linkage_name,
|
|
197
|
-
linkage_name: frame_linkage_name,
|
|
198
|
-
fields: frame_type.fields.map { |field_name, field_type| IR::Field.new(name: field_name, type: field_type) },
|
|
199
|
-
packed: false,
|
|
200
|
-
alignment: nil,
|
|
201
|
-
)
|
|
202
|
-
@artifacts.synthetic_functions << build_async_resume_function(binding, normalized_statements, frame_type, resume_linkage_name, async_info)
|
|
203
|
-
@artifacts.synthetic_functions << build_async_ready_function(frame_type, ready_linkage_name, async_info)
|
|
204
|
-
@artifacts.synthetic_functions << build_async_set_waiter_function(frame_type, set_waiter_linkage_name, async_info)
|
|
205
|
-
@artifacts.synthetic_functions << build_async_release_function(frame_type, release_linkage_name, async_info)
|
|
206
|
-
@artifacts.synthetic_functions << build_async_take_result_function(frame_type, take_result_linkage_name, async_info)
|
|
207
|
-
@artifacts.synthetic_functions << build_async_cancel_function(frame_type, cancel_linkage_name, async_info)
|
|
208
|
-
|
|
209
|
-
if root_main_entrypoint_signature(binding)
|
|
210
|
-
@artifacts.synthetic_functions << build_async_constructor_function(
|
|
228
|
+
build_async_constructor_function(
|
|
211
229
|
binding,
|
|
212
230
|
decl,
|
|
213
231
|
frame_type,
|
|
@@ -220,23 +238,7 @@ module MilkTea
|
|
|
220
238
|
cancel_linkage_name,
|
|
221
239
|
async_info,
|
|
222
240
|
)
|
|
223
|
-
|
|
224
|
-
return build_async_main_entrypoint(binding, constructor_linkage_name, async_info)
|
|
225
241
|
end
|
|
226
|
-
|
|
227
|
-
build_async_constructor_function(
|
|
228
|
-
binding,
|
|
229
|
-
decl,
|
|
230
|
-
frame_type,
|
|
231
|
-
constructor_linkage_name,
|
|
232
|
-
resume_linkage_name,
|
|
233
|
-
ready_linkage_name,
|
|
234
|
-
set_waiter_linkage_name,
|
|
235
|
-
release_linkage_name,
|
|
236
|
-
take_result_linkage_name,
|
|
237
|
-
cancel_linkage_name,
|
|
238
|
-
async_info,
|
|
239
|
-
)
|
|
240
242
|
end
|
|
241
243
|
end
|
|
242
244
|
end
|