| ... | ... | @@ -58,20 +58,14 @@ pub const ResultLoc = union(enum) { |
| 58 | 58 | }; |
| 59 | 59 | }; |
| 60 | 60 | |
| 61 | | pub fn typeExpr(mod: *Module, scope: *Scope, type_node: ast.Node.Index) InnerError!*zir.Inst { |
| 62 | | const tree = scope.tree(); |
| 63 | | const token_starts = tree.tokens.items(.start); |
| 61 | const void_inst: zir.Inst.Ref = @enumToInt(zir.Const.void_value); |
| 64 | 62 | |
| 65 | | const type_src = token_starts[tree.firstToken(type_node)]; |
| 66 | | const type_type = try addZIRInstConst(mod, scope, type_src, .{ |
| 67 | | .ty = Type.initTag(.type), |
| 68 | | .val = Value.initTag(.type_type), |
| 69 | | }); |
| 70 | | const type_rl: ResultLoc = .{ .ty = type_type }; |
| 63 | pub fn typeExpr(mod: *Module, scope: *Scope, type_node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 64 | const type_rl: ResultLoc = .{ .ty = @enumToInt(zir.Const.type_type) }; |
| 71 | 65 | return expr(mod, scope, type_rl, type_node); |
| 72 | 66 | } |
| 73 | 67 | |
| 74 | | fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { |
| 68 | fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 75 | 69 | const tree = scope.tree(); |
| 76 | 70 | const node_tags = tree.nodes.items(.tag); |
| 77 | 71 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -265,7 +259,7 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.I |
| 265 | 259 | /// When `rl` is discard, ptr, inferred_ptr, bitcasted_ptr, or inferred_ptr, the |
| 266 | 260 | /// result instruction can be used to inspect whether it is isNoReturn() but that is it, |
| 267 | 261 | /// it must otherwise not be used. |
| 268 | | pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { |
| 262 | pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 269 | 263 | const tree = scope.tree(); |
| 270 | 264 | const main_tokens = tree.nodes.items(.main_token); |
| 271 | 265 | const token_tags = tree.tokens.items(.tag); |
| ... | ... | @@ -294,20 +288,62 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 294 | 288 | .asm_output => unreachable, // Handled in `asmExpr`. |
| 295 | 289 | .asm_input => unreachable, // Handled in `asmExpr`. |
| 296 | 290 | |
| 297 | | .assign => return rvalueVoid(mod, scope, rl, node, try assign(mod, scope, node)), |
| 298 | | .assign_bit_and => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .bit_and)), |
| 299 | | .assign_bit_or => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .bit_or)), |
| 300 | | .assign_bit_shift_left => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .shl)), |
| 301 | | .assign_bit_shift_right => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .shr)), |
| 302 | | .assign_bit_xor => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .xor)), |
| 303 | | .assign_div => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .div)), |
| 304 | | .assign_sub => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .sub)), |
| 305 | | .assign_sub_wrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .subwrap)), |
| 306 | | .assign_mod => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .mod_rem)), |
| 307 | | .assign_add => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .add)), |
| 308 | | .assign_add_wrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .addwrap)), |
| 309 | | .assign_mul => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .mul)), |
| 310 | | .assign_mul_wrap => return rvalueVoid(mod, scope, rl, node, try assignOp(mod, scope, node, .mulwrap)), |
| 291 | .assign => { |
| 292 | try assign(mod, scope, node); |
| 293 | return rvalue(mod, scope, rl, void_inst, node); |
| 294 | }, |
| 295 | .assign_bit_and => { |
| 296 | try assignOp(mod, scope, node, .bit_and); |
| 297 | return rvalue(mod, scope, rl, void_inst, node); |
| 298 | }, |
| 299 | .assign_bit_or => { |
| 300 | try assignOp(mod, scope, node, .bit_or); |
| 301 | return rvalue(mod, scope, rl, void_inst, node); |
| 302 | }, |
| 303 | .assign_bit_shift_left => { |
| 304 | try assignOp(mod, scope, node, .shl); |
| 305 | return rvalue(mod, scope, rl, void_inst, node); |
| 306 | }, |
| 307 | .assign_bit_shift_right => { |
| 308 | try assignOp(mod, scope, node, .shr); |
| 309 | return rvalue(mod, scope, rl, void_inst, node); |
| 310 | }, |
| 311 | .assign_bit_xor => { |
| 312 | try assignOp(mod, scope, node, .xor); |
| 313 | return rvalue(mod, scope, rl, void_inst, node); |
| 314 | }, |
| 315 | .assign_div => { |
| 316 | try assignOp(mod, scope, node, .div); |
| 317 | return rvalue(mod, scope, rl, void_inst, node); |
| 318 | }, |
| 319 | .assign_sub => { |
| 320 | try assignOp(mod, scope, node, .sub); |
| 321 | return rvalue(mod, scope, rl, void_inst, node); |
| 322 | }, |
| 323 | .assign_sub_wrap => { |
| 324 | try assignOp(mod, scope, node, .subwrap); |
| 325 | return rvalue(mod, scope, rl, void_inst, node); |
| 326 | }, |
| 327 | .assign_mod => { |
| 328 | try assignOp(mod, scope, node, .mod_rem); |
| 329 | return rvalue(mod, scope, rl, void_inst, node); |
| 330 | }, |
| 331 | .assign_add => { |
| 332 | try assignOp(mod, scope, node, .add); |
| 333 | return rvalue(mod, scope, rl, void_inst, node); |
| 334 | }, |
| 335 | .assign_add_wrap => { |
| 336 | try assignOp(mod, scope, node, .addwrap); |
| 337 | return rvalue(mod, scope, rl, void_inst, node); |
| 338 | }, |
| 339 | .assign_mul => { |
| 340 | try assignOp(mod, scope, node, .mul); |
| 341 | return rvalue(mod, scope, rl, void_inst, node); |
| 342 | }, |
| 343 | .assign_mul_wrap => { |
| 344 | try assignOp(mod, scope, node, .mulwrap); |
| 345 | return rvalue(mod, scope, rl, void_inst, node); |
| 346 | }, |
| 311 | 347 | |
| 312 | 348 | .add => return simpleBinOp(mod, scope, rl, node, .add), |
| 313 | 349 | .add_wrap => return simpleBinOp(mod, scope, rl, node, .addwrap), |
| ... | ... | @@ -336,10 +372,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 336 | 372 | .bool_and => return boolBinOp(mod, scope, rl, node, true), |
| 337 | 373 | .bool_or => return boolBinOp(mod, scope, rl, node, false), |
| 338 | 374 | |
| 339 | | .bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node)), |
| 340 | | .bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node)), |
| 341 | | .negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)), |
| 342 | | .negation_wrap => return rvalue(mod, scope, rl, try negation(mod, scope, node, .subwrap)), |
| 375 | .bool_not => @panic("TODO"), |
| 376 | .bit_not => @panic("TODO"), |
| 377 | .negation => @panic("TODO"), |
| 378 | .negation_wrap => @panic("TODO"), |
| 379 | //.bool_not => return rvalue(mod, scope, rl, try boolNot(mod, scope, node)), |
| 380 | //.bit_not => return rvalue(mod, scope, rl, try bitNot(mod, scope, node)), |
| 381 | //.negation => return rvalue(mod, scope, rl, try negation(mod, scope, node, .sub)), |
| 382 | //.negation_wrap => return rvalue(mod, scope, rl, try negation(mod, scope, node, .subwrap)), |
| 343 | 383 | |
| 344 | 384 | .identifier => return identifier(mod, scope, rl, node), |
| 345 | 385 | |
| ... | ... | @@ -377,6 +417,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 377 | 417 | }, |
| 378 | 418 | |
| 379 | 419 | .unreachable_literal => { |
| 420 | if (true) @panic("TODO update for zir-memory-layout"); |
| 380 | 421 | const main_token = main_tokens[node]; |
| 381 | 422 | const src = token_starts[main_token]; |
| 382 | 423 | return addZIRNoOp(mod, scope, src, .unreachable_safe); |
| ... | ... | @@ -402,16 +443,19 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 402 | 443 | .slice_sentinel => return sliceExpr(mod, scope, rl, tree.sliceSentinel(node)), |
| 403 | 444 | |
| 404 | 445 | .deref => { |
| 446 | if (true) @panic("TODO update for zir-memory-layout"); |
| 405 | 447 | const lhs = try expr(mod, scope, .none, node_datas[node].lhs); |
| 406 | 448 | const src = token_starts[main_tokens[node]]; |
| 407 | 449 | const result = try addZIRUnOp(mod, scope, src, .deref, lhs); |
| 408 | 450 | return rvalue(mod, scope, rl, result); |
| 409 | 451 | }, |
| 410 | 452 | .address_of => { |
| 453 | if (true) @panic("TODO update for zir-memory-layout"); |
| 411 | 454 | const result = try expr(mod, scope, .ref, node_datas[node].lhs); |
| 412 | 455 | return rvalue(mod, scope, rl, result); |
| 413 | 456 | }, |
| 414 | 457 | .undefined_literal => { |
| 458 | if (true) @panic("TODO update for zir-memory-layout"); |
| 415 | 459 | const main_token = main_tokens[node]; |
| 416 | 460 | const src = token_starts[main_token]; |
| 417 | 461 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | ... | @@ -421,6 +465,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 421 | 465 | return rvalue(mod, scope, rl, result); |
| 422 | 466 | }, |
| 423 | 467 | .true_literal => { |
| 468 | if (true) @panic("TODO update for zir-memory-layout"); |
| 424 | 469 | const main_token = main_tokens[node]; |
| 425 | 470 | const src = token_starts[main_token]; |
| 426 | 471 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | ... | @@ -430,6 +475,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 430 | 475 | return rvalue(mod, scope, rl, result); |
| 431 | 476 | }, |
| 432 | 477 | .false_literal => { |
| 478 | if (true) @panic("TODO update for zir-memory-layout"); |
| 433 | 479 | const main_token = main_tokens[node]; |
| 434 | 480 | const src = token_starts[main_token]; |
| 435 | 481 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | ... | @@ -439,6 +485,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 439 | 485 | return rvalue(mod, scope, rl, result); |
| 440 | 486 | }, |
| 441 | 487 | .null_literal => { |
| 488 | if (true) @panic("TODO update for zir-memory-layout"); |
| 442 | 489 | const main_token = main_tokens[node]; |
| 443 | 490 | const src = token_starts[main_token]; |
| 444 | 491 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | ... | @@ -448,12 +495,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 448 | 495 | return rvalue(mod, scope, rl, result); |
| 449 | 496 | }, |
| 450 | 497 | .optional_type => { |
| 498 | if (true) @panic("TODO update for zir-memory-layout"); |
| 451 | 499 | const src = token_starts[main_tokens[node]]; |
| 452 | 500 | const operand = try typeExpr(mod, scope, node_datas[node].lhs); |
| 453 | 501 | const result = try addZIRUnOp(mod, scope, src, .optional_type, operand); |
| 454 | 502 | return rvalue(mod, scope, rl, result); |
| 455 | 503 | }, |
| 456 | 504 | .unwrap_optional => { |
| 505 | if (true) @panic("TODO update for zir-memory-layout"); |
| 457 | 506 | const src = token_starts[main_tokens[node]]; |
| 458 | 507 | switch (rl) { |
| 459 | 508 | .ref => return addZIRUnOp( |
| ... | ... | @@ -473,6 +522,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 473 | 522 | } |
| 474 | 523 | }, |
| 475 | 524 | .block_two, .block_two_semicolon => { |
| 525 | if (true) @panic("TODO update for zir-memory-layout"); |
| 476 | 526 | const statements = [2]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; |
| 477 | 527 | if (node_datas[node].lhs == 0) { |
| 478 | 528 | return blockExpr(mod, scope, rl, node, statements[0..0]); |
| ... | ... | @@ -483,10 +533,12 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 483 | 533 | } |
| 484 | 534 | }, |
| 485 | 535 | .block, .block_semicolon => { |
| 536 | if (true) @panic("TODO update for zir-memory-layout"); |
| 486 | 537 | const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; |
| 487 | 538 | return blockExpr(mod, scope, rl, node, statements); |
| 488 | 539 | }, |
| 489 | 540 | .enum_literal => { |
| 541 | if (true) @panic("TODO update for zir-memory-layout"); |
| 490 | 542 | const ident_token = main_tokens[node]; |
| 491 | 543 | const gen_zir = scope.getGenZir(); |
| 492 | 544 | const string_bytes = &gen_zir.zir_exec.string_bytes; |
| ... | ... | @@ -497,6 +549,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 497 | 549 | return rvalue(mod, scope, rl, result); |
| 498 | 550 | }, |
| 499 | 551 | .error_value => { |
| 552 | if (true) @panic("TODO update for zir-memory-layout"); |
| 500 | 553 | const ident_token = node_datas[node].rhs; |
| 501 | 554 | const name = try mod.identifierTokenString(scope, ident_token); |
| 502 | 555 | const src = token_starts[ident_token]; |
| ... | ... | @@ -504,6 +557,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 504 | 557 | return rvalue(mod, scope, rl, result); |
| 505 | 558 | }, |
| 506 | 559 | .error_union => { |
| 560 | if (true) @panic("TODO update for zir-memory-layout"); |
| 507 | 561 | const error_set = try typeExpr(mod, scope, node_datas[node].lhs); |
| 508 | 562 | const payload = try typeExpr(mod, scope, node_datas[node].rhs); |
| 509 | 563 | const src = token_starts[main_tokens[node]]; |
| ... | ... | @@ -511,6 +565,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 511 | 565 | return rvalue(mod, scope, rl, result); |
| 512 | 566 | }, |
| 513 | 567 | .merge_error_sets => { |
| 568 | if (true) @panic("TODO update for zir-memory-layout"); |
| 514 | 569 | const lhs = try typeExpr(mod, scope, node_datas[node].lhs); |
| 515 | 570 | const rhs = try typeExpr(mod, scope, node_datas[node].rhs); |
| 516 | 571 | const src = token_starts[main_tokens[node]]; |
| ... | ... | @@ -518,6 +573,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 518 | 573 | return rvalue(mod, scope, rl, result); |
| 519 | 574 | }, |
| 520 | 575 | .anyframe_literal => { |
| 576 | if (true) @panic("TODO update for zir-memory-layout"); |
| 521 | 577 | const main_token = main_tokens[node]; |
| 522 | 578 | const src = token_starts[main_token]; |
| 523 | 579 | const result = try addZIRInstConst(mod, scope, src, .{ |
| ... | ... | @@ -527,12 +583,14 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 527 | 583 | return rvalue(mod, scope, rl, result); |
| 528 | 584 | }, |
| 529 | 585 | .anyframe_type => { |
| 586 | if (true) @panic("TODO update for zir-memory-layout"); |
| 530 | 587 | const src = token_starts[node_datas[node].lhs]; |
| 531 | 588 | const return_type = try typeExpr(mod, scope, node_datas[node].rhs); |
| 532 | 589 | const result = try addZIRUnOp(mod, scope, src, .anyframe_type, return_type); |
| 533 | 590 | return rvalue(mod, scope, rl, result); |
| 534 | 591 | }, |
| 535 | 592 | .@"catch" => { |
| 593 | if (true) @panic("TODO update for zir-memory-layout"); |
| 536 | 594 | const catch_token = main_tokens[node]; |
| 537 | 595 | const payload_token: ?ast.TokenIndex = if (token_tags[catch_token + 1] == .pipe) |
| 538 | 596 | catch_token + 2 |
| ... | ... | @@ -631,9 +689,11 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 631 | 689 | .@"switch", .switch_comma => return switchExpr(mod, scope, rl, node), |
| 632 | 690 | |
| 633 | 691 | .@"nosuspend" => return nosuspendExpr(mod, scope, rl, node), |
| 634 | | .@"suspend" => return rvalue(mod, scope, rl, try suspendExpr(mod, scope, node)), |
| 692 | .@"suspend" => @panic("TODO"), |
| 693 | //.@"suspend" => return rvalue(mod, scope, rl, try suspendExpr(mod, scope, node)), |
| 635 | 694 | .@"await" => return awaitExpr(mod, scope, rl, node), |
| 636 | | .@"resume" => return rvalue(mod, scope, rl, try resumeExpr(mod, scope, node)), |
| 695 | .@"resume" => @panic("TODO"), |
| 696 | //.@"resume" => return rvalue(mod, scope, rl, try resumeExpr(mod, scope, node)), |
| 637 | 697 | |
| 638 | 698 | .@"defer" => return mod.failNode(scope, node, "TODO implement astgen.expr for .defer", .{}), |
| 639 | 699 | .@"errdefer" => return mod.failNode(scope, node, "TODO implement astgen.expr for .errdefer", .{}), |
| ... | ... | @@ -673,20 +733,22 @@ pub fn comptimeExpr( |
| 673 | 733 | parent_scope: *Scope, |
| 674 | 734 | rl: ResultLoc, |
| 675 | 735 | node: ast.Node.Index, |
| 676 | | ) InnerError!*zir.Inst { |
| 736 | ) InnerError!zir.Inst.Ref { |
| 737 | if (true) @panic("TODO update for zir-memory-layout branch"); |
| 738 | |
| 677 | 739 | // If we are already in a comptime scope, no need to make another one. |
| 678 | 740 | if (parent_scope.isComptime()) { |
| 679 | 741 | return expr(mod, parent_scope, rl, node); |
| 680 | 742 | } |
| 681 | 743 | |
| 744 | const gz = parent_scope.getGenZir(); |
| 682 | 745 | const tree = parent_scope.tree(); |
| 683 | 746 | const token_starts = tree.tokens.items(.start); |
| 684 | 747 | |
| 685 | 748 | // Make a scope to collect generated instructions in the sub-expression. |
| 686 | 749 | var block_scope: Scope.GenZir = .{ |
| 687 | 750 | .parent = parent_scope, |
| 688 | | .decl = parent_scope.ownerDecl().?, |
| 689 | | .arena = parent_scope.arena(), |
| 751 | .zir_code = gz.zir_code, |
| 690 | 752 | .force_comptime = true, |
| 691 | 753 | .instructions = .{}, |
| 692 | 754 | }; |
| ... | ... | @@ -698,7 +760,7 @@ pub fn comptimeExpr( |
| 698 | 760 | |
| 699 | 761 | const src = token_starts[tree.firstToken(node)]; |
| 700 | 762 | const block = try addZIRInstBlock(mod, parent_scope, src, .block_comptime_flat, .{ |
| 701 | | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), |
| 763 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 702 | 764 | }); |
| 703 | 765 | |
| 704 | 766 | return &block.base; |
| ... | ... | @@ -709,7 +771,8 @@ fn breakExpr( |
| 709 | 771 | parent_scope: *Scope, |
| 710 | 772 | rl: ResultLoc, |
| 711 | 773 | node: ast.Node.Index, |
| 712 | | ) InnerError!*zir.Inst { |
| 774 | ) InnerError!zir.Inst.Ref { |
| 775 | if (true) @panic("TODO update for zir-memory-layout"); |
| 713 | 776 | const tree = parent_scope.tree(); |
| 714 | 777 | const node_datas = tree.nodes.items(.data); |
| 715 | 778 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -787,7 +850,8 @@ fn continueExpr( |
| 787 | 850 | parent_scope: *Scope, |
| 788 | 851 | rl: ResultLoc, |
| 789 | 852 | node: ast.Node.Index, |
| 790 | | ) InnerError!*zir.Inst { |
| 853 | ) InnerError!zir.Inst.Ref { |
| 854 | if (true) @panic("TODO update for zir-memory-layout"); |
| 791 | 855 | const tree = parent_scope.tree(); |
| 792 | 856 | const node_datas = tree.nodes.items(.data); |
| 793 | 857 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -843,7 +907,7 @@ pub fn blockExpr( |
| 843 | 907 | rl: ResultLoc, |
| 844 | 908 | block_node: ast.Node.Index, |
| 845 | 909 | statements: []const ast.Node.Index, |
| 846 | | ) InnerError!*zir.Inst { |
| 910 | ) InnerError!zir.Inst.Ref { |
| 847 | 911 | const tracy = trace(@src()); |
| 848 | 912 | defer tracy.end(); |
| 849 | 913 | |
| ... | ... | @@ -859,7 +923,7 @@ pub fn blockExpr( |
| 859 | 923 | } |
| 860 | 924 | |
| 861 | 925 | try blockExprStmts(mod, scope, block_node, statements); |
| 862 | | return rvalueVoid(mod, scope, rl, block_node, {}); |
| 926 | return rvalue(mod, scope, rl, void_inst, block_node); |
| 863 | 927 | } |
| 864 | 928 | |
| 865 | 929 | fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIndex) !void { |
| ... | ... | @@ -875,21 +939,18 @@ fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIn |
| 875 | 939 | const main_tokens = tree.nodes.items(.main_token); |
| 876 | 940 | const token_starts = tree.tokens.items(.start); |
| 877 | 941 | |
| 878 | | const label_src = token_starts[label]; |
| 879 | | const prev_label_src = token_starts[prev_label.token]; |
| 880 | | |
| 881 | 942 | const label_name = try mod.identifierTokenString(parent_scope, label); |
| 882 | 943 | const msg = msg: { |
| 883 | 944 | const msg = try mod.errMsg( |
| 884 | 945 | parent_scope, |
| 885 | | label_src, |
| 946 | gen_zir.tokSrcLoc(label), |
| 886 | 947 | "redefinition of label '{s}'", |
| 887 | 948 | .{label_name}, |
| 888 | 949 | ); |
| 889 | 950 | errdefer msg.destroy(mod.gpa); |
| 890 | 951 | try mod.errNote( |
| 891 | 952 | parent_scope, |
| 892 | | prev_label_src, |
| 953 | gen_zir.tokSrcLoc(prev_label.token), |
| 893 | 954 | msg, |
| 894 | 955 | "previous definition is here", |
| 895 | 956 | .{}, |
| ... | ... | @@ -917,7 +978,7 @@ fn labeledBlockExpr( |
| 917 | 978 | block_node: ast.Node.Index, |
| 918 | 979 | statements: []const ast.Node.Index, |
| 919 | 980 | zir_tag: zir.Inst.Tag, |
| 920 | | ) InnerError!*zir.Inst { |
| 981 | ) InnerError!zir.Inst.Ref { |
| 921 | 982 | const tracy = trace(@src()); |
| 922 | 983 | defer tracy.end(); |
| 923 | 984 | |
| ... | ... | @@ -1285,6 +1346,7 @@ fn assignOp( |
| 1285 | 1346 | infix_node: ast.Node.Index, |
| 1286 | 1347 | op_inst_tag: zir.Inst.Tag, |
| 1287 | 1348 | ) InnerError!void { |
| 1349 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1288 | 1350 | const tree = scope.tree(); |
| 1289 | 1351 | const node_datas = tree.nodes.items(.data); |
| 1290 | 1352 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -1299,7 +1361,7 @@ fn assignOp( |
| 1299 | 1361 | _ = try addZIRBinOp(mod, scope, src, .store, lhs_ptr, result); |
| 1300 | 1362 | } |
| 1301 | 1363 | |
| 1302 | | fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { |
| 1364 | fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 1303 | 1365 | const tree = scope.tree(); |
| 1304 | 1366 | const node_datas = tree.nodes.items(.data); |
| 1305 | 1367 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -1314,7 +1376,7 @@ fn boolNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.In |
| 1314 | 1376 | return addZIRUnOp(mod, scope, src, .bool_not, operand); |
| 1315 | 1377 | } |
| 1316 | 1378 | |
| 1317 | | fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { |
| 1379 | fn bitNot(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 1318 | 1380 | const tree = scope.tree(); |
| 1319 | 1381 | const node_datas = tree.nodes.items(.data); |
| 1320 | 1382 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -1330,7 +1392,7 @@ fn negation( |
| 1330 | 1392 | scope: *Scope, |
| 1331 | 1393 | node: ast.Node.Index, |
| 1332 | 1394 | op_inst_tag: zir.Inst.Tag, |
| 1333 | | ) InnerError!*zir.Inst { |
| 1395 | ) InnerError!zir.Inst.Ref { |
| 1334 | 1396 | const tree = scope.tree(); |
| 1335 | 1397 | const node_datas = tree.nodes.items(.data); |
| 1336 | 1398 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -1350,7 +1412,8 @@ fn ptrType( |
| 1350 | 1412 | scope: *Scope, |
| 1351 | 1413 | rl: ResultLoc, |
| 1352 | 1414 | ptr_info: ast.full.PtrType, |
| 1353 | | ) InnerError!*zir.Inst { |
| 1415 | ) InnerError!zir.Inst.Ref { |
| 1416 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1354 | 1417 | const tree = scope.tree(); |
| 1355 | 1418 | const token_starts = tree.tokens.items(.start); |
| 1356 | 1419 | |
| ... | ... | @@ -1394,7 +1457,8 @@ fn ptrType( |
| 1394 | 1457 | return rvalue(mod, scope, rl, result); |
| 1395 | 1458 | } |
| 1396 | 1459 | |
| 1397 | | fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !*zir.Inst { |
| 1460 | fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| 1461 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1398 | 1462 | const tree = scope.tree(); |
| 1399 | 1463 | const main_tokens = tree.nodes.items(.main_token); |
| 1400 | 1464 | const node_datas = tree.nodes.items(.data); |
| ... | ... | @@ -1421,7 +1485,8 @@ fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) ! |
| 1421 | 1485 | } |
| 1422 | 1486 | } |
| 1423 | 1487 | |
| 1424 | | fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !*zir.Inst { |
| 1488 | fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| 1489 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1425 | 1490 | const tree = scope.tree(); |
| 1426 | 1491 | const main_tokens = tree.nodes.items(.main_token); |
| 1427 | 1492 | const token_starts = tree.tokens.items(.start); |
| ... | ... | @@ -1454,7 +1519,8 @@ fn containerDecl( |
| 1454 | 1519 | scope: *Scope, |
| 1455 | 1520 | rl: ResultLoc, |
| 1456 | 1521 | container_decl: ast.full.ContainerDecl, |
| 1457 | | ) InnerError!*zir.Inst { |
| 1522 | ) InnerError!zir.Inst.Ref { |
| 1523 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1458 | 1524 | return mod.failTok(scope, container_decl.ast.main_token, "TODO implement container decls", .{}); |
| 1459 | 1525 | } |
| 1460 | 1526 | |
| ... | ... | @@ -1463,7 +1529,8 @@ fn errorSetDecl( |
| 1463 | 1529 | scope: *Scope, |
| 1464 | 1530 | rl: ResultLoc, |
| 1465 | 1531 | node: ast.Node.Index, |
| 1466 | | ) InnerError!*zir.Inst { |
| 1532 | ) InnerError!zir.Inst.Ref { |
| 1533 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1467 | 1534 | const tree = scope.tree(); |
| 1468 | 1535 | const main_tokens = tree.nodes.items(.main_token); |
| 1469 | 1536 | const token_tags = tree.tokens.items(.tag); |
| ... | ... | @@ -1516,7 +1583,9 @@ fn orelseCatchExpr( |
| 1516 | 1583 | unwrap_code_op: zir.Inst.Tag, |
| 1517 | 1584 | rhs: ast.Node.Index, |
| 1518 | 1585 | payload_token: ?ast.TokenIndex, |
| 1519 | | ) InnerError!*zir.Inst { |
| 1586 | ) InnerError!zir.Inst.Ref { |
| 1587 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1588 | |
| 1520 | 1589 | const tree = scope.tree(); |
| 1521 | 1590 | const token_starts = tree.tokens.items(.start); |
| 1522 | 1591 | |
| ... | ... | @@ -1548,7 +1617,7 @@ fn orelseCatchExpr( |
| 1548 | 1617 | }, .{}); |
| 1549 | 1618 | |
| 1550 | 1619 | const block = try addZIRInstBlock(mod, scope, src, .block, .{ |
| 1551 | | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), |
| 1620 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 1552 | 1621 | }); |
| 1553 | 1622 | |
| 1554 | 1623 | var then_scope: Scope.GenZir = .{ |
| ... | ... | @@ -1624,11 +1693,11 @@ fn finishThenElseBlock( |
| 1624 | 1693 | else_body: *zir.Body, |
| 1625 | 1694 | then_src: usize, |
| 1626 | 1695 | else_src: usize, |
| 1627 | | then_result: *zir.Inst, |
| 1696 | then_result: zir.Inst.Ref, |
| 1628 | 1697 | else_result: ?*zir.Inst, |
| 1629 | | main_block: *zir.Inst.Block, |
| 1630 | | then_break_block: *zir.Inst.Block, |
| 1631 | | ) InnerError!*zir.Inst { |
| 1698 | main_block: zir.Inst.Ref.Block, |
| 1699 | then_break_block: zir.Inst.Ref.Block, |
| 1700 | ) InnerError!zir.Inst.Ref { |
| 1632 | 1701 | // We now have enough information to decide whether the result instruction should |
| 1633 | 1702 | // be communicated via result location pointer or break instructions. |
| 1634 | 1703 | const strat = rlStrategy(rl, block_scope); |
| ... | ... | @@ -1699,7 +1768,8 @@ fn tokenIdentEql(mod: *Module, scope: *Scope, token1: ast.TokenIndex, token2: as |
| 1699 | 1768 | return mem.eql(u8, ident_name_1, ident_name_2); |
| 1700 | 1769 | } |
| 1701 | 1770 | |
| 1702 | | pub fn fieldAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { |
| 1771 | pub fn fieldAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 1772 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1703 | 1773 | const tree = scope.tree(); |
| 1704 | 1774 | const token_starts = tree.tokens.items(.start); |
| 1705 | 1775 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -1727,7 +1797,8 @@ fn arrayAccess( |
| 1727 | 1797 | scope: *Scope, |
| 1728 | 1798 | rl: ResultLoc, |
| 1729 | 1799 | node: ast.Node.Index, |
| 1730 | | ) InnerError!*zir.Inst { |
| 1800 | ) InnerError!zir.Inst.Ref { |
| 1801 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1731 | 1802 | const tree = scope.tree(); |
| 1732 | 1803 | const main_tokens = tree.nodes.items(.main_token); |
| 1733 | 1804 | const token_starts = tree.tokens.items(.start); |
| ... | ... | @@ -1756,7 +1827,8 @@ fn sliceExpr( |
| 1756 | 1827 | scope: *Scope, |
| 1757 | 1828 | rl: ResultLoc, |
| 1758 | 1829 | slice: ast.full.Slice, |
| 1759 | | ) InnerError!*zir.Inst { |
| 1830 | ) InnerError!zir.Inst.Ref { |
| 1831 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1760 | 1832 | const tree = scope.tree(); |
| 1761 | 1833 | const token_starts = tree.tokens.items(.start); |
| 1762 | 1834 | |
| ... | ... | @@ -1805,7 +1877,8 @@ fn simpleBinOp( |
| 1805 | 1877 | rl: ResultLoc, |
| 1806 | 1878 | infix_node: ast.Node.Index, |
| 1807 | 1879 | op_inst_tag: zir.Inst.Tag, |
| 1808 | | ) InnerError!*zir.Inst { |
| 1880 | ) InnerError!zir.Inst.Ref { |
| 1881 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1809 | 1882 | const tree = scope.tree(); |
| 1810 | 1883 | const node_datas = tree.nodes.items(.data); |
| 1811 | 1884 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -1824,7 +1897,8 @@ fn boolBinOp( |
| 1824 | 1897 | rl: ResultLoc, |
| 1825 | 1898 | infix_node: ast.Node.Index, |
| 1826 | 1899 | is_bool_and: bool, |
| 1827 | | ) InnerError!*zir.Inst { |
| 1900 | ) InnerError!zir.Inst.Ref { |
| 1901 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1828 | 1902 | const tree = scope.tree(); |
| 1829 | 1903 | const node_datas = tree.nodes.items(.data); |
| 1830 | 1904 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -1853,7 +1927,7 @@ fn boolBinOp( |
| 1853 | 1927 | }, .{}); |
| 1854 | 1928 | |
| 1855 | 1929 | const block = try addZIRInstBlock(mod, scope, src, .block, .{ |
| 1856 | | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), |
| 1930 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 1857 | 1931 | }); |
| 1858 | 1932 | |
| 1859 | 1933 | var rhs_scope: Scope.GenZir = .{ |
| ... | ... | @@ -1893,15 +1967,15 @@ fn boolBinOp( |
| 1893 | 1967 | // break rhs |
| 1894 | 1968 | // else |
| 1895 | 1969 | // break false |
| 1896 | | condbr.positionals.then_body = .{ .instructions = try rhs_scope.arena.dupe(*zir.Inst, rhs_scope.instructions.items) }; |
| 1897 | | condbr.positionals.else_body = .{ .instructions = try const_scope.arena.dupe(*zir.Inst, const_scope.instructions.items) }; |
| 1970 | condbr.positionals.then_body = .{ .instructions = try rhs_scope.arena.dupe(zir.Inst.Ref, rhs_scope.instructions.items) }; |
| 1971 | condbr.positionals.else_body = .{ .instructions = try const_scope.arena.dupe(zir.Inst.Ref, const_scope.instructions.items) }; |
| 1898 | 1972 | } else { |
| 1899 | 1973 | // if lhs // OR |
| 1900 | 1974 | // break true |
| 1901 | 1975 | // else |
| 1902 | 1976 | // break rhs |
| 1903 | | condbr.positionals.then_body = .{ .instructions = try const_scope.arena.dupe(*zir.Inst, const_scope.instructions.items) }; |
| 1904 | | condbr.positionals.else_body = .{ .instructions = try rhs_scope.arena.dupe(*zir.Inst, rhs_scope.instructions.items) }; |
| 1977 | condbr.positionals.then_body = .{ .instructions = try const_scope.arena.dupe(zir.Inst.Ref, const_scope.instructions.items) }; |
| 1978 | condbr.positionals.else_body = .{ .instructions = try rhs_scope.arena.dupe(zir.Inst.Ref, rhs_scope.instructions.items) }; |
| 1905 | 1979 | } |
| 1906 | 1980 | |
| 1907 | 1981 | return rvalue(mod, scope, rl, &block.base); |
| ... | ... | @@ -1912,7 +1986,8 @@ fn ifExpr( |
| 1912 | 1986 | scope: *Scope, |
| 1913 | 1987 | rl: ResultLoc, |
| 1914 | 1988 | if_full: ast.full.If, |
| 1915 | | ) InnerError!*zir.Inst { |
| 1989 | ) InnerError!zir.Inst.Ref { |
| 1990 | if (true) @panic("TODO update for zir-memory-layout"); |
| 1916 | 1991 | var block_scope: Scope.GenZir = .{ |
| 1917 | 1992 | .parent = scope, |
| 1918 | 1993 | .decl = scope.ownerDecl().?, |
| ... | ... | @@ -1951,7 +2026,7 @@ fn ifExpr( |
| 1951 | 2026 | }, .{}); |
| 1952 | 2027 | |
| 1953 | 2028 | const block = try addZIRInstBlock(mod, scope, if_src, .block, .{ |
| 1954 | | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), |
| 2029 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 1955 | 2030 | }); |
| 1956 | 2031 | |
| 1957 | 2032 | const then_src = token_starts[tree.lastToken(if_full.ast.then_expr)]; |
| ... | ... | @@ -2016,7 +2091,7 @@ fn ifExpr( |
| 2016 | 2091 | /// Expects to find exactly 1 .store_to_block_ptr instruction. |
| 2017 | 2092 | fn copyBodyWithElidedStoreBlockPtr(body: *zir.Body, scope: Module.Scope.GenZir) !void { |
| 2018 | 2093 | body.* = .{ |
| 2019 | | .instructions = try scope.arena.alloc(*zir.Inst, scope.instructions.items.len - 1), |
| 2094 | .instructions = try scope.arena.alloc(zir.Inst.Ref, scope.instructions.items.len - 1), |
| 2020 | 2095 | }; |
| 2021 | 2096 | var dst_index: usize = 0; |
| 2022 | 2097 | for (scope.instructions.items) |src_inst| { |
| ... | ... | @@ -2030,7 +2105,7 @@ fn copyBodyWithElidedStoreBlockPtr(body: *zir.Body, scope: Module.Scope.GenZir) |
| 2030 | 2105 | |
| 2031 | 2106 | fn copyBodyNoEliding(body: *zir.Body, scope: Module.Scope.GenZir) !void { |
| 2032 | 2107 | body.* = .{ |
| 2033 | | .instructions = try scope.arena.dupe(*zir.Inst, scope.instructions.items), |
| 2108 | .instructions = try scope.arena.dupe(zir.Inst.Ref, scope.instructions.items), |
| 2034 | 2109 | }; |
| 2035 | 2110 | } |
| 2036 | 2111 | |
| ... | ... | @@ -2039,7 +2114,8 @@ fn whileExpr( |
| 2039 | 2114 | scope: *Scope, |
| 2040 | 2115 | rl: ResultLoc, |
| 2041 | 2116 | while_full: ast.full.While, |
| 2042 | | ) InnerError!*zir.Inst { |
| 2117 | ) InnerError!zir.Inst.Ref { |
| 2118 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2043 | 2119 | if (while_full.label_token) |label_token| { |
| 2044 | 2120 | try checkLabelRedefinition(mod, scope, label_token); |
| 2045 | 2121 | } |
| ... | ... | @@ -2096,7 +2172,7 @@ fn whileExpr( |
| 2096 | 2172 | .else_body = undefined, // populated below |
| 2097 | 2173 | }, .{}); |
| 2098 | 2174 | const cond_block = try addZIRInstBlock(mod, &loop_scope.base, while_src, .block, .{ |
| 2099 | | .instructions = try loop_scope.arena.dupe(*zir.Inst, continue_scope.instructions.items), |
| 2175 | .instructions = try loop_scope.arena.dupe(zir.Inst.Ref, continue_scope.instructions.items), |
| 2100 | 2176 | }); |
| 2101 | 2177 | // TODO avoid emitting the continue expr when there |
| 2102 | 2178 | // are no jumps to it. This happens when the last statement of a while body is noreturn |
| ... | ... | @@ -2113,13 +2189,13 @@ fn whileExpr( |
| 2113 | 2189 | }, |
| 2114 | 2190 | .positionals = .{ |
| 2115 | 2191 | .body = .{ |
| 2116 | | .instructions = try scope.arena().dupe(*zir.Inst, loop_scope.instructions.items), |
| 2192 | .instructions = try scope.arena().dupe(zir.Inst.Ref, loop_scope.instructions.items), |
| 2117 | 2193 | }, |
| 2118 | 2194 | }, |
| 2119 | 2195 | .kw_args = .{}, |
| 2120 | 2196 | }; |
| 2121 | 2197 | const while_block = try addZIRInstBlock(mod, scope, while_src, .block, .{ |
| 2122 | | .instructions = try scope.arena().dupe(*zir.Inst, &[1]*zir.Inst{&loop.base}), |
| 2198 | .instructions = try scope.arena().dupe(zir.Inst.Ref, &[1]zir.Inst.Ref{&loop.base}), |
| 2123 | 2199 | }); |
| 2124 | 2200 | loop_scope.break_block = while_block; |
| 2125 | 2201 | loop_scope.continue_block = cond_block; |
| ... | ... | @@ -2195,7 +2271,8 @@ fn forExpr( |
| 2195 | 2271 | scope: *Scope, |
| 2196 | 2272 | rl: ResultLoc, |
| 2197 | 2273 | for_full: ast.full.While, |
| 2198 | | ) InnerError!*zir.Inst { |
| 2274 | ) InnerError!zir.Inst.Ref { |
| 2275 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2199 | 2276 | if (for_full.label_token) |label_token| { |
| 2200 | 2277 | try checkLabelRedefinition(mod, scope, label_token); |
| 2201 | 2278 | } |
| ... | ... | @@ -2258,7 +2335,7 @@ fn forExpr( |
| 2258 | 2335 | .else_body = undefined, // populated below |
| 2259 | 2336 | }, .{}); |
| 2260 | 2337 | const cond_block = try addZIRInstBlock(mod, &loop_scope.base, for_src, .block, .{ |
| 2261 | | .instructions = try loop_scope.arena.dupe(*zir.Inst, cond_scope.instructions.items), |
| 2338 | .instructions = try loop_scope.arena.dupe(zir.Inst.Ref, cond_scope.instructions.items), |
| 2262 | 2339 | }); |
| 2263 | 2340 | |
| 2264 | 2341 | // increment index variable |
| ... | ... | @@ -2278,13 +2355,13 @@ fn forExpr( |
| 2278 | 2355 | }, |
| 2279 | 2356 | .positionals = .{ |
| 2280 | 2357 | .body = .{ |
| 2281 | | .instructions = try scope.arena().dupe(*zir.Inst, loop_scope.instructions.items), |
| 2358 | .instructions = try scope.arena().dupe(zir.Inst.Ref, loop_scope.instructions.items), |
| 2282 | 2359 | }, |
| 2283 | 2360 | }, |
| 2284 | 2361 | .kw_args = .{}, |
| 2285 | 2362 | }; |
| 2286 | 2363 | const for_block = try addZIRInstBlock(mod, scope, for_src, .block, .{ |
| 2287 | | .instructions = try scope.arena().dupe(*zir.Inst, &[1]*zir.Inst{&loop.base}), |
| 2364 | .instructions = try scope.arena().dupe(zir.Inst.Ref, &[1]zir.Inst.Ref{&loop.base}), |
| 2288 | 2365 | }); |
| 2289 | 2366 | loop_scope.break_block = for_block; |
| 2290 | 2367 | loop_scope.continue_block = cond_block; |
| ... | ... | @@ -2407,7 +2484,8 @@ fn switchExpr( |
| 2407 | 2484 | scope: *Scope, |
| 2408 | 2485 | rl: ResultLoc, |
| 2409 | 2486 | switch_node: ast.Node.Index, |
| 2410 | | ) InnerError!*zir.Inst { |
| 2487 | ) InnerError!zir.Inst.Ref { |
| 2488 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2411 | 2489 | const tree = scope.tree(); |
| 2412 | 2490 | const node_datas = tree.nodes.items(.data); |
| 2413 | 2491 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -2432,7 +2510,7 @@ fn switchExpr( |
| 2432 | 2510 | setBlockResultLoc(&block_scope, rl); |
| 2433 | 2511 | defer block_scope.instructions.deinit(mod.gpa); |
| 2434 | 2512 | |
| 2435 | | var items = std.ArrayList(*zir.Inst).init(mod.gpa); |
| 2513 | var items = std.ArrayList(zir.Inst.Ref).init(mod.gpa); |
| 2436 | 2514 | defer items.deinit(); |
| 2437 | 2515 | |
| 2438 | 2516 | // First we gather all the switch items and check else/'_' prongs. |
| ... | ... | @@ -2549,13 +2627,13 @@ fn switchExpr( |
| 2549 | 2627 | const switch_inst = try addZirInstT(mod, &block_scope.base, switch_src, zir.Inst.SwitchBr, rl_and_tag.tag, .{ |
| 2550 | 2628 | .target = target, |
| 2551 | 2629 | .cases = cases, |
| 2552 | | .items = try block_scope.arena.dupe(*zir.Inst, items.items), |
| 2630 | .items = try block_scope.arena.dupe(zir.Inst.Ref, items.items), |
| 2553 | 2631 | .else_body = undefined, // populated below |
| 2554 | 2632 | .range = first_range, |
| 2555 | 2633 | .special_prong = special_prong, |
| 2556 | 2634 | }); |
| 2557 | 2635 | const block = try addZIRInstBlock(mod, scope, switch_src, .block, .{ |
| 2558 | | .instructions = try block_scope.arena.dupe(*zir.Inst, block_scope.instructions.items), |
| 2636 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 2559 | 2637 | }); |
| 2560 | 2638 | |
| 2561 | 2639 | var case_scope: Scope.GenZir = .{ |
| ... | ... | @@ -2611,7 +2689,7 @@ fn switchExpr( |
| 2611 | 2689 | |
| 2612 | 2690 | cases[case_index] = .{ |
| 2613 | 2691 | .item = item, |
| 2614 | | .body = .{ .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items) }, |
| 2692 | .body = .{ .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items) }, |
| 2615 | 2693 | }; |
| 2616 | 2694 | case_index += 1; |
| 2617 | 2695 | continue; |
| ... | ... | @@ -2658,14 +2736,14 @@ fn switchExpr( |
| 2658 | 2736 | .else_body = undefined, // populated below |
| 2659 | 2737 | }, .{}); |
| 2660 | 2738 | const cond_block = try addZIRInstBlock(mod, &else_scope.base, case_src, .block, .{ |
| 2661 | | .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items), |
| 2739 | .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items), |
| 2662 | 2740 | }); |
| 2663 | 2741 | |
| 2664 | 2742 | // reset cond_scope for then_body |
| 2665 | 2743 | case_scope.instructions.items.len = 0; |
| 2666 | 2744 | try switchCaseExpr(mod, &case_scope.base, block_scope.break_result_loc, block, case, target); |
| 2667 | 2745 | condbr.positionals.then_body = .{ |
| 2668 | | .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items), |
| 2746 | .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items), |
| 2669 | 2747 | }; |
| 2670 | 2748 | |
| 2671 | 2749 | // reset cond_scope for else_body |
| ... | ... | @@ -2674,7 +2752,7 @@ fn switchExpr( |
| 2674 | 2752 | .block = cond_block, |
| 2675 | 2753 | }, .{}); |
| 2676 | 2754 | condbr.positionals.else_body = .{ |
| 2677 | | .instructions = try scope.arena().dupe(*zir.Inst, case_scope.instructions.items), |
| 2755 | .instructions = try scope.arena().dupe(zir.Inst.Ref, case_scope.instructions.items), |
| 2678 | 2756 | }; |
| 2679 | 2757 | } |
| 2680 | 2758 | |
| ... | ... | @@ -2686,7 +2764,7 @@ fn switchExpr( |
| 2686 | 2764 | _ = try addZIRNoOp(mod, &else_scope.base, switch_src, .unreachable_unsafe); |
| 2687 | 2765 | } |
| 2688 | 2766 | switch_inst.positionals.else_body = .{ |
| 2689 | | .instructions = try block_scope.arena.dupe(*zir.Inst, else_scope.instructions.items), |
| 2767 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, else_scope.instructions.items), |
| 2690 | 2768 | }; |
| 2691 | 2769 | |
| 2692 | 2770 | return &block.base; |
| ... | ... | @@ -2698,7 +2776,7 @@ fn switchCaseExpr( |
| 2698 | 2776 | rl: ResultLoc, |
| 2699 | 2777 | block: *zir.Inst.Block, |
| 2700 | 2778 | case: ast.full.SwitchCase, |
| 2701 | | target: *zir.Inst, |
| 2779 | target: zir.Inst.Ref, |
| 2702 | 2780 | ) !void { |
| 2703 | 2781 | const tree = scope.tree(); |
| 2704 | 2782 | const node_datas = tree.nodes.items(.data); |
| ... | ... | @@ -2733,27 +2811,22 @@ fn switchCaseExpr( |
| 2733 | 2811 | } |
| 2734 | 2812 | } |
| 2735 | 2813 | |
| 2736 | | fn ret(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { |
| 2814 | fn ret(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 2737 | 2815 | const tree = scope.tree(); |
| 2738 | 2816 | const node_datas = tree.nodes.items(.data); |
| 2739 | 2817 | const main_tokens = tree.nodes.items(.main_token); |
| 2740 | | const token_starts = tree.tokens.items(.start); |
| 2741 | 2818 | |
| 2742 | | const src = token_starts[main_tokens[node]]; |
| 2743 | | const rhs_node = node_datas[node].lhs; |
| 2744 | | if (rhs_node != 0) { |
| 2745 | | if (nodeMayNeedMemoryLocation(scope, rhs_node)) { |
| 2746 | | const ret_ptr = try addZIRNoOp(mod, scope, src, .ret_ptr); |
| 2747 | | const operand = try expr(mod, scope, .{ .ptr = ret_ptr }, rhs_node); |
| 2748 | | return addZIRUnOp(mod, scope, src, .@"return", operand); |
| 2749 | | } else { |
| 2750 | | const fn_ret_ty = try addZIRNoOp(mod, scope, src, .ret_type); |
| 2751 | | const operand = try expr(mod, scope, .{ .ty = fn_ret_ty }, rhs_node); |
| 2752 | | return addZIRUnOp(mod, scope, src, .@"return", operand); |
| 2753 | | } |
| 2754 | | } else { |
| 2755 | | return addZIRNoOp(mod, scope, src, .return_void); |
| 2756 | | } |
| 2819 | const operand_node = node_datas[node].lhs; |
| 2820 | const gz = scope.getGenZir(); |
| 2821 | const operand: zir.Inst.Ref = if (operand_node != 0) operand: { |
| 2822 | const rl: ResultLoc = if (nodeMayNeedMemoryLocation(scope, operand_node)) .{ |
| 2823 | .ptr = try gz.addNode(.ret_ptr, node), |
| 2824 | } else .{ |
| 2825 | .ty = try gz.addNode(.ret_type, node), |
| 2826 | }; |
| 2827 | break :operand try expr(mod, scope, rl, operand_node); |
| 2828 | } else void_inst; |
| 2829 | return gz.addUnNode(.ret_node, operand, node); |
| 2757 | 2830 | } |
| 2758 | 2831 | |
| 2759 | 2832 | fn identifier( |
| ... | ... | @@ -2761,7 +2834,8 @@ fn identifier( |
| 2761 | 2834 | scope: *Scope, |
| 2762 | 2835 | rl: ResultLoc, |
| 2763 | 2836 | ident: ast.Node.Index, |
| 2764 | | ) InnerError!*zir.Inst { |
| 2837 | ) InnerError!zir.Inst.Ref { |
| 2838 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2765 | 2839 | const tracy = trace(@src()); |
| 2766 | 2840 | defer tracy.end(); |
| 2767 | 2841 | |
| ... | ... | @@ -2882,7 +2956,8 @@ fn stringLiteral( |
| 2882 | 2956 | scope: *Scope, |
| 2883 | 2957 | rl: ResultLoc, |
| 2884 | 2958 | str_lit: ast.Node.Index, |
| 2885 | | ) InnerError!*zir.Inst { |
| 2959 | ) InnerError!zir.Inst.Ref { |
| 2960 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2886 | 2961 | const tree = scope.tree(); |
| 2887 | 2962 | const main_tokens = tree.nodes.items(.main_token); |
| 2888 | 2963 | const token_starts = tree.tokens.items(.start); |
| ... | ... | @@ -2899,7 +2974,8 @@ fn multilineStringLiteral( |
| 2899 | 2974 | scope: *Scope, |
| 2900 | 2975 | rl: ResultLoc, |
| 2901 | 2976 | str_lit: ast.Node.Index, |
| 2902 | | ) InnerError!*zir.Inst { |
| 2977 | ) InnerError!zir.Inst.Ref { |
| 2978 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2903 | 2979 | const tree = scope.tree(); |
| 2904 | 2980 | const node_datas = tree.nodes.items(.data); |
| 2905 | 2981 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -2943,7 +3019,8 @@ fn multilineStringLiteral( |
| 2943 | 3019 | return rvalue(mod, scope, rl, str_inst); |
| 2944 | 3020 | } |
| 2945 | 3021 | |
| 2946 | | fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !*zir.Inst { |
| 3022 | fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| 3023 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2947 | 3024 | const tree = scope.tree(); |
| 2948 | 3025 | const main_tokens = tree.nodes.items(.main_token); |
| 2949 | 3026 | const main_token = main_tokens[node]; |
| ... | ... | @@ -2970,11 +3047,11 @@ fn integerLiteral( |
| 2970 | 3047 | mod: *Module, |
| 2971 | 3048 | scope: *Scope, |
| 2972 | 3049 | rl: ResultLoc, |
| 2973 | | int_lit: ast.Node.Index, |
| 2974 | | ) InnerError!*zir.Inst { |
| 3050 | node: ast.Node.Index, |
| 3051 | ) InnerError!zir.Inst.Ref { |
| 2975 | 3052 | const tree = scope.tree(); |
| 2976 | 3053 | const main_tokens = tree.nodes.items(.main_token); |
| 2977 | | const int_token = main_tokens[int_lit]; |
| 3054 | const int_token = main_tokens[node]; |
| 2978 | 3055 | const prefixed_bytes = tree.tokenSlice(int_token); |
| 2979 | 3056 | const gz = scope.getGenZir(); |
| 2980 | 3057 | if (std.fmt.parseInt(u64, prefixed_bytes, 0)) |small_int| { |
| ... | ... | @@ -2983,9 +3060,9 @@ fn integerLiteral( |
| 2983 | 3060 | 1 => @enumToInt(zir.Const.one), |
| 2984 | 3061 | else => try gz.addInt(small_int), |
| 2985 | 3062 | }; |
| 2986 | | return rvalue(mod, scope, rl, result); |
| 3063 | return rvalue(mod, scope, rl, result, node); |
| 2987 | 3064 | } else |err| { |
| 2988 | | return mod.failTok(scope, int_token, "TODO implement int literals that don't fit in a u64", .{}); |
| 3065 | return mod.failNode(scope, node, "TODO implement int literals that don't fit in a u64", .{}); |
| 2989 | 3066 | } |
| 2990 | 3067 | } |
| 2991 | 3068 | |
| ... | ... | @@ -2994,7 +3071,8 @@ fn floatLiteral( |
| 2994 | 3071 | scope: *Scope, |
| 2995 | 3072 | rl: ResultLoc, |
| 2996 | 3073 | float_lit: ast.Node.Index, |
| 2997 | | ) InnerError!*zir.Inst { |
| 3074 | ) InnerError!zir.Inst.Ref { |
| 3075 | if (true) @panic("TODO update for zir-memory-layout"); |
| 2998 | 3076 | const arena = scope.arena(); |
| 2999 | 3077 | const tree = scope.tree(); |
| 3000 | 3078 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -3016,7 +3094,8 @@ fn floatLiteral( |
| 3016 | 3094 | return rvalue(mod, scope, rl, result); |
| 3017 | 3095 | } |
| 3018 | 3096 | |
| 3019 | | fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) InnerError!*zir.Inst { |
| 3097 | fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) InnerError!zir.Inst.Ref { |
| 3098 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3020 | 3099 | const arena = scope.arena(); |
| 3021 | 3100 | const tree = scope.tree(); |
| 3022 | 3101 | const main_tokens = tree.nodes.items(.main_token); |
| ... | ... | @@ -3028,7 +3107,7 @@ fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) Inner |
| 3028 | 3107 | } |
| 3029 | 3108 | |
| 3030 | 3109 | const inputs = try arena.alloc([]const u8, full.inputs.len); |
| 3031 | | const args = try arena.alloc(*zir.Inst, full.inputs.len); |
| 3110 | const args = try arena.alloc(zir.Inst.Ref, full.inputs.len); |
| 3032 | 3111 | |
| 3033 | 3112 | const src = token_starts[full.ast.asm_token]; |
| 3034 | 3113 | const str_type = try addZIRInstConst(mod, scope, src, .{ |
| ... | ... | @@ -3068,7 +3147,7 @@ fn as( |
| 3068 | 3147 | src: usize, |
| 3069 | 3148 | lhs: ast.Node.Index, |
| 3070 | 3149 | rhs: ast.Node.Index, |
| 3071 | | ) InnerError!*zir.Inst { |
| 3150 | ) InnerError!zir.Inst.Ref { |
| 3072 | 3151 | const dest_type = try typeExpr(mod, scope, lhs); |
| 3073 | 3152 | switch (rl) { |
| 3074 | 3153 | .none, .discard, .ref, .ty => { |
| ... | ... | @@ -3099,10 +3178,10 @@ fn asRlPtr( |
| 3099 | 3178 | scope: *Scope, |
| 3100 | 3179 | rl: ResultLoc, |
| 3101 | 3180 | src: usize, |
| 3102 | | result_ptr: *zir.Inst, |
| 3181 | result_ptr: zir.Inst.Ref, |
| 3103 | 3182 | operand_node: ast.Node.Index, |
| 3104 | | dest_type: *zir.Inst, |
| 3105 | | ) InnerError!*zir.Inst { |
| 3183 | dest_type: zir.Inst.Ref, |
| 3184 | ) InnerError!zir.Inst.Ref { |
| 3106 | 3185 | // Detect whether this expr() call goes into rvalue() to store the result into the |
| 3107 | 3186 | // result location. If it does, elide the coerce_result_ptr instruction |
| 3108 | 3187 | // as well as the store instruction, instead passing the result as an rvalue. |
| ... | ... | @@ -3146,7 +3225,7 @@ fn bitCast( |
| 3146 | 3225 | src: usize, |
| 3147 | 3226 | lhs: ast.Node.Index, |
| 3148 | 3227 | rhs: ast.Node.Index, |
| 3149 | | ) InnerError!*zir.Inst { |
| 3228 | ) InnerError!zir.Inst.Ref { |
| 3150 | 3229 | const dest_type = try typeExpr(mod, scope, lhs); |
| 3151 | 3230 | switch (rl) { |
| 3152 | 3231 | .none => { |
| ... | ... | @@ -3193,7 +3272,7 @@ fn typeOf( |
| 3193 | 3272 | builtin_token: ast.TokenIndex, |
| 3194 | 3273 | src: usize, |
| 3195 | 3274 | params: []const ast.Node.Index, |
| 3196 | | ) InnerError!*zir.Inst { |
| 3275 | ) InnerError!zir.Inst.Ref { |
| 3197 | 3276 | if (params.len < 1) { |
| 3198 | 3277 | return mod.failTok(scope, builtin_token, "expected at least 1 argument, found 0", .{}); |
| 3199 | 3278 | } |
| ... | ... | @@ -3201,7 +3280,7 @@ fn typeOf( |
| 3201 | 3280 | return rvalue(mod, scope, rl, try addZIRUnOp(mod, scope, src, .typeof, try expr(mod, scope, .none, params[0]))); |
| 3202 | 3281 | } |
| 3203 | 3282 | const arena = scope.arena(); |
| 3204 | | var items = try arena.alloc(*zir.Inst, params.len); |
| 3283 | var items = try arena.alloc(zir.Inst.Ref, params.len); |
| 3205 | 3284 | for (params) |param, param_i| |
| 3206 | 3285 | items[param_i] = try expr(mod, scope, .none, param); |
| 3207 | 3286 | return rvalue(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.TypeOfPeer, .{ .items = items }, .{})); |
| ... | ... | @@ -3213,7 +3292,8 @@ fn builtinCall( |
| 3213 | 3292 | rl: ResultLoc, |
| 3214 | 3293 | call: ast.Node.Index, |
| 3215 | 3294 | params: []const ast.Node.Index, |
| 3216 | | ) InnerError!*zir.Inst { |
| 3295 | ) InnerError!zir.Inst.Ref { |
| 3296 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3217 | 3297 | const tree = scope.tree(); |
| 3218 | 3298 | const main_tokens = tree.nodes.items(.main_token); |
| 3219 | 3299 | const token_starts = tree.tokens.items(.start); |
| ... | ... | @@ -3284,7 +3364,7 @@ fn builtinCall( |
| 3284 | 3364 | }, |
| 3285 | 3365 | .compile_log => { |
| 3286 | 3366 | const arena = scope.arena(); |
| 3287 | | var targets = try arena.alloc(*zir.Inst, params.len); |
| 3367 | var targets = try arena.alloc(zir.Inst.Ref, params.len); |
| 3288 | 3368 | for (params) |param, param_i| |
| 3289 | 3369 | targets[param_i] = try expr(mod, scope, .none, param); |
| 3290 | 3370 | const result = try addZIRInst(mod, scope, src, zir.Inst.CompileLog, .{ .to_log = targets }, .{}); |
| ... | ... | @@ -3414,7 +3494,7 @@ fn callExpr( |
| 3414 | 3494 | rl: ResultLoc, |
| 3415 | 3495 | node: ast.Node.Index, |
| 3416 | 3496 | call: ast.full.Call, |
| 3417 | | ) InnerError!*zir.Inst { |
| 3497 | ) InnerError!zir.Inst.Ref { |
| 3418 | 3498 | if (true) { |
| 3419 | 3499 | @panic("TODO update for zir-memory-layout branch"); |
| 3420 | 3500 | } |
| ... | ... | @@ -3459,7 +3539,7 @@ fn callExpr( |
| 3459 | 3539 | return rvalue(mod, scope, rl, result); // TODO function call with result location |
| 3460 | 3540 | } |
| 3461 | 3541 | |
| 3462 | | fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { |
| 3542 | fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 3463 | 3543 | const tree = scope.tree(); |
| 3464 | 3544 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; |
| 3465 | 3545 | |
| ... | ... | @@ -3504,12 +3584,13 @@ fn suspendExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zi |
| 3504 | 3584 | } |
| 3505 | 3585 | |
| 3506 | 3586 | const block = try addZIRInstBlock(mod, scope, src, .suspend_block, .{ |
| 3507 | | .instructions = try scope.arena().dupe(*zir.Inst, suspend_scope.instructions.items), |
| 3587 | .instructions = try scope.arena().dupe(zir.Inst.Ref, suspend_scope.instructions.items), |
| 3508 | 3588 | }); |
| 3509 | 3589 | return &block.base; |
| 3510 | 3590 | } |
| 3511 | 3591 | |
| 3512 | | fn nosuspendExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { |
| 3592 | fn nosuspendExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 3593 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3513 | 3594 | const tree = scope.tree(); |
| 3514 | 3595 | var child_scope = Scope.Nosuspend{ |
| 3515 | 3596 | .parent = scope, |
| ... | ... | @@ -3520,7 +3601,8 @@ fn nosuspendExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Inde |
| 3520 | 3601 | return expr(mod, &child_scope.base, rl, tree.nodes.items(.data)[node].lhs); |
| 3521 | 3602 | } |
| 3522 | 3603 | |
| 3523 | | fn awaitExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!*zir.Inst { |
| 3604 | fn awaitExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 3605 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3524 | 3606 | const tree = scope.tree(); |
| 3525 | 3607 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; |
| 3526 | 3608 | const is_nosuspend = scope.getNosuspend() != null; |
| ... | ... | @@ -3542,7 +3624,7 @@ fn awaitExpr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) I |
| 3542 | 3624 | return addZIRUnOp(mod, scope, src, if (is_nosuspend) .nosuspend_await else .@"await", operand); |
| 3543 | 3625 | } |
| 3544 | 3626 | |
| 3545 | | fn resumeExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!*zir.Inst { |
| 3627 | fn resumeExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 3546 | 3628 | const tree = scope.tree(); |
| 3547 | 3629 | const src = tree.tokens.items(.start)[tree.nodes.items(.main_token)[node]]; |
| 3548 | 3630 | |
| ... | ... | @@ -3828,7 +3910,7 @@ fn rvalue( |
| 3828 | 3910 | // We need a pointer but we have a value. |
| 3829 | 3911 | const tree = scope.tree(); |
| 3830 | 3912 | const src_token = tree.firstToken(src_node); |
| 3831 | | return gz.addUnTok(.ref, result, src_tok); |
| 3913 | return gz.addUnTok(.ref, result, src_token); |
| 3832 | 3914 | }, |
| 3833 | 3915 | .ty => |ty_inst| return gz.addBin(.as, ty_inst, result), |
| 3834 | 3916 | .ptr => |ptr_inst| { |
| ... | ... | @@ -3844,31 +3926,12 @@ fn rvalue( |
| 3844 | 3926 | }, |
| 3845 | 3927 | .block_ptr => |block_scope| { |
| 3846 | 3928 | block_scope.rvalue_rl_count += 1; |
| 3847 | | _ = try gz.addBin(.store_to_block_ptr, block_scope.rl_ptr.?, result); |
| 3929 | _ = try gz.addBin(.store_to_block_ptr, block_scope.rl_ptr, result); |
| 3848 | 3930 | return result; |
| 3849 | 3931 | }, |
| 3850 | 3932 | } |
| 3851 | 3933 | } |
| 3852 | 3934 | |
| 3853 | | /// TODO when reworking ZIR memory layout, make the void value correspond to a hard coded |
| 3854 | | /// index; that way this does not actually need to allocate anything. |
| 3855 | | fn rvalueVoid( |
| 3856 | | mod: *Module, |
| 3857 | | scope: *Scope, |
| 3858 | | rl: ResultLoc, |
| 3859 | | node: ast.Node.Index, |
| 3860 | | result: void, |
| 3861 | | ) InnerError!*zir.Inst { |
| 3862 | | const tree = scope.tree(); |
| 3863 | | const main_tokens = tree.nodes.items(.main_token); |
| 3864 | | const src = tree.tokens.items(.start)[tree.firstToken(node)]; |
| 3865 | | const void_inst = try addZIRInstConst(mod, scope, src, .{ |
| 3866 | | .ty = Type.initTag(.void), |
| 3867 | | .val = Value.initTag(.void_value), |
| 3868 | | }); |
| 3869 | | return rvalue(mod, scope, rl, void_inst); |
| 3870 | | } |
| 3871 | | |
| 3872 | 3935 | fn rlStrategy(rl: ResultLoc, block_scope: *Scope.GenZir) ResultLoc.Strategy { |
| 3873 | 3936 | var elide_store_to_block_ptr_instructions = false; |
| 3874 | 3937 | switch (rl) { |
| ... | ... | @@ -3953,190 +4016,3 @@ fn setBlockResultLoc(block_scope: *Scope.GenZir, parent_rl: ResultLoc) void { |
| 3953 | 4016 | }, |
| 3954 | 4017 | } |
| 3955 | 4018 | } |
| 3956 | | |
| 3957 | | pub fn addZirInstTag( |
| 3958 | | mod: *Module, |
| 3959 | | scope: *Scope, |
| 3960 | | src: usize, |
| 3961 | | comptime tag: zir.Inst.Tag, |
| 3962 | | positionals: std.meta.fieldInfo(tag.Type(), .positionals).field_type, |
| 3963 | | ) !*zir.Inst { |
| 3964 | | const gen_zir = scope.getGenZir(); |
| 3965 | | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); |
| 3966 | | const inst = try gen_zir.arena.create(tag.Type()); |
| 3967 | | inst.* = .{ |
| 3968 | | .base = .{ |
| 3969 | | .tag = tag, |
| 3970 | | .src = src, |
| 3971 | | }, |
| 3972 | | .positionals = positionals, |
| 3973 | | .kw_args = .{}, |
| 3974 | | }; |
| 3975 | | gen_zir.instructions.appendAssumeCapacity(&inst.base); |
| 3976 | | return &inst.base; |
| 3977 | | } |
| 3978 | | |
| 3979 | | pub fn addZirInstT( |
| 3980 | | mod: *Module, |
| 3981 | | scope: *Scope, |
| 3982 | | src: usize, |
| 3983 | | comptime T: type, |
| 3984 | | tag: zir.Inst.Tag, |
| 3985 | | positionals: std.meta.fieldInfo(T, .positionals).field_type, |
| 3986 | | ) !*T { |
| 3987 | | const gen_zir = scope.getGenZir(); |
| 3988 | | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); |
| 3989 | | const inst = try gen_zir.arena.create(T); |
| 3990 | | inst.* = .{ |
| 3991 | | .base = .{ |
| 3992 | | .tag = tag, |
| 3993 | | .src = src, |
| 3994 | | }, |
| 3995 | | .positionals = positionals, |
| 3996 | | .kw_args = .{}, |
| 3997 | | }; |
| 3998 | | gen_zir.instructions.appendAssumeCapacity(&inst.base); |
| 3999 | | return inst; |
| 4000 | | } |
| 4001 | | |
| 4002 | | pub fn addZIRInstSpecial( |
| 4003 | | mod: *Module, |
| 4004 | | scope: *Scope, |
| 4005 | | src: usize, |
| 4006 | | comptime T: type, |
| 4007 | | positionals: std.meta.fieldInfo(T, .positionals).field_type, |
| 4008 | | kw_args: std.meta.fieldInfo(T, .kw_args).field_type, |
| 4009 | | ) !*T { |
| 4010 | | const gen_zir = scope.getGenZir(); |
| 4011 | | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); |
| 4012 | | const inst = try gen_zir.arena.create(T); |
| 4013 | | inst.* = .{ |
| 4014 | | .base = .{ |
| 4015 | | .tag = T.base_tag, |
| 4016 | | .src = src, |
| 4017 | | }, |
| 4018 | | .positionals = positionals, |
| 4019 | | .kw_args = kw_args, |
| 4020 | | }; |
| 4021 | | gen_zir.instructions.appendAssumeCapacity(&inst.base); |
| 4022 | | return inst; |
| 4023 | | } |
| 4024 | | |
| 4025 | | pub fn addZIRNoOpT(mod: *Module, scope: *Scope, src: usize, tag: zir.Inst.Tag) !*zir.Inst.NoOp { |
| 4026 | | const gen_zir = scope.getGenZir(); |
| 4027 | | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); |
| 4028 | | const inst = try gen_zir.arena.create(zir.Inst.NoOp); |
| 4029 | | inst.* = .{ |
| 4030 | | .base = .{ |
| 4031 | | .tag = tag, |
| 4032 | | .src = src, |
| 4033 | | }, |
| 4034 | | .positionals = .{}, |
| 4035 | | .kw_args = .{}, |
| 4036 | | }; |
| 4037 | | gen_zir.instructions.appendAssumeCapacity(&inst.base); |
| 4038 | | return inst; |
| 4039 | | } |
| 4040 | | |
| 4041 | | pub fn addZIRNoOp(mod: *Module, scope: *Scope, src: usize, tag: zir.Inst.Tag) !*zir.Inst { |
| 4042 | | const inst = try addZIRNoOpT(mod, scope, src, tag); |
| 4043 | | return &inst.base; |
| 4044 | | } |
| 4045 | | |
| 4046 | | pub fn addZIRUnOp( |
| 4047 | | mod: *Module, |
| 4048 | | scope: *Scope, |
| 4049 | | src: usize, |
| 4050 | | tag: zir.Inst.Tag, |
| 4051 | | operand: *zir.Inst, |
| 4052 | | ) !*zir.Inst { |
| 4053 | | const gen_zir = scope.getGenZir(); |
| 4054 | | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); |
| 4055 | | const inst = try gen_zir.arena.create(zir.Inst.UnOp); |
| 4056 | | inst.* = .{ |
| 4057 | | .base = .{ |
| 4058 | | .tag = tag, |
| 4059 | | .src = src, |
| 4060 | | }, |
| 4061 | | .positionals = .{ |
| 4062 | | .operand = operand, |
| 4063 | | }, |
| 4064 | | .kw_args = .{}, |
| 4065 | | }; |
| 4066 | | gen_zir.instructions.appendAssumeCapacity(&inst.base); |
| 4067 | | return &inst.base; |
| 4068 | | } |
| 4069 | | |
| 4070 | | pub fn addZIRBinOp( |
| 4071 | | mod: *Module, |
| 4072 | | scope: *Scope, |
| 4073 | | src: usize, |
| 4074 | | tag: zir.Inst.Tag, |
| 4075 | | lhs: *zir.Inst, |
| 4076 | | rhs: *zir.Inst, |
| 4077 | | ) !*zir.Inst { |
| 4078 | | const gen_zir = scope.getGenZir(); |
| 4079 | | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); |
| 4080 | | const inst = try gen_zir.arena.create(zir.Inst.BinOp); |
| 4081 | | inst.* = .{ |
| 4082 | | .base = .{ |
| 4083 | | .tag = tag, |
| 4084 | | .src = src, |
| 4085 | | }, |
| 4086 | | .positionals = .{ |
| 4087 | | .lhs = lhs, |
| 4088 | | .rhs = rhs, |
| 4089 | | }, |
| 4090 | | .kw_args = .{}, |
| 4091 | | }; |
| 4092 | | gen_zir.instructions.appendAssumeCapacity(&inst.base); |
| 4093 | | return &inst.base; |
| 4094 | | } |
| 4095 | | |
| 4096 | | pub fn addZIRInstBlock( |
| 4097 | | mod: *Module, |
| 4098 | | scope: *Scope, |
| 4099 | | src: usize, |
| 4100 | | tag: zir.Inst.Tag, |
| 4101 | | body: zir.Body, |
| 4102 | | ) !*zir.Inst.Block { |
| 4103 | | const gen_zir = scope.getGenZir(); |
| 4104 | | try gen_zir.instructions.ensureCapacity(mod.gpa, gen_zir.instructions.items.len + 1); |
| 4105 | | const inst = try gen_zir.arena.create(zir.Inst.Block); |
| 4106 | | inst.* = .{ |
| 4107 | | .base = .{ |
| 4108 | | .tag = tag, |
| 4109 | | .src = src, |
| 4110 | | }, |
| 4111 | | .positionals = .{ |
| 4112 | | .body = body, |
| 4113 | | }, |
| 4114 | | .kw_args = .{}, |
| 4115 | | }; |
| 4116 | | gen_zir.instructions.appendAssumeCapacity(&inst.base); |
| 4117 | | return inst; |
| 4118 | | } |
| 4119 | | |
| 4120 | | pub fn addZIRInst( |
| 4121 | | mod: *Module, |
| 4122 | | scope: *Scope, |
| 4123 | | src: usize, |
| 4124 | | comptime T: type, |
| 4125 | | positionals: std.meta.fieldInfo(T, .positionals).field_type, |
| 4126 | | kw_args: std.meta.fieldInfo(T, .kw_args).field_type, |
| 4127 | | ) !*zir.Inst { |
| 4128 | | const inst_special = try addZIRInstSpecial(mod, scope, src, T, positionals, kw_args); |
| 4129 | | return &inst_special.base; |
| 4130 | | } |
| 4131 | | |
| 4132 | | /// TODO The existence of this function is a workaround for a bug in stage1. |
| 4133 | | pub fn addZIRInstConst(mod: *Module, scope: *Scope, src: usize, typed_value: TypedValue) !*zir.Inst { |
| 4134 | | const P = std.meta.fieldInfo(zir.Inst.Const, .positionals).field_type; |
| 4135 | | return addZIRInst(mod, scope, src, zir.Inst.Const, P{ .typed_value = typed_value }, .{}); |
| 4136 | | } |
| 4137 | | |
| 4138 | | /// TODO The existence of this function is a workaround for a bug in stage1. |
| 4139 | | pub fn addZIRInstLoop(mod: *Module, scope: *Scope, src: usize, body: zir.Body) !*zir.Inst.Loop { |
| 4140 | | const P = std.meta.fieldInfo(zir.Inst.Loop, .positionals).field_type; |
| 4141 | | return addZIRInstSpecial(mod, scope, src, zir.Inst.Loop, P{ .body = body }, .{}); |
| 4142 | | } |