| ... | @@ -19,6 +19,7 @@ const zir = @import("zir.zig"); | ... | @@ -19,6 +19,7 @@ const zir = @import("zir.zig"); |
| 19 | const Module = @import("Module.zig"); | 19 | const Module = @import("Module.zig"); |
| 20 | const trace = @import("tracy.zig").trace; | 20 | const trace = @import("tracy.zig").trace; |
| 21 | const Scope = Module.Scope; | 21 | const Scope = Module.Scope; |
| | 22 | const GenZir = Scope.GenZir; |
| 22 | const InnerError = Module.InnerError; | 23 | const InnerError = Module.InnerError; |
| 23 | const Decl = Module.Decl; | 24 | const Decl = Module.Decl; |
| 24 | const BuiltinFn = @import("BuiltinFn.zig"); | 25 | const BuiltinFn = @import("BuiltinFn.zig"); |
| ... | @@ -138,7 +139,7 @@ pub const ResultLoc = union(enum) { | ... | @@ -138,7 +139,7 @@ pub const ResultLoc = union(enum) { |
| 138 | /// There is a pointer for the expression to store its result into, however, its type | 139 | /// There is a pointer for the expression to store its result into, however, its type |
| 139 | /// is inferred based on peer type resolution for a `zir.Inst.Block`. | 140 | /// is inferred based on peer type resolution for a `zir.Inst.Block`. |
| 140 | /// The result instruction from the expression must be ignored. | 141 | /// The result instruction from the expression must be ignored. |
| 141 | block_ptr: *Scope.GenZir, | 142 | block_ptr: *GenZir, |
| 142 | | 143 | |
| 143 | pub const Strategy = struct { | 144 | pub const Strategy = struct { |
| 144 | elide_store_to_block_ptr_instructions: bool, | 145 | elide_store_to_block_ptr_instructions: bool, |
| ... | @@ -155,7 +156,7 @@ pub const ResultLoc = union(enum) { | ... | @@ -155,7 +156,7 @@ pub const ResultLoc = union(enum) { |
| 155 | }; | 156 | }; |
| 156 | }; | 157 | }; |
| 157 | | 158 | |
| 158 | fn strategy(rl: ResultLoc, block_scope: *Scope.GenZir) Strategy { | 159 | fn strategy(rl: ResultLoc, block_scope: *GenZir) Strategy { |
| 159 | var elide_store_to_block_ptr_instructions = false; | 160 | var elide_store_to_block_ptr_instructions = false; |
| 160 | switch (rl) { | 161 | switch (rl) { |
| 161 | // In this branch there will not be any store_to_block_ptr instructions. | 162 | // In this branch there will not be any store_to_block_ptr instructions. |
| ... | @@ -191,11 +192,11 @@ pub const ResultLoc = union(enum) { | ... | @@ -191,11 +192,11 @@ pub const ResultLoc = union(enum) { |
| 191 | } | 192 | } |
| 192 | }; | 193 | }; |
| 193 | | 194 | |
| 194 | pub fn typeExpr(mod: *Module, scope: *Scope, type_node: ast.Node.Index) InnerError!zir.Inst.Ref { | 195 | pub fn typeExpr(gz: *GenZir, scope: *Scope, type_node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 195 | return expr(mod, scope, .{ .ty = .type_type }, type_node); | 196 | return expr(gz, scope, .{ .ty = .type_type }, type_node); |
| 196 | } | 197 | } |
| 197 | | 198 | |
| 198 | fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { | 199 | fn lvalExpr(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 199 | const tree = scope.tree(); | 200 | const tree = scope.tree(); |
| 200 | const node_tags = tree.nodes.items(.tag); | 201 | const node_tags = tree.nodes.items(.tag); |
| 201 | const main_tokens = tree.nodes.items(.main_token); | 202 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -354,7 +355,7 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.In | ... | @@ -354,7 +355,7 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.In |
| 354 | .@"comptime", | 355 | .@"comptime", |
| 355 | .@"nosuspend", | 356 | .@"nosuspend", |
| 356 | .error_value, | 357 | .error_value, |
| 357 | => return mod.failNode(scope, node, "invalid left-hand side to assignment", .{}), | 358 | => return gz.astgen.mod.failNode(scope, node, "invalid left-hand side to assignment", .{}), |
| 358 | | 359 | |
| 359 | .builtin_call, | 360 | .builtin_call, |
| 360 | .builtin_call_comma, | 361 | .builtin_call_comma, |
| ... | @@ -367,7 +368,7 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.In | ... | @@ -367,7 +368,7 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.In |
| 367 | // let it pass, and the error will be "invalid builtin function" later. | 368 | // let it pass, and the error will be "invalid builtin function" later. |
| 368 | if (BuiltinFn.list.get(builtin_name)) |info| { | 369 | if (BuiltinFn.list.get(builtin_name)) |info| { |
| 369 | if (!info.allows_lvalue) { | 370 | if (!info.allows_lvalue) { |
| 370 | return mod.failNode(scope, node, "invalid left-hand side to assignment", .{}); | 371 | return gz.astgen.mod.failNode(scope, node, "invalid left-hand side to assignment", .{}); |
| 371 | } | 372 | } |
| 372 | } | 373 | } |
| 373 | }, | 374 | }, |
| ... | @@ -382,22 +383,21 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.In | ... | @@ -382,22 +383,21 @@ fn lvalExpr(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.In |
| 382 | .@"orelse", | 383 | .@"orelse", |
| 383 | => {}, | 384 | => {}, |
| 384 | } | 385 | } |
| 385 | return expr(mod, scope, .ref, node); | 386 | return expr(gz, scope, .ref, node); |
| 386 | } | 387 | } |
| 387 | | 388 | |
| 388 | /// Turn Zig AST into untyped ZIR istructions. | 389 | /// Turn Zig AST into untyped ZIR istructions. |
| 389 | /// When `rl` is discard, ptr, inferred_ptr, bitcasted_ptr, or inferred_ptr, the | 390 | /// When `rl` is discard, ptr, inferred_ptr, bitcasted_ptr, or inferred_ptr, the |
| 390 | /// result instruction can be used to inspect whether it is isNoReturn() but that is it, | 391 | /// result instruction can be used to inspect whether it is isNoReturn() but that is it, |
| 391 | /// it must otherwise not be used. | 392 | /// it must otherwise not be used. |
| 392 | pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { | 393 | pub fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| | 394 | const mod = gz.astgen.mod; |
| 393 | const tree = scope.tree(); | 395 | const tree = scope.tree(); |
| 394 | const main_tokens = tree.nodes.items(.main_token); | 396 | const main_tokens = tree.nodes.items(.main_token); |
| 395 | const token_tags = tree.tokens.items(.tag); | 397 | const token_tags = tree.tokens.items(.tag); |
| 396 | const node_datas = tree.nodes.items(.data); | 398 | const node_datas = tree.nodes.items(.data); |
| 397 | const node_tags = tree.nodes.items(.tag); | 399 | const node_tags = tree.nodes.items(.tag); |
| 398 | | 400 | |
| 399 | const gz = scope.getGenZir(); | | |
| 400 | | | |
| 401 | switch (node_tags[node]) { | 401 | switch (node_tags[node]) { |
| 402 | .root => unreachable, // Top-level declaration. | 402 | .root => unreachable, // Top-level declaration. |
| 403 | .@"usingnamespace" => unreachable, // Top-level declaration. | 403 | .@"usingnamespace" => unreachable, // Top-level declaration. |
| ... | @@ -420,131 +420,131 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -420,131 +420,131 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 420 | .asm_input => unreachable, // Handled in `asmExpr`. | 420 | .asm_input => unreachable, // Handled in `asmExpr`. |
| 421 | | 421 | |
| 422 | .assign => { | 422 | .assign => { |
| 423 | try assign(mod, scope, node); | 423 | try assign(gz, scope, node); |
| 424 | return rvalue(mod, scope, rl, .void_value, node); | 424 | return rvalue(gz, scope, rl, .void_value, node); |
| 425 | }, | 425 | }, |
| 426 | .assign_bit_and => { | 426 | .assign_bit_and => { |
| 427 | try assignOp(mod, scope, node, .bit_and); | 427 | try assignOp(gz, scope, node, .bit_and); |
| 428 | return rvalue(mod, scope, rl, .void_value, node); | 428 | return rvalue(gz, scope, rl, .void_value, node); |
| 429 | }, | 429 | }, |
| 430 | .assign_bit_or => { | 430 | .assign_bit_or => { |
| 431 | try assignOp(mod, scope, node, .bit_or); | 431 | try assignOp(gz, scope, node, .bit_or); |
| 432 | return rvalue(mod, scope, rl, .void_value, node); | 432 | return rvalue(gz, scope, rl, .void_value, node); |
| 433 | }, | 433 | }, |
| 434 | .assign_bit_shift_left => { | 434 | .assign_bit_shift_left => { |
| 435 | try assignOp(mod, scope, node, .shl); | 435 | try assignOp(gz, scope, node, .shl); |
| 436 | return rvalue(mod, scope, rl, .void_value, node); | 436 | return rvalue(gz, scope, rl, .void_value, node); |
| 437 | }, | 437 | }, |
| 438 | .assign_bit_shift_right => { | 438 | .assign_bit_shift_right => { |
| 439 | try assignOp(mod, scope, node, .shr); | 439 | try assignOp(gz, scope, node, .shr); |
| 440 | return rvalue(mod, scope, rl, .void_value, node); | 440 | return rvalue(gz, scope, rl, .void_value, node); |
| 441 | }, | 441 | }, |
| 442 | .assign_bit_xor => { | 442 | .assign_bit_xor => { |
| 443 | try assignOp(mod, scope, node, .xor); | 443 | try assignOp(gz, scope, node, .xor); |
| 444 | return rvalue(mod, scope, rl, .void_value, node); | 444 | return rvalue(gz, scope, rl, .void_value, node); |
| 445 | }, | 445 | }, |
| 446 | .assign_div => { | 446 | .assign_div => { |
| 447 | try assignOp(mod, scope, node, .div); | 447 | try assignOp(gz, scope, node, .div); |
| 448 | return rvalue(mod, scope, rl, .void_value, node); | 448 | return rvalue(gz, scope, rl, .void_value, node); |
| 449 | }, | 449 | }, |
| 450 | .assign_sub => { | 450 | .assign_sub => { |
| 451 | try assignOp(mod, scope, node, .sub); | 451 | try assignOp(gz, scope, node, .sub); |
| 452 | return rvalue(mod, scope, rl, .void_value, node); | 452 | return rvalue(gz, scope, rl, .void_value, node); |
| 453 | }, | 453 | }, |
| 454 | .assign_sub_wrap => { | 454 | .assign_sub_wrap => { |
| 455 | try assignOp(mod, scope, node, .subwrap); | 455 | try assignOp(gz, scope, node, .subwrap); |
| 456 | return rvalue(mod, scope, rl, .void_value, node); | 456 | return rvalue(gz, scope, rl, .void_value, node); |
| 457 | }, | 457 | }, |
| 458 | .assign_mod => { | 458 | .assign_mod => { |
| 459 | try assignOp(mod, scope, node, .mod_rem); | 459 | try assignOp(gz, scope, node, .mod_rem); |
| 460 | return rvalue(mod, scope, rl, .void_value, node); | 460 | return rvalue(gz, scope, rl, .void_value, node); |
| 461 | }, | 461 | }, |
| 462 | .assign_add => { | 462 | .assign_add => { |
| 463 | try assignOp(mod, scope, node, .add); | 463 | try assignOp(gz, scope, node, .add); |
| 464 | return rvalue(mod, scope, rl, .void_value, node); | 464 | return rvalue(gz, scope, rl, .void_value, node); |
| 465 | }, | 465 | }, |
| 466 | .assign_add_wrap => { | 466 | .assign_add_wrap => { |
| 467 | try assignOp(mod, scope, node, .addwrap); | 467 | try assignOp(gz, scope, node, .addwrap); |
| 468 | return rvalue(mod, scope, rl, .void_value, node); | 468 | return rvalue(gz, scope, rl, .void_value, node); |
| 469 | }, | 469 | }, |
| 470 | .assign_mul => { | 470 | .assign_mul => { |
| 471 | try assignOp(mod, scope, node, .mul); | 471 | try assignOp(gz, scope, node, .mul); |
| 472 | return rvalue(mod, scope, rl, .void_value, node); | 472 | return rvalue(gz, scope, rl, .void_value, node); |
| 473 | }, | 473 | }, |
| 474 | .assign_mul_wrap => { | 474 | .assign_mul_wrap => { |
| 475 | try assignOp(mod, scope, node, .mulwrap); | 475 | try assignOp(gz, scope, node, .mulwrap); |
| 476 | return rvalue(mod, scope, rl, .void_value, node); | 476 | return rvalue(gz, scope, rl, .void_value, node); |
| 477 | }, | 477 | }, |
| 478 | | 478 | |
| 479 | .add => return simpleBinOp(mod, scope, rl, node, .add), | 479 | .add => return simpleBinOp(gz, scope, rl, node, .add), |
| 480 | .add_wrap => return simpleBinOp(mod, scope, rl, node, .addwrap), | 480 | .add_wrap => return simpleBinOp(gz, scope, rl, node, .addwrap), |
| 481 | .sub => return simpleBinOp(mod, scope, rl, node, .sub), | 481 | .sub => return simpleBinOp(gz, scope, rl, node, .sub), |
| 482 | .sub_wrap => return simpleBinOp(mod, scope, rl, node, .subwrap), | 482 | .sub_wrap => return simpleBinOp(gz, scope, rl, node, .subwrap), |
| 483 | .mul => return simpleBinOp(mod, scope, rl, node, .mul), | 483 | .mul => return simpleBinOp(gz, scope, rl, node, .mul), |
| 484 | .mul_wrap => return simpleBinOp(mod, scope, rl, node, .mulwrap), | 484 | .mul_wrap => return simpleBinOp(gz, scope, rl, node, .mulwrap), |
| 485 | .div => return simpleBinOp(mod, scope, rl, node, .div), | 485 | .div => return simpleBinOp(gz, scope, rl, node, .div), |
| 486 | .mod => return simpleBinOp(mod, scope, rl, node, .mod_rem), | 486 | .mod => return simpleBinOp(gz, scope, rl, node, .mod_rem), |
| 487 | .bit_and => return simpleBinOp(mod, scope, rl, node, .bit_and), | 487 | .bit_and => return simpleBinOp(gz, scope, rl, node, .bit_and), |
| 488 | .bit_or => return simpleBinOp(mod, scope, rl, node, .bit_or), | 488 | .bit_or => return simpleBinOp(gz, scope, rl, node, .bit_or), |
| 489 | .bit_shift_left => return simpleBinOp(mod, scope, rl, node, .shl), | 489 | .bit_shift_left => return simpleBinOp(gz, scope, rl, node, .shl), |
| 490 | .bit_shift_right => return simpleBinOp(mod, scope, rl, node, .shr), | 490 | .bit_shift_right => return simpleBinOp(gz, scope, rl, node, .shr), |
| 491 | .bit_xor => return simpleBinOp(mod, scope, rl, node, .xor), | 491 | .bit_xor => return simpleBinOp(gz, scope, rl, node, .xor), |
| 492 | | 492 | |
| 493 | .bang_equal => return simpleBinOp(mod, scope, rl, node, .cmp_neq), | 493 | .bang_equal => return simpleBinOp(gz, scope, rl, node, .cmp_neq), |
| 494 | .equal_equal => return simpleBinOp(mod, scope, rl, node, .cmp_eq), | 494 | .equal_equal => return simpleBinOp(gz, scope, rl, node, .cmp_eq), |
| 495 | .greater_than => return simpleBinOp(mod, scope, rl, node, .cmp_gt), | 495 | .greater_than => return simpleBinOp(gz, scope, rl, node, .cmp_gt), |
| 496 | .greater_or_equal => return simpleBinOp(mod, scope, rl, node, .cmp_gte), | 496 | .greater_or_equal => return simpleBinOp(gz, scope, rl, node, .cmp_gte), |
| 497 | .less_than => return simpleBinOp(mod, scope, rl, node, .cmp_lt), | 497 | .less_than => return simpleBinOp(gz, scope, rl, node, .cmp_lt), |
| 498 | .less_or_equal => return simpleBinOp(mod, scope, rl, node, .cmp_lte), | 498 | .less_or_equal => return simpleBinOp(gz, scope, rl, node, .cmp_lte), |
| 499 | | 499 | |
| 500 | .array_cat => return simpleBinOp(mod, scope, rl, node, .array_cat), | 500 | .array_cat => return simpleBinOp(gz, scope, rl, node, .array_cat), |
| 501 | .array_mult => return simpleBinOp(mod, scope, rl, node, .array_mul), | 501 | .array_mult => return simpleBinOp(gz, scope, rl, node, .array_mul), |
| 502 | | 502 | |
| 503 | .error_union => return simpleBinOp(mod, scope, rl, node, .error_union_type), | 503 | .error_union => return simpleBinOp(gz, scope, rl, node, .error_union_type), |
| 504 | .merge_error_sets => return simpleBinOp(mod, scope, rl, node, .merge_error_sets), | 504 | .merge_error_sets => return simpleBinOp(gz, scope, rl, node, .merge_error_sets), |
| 505 | | 505 | |
| 506 | .bool_and => return boolBinOp(mod, scope, rl, node, .bool_br_and), | 506 | .bool_and => return boolBinOp(gz, scope, rl, node, .bool_br_and), |
| 507 | .bool_or => return boolBinOp(mod, scope, rl, node, .bool_br_or), | 507 | .bool_or => return boolBinOp(gz, scope, rl, node, .bool_br_or), |
| 508 | | 508 | |
| 509 | .bool_not => return boolNot(mod, scope, rl, node), | 509 | .bool_not => return boolNot(gz, scope, rl, node), |
| 510 | .bit_not => return bitNot(mod, scope, rl, node), | 510 | .bit_not => return bitNot(gz, scope, rl, node), |
| 511 | | 511 | |
| 512 | .negation => return negation(mod, scope, rl, node, .negate), | 512 | .negation => return negation(gz, scope, rl, node, .negate), |
| 513 | .negation_wrap => return negation(mod, scope, rl, node, .negate_wrap), | 513 | .negation_wrap => return negation(gz, scope, rl, node, .negate_wrap), |
| 514 | | 514 | |
| 515 | .identifier => return identifier(mod, scope, rl, node), | 515 | .identifier => return identifier(gz, scope, rl, node), |
| 516 | | 516 | |
| 517 | .asm_simple => return asmExpr(mod, scope, rl, node, tree.asmSimple(node)), | 517 | .asm_simple => return asmExpr(gz, scope, rl, node, tree.asmSimple(node)), |
| 518 | .@"asm" => return asmExpr(mod, scope, rl, node, tree.asmFull(node)), | 518 | .@"asm" => return asmExpr(gz, scope, rl, node, tree.asmFull(node)), |
| 519 | | 519 | |
| 520 | .string_literal => return stringLiteral(mod, scope, rl, node), | 520 | .string_literal => return stringLiteral(gz, scope, rl, node), |
| 521 | .multiline_string_literal => return multilineStringLiteral(mod, scope, rl, node), | 521 | .multiline_string_literal => return multilineStringLiteral(gz, scope, rl, node), |
| 522 | | 522 | |
| 523 | .integer_literal => return integerLiteral(mod, scope, rl, node), | 523 | .integer_literal => return integerLiteral(gz, scope, rl, node), |
| 524 | | 524 | |
| 525 | .builtin_call_two, .builtin_call_two_comma => { | 525 | .builtin_call_two, .builtin_call_two_comma => { |
| 526 | if (node_datas[node].lhs == 0) { | 526 | if (node_datas[node].lhs == 0) { |
| 527 | const params = [_]ast.Node.Index{}; | 527 | const params = [_]ast.Node.Index{}; |
| 528 | return builtinCall(mod, scope, rl, node, &params); | 528 | return builtinCall(gz, scope, rl, node, &params); |
| 529 | } else if (node_datas[node].rhs == 0) { | 529 | } else if (node_datas[node].rhs == 0) { |
| 530 | const params = [_]ast.Node.Index{node_datas[node].lhs}; | 530 | const params = [_]ast.Node.Index{node_datas[node].lhs}; |
| 531 | return builtinCall(mod, scope, rl, node, &params); | 531 | return builtinCall(gz, scope, rl, node, &params); |
| 532 | } else { | 532 | } else { |
| 533 | const params = [_]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; | 533 | const params = [_]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; |
| 534 | return builtinCall(mod, scope, rl, node, &params); | 534 | return builtinCall(gz, scope, rl, node, &params); |
| 535 | } | 535 | } |
| 536 | }, | 536 | }, |
| 537 | .builtin_call, .builtin_call_comma => { | 537 | .builtin_call, .builtin_call_comma => { |
| 538 | const params = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; | 538 | const params = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; |
| 539 | return builtinCall(mod, scope, rl, node, params); | 539 | return builtinCall(gz, scope, rl, node, params); |
| 540 | }, | 540 | }, |
| 541 | | 541 | |
| 542 | .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => { | 542 | .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => { |
| 543 | var params: [1]ast.Node.Index = undefined; | 543 | var params: [1]ast.Node.Index = undefined; |
| 544 | return callExpr(mod, scope, rl, node, tree.callOne(&params, node)); | 544 | return callExpr(gz, scope, rl, node, tree.callOne(&params, node)); |
| 545 | }, | 545 | }, |
| 546 | .call, .call_comma, .async_call, .async_call_comma => { | 546 | .call, .call_comma, .async_call, .async_call_comma => { |
| 547 | return callExpr(mod, scope, rl, node, tree.callFull(node)); | 547 | return callExpr(gz, scope, rl, node, tree.callFull(node)); |
| 548 | }, | 548 | }, |
| 549 | | 549 | |
| 550 | .unreachable_literal => { | 550 | .unreachable_literal => { |
| ... | @@ -557,102 +557,102 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -557,102 +557,102 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 557 | }); | 557 | }); |
| 558 | return zir.Inst.Ref.unreachable_value; | 558 | return zir.Inst.Ref.unreachable_value; |
| 559 | }, | 559 | }, |
| 560 | .@"return" => return ret(mod, scope, node), | 560 | .@"return" => return ret(gz, scope, node), |
| 561 | .field_access => return fieldAccess(mod, scope, rl, node), | 561 | .field_access => return fieldAccess(gz, scope, rl, node), |
| 562 | .float_literal => return floatLiteral(mod, scope, rl, node), | 562 | .float_literal => return floatLiteral(gz, scope, rl, node), |
| 563 | | 563 | |
| 564 | .if_simple => return ifExpr(mod, scope, rl, node, tree.ifSimple(node)), | 564 | .if_simple => return ifExpr(gz, scope, rl, node, tree.ifSimple(node)), |
| 565 | .@"if" => return ifExpr(mod, scope, rl, node, tree.ifFull(node)), | 565 | .@"if" => return ifExpr(gz, scope, rl, node, tree.ifFull(node)), |
| 566 | | 566 | |
| 567 | .while_simple => return whileExpr(mod, scope, rl, node, tree.whileSimple(node)), | 567 | .while_simple => return whileExpr(gz, scope, rl, node, tree.whileSimple(node)), |
| 568 | .while_cont => return whileExpr(mod, scope, rl, node, tree.whileCont(node)), | 568 | .while_cont => return whileExpr(gz, scope, rl, node, tree.whileCont(node)), |
| 569 | .@"while" => return whileExpr(mod, scope, rl, node, tree.whileFull(node)), | 569 | .@"while" => return whileExpr(gz, scope, rl, node, tree.whileFull(node)), |
| 570 | | 570 | |
| 571 | .for_simple => return forExpr(mod, scope, rl, node, tree.forSimple(node)), | 571 | .for_simple => return forExpr(gz, scope, rl, node, tree.forSimple(node)), |
| 572 | .@"for" => return forExpr(mod, scope, rl, node, tree.forFull(node)), | 572 | .@"for" => return forExpr(gz, scope, rl, node, tree.forFull(node)), |
| 573 | | 573 | |
| 574 | .slice_open => { | 574 | .slice_open => { |
| 575 | const lhs = try expr(mod, scope, .ref, node_datas[node].lhs); | 575 | const lhs = try expr(gz, scope, .ref, node_datas[node].lhs); |
| 576 | const start = try expr(mod, scope, .{ .ty = .usize_type }, node_datas[node].rhs); | 576 | const start = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs); |
| 577 | const result = try gz.addPlNode(.slice_start, node, zir.Inst.SliceStart{ | 577 | const result = try gz.addPlNode(.slice_start, node, zir.Inst.SliceStart{ |
| 578 | .lhs = lhs, | 578 | .lhs = lhs, |
| 579 | .start = start, | 579 | .start = start, |
| 580 | }); | 580 | }); |
| 581 | return rvalue(mod, scope, rl, result, node); | 581 | return rvalue(gz, scope, rl, result, node); |
| 582 | }, | 582 | }, |
| 583 | .slice => { | 583 | .slice => { |
| 584 | const lhs = try expr(mod, scope, .ref, node_datas[node].lhs); | 584 | const lhs = try expr(gz, scope, .ref, node_datas[node].lhs); |
| 585 | const extra = tree.extraData(node_datas[node].rhs, ast.Node.Slice); | 585 | const extra = tree.extraData(node_datas[node].rhs, ast.Node.Slice); |
| 586 | const start = try expr(mod, scope, .{ .ty = .usize_type }, extra.start); | 586 | const start = try expr(gz, scope, .{ .ty = .usize_type }, extra.start); |
| 587 | const end = try expr(mod, scope, .{ .ty = .usize_type }, extra.end); | 587 | const end = try expr(gz, scope, .{ .ty = .usize_type }, extra.end); |
| 588 | const result = try gz.addPlNode(.slice_end, node, zir.Inst.SliceEnd{ | 588 | const result = try gz.addPlNode(.slice_end, node, zir.Inst.SliceEnd{ |
| 589 | .lhs = lhs, | 589 | .lhs = lhs, |
| 590 | .start = start, | 590 | .start = start, |
| 591 | .end = end, | 591 | .end = end, |
| 592 | }); | 592 | }); |
| 593 | return rvalue(mod, scope, rl, result, node); | 593 | return rvalue(gz, scope, rl, result, node); |
| 594 | }, | 594 | }, |
| 595 | .slice_sentinel => { | 595 | .slice_sentinel => { |
| 596 | const lhs = try expr(mod, scope, .ref, node_datas[node].lhs); | 596 | const lhs = try expr(gz, scope, .ref, node_datas[node].lhs); |
| 597 | const extra = tree.extraData(node_datas[node].rhs, ast.Node.SliceSentinel); | 597 | const extra = tree.extraData(node_datas[node].rhs, ast.Node.SliceSentinel); |
| 598 | const start = try expr(mod, scope, .{ .ty = .usize_type }, extra.start); | 598 | const start = try expr(gz, scope, .{ .ty = .usize_type }, extra.start); |
| 599 | const end = try expr(mod, scope, .{ .ty = .usize_type }, extra.end); | 599 | const end = try expr(gz, scope, .{ .ty = .usize_type }, extra.end); |
| 600 | const sentinel = try expr(mod, scope, .{ .ty = .usize_type }, extra.sentinel); | 600 | const sentinel = try expr(gz, scope, .{ .ty = .usize_type }, extra.sentinel); |
| 601 | const result = try gz.addPlNode(.slice_sentinel, node, zir.Inst.SliceSentinel{ | 601 | const result = try gz.addPlNode(.slice_sentinel, node, zir.Inst.SliceSentinel{ |
| 602 | .lhs = lhs, | 602 | .lhs = lhs, |
| 603 | .start = start, | 603 | .start = start, |
| 604 | .end = end, | 604 | .end = end, |
| 605 | .sentinel = sentinel, | 605 | .sentinel = sentinel, |
| 606 | }); | 606 | }); |
| 607 | return rvalue(mod, scope, rl, result, node); | 607 | return rvalue(gz, scope, rl, result, node); |
| 608 | }, | 608 | }, |
| 609 | | 609 | |
| 610 | .deref => { | 610 | .deref => { |
| 611 | const lhs = try expr(mod, scope, .none, node_datas[node].lhs); | 611 | const lhs = try expr(gz, scope, .none, node_datas[node].lhs); |
| 612 | const result = try gz.addUnNode(.load, lhs, node); | 612 | const result = try gz.addUnNode(.load, lhs, node); |
| 613 | return rvalue(mod, scope, rl, result, node); | 613 | return rvalue(gz, scope, rl, result, node); |
| 614 | }, | 614 | }, |
| 615 | .address_of => { | 615 | .address_of => { |
| 616 | const result = try expr(mod, scope, .ref, node_datas[node].lhs); | 616 | const result = try expr(gz, scope, .ref, node_datas[node].lhs); |
| 617 | return rvalue(mod, scope, rl, result, node); | 617 | return rvalue(gz, scope, rl, result, node); |
| 618 | }, | 618 | }, |
| 619 | .undefined_literal => return rvalue(mod, scope, rl, .undef, node), | 619 | .undefined_literal => return rvalue(gz, scope, rl, .undef, node), |
| 620 | .true_literal => return rvalue(mod, scope, rl, .bool_true, node), | 620 | .true_literal => return rvalue(gz, scope, rl, .bool_true, node), |
| 621 | .false_literal => return rvalue(mod, scope, rl, .bool_false, node), | 621 | .false_literal => return rvalue(gz, scope, rl, .bool_false, node), |
| 622 | .null_literal => return rvalue(mod, scope, rl, .null_value, node), | 622 | .null_literal => return rvalue(gz, scope, rl, .null_value, node), |
| 623 | .optional_type => { | 623 | .optional_type => { |
| 624 | const operand = try typeExpr(mod, scope, node_datas[node].lhs); | 624 | const operand = try typeExpr(gz, scope, node_datas[node].lhs); |
| 625 | const result = try gz.addUnNode(.optional_type, operand, node); | 625 | const result = try gz.addUnNode(.optional_type, operand, node); |
| 626 | return rvalue(mod, scope, rl, result, node); | 626 | return rvalue(gz, scope, rl, result, node); |
| 627 | }, | 627 | }, |
| 628 | .unwrap_optional => switch (rl) { | 628 | .unwrap_optional => switch (rl) { |
| 629 | .ref => return gz.addUnNode( | 629 | .ref => return gz.addUnNode( |
| 630 | .optional_payload_safe_ptr, | 630 | .optional_payload_safe_ptr, |
| 631 | try expr(mod, scope, .ref, node_datas[node].lhs), | 631 | try expr(gz, scope, .ref, node_datas[node].lhs), |
| 632 | node, | 632 | node, |
| 633 | ), | 633 | ), |
| 634 | else => return rvalue(mod, scope, rl, try gz.addUnNode( | 634 | else => return rvalue(gz, scope, rl, try gz.addUnNode( |
| 635 | .optional_payload_safe, | 635 | .optional_payload_safe, |
| 636 | try expr(mod, scope, .none, node_datas[node].lhs), | 636 | try expr(gz, scope, .none, node_datas[node].lhs), |
| 637 | node, | 637 | node, |
| 638 | ), node), | 638 | ), node), |
| 639 | }, | 639 | }, |
| 640 | .block_two, .block_two_semicolon => { | 640 | .block_two, .block_two_semicolon => { |
| 641 | const statements = [2]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; | 641 | const statements = [2]ast.Node.Index{ node_datas[node].lhs, node_datas[node].rhs }; |
| 642 | if (node_datas[node].lhs == 0) { | 642 | if (node_datas[node].lhs == 0) { |
| 643 | return blockExpr(mod, scope, rl, node, statements[0..0]); | 643 | return blockExpr(gz, scope, rl, node, statements[0..0]); |
| 644 | } else if (node_datas[node].rhs == 0) { | 644 | } else if (node_datas[node].rhs == 0) { |
| 645 | return blockExpr(mod, scope, rl, node, statements[0..1]); | 645 | return blockExpr(gz, scope, rl, node, statements[0..1]); |
| 646 | } else { | 646 | } else { |
| 647 | return blockExpr(mod, scope, rl, node, statements[0..2]); | 647 | return blockExpr(gz, scope, rl, node, statements[0..2]); |
| 648 | } | 648 | } |
| 649 | }, | 649 | }, |
| 650 | .block, .block_semicolon => { | 650 | .block, .block_semicolon => { |
| 651 | const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; | 651 | const statements = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs]; |
| 652 | return blockExpr(mod, scope, rl, node, statements); | 652 | return blockExpr(gz, scope, rl, node, statements); |
| 653 | }, | 653 | }, |
| 654 | .enum_literal => return simpleStrTok(mod, scope, rl, main_tokens[node], node, .enum_literal), | 654 | .enum_literal => return simpleStrTok(gz, scope, rl, main_tokens[node], node, .enum_literal), |
| 655 | .error_value => return simpleStrTok(mod, scope, rl, node_datas[node].rhs, node, .error_value), | 655 | .error_value => return simpleStrTok(gz, scope, rl, node_datas[node].rhs, node, .error_value), |
| 656 | .anyframe_literal => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), | 656 | .anyframe_literal => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), |
| 657 | .anyframe_type => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), | 657 | .anyframe_type => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), |
| 658 | .@"catch" => { | 658 | .@"catch" => { |
| ... | @@ -663,7 +663,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -663,7 +663,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 663 | null; | 663 | null; |
| 664 | switch (rl) { | 664 | switch (rl) { |
| 665 | .ref => return orelseCatchExpr( | 665 | .ref => return orelseCatchExpr( |
| 666 | mod, | 666 | gz, |
| 667 | scope, | 667 | scope, |
| 668 | rl, | 668 | rl, |
| 669 | node, | 669 | node, |
| ... | @@ -675,7 +675,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -675,7 +675,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 675 | payload_token, | 675 | payload_token, |
| 676 | ), | 676 | ), |
| 677 | else => return orelseCatchExpr( | 677 | else => return orelseCatchExpr( |
| 678 | mod, | 678 | gz, |
| 679 | scope, | 679 | scope, |
| 680 | rl, | 680 | rl, |
| 681 | node, | 681 | node, |
| ... | @@ -690,7 +690,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -690,7 +690,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 690 | }, | 690 | }, |
| 691 | .@"orelse" => switch (rl) { | 691 | .@"orelse" => switch (rl) { |
| 692 | .ref => return orelseCatchExpr( | 692 | .ref => return orelseCatchExpr( |
| 693 | mod, | 693 | gz, |
| 694 | scope, | 694 | scope, |
| 695 | rl, | 695 | rl, |
| 696 | node, | 696 | node, |
| ... | @@ -702,7 +702,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -702,7 +702,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 702 | null, | 702 | null, |
| 703 | ), | 703 | ), |
| 704 | else => return orelseCatchExpr( | 704 | else => return orelseCatchExpr( |
| 705 | mod, | 705 | gz, |
| 706 | scope, | 706 | scope, |
| 707 | rl, | 707 | rl, |
| 708 | node, | 708 | node, |
| ... | @@ -715,43 +715,43 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -715,43 +715,43 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 715 | ), | 715 | ), |
| 716 | }, | 716 | }, |
| 717 | | 717 | |
| 718 | .ptr_type_aligned => return ptrType(mod, scope, rl, node, tree.ptrTypeAligned(node)), | 718 | .ptr_type_aligned => return ptrType(gz, scope, rl, node, tree.ptrTypeAligned(node)), |
| 719 | .ptr_type_sentinel => return ptrType(mod, scope, rl, node, tree.ptrTypeSentinel(node)), | 719 | .ptr_type_sentinel => return ptrType(gz, scope, rl, node, tree.ptrTypeSentinel(node)), |
| 720 | .ptr_type => return ptrType(mod, scope, rl, node, tree.ptrType(node)), | 720 | .ptr_type => return ptrType(gz, scope, rl, node, tree.ptrType(node)), |
| 721 | .ptr_type_bit_range => return ptrType(mod, scope, rl, node, tree.ptrTypeBitRange(node)), | 721 | .ptr_type_bit_range => return ptrType(gz, scope, rl, node, tree.ptrTypeBitRange(node)), |
| 722 | | 722 | |
| 723 | .container_decl, | 723 | .container_decl, |
| 724 | .container_decl_trailing, | 724 | .container_decl_trailing, |
| 725 | => return containerDecl(mod, scope, rl, tree.containerDecl(node)), | 725 | => return containerDecl(gz, scope, rl, tree.containerDecl(node)), |
| 726 | .container_decl_two, .container_decl_two_trailing => { | 726 | .container_decl_two, .container_decl_two_trailing => { |
| 727 | var buffer: [2]ast.Node.Index = undefined; | 727 | var buffer: [2]ast.Node.Index = undefined; |
| 728 | return containerDecl(mod, scope, rl, tree.containerDeclTwo(&buffer, node)); | 728 | return containerDecl(gz, scope, rl, tree.containerDeclTwo(&buffer, node)); |
| 729 | }, | 729 | }, |
| 730 | .container_decl_arg, | 730 | .container_decl_arg, |
| 731 | .container_decl_arg_trailing, | 731 | .container_decl_arg_trailing, |
| 732 | => return containerDecl(mod, scope, rl, tree.containerDeclArg(node)), | 732 | => return containerDecl(gz, scope, rl, tree.containerDeclArg(node)), |
| 733 | | 733 | |
| 734 | .tagged_union, | 734 | .tagged_union, |
| 735 | .tagged_union_trailing, | 735 | .tagged_union_trailing, |
| 736 | => return containerDecl(mod, scope, rl, tree.taggedUnion(node)), | 736 | => return containerDecl(gz, scope, rl, tree.taggedUnion(node)), |
| 737 | .tagged_union_two, .tagged_union_two_trailing => { | 737 | .tagged_union_two, .tagged_union_two_trailing => { |
| 738 | var buffer: [2]ast.Node.Index = undefined; | 738 | var buffer: [2]ast.Node.Index = undefined; |
| 739 | return containerDecl(mod, scope, rl, tree.taggedUnionTwo(&buffer, node)); | 739 | return containerDecl(gz, scope, rl, tree.taggedUnionTwo(&buffer, node)); |
| 740 | }, | 740 | }, |
| 741 | .tagged_union_enum_tag, | 741 | .tagged_union_enum_tag, |
| 742 | .tagged_union_enum_tag_trailing, | 742 | .tagged_union_enum_tag_trailing, |
| 743 | => return containerDecl(mod, scope, rl, tree.taggedUnionEnumTag(node)), | 743 | => return containerDecl(gz, scope, rl, tree.taggedUnionEnumTag(node)), |
| 744 | | 744 | |
| 745 | .@"break" => return breakExpr(mod, scope, node), | 745 | .@"break" => return breakExpr(gz, scope, node), |
| 746 | .@"continue" => return continueExpr(mod, scope, node), | 746 | .@"continue" => return continueExpr(gz, scope, node), |
| 747 | .grouped_expression => return expr(mod, scope, rl, node_datas[node].lhs), | 747 | .grouped_expression => return expr(gz, scope, rl, node_datas[node].lhs), |
| 748 | .array_type => return arrayType(mod, scope, rl, node), | 748 | .array_type => return arrayType(gz, scope, rl, node), |
| 749 | .array_type_sentinel => return arrayTypeSentinel(mod, scope, rl, node), | 749 | .array_type_sentinel => return arrayTypeSentinel(gz, scope, rl, node), |
| 750 | .char_literal => return charLiteral(mod, scope, rl, node), | 750 | .char_literal => return charLiteral(gz, scope, rl, node), |
| 751 | .error_set_decl => return errorSetDecl(mod, scope, rl, node), | 751 | .error_set_decl => return errorSetDecl(gz, scope, rl, node), |
| 752 | .array_access => return arrayAccess(mod, scope, rl, node), | 752 | .array_access => return arrayAccess(gz, scope, rl, node), |
| 753 | .@"comptime" => return comptimeExpr(mod, scope, rl, node_datas[node].lhs), | 753 | .@"comptime" => return comptimeExpr(gz, scope, rl, node_datas[node].lhs), |
| 754 | .@"switch", .switch_comma => return switchExpr(mod, scope, rl, node), | 754 | .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node), |
| 755 | | 755 | |
| 756 | .@"nosuspend" => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), | 756 | .@"nosuspend" => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), |
| 757 | .@"suspend" => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), | 757 | .@"suspend" => return mod.failNode(scope, node, "async and related features are not yet supported", .{}), |
| ... | @@ -792,22 +792,20 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In | ... | @@ -792,22 +792,20 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In |
| 792 | } | 792 | } |
| 793 | | 793 | |
| 794 | pub fn comptimeExpr( | 794 | pub fn comptimeExpr( |
| 795 | mod: *Module, | 795 | gz: *GenZir, |
| 796 | parent_scope: *Scope, | 796 | scope: *Scope, |
| 797 | rl: ResultLoc, | 797 | rl: ResultLoc, |
| 798 | node: ast.Node.Index, | 798 | node: ast.Node.Index, |
| 799 | ) InnerError!zir.Inst.Ref { | 799 | ) InnerError!zir.Inst.Ref { |
| 800 | const gz = parent_scope.getGenZir(); | | |
| 801 | | | |
| 802 | const prev_force_comptime = gz.force_comptime; | 800 | const prev_force_comptime = gz.force_comptime; |
| 803 | gz.force_comptime = true; | 801 | gz.force_comptime = true; |
| 804 | const result = try expr(mod, parent_scope, rl, node); | 802 | const result = try expr(gz, scope, rl, node); |
| 805 | gz.force_comptime = prev_force_comptime; | 803 | gz.force_comptime = prev_force_comptime; |
| 806 | return result; | 804 | return result; |
| 807 | } | 805 | } |
| 808 | | 806 | |
| 809 | fn breakExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { | 807 | fn breakExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 810 | const parent_gz = parent_scope.getGenZir(); | 808 | const mod = parent_gz.astgen.mod; |
| 811 | const tree = parent_gz.tree(); | 809 | const tree = parent_gz.tree(); |
| 812 | const node_datas = tree.nodes.items(.data); | 810 | const node_datas = tree.nodes.items(.data); |
| 813 | const break_label = node_datas[node].lhs; | 811 | const break_label = node_datas[node].lhs; |
| ... | @@ -818,7 +816,7 @@ fn breakExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerErro | ... | @@ -818,7 +816,7 @@ fn breakExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerErro |
| 818 | while (true) { | 816 | while (true) { |
| 819 | switch (scope.tag) { | 817 | switch (scope.tag) { |
| 820 | .gen_zir => { | 818 | .gen_zir => { |
| 821 | const block_gz = scope.cast(Scope.GenZir).?; | 819 | const block_gz = scope.cast(GenZir).?; |
| 822 | | 820 | |
| 823 | const block_inst = blk: { | 821 | const block_inst = blk: { |
| 824 | if (break_label != 0) { | 822 | if (break_label != 0) { |
| ... | @@ -841,7 +839,7 @@ fn breakExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerErro | ... | @@ -841,7 +839,7 @@ fn breakExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerErro |
| 841 | } | 839 | } |
| 842 | block_gz.break_count += 1; | 840 | block_gz.break_count += 1; |
| 843 | const prev_rvalue_rl_count = block_gz.rvalue_rl_count; | 841 | const prev_rvalue_rl_count = block_gz.rvalue_rl_count; |
| 844 | const operand = try expr(mod, parent_scope, block_gz.break_result_loc, rhs); | 842 | const operand = try expr(parent_gz, parent_scope, block_gz.break_result_loc, rhs); |
| 845 | const have_store_to_block = block_gz.rvalue_rl_count != prev_rvalue_rl_count; | 843 | const have_store_to_block = block_gz.rvalue_rl_count != prev_rvalue_rl_count; |
| 846 | | 844 | |
| 847 | const br = try parent_gz.addBreak(.@"break", block_inst, operand); | 845 | const br = try parent_gz.addBreak(.@"break", block_inst, operand); |
| ... | @@ -872,8 +870,8 @@ fn breakExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerErro | ... | @@ -872,8 +870,8 @@ fn breakExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerErro |
| 872 | } | 870 | } |
| 873 | } | 871 | } |
| 874 | | 872 | |
| 875 | fn continueExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { | 873 | fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 876 | const parent_gz = parent_scope.getGenZir(); | 874 | const mod = parent_gz.astgen.mod; |
| 877 | const tree = parent_gz.tree(); | 875 | const tree = parent_gz.tree(); |
| 878 | const node_datas = tree.nodes.items(.data); | 876 | const node_datas = tree.nodes.items(.data); |
| 879 | const break_label = node_datas[node].lhs; | 877 | const break_label = node_datas[node].lhs; |
| ... | @@ -883,7 +881,7 @@ fn continueExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerE | ... | @@ -883,7 +881,7 @@ fn continueExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerE |
| 883 | while (true) { | 881 | while (true) { |
| 884 | switch (scope.tag) { | 882 | switch (scope.tag) { |
| 885 | .gen_zir => { | 883 | .gen_zir => { |
| 886 | const gen_zir = scope.cast(Scope.GenZir).?; | 884 | const gen_zir = scope.cast(GenZir).?; |
| 887 | const continue_block = gen_zir.continue_block; | 885 | const continue_block = gen_zir.continue_block; |
| 888 | if (continue_block == 0) { | 886 | if (continue_block == 0) { |
| 889 | scope = gen_zir.parent; | 887 | scope = gen_zir.parent; |
| ... | @@ -918,7 +916,7 @@ fn continueExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerE | ... | @@ -918,7 +916,7 @@ fn continueExpr(mod: *Module, parent_scope: *Scope, node: ast.Node.Index) InnerE |
| 918 | } | 916 | } |
| 919 | | 917 | |
| 920 | pub fn blockExpr( | 918 | pub fn blockExpr( |
| 921 | mod: *Module, | 919 | gz: *GenZir, |
| 922 | scope: *Scope, | 920 | scope: *Scope, |
| 923 | rl: ResultLoc, | 921 | rl: ResultLoc, |
| 924 | block_node: ast.Node.Index, | 922 | block_node: ast.Node.Index, |
| ... | @@ -935,11 +933,11 @@ pub fn blockExpr( | ... | @@ -935,11 +933,11 @@ pub fn blockExpr( |
| 935 | if (token_tags[lbrace - 1] == .colon and | 933 | if (token_tags[lbrace - 1] == .colon and |
| 936 | token_tags[lbrace - 2] == .identifier) | 934 | token_tags[lbrace - 2] == .identifier) |
| 937 | { | 935 | { |
| 938 | return labeledBlockExpr(mod, scope, rl, block_node, statements, .block); | 936 | return labeledBlockExpr(gz, scope, rl, block_node, statements, .block); |
| 939 | } | 937 | } |
| 940 | | 938 | |
| 941 | try blockExprStmts(mod, scope, block_node, statements); | 939 | try blockExprStmts(gz, scope, block_node, statements); |
| 942 | return rvalue(mod, scope, rl, .void_value, block_node); | 940 | return rvalue(gz, scope, rl, .void_value, block_node); |
| 943 | } | 941 | } |
| 944 | | 942 | |
| 945 | fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIndex) !void { | 943 | fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIndex) !void { |
| ... | @@ -948,7 +946,7 @@ fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIn | ... | @@ -948,7 +946,7 @@ fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIn |
| 948 | while (true) { | 946 | while (true) { |
| 949 | switch (scope.tag) { | 947 | switch (scope.tag) { |
| 950 | .gen_zir => { | 948 | .gen_zir => { |
| 951 | const gen_zir = scope.cast(Scope.GenZir).?; | 949 | const gen_zir = scope.cast(GenZir).?; |
| 952 | if (gen_zir.label) |prev_label| { | 950 | if (gen_zir.label) |prev_label| { |
| 953 | if (try tokenIdentEql(mod, parent_scope, label, prev_label.token)) { | 951 | if (try tokenIdentEql(mod, parent_scope, label, prev_label.token)) { |
| 954 | const tree = parent_scope.tree(); | 952 | const tree = parent_scope.tree(); |
| ... | @@ -985,7 +983,7 @@ fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIn | ... | @@ -985,7 +983,7 @@ fn checkLabelRedefinition(mod: *Module, parent_scope: *Scope, label: ast.TokenIn |
| 985 | } | 983 | } |
| 986 | | 984 | |
| 987 | fn labeledBlockExpr( | 985 | fn labeledBlockExpr( |
| 988 | mod: *Module, | 986 | gz: *GenZir, |
| 989 | parent_scope: *Scope, | 987 | parent_scope: *Scope, |
| 990 | rl: ResultLoc, | 988 | rl: ResultLoc, |
| 991 | block_node: ast.Node.Index, | 989 | block_node: ast.Node.Index, |
| ... | @@ -997,6 +995,7 @@ fn labeledBlockExpr( | ... | @@ -997,6 +995,7 @@ fn labeledBlockExpr( |
| 997 | | 995 | |
| 998 | assert(zir_tag == .block); | 996 | assert(zir_tag == .block); |
| 999 | | 997 | |
| | 998 | const mod = gz.astgen.mod; |
| 1000 | const tree = parent_scope.tree(); | 999 | const tree = parent_scope.tree(); |
| 1001 | const main_tokens = tree.nodes.items(.main_token); | 1000 | const main_tokens = tree.nodes.items(.main_token); |
| 1002 | const token_tags = tree.tokens.items(.tag); | 1001 | const token_tags = tree.tokens.items(.tag); |
| ... | @@ -1009,17 +1008,16 @@ fn labeledBlockExpr( | ... | @@ -1009,17 +1008,16 @@ fn labeledBlockExpr( |
| 1009 | | 1008 | |
| 1010 | // Reserve the Block ZIR instruction index so that we can put it into the GenZir struct | 1009 | // Reserve the Block ZIR instruction index so that we can put it into the GenZir struct |
| 1011 | // so that break statements can reference it. | 1010 | // so that break statements can reference it. |
| 1012 | const gz = parent_scope.getGenZir(); | | |
| 1013 | const block_inst = try gz.addBlock(zir_tag, block_node); | 1011 | const block_inst = try gz.addBlock(zir_tag, block_node); |
| 1014 | try gz.instructions.append(mod.gpa, block_inst); | 1012 | try gz.instructions.append(mod.gpa, block_inst); |
| 1015 | | 1013 | |
| 1016 | var block_scope: Scope.GenZir = .{ | 1014 | var block_scope: GenZir = .{ |
| 1017 | .parent = parent_scope, | 1015 | .parent = parent_scope, |
| 1018 | .astgen = gz.astgen, | 1016 | .astgen = gz.astgen, |
| 1019 | .force_comptime = gz.force_comptime, | 1017 | .force_comptime = gz.force_comptime, |
| 1020 | .instructions = .{}, | 1018 | .instructions = .{}, |
| 1021 | // TODO @as here is working around a stage1 miscompilation bug :( | 1019 | // TODO @as here is working around a stage1 miscompilation bug :( |
| 1022 | .label = @as(?Scope.GenZir.Label, Scope.GenZir.Label{ | 1020 | .label = @as(?GenZir.Label, GenZir.Label{ |
| 1023 | .token = label_token, | 1021 | .token = label_token, |
| 1024 | .block_inst = block_inst, | 1022 | .block_inst = block_inst, |
| 1025 | }), | 1023 | }), |
| ... | @@ -1029,7 +1027,7 @@ fn labeledBlockExpr( | ... | @@ -1029,7 +1027,7 @@ fn labeledBlockExpr( |
| 1029 | defer block_scope.labeled_breaks.deinit(mod.gpa); | 1027 | defer block_scope.labeled_breaks.deinit(mod.gpa); |
| 1030 | defer block_scope.labeled_store_to_block_ptr_list.deinit(mod.gpa); | 1028 | defer block_scope.labeled_store_to_block_ptr_list.deinit(mod.gpa); |
| 1031 | | 1029 | |
| 1032 | try blockExprStmts(mod, &block_scope.base, block_node, statements); | 1030 | try blockExprStmts(&block_scope, &block_scope.base, block_node, statements); |
| 1033 | | 1031 | |
| 1034 | if (!block_scope.label.?.used) { | 1032 | if (!block_scope.label.?.used) { |
| 1035 | return mod.failTok(parent_scope, label_token, "unused block label", .{}); | 1033 | return mod.failTok(parent_scope, label_token, "unused block label", .{}); |
| ... | @@ -1064,14 +1062,14 @@ fn labeledBlockExpr( | ... | @@ -1064,14 +1062,14 @@ fn labeledBlockExpr( |
| 1064 | const block_ref = gz.astgen.indexToRef(block_inst); | 1062 | const block_ref = gz.astgen.indexToRef(block_inst); |
| 1065 | switch (rl) { | 1063 | switch (rl) { |
| 1066 | .ref => return block_ref, | 1064 | .ref => return block_ref, |
| 1067 | else => return rvalue(mod, parent_scope, rl, block_ref, block_node), | 1065 | else => return rvalue(gz, parent_scope, rl, block_ref, block_node), |
| 1068 | } | 1066 | } |
| 1069 | }, | 1067 | }, |
| 1070 | } | 1068 | } |
| 1071 | } | 1069 | } |
| 1072 | | 1070 | |
| 1073 | fn blockExprStmts( | 1071 | fn blockExprStmts( |
| 1074 | mod: *Module, | 1072 | gz: *GenZir, |
| 1075 | parent_scope: *Scope, | 1073 | parent_scope: *Scope, |
| 1076 | node: ast.Node.Index, | 1074 | node: ast.Node.Index, |
| 1077 | statements: []const ast.Node.Index, | 1075 | statements: []const ast.Node.Index, |
| ... | @@ -1080,41 +1078,39 @@ fn blockExprStmts( | ... | @@ -1080,41 +1078,39 @@ fn blockExprStmts( |
| 1080 | const main_tokens = tree.nodes.items(.main_token); | 1078 | const main_tokens = tree.nodes.items(.main_token); |
| 1081 | const node_tags = tree.nodes.items(.tag); | 1079 | const node_tags = tree.nodes.items(.tag); |
| 1082 | | 1080 | |
| 1083 | var block_arena = std.heap.ArenaAllocator.init(mod.gpa); | 1081 | var block_arena = std.heap.ArenaAllocator.init(gz.astgen.mod.gpa); |
| 1084 | defer block_arena.deinit(); | 1082 | defer block_arena.deinit(); |
| 1085 | | 1083 | |
| 1086 | const gz = parent_scope.getGenZir(); | | |
| 1087 | | | |
| 1088 | var scope = parent_scope; | 1084 | var scope = parent_scope; |
| 1089 | for (statements) |statement| { | 1085 | for (statements) |statement| { |
| 1090 | if (!gz.force_comptime) { | 1086 | if (!gz.force_comptime) { |
| 1091 | _ = try gz.addNode(.dbg_stmt_node, statement); | 1087 | _ = try gz.addNode(.dbg_stmt_node, statement); |
| 1092 | } | 1088 | } |
| 1093 | switch (node_tags[statement]) { | 1089 | switch (node_tags[statement]) { |
| 1094 | .global_var_decl => scope = try varDecl(mod, scope, statement, &block_arena.allocator, tree.globalVarDecl(statement)), | 1090 | .global_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.globalVarDecl(statement)), |
| 1095 | .local_var_decl => scope = try varDecl(mod, scope, statement, &block_arena.allocator, tree.localVarDecl(statement)), | 1091 | .local_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.localVarDecl(statement)), |
| 1096 | .simple_var_decl => scope = try varDecl(mod, scope, statement, &block_arena.allocator, tree.simpleVarDecl(statement)), | 1092 | .simple_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.simpleVarDecl(statement)), |
| 1097 | .aligned_var_decl => scope = try varDecl(mod, scope, statement, &block_arena.allocator, tree.alignedVarDecl(statement)), | 1093 | .aligned_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.alignedVarDecl(statement)), |
| 1098 | | 1094 | |
| 1099 | .assign => try assign(mod, scope, statement), | 1095 | .assign => try assign(gz, scope, statement), |
| 1100 | .assign_bit_and => try assignOp(mod, scope, statement, .bit_and), | 1096 | .assign_bit_and => try assignOp(gz, scope, statement, .bit_and), |
| 1101 | .assign_bit_or => try assignOp(mod, scope, statement, .bit_or), | 1097 | .assign_bit_or => try assignOp(gz, scope, statement, .bit_or), |
| 1102 | .assign_bit_shift_left => try assignOp(mod, scope, statement, .shl), | 1098 | .assign_bit_shift_left => try assignOp(gz, scope, statement, .shl), |
| 1103 | .assign_bit_shift_right => try assignOp(mod, scope, statement, .shr), | 1099 | .assign_bit_shift_right => try assignOp(gz, scope, statement, .shr), |
| 1104 | .assign_bit_xor => try assignOp(mod, scope, statement, .xor), | 1100 | .assign_bit_xor => try assignOp(gz, scope, statement, .xor), |
| 1105 | .assign_div => try assignOp(mod, scope, statement, .div), | 1101 | .assign_div => try assignOp(gz, scope, statement, .div), |
| 1106 | .assign_sub => try assignOp(mod, scope, statement, .sub), | 1102 | .assign_sub => try assignOp(gz, scope, statement, .sub), |
| 1107 | .assign_sub_wrap => try assignOp(mod, scope, statement, .subwrap), | 1103 | .assign_sub_wrap => try assignOp(gz, scope, statement, .subwrap), |
| 1108 | .assign_mod => try assignOp(mod, scope, statement, .mod_rem), | 1104 | .assign_mod => try assignOp(gz, scope, statement, .mod_rem), |
| 1109 | .assign_add => try assignOp(mod, scope, statement, .add), | 1105 | .assign_add => try assignOp(gz, scope, statement, .add), |
| 1110 | .assign_add_wrap => try assignOp(mod, scope, statement, .addwrap), | 1106 | .assign_add_wrap => try assignOp(gz, scope, statement, .addwrap), |
| 1111 | .assign_mul => try assignOp(mod, scope, statement, .mul), | 1107 | .assign_mul => try assignOp(gz, scope, statement, .mul), |
| 1112 | .assign_mul_wrap => try assignOp(mod, scope, statement, .mulwrap), | 1108 | .assign_mul_wrap => try assignOp(gz, scope, statement, .mulwrap), |
| 1113 | | 1109 | |
| 1114 | else => { | 1110 | else => { |
| 1115 | // We need to emit an error if the result is not `noreturn` or `void`, but | 1111 | // We need to emit an error if the result is not `noreturn` or `void`, but |
| 1116 | // we want to avoid adding the ZIR instruction if possible for performance. | 1112 | // we want to avoid adding the ZIR instruction if possible for performance. |
| 1117 | const maybe_unused_result = try expr(mod, scope, .none, statement); | 1113 | const maybe_unused_result = try expr(gz, scope, .none, statement); |
| 1118 | const elide_check = if (gz.astgen.refToIndex(maybe_unused_result)) |inst| b: { | 1114 | const elide_check = if (gz.astgen.refToIndex(maybe_unused_result)) |inst| b: { |
| 1119 | // Note that this array becomes invalid after appending more items to it | 1115 | // Note that this array becomes invalid after appending more items to it |
| 1120 | // in the above while loop. | 1116 | // in the above while loop. |
| ... | @@ -1293,19 +1289,19 @@ fn blockExprStmts( | ... | @@ -1293,19 +1289,19 @@ fn blockExprStmts( |
| 1293 | } | 1289 | } |
| 1294 | | 1290 | |
| 1295 | fn varDecl( | 1291 | fn varDecl( |
| 1296 | mod: *Module, | 1292 | gz: *GenZir, |
| 1297 | scope: *Scope, | 1293 | scope: *Scope, |
| 1298 | node: ast.Node.Index, | 1294 | node: ast.Node.Index, |
| 1299 | block_arena: *Allocator, | 1295 | block_arena: *Allocator, |
| 1300 | var_decl: ast.full.VarDecl, | 1296 | var_decl: ast.full.VarDecl, |
| 1301 | ) InnerError!*Scope { | 1297 | ) InnerError!*Scope { |
| | 1298 | const mod = gz.astgen.mod; |
| 1302 | if (var_decl.comptime_token) |comptime_token| { | 1299 | if (var_decl.comptime_token) |comptime_token| { |
| 1303 | return mod.failTok(scope, comptime_token, "TODO implement comptime locals", .{}); | 1300 | return mod.failTok(scope, comptime_token, "TODO implement comptime locals", .{}); |
| 1304 | } | 1301 | } |
| 1305 | if (var_decl.ast.align_node != 0) { | 1302 | if (var_decl.ast.align_node != 0) { |
| 1306 | return mod.failNode(scope, var_decl.ast.align_node, "TODO implement alignment on locals", .{}); | 1303 | return mod.failNode(scope, var_decl.ast.align_node, "TODO implement alignment on locals", .{}); |
| 1307 | } | 1304 | } |
| 1308 | const gz = scope.getGenZir(); | | |
| 1309 | const astgen = gz.astgen; | 1305 | const astgen = gz.astgen; |
| 1310 | const tree = scope.tree(); | 1306 | const tree = scope.tree(); |
| 1311 | const token_tags = tree.tokens.items(.tag); | 1307 | const token_tags = tree.tokens.items(.tag); |
| ... | @@ -1348,7 +1344,7 @@ fn varDecl( | ... | @@ -1348,7 +1344,7 @@ fn varDecl( |
| 1348 | } | 1344 | } |
| 1349 | s = local_ptr.parent; | 1345 | s = local_ptr.parent; |
| 1350 | }, | 1346 | }, |
| 1351 | .gen_zir => s = s.cast(Scope.GenZir).?.parent, | 1347 | .gen_zir => s = s.cast(GenZir).?.parent, |
| 1352 | else => break, | 1348 | else => break, |
| 1353 | }; | 1349 | }; |
| 1354 | } | 1350 | } |
| ... | @@ -1369,9 +1365,9 @@ fn varDecl( | ... | @@ -1369,9 +1365,9 @@ fn varDecl( |
| 1369 | // the variable, no memory location needed. | 1365 | // the variable, no memory location needed. |
| 1370 | if (!nodeMayNeedMemoryLocation(scope, var_decl.ast.init_node)) { | 1366 | if (!nodeMayNeedMemoryLocation(scope, var_decl.ast.init_node)) { |
| 1371 | const result_loc: ResultLoc = if (var_decl.ast.type_node != 0) .{ | 1367 | const result_loc: ResultLoc = if (var_decl.ast.type_node != 0) .{ |
| 1372 | .ty = try typeExpr(mod, scope, var_decl.ast.type_node), | 1368 | .ty = try typeExpr(gz, scope, var_decl.ast.type_node), |
| 1373 | } else .none; | 1369 | } else .none; |
| 1374 | const init_inst = try expr(mod, scope, result_loc, var_decl.ast.init_node); | 1370 | const init_inst = try expr(gz, scope, result_loc, var_decl.ast.init_node); |
| 1375 | const sub_scope = try block_arena.create(Scope.LocalVal); | 1371 | const sub_scope = try block_arena.create(Scope.LocalVal); |
| 1376 | sub_scope.* = .{ | 1372 | sub_scope.* = .{ |
| 1377 | .parent = scope, | 1373 | .parent = scope, |
| ... | @@ -1385,7 +1381,7 @@ fn varDecl( | ... | @@ -1385,7 +1381,7 @@ fn varDecl( |
| 1385 | | 1381 | |
| 1386 | // Detect whether the initialization expression actually uses the | 1382 | // Detect whether the initialization expression actually uses the |
| 1387 | // result location pointer. | 1383 | // result location pointer. |
| 1388 | var init_scope: Scope.GenZir = .{ | 1384 | var init_scope: GenZir = .{ |
| 1389 | .parent = scope, | 1385 | .parent = scope, |
| 1390 | .force_comptime = gz.force_comptime, | 1386 | .force_comptime = gz.force_comptime, |
| 1391 | .astgen = astgen, | 1387 | .astgen = astgen, |
| ... | @@ -1395,7 +1391,7 @@ fn varDecl( | ... | @@ -1395,7 +1391,7 @@ fn varDecl( |
| 1395 | var resolve_inferred_alloc: zir.Inst.Ref = .none; | 1391 | var resolve_inferred_alloc: zir.Inst.Ref = .none; |
| 1396 | var opt_type_inst: zir.Inst.Ref = .none; | 1392 | var opt_type_inst: zir.Inst.Ref = .none; |
| 1397 | if (var_decl.ast.type_node != 0) { | 1393 | if (var_decl.ast.type_node != 0) { |
| 1398 | const type_inst = try typeExpr(mod, &init_scope.base, var_decl.ast.type_node); | 1394 | const type_inst = try typeExpr(gz, &init_scope.base, var_decl.ast.type_node); |
| 1399 | opt_type_inst = type_inst; | 1395 | opt_type_inst = type_inst; |
| 1400 | init_scope.rl_ptr = try init_scope.addUnNode(.alloc, type_inst, node); | 1396 | init_scope.rl_ptr = try init_scope.addUnNode(.alloc, type_inst, node); |
| 1401 | } else { | 1397 | } else { |
| ... | @@ -1404,7 +1400,7 @@ fn varDecl( | ... | @@ -1404,7 +1400,7 @@ fn varDecl( |
| 1404 | init_scope.rl_ptr = alloc; | 1400 | init_scope.rl_ptr = alloc; |
| 1405 | } | 1401 | } |
| 1406 | const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope }; | 1402 | const init_result_loc: ResultLoc = .{ .block_ptr = &init_scope }; |
| 1407 | const init_inst = try expr(mod, &init_scope.base, init_result_loc, var_decl.ast.init_node); | 1403 | const init_inst = try expr(&init_scope, &init_scope.base, init_result_loc, var_decl.ast.init_node); |
| 1408 | const zir_tags = astgen.instructions.items(.tag); | 1404 | const zir_tags = astgen.instructions.items(.tag); |
| 1409 | const zir_datas = astgen.instructions.items(.data); | 1405 | const zir_datas = astgen.instructions.items(.data); |
| 1410 | | 1406 | |
| ... | @@ -1476,7 +1472,7 @@ fn varDecl( | ... | @@ -1476,7 +1472,7 @@ fn varDecl( |
| 1476 | result_loc: ResultLoc, | 1472 | result_loc: ResultLoc, |
| 1477 | alloc: zir.Inst.Ref, | 1473 | alloc: zir.Inst.Ref, |
| 1478 | } = if (var_decl.ast.type_node != 0) a: { | 1474 | } = if (var_decl.ast.type_node != 0) a: { |
| 1479 | const type_inst = try typeExpr(mod, scope, var_decl.ast.type_node); | 1475 | const type_inst = try typeExpr(gz, scope, var_decl.ast.type_node); |
| 1480 | | 1476 | |
| 1481 | const alloc = try gz.addUnNode(.alloc_mut, type_inst, node); | 1477 | const alloc = try gz.addUnNode(.alloc_mut, type_inst, node); |
| 1482 | break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; | 1478 | break :a .{ .alloc = alloc, .result_loc = .{ .ptr = alloc } }; |
| ... | @@ -1485,7 +1481,7 @@ fn varDecl( | ... | @@ -1485,7 +1481,7 @@ fn varDecl( |
| 1485 | resolve_inferred_alloc = alloc; | 1481 | resolve_inferred_alloc = alloc; |
| 1486 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; | 1482 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; |
| 1487 | }; | 1483 | }; |
| 1488 | const init_inst = try expr(mod, scope, var_data.result_loc, var_decl.ast.init_node); | 1484 | const init_inst = try expr(gz, scope, var_data.result_loc, var_decl.ast.init_node); |
| 1489 | if (resolve_inferred_alloc != .none) { | 1485 | if (resolve_inferred_alloc != .none) { |
| 1490 | _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); | 1486 | _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); |
| 1491 | } | 1487 | } |
| ... | @@ -1503,7 +1499,7 @@ fn varDecl( | ... | @@ -1503,7 +1499,7 @@ fn varDecl( |
| 1503 | } | 1499 | } |
| 1504 | } | 1500 | } |
| 1505 | | 1501 | |
| 1506 | fn assign(mod: *Module, scope: *Scope, infix_node: ast.Node.Index) InnerError!void { | 1502 | fn assign(gz: *GenZir, scope: *Scope, infix_node: ast.Node.Index) InnerError!void { |
| 1507 | const tree = scope.tree(); | 1503 | const tree = scope.tree(); |
| 1508 | const node_datas = tree.nodes.items(.data); | 1504 | const node_datas = tree.nodes.items(.data); |
| 1509 | const main_tokens = tree.nodes.items(.main_token); | 1505 | const main_tokens = tree.nodes.items(.main_token); |
| ... | @@ -1515,28 +1511,27 @@ fn assign(mod: *Module, scope: *Scope, infix_node: ast.Node.Index) InnerError!vo | ... | @@ -1515,28 +1511,27 @@ fn assign(mod: *Module, scope: *Scope, infix_node: ast.Node.Index) InnerError!vo |
| 1515 | // This intentionally does not support `@"_"` syntax. | 1511 | // This intentionally does not support `@"_"` syntax. |
| 1516 | const ident_name = tree.tokenSlice(main_tokens[lhs]); | 1512 | const ident_name = tree.tokenSlice(main_tokens[lhs]); |
| 1517 | if (mem.eql(u8, ident_name, "_")) { | 1513 | if (mem.eql(u8, ident_name, "_")) { |
| 1518 | _ = try expr(mod, scope, .discard, rhs); | 1514 | _ = try expr(gz, scope, .discard, rhs); |
| 1519 | return; | 1515 | return; |
| 1520 | } | 1516 | } |
| 1521 | } | 1517 | } |
| 1522 | const lvalue = try lvalExpr(mod, scope, lhs); | 1518 | const lvalue = try lvalExpr(gz, scope, lhs); |
| 1523 | _ = try expr(mod, scope, .{ .ptr = lvalue }, rhs); | 1519 | _ = try expr(gz, scope, .{ .ptr = lvalue }, rhs); |
| 1524 | } | 1520 | } |
| 1525 | | 1521 | |
| 1526 | fn assignOp( | 1522 | fn assignOp( |
| 1527 | mod: *Module, | 1523 | gz: *GenZir, |
| 1528 | scope: *Scope, | 1524 | scope: *Scope, |
| 1529 | infix_node: ast.Node.Index, | 1525 | infix_node: ast.Node.Index, |
| 1530 | op_inst_tag: zir.Inst.Tag, | 1526 | op_inst_tag: zir.Inst.Tag, |
| 1531 | ) InnerError!void { | 1527 | ) InnerError!void { |
| 1532 | const tree = scope.tree(); | 1528 | const tree = scope.tree(); |
| 1533 | const node_datas = tree.nodes.items(.data); | 1529 | const node_datas = tree.nodes.items(.data); |
| 1534 | const gz = scope.getGenZir(); | | |
| 1535 | | 1530 | |
| 1536 | const lhs_ptr = try lvalExpr(mod, scope, node_datas[infix_node].lhs); | 1531 | const lhs_ptr = try lvalExpr(gz, scope, node_datas[infix_node].lhs); |
| 1537 | const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node); | 1532 | const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node); |
| 1538 | const lhs_type = try gz.addUnTok(.typeof, lhs, infix_node); | 1533 | const lhs_type = try gz.addUnTok(.typeof, lhs, infix_node); |
| 1539 | const rhs = try expr(mod, scope, .{ .ty = lhs_type }, node_datas[infix_node].rhs); | 1534 | const rhs = try expr(gz, scope, .{ .ty = lhs_type }, node_datas[infix_node].rhs); |
| 1540 | | 1535 | |
| 1541 | const result = try gz.addPlNode(op_inst_tag, infix_node, zir.Inst.Bin{ | 1536 | const result = try gz.addPlNode(op_inst_tag, infix_node, zir.Inst.Bin{ |
| 1542 | .lhs = lhs, | 1537 | .lhs = lhs, |
| ... | @@ -1545,28 +1540,26 @@ fn assignOp( | ... | @@ -1545,28 +1540,26 @@ fn assignOp( |
| 1545 | _ = try gz.addBin(.store, lhs_ptr, result); | 1540 | _ = try gz.addBin(.store, lhs_ptr, result); |
| 1546 | } | 1541 | } |
| 1547 | | 1542 | |
| 1548 | fn boolNot(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { | 1543 | fn boolNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 1549 | const tree = scope.tree(); | 1544 | const tree = scope.tree(); |
| 1550 | const node_datas = tree.nodes.items(.data); | 1545 | const node_datas = tree.nodes.items(.data); |
| 1551 | | 1546 | |
| 1552 | const operand = try expr(mod, scope, .{ .ty = .bool_type }, node_datas[node].lhs); | 1547 | const operand = try expr(gz, scope, .{ .ty = .bool_type }, node_datas[node].lhs); |
| 1553 | const gz = scope.getGenZir(); | | |
| 1554 | const result = try gz.addUnNode(.bool_not, operand, node); | 1548 | const result = try gz.addUnNode(.bool_not, operand, node); |
| 1555 | return rvalue(mod, scope, rl, result, node); | 1549 | return rvalue(gz, scope, rl, result, node); |
| 1556 | } | 1550 | } |
| 1557 | | 1551 | |
| 1558 | fn bitNot(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { | 1552 | fn bitNot(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 1559 | const tree = scope.tree(); | 1553 | const tree = scope.tree(); |
| 1560 | const node_datas = tree.nodes.items(.data); | 1554 | const node_datas = tree.nodes.items(.data); |
| 1561 | | 1555 | |
| 1562 | const gz = scope.getGenZir(); | 1556 | const operand = try expr(gz, scope, .none, node_datas[node].lhs); |
| 1563 | const operand = try expr(mod, scope, .none, node_datas[node].lhs); | | |
| 1564 | const result = try gz.addUnNode(.bit_not, operand, node); | 1557 | const result = try gz.addUnNode(.bit_not, operand, node); |
| 1565 | return rvalue(mod, scope, rl, result, node); | 1558 | return rvalue(gz, scope, rl, result, node); |
| 1566 | } | 1559 | } |
| 1567 | | 1560 | |
| 1568 | fn negation( | 1561 | fn negation( |
| 1569 | mod: *Module, | 1562 | gz: *GenZir, |
| 1570 | scope: *Scope, | 1563 | scope: *Scope, |
| 1571 | rl: ResultLoc, | 1564 | rl: ResultLoc, |
| 1572 | node: ast.Node.Index, | 1565 | node: ast.Node.Index, |
| ... | @@ -1575,23 +1568,21 @@ fn negation( | ... | @@ -1575,23 +1568,21 @@ fn negation( |
| 1575 | const tree = scope.tree(); | 1568 | const tree = scope.tree(); |
| 1576 | const node_datas = tree.nodes.items(.data); | 1569 | const node_datas = tree.nodes.items(.data); |
| 1577 | | 1570 | |
| 1578 | const gz = scope.getGenZir(); | 1571 | const operand = try expr(gz, scope, .none, node_datas[node].lhs); |
| 1579 | const operand = try expr(mod, scope, .none, node_datas[node].lhs); | | |
| 1580 | const result = try gz.addUnNode(tag, operand, node); | 1572 | const result = try gz.addUnNode(tag, operand, node); |
| 1581 | return rvalue(mod, scope, rl, result, node); | 1573 | return rvalue(gz, scope, rl, result, node); |
| 1582 | } | 1574 | } |
| 1583 | | 1575 | |
| 1584 | fn ptrType( | 1576 | fn ptrType( |
| 1585 | mod: *Module, | 1577 | gz: *GenZir, |
| 1586 | scope: *Scope, | 1578 | scope: *Scope, |
| 1587 | rl: ResultLoc, | 1579 | rl: ResultLoc, |
| 1588 | node: ast.Node.Index, | 1580 | node: ast.Node.Index, |
| 1589 | ptr_info: ast.full.PtrType, | 1581 | ptr_info: ast.full.PtrType, |
| 1590 | ) InnerError!zir.Inst.Ref { | 1582 | ) InnerError!zir.Inst.Ref { |
| 1591 | const tree = scope.tree(); | 1583 | const tree = scope.tree(); |
| 1592 | const gz = scope.getGenZir(); | | |
| 1593 | | 1584 | |
| 1594 | const elem_type = try typeExpr(mod, scope, ptr_info.ast.child_type); | 1585 | const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type); |
| 1595 | | 1586 | |
| 1596 | const simple = ptr_info.ast.align_node == 0 and | 1587 | const simple = ptr_info.ast.align_node == 0 and |
| 1597 | ptr_info.ast.sentinel == 0 and | 1588 | ptr_info.ast.sentinel == 0 and |
| ... | @@ -1607,7 +1598,7 @@ fn ptrType( | ... | @@ -1607,7 +1598,7 @@ fn ptrType( |
| 1607 | .elem_type = elem_type, | 1598 | .elem_type = elem_type, |
| 1608 | }, | 1599 | }, |
| 1609 | } }); | 1600 | } }); |
| 1610 | return rvalue(mod, scope, rl, result, node); | 1601 | return rvalue(gz, scope, rl, result, node); |
| 1611 | } | 1602 | } |
| 1612 | | 1603 | |
| 1613 | var sentinel_ref: zir.Inst.Ref = .none; | 1604 | var sentinel_ref: zir.Inst.Ref = .none; |
| ... | @@ -1617,17 +1608,17 @@ fn ptrType( | ... | @@ -1617,17 +1608,17 @@ fn ptrType( |
| 1617 | var trailing_count: u32 = 0; | 1608 | var trailing_count: u32 = 0; |
| 1618 | | 1609 | |
| 1619 | if (ptr_info.ast.sentinel != 0) { | 1610 | if (ptr_info.ast.sentinel != 0) { |
| 1620 | sentinel_ref = try expr(mod, scope, .{ .ty = elem_type }, ptr_info.ast.sentinel); | 1611 | sentinel_ref = try expr(gz, scope, .{ .ty = elem_type }, ptr_info.ast.sentinel); |
| 1621 | trailing_count += 1; | 1612 | trailing_count += 1; |
| 1622 | } | 1613 | } |
| 1623 | if (ptr_info.ast.align_node != 0) { | 1614 | if (ptr_info.ast.align_node != 0) { |
| 1624 | align_ref = try expr(mod, scope, .none, ptr_info.ast.align_node); | 1615 | align_ref = try expr(gz, scope, .none, ptr_info.ast.align_node); |
| 1625 | trailing_count += 1; | 1616 | trailing_count += 1; |
| 1626 | } | 1617 | } |
| 1627 | if (ptr_info.ast.bit_range_start != 0) { | 1618 | if (ptr_info.ast.bit_range_start != 0) { |
| 1628 | assert(ptr_info.ast.bit_range_end != 0); | 1619 | assert(ptr_info.ast.bit_range_end != 0); |
| 1629 | bit_start_ref = try expr(mod, scope, .none, ptr_info.ast.bit_range_start); | 1620 | bit_start_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_start); |
| 1630 | bit_end_ref = try expr(mod, scope, .none, ptr_info.ast.bit_range_end); | 1621 | bit_end_ref = try expr(gz, scope, .none, ptr_info.ast.bit_range_end); |
| 1631 | trailing_count += 2; | 1622 | trailing_count += 2; |
| 1632 | } | 1623 | } |
| 1633 | | 1624 | |
| ... | @@ -1667,54 +1658,51 @@ fn ptrType( | ... | @@ -1667,54 +1658,51 @@ fn ptrType( |
| 1667 | } }); | 1658 | } }); |
| 1668 | gz.instructions.appendAssumeCapacity(new_index); | 1659 | gz.instructions.appendAssumeCapacity(new_index); |
| 1669 | | 1660 | |
| 1670 | return rvalue(mod, scope, rl, result, node); | 1661 | return rvalue(gz, scope, rl, result, node); |
| 1671 | } | 1662 | } |
| 1672 | | 1663 | |
| 1673 | fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { | 1664 | fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| 1674 | const tree = scope.tree(); | 1665 | const tree = scope.tree(); |
| 1675 | const node_datas = tree.nodes.items(.data); | 1666 | const node_datas = tree.nodes.items(.data); |
| 1676 | const gz = scope.getGenZir(); | | |
| 1677 | | 1667 | |
| 1678 | // TODO check for [_]T | 1668 | // TODO check for [_]T |
| 1679 | const len = try expr(mod, scope, .{ .ty = .usize_type }, node_datas[node].lhs); | 1669 | const len = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].lhs); |
| 1680 | const elem_type = try typeExpr(mod, scope, node_datas[node].rhs); | 1670 | const elem_type = try typeExpr(gz, scope, node_datas[node].rhs); |
| 1681 | | 1671 | |
| 1682 | const result = try gz.addBin(.array_type, len, elem_type); | 1672 | const result = try gz.addBin(.array_type, len, elem_type); |
| 1683 | return rvalue(mod, scope, rl, result, node); | 1673 | return rvalue(gz, scope, rl, result, node); |
| 1684 | } | 1674 | } |
| 1685 | | 1675 | |
| 1686 | fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { | 1676 | fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| 1687 | const tree = scope.tree(); | 1677 | const tree = scope.tree(); |
| 1688 | const node_datas = tree.nodes.items(.data); | 1678 | const node_datas = tree.nodes.items(.data); |
| 1689 | const extra = tree.extraData(node_datas[node].rhs, ast.Node.ArrayTypeSentinel); | 1679 | const extra = tree.extraData(node_datas[node].rhs, ast.Node.ArrayTypeSentinel); |
| 1690 | const gz = scope.getGenZir(); | | |
| 1691 | | 1680 | |
| 1692 | // TODO check for [_]T | 1681 | // TODO check for [_]T |
| 1693 | const len = try expr(mod, scope, .{ .ty = .usize_type }, node_datas[node].lhs); | 1682 | const len = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].lhs); |
| 1694 | const elem_type = try typeExpr(mod, scope, extra.elem_type); | 1683 | const elem_type = try typeExpr(gz, scope, extra.elem_type); |
| 1695 | const sentinel = try expr(mod, scope, .{ .ty = elem_type }, extra.sentinel); | 1684 | const sentinel = try expr(gz, scope, .{ .ty = elem_type }, extra.sentinel); |
| 1696 | | 1685 | |
| 1697 | const result = try gz.addArrayTypeSentinel(len, elem_type, sentinel); | 1686 | const result = try gz.addArrayTypeSentinel(len, elem_type, sentinel); |
| 1698 | return rvalue(mod, scope, rl, result, node); | 1687 | return rvalue(gz, scope, rl, result, node); |
| 1699 | } | 1688 | } |
| 1700 | | 1689 | |
| 1701 | fn containerDecl( | 1690 | fn containerDecl( |
| 1702 | mod: *Module, | 1691 | gz: *GenZir, |
| 1703 | scope: *Scope, | 1692 | scope: *Scope, |
| 1704 | rl: ResultLoc, | 1693 | rl: ResultLoc, |
| 1705 | container_decl: ast.full.ContainerDecl, | 1694 | container_decl: ast.full.ContainerDecl, |
| 1706 | ) InnerError!zir.Inst.Ref { | 1695 | ) InnerError!zir.Inst.Ref { |
| 1707 | return mod.failTok(scope, container_decl.ast.main_token, "TODO implement container decls", .{}); | 1696 | return gz.astgen.mod.failTok(scope, container_decl.ast.main_token, "TODO implement container decls", .{}); |
| 1708 | } | 1697 | } |
| 1709 | | 1698 | |
| 1710 | fn errorSetDecl( | 1699 | fn errorSetDecl( |
| 1711 | mod: *Module, | 1700 | gz: *GenZir, |
| 1712 | scope: *Scope, | 1701 | scope: *Scope, |
| 1713 | rl: ResultLoc, | 1702 | rl: ResultLoc, |
| 1714 | node: ast.Node.Index, | 1703 | node: ast.Node.Index, |
| 1715 | ) InnerError!zir.Inst.Ref { | 1704 | ) InnerError!zir.Inst.Ref { |
| 1716 | if (true) @panic("TODO update for zir-memory-layout branch"); | 1705 | if (true) @panic("TODO update for zir-memory-layout branch"); |
| 1717 | const gz = scope.getGenZir(); | | |
| 1718 | const tree = gz.tree(); | 1706 | const tree = gz.tree(); |
| 1719 | const main_tokens = tree.nodes.items(.main_token); | 1707 | const main_tokens = tree.nodes.items(.main_token); |
| 1720 | const token_tags = tree.tokens.items(.tag); | 1708 | const token_tags = tree.tokens.items(.tag); |
| ... | @@ -1751,11 +1739,11 @@ fn errorSetDecl( | ... | @@ -1751,11 +1739,11 @@ fn errorSetDecl( |
| 1751 | } | 1739 | } |
| 1752 | } | 1740 | } |
| 1753 | const result = try addZIRInst(mod, scope, src, zir.Inst.ErrorSet, .{ .fields = fields }, .{}); | 1741 | const result = try addZIRInst(mod, scope, src, zir.Inst.ErrorSet, .{ .fields = fields }, .{}); |
| 1754 | return rvalue(mod, scope, rl, result); | 1742 | return rvalue(gz, scope, rl, result); |
| 1755 | } | 1743 | } |
| 1756 | | 1744 | |
| 1757 | fn orelseCatchExpr( | 1745 | fn orelseCatchExpr( |
| 1758 | mod: *Module, | 1746 | parent_gz: *GenZir, |
| 1759 | scope: *Scope, | 1747 | scope: *Scope, |
| 1760 | rl: ResultLoc, | 1748 | rl: ResultLoc, |
| 1761 | node: ast.Node.Index, | 1749 | node: ast.Node.Index, |
| ... | @@ -1766,10 +1754,10 @@ fn orelseCatchExpr( | ... | @@ -1766,10 +1754,10 @@ fn orelseCatchExpr( |
| 1766 | rhs: ast.Node.Index, | 1754 | rhs: ast.Node.Index, |
| 1767 | payload_token: ?ast.TokenIndex, | 1755 | payload_token: ?ast.TokenIndex, |
| 1768 | ) InnerError!zir.Inst.Ref { | 1756 | ) InnerError!zir.Inst.Ref { |
| 1769 | const parent_gz = scope.getGenZir(); | 1757 | const mod = parent_gz.astgen.mod; |
| 1770 | const tree = parent_gz.tree(); | 1758 | const tree = parent_gz.tree(); |
| 1771 | | 1759 | |
| 1772 | var block_scope: Scope.GenZir = .{ | 1760 | var block_scope: GenZir = .{ |
| 1773 | .parent = scope, | 1761 | .parent = scope, |
| 1774 | .astgen = parent_gz.astgen, | 1762 | .astgen = parent_gz.astgen, |
| 1775 | .force_comptime = parent_gz.force_comptime, | 1763 | .force_comptime = parent_gz.force_comptime, |
| ... | @@ -1797,7 +1785,7 @@ fn orelseCatchExpr( | ... | @@ -1797,7 +1785,7 @@ fn orelseCatchExpr( |
| 1797 | break :blk .{ .ty = wrapped_ty }; | 1785 | break :blk .{ .ty = wrapped_ty }; |
| 1798 | }, | 1786 | }, |
| 1799 | }; | 1787 | }; |
| 1800 | const operand = try expr(mod, &block_scope.base, operand_rl, lhs); | 1788 | const operand = try expr(&block_scope, &block_scope.base, operand_rl, lhs); |
| 1801 | const cond = try block_scope.addUnNode(cond_op, operand, node); | 1789 | const cond = try block_scope.addUnNode(cond_op, operand, node); |
| 1802 | const condbr = try block_scope.addCondBr(.condbr, node); | 1790 | const condbr = try block_scope.addCondBr(.condbr, node); |
| 1803 | | 1791 | |
| ... | @@ -1805,7 +1793,7 @@ fn orelseCatchExpr( | ... | @@ -1805,7 +1793,7 @@ fn orelseCatchExpr( |
| 1805 | try parent_gz.instructions.append(mod.gpa, block); | 1793 | try parent_gz.instructions.append(mod.gpa, block); |
| 1806 | try block_scope.setBlockBody(block); | 1794 | try block_scope.setBlockBody(block); |
| 1807 | | 1795 | |
| 1808 | var then_scope: Scope.GenZir = .{ | 1796 | var then_scope: GenZir = .{ |
| 1809 | .parent = scope, | 1797 | .parent = scope, |
| 1810 | .astgen = parent_gz.astgen, | 1798 | .astgen = parent_gz.astgen, |
| 1811 | .force_comptime = block_scope.force_comptime, | 1799 | .force_comptime = block_scope.force_comptime, |
| ... | @@ -1831,12 +1819,12 @@ fn orelseCatchExpr( | ... | @@ -1831,12 +1819,12 @@ fn orelseCatchExpr( |
| 1831 | }; | 1819 | }; |
| 1832 | | 1820 | |
| 1833 | block_scope.break_count += 1; | 1821 | block_scope.break_count += 1; |
| 1834 | const then_result = try expr(mod, then_sub_scope, block_scope.break_result_loc, rhs); | 1822 | const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_loc, rhs); |
| 1835 | // We hold off on the break instructions as well as copying the then/else | 1823 | // We hold off on the break instructions as well as copying the then/else |
| 1836 | // instructions into place until we know whether to keep store_to_block_ptr | 1824 | // instructions into place until we know whether to keep store_to_block_ptr |
| 1837 | // instructions or not. | 1825 | // instructions or not. |
| 1838 | | 1826 | |
| 1839 | var else_scope: Scope.GenZir = .{ | 1827 | var else_scope: GenZir = .{ |
| 1840 | .parent = scope, | 1828 | .parent = scope, |
| 1841 | .astgen = parent_gz.astgen, | 1829 | .astgen = parent_gz.astgen, |
| 1842 | .force_comptime = block_scope.force_comptime, | 1830 | .force_comptime = block_scope.force_comptime, |
| ... | @@ -1848,11 +1836,11 @@ fn orelseCatchExpr( | ... | @@ -1848,11 +1836,11 @@ fn orelseCatchExpr( |
| 1848 | const unwrapped_payload = try else_scope.addUnNode(unwrap_op, operand, node); | 1836 | const unwrapped_payload = try else_scope.addUnNode(unwrap_op, operand, node); |
| 1849 | const else_result = switch (rl) { | 1837 | const else_result = switch (rl) { |
| 1850 | .ref => unwrapped_payload, | 1838 | .ref => unwrapped_payload, |
| 1851 | else => try rvalue(mod, &else_scope.base, block_scope.break_result_loc, unwrapped_payload, node), | 1839 | else => try rvalue(&else_scope, &else_scope.base, block_scope.break_result_loc, unwrapped_payload, node), |
| 1852 | }; | 1840 | }; |
| 1853 | | 1841 | |
| 1854 | return finishThenElseBlock( | 1842 | return finishThenElseBlock( |
| 1855 | mod, | 1843 | parent_gz, |
| 1856 | scope, | 1844 | scope, |
| 1857 | rl, | 1845 | rl, |
| 1858 | node, | 1846 | node, |
| ... | @@ -1872,13 +1860,13 @@ fn orelseCatchExpr( | ... | @@ -1872,13 +1860,13 @@ fn orelseCatchExpr( |
| 1872 | } | 1860 | } |
| 1873 | | 1861 | |
| 1874 | fn finishThenElseBlock( | 1862 | fn finishThenElseBlock( |
| 1875 | mod: *Module, | 1863 | parent_gz: *GenZir, |
| 1876 | parent_scope: *Scope, | 1864 | parent_scope: *Scope, |
| 1877 | rl: ResultLoc, | 1865 | rl: ResultLoc, |
| 1878 | node: ast.Node.Index, | 1866 | node: ast.Node.Index, |
| 1879 | block_scope: *Scope.GenZir, | 1867 | block_scope: *GenZir, |
| 1880 | then_scope: *Scope.GenZir, | 1868 | then_scope: *GenZir, |
| 1881 | else_scope: *Scope.GenZir, | 1869 | else_scope: *GenZir, |
| 1882 | condbr: zir.Inst.Index, | 1870 | condbr: zir.Inst.Index, |
| 1883 | cond: zir.Inst.Ref, | 1871 | cond: zir.Inst.Ref, |
| 1884 | then_src: ast.Node.Index, | 1872 | then_src: ast.Node.Index, |
| ... | @@ -1925,7 +1913,7 @@ fn finishThenElseBlock( | ... | @@ -1925,7 +1913,7 @@ fn finishThenElseBlock( |
| 1925 | const block_ref = astgen.indexToRef(main_block); | 1913 | const block_ref = astgen.indexToRef(main_block); |
| 1926 | switch (rl) { | 1914 | switch (rl) { |
| 1927 | .ref => return block_ref, | 1915 | .ref => return block_ref, |
| 1928 | else => return rvalue(mod, parent_scope, rl, block_ref, node), | 1916 | else => return rvalue(parent_gz, parent_scope, rl, block_ref, node), |
| 1929 | } | 1917 | } |
| 1930 | }, | 1918 | }, |
| 1931 | } | 1919 | } |
| ... | @@ -1942,15 +1930,16 @@ fn tokenIdentEql(mod: *Module, scope: *Scope, token1: ast.TokenIndex, token2: as | ... | @@ -1942,15 +1930,16 @@ fn tokenIdentEql(mod: *Module, scope: *Scope, token1: ast.TokenIndex, token2: as |
| 1942 | } | 1930 | } |
| 1943 | | 1931 | |
| 1944 | pub fn fieldAccess( | 1932 | pub fn fieldAccess( |
| 1945 | mod: *Module, | 1933 | gz: *GenZir, |
| 1946 | scope: *Scope, | 1934 | scope: *Scope, |
| 1947 | rl: ResultLoc, | 1935 | rl: ResultLoc, |
| 1948 | node: ast.Node.Index, | 1936 | node: ast.Node.Index, |
| 1949 | ) InnerError!zir.Inst.Ref { | 1937 | ) InnerError!zir.Inst.Ref { |
| 1950 | const gz = scope.getGenZir(); | 1938 | const mod = gz.astgen.mod; |
| 1951 | const tree = gz.tree(); | 1939 | const tree = gz.tree(); |
| 1952 | const main_tokens = tree.nodes.items(.main_token); | 1940 | const main_tokens = tree.nodes.items(.main_token); |
| 1953 | const node_datas = tree.nodes.items(.data); | 1941 | const node_datas = tree.nodes.items(.data); |
| | 1942 | |
| 1954 | const object_node = node_datas[node].lhs; | 1943 | const object_node = node_datas[node].lhs; |
| 1955 | const dot_token = main_tokens[node]; | 1944 | const dot_token = main_tokens[node]; |
| 1956 | const field_ident = dot_token + 1; | 1945 | const field_ident = dot_token + 1; |
| ... | @@ -1960,111 +1949,109 @@ pub fn fieldAccess( | ... | @@ -1960,111 +1949,109 @@ pub fn fieldAccess( |
| 1960 | try string_bytes.append(mod.gpa, 0); | 1949 | try string_bytes.append(mod.gpa, 0); |
| 1961 | switch (rl) { | 1950 | switch (rl) { |
| 1962 | .ref => return gz.addPlNode(.field_ptr, node, zir.Inst.Field{ | 1951 | .ref => return gz.addPlNode(.field_ptr, node, zir.Inst.Field{ |
| 1963 | .lhs = try expr(mod, scope, .ref, object_node), | 1952 | .lhs = try expr(gz, scope, .ref, object_node), |
| 1964 | .field_name_start = str_index, | 1953 | .field_name_start = str_index, |
| 1965 | }), | 1954 | }), |
| 1966 | else => return rvalue(mod, scope, rl, try gz.addPlNode(.field_val, node, zir.Inst.Field{ | 1955 | else => return rvalue(gz, scope, rl, try gz.addPlNode(.field_val, node, zir.Inst.Field{ |
| 1967 | .lhs = try expr(mod, scope, .none, object_node), | 1956 | .lhs = try expr(gz, scope, .none, object_node), |
| 1968 | .field_name_start = str_index, | 1957 | .field_name_start = str_index, |
| 1969 | }), node), | 1958 | }), node), |
| 1970 | } | 1959 | } |
| 1971 | } | 1960 | } |
| 1972 | | 1961 | |
| 1973 | fn arrayAccess( | 1962 | fn arrayAccess( |
| 1974 | mod: *Module, | 1963 | gz: *GenZir, |
| 1975 | scope: *Scope, | 1964 | scope: *Scope, |
| 1976 | rl: ResultLoc, | 1965 | rl: ResultLoc, |
| 1977 | node: ast.Node.Index, | 1966 | node: ast.Node.Index, |
| 1978 | ) InnerError!zir.Inst.Ref { | 1967 | ) InnerError!zir.Inst.Ref { |
| 1979 | const gz = scope.getGenZir(); | | |
| 1980 | const tree = gz.tree(); | 1968 | const tree = gz.tree(); |
| 1981 | const main_tokens = tree.nodes.items(.main_token); | 1969 | const main_tokens = tree.nodes.items(.main_token); |
| 1982 | const node_datas = tree.nodes.items(.data); | 1970 | const node_datas = tree.nodes.items(.data); |
| 1983 | switch (rl) { | 1971 | switch (rl) { |
| 1984 | .ref => return gz.addBin( | 1972 | .ref => return gz.addBin( |
| 1985 | .elem_ptr, | 1973 | .elem_ptr, |
| 1986 | try expr(mod, scope, .ref, node_datas[node].lhs), | 1974 | try expr(gz, scope, .ref, node_datas[node].lhs), |
| 1987 | try expr(mod, scope, .{ .ty = .usize_type }, node_datas[node].rhs), | 1975 | try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs), |
| 1988 | ), | 1976 | ), |
| 1989 | else => return rvalue(mod, scope, rl, try gz.addBin( | 1977 | else => return rvalue(gz, scope, rl, try gz.addBin( |
| 1990 | .elem_val, | 1978 | .elem_val, |
| 1991 | try expr(mod, scope, .none, node_datas[node].lhs), | 1979 | try expr(gz, scope, .none, node_datas[node].lhs), |
| 1992 | try expr(mod, scope, .{ .ty = .usize_type }, node_datas[node].rhs), | 1980 | try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs), |
| 1993 | ), node), | 1981 | ), node), |
| 1994 | } | 1982 | } |
| 1995 | } | 1983 | } |
| 1996 | | 1984 | |
| 1997 | fn simpleBinOp( | 1985 | fn simpleBinOp( |
| 1998 | mod: *Module, | 1986 | gz: *GenZir, |
| 1999 | scope: *Scope, | 1987 | scope: *Scope, |
| 2000 | rl: ResultLoc, | 1988 | rl: ResultLoc, |
| 2001 | node: ast.Node.Index, | 1989 | node: ast.Node.Index, |
| 2002 | op_inst_tag: zir.Inst.Tag, | 1990 | op_inst_tag: zir.Inst.Tag, |
| 2003 | ) InnerError!zir.Inst.Ref { | 1991 | ) InnerError!zir.Inst.Ref { |
| 2004 | const gz = scope.getGenZir(); | | |
| 2005 | const tree = gz.tree(); | 1992 | const tree = gz.tree(); |
| 2006 | const node_datas = tree.nodes.items(.data); | 1993 | const node_datas = tree.nodes.items(.data); |
| 2007 | | 1994 | |
| 2008 | const result = try gz.addPlNode(op_inst_tag, node, zir.Inst.Bin{ | 1995 | const result = try gz.addPlNode(op_inst_tag, node, zir.Inst.Bin{ |
| 2009 | .lhs = try expr(mod, scope, .none, node_datas[node].lhs), | 1996 | .lhs = try expr(gz, scope, .none, node_datas[node].lhs), |
| 2010 | .rhs = try expr(mod, scope, .none, node_datas[node].rhs), | 1997 | .rhs = try expr(gz, scope, .none, node_datas[node].rhs), |
| 2011 | }); | 1998 | }); |
| 2012 | return rvalue(mod, scope, rl, result, node); | 1999 | return rvalue(gz, scope, rl, result, node); |
| 2013 | } | 2000 | } |
| 2014 | | 2001 | |
| 2015 | fn simpleStrTok( | 2002 | fn simpleStrTok( |
| 2016 | mod: *Module, | 2003 | gz: *GenZir, |
| 2017 | scope: *Scope, | 2004 | scope: *Scope, |
| 2018 | rl: ResultLoc, | 2005 | rl: ResultLoc, |
| 2019 | ident_token: ast.TokenIndex, | 2006 | ident_token: ast.TokenIndex, |
| 2020 | node: ast.Node.Index, | 2007 | node: ast.Node.Index, |
| 2021 | op_inst_tag: zir.Inst.Tag, | 2008 | op_inst_tag: zir.Inst.Tag, |
| 2022 | ) InnerError!zir.Inst.Ref { | 2009 | ) InnerError!zir.Inst.Ref { |
| 2023 | const gz = scope.getGenZir(); | 2010 | const mod = gz.astgen.mod; |
| 2024 | const string_bytes = &gz.astgen.string_bytes; | 2011 | const string_bytes = &gz.astgen.string_bytes; |
| 2025 | const str_index = @intCast(u32, string_bytes.items.len); | 2012 | const str_index = @intCast(u32, string_bytes.items.len); |
| 2026 | try mod.appendIdentStr(scope, ident_token, string_bytes); | 2013 | try mod.appendIdentStr(scope, ident_token, string_bytes); |
| 2027 | try string_bytes.append(mod.gpa, 0); | 2014 | try string_bytes.append(mod.gpa, 0); |
| 2028 | const result = try gz.addStrTok(op_inst_tag, str_index, ident_token); | 2015 | const result = try gz.addStrTok(op_inst_tag, str_index, ident_token); |
| 2029 | return rvalue(mod, scope, rl, result, node); | 2016 | return rvalue(gz, scope, rl, result, node); |
| 2030 | } | 2017 | } |
| 2031 | | 2018 | |
| 2032 | fn boolBinOp( | 2019 | fn boolBinOp( |
| 2033 | mod: *Module, | 2020 | gz: *GenZir, |
| 2034 | scope: *Scope, | 2021 | scope: *Scope, |
| 2035 | rl: ResultLoc, | 2022 | rl: ResultLoc, |
| 2036 | node: ast.Node.Index, | 2023 | node: ast.Node.Index, |
| 2037 | zir_tag: zir.Inst.Tag, | 2024 | zir_tag: zir.Inst.Tag, |
| 2038 | ) InnerError!zir.Inst.Ref { | 2025 | ) InnerError!zir.Inst.Ref { |
| 2039 | const gz = scope.getGenZir(); | | |
| 2040 | const node_datas = gz.tree().nodes.items(.data); | 2026 | const node_datas = gz.tree().nodes.items(.data); |
| 2041 | | 2027 | |
| 2042 | const lhs = try expr(mod, scope, .{ .ty = .bool_type }, node_datas[node].lhs); | 2028 | const lhs = try expr(gz, scope, .{ .ty = .bool_type }, node_datas[node].lhs); |
| 2043 | const bool_br = try gz.addBoolBr(zir_tag, lhs); | 2029 | const bool_br = try gz.addBoolBr(zir_tag, lhs); |
| 2044 | | 2030 | |
| 2045 | var rhs_scope: Scope.GenZir = .{ | 2031 | var rhs_scope: GenZir = .{ |
| 2046 | .parent = scope, | 2032 | .parent = scope, |
| 2047 | .astgen = gz.astgen, | 2033 | .astgen = gz.astgen, |
| 2048 | .force_comptime = gz.force_comptime, | 2034 | .force_comptime = gz.force_comptime, |
| 2049 | }; | 2035 | }; |
| 2050 | defer rhs_scope.instructions.deinit(mod.gpa); | 2036 | defer rhs_scope.instructions.deinit(gz.astgen.mod.gpa); |
| 2051 | const rhs = try expr(mod, &rhs_scope.base, .{ .ty = .bool_type }, node_datas[node].rhs); | 2037 | const rhs = try expr(&rhs_scope, &rhs_scope.base, .{ .ty = .bool_type }, node_datas[node].rhs); |
| 2052 | _ = try rhs_scope.addBreak(.break_inline, bool_br, rhs); | 2038 | _ = try rhs_scope.addBreak(.break_inline, bool_br, rhs); |
| 2053 | try rhs_scope.setBoolBrBody(bool_br); | 2039 | try rhs_scope.setBoolBrBody(bool_br); |
| 2054 | | 2040 | |
| 2055 | const block_ref = gz.astgen.indexToRef(bool_br); | 2041 | const block_ref = gz.astgen.indexToRef(bool_br); |
| 2056 | return rvalue(mod, scope, rl, block_ref, node); | 2042 | return rvalue(gz, scope, rl, block_ref, node); |
| 2057 | } | 2043 | } |
| 2058 | | 2044 | |
| 2059 | fn ifExpr( | 2045 | fn ifExpr( |
| 2060 | mod: *Module, | 2046 | parent_gz: *GenZir, |
| 2061 | scope: *Scope, | 2047 | scope: *Scope, |
| 2062 | rl: ResultLoc, | 2048 | rl: ResultLoc, |
| 2063 | node: ast.Node.Index, | 2049 | node: ast.Node.Index, |
| 2064 | if_full: ast.full.If, | 2050 | if_full: ast.full.If, |
| 2065 | ) InnerError!zir.Inst.Ref { | 2051 | ) InnerError!zir.Inst.Ref { |
| 2066 | const parent_gz = scope.getGenZir(); | 2052 | const mod = parent_gz.astgen.mod; |
| 2067 | var block_scope: Scope.GenZir = .{ | 2053 | |
| | 2054 | var block_scope: GenZir = .{ |
| 2068 | .parent = scope, | 2055 | .parent = scope, |
| 2069 | .astgen = parent_gz.astgen, | 2056 | .astgen = parent_gz.astgen, |
| 2070 | .force_comptime = parent_gz.force_comptime, | 2057 | .force_comptime = parent_gz.force_comptime, |
| ... | @@ -2080,7 +2067,7 @@ fn ifExpr( | ... | @@ -2080,7 +2067,7 @@ fn ifExpr( |
| 2080 | } else if (if_full.payload_token) |payload_token| { | 2067 | } else if (if_full.payload_token) |payload_token| { |
| 2081 | return mod.failTok(scope, payload_token, "TODO implement if optional", .{}); | 2068 | return mod.failTok(scope, payload_token, "TODO implement if optional", .{}); |
| 2082 | } else { | 2069 | } else { |
| 2083 | break :c try expr(mod, &block_scope.base, .{ .ty = .bool_type }, if_full.ast.cond_expr); | 2070 | break :c try expr(&block_scope, &block_scope.base, .{ .ty = .bool_type }, if_full.ast.cond_expr); |
| 2084 | } | 2071 | } |
| 2085 | }; | 2072 | }; |
| 2086 | | 2073 | |
| ... | @@ -2090,7 +2077,7 @@ fn ifExpr( | ... | @@ -2090,7 +2077,7 @@ fn ifExpr( |
| 2090 | try parent_gz.instructions.append(mod.gpa, block); | 2077 | try parent_gz.instructions.append(mod.gpa, block); |
| 2091 | try block_scope.setBlockBody(block); | 2078 | try block_scope.setBlockBody(block); |
| 2092 | | 2079 | |
| 2093 | var then_scope: Scope.GenZir = .{ | 2080 | var then_scope: GenZir = .{ |
| 2094 | .parent = scope, | 2081 | .parent = scope, |
| 2095 | .astgen = parent_gz.astgen, | 2082 | .astgen = parent_gz.astgen, |
| 2096 | .force_comptime = block_scope.force_comptime, | 2083 | .force_comptime = block_scope.force_comptime, |
| ... | @@ -2102,12 +2089,12 @@ fn ifExpr( | ... | @@ -2102,12 +2089,12 @@ fn ifExpr( |
| 2102 | const then_sub_scope = &then_scope.base; | 2089 | const then_sub_scope = &then_scope.base; |
| 2103 | | 2090 | |
| 2104 | block_scope.break_count += 1; | 2091 | block_scope.break_count += 1; |
| 2105 | const then_result = try expr(mod, then_sub_scope, block_scope.break_result_loc, if_full.ast.then_expr); | 2092 | const then_result = try expr(&then_scope, then_sub_scope, block_scope.break_result_loc, if_full.ast.then_expr); |
| 2106 | // We hold off on the break instructions as well as copying the then/else | 2093 | // We hold off on the break instructions as well as copying the then/else |
| 2107 | // instructions into place until we know whether to keep store_to_block_ptr | 2094 | // instructions into place until we know whether to keep store_to_block_ptr |
| 2108 | // instructions or not. | 2095 | // instructions or not. |
| 2109 | | 2096 | |
| 2110 | var else_scope: Scope.GenZir = .{ | 2097 | var else_scope: GenZir = .{ |
| 2111 | .parent = scope, | 2098 | .parent = scope, |
| 2112 | .astgen = parent_gz.astgen, | 2099 | .astgen = parent_gz.astgen, |
| 2113 | .force_comptime = block_scope.force_comptime, | 2100 | .force_comptime = block_scope.force_comptime, |
| ... | @@ -2124,7 +2111,7 @@ fn ifExpr( | ... | @@ -2124,7 +2111,7 @@ fn ifExpr( |
| 2124 | const sub_scope = &else_scope.base; | 2111 | const sub_scope = &else_scope.base; |
| 2125 | break :blk .{ | 2112 | break :blk .{ |
| 2126 | .src = else_node, | 2113 | .src = else_node, |
| 2127 | .result = try expr(mod, sub_scope, block_scope.break_result_loc, else_node), | 2114 | .result = try expr(&else_scope, sub_scope, block_scope.break_result_loc, else_node), |
| 2128 | }; | 2115 | }; |
| 2129 | } else .{ | 2116 | } else .{ |
| 2130 | .src = if_full.ast.then_expr, | 2117 | .src = if_full.ast.then_expr, |
| ... | @@ -2132,7 +2119,7 @@ fn ifExpr( | ... | @@ -2132,7 +2119,7 @@ fn ifExpr( |
| 2132 | }; | 2119 | }; |
| 2133 | | 2120 | |
| 2134 | return finishThenElseBlock( | 2121 | return finishThenElseBlock( |
| 2135 | mod, | 2122 | parent_gz, |
| 2136 | scope, | 2123 | scope, |
| 2137 | rl, | 2124 | rl, |
| 2138 | node, | 2125 | node, |
| ... | @@ -2154,8 +2141,8 @@ fn ifExpr( | ... | @@ -2154,8 +2141,8 @@ fn ifExpr( |
| 2154 | fn setCondBrPayload( | 2141 | fn setCondBrPayload( |
| 2155 | condbr: zir.Inst.Index, | 2142 | condbr: zir.Inst.Index, |
| 2156 | cond: zir.Inst.Ref, | 2143 | cond: zir.Inst.Ref, |
| 2157 | then_scope: *Scope.GenZir, | 2144 | then_scope: *GenZir, |
| 2158 | else_scope: *Scope.GenZir, | 2145 | else_scope: *GenZir, |
| 2159 | ) !void { | 2146 | ) !void { |
| 2160 | const astgen = then_scope.astgen; | 2147 | const astgen = then_scope.astgen; |
| 2161 | | 2148 | |
| ... | @@ -2177,8 +2164,8 @@ fn setCondBrPayload( | ... | @@ -2177,8 +2164,8 @@ fn setCondBrPayload( |
| 2177 | fn setCondBrPayloadElideBlockStorePtr( | 2164 | fn setCondBrPayloadElideBlockStorePtr( |
| 2178 | condbr: zir.Inst.Index, | 2165 | condbr: zir.Inst.Index, |
| 2179 | cond: zir.Inst.Ref, | 2166 | cond: zir.Inst.Ref, |
| 2180 | then_scope: *Scope.GenZir, | 2167 | then_scope: *GenZir, |
| 2181 | else_scope: *Scope.GenZir, | 2168 | else_scope: *GenZir, |
| 2182 | ) !void { | 2169 | ) !void { |
| 2183 | const astgen = then_scope.astgen; | 2170 | const astgen = then_scope.astgen; |
| 2184 | | 2171 | |
| ... | @@ -2194,7 +2181,7 @@ fn setCondBrPayloadElideBlockStorePtr( | ... | @@ -2194,7 +2181,7 @@ fn setCondBrPayloadElideBlockStorePtr( |
| 2194 | }); | 2181 | }); |
| 2195 | | 2182 | |
| 2196 | const zir_tags = astgen.instructions.items(.tag); | 2183 | const zir_tags = astgen.instructions.items(.tag); |
| 2197 | for ([_]*Scope.GenZir{ then_scope, else_scope }) |scope| { | 2184 | for ([_]*GenZir{ then_scope, else_scope }) |scope| { |
| 2198 | for (scope.instructions.items) |src_inst| { | 2185 | for (scope.instructions.items) |src_inst| { |
| 2199 | if (zir_tags[src_inst] != .store_to_block_ptr) { | 2186 | if (zir_tags[src_inst] != .store_to_block_ptr) { |
| 2200 | astgen.extra.appendAssumeCapacity(src_inst); | 2187 | astgen.extra.appendAssumeCapacity(src_inst); |
| ... | @@ -2204,22 +2191,23 @@ fn setCondBrPayloadElideBlockStorePtr( | ... | @@ -2204,22 +2191,23 @@ fn setCondBrPayloadElideBlockStorePtr( |
| 2204 | } | 2191 | } |
| 2205 | | 2192 | |
| 2206 | fn whileExpr( | 2193 | fn whileExpr( |
| 2207 | mod: *Module, | 2194 | parent_gz: *GenZir, |
| 2208 | scope: *Scope, | 2195 | scope: *Scope, |
| 2209 | rl: ResultLoc, | 2196 | rl: ResultLoc, |
| 2210 | node: ast.Node.Index, | 2197 | node: ast.Node.Index, |
| 2211 | while_full: ast.full.While, | 2198 | while_full: ast.full.While, |
| 2212 | ) InnerError!zir.Inst.Ref { | 2199 | ) InnerError!zir.Inst.Ref { |
| | 2200 | const mod = parent_gz.astgen.mod; |
| 2213 | if (while_full.label_token) |label_token| { | 2201 | if (while_full.label_token) |label_token| { |
| 2214 | try checkLabelRedefinition(mod, scope, label_token); | 2202 | try checkLabelRedefinition(mod, scope, label_token); |
| 2215 | } | 2203 | } |
| 2216 | const parent_gz = scope.getGenZir(); | 2204 | |
| 2217 | const is_inline = parent_gz.force_comptime or while_full.inline_token != null; | 2205 | const is_inline = parent_gz.force_comptime or while_full.inline_token != null; |
| 2218 | const loop_tag: zir.Inst.Tag = if (is_inline) .block_inline else .loop; | 2206 | const loop_tag: zir.Inst.Tag = if (is_inline) .block_inline else .loop; |
| 2219 | const loop_block = try parent_gz.addBlock(loop_tag, node); | 2207 | const loop_block = try parent_gz.addBlock(loop_tag, node); |
| 2220 | try parent_gz.instructions.append(mod.gpa, loop_block); | 2208 | try parent_gz.instructions.append(mod.gpa, loop_block); |
| 2221 | | 2209 | |
| 2222 | var loop_scope: Scope.GenZir = .{ | 2210 | var loop_scope: GenZir = .{ |
| 2223 | .parent = scope, | 2211 | .parent = scope, |
| 2224 | .astgen = parent_gz.astgen, | 2212 | .astgen = parent_gz.astgen, |
| 2225 | .force_comptime = parent_gz.force_comptime, | 2213 | .force_comptime = parent_gz.force_comptime, |
| ... | @@ -2228,7 +2216,7 @@ fn whileExpr( | ... | @@ -2228,7 +2216,7 @@ fn whileExpr( |
| 2228 | loop_scope.setBreakResultLoc(rl); | 2216 | loop_scope.setBreakResultLoc(rl); |
| 2229 | defer loop_scope.instructions.deinit(mod.gpa); | 2217 | defer loop_scope.instructions.deinit(mod.gpa); |
| 2230 | | 2218 | |
| 2231 | var continue_scope: Scope.GenZir = .{ | 2219 | var continue_scope: GenZir = .{ |
| 2232 | .parent = &loop_scope.base, | 2220 | .parent = &loop_scope.base, |
| 2233 | .astgen = parent_gz.astgen, | 2221 | .astgen = parent_gz.astgen, |
| 2234 | .force_comptime = loop_scope.force_comptime, | 2222 | .force_comptime = loop_scope.force_comptime, |
| ... | @@ -2244,7 +2232,7 @@ fn whileExpr( | ... | @@ -2244,7 +2232,7 @@ fn whileExpr( |
| 2244 | return mod.failTok(scope, payload_token, "TODO implement while optional", .{}); | 2232 | return mod.failTok(scope, payload_token, "TODO implement while optional", .{}); |
| 2245 | } else { | 2233 | } else { |
| 2246 | const bool_type_rl: ResultLoc = .{ .ty = .bool_type }; | 2234 | const bool_type_rl: ResultLoc = .{ .ty = .bool_type }; |
| 2247 | break :c try expr(mod, &continue_scope.base, bool_type_rl, while_full.ast.cond_expr); | 2235 | break :c try expr(&continue_scope, &continue_scope.base, bool_type_rl, while_full.ast.cond_expr); |
| 2248 | } | 2236 | } |
| 2249 | }; | 2237 | }; |
| 2250 | | 2238 | |
| ... | @@ -2259,7 +2247,7 @@ fn whileExpr( | ... | @@ -2259,7 +2247,7 @@ fn whileExpr( |
| 2259 | // are no jumps to it. This happens when the last statement of a while body is noreturn | 2247 | // are no jumps to it. This happens when the last statement of a while body is noreturn |
| 2260 | // and there are no `continue` statements. | 2248 | // and there are no `continue` statements. |
| 2261 | if (while_full.ast.cont_expr != 0) { | 2249 | if (while_full.ast.cont_expr != 0) { |
| 2262 | _ = try expr(mod, &loop_scope.base, .{ .ty = .void_type }, while_full.ast.cont_expr); | 2250 | _ = try expr(&loop_scope, &loop_scope.base, .{ .ty = .void_type }, while_full.ast.cont_expr); |
| 2263 | } | 2251 | } |
| 2264 | const repeat_tag: zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat; | 2252 | const repeat_tag: zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat; |
| 2265 | _ = try loop_scope.addNode(repeat_tag, node); | 2253 | _ = try loop_scope.addNode(repeat_tag, node); |
| ... | @@ -2268,13 +2256,13 @@ fn whileExpr( | ... | @@ -2268,13 +2256,13 @@ fn whileExpr( |
| 2268 | loop_scope.break_block = loop_block; | 2256 | loop_scope.break_block = loop_block; |
| 2269 | loop_scope.continue_block = cond_block; | 2257 | loop_scope.continue_block = cond_block; |
| 2270 | if (while_full.label_token) |label_token| { | 2258 | if (while_full.label_token) |label_token| { |
| 2271 | loop_scope.label = @as(?Scope.GenZir.Label, Scope.GenZir.Label{ | 2259 | loop_scope.label = @as(?GenZir.Label, GenZir.Label{ |
| 2272 | .token = label_token, | 2260 | .token = label_token, |
| 2273 | .block_inst = loop_block, | 2261 | .block_inst = loop_block, |
| 2274 | }); | 2262 | }); |
| 2275 | } | 2263 | } |
| 2276 | | 2264 | |
| 2277 | var then_scope: Scope.GenZir = .{ | 2265 | var then_scope: GenZir = .{ |
| 2278 | .parent = &continue_scope.base, | 2266 | .parent = &continue_scope.base, |
| 2279 | .astgen = parent_gz.astgen, | 2267 | .astgen = parent_gz.astgen, |
| 2280 | .force_comptime = continue_scope.force_comptime, | 2268 | .force_comptime = continue_scope.force_comptime, |
| ... | @@ -2285,9 +2273,9 @@ fn whileExpr( | ... | @@ -2285,9 +2273,9 @@ fn whileExpr( |
| 2285 | const then_sub_scope = &then_scope.base; | 2273 | const then_sub_scope = &then_scope.base; |
| 2286 | | 2274 | |
| 2287 | loop_scope.break_count += 1; | 2275 | loop_scope.break_count += 1; |
| 2288 | const then_result = try expr(mod, then_sub_scope, loop_scope.break_result_loc, while_full.ast.then_expr); | 2276 | const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, while_full.ast.then_expr); |
| 2289 | | 2277 | |
| 2290 | var else_scope: Scope.GenZir = .{ | 2278 | var else_scope: GenZir = .{ |
| 2291 | .parent = &continue_scope.base, | 2279 | .parent = &continue_scope.base, |
| 2292 | .astgen = parent_gz.astgen, | 2280 | .astgen = parent_gz.astgen, |
| 2293 | .force_comptime = continue_scope.force_comptime, | 2281 | .force_comptime = continue_scope.force_comptime, |
| ... | @@ -2304,7 +2292,7 @@ fn whileExpr( | ... | @@ -2304,7 +2292,7 @@ fn whileExpr( |
| 2304 | const sub_scope = &else_scope.base; | 2292 | const sub_scope = &else_scope.base; |
| 2305 | break :blk .{ | 2293 | break :blk .{ |
| 2306 | .src = else_node, | 2294 | .src = else_node, |
| 2307 | .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node), | 2295 | .result = try expr(&else_scope, sub_scope, loop_scope.break_result_loc, else_node), |
| 2308 | }; | 2296 | }; |
| 2309 | } else .{ | 2297 | } else .{ |
| 2310 | .src = while_full.ast.then_expr, | 2298 | .src = while_full.ast.then_expr, |
| ... | @@ -2318,7 +2306,7 @@ fn whileExpr( | ... | @@ -2318,7 +2306,7 @@ fn whileExpr( |
| 2318 | } | 2306 | } |
| 2319 | const break_tag: zir.Inst.Tag = if (is_inline) .break_inline else .@"break"; | 2307 | const break_tag: zir.Inst.Tag = if (is_inline) .break_inline else .@"break"; |
| 2320 | return finishThenElseBlock( | 2308 | return finishThenElseBlock( |
| 2321 | mod, | 2309 | parent_gz, |
| 2322 | scope, | 2310 | scope, |
| 2323 | rl, | 2311 | rl, |
| 2324 | node, | 2312 | node, |
| ... | @@ -2338,22 +2326,22 @@ fn whileExpr( | ... | @@ -2338,22 +2326,22 @@ fn whileExpr( |
| 2338 | } | 2326 | } |
| 2339 | | 2327 | |
| 2340 | fn forExpr( | 2328 | fn forExpr( |
| 2341 | mod: *Module, | 2329 | parent_gz: *GenZir, |
| 2342 | scope: *Scope, | 2330 | scope: *Scope, |
| 2343 | rl: ResultLoc, | 2331 | rl: ResultLoc, |
| 2344 | node: ast.Node.Index, | 2332 | node: ast.Node.Index, |
| 2345 | for_full: ast.full.While, | 2333 | for_full: ast.full.While, |
| 2346 | ) InnerError!zir.Inst.Ref { | 2334 | ) InnerError!zir.Inst.Ref { |
| | 2335 | const mod = parent_gz.astgen.mod; |
| 2347 | if (for_full.label_token) |label_token| { | 2336 | if (for_full.label_token) |label_token| { |
| 2348 | try checkLabelRedefinition(mod, scope, label_token); | 2337 | try checkLabelRedefinition(mod, scope, label_token); |
| 2349 | } | 2338 | } |
| 2350 | // Set up variables and constants. | 2339 | // Set up variables and constants. |
| 2351 | const parent_gz = scope.getGenZir(); | | |
| 2352 | const is_inline = parent_gz.force_comptime or for_full.inline_token != null; | 2340 | const is_inline = parent_gz.force_comptime or for_full.inline_token != null; |
| 2353 | const tree = parent_gz.tree(); | 2341 | const tree = parent_gz.tree(); |
| 2354 | const token_tags = tree.tokens.items(.tag); | 2342 | const token_tags = tree.tokens.items(.tag); |
| 2355 | | 2343 | |
| 2356 | const array_ptr = try expr(mod, scope, .ref, for_full.ast.cond_expr); | 2344 | const array_ptr = try expr(parent_gz, scope, .ref, for_full.ast.cond_expr); |
| 2357 | const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr); | 2345 | const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr); |
| 2358 | | 2346 | |
| 2359 | const index_ptr = blk: { | 2347 | const index_ptr = blk: { |
| ... | @@ -2367,7 +2355,7 @@ fn forExpr( | ... | @@ -2367,7 +2355,7 @@ fn forExpr( |
| 2367 | const loop_block = try parent_gz.addBlock(loop_tag, node); | 2355 | const loop_block = try parent_gz.addBlock(loop_tag, node); |
| 2368 | try parent_gz.instructions.append(mod.gpa, loop_block); | 2356 | try parent_gz.instructions.append(mod.gpa, loop_block); |
| 2369 | | 2357 | |
| 2370 | var loop_scope: Scope.GenZir = .{ | 2358 | var loop_scope: GenZir = .{ |
| 2371 | .parent = scope, | 2359 | .parent = scope, |
| 2372 | .astgen = parent_gz.astgen, | 2360 | .astgen = parent_gz.astgen, |
| 2373 | .force_comptime = parent_gz.force_comptime, | 2361 | .force_comptime = parent_gz.force_comptime, |
| ... | @@ -2376,7 +2364,7 @@ fn forExpr( | ... | @@ -2376,7 +2364,7 @@ fn forExpr( |
| 2376 | loop_scope.setBreakResultLoc(rl); | 2364 | loop_scope.setBreakResultLoc(rl); |
| 2377 | defer loop_scope.instructions.deinit(mod.gpa); | 2365 | defer loop_scope.instructions.deinit(mod.gpa); |
| 2378 | | 2366 | |
| 2379 | var cond_scope: Scope.GenZir = .{ | 2367 | var cond_scope: GenZir = .{ |
| 2380 | .parent = &loop_scope.base, | 2368 | .parent = &loop_scope.base, |
| 2381 | .astgen = parent_gz.astgen, | 2369 | .astgen = parent_gz.astgen, |
| 2382 | .force_comptime = loop_scope.force_comptime, | 2370 | .force_comptime = loop_scope.force_comptime, |
| ... | @@ -2412,13 +2400,13 @@ fn forExpr( | ... | @@ -2412,13 +2400,13 @@ fn forExpr( |
| 2412 | loop_scope.break_block = loop_block; | 2400 | loop_scope.break_block = loop_block; |
| 2413 | loop_scope.continue_block = cond_block; | 2401 | loop_scope.continue_block = cond_block; |
| 2414 | if (for_full.label_token) |label_token| { | 2402 | if (for_full.label_token) |label_token| { |
| 2415 | loop_scope.label = @as(?Scope.GenZir.Label, Scope.GenZir.Label{ | 2403 | loop_scope.label = @as(?GenZir.Label, GenZir.Label{ |
| 2416 | .token = label_token, | 2404 | .token = label_token, |
| 2417 | .block_inst = loop_block, | 2405 | .block_inst = loop_block, |
| 2418 | }); | 2406 | }); |
| 2419 | } | 2407 | } |
| 2420 | | 2408 | |
| 2421 | var then_scope: Scope.GenZir = .{ | 2409 | var then_scope: GenZir = .{ |
| 2422 | .parent = &cond_scope.base, | 2410 | .parent = &cond_scope.base, |
| 2423 | .astgen = parent_gz.astgen, | 2411 | .astgen = parent_gz.astgen, |
| 2424 | .force_comptime = cond_scope.force_comptime, | 2412 | .force_comptime = cond_scope.force_comptime, |
| ... | @@ -2460,9 +2448,9 @@ fn forExpr( | ... | @@ -2460,9 +2448,9 @@ fn forExpr( |
| 2460 | }; | 2448 | }; |
| 2461 | | 2449 | |
| 2462 | loop_scope.break_count += 1; | 2450 | loop_scope.break_count += 1; |
| 2463 | const then_result = try expr(mod, then_sub_scope, loop_scope.break_result_loc, for_full.ast.then_expr); | 2451 | const then_result = try expr(&then_scope, then_sub_scope, loop_scope.break_result_loc, for_full.ast.then_expr); |
| 2464 | | 2452 | |
| 2465 | var else_scope: Scope.GenZir = .{ | 2453 | var else_scope: GenZir = .{ |
| 2466 | .parent = &cond_scope.base, | 2454 | .parent = &cond_scope.base, |
| 2467 | .astgen = parent_gz.astgen, | 2455 | .astgen = parent_gz.astgen, |
| 2468 | .force_comptime = cond_scope.force_comptime, | 2456 | .force_comptime = cond_scope.force_comptime, |
| ... | @@ -2479,7 +2467,7 @@ fn forExpr( | ... | @@ -2479,7 +2467,7 @@ fn forExpr( |
| 2479 | const sub_scope = &else_scope.base; | 2467 | const sub_scope = &else_scope.base; |
| 2480 | break :blk .{ | 2468 | break :blk .{ |
| 2481 | .src = else_node, | 2469 | .src = else_node, |
| 2482 | .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node), | 2470 | .result = try expr(&else_scope, sub_scope, loop_scope.break_result_loc, else_node), |
| 2483 | }; | 2471 | }; |
| 2484 | } else .{ | 2472 | } else .{ |
| 2485 | .src = for_full.ast.then_expr, | 2473 | .src = for_full.ast.then_expr, |
| ... | @@ -2493,7 +2481,7 @@ fn forExpr( | ... | @@ -2493,7 +2481,7 @@ fn forExpr( |
| 2493 | } | 2481 | } |
| 2494 | const break_tag: zir.Inst.Tag = if (is_inline) .break_inline else .@"break"; | 2482 | const break_tag: zir.Inst.Tag = if (is_inline) .break_inline else .@"break"; |
| 2495 | return finishThenElseBlock( | 2483 | return finishThenElseBlock( |
| 2496 | mod, | 2484 | parent_gz, |
| 2497 | scope, | 2485 | scope, |
| 2498 | rl, | 2486 | rl, |
| 2499 | node, | 2487 | node, |
| ... | @@ -2528,7 +2516,7 @@ fn getRangeNode( | ... | @@ -2528,7 +2516,7 @@ fn getRangeNode( |
| 2528 | } | 2516 | } |
| 2529 | | 2517 | |
| 2530 | fn switchExpr( | 2518 | fn switchExpr( |
| 2531 | mod: *Module, | 2519 | gz: *GenZir, |
| 2532 | scope: *Scope, | 2520 | scope: *Scope, |
| 2533 | rl: ResultLoc, | 2521 | rl: ResultLoc, |
| 2534 | switch_node: ast.Node.Index, | 2522 | switch_node: ast.Node.Index, |
| ... | @@ -2548,7 +2536,7 @@ fn switchExpr( | ... | @@ -2548,7 +2536,7 @@ fn switchExpr( |
| 2548 | | 2536 | |
| 2549 | const switch_src = token_starts[switch_token]; | 2537 | const switch_src = token_starts[switch_token]; |
| 2550 | | 2538 | |
| 2551 | var block_scope: Scope.GenZir = .{ | 2539 | var block_scope: GenZir = .{ |
| 2552 | .parent = scope, | 2540 | .parent = scope, |
| 2553 | .decl = scope.ownerDecl().?, | 2541 | .decl = scope.ownerDecl().?, |
| 2554 | .arena = scope.arena(), | 2542 | .arena = scope.arena(), |
| ... | @@ -2647,13 +2635,13 @@ fn switchExpr( | ... | @@ -2647,13 +2635,13 @@ fn switchExpr( |
| 2647 | // Generate all the switch items as comptime expressions. | 2635 | // Generate all the switch items as comptime expressions. |
| 2648 | for (case.ast.values) |item| { | 2636 | for (case.ast.values) |item| { |
| 2649 | if (getRangeNode(node_tags, node_datas, item)) |range| { | 2637 | if (getRangeNode(node_tags, node_datas, item)) |range| { |
| 2650 | const start = try comptimeExpr(mod, &block_scope.base, .none, node_datas[range].lhs); | 2638 | const start = try comptimeExpr(&block_scope, &block_scope.base, .none, node_datas[range].lhs); |
| 2651 | const end = try comptimeExpr(mod, &block_scope.base, .none, node_datas[range].rhs); | 2639 | const end = try comptimeExpr(&block_scope, &block_scope.base, .none, node_datas[range].rhs); |
| 2652 | const range_src = token_starts[main_tokens[range]]; | 2640 | const range_src = token_starts[main_tokens[range]]; |
| 2653 | const range_inst = try addZIRBinOp(mod, &block_scope.base, range_src, .switch_range, start, end); | 2641 | const range_inst = try addZIRBinOp(mod, &block_scope.base, range_src, .switch_range, start, end); |
| 2654 | try items.append(range_inst); | 2642 | try items.append(range_inst); |
| 2655 | } else { | 2643 | } else { |
| 2656 | const item_inst = try comptimeExpr(mod, &block_scope.base, .none, item); | 2644 | const item_inst = try comptimeExpr(&block_scope, &block_scope.base, .none, item); |
| 2657 | try items.append(item_inst); | 2645 | try items.append(item_inst); |
| 2658 | } | 2646 | } |
| 2659 | } | 2647 | } |
| ... | @@ -2671,7 +2659,7 @@ fn switchExpr( | ... | @@ -2671,7 +2659,7 @@ fn switchExpr( |
| 2671 | .rl = .none, | 2659 | .rl = .none, |
| 2672 | .tag = .switchbr, | 2660 | .tag = .switchbr, |
| 2673 | }; | 2661 | }; |
| 2674 | const target = try expr(mod, &block_scope.base, rl_and_tag.rl, target_node); | 2662 | const target = try expr(&block_scope, &block_scope.base, rl_and_tag.rl, target_node); |
| 2675 | const switch_inst = try addZirInstT(mod, &block_scope.base, switch_src, zir.Inst.SwitchBr, rl_and_tag.tag, .{ | 2663 | const switch_inst = try addZirInstT(mod, &block_scope.base, switch_src, zir.Inst.SwitchBr, rl_and_tag.tag, .{ |
| 2676 | .target = target, | 2664 | .target = target, |
| 2677 | .cases = cases, | 2665 | .cases = cases, |
| ... | @@ -2684,7 +2672,7 @@ fn switchExpr( | ... | @@ -2684,7 +2672,7 @@ fn switchExpr( |
| 2684 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), | 2672 | .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items), |
| 2685 | }); | 2673 | }); |
| 2686 | | 2674 | |
| 2687 | var case_scope: Scope.GenZir = .{ | 2675 | var case_scope: GenZir = .{ |
| 2688 | .parent = scope, | 2676 | .parent = scope, |
| 2689 | .decl = block_scope.decl, | 2677 | .decl = block_scope.decl, |
| 2690 | .arena = block_scope.arena, | 2678 | .arena = block_scope.arena, |
| ... | @@ -2693,7 +2681,7 @@ fn switchExpr( | ... | @@ -2693,7 +2681,7 @@ fn switchExpr( |
| 2693 | }; | 2681 | }; |
| 2694 | defer case_scope.instructions.deinit(mod.gpa); | 2682 | defer case_scope.instructions.deinit(mod.gpa); |
| 2695 | | 2683 | |
| 2696 | var else_scope: Scope.GenZir = .{ | 2684 | var else_scope: GenZir = .{ |
| 2697 | .parent = scope, | 2685 | .parent = scope, |
| 2698 | .decl = case_scope.decl, | 2686 | .decl = case_scope.decl, |
| 2699 | .arena = case_scope.arena, | 2687 | .arena = case_scope.arena, |
| ... | @@ -2819,7 +2807,7 @@ fn switchExpr( | ... | @@ -2819,7 +2807,7 @@ fn switchExpr( |
| 2819 | } | 2807 | } |
| 2820 | | 2808 | |
| 2821 | fn switchCaseExpr( | 2809 | fn switchCaseExpr( |
| 2822 | mod: *Module, | 2810 | gz: *GenZir, |
| 2823 | scope: *Scope, | 2811 | scope: *Scope, |
| 2824 | rl: ResultLoc, | 2812 | rl: ResultLoc, |
| 2825 | block: *zir.Inst.Block, | 2813 | block: *zir.Inst.Block, |
| ... | @@ -2849,7 +2837,7 @@ fn switchCaseExpr( | ... | @@ -2849,7 +2837,7 @@ fn switchCaseExpr( |
| 2849 | return mod.failTok(scope, ident, "TODO implement switch value payload", .{}); | 2837 | return mod.failTok(scope, ident, "TODO implement switch value payload", .{}); |
| 2850 | }; | 2838 | }; |
| 2851 | | 2839 | |
| 2852 | const case_body = try expr(mod, sub_scope, rl, case.ast.target_expr); | 2840 | const case_body = try expr(gz, sub_scope, rl, case.ast.target_expr); |
| 2853 | if (!case_body.tag.isNoReturn()) { | 2841 | if (!case_body.tag.isNoReturn()) { |
| 2854 | _ = try addZIRInst(mod, sub_scope, case_src, zir.Inst.Break, .{ | 2842 | _ = try addZIRInst(mod, sub_scope, case_src, zir.Inst.Break, .{ |
| 2855 | .block = block, | 2843 | .block = block, |
| ... | @@ -2858,27 +2846,26 @@ fn switchCaseExpr( | ... | @@ -2858,27 +2846,26 @@ fn switchCaseExpr( |
| 2858 | } | 2846 | } |
| 2859 | } | 2847 | } |
| 2860 | | 2848 | |
| 2861 | fn ret(mod: *Module, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { | 2849 | fn ret(gz: *GenZir, scope: *Scope, node: ast.Node.Index) InnerError!zir.Inst.Ref { |
| 2862 | const tree = scope.tree(); | 2850 | const tree = scope.tree(); |
| 2863 | const node_datas = tree.nodes.items(.data); | 2851 | const node_datas = tree.nodes.items(.data); |
| 2864 | const main_tokens = tree.nodes.items(.main_token); | 2852 | const main_tokens = tree.nodes.items(.main_token); |
| 2865 | | 2853 | |
| 2866 | const operand_node = node_datas[node].lhs; | 2854 | const operand_node = node_datas[node].lhs; |
| 2867 | const gz = scope.getGenZir(); | | |
| 2868 | const operand: zir.Inst.Ref = if (operand_node != 0) operand: { | 2855 | const operand: zir.Inst.Ref = if (operand_node != 0) operand: { |
| 2869 | const rl: ResultLoc = if (nodeMayNeedMemoryLocation(scope, operand_node)) .{ | 2856 | const rl: ResultLoc = if (nodeMayNeedMemoryLocation(scope, operand_node)) .{ |
| 2870 | .ptr = try gz.addNode(.ret_ptr, node), | 2857 | .ptr = try gz.addNode(.ret_ptr, node), |
| 2871 | } else .{ | 2858 | } else .{ |
| 2872 | .ty = try gz.addNode(.ret_type, node), | 2859 | .ty = try gz.addNode(.ret_type, node), |
| 2873 | }; | 2860 | }; |
| 2874 | break :operand try expr(mod, scope, rl, operand_node); | 2861 | break :operand try expr(gz, scope, rl, operand_node); |
| 2875 | } else .void_value; | 2862 | } else .void_value; |
| 2876 | _ = try gz.addUnNode(.ret_node, operand, node); | 2863 | _ = try gz.addUnNode(.ret_node, operand, node); |
| 2877 | return zir.Inst.Ref.unreachable_value; | 2864 | return zir.Inst.Ref.unreachable_value; |
| 2878 | } | 2865 | } |
| 2879 | | 2866 | |
| 2880 | fn identifier( | 2867 | fn identifier( |
| 2881 | mod: *Module, | 2868 | gz: *GenZir, |
| 2882 | scope: *Scope, | 2869 | scope: *Scope, |
| 2883 | rl: ResultLoc, | 2870 | rl: ResultLoc, |
| 2884 | ident: ast.Node.Index, | 2871 | ident: ast.Node.Index, |
| ... | @@ -2886,11 +2873,10 @@ fn identifier( | ... | @@ -2886,11 +2873,10 @@ fn identifier( |
| 2886 | const tracy = trace(@src()); | 2873 | const tracy = trace(@src()); |
| 2887 | defer tracy.end(); | 2874 | defer tracy.end(); |
| 2888 | | 2875 | |
| | 2876 | const mod = gz.astgen.mod; |
| 2889 | const tree = scope.tree(); | 2877 | const tree = scope.tree(); |
| 2890 | const main_tokens = tree.nodes.items(.main_token); | 2878 | const main_tokens = tree.nodes.items(.main_token); |
| 2891 | | 2879 | |
| 2892 | const gz = scope.getGenZir(); | | |
| 2893 | | | |
| 2894 | const ident_token = main_tokens[ident]; | 2880 | const ident_token = main_tokens[ident]; |
| 2895 | const ident_name = try mod.identifierTokenString(scope, ident_token); | 2881 | const ident_name = try mod.identifierTokenString(scope, ident_token); |
| 2896 | if (mem.eql(u8, ident_name, "_")) { | 2882 | if (mem.eql(u8, ident_name, "_")) { |
| ... | @@ -2898,7 +2884,7 @@ fn identifier( | ... | @@ -2898,7 +2884,7 @@ fn identifier( |
| 2898 | } | 2884 | } |
| 2899 | | 2885 | |
| 2900 | if (simple_types.get(ident_name)) |zir_const_ref| { | 2886 | if (simple_types.get(ident_name)) |zir_const_ref| { |
| 2901 | return rvalue(mod, scope, rl, zir_const_ref, ident); | 2887 | return rvalue(gz, scope, rl, zir_const_ref, ident); |
| 2902 | } | 2888 | } |
| 2903 | | 2889 | |
| 2904 | if (ident_name.len >= 2) integer: { | 2890 | if (ident_name.len >= 2) integer: { |
| ... | @@ -2925,7 +2911,7 @@ fn identifier( | ... | @@ -2925,7 +2911,7 @@ fn identifier( |
| 2925 | .bit_count = bit_count, | 2911 | .bit_count = bit_count, |
| 2926 | } }, | 2912 | } }, |
| 2927 | }); | 2913 | }); |
| 2928 | return rvalue(mod, scope, rl, result, ident); | 2914 | return rvalue(gz, scope, rl, result, ident); |
| 2929 | } | 2915 | } |
| 2930 | } | 2916 | } |
| 2931 | | 2917 | |
| ... | @@ -2936,7 +2922,7 @@ fn identifier( | ... | @@ -2936,7 +2922,7 @@ fn identifier( |
| 2936 | .local_val => { | 2922 | .local_val => { |
| 2937 | const local_val = s.cast(Scope.LocalVal).?; | 2923 | const local_val = s.cast(Scope.LocalVal).?; |
| 2938 | if (mem.eql(u8, local_val.name, ident_name)) { | 2924 | if (mem.eql(u8, local_val.name, ident_name)) { |
| 2939 | return rvalue(mod, scope, rl, local_val.inst, ident); | 2925 | return rvalue(gz, scope, rl, local_val.inst, ident); |
| 2940 | } | 2926 | } |
| 2941 | s = local_val.parent; | 2927 | s = local_val.parent; |
| 2942 | }, | 2928 | }, |
| ... | @@ -2945,11 +2931,11 @@ fn identifier( | ... | @@ -2945,11 +2931,11 @@ fn identifier( |
| 2945 | if (mem.eql(u8, local_ptr.name, ident_name)) { | 2931 | if (mem.eql(u8, local_ptr.name, ident_name)) { |
| 2946 | if (rl == .ref) return local_ptr.ptr; | 2932 | if (rl == .ref) return local_ptr.ptr; |
| 2947 | const loaded = try gz.addUnNode(.load, local_ptr.ptr, ident); | 2933 | const loaded = try gz.addUnNode(.load, local_ptr.ptr, ident); |
| 2948 | return rvalue(mod, scope, rl, loaded, ident); | 2934 | return rvalue(gz, scope, rl, loaded, ident); |
| 2949 | } | 2935 | } |
| 2950 | s = local_ptr.parent; | 2936 | s = local_ptr.parent; |
| 2951 | }, | 2937 | }, |
| 2952 | .gen_zir => s = s.cast(Scope.GenZir).?.parent, | 2938 | .gen_zir => s = s.cast(GenZir).?.parent, |
| 2953 | else => break, | 2939 | else => break, |
| 2954 | }; | 2940 | }; |
| 2955 | } | 2941 | } |
| ... | @@ -2963,24 +2949,23 @@ fn identifier( | ... | @@ -2963,24 +2949,23 @@ fn identifier( |
| 2963 | const decl_index = @intCast(u32, gop.index); | 2949 | const decl_index = @intCast(u32, gop.index); |
| 2964 | switch (rl) { | 2950 | switch (rl) { |
| 2965 | .ref => return gz.addDecl(.decl_ref, decl_index, ident), | 2951 | .ref => return gz.addDecl(.decl_ref, decl_index, ident), |
| 2966 | else => return rvalue(mod, scope, rl, try gz.addDecl(.decl_val, decl_index, ident), ident), | 2952 | else => return rvalue(gz, scope, rl, try gz.addDecl(.decl_val, decl_index, ident), ident), |
| 2967 | } | 2953 | } |
| 2968 | } | 2954 | } |
| 2969 | | 2955 | |
| 2970 | fn stringLiteral( | 2956 | fn stringLiteral( |
| 2971 | mod: *Module, | 2957 | gz: *GenZir, |
| 2972 | scope: *Scope, | 2958 | scope: *Scope, |
| 2973 | rl: ResultLoc, | 2959 | rl: ResultLoc, |
| 2974 | node: ast.Node.Index, | 2960 | node: ast.Node.Index, |
| 2975 | ) InnerError!zir.Inst.Ref { | 2961 | ) InnerError!zir.Inst.Ref { |
| 2976 | const tree = scope.tree(); | 2962 | const tree = scope.tree(); |
| 2977 | const main_tokens = tree.nodes.items(.main_token); | 2963 | const main_tokens = tree.nodes.items(.main_token); |
| 2978 | const gz = scope.getGenZir(); | | |
| 2979 | const string_bytes = &gz.astgen.string_bytes; | 2964 | const string_bytes = &gz.astgen.string_bytes; |
| 2980 | const str_index = string_bytes.items.len; | 2965 | const str_index = string_bytes.items.len; |
| 2981 | const str_lit_token = main_tokens[node]; | 2966 | const str_lit_token = main_tokens[node]; |
| 2982 | const token_bytes = tree.tokenSlice(str_lit_token); | 2967 | const token_bytes = tree.tokenSlice(str_lit_token); |
| 2983 | try mod.parseStrLit(scope, str_lit_token, string_bytes, token_bytes, 0); | 2968 | try gz.astgen.mod.parseStrLit(scope, str_lit_token, string_bytes, token_bytes, 0); |
| 2984 | const str_len = string_bytes.items.len - str_index; | 2969 | const str_len = string_bytes.items.len - str_index; |
| 2985 | const result = try gz.add(.{ | 2970 | const result = try gz.add(.{ |
| 2986 | .tag = .str, | 2971 | .tag = .str, |
| ... | @@ -2989,22 +2974,23 @@ fn stringLiteral( | ... | @@ -2989,22 +2974,23 @@ fn stringLiteral( |
| 2989 | .len = @intCast(u32, str_len), | 2974 | .len = @intCast(u32, str_len), |
| 2990 | } }, | 2975 | } }, |
| 2991 | }); | 2976 | }); |
| 2992 | return rvalue(mod, scope, rl, result, node); | 2977 | return rvalue(gz, scope, rl, result, node); |
| 2993 | } | 2978 | } |
| 2994 | | 2979 | |
| 2995 | fn multilineStringLiteral( | 2980 | fn multilineStringLiteral( |
| 2996 | mod: *Module, | 2981 | gz: *GenZir, |
| 2997 | scope: *Scope, | 2982 | scope: *Scope, |
| 2998 | rl: ResultLoc, | 2983 | rl: ResultLoc, |
| 2999 | node: ast.Node.Index, | 2984 | node: ast.Node.Index, |
| 3000 | ) InnerError!zir.Inst.Ref { | 2985 | ) InnerError!zir.Inst.Ref { |
| 3001 | const gz = scope.getGenZir(); | | |
| 3002 | const tree = gz.tree(); | 2986 | const tree = gz.tree(); |
| 3003 | const node_datas = tree.nodes.items(.data); | 2987 | const node_datas = tree.nodes.items(.data); |
| 3004 | const main_tokens = tree.nodes.items(.main_token); | 2988 | const main_tokens = tree.nodes.items(.main_token); |
| 3005 | | 2989 | |
| 3006 | const start = node_datas[node].lhs; | 2990 | const start = node_datas[node].lhs; |
| 3007 | const end = node_datas[node].rhs; | 2991 | const end = node_datas[node].rhs; |
| | 2992 | |
| | 2993 | const gpa = gz.astgen.mod.gpa; |
| 3008 | const string_bytes = &gz.astgen.string_bytes; | 2994 | const string_bytes = &gz.astgen.string_bytes; |
| 3009 | const str_index = string_bytes.items.len; | 2995 | const str_index = string_bytes.items.len; |
| 3010 | | 2996 | |
| ... | @@ -3013,14 +2999,14 @@ fn multilineStringLiteral( | ... | @@ -3013,14 +2999,14 @@ fn multilineStringLiteral( |
| 3013 | { | 2999 | { |
| 3014 | const slice = tree.tokenSlice(tok_i); | 3000 | const slice = tree.tokenSlice(tok_i); |
| 3015 | const line_bytes = slice[2 .. slice.len - 1]; | 3001 | const line_bytes = slice[2 .. slice.len - 1]; |
| 3016 | try string_bytes.appendSlice(mod.gpa, line_bytes); | 3002 | try string_bytes.appendSlice(gpa, line_bytes); |
| 3017 | tok_i += 1; | 3003 | tok_i += 1; |
| 3018 | } | 3004 | } |
| 3019 | // Following lines: each line prepends a newline. | 3005 | // Following lines: each line prepends a newline. |
| 3020 | while (tok_i <= end) : (tok_i += 1) { | 3006 | while (tok_i <= end) : (tok_i += 1) { |
| 3021 | const slice = tree.tokenSlice(tok_i); | 3007 | const slice = tree.tokenSlice(tok_i); |
| 3022 | const line_bytes = slice[2 .. slice.len - 1]; | 3008 | const line_bytes = slice[2 .. slice.len - 1]; |
| 3023 | try string_bytes.ensureCapacity(mod.gpa, string_bytes.items.len + line_bytes.len + 1); | 3009 | try string_bytes.ensureCapacity(gpa, string_bytes.items.len + line_bytes.len + 1); |
| 3024 | string_bytes.appendAssumeCapacity('\n'); | 3010 | string_bytes.appendAssumeCapacity('\n'); |
| 3025 | string_bytes.appendSliceAssumeCapacity(line_bytes); | 3011 | string_bytes.appendSliceAssumeCapacity(line_bytes); |
| 3026 | } | 3012 | } |
| ... | @@ -3031,11 +3017,11 @@ fn multilineStringLiteral( | ... | @@ -3031,11 +3017,11 @@ fn multilineStringLiteral( |
| 3031 | .len = @intCast(u32, string_bytes.items.len - str_index), | 3017 | .len = @intCast(u32, string_bytes.items.len - str_index), |
| 3032 | } }, | 3018 | } }, |
| 3033 | }); | 3019 | }); |
| 3034 | return rvalue(mod, scope, rl, result, node); | 3020 | return rvalue(gz, scope, rl, result, node); |
| 3035 | } | 3021 | } |
| 3036 | | 3022 | |
| 3037 | fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { | 3023 | fn charLiteral(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !zir.Inst.Ref { |
| 3038 | const gz = scope.getGenZir(); | 3024 | const mod = gz.astgen.mod; |
| 3039 | const tree = gz.tree(); | 3025 | const tree = gz.tree(); |
| 3040 | const main_tokens = tree.nodes.items(.main_token); | 3026 | const main_tokens = tree.nodes.items(.main_token); |
| 3041 | const main_token = main_tokens[node]; | 3027 | const main_token = main_tokens[node]; |
| ... | @@ -3051,11 +3037,11 @@ fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) | ... | @@ -3051,11 +3037,11 @@ fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) |
| 3051 | }, | 3037 | }, |
| 3052 | }; | 3038 | }; |
| 3053 | const result = try gz.addInt(value); | 3039 | const result = try gz.addInt(value); |
| 3054 | return rvalue(mod, scope, rl, result, node); | 3040 | return rvalue(gz, scope, rl, result, node); |
| 3055 | } | 3041 | } |
| 3056 | | 3042 | |
| 3057 | fn integerLiteral( | 3043 | fn integerLiteral( |
| 3058 | mod: *Module, | 3044 | gz: *GenZir, |
| 3059 | scope: *Scope, | 3045 | scope: *Scope, |
| 3060 | rl: ResultLoc, | 3046 | rl: ResultLoc, |
| 3061 | node: ast.Node.Index, | 3047 | node: ast.Node.Index, |
| ... | @@ -3064,21 +3050,20 @@ fn integerLiteral( | ... | @@ -3064,21 +3050,20 @@ fn integerLiteral( |
| 3064 | const main_tokens = tree.nodes.items(.main_token); | 3050 | const main_tokens = tree.nodes.items(.main_token); |
| 3065 | const int_token = main_tokens[node]; | 3051 | const int_token = main_tokens[node]; |
| 3066 | const prefixed_bytes = tree.tokenSlice(int_token); | 3052 | const prefixed_bytes = tree.tokenSlice(int_token); |
| 3067 | const gz = scope.getGenZir(); | | |
| 3068 | if (std.fmt.parseInt(u64, prefixed_bytes, 0)) |small_int| { | 3053 | if (std.fmt.parseInt(u64, prefixed_bytes, 0)) |small_int| { |
| 3069 | const result: zir.Inst.Ref = switch (small_int) { | 3054 | const result: zir.Inst.Ref = switch (small_int) { |
| 3070 | 0 => .zero, | 3055 | 0 => .zero, |
| 3071 | 1 => .one, | 3056 | 1 => .one, |
| 3072 | else => try gz.addInt(small_int), | 3057 | else => try gz.addInt(small_int), |
| 3073 | }; | 3058 | }; |
| 3074 | return rvalue(mod, scope, rl, result, node); | 3059 | return rvalue(gz, scope, rl, result, node); |
| 3075 | } else |err| { | 3060 | } else |err| { |
| 3076 | return mod.failNode(scope, node, "TODO implement int literals that don't fit in a u64", .{}); | 3061 | return gz.astgen.mod.failNode(scope, node, "TODO implement int literals that don't fit in a u64", .{}); |
| 3077 | } | 3062 | } |
| 3078 | } | 3063 | } |
| 3079 | | 3064 | |
| 3080 | fn floatLiteral( | 3065 | fn floatLiteral( |
| 3081 | mod: *Module, | 3066 | gz: *GenZir, |
| 3082 | scope: *Scope, | 3067 | scope: *Scope, |
| 3083 | rl: ResultLoc, | 3068 | rl: ResultLoc, |
| 3084 | node: ast.Node.Index, | 3069 | node: ast.Node.Index, |
| ... | @@ -3086,13 +3071,12 @@ fn floatLiteral( | ... | @@ -3086,13 +3071,12 @@ fn floatLiteral( |
| 3086 | const arena = scope.arena(); | 3071 | const arena = scope.arena(); |
| 3087 | const tree = scope.tree(); | 3072 | const tree = scope.tree(); |
| 3088 | const main_tokens = tree.nodes.items(.main_token); | 3073 | const main_tokens = tree.nodes.items(.main_token); |
| 3089 | const gz = scope.getGenZir(); | | |
| 3090 | | 3074 | |
| 3091 | const main_token = main_tokens[node]; | 3075 | const main_token = main_tokens[node]; |
| 3092 | const bytes = tree.tokenSlice(main_token); | 3076 | const bytes = tree.tokenSlice(main_token); |
| 3093 | if (bytes.len > 2 and bytes[1] == 'x') { | 3077 | if (bytes.len > 2 and bytes[1] == 'x') { |
| 3094 | assert(bytes[0] == '0'); // validated by tokenizer | 3078 | assert(bytes[0] == '0'); // validated by tokenizer |
| 3095 | return mod.failTok(scope, main_token, "TODO implement hex floats", .{}); | 3079 | return gz.astgen.mod.failTok(scope, main_token, "TODO implement hex floats", .{}); |
| 3096 | } | 3080 | } |
| 3097 | const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) { | 3081 | const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) { |
| 3098 | error.InvalidCharacter => unreachable, // validated by tokenizer | 3082 | error.InvalidCharacter => unreachable, // validated by tokenizer |
| ... | @@ -3106,23 +3090,23 @@ fn floatLiteral( | ... | @@ -3106,23 +3090,23 @@ fn floatLiteral( |
| 3106 | .tag = .@"const", | 3090 | .tag = .@"const", |
| 3107 | .data = .{ .@"const" = typed_value }, | 3091 | .data = .{ .@"const" = typed_value }, |
| 3108 | }); | 3092 | }); |
| 3109 | return rvalue(mod, scope, rl, result, node); | 3093 | return rvalue(gz, scope, rl, result, node); |
| 3110 | } | 3094 | } |
| 3111 | | 3095 | |
| 3112 | fn asmExpr( | 3096 | fn asmExpr( |
| 3113 | mod: *Module, | 3097 | gz: *GenZir, |
| 3114 | scope: *Scope, | 3098 | scope: *Scope, |
| 3115 | rl: ResultLoc, | 3099 | rl: ResultLoc, |
| 3116 | node: ast.Node.Index, | 3100 | node: ast.Node.Index, |
| 3117 | full: ast.full.Asm, | 3101 | full: ast.full.Asm, |
| 3118 | ) InnerError!zir.Inst.Ref { | 3102 | ) InnerError!zir.Inst.Ref { |
| | 3103 | const mod = gz.astgen.mod; |
| 3119 | const arena = scope.arena(); | 3104 | const arena = scope.arena(); |
| 3120 | const tree = scope.tree(); | 3105 | const tree = scope.tree(); |
| 3121 | const main_tokens = tree.nodes.items(.main_token); | 3106 | const main_tokens = tree.nodes.items(.main_token); |
| 3122 | const node_datas = tree.nodes.items(.data); | 3107 | const node_datas = tree.nodes.items(.data); |
| 3123 | const gz = scope.getGenZir(); | | |
| 3124 | | 3108 | |
| 3125 | const asm_source = try expr(mod, scope, .{ .ty = .const_slice_u8_type }, full.ast.template); | 3109 | const asm_source = try expr(gz, scope, .{ .ty = .const_slice_u8_type }, full.ast.template); |
| 3126 | | 3110 | |
| 3127 | if (full.outputs.len != 0) { | 3111 | if (full.outputs.len != 0) { |
| 3128 | return mod.failTok(scope, full.ast.asm_token, "TODO implement asm with an output", .{}); | 3112 | return mod.failTok(scope, full.ast.asm_token, "TODO implement asm with an output", .{}); |
| ... | @@ -3139,7 +3123,7 @@ fn asmExpr( | ... | @@ -3139,7 +3123,7 @@ fn asmExpr( |
| 3139 | try mod.parseStrLit(scope, constraint_token, string_bytes, token_bytes, 0); | 3123 | try mod.parseStrLit(scope, constraint_token, string_bytes, token_bytes, 0); |
| 3140 | try string_bytes.append(mod.gpa, 0); | 3124 | try string_bytes.append(mod.gpa, 0); |
| 3141 | | 3125 | |
| 3142 | args[i] = try expr(mod, scope, .{ .ty = .usize_type }, node_datas[input].lhs); | 3126 | args[i] = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[input].lhs); |
| 3143 | } | 3127 | } |
| 3144 | | 3128 | |
| 3145 | const tag: zir.Inst.Tag = if (full.volatile_token != null) .asm_volatile else .@"asm"; | 3129 | const tag: zir.Inst.Tag = if (full.volatile_token != null) .asm_volatile else .@"asm"; |
| ... | @@ -3156,11 +3140,11 @@ fn asmExpr( | ... | @@ -3156,11 +3140,11 @@ fn asmExpr( |
| 3156 | gz.astgen.appendRefsAssumeCapacity(args); | 3140 | gz.astgen.appendRefsAssumeCapacity(args); |
| 3157 | gz.astgen.extra.appendSliceAssumeCapacity(constraints); | 3141 | gz.astgen.extra.appendSliceAssumeCapacity(constraints); |
| 3158 | | 3142 | |
| 3159 | return rvalue(mod, scope, rl, result, node); | 3143 | return rvalue(gz, scope, rl, result, node); |
| 3160 | } | 3144 | } |
| 3161 | | 3145 | |
| 3162 | fn as( | 3146 | fn as( |
| 3163 | mod: *Module, | 3147 | gz: *GenZir, |
| 3164 | scope: *Scope, | 3148 | scope: *Scope, |
| 3165 | rl: ResultLoc, | 3149 | rl: ResultLoc, |
| 3166 | builtin_token: ast.TokenIndex, | 3150 | builtin_token: ast.TokenIndex, |
| ... | @@ -3168,33 +3152,33 @@ fn as( | ... | @@ -3168,33 +3152,33 @@ fn as( |
| 3168 | lhs: ast.Node.Index, | 3152 | lhs: ast.Node.Index, |
| 3169 | rhs: ast.Node.Index, | 3153 | rhs: ast.Node.Index, |
| 3170 | ) InnerError!zir.Inst.Ref { | 3154 | ) InnerError!zir.Inst.Ref { |
| 3171 | const dest_type = try typeExpr(mod, scope, lhs); | 3155 | const dest_type = try typeExpr(gz, scope, lhs); |
| 3172 | switch (rl) { | 3156 | switch (rl) { |
| 3173 | .none, .discard, .ref, .ty => { | 3157 | .none, .discard, .ref, .ty => { |
| 3174 | const result = try expr(mod, scope, .{ .ty = dest_type }, rhs); | 3158 | const result = try expr(gz, scope, .{ .ty = dest_type }, rhs); |
| 3175 | return rvalue(mod, scope, rl, result, node); | 3159 | return rvalue(gz, scope, rl, result, node); |
| 3176 | }, | 3160 | }, |
| 3177 | | 3161 | |
| 3178 | .ptr => |result_ptr| { | 3162 | .ptr => |result_ptr| { |
| 3179 | return asRlPtr(mod, scope, rl, result_ptr, rhs, dest_type); | 3163 | return asRlPtr(gz, scope, rl, result_ptr, rhs, dest_type); |
| 3180 | }, | 3164 | }, |
| 3181 | .block_ptr => |block_scope| { | 3165 | .block_ptr => |block_scope| { |
| 3182 | return asRlPtr(mod, scope, rl, block_scope.rl_ptr, rhs, dest_type); | 3166 | return asRlPtr(gz, scope, rl, block_scope.rl_ptr, rhs, dest_type); |
| 3183 | }, | 3167 | }, |
| 3184 | | 3168 | |
| 3185 | .bitcasted_ptr => |bitcasted_ptr| { | 3169 | .bitcasted_ptr => |bitcasted_ptr| { |
| 3186 | // TODO here we should be able to resolve the inference; we now have a type for the result. | 3170 | // TODO here we should be able to resolve the inference; we now have a type for the result. |
| 3187 | return mod.failTok(scope, builtin_token, "TODO implement @as with result location @bitCast", .{}); | 3171 | return gz.astgen.mod.failTok(scope, builtin_token, "TODO implement @as with result location @bitCast", .{}); |
| 3188 | }, | 3172 | }, |
| 3189 | .inferred_ptr => |result_alloc| { | 3173 | .inferred_ptr => |result_alloc| { |
| 3190 | // TODO here we should be able to resolve the inference; we now have a type for the result. | 3174 | // TODO here we should be able to resolve the inference; we now have a type for the result. |
| 3191 | return mod.failTok(scope, builtin_token, "TODO implement @as with inferred-type result location pointer", .{}); | 3175 | return gz.astgen.mod.failTok(scope, builtin_token, "TODO implement @as with inferred-type result location pointer", .{}); |
| 3192 | }, | 3176 | }, |
| 3193 | } | 3177 | } |
| 3194 | } | 3178 | } |
| 3195 | | 3179 | |
| 3196 | fn asRlPtr( | 3180 | fn asRlPtr( |
| 3197 | mod: *Module, | 3181 | parent_gz: *GenZir, |
| 3198 | scope: *Scope, | 3182 | scope: *Scope, |
| 3199 | rl: ResultLoc, | 3183 | rl: ResultLoc, |
| 3200 | result_ptr: zir.Inst.Ref, | 3184 | result_ptr: zir.Inst.Ref, |
| ... | @@ -3204,26 +3188,25 @@ fn asRlPtr( | ... | @@ -3204,26 +3188,25 @@ fn asRlPtr( |
| 3204 | // Detect whether this expr() call goes into rvalue() to store the result into the | 3188 | // Detect whether this expr() call goes into rvalue() to store the result into the |
| 3205 | // result location. If it does, elide the coerce_result_ptr instruction | 3189 | // result location. If it does, elide the coerce_result_ptr instruction |
| 3206 | // as well as the store instruction, instead passing the result as an rvalue. | 3190 | // as well as the store instruction, instead passing the result as an rvalue. |
| 3207 | const parent_gz = scope.getGenZir(); | | |
| 3208 | const astgen = parent_gz.astgen; | 3191 | const astgen = parent_gz.astgen; |
| 3209 | | 3192 | |
| 3210 | var as_scope: Scope.GenZir = .{ | 3193 | var as_scope: GenZir = .{ |
| 3211 | .parent = scope, | 3194 | .parent = scope, |
| 3212 | .astgen = astgen, | 3195 | .astgen = astgen, |
| 3213 | .force_comptime = parent_gz.force_comptime, | 3196 | .force_comptime = parent_gz.force_comptime, |
| 3214 | .instructions = .{}, | 3197 | .instructions = .{}, |
| 3215 | }; | 3198 | }; |
| 3216 | defer as_scope.instructions.deinit(mod.gpa); | 3199 | defer as_scope.instructions.deinit(astgen.mod.gpa); |
| 3217 | | 3200 | |
| 3218 | as_scope.rl_ptr = try as_scope.addBin(.coerce_result_ptr, dest_type, result_ptr); | 3201 | as_scope.rl_ptr = try as_scope.addBin(.coerce_result_ptr, dest_type, result_ptr); |
| 3219 | const result = try expr(mod, &as_scope.base, .{ .block_ptr = &as_scope }, operand_node); | 3202 | const result = try expr(&as_scope, &as_scope.base, .{ .block_ptr = &as_scope }, operand_node); |
| 3220 | const parent_zir = &parent_gz.instructions; | 3203 | const parent_zir = &parent_gz.instructions; |
| 3221 | if (as_scope.rvalue_rl_count == 1) { | 3204 | if (as_scope.rvalue_rl_count == 1) { |
| 3222 | // Busted! This expression didn't actually need a pointer. | 3205 | // Busted! This expression didn't actually need a pointer. |
| 3223 | const zir_tags = astgen.instructions.items(.tag); | 3206 | const zir_tags = astgen.instructions.items(.tag); |
| 3224 | const zir_datas = astgen.instructions.items(.data); | 3207 | const zir_datas = astgen.instructions.items(.data); |
| 3225 | const expected_len = parent_zir.items.len + as_scope.instructions.items.len - 2; | 3208 | const expected_len = parent_zir.items.len + as_scope.instructions.items.len - 2; |
| 3226 | try parent_zir.ensureCapacity(mod.gpa, expected_len); | 3209 | try parent_zir.ensureCapacity(astgen.mod.gpa, expected_len); |
| 3227 | for (as_scope.instructions.items) |src_inst| { | 3210 | for (as_scope.instructions.items) |src_inst| { |
| 3228 | if (astgen.indexToRef(src_inst) == as_scope.rl_ptr) continue; | 3211 | if (astgen.indexToRef(src_inst) == as_scope.rl_ptr) continue; |
| 3229 | if (zir_tags[src_inst] == .store_to_block_ptr) { | 3212 | if (zir_tags[src_inst] == .store_to_block_ptr) { |
| ... | @@ -3233,15 +3216,15 @@ fn asRlPtr( | ... | @@ -3233,15 +3216,15 @@ fn asRlPtr( |
| 3233 | } | 3216 | } |
| 3234 | assert(parent_zir.items.len == expected_len); | 3217 | assert(parent_zir.items.len == expected_len); |
| 3235 | const casted_result = try parent_gz.addBin(.as, dest_type, result); | 3218 | const casted_result = try parent_gz.addBin(.as, dest_type, result); |
| 3236 | return rvalue(mod, scope, rl, casted_result, operand_node); | 3219 | return rvalue(parent_gz, scope, rl, casted_result, operand_node); |
| 3237 | } else { | 3220 | } else { |
| 3238 | try parent_zir.appendSlice(mod.gpa, as_scope.instructions.items); | 3221 | try parent_zir.appendSlice(astgen.mod.gpa, as_scope.instructions.items); |
| 3239 | return result; | 3222 | return result; |
| 3240 | } | 3223 | } |
| 3241 | } | 3224 | } |
| 3242 | | 3225 | |
| 3243 | fn bitCast( | 3226 | fn bitCast( |
| 3244 | mod: *Module, | 3227 | gz: *GenZir, |
| 3245 | scope: *Scope, | 3228 | scope: *Scope, |
| 3246 | rl: ResultLoc, | 3229 | rl: ResultLoc, |
| 3247 | builtin_token: ast.TokenIndex, | 3230 | builtin_token: ast.TokenIndex, |
| ... | @@ -3250,31 +3233,31 @@ fn bitCast( | ... | @@ -3250,31 +3233,31 @@ fn bitCast( |
| 3250 | rhs: ast.Node.Index, | 3233 | rhs: ast.Node.Index, |
| 3251 | ) InnerError!zir.Inst.Ref { | 3234 | ) InnerError!zir.Inst.Ref { |
| 3252 | if (true) @panic("TODO update for zir-memory-layout"); | 3235 | if (true) @panic("TODO update for zir-memory-layout"); |
| 3253 | const dest_type = try typeExpr(mod, scope, lhs); | 3236 | const dest_type = try typeExpr(gz, scope, lhs); |
| 3254 | switch (rl) { | 3237 | switch (rl) { |
| 3255 | .none => { | 3238 | .none => { |
| 3256 | const operand = try expr(mod, scope, .none, rhs); | 3239 | const operand = try expr(gz, scope, .none, rhs); |
| 3257 | return addZIRBinOp(mod, scope, src, .bitcast, dest_type, operand); | 3240 | return addZIRBinOp(mod, scope, src, .bitcast, dest_type, operand); |
| 3258 | }, | 3241 | }, |
| 3259 | .discard => { | 3242 | .discard => { |
| 3260 | const operand = try expr(mod, scope, .none, rhs); | 3243 | const operand = try expr(gz, scope, .none, rhs); |
| 3261 | const result = try addZIRBinOp(mod, scope, src, .bitcast, dest_type, operand); | 3244 | const result = try addZIRBinOp(mod, scope, src, .bitcast, dest_type, operand); |
| 3262 | _ = try addZIRUnOp(mod, scope, result.src, .ensure_result_non_error, result); | 3245 | _ = try addZIRUnOp(mod, scope, result.src, .ensure_result_non_error, result); |
| 3263 | return result; | 3246 | return result; |
| 3264 | }, | 3247 | }, |
| 3265 | .ref => { | 3248 | .ref => { |
| 3266 | const operand = try expr(mod, scope, .ref, rhs); | 3249 | const operand = try expr(gz, scope, .ref, rhs); |
| 3267 | const result = try addZIRBinOp(mod, scope, src, .bitcast_ref, dest_type, operand); | 3250 | const result = try addZIRBinOp(mod, scope, src, .bitcast_ref, dest_type, operand); |
| 3268 | return result; | 3251 | return result; |
| 3269 | }, | 3252 | }, |
| 3270 | .ty => |result_ty| { | 3253 | .ty => |result_ty| { |
| 3271 | const result = try expr(mod, scope, .none, rhs); | 3254 | const result = try expr(gz, scope, .none, rhs); |
| 3272 | const bitcasted = try addZIRBinOp(mod, scope, src, .bitcast, dest_type, result); | 3255 | const bitcasted = try addZIRBinOp(mod, scope, src, .bitcast, dest_type, result); |
| 3273 | return addZIRBinOp(mod, scope, src, .as, result_ty, bitcasted); | 3256 | return addZIRBinOp(mod, scope, src, .as, result_ty, bitcasted); |
| 3274 | }, | 3257 | }, |
| 3275 | .ptr => |result_ptr| { | 3258 | .ptr => |result_ptr| { |
| 3276 | const casted_result_ptr = try addZIRUnOp(mod, scope, src, .bitcast_result_ptr, result_ptr); | 3259 | const casted_result_ptr = try addZIRUnOp(mod, scope, src, .bitcast_result_ptr, result_ptr); |
| 3277 | return expr(mod, scope, .{ .bitcasted_ptr = casted_result_ptr.castTag(.bitcast_result_ptr).? }, rhs); | 3260 | return expr(gz, scope, .{ .bitcasted_ptr = casted_result_ptr.castTag(.bitcast_result_ptr).? }, rhs); |
| 3278 | }, | 3261 | }, |
| 3279 | .bitcasted_ptr => |bitcasted_ptr| { | 3262 | .bitcasted_ptr => |bitcasted_ptr| { |
| 3280 | return mod.failTok(scope, builtin_token, "TODO implement @bitCast with result location another @bitCast", .{}); | 3263 | return mod.failTok(scope, builtin_token, "TODO implement @bitCast with result location another @bitCast", .{}); |
| ... | @@ -3290,7 +3273,7 @@ fn bitCast( | ... | @@ -3290,7 +3273,7 @@ fn bitCast( |
| 3290 | } | 3273 | } |
| 3291 | | 3274 | |
| 3292 | fn typeOf( | 3275 | fn typeOf( |
| 3293 | mod: *Module, | 3276 | gz: *GenZir, |
| 3294 | scope: *Scope, | 3277 | scope: *Scope, |
| 3295 | rl: ResultLoc, | 3278 | rl: ResultLoc, |
| 3296 | builtin_token: ast.TokenIndex, | 3279 | builtin_token: ast.TokenIndex, |
| ... | @@ -3298,22 +3281,16 @@ fn typeOf( | ... | @@ -3298,22 +3281,16 @@ fn typeOf( |
| 3298 | params: []const ast.Node.Index, | 3281 | params: []const ast.Node.Index, |
| 3299 | ) InnerError!zir.Inst.Ref { | 3282 | ) InnerError!zir.Inst.Ref { |
| 3300 | if (params.len < 1) { | 3283 | if (params.len < 1) { |
| 3301 | return mod.failTok(scope, builtin_token, "expected at least 1 argument, found 0", .{}); | 3284 | return gz.astgen.mod.failTok(scope, builtin_token, "expected at least 1 argument, found 0", .{}); |
| 3302 | } | 3285 | } |
| 3303 | const gz = scope.getGenZir(); | | |
| 3304 | if (params.len == 1) { | 3286 | if (params.len == 1) { |
| 3305 | return rvalue( | 3287 | const result = try gz.addUnTok(.typeof, try expr(gz, scope, .none, params[0]), node); |
| 3306 | mod, | 3288 | return rvalue(gz, scope, rl, result, node); |
| 3307 | scope, | | |
| 3308 | rl, | | |
| 3309 | try gz.addUnTok(.typeof, try expr(mod, scope, .none, params[0]), node), | | |
| 3310 | node, | | |
| 3311 | ); | | |
| 3312 | } | 3289 | } |
| 3313 | const arena = scope.arena(); | 3290 | const arena = scope.arena(); |
| 3314 | var items = try arena.alloc(zir.Inst.Ref, params.len); | 3291 | var items = try arena.alloc(zir.Inst.Ref, params.len); |
| 3315 | for (params) |param, param_i| { | 3292 | for (params) |param, param_i| { |
| 3316 | items[param_i] = try expr(mod, scope, .none, param); | 3293 | items[param_i] = try expr(gz, scope, .none, param); |
| 3317 | } | 3294 | } |
| 3318 | | 3295 | |
| 3319 | const result = try gz.addPlNode(.typeof_peer, node, zir.Inst.MultiOp{ | 3296 | const result = try gz.addPlNode(.typeof_peer, node, zir.Inst.MultiOp{ |
| ... | @@ -3321,16 +3298,17 @@ fn typeOf( | ... | @@ -3321,16 +3298,17 @@ fn typeOf( |
| 3321 | }); | 3298 | }); |
| 3322 | try gz.astgen.appendRefs(items); | 3299 | try gz.astgen.appendRefs(items); |
| 3323 | | 3300 | |
| 3324 | return rvalue(mod, scope, rl, result, node); | 3301 | return rvalue(gz, scope, rl, result, node); |
| 3325 | } | 3302 | } |
| 3326 | | 3303 | |
| 3327 | fn builtinCall( | 3304 | fn builtinCall( |
| 3328 | mod: *Module, | 3305 | gz: *GenZir, |
| 3329 | scope: *Scope, | 3306 | scope: *Scope, |
| 3330 | rl: ResultLoc, | 3307 | rl: ResultLoc, |
| 3331 | node: ast.Node.Index, | 3308 | node: ast.Node.Index, |
| 3332 | params: []const ast.Node.Index, | 3309 | params: []const ast.Node.Index, |
| 3333 | ) InnerError!zir.Inst.Ref { | 3310 | ) InnerError!zir.Inst.Ref { |
| | 3311 | const mod = gz.astgen.mod; |
| 3334 | const tree = scope.tree(); | 3312 | const tree = scope.tree(); |
| 3335 | const main_tokens = tree.nodes.items(.main_token); | 3313 | const main_tokens = tree.nodes.items(.main_token); |
| 3336 | | 3314 | |
| ... | @@ -3356,83 +3334,81 @@ fn builtinCall( | ... | @@ -3356,83 +3334,81 @@ fn builtinCall( |
| 3356 | } | 3334 | } |
| 3357 | } | 3335 | } |
| 3358 | | 3336 | |
| 3359 | const gz = scope.getGenZir(); | | |
| 3360 | | | |
| 3361 | switch (info.tag) { | 3337 | switch (info.tag) { |
| 3362 | .ptr_to_int => { | 3338 | .ptr_to_int => { |
| 3363 | const operand = try expr(mod, scope, .none, params[0]); | 3339 | const operand = try expr(gz, scope, .none, params[0]); |
| 3364 | const result = try gz.addUnNode(.ptrtoint, operand, node); | 3340 | const result = try gz.addUnNode(.ptrtoint, operand, node); |
| 3365 | return rvalue(mod, scope, rl, result, node); | 3341 | return rvalue(gz, scope, rl, result, node); |
| 3366 | }, | 3342 | }, |
| 3367 | .float_cast => { | 3343 | .float_cast => { |
| 3368 | const dest_type = try typeExpr(mod, scope, params[0]); | 3344 | const dest_type = try typeExpr(gz, scope, params[0]); |
| 3369 | const rhs = try expr(mod, scope, .none, params[1]); | 3345 | const rhs = try expr(gz, scope, .none, params[1]); |
| 3370 | const result = try gz.addPlNode(.floatcast, node, zir.Inst.Bin{ | 3346 | const result = try gz.addPlNode(.floatcast, node, zir.Inst.Bin{ |
| 3371 | .lhs = dest_type, | 3347 | .lhs = dest_type, |
| 3372 | .rhs = rhs, | 3348 | .rhs = rhs, |
| 3373 | }); | 3349 | }); |
| 3374 | return rvalue(mod, scope, rl, result, node); | 3350 | return rvalue(gz, scope, rl, result, node); |
| 3375 | }, | 3351 | }, |
| 3376 | .int_cast => { | 3352 | .int_cast => { |
| 3377 | const dest_type = try typeExpr(mod, scope, params[0]); | 3353 | const dest_type = try typeExpr(gz, scope, params[0]); |
| 3378 | const rhs = try expr(mod, scope, .none, params[1]); | 3354 | const rhs = try expr(gz, scope, .none, params[1]); |
| 3379 | const result = try gz.addPlNode(.intcast, node, zir.Inst.Bin{ | 3355 | const result = try gz.addPlNode(.intcast, node, zir.Inst.Bin{ |
| 3380 | .lhs = dest_type, | 3356 | .lhs = dest_type, |
| 3381 | .rhs = rhs, | 3357 | .rhs = rhs, |
| 3382 | }); | 3358 | }); |
| 3383 | return rvalue(mod, scope, rl, result, node); | 3359 | return rvalue(gz, scope, rl, result, node); |
| 3384 | }, | 3360 | }, |
| 3385 | .breakpoint => { | 3361 | .breakpoint => { |
| 3386 | const result = try gz.add(.{ | 3362 | const result = try gz.add(.{ |
| 3387 | .tag = .breakpoint, | 3363 | .tag = .breakpoint, |
| 3388 | .data = .{ .node = gz.astgen.decl.nodeIndexToRelative(node) }, | 3364 | .data = .{ .node = gz.astgen.decl.nodeIndexToRelative(node) }, |
| 3389 | }); | 3365 | }); |
| 3390 | return rvalue(mod, scope, rl, result, node); | 3366 | return rvalue(gz, scope, rl, result, node); |
| 3391 | }, | 3367 | }, |
| 3392 | .import => { | 3368 | .import => { |
| 3393 | const target = try expr(mod, scope, .none, params[0]); | 3369 | const target = try expr(gz, scope, .none, params[0]); |
| 3394 | const result = try gz.addUnNode(.import, target, node); | 3370 | const result = try gz.addUnNode(.import, target, node); |
| 3395 | return rvalue(mod, scope, rl, result, node); | 3371 | return rvalue(gz, scope, rl, result, node); |
| 3396 | }, | 3372 | }, |
| 3397 | .compile_error => { | 3373 | .compile_error => { |
| 3398 | const target = try expr(mod, scope, .none, params[0]); | 3374 | const target = try expr(gz, scope, .none, params[0]); |
| 3399 | const result = try gz.addUnNode(.compile_error, target, node); | 3375 | const result = try gz.addUnNode(.compile_error, target, node); |
| 3400 | return rvalue(mod, scope, rl, result, node); | 3376 | return rvalue(gz, scope, rl, result, node); |
| 3401 | }, | 3377 | }, |
| 3402 | .set_eval_branch_quota => { | 3378 | .set_eval_branch_quota => { |
| 3403 | const quota = try expr(mod, scope, .{ .ty = .u32_type }, params[0]); | 3379 | const quota = try expr(gz, scope, .{ .ty = .u32_type }, params[0]); |
| 3404 | const result = try gz.addUnNode(.set_eval_branch_quota, quota, node); | 3380 | const result = try gz.addUnNode(.set_eval_branch_quota, quota, node); |
| 3405 | return rvalue(mod, scope, rl, result, node); | 3381 | return rvalue(gz, scope, rl, result, node); |
| 3406 | }, | 3382 | }, |
| 3407 | .compile_log => { | 3383 | .compile_log => { |
| 3408 | const arg_refs = try mod.gpa.alloc(zir.Inst.Ref, params.len); | 3384 | const arg_refs = try mod.gpa.alloc(zir.Inst.Ref, params.len); |
| 3409 | defer mod.gpa.free(arg_refs); | 3385 | defer mod.gpa.free(arg_refs); |
| 3410 | | 3386 | |
| 3411 | for (params) |param, i| arg_refs[i] = try expr(mod, scope, .none, param); | 3387 | for (params) |param, i| arg_refs[i] = try expr(gz, scope, .none, param); |
| 3412 | | 3388 | |
| 3413 | const result = try gz.addPlNode(.compile_log, node, zir.Inst.MultiOp{ | 3389 | const result = try gz.addPlNode(.compile_log, node, zir.Inst.MultiOp{ |
| 3414 | .operands_len = @intCast(u32, params.len), | 3390 | .operands_len = @intCast(u32, params.len), |
| 3415 | }); | 3391 | }); |
| 3416 | try gz.astgen.appendRefs(arg_refs); | 3392 | try gz.astgen.appendRefs(arg_refs); |
| 3417 | return rvalue(mod, scope, rl, result, node); | 3393 | return rvalue(gz, scope, rl, result, node); |
| 3418 | }, | 3394 | }, |
| 3419 | .field => { | 3395 | .field => { |
| 3420 | const field_name = try comptimeExpr(mod, scope, .{ .ty = .const_slice_u8_type }, params[1]); | 3396 | const field_name = try comptimeExpr(gz, scope, .{ .ty = .const_slice_u8_type }, params[1]); |
| 3421 | if (rl == .ref) { | 3397 | if (rl == .ref) { |
| 3422 | return try gz.addPlNode(.field_ptr_named, node, zir.Inst.FieldNamed{ | 3398 | return try gz.addPlNode(.field_ptr_named, node, zir.Inst.FieldNamed{ |
| 3423 | .lhs = try expr(mod, scope, .ref, params[0]), | 3399 | .lhs = try expr(gz, scope, .ref, params[0]), |
| 3424 | .field_name = field_name, | 3400 | .field_name = field_name, |
| 3425 | }); | 3401 | }); |
| 3426 | } | 3402 | } |
| 3427 | const result = try gz.addPlNode(.field_val_named, node, zir.Inst.FieldNamed{ | 3403 | const result = try gz.addPlNode(.field_val_named, node, zir.Inst.FieldNamed{ |
| 3428 | .lhs = try expr(mod, scope, .none, params[0]), | 3404 | .lhs = try expr(gz, scope, .none, params[0]), |
| 3429 | .field_name = field_name, | 3405 | .field_name = field_name, |
| 3430 | }); | 3406 | }); |
| 3431 | return rvalue(mod, scope, rl, result, node); | 3407 | return rvalue(gz, scope, rl, result, node); |
| 3432 | }, | 3408 | }, |
| 3433 | .as => return as(mod, scope, rl, builtin_token, node, params[0], params[1]), | 3409 | .as => return as(gz, scope, rl, builtin_token, node, params[0], params[1]), |
| 3434 | .bit_cast => return bitCast(mod, scope, rl, builtin_token, node, params[0], params[1]), | 3410 | .bit_cast => return bitCast(gz, scope, rl, builtin_token, node, params[0], params[1]), |
| 3435 | .TypeOf => return typeOf(mod, scope, rl, builtin_token, node, params), | 3411 | .TypeOf => return typeOf(gz, scope, rl, builtin_token, node, params), |
| 3436 | | 3412 | |
| 3437 | .add_with_overflow, | 3413 | .add_with_overflow, |
| 3438 | .align_cast, | 3414 | .align_cast, |
| ... | @@ -3533,21 +3509,21 @@ fn builtinCall( | ... | @@ -3533,21 +3509,21 @@ fn builtinCall( |
| 3533 | } | 3509 | } |
| 3534 | | 3510 | |
| 3535 | fn callExpr( | 3511 | fn callExpr( |
| 3536 | mod: *Module, | 3512 | gz: *GenZir, |
| 3537 | scope: *Scope, | 3513 | scope: *Scope, |
| 3538 | rl: ResultLoc, | 3514 | rl: ResultLoc, |
| 3539 | node: ast.Node.Index, | 3515 | node: ast.Node.Index, |
| 3540 | call: ast.full.Call, | 3516 | call: ast.full.Call, |
| 3541 | ) InnerError!zir.Inst.Ref { | 3517 | ) InnerError!zir.Inst.Ref { |
| | 3518 | const mod = gz.astgen.mod; |
| 3542 | if (call.async_token) |async_token| { | 3519 | if (call.async_token) |async_token| { |
| 3543 | return mod.failTok(scope, async_token, "async and related features are not yet supported", .{}); | 3520 | return mod.failTok(scope, async_token, "async and related features are not yet supported", .{}); |
| 3544 | } | 3521 | } |
| 3545 | const lhs = try expr(mod, scope, .none, call.ast.fn_expr); | 3522 | const lhs = try expr(gz, scope, .none, call.ast.fn_expr); |
| 3546 | | 3523 | |
| 3547 | const args = try mod.gpa.alloc(zir.Inst.Ref, call.ast.params.len); | 3524 | const args = try mod.gpa.alloc(zir.Inst.Ref, call.ast.params.len); |
| 3548 | defer mod.gpa.free(args); | 3525 | defer mod.gpa.free(args); |
| 3549 | | 3526 | |
| 3550 | const gz = scope.getGenZir(); | | |
| 3551 | for (call.ast.params) |param_node, i| { | 3527 | for (call.ast.params) |param_node, i| { |
| 3552 | const param_type = try gz.add(.{ | 3528 | const param_type = try gz.add(.{ |
| 3553 | .tag = .param_type, | 3529 | .tag = .param_type, |
| ... | @@ -3556,7 +3532,7 @@ fn callExpr( | ... | @@ -3556,7 +3532,7 @@ fn callExpr( |
| 3556 | .param_index = @intCast(u32, i), | 3532 | .param_index = @intCast(u32, i), |
| 3557 | } }, | 3533 | } }, |
| 3558 | }); | 3534 | }); |
| 3559 | args[i] = try expr(mod, scope, .{ .ty = param_type }, param_node); | 3535 | args[i] = try expr(gz, scope, .{ .ty = param_type }, param_node); |
| 3560 | } | 3536 | } |
| 3561 | | 3537 | |
| 3562 | const modifier: std.builtin.CallOptions.Modifier = switch (call.async_token != null) { | 3538 | const modifier: std.builtin.CallOptions.Modifier = switch (call.async_token != null) { |
| ... | @@ -3579,7 +3555,7 @@ fn callExpr( | ... | @@ -3579,7 +3555,7 @@ fn callExpr( |
| 3579 | }; | 3555 | }; |
| 3580 | break :res try gz.addCall(tag, lhs, args, node); | 3556 | break :res try gz.addCall(tag, lhs, args, node); |
| 3581 | }; | 3557 | }; |
| 3582 | return rvalue(mod, scope, rl, result, node); // TODO function call with result location | 3558 | return rvalue(gz, scope, rl, result, node); // TODO function call with result location |
| 3583 | } | 3559 | } |
| 3584 | | 3560 | |
| 3585 | pub const simple_types = std.ComptimeStringMap(zir.Inst.Ref, .{ | 3561 | pub const simple_types = std.ComptimeStringMap(zir.Inst.Ref, .{ |
| ... | @@ -3841,13 +3817,12 @@ fn nodeMayNeedMemoryLocation(scope: *Scope, start_node: ast.Node.Index) bool { | ... | @@ -3841,13 +3817,12 @@ fn nodeMayNeedMemoryLocation(scope: *Scope, start_node: ast.Node.Index) bool { |
| 3841 | /// As an example, if the `ResultLoc` is `ptr`, it will write the result to the pointer. | 3817 | /// As an example, if the `ResultLoc` is `ptr`, it will write the result to the pointer. |
| 3842 | /// If the `ResultLoc` is `ty`, it will coerce the result to the type. | 3818 | /// If the `ResultLoc` is `ty`, it will coerce the result to the type. |
| 3843 | fn rvalue( | 3819 | fn rvalue( |
| 3844 | mod: *Module, | 3820 | gz: *GenZir, |
| 3845 | scope: *Scope, | 3821 | scope: *Scope, |
| 3846 | rl: ResultLoc, | 3822 | rl: ResultLoc, |
| 3847 | result: zir.Inst.Ref, | 3823 | result: zir.Inst.Ref, |
| 3848 | src_node: ast.Node.Index, | 3824 | src_node: ast.Node.Index, |
| 3849 | ) InnerError!zir.Inst.Ref { | 3825 | ) InnerError!zir.Inst.Ref { |
| 3850 | const gz = scope.getGenZir(); | | |
| 3851 | switch (rl) { | 3826 | switch (rl) { |
| 3852 | .none => return result, | 3827 | .none => return result, |
| 3853 | .discard => { | 3828 | .discard => { |
| ... | @@ -3933,7 +3908,7 @@ fn rvalue( | ... | @@ -3933,7 +3908,7 @@ fn rvalue( |
| 3933 | return result; | 3908 | return result; |
| 3934 | }, | 3909 | }, |
| 3935 | .bitcasted_ptr => |bitcasted_ptr| { | 3910 | .bitcasted_ptr => |bitcasted_ptr| { |
| 3936 | return mod.failNode(scope, src_node, "TODO implement rvalue .bitcasted_ptr", .{}); | 3911 | return gz.astgen.mod.failNode(scope, src_node, "TODO implement rvalue .bitcasted_ptr", .{}); |
| 3937 | }, | 3912 | }, |
| 3938 | .inferred_ptr => |alloc| { | 3913 | .inferred_ptr => |alloc| { |
| 3939 | _ = try gz.addBin(.store_to_inferred_ptr, alloc, result); | 3914 | _ = try gz.addBin(.store_to_inferred_ptr, alloc, result); |