mt-lang 0.3.24 → 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 +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 +1 -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 +964 -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/cli/commands/bindgen.rb +1 -1
- data/lib/milk_tea/tooling/cli/commands/check.rb +5 -5
- data/lib/milk_tea/tooling/cli/commands/debug.rb +3 -3
- data/lib/milk_tea/tooling/cli/commands/deps.rb +1 -1
- data/lib/milk_tea/tooling/cli/commands/emit_c.rb +2 -2
- data/lib/milk_tea/tooling/cli/commands/format.rb +6 -6
- data/lib/milk_tea/tooling/cli/commands/lint.rb +3 -3
- data/lib/milk_tea/tooling/cli/commands/lower.rb +3 -3
- data/lib/milk_tea/tooling/cli/commands/parse.rb +3 -3
- data/lib/milk_tea/tooling/cli/commands/test.rb +3 -3
- data/lib/milk_tea/tooling/cli/commands/toolchain.rb +1 -1
- data/lib/milk_tea/tooling/cli.rb +22 -34
- 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
|
@@ -6,7 +6,7 @@ module MilkTea
|
|
|
6
6
|
def check_definite_assignment(binding)
|
|
7
7
|
return unless binding.ast.respond_to?(:body)
|
|
8
8
|
|
|
9
|
-
resolution =
|
|
9
|
+
resolution = build_binding_resolution_snapshot
|
|
10
10
|
graph = ControlFlow::Builder.new(
|
|
11
11
|
binding_resolution: ControlFlow::BindingResolution.new(
|
|
12
12
|
identifier_binding_ids: resolution.identifier_binding_ids,
|
|
@@ -32,7 +32,7 @@ module MilkTea
|
|
|
32
32
|
end
|
|
33
33
|
# Any binding read but never defined in this function body is treated as
|
|
34
34
|
# preassigned (for example module-level const/var bindings).
|
|
35
|
-
initially_assigned.merge(graph.
|
|
35
|
+
initially_assigned.merge(graph.all_read_binding_keys - local_declared_ids)
|
|
36
36
|
|
|
37
37
|
result = ControlFlow::DefiniteAssignment.solve(graph, initially_assigned:)
|
|
38
38
|
first_issue = result.read_before_assignment.min_by do |issue|
|
|
@@ -57,7 +57,7 @@ module MilkTea
|
|
|
57
57
|
return unless binding.ast.respond_to?(:body)
|
|
58
58
|
|
|
59
59
|
@nullability_flow_result = nil
|
|
60
|
-
resolution =
|
|
60
|
+
resolution = lexical_binding_resolution(binding.ast.body, scopes)
|
|
61
61
|
graph = ControlFlow::Builder.new(
|
|
62
62
|
binding_resolution: ControlFlow::BindingResolution.new(
|
|
63
63
|
identifier_binding_ids: resolution.identifier_binding_ids,
|
|
@@ -214,7 +214,7 @@ module MilkTea
|
|
|
214
214
|
end
|
|
215
215
|
end
|
|
216
216
|
|
|
217
|
-
def
|
|
217
|
+
def lexical_binding_resolution(statements, scopes)
|
|
218
218
|
declaration_binding_ids = {}
|
|
219
219
|
identifier_binding_ids = {}
|
|
220
220
|
|
|
@@ -225,7 +225,7 @@ module MilkTea
|
|
|
225
225
|
end
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
visit_statements_lexical(
|
|
229
229
|
statements || [],
|
|
230
230
|
[initial_scope],
|
|
231
231
|
declaration_binding_ids,
|
|
@@ -242,14 +242,14 @@ module MilkTea
|
|
|
242
242
|
)
|
|
243
243
|
end
|
|
244
244
|
|
|
245
|
-
def
|
|
245
|
+
def visit_statements_lexical(statements, scopes, declaration_ids, identifier_ids)
|
|
246
246
|
block_scopes = scopes + [{}]
|
|
247
247
|
statements.each do |statement|
|
|
248
248
|
case statement
|
|
249
249
|
when AST::ErrorBlockStmt
|
|
250
250
|
if statement.header_type == :for
|
|
251
251
|
Array(statement.header_iterables).each do |iterable|
|
|
252
|
-
|
|
252
|
+
visit_expression_lexical(iterable, block_scopes, identifier_ids, declaration_ids)
|
|
253
253
|
end
|
|
254
254
|
for_scopes = block_scopes + [{}]
|
|
255
255
|
Array(statement.header_bindings).each do |binding|
|
|
@@ -257,43 +257,43 @@ module MilkTea
|
|
|
257
257
|
for_scopes.last[binding.name] = binding_id
|
|
258
258
|
declaration_ids[binding.object_id] = binding_id
|
|
259
259
|
end
|
|
260
|
-
|
|
260
|
+
visit_statements_lexical(statement.body || [], for_scopes, declaration_ids, identifier_ids)
|
|
261
261
|
else
|
|
262
|
-
|
|
263
|
-
|
|
262
|
+
visit_expression_lexical(statement.header_expression, block_scopes, identifier_ids, declaration_ids) if statement.header_expression
|
|
263
|
+
visit_statements_lexical(statement.body || [], block_scopes, declaration_ids, identifier_ids)
|
|
264
264
|
end
|
|
265
265
|
when AST::LocalDecl
|
|
266
|
-
|
|
266
|
+
visit_expression_lexical(statement.value, block_scopes, identifier_ids, declaration_ids) if statement.value
|
|
267
267
|
if statement.else_binding && (statement.else_body || statement.recovered_else)
|
|
268
268
|
else_scopes = block_scopes + [{}]
|
|
269
269
|
binding_id = @preassigned_local_binding_ids.fetch(statement.else_binding.object_id)
|
|
270
270
|
else_scopes.last[statement.else_binding.name] = binding_id
|
|
271
271
|
declaration_ids[statement.else_binding.object_id] = binding_id
|
|
272
|
-
|
|
272
|
+
visit_statements_lexical(statement.else_body || [], else_scopes, declaration_ids, identifier_ids)
|
|
273
273
|
else
|
|
274
|
-
|
|
274
|
+
visit_statements_lexical(statement.else_body || [], block_scopes, declaration_ids, identifier_ids)
|
|
275
275
|
end
|
|
276
276
|
binding_id = @preassigned_local_binding_ids.fetch(statement.object_id)
|
|
277
|
-
unless
|
|
277
|
+
unless let_else_discards_binding?(statement)
|
|
278
278
|
block_scopes.last[statement.name] = binding_id
|
|
279
279
|
declaration_ids[statement.object_id] = binding_id
|
|
280
280
|
end
|
|
281
281
|
when AST::Assignment
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
visit_expression_lexical(statement.value, block_scopes, identifier_ids, declaration_ids)
|
|
283
|
+
visit_assignment_reads_lexical(statement.target, statement.operator, block_scopes, identifier_ids, declaration_ids)
|
|
284
284
|
if statement.target.is_a?(AST::Identifier)
|
|
285
|
-
if (binding_id =
|
|
285
|
+
if (binding_id = resolve_name_in_lexical_scopes(statement.target.name, block_scopes))
|
|
286
286
|
identifier_ids[statement.target.object_id] = binding_id
|
|
287
287
|
end
|
|
288
288
|
end
|
|
289
289
|
when AST::IfStmt
|
|
290
290
|
statement.branches.each do |branch|
|
|
291
|
-
|
|
292
|
-
|
|
291
|
+
visit_expression_lexical(branch.condition, block_scopes, identifier_ids, declaration_ids)
|
|
292
|
+
visit_statements_lexical(branch.body || [], block_scopes, declaration_ids, identifier_ids)
|
|
293
293
|
end
|
|
294
|
-
|
|
294
|
+
visit_statements_lexical(statement.else_body || [], block_scopes, declaration_ids, identifier_ids)
|
|
295
295
|
when AST::MatchStmt
|
|
296
|
-
|
|
296
|
+
visit_expression_lexical(statement.expression, block_scopes, identifier_ids, declaration_ids)
|
|
297
297
|
statement.arms.each do |arm|
|
|
298
298
|
arm_scopes = block_scopes + [{}]
|
|
299
299
|
if arm.binding_name
|
|
@@ -301,14 +301,14 @@ module MilkTea
|
|
|
301
301
|
arm_scopes.last[arm.binding_name] = binding_id
|
|
302
302
|
declaration_ids[arm.object_id] = binding_id
|
|
303
303
|
end
|
|
304
|
-
|
|
304
|
+
visit_statements_lexical(if arm.respond_to?(:body) then (arm.body || []) else [arm.value].compact end, arm_scopes, declaration_ids, identifier_ids)
|
|
305
305
|
end
|
|
306
306
|
when AST::UnsafeStmt, AST::WhileStmt
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
visit_expression_lexical(statement.condition, block_scopes, identifier_ids, declaration_ids) if statement.is_a?(AST::WhileStmt)
|
|
308
|
+
visit_statements_lexical(statement.body || [], block_scopes, declaration_ids, identifier_ids)
|
|
309
309
|
when AST::ForStmt
|
|
310
310
|
statement.iterables.each do |iterable|
|
|
311
|
-
|
|
311
|
+
visit_expression_lexical(iterable, block_scopes, identifier_ids, declaration_ids)
|
|
312
312
|
end
|
|
313
313
|
for_scopes = block_scopes + [{}]
|
|
314
314
|
statement.bindings.each do |binding|
|
|
@@ -316,77 +316,77 @@ module MilkTea
|
|
|
316
316
|
for_scopes.last[binding.name] = binding_id
|
|
317
317
|
declaration_ids[binding.object_id] = binding_id
|
|
318
318
|
end
|
|
319
|
-
|
|
319
|
+
visit_statements_lexical(statement.body || [], for_scopes, declaration_ids, identifier_ids)
|
|
320
320
|
when AST::DeferStmt
|
|
321
|
-
|
|
321
|
+
visit_statements_lexical(statement.body, block_scopes, declaration_ids, identifier_ids)
|
|
322
322
|
when AST::ExpressionStmt
|
|
323
|
-
|
|
323
|
+
visit_expression_lexical(statement.expression, block_scopes, identifier_ids, declaration_ids)
|
|
324
324
|
when AST::ReturnStmt
|
|
325
|
-
|
|
325
|
+
visit_expression_lexical(statement.value, block_scopes, identifier_ids, declaration_ids) if statement.value
|
|
326
326
|
when AST::StaticAssert
|
|
327
|
-
|
|
327
|
+
visit_expression_lexical(statement.condition, block_scopes, identifier_ids, declaration_ids)
|
|
328
328
|
end
|
|
329
329
|
end
|
|
330
330
|
end
|
|
331
331
|
|
|
332
|
-
def
|
|
332
|
+
def visit_expression_lexical(expression, scopes, identifier_ids, declaration_ids = nil)
|
|
333
333
|
case expression
|
|
334
334
|
when nil
|
|
335
335
|
nil
|
|
336
336
|
when AST::Identifier
|
|
337
|
-
if (binding_id =
|
|
337
|
+
if (binding_id = resolve_name_in_lexical_scopes(expression.name, scopes))
|
|
338
338
|
identifier_ids[expression.object_id] = binding_id
|
|
339
339
|
end
|
|
340
340
|
when AST::MemberAccess
|
|
341
|
-
|
|
341
|
+
visit_expression_lexical(expression.receiver, scopes, identifier_ids, declaration_ids)
|
|
342
342
|
when AST::IndexAccess
|
|
343
|
-
|
|
344
|
-
|
|
343
|
+
visit_expression_lexical(expression.receiver, scopes, identifier_ids, declaration_ids)
|
|
344
|
+
visit_expression_lexical(expression.index, scopes, identifier_ids, declaration_ids)
|
|
345
345
|
when AST::Specialization
|
|
346
|
-
|
|
346
|
+
visit_expression_lexical(expression.callee, scopes, identifier_ids, declaration_ids)
|
|
347
347
|
when AST::Call
|
|
348
|
-
|
|
349
|
-
expression.arguments.each { |argument|
|
|
348
|
+
visit_expression_lexical(expression.callee, scopes, identifier_ids, declaration_ids)
|
|
349
|
+
expression.arguments.each { |argument| visit_expression_lexical(argument.value, scopes, identifier_ids, declaration_ids) }
|
|
350
350
|
when AST::UnaryOp
|
|
351
|
-
|
|
351
|
+
visit_expression_lexical(expression.operand, scopes, identifier_ids, declaration_ids)
|
|
352
352
|
when AST::BinaryOp
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
visit_expression_lexical(expression.left, scopes, identifier_ids, declaration_ids)
|
|
354
|
+
visit_expression_lexical(expression.right, scopes, identifier_ids, declaration_ids)
|
|
355
355
|
when AST::RangeExpr
|
|
356
|
-
|
|
357
|
-
|
|
356
|
+
visit_expression_lexical(expression.start_expr, scopes, identifier_ids, declaration_ids)
|
|
357
|
+
visit_expression_lexical(expression.end_expr, scopes, identifier_ids, declaration_ids)
|
|
358
358
|
when AST::IfExpr
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
359
|
+
visit_expression_lexical(expression.condition, scopes, identifier_ids, declaration_ids)
|
|
360
|
+
visit_expression_lexical(expression.then_expression, scopes, identifier_ids, declaration_ids)
|
|
361
|
+
visit_expression_lexical(expression.else_expression, scopes, identifier_ids, declaration_ids)
|
|
362
362
|
when AST::MatchExpr
|
|
363
|
-
|
|
363
|
+
visit_expression_lexical(expression.expression, scopes, identifier_ids, declaration_ids)
|
|
364
364
|
expression.arms.each do |arm|
|
|
365
|
-
|
|
365
|
+
visit_expression_lexical(arm.pattern, scopes, identifier_ids, declaration_ids)
|
|
366
366
|
arm_scopes = scopes
|
|
367
367
|
if arm.binding_name
|
|
368
368
|
binding_id = @preassigned_local_binding_ids.fetch(arm.object_id)
|
|
369
369
|
arm_scopes = scopes + [{ arm.binding_name => binding_id }]
|
|
370
370
|
declaration_ids[arm.object_id] = binding_id if declaration_ids
|
|
371
371
|
end
|
|
372
|
-
|
|
372
|
+
visit_expression_lexical(if arm.respond_to?(:value) then arm.value else arm.body end, arm_scopes, identifier_ids, declaration_ids)
|
|
373
373
|
end
|
|
374
374
|
when AST::UnsafeExpr
|
|
375
|
-
|
|
375
|
+
visit_expression_lexical(expression.expression, scopes, identifier_ids, declaration_ids)
|
|
376
376
|
when AST::AwaitExpr
|
|
377
|
-
|
|
377
|
+
visit_expression_lexical(expression.expression, scopes, identifier_ids, declaration_ids)
|
|
378
378
|
when AST::FormatString
|
|
379
379
|
expression.parts.each do |part|
|
|
380
380
|
next unless part.is_a?(AST::FormatExprPart)
|
|
381
381
|
|
|
382
|
-
|
|
382
|
+
visit_expression_lexical(part.expression, scopes, identifier_ids, declaration_ids)
|
|
383
383
|
end
|
|
384
384
|
end
|
|
385
385
|
end
|
|
386
386
|
|
|
387
|
-
def
|
|
387
|
+
def visit_assignment_reads_lexical(target, operator, scopes, identifier_ids, declaration_ids = nil)
|
|
388
388
|
if operator != "=" && target.is_a?(AST::Identifier)
|
|
389
|
-
if (binding_id =
|
|
389
|
+
if (binding_id = resolve_name_in_lexical_scopes(target.name, scopes))
|
|
390
390
|
identifier_ids[target.object_id] = binding_id
|
|
391
391
|
end
|
|
392
392
|
end
|
|
@@ -395,16 +395,16 @@ module MilkTea
|
|
|
395
395
|
when AST::Identifier
|
|
396
396
|
nil
|
|
397
397
|
when AST::MemberAccess
|
|
398
|
-
|
|
398
|
+
visit_expression_lexical(target.receiver, scopes, identifier_ids, declaration_ids)
|
|
399
399
|
when AST::IndexAccess
|
|
400
|
-
|
|
401
|
-
|
|
400
|
+
visit_expression_lexical(target.receiver, scopes, identifier_ids, declaration_ids)
|
|
401
|
+
visit_expression_lexical(target.index, scopes, identifier_ids, declaration_ids)
|
|
402
402
|
else
|
|
403
|
-
|
|
403
|
+
visit_expression_lexical(target, scopes, identifier_ids, declaration_ids)
|
|
404
404
|
end
|
|
405
405
|
end
|
|
406
406
|
|
|
407
|
-
def
|
|
407
|
+
def resolve_name_in_lexical_scopes(name, scopes)
|
|
408
408
|
scopes.reverse_each do |scope|
|
|
409
409
|
return scope[name] if scope.key?(name)
|
|
410
410
|
end
|
|
@@ -86,7 +86,7 @@ module MilkTea
|
|
|
86
86
|
end
|
|
87
87
|
elsif statement.header_type == :for
|
|
88
88
|
if statement.header_bindings && statement.header_iterables
|
|
89
|
-
check_for_stmt(
|
|
89
|
+
check_for_stmt(rebuild_for_statement(statement), scopes:, return_type:, allow_return:)
|
|
90
90
|
else
|
|
91
91
|
with_loop do
|
|
92
92
|
check_block(statement.body, scopes:, return_type:, allow_return:)
|
|
@@ -221,7 +221,7 @@ module MilkTea
|
|
|
221
221
|
end
|
|
222
222
|
|
|
223
223
|
current_scope = current_actual_scope(scopes)
|
|
224
|
-
discard_binding = statement.name == "_" ||
|
|
224
|
+
discard_binding = statement.name == "_" || let_else_discards_binding?(statement)
|
|
225
225
|
raise_sema_error("duplicate local #{statement.name}") if !discard_binding && current_scope.key?(statement.name)
|
|
226
226
|
ensure_non_reserved_primitive_name!(statement.name, kind_label: "local", line: statement.line, column: statement.column) unless discard_binding
|
|
227
227
|
|
|
@@ -752,7 +752,7 @@ module MilkTea
|
|
|
752
752
|
expression.is_a?(AST::Identifier) && expression.name == "_"
|
|
753
753
|
end
|
|
754
754
|
|
|
755
|
-
def
|
|
755
|
+
def let_else_discards_binding?(statement)
|
|
756
756
|
statement.is_a?(AST::LocalDecl) && (statement.else_body || statement.recovered_else) && statement.name == "_"
|
|
757
757
|
end
|
|
758
758
|
|
|
@@ -238,7 +238,7 @@ module MilkTea
|
|
|
238
238
|
|
|
239
239
|
def set_const_value(name, value)
|
|
240
240
|
binding = @ctx.top_level_values.fetch(name)
|
|
241
|
-
@ctx.top_level_values[name] = ValueBinding.new(
|
|
241
|
+
@ctx.top_level_values[name] = Bindings::ValueBinding.new(
|
|
242
242
|
id: binding.id,
|
|
243
243
|
name: binding.name,
|
|
244
244
|
storage_type: binding.storage_type,
|
|
@@ -19,7 +19,7 @@ module MilkTea
|
|
|
19
19
|
methods: snapshot_methods,
|
|
20
20
|
implemented_interfaces: snapshot_implemented_interfaces,
|
|
21
21
|
local_completion_frames: @local_completion_frames.dup.freeze,
|
|
22
|
-
binding_resolution:
|
|
22
|
+
binding_resolution: build_binding_resolution_snapshot,
|
|
23
23
|
callable_value_identifier_sites: @callable_value_identifier_sites.dup.freeze,
|
|
24
24
|
callable_value_member_access_sites: @callable_value_member_access_sites.dup.freeze,
|
|
25
25
|
required_unsafe_lines: @required_unsafe_lines.uniq.freeze,
|
|
@@ -108,8 +108,8 @@ module MilkTea
|
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
def install_builtin_attributes
|
|
111
|
-
BUILTIN_ATTRIBUTE_NAMES.each do |name|
|
|
112
|
-
@ctx.attributes[name] =
|
|
111
|
+
Bindings::BUILTIN_ATTRIBUTE_NAMES.each do |name|
|
|
112
|
+
@ctx.attributes[name] = Bindings.builtin_attribute_binding(name, @ctx.types)
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
|
|
@@ -163,8 +163,8 @@ module MilkTea
|
|
|
163
163
|
|
|
164
164
|
module_binding = @ctx.imported_modules[module_path]
|
|
165
165
|
unless module_binding
|
|
166
|
-
|
|
167
|
-
@ctx.imports[module_path] =
|
|
166
|
+
install_fallback_prelude_types(module_path)
|
|
167
|
+
@ctx.imports[module_path] = create_empty_module_binding(module_path) unless @ctx.imports.key?(module_path)
|
|
168
168
|
next
|
|
169
169
|
end
|
|
170
170
|
|
|
@@ -177,8 +177,8 @@ module MilkTea
|
|
|
177
177
|
end
|
|
178
178
|
end
|
|
179
179
|
|
|
180
|
-
def
|
|
181
|
-
ModuleBinding.new(
|
|
180
|
+
def create_empty_module_binding(module_path)
|
|
181
|
+
Bindings::ModuleBinding.new(
|
|
182
182
|
name: module_path,
|
|
183
183
|
types: {}, type_declarations: {}, interfaces: {},
|
|
184
184
|
attributes: {}, attribute_applications: {},
|
|
@@ -190,7 +190,7 @@ module MilkTea
|
|
|
190
190
|
)
|
|
191
191
|
end
|
|
192
192
|
|
|
193
|
-
def
|
|
193
|
+
def install_fallback_prelude_types(module_path)
|
|
194
194
|
case module_path
|
|
195
195
|
when "std.option"
|
|
196
196
|
@ctx.types["Option"] = Types::BUILTIN_OPTION_TYPE unless @ctx.types.key?("Option")
|
|
@@ -330,7 +330,7 @@ module MilkTea
|
|
|
330
330
|
params << Types::Registry.parameter(param.name, resolve_type_ref(param.type))
|
|
331
331
|
end
|
|
332
332
|
|
|
333
|
-
@ctx.attributes[decl.name] = AttributeBinding.new(
|
|
333
|
+
@ctx.attributes[decl.name] = Bindings::AttributeBinding.new(
|
|
334
334
|
name: decl.name,
|
|
335
335
|
targets: decl.targets.freeze,
|
|
336
336
|
params: params.freeze,
|
|
@@ -490,7 +490,7 @@ module MilkTea
|
|
|
490
490
|
nested_scope = decl.is_a?(AST::StructDecl) ? resolve_nested_type_bindings(decl) : {}
|
|
491
491
|
if decl.is_a?(AST::StructDecl) && struct_type.respond_to?(:define_nested_types)
|
|
492
492
|
struct_type.define_nested_types(nested_scope)
|
|
493
|
-
|
|
493
|
+
define_nested_type_bindings(decl, parent_name: decl.name)
|
|
494
494
|
end
|
|
495
495
|
|
|
496
496
|
decl.fields.each do |field|
|
|
@@ -804,14 +804,14 @@ module MilkTea
|
|
|
804
804
|
end
|
|
805
805
|
|
|
806
806
|
|
|
807
|
-
def
|
|
807
|
+
def define_nested_type_bindings(parent_decl, parent_name: parent_decl.name)
|
|
808
808
|
parent_decl.nested_types.each do |nested|
|
|
809
809
|
qualified_name = "#{parent_name}.#{nested.name}"
|
|
810
810
|
nested_type = @ctx.types[qualified_name]
|
|
811
811
|
next unless nested_type.is_a?(Types::Struct)
|
|
812
812
|
nested_scope = resolve_nested_type_bindings(nested, parent_name: qualified_name)
|
|
813
813
|
nested_type.define_nested_types(nested_scope)
|
|
814
|
-
|
|
814
|
+
define_nested_type_bindings(nested, parent_name: qualified_name)
|
|
815
815
|
end
|
|
816
816
|
end
|
|
817
817
|
|
|
@@ -4,7 +4,8 @@ require "fiddle"
|
|
|
4
4
|
require_relative "../types"
|
|
5
5
|
|
|
6
6
|
module MilkTea
|
|
7
|
-
module
|
|
7
|
+
module Types
|
|
8
|
+
module Layout
|
|
8
9
|
|
|
9
10
|
POINTER_SIZE = Fiddle::SIZEOF_VOIDP
|
|
10
11
|
|
|
@@ -260,5 +261,6 @@ module MilkTea
|
|
|
260
261
|
ensure
|
|
261
262
|
stack.delete(type)
|
|
262
263
|
end
|
|
264
|
+
end
|
|
263
265
|
end
|
|
264
266
|
end
|