| author | |
| committer | |
| log | c6076a136099c9a87aa1fee1b797b8c944198c5c |
| tree | ebac2271d5121626c0cde652dbf90ee4523cd148 |
| parent | 7000316113e44ab9c6bdacaef17915d25fb764ed |
| signature |
17 files changed, 609 insertions(+), 621 deletions(-)
src-self-hosted/arg.zig+5-5| ... | ... | @@ -119,9 +119,9 @@ pub const Args = struct { |
| 119 | 119 | |
| 120 | 120 | // MergeN creation disallows 0 length flag entry (doesn't make sense) |
| 121 | 121 | switch (flag_args) { |
| 122 | FlagArg.None => unreachable, | |
| 123 | FlagArg.Single => |inner| try prev.append(inner), | |
| 124 | FlagArg.Many => |inner| try prev.appendSlice(inner.toSliceConst()), | |
| 122 | .None => unreachable, | |
| 123 | .Single => |inner| try prev.append(inner), | |
| 124 | .Many => |inner| try prev.appendSlice(inner.toSliceConst()), | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | _ = try parsed.flags.put(flag_name_trimmed, FlagArg{ .Many = prev }); |
| ... | ... | @@ -158,7 +158,7 @@ pub const Args = struct { |
| 158 | 158 | pub fn single(self: *Args, name: []const u8) ?[]const u8 { |
| 159 | 159 | if (self.flags.get(name)) |entry| { |
| 160 | 160 | switch (entry.value) { |
| 161 | FlagArg.Single => |inner| { | |
| 161 | .Single => |inner| { | |
| 162 | 162 | return inner; |
| 163 | 163 | }, |
| 164 | 164 | else => @panic("attempted to retrieve flag with wrong type"), |
| ... | ... | @@ -172,7 +172,7 @@ pub const Args = struct { |
| 172 | 172 | pub fn many(self: *Args, name: []const u8) []const []const u8 { |
| 173 | 173 | if (self.flags.get(name)) |entry| { |
| 174 | 174 | switch (entry.value) { |
| 175 | FlagArg.Many => |inner| { | |
| 175 | .Many => |inner| { | |
| 176 | 176 | return inner.toSliceConst(); |
| 177 | 177 | }, |
| 178 | 178 | else => @panic("attempted to retrieve flag with wrong type"), |
src-self-hosted/c_int.zig+9-9| ... | ... | @@ -19,56 +19,56 @@ pub const CInt = struct { |
| 19 | 19 | |
| 20 | 20 | pub const list = [_]CInt{ |
| 21 | 21 | CInt{ |
| 22 | .id = Id.Short, | |
| 22 | .id = .Short, | |
| 23 | 23 | .zig_name = "c_short", |
| 24 | 24 | .c_name = "short", |
| 25 | 25 | .is_signed = true, |
| 26 | 26 | }, |
| 27 | 27 | CInt{ |
| 28 | .id = Id.UShort, | |
| 28 | .id = .UShort, | |
| 29 | 29 | .zig_name = "c_ushort", |
| 30 | 30 | .c_name = "unsigned short", |
| 31 | 31 | .is_signed = false, |
| 32 | 32 | }, |
| 33 | 33 | CInt{ |
| 34 | .id = Id.Int, | |
| 34 | .id = .Int, | |
| 35 | 35 | .zig_name = "c_int", |
| 36 | 36 | .c_name = "int", |
| 37 | 37 | .is_signed = true, |
| 38 | 38 | }, |
| 39 | 39 | CInt{ |
| 40 | .id = Id.UInt, | |
| 40 | .id = .UInt, | |
| 41 | 41 | .zig_name = "c_uint", |
| 42 | 42 | .c_name = "unsigned int", |
| 43 | 43 | .is_signed = false, |
| 44 | 44 | }, |
| 45 | 45 | CInt{ |
| 46 | .id = Id.Long, | |
| 46 | .id = .Long, | |
| 47 | 47 | .zig_name = "c_long", |
| 48 | 48 | .c_name = "long", |
| 49 | 49 | .is_signed = true, |
| 50 | 50 | }, |
| 51 | 51 | CInt{ |
| 52 | .id = Id.ULong, | |
| 52 | .id = .ULong, | |
| 53 | 53 | .zig_name = "c_ulong", |
| 54 | 54 | .c_name = "unsigned long", |
| 55 | 55 | .is_signed = false, |
| 56 | 56 | }, |
| 57 | 57 | CInt{ |
| 58 | .id = Id.LongLong, | |
| 58 | .id = .LongLong, | |
| 59 | 59 | .zig_name = "c_longlong", |
| 60 | 60 | .c_name = "long long", |
| 61 | 61 | .is_signed = true, |
| 62 | 62 | }, |
| 63 | 63 | CInt{ |
| 64 | .id = Id.ULongLong, | |
| 64 | .id = .ULongLong, | |
| 65 | 65 | .zig_name = "c_ulonglong", |
| 66 | 66 | .c_name = "unsigned long long", |
| 67 | 67 | .is_signed = false, |
| 68 | 68 | }, |
| 69 | 69 | }; |
| 70 | 70 | |
| 71 | pub fn sizeInBits(id: CInt.Id, self: Target) u32 { | |
| 71 | pub fn sizeInBits(id: Id, self: Target) u32 { | |
| 72 | 72 | const arch = self.getArch(); |
| 73 | 73 | switch (self.getOs()) { |
| 74 | 74 | .freestanding => switch (self.getArch()) { |
src-self-hosted/codegen.zig+16-17| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const Compilation = @import("compilation.zig").Compilation; |
| 4 | 3 | const llvm = @import("llvm.zig"); |
| 5 | 4 | const c = @import("c.zig"); |
| ... | ... | @@ -31,7 +30,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 31 | 30 | llvm.SetTarget(module, comp.llvm_triple.ptr()); |
| 32 | 31 | llvm.SetDataLayout(module, comp.target_layout_str); |
| 33 | 32 | |
| 34 | if (comp.target.getObjectFormat() == builtin.ObjectFormat.coff) { | |
| 33 | if (comp.target.getObjectFormat() == .coff) { | |
| 35 | 34 | llvm.AddModuleCodeViewFlag(module); |
| 36 | 35 | } else { |
| 37 | 36 | llvm.AddModuleDebugInfoFlag(module); |
| ... | ... | @@ -59,7 +58,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 59 | 58 | comp.name.ptr(), |
| 60 | 59 | comp.root_package.root_src_dir.ptr(), |
| 61 | 60 | ) orelse return error.OutOfMemory; |
| 62 | const is_optimized = comp.build_mode != builtin.Mode.Debug; | |
| 61 | const is_optimized = comp.build_mode != .Debug; | |
| 63 | 62 | const compile_unit = llvm.CreateCompileUnit( |
| 64 | 63 | dibuilder, |
| 65 | 64 | DW.LANG_C99, |
| ... | ... | @@ -105,8 +104,8 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 105 | 104 | |
| 106 | 105 | assert(comp.emit_file_type == Compilation.Emit.Binary); // TODO support other types |
| 107 | 106 | |
| 108 | const is_small = comp.build_mode == builtin.Mode.ReleaseSmall; | |
| 109 | const is_debug = comp.build_mode == builtin.Mode.Debug; | |
| 107 | const is_small = comp.build_mode == .ReleaseSmall; | |
| 108 | const is_debug = comp.build_mode == .Debug; | |
| 110 | 109 | |
| 111 | 110 | var err_msg: [*]u8 = undefined; |
| 112 | 111 | // TODO integrate this with evented I/O |
| ... | ... | @@ -114,7 +113,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 114 | 113 | comp.target_machine, |
| 115 | 114 | module, |
| 116 | 115 | output_path.ptr(), |
| 117 | llvm.EmitBinary, | |
| 116 | .EmitBinary, | |
| 118 | 117 | &err_msg, |
| 119 | 118 | is_debug, |
| 120 | 119 | is_small, |
| ... | ... | @@ -234,8 +233,8 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 234 | 233 | // create debug variable declarations for variables and allocate all local variables |
| 235 | 234 | for (var_list) |var_scope, i| { |
| 236 | 235 | const var_type = switch (var_scope.data) { |
| 237 | Scope.Var.Data.Const => unreachable, | |
| 238 | Scope.Var.Data.Param => |param| param.typ, | |
| 236 | .Const => unreachable, | |
| 237 | .Param => |param| param.typ, | |
| 239 | 238 | }; |
| 240 | 239 | // if (!type_has_bits(var->value->type)) { |
| 241 | 240 | // continue; |
| ... | ... | @@ -266,7 +265,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 266 | 265 | var_scope.data.Param.llvm_value = llvm.GetParam(llvm_fn, @intCast(c_uint, i)); |
| 267 | 266 | } else { |
| 268 | 267 | // gen_type = var->value->type; |
| 269 | var_scope.data.Param.llvm_value = try renderAlloca(ofile, var_type, var_scope.name, Type.Pointer.Align.Abi); | |
| 268 | var_scope.data.Param.llvm_value = try renderAlloca(ofile, var_type, var_scope.name, .Abi); | |
| 270 | 269 | } |
| 271 | 270 | // if (var->decl_node) { |
| 272 | 271 | // var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope), |
| ... | ... | @@ -300,8 +299,8 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 300 | 299 | ofile, |
| 301 | 300 | llvm_param, |
| 302 | 301 | scope_var.data.Param.llvm_value, |
| 303 | Type.Pointer.Align.Abi, | |
| 304 | Type.Pointer.Vol.Non, | |
| 302 | .Abi, | |
| 303 | .Non, | |
| 305 | 304 | ); |
| 306 | 305 | } |
| 307 | 306 | |
| ... | ... | @@ -383,8 +382,8 @@ fn renderLoadUntyped( |
| 383 | 382 | ) !*llvm.Value { |
| 384 | 383 | const result = llvm.BuildLoad(ofile.builder, ptr, name) orelse return error.OutOfMemory; |
| 385 | 384 | switch (vol) { |
| 386 | Type.Pointer.Vol.Non => {}, | |
| 387 | Type.Pointer.Vol.Volatile => llvm.SetVolatile(result, 1), | |
| 385 | .Non => {}, | |
| 386 | .Volatile => llvm.SetVolatile(result, 1), | |
| 388 | 387 | } |
| 389 | 388 | llvm.SetAlignment(result, resolveAlign(ofile, alignment, llvm.GetElementType(llvm.TypeOf(ptr)))); |
| 390 | 389 | return result; |
| ... | ... | @@ -414,8 +413,8 @@ pub fn renderStoreUntyped( |
| 414 | 413 | ) !*llvm.Value { |
| 415 | 414 | const result = llvm.BuildStore(ofile.builder, value, ptr) orelse return error.OutOfMemory; |
| 416 | 415 | switch (vol) { |
| 417 | Type.Pointer.Vol.Non => {}, | |
| 418 | Type.Pointer.Vol.Volatile => llvm.SetVolatile(result, 1), | |
| 416 | .Non => {}, | |
| 417 | .Volatile => llvm.SetVolatile(result, 1), | |
| 419 | 418 | } |
| 420 | 419 | llvm.SetAlignment(result, resolveAlign(ofile, alignment, llvm.TypeOf(value))); |
| 421 | 420 | return result; |
| ... | ... | @@ -445,7 +444,7 @@ pub fn renderAlloca( |
| 445 | 444 | |
| 446 | 445 | pub fn resolveAlign(ofile: *ObjectFile, alignment: Type.Pointer.Align, llvm_type: *llvm.Type) u32 { |
| 447 | 446 | return switch (alignment) { |
| 448 | Type.Pointer.Align.Abi => return llvm.ABIAlignmentOfType(ofile.comp.target_data_ref, llvm_type), | |
| 449 | Type.Pointer.Align.Override => |a| a, | |
| 447 | .Abi => return llvm.ABIAlignmentOfType(ofile.comp.target_data_ref, llvm_type), | |
| 448 | .Override => |a| a, | |
| 450 | 449 | }; |
| 451 | 450 | } |
src-self-hosted/compilation.zig+29-29| ... | ... | @@ -5,7 +5,7 @@ const Allocator = mem.Allocator; |
| 5 | 5 | const Buffer = std.Buffer; |
| 6 | 6 | const llvm = @import("llvm.zig"); |
| 7 | 7 | const c = @import("c.zig"); |
| 8 | const builtin = @import("builtin"); | |
| 8 | const builtin = std.builtin; | |
| 9 | 9 | const Target = std.Target; |
| 10 | 10 | const warn = std.debug.warn; |
| 11 | 11 | const Token = std.zig.Token; |
| ... | ... | @@ -481,7 +481,7 @@ pub const Compilation = struct { |
| 481 | 481 | comp.zig_std_dir = try std.fs.path.join(comp.arena(), [_][]const u8{ zig_lib_dir, "std" }); |
| 482 | 482 | |
| 483 | 483 | const opt_level = switch (build_mode) { |
| 484 | builtin.Mode.Debug => llvm.CodeGenLevelNone, | |
| 484 | .Debug => llvm.CodeGenLevelNone, | |
| 485 | 485 | else => llvm.CodeGenLevelAggressive, |
| 486 | 486 | }; |
| 487 | 487 | |
| ... | ... | @@ -594,11 +594,11 @@ pub const Compilation = struct { |
| 594 | 594 | .base = Type{ |
| 595 | 595 | .name = "type", |
| 596 | 596 | .base = Value{ |
| 597 | .id = Value.Id.Type, | |
| 597 | .id = .Type, | |
| 598 | 598 | .typ = undefined, |
| 599 | 599 | .ref_count = std.atomic.Int(usize).init(3), // 3 because it references itself twice |
| 600 | 600 | }, |
| 601 | .id = builtin.TypeId.Type, | |
| 601 | .id = .Type, | |
| 602 | 602 | .abi_alignment = Type.AbiAlignment.init(), |
| 603 | 603 | }, |
| 604 | 604 | .value = undefined, |
| ... | ... | @@ -612,11 +612,11 @@ pub const Compilation = struct { |
| 612 | 612 | .base = Type{ |
| 613 | 613 | .name = "void", |
| 614 | 614 | .base = Value{ |
| 615 | .id = Value.Id.Type, | |
| 615 | .id = .Type, | |
| 616 | 616 | .typ = &Type.MetaType.get(comp).base, |
| 617 | 617 | .ref_count = std.atomic.Int(usize).init(1), |
| 618 | 618 | }, |
| 619 | .id = builtin.TypeId.Void, | |
| 619 | .id = .Void, | |
| 620 | 620 | .abi_alignment = Type.AbiAlignment.init(), |
| 621 | 621 | }, |
| 622 | 622 | }; |
| ... | ... | @@ -627,11 +627,11 @@ pub const Compilation = struct { |
| 627 | 627 | .base = Type{ |
| 628 | 628 | .name = "noreturn", |
| 629 | 629 | .base = Value{ |
| 630 | .id = Value.Id.Type, | |
| 630 | .id = .Type, | |
| 631 | 631 | .typ = &Type.MetaType.get(comp).base, |
| 632 | 632 | .ref_count = std.atomic.Int(usize).init(1), |
| 633 | 633 | }, |
| 634 | .id = builtin.TypeId.NoReturn, | |
| 634 | .id = .NoReturn, | |
| 635 | 635 | .abi_alignment = Type.AbiAlignment.init(), |
| 636 | 636 | }, |
| 637 | 637 | }; |
| ... | ... | @@ -642,11 +642,11 @@ pub const Compilation = struct { |
| 642 | 642 | .base = Type{ |
| 643 | 643 | .name = "comptime_int", |
| 644 | 644 | .base = Value{ |
| 645 | .id = Value.Id.Type, | |
| 645 | .id = .Type, | |
| 646 | 646 | .typ = &Type.MetaType.get(comp).base, |
| 647 | 647 | .ref_count = std.atomic.Int(usize).init(1), |
| 648 | 648 | }, |
| 649 | .id = builtin.TypeId.ComptimeInt, | |
| 649 | .id = .ComptimeInt, | |
| 650 | 650 | .abi_alignment = Type.AbiAlignment.init(), |
| 651 | 651 | }, |
| 652 | 652 | }; |
| ... | ... | @@ -657,11 +657,11 @@ pub const Compilation = struct { |
| 657 | 657 | .base = Type{ |
| 658 | 658 | .name = "bool", |
| 659 | 659 | .base = Value{ |
| 660 | .id = Value.Id.Type, | |
| 660 | .id = .Type, | |
| 661 | 661 | .typ = &Type.MetaType.get(comp).base, |
| 662 | 662 | .ref_count = std.atomic.Int(usize).init(1), |
| 663 | 663 | }, |
| 664 | .id = builtin.TypeId.Bool, | |
| 664 | .id = .Bool, | |
| 665 | 665 | .abi_alignment = Type.AbiAlignment.init(), |
| 666 | 666 | }, |
| 667 | 667 | }; |
| ... | ... | @@ -670,7 +670,7 @@ pub const Compilation = struct { |
| 670 | 670 | comp.void_value = try comp.arena().create(Value.Void); |
| 671 | 671 | comp.void_value.* = Value.Void{ |
| 672 | 672 | .base = Value{ |
| 673 | .id = Value.Id.Void, | |
| 673 | .id = .Void, | |
| 674 | 674 | .typ = &Type.Void.get(comp).base, |
| 675 | 675 | .ref_count = std.atomic.Int(usize).init(1), |
| 676 | 676 | }, |
| ... | ... | @@ -679,7 +679,7 @@ pub const Compilation = struct { |
| 679 | 679 | comp.true_value = try comp.arena().create(Value.Bool); |
| 680 | 680 | comp.true_value.* = Value.Bool{ |
| 681 | 681 | .base = Value{ |
| 682 | .id = Value.Id.Bool, | |
| 682 | .id = .Bool, | |
| 683 | 683 | .typ = &Type.Bool.get(comp).base, |
| 684 | 684 | .ref_count = std.atomic.Int(usize).init(1), |
| 685 | 685 | }, |
| ... | ... | @@ -689,7 +689,7 @@ pub const Compilation = struct { |
| 689 | 689 | comp.false_value = try comp.arena().create(Value.Bool); |
| 690 | 690 | comp.false_value.* = Value.Bool{ |
| 691 | 691 | .base = Value{ |
| 692 | .id = Value.Id.Bool, | |
| 692 | .id = .Bool, | |
| 693 | 693 | .typ = &Type.Bool.get(comp).base, |
| 694 | 694 | .ref_count = std.atomic.Int(usize).init(1), |
| 695 | 695 | }, |
| ... | ... | @@ -699,7 +699,7 @@ pub const Compilation = struct { |
| 699 | 699 | comp.noreturn_value = try comp.arena().create(Value.NoReturn); |
| 700 | 700 | comp.noreturn_value.* = Value.NoReturn{ |
| 701 | 701 | .base = Value{ |
| 702 | .id = Value.Id.NoReturn, | |
| 702 | .id = .NoReturn, | |
| 703 | 703 | .typ = &Type.NoReturn.get(comp).base, |
| 704 | 704 | .ref_count = std.atomic.Int(usize).init(1), |
| 705 | 705 | }, |
| ... | ... | @@ -711,11 +711,11 @@ pub const Compilation = struct { |
| 711 | 711 | .base = Type{ |
| 712 | 712 | .name = cint.zig_name, |
| 713 | 713 | .base = Value{ |
| 714 | .id = Value.Id.Type, | |
| 714 | .id = .Type, | |
| 715 | 715 | .typ = &Type.MetaType.get(comp).base, |
| 716 | 716 | .ref_count = std.atomic.Int(usize).init(1), |
| 717 | 717 | }, |
| 718 | .id = builtin.TypeId.Int, | |
| 718 | .id = .Int, | |
| 719 | 719 | .abi_alignment = Type.AbiAlignment.init(), |
| 720 | 720 | }, |
| 721 | 721 | .key = Type.Int.Key{ |
| ... | ... | @@ -732,11 +732,11 @@ pub const Compilation = struct { |
| 732 | 732 | .base = Type{ |
| 733 | 733 | .name = "u8", |
| 734 | 734 | .base = Value{ |
| 735 | .id = Value.Id.Type, | |
| 735 | .id = .Type, | |
| 736 | 736 | .typ = &Type.MetaType.get(comp).base, |
| 737 | 737 | .ref_count = std.atomic.Int(usize).init(1), |
| 738 | 738 | }, |
| 739 | .id = builtin.TypeId.Int, | |
| 739 | .id = .Int, | |
| 740 | 740 | .abi_alignment = Type.AbiAlignment.init(), |
| 741 | 741 | }, |
| 742 | 742 | .key = Type.Int.Key{ |
| ... | ... | @@ -884,15 +884,15 @@ pub const Compilation = struct { |
| 884 | 884 | while (ast_it.next()) |decl_ptr| { |
| 885 | 885 | const decl = decl_ptr.*; |
| 886 | 886 | switch (decl.id) { |
| 887 | ast.Node.Id.Comptime => { | |
| 887 | .Comptime => { | |
| 888 | 888 | const comptime_node = @fieldParentPtr(ast.Node.Comptime, "base", decl); |
| 889 | 889 | |
| 890 | 890 | // TODO connect existing comptime decls to updated source files |
| 891 | 891 | |
| 892 | 892 | try self.prelink_group.call(addCompTimeBlock, self, tree_scope, &decl_scope.base, comptime_node); |
| 893 | 893 | }, |
| 894 | ast.Node.Id.VarDecl => @panic("TODO"), | |
| 895 | ast.Node.Id.FnProto => { | |
| 894 | .VarDecl => @panic("TODO"), | |
| 895 | .FnProto => { | |
| 896 | 896 | const fn_proto = @fieldParentPtr(ast.Node.FnProto, "base", decl); |
| 897 | 897 | |
| 898 | 898 | const name = if (fn_proto.name_token) |name_token| tree_scope.tree.tokenSlice(name_token) else { |
| ... | ... | @@ -945,7 +945,7 @@ pub const Compilation = struct { |
| 945 | 945 | try group.call(addTopLevelDecl, self, &fn_decl.base, locked_table); |
| 946 | 946 | } |
| 947 | 947 | }, |
| 948 | ast.Node.Id.TestDecl => @panic("TODO"), | |
| 948 | .TestDecl => @panic("TODO"), | |
| 949 | 949 | else => unreachable, |
| 950 | 950 | } |
| 951 | 951 | } |
| ... | ... | @@ -1285,12 +1285,12 @@ fn parseVisibToken(tree: *ast.Tree, optional_token_index: ?ast.TokenIndex) Visib |
| 1285 | 1285 | /// The function that actually does the generation. |
| 1286 | 1286 | async fn generateDecl(comp: *Compilation, decl: *Decl) !void { |
| 1287 | 1287 | switch (decl.id) { |
| 1288 | Decl.Id.Var => @panic("TODO"), | |
| 1289 | Decl.Id.Fn => { | |
| 1288 | .Var => @panic("TODO"), | |
| 1289 | .Fn => { | |
| 1290 | 1290 | const fn_decl = @fieldParentPtr(Decl.Fn, "base", decl); |
| 1291 | 1291 | return generateDeclFn(comp, fn_decl); |
| 1292 | 1292 | }, |
| 1293 | Decl.Id.CompTime => @panic("TODO"), | |
| 1293 | .CompTime => @panic("TODO"), | |
| 1294 | 1294 | } |
| 1295 | 1295 | } |
| 1296 | 1296 | |
| ... | ... | @@ -1385,8 +1385,8 @@ async fn analyzeFnType( |
| 1385 | 1385 | fn_proto: *ast.Node.FnProto, |
| 1386 | 1386 | ) !*Type.Fn { |
| 1387 | 1387 | const return_type_node = switch (fn_proto.return_type) { |
| 1388 | ast.Node.FnProto.ReturnType.Explicit => |n| n, | |
| 1389 | ast.Node.FnProto.ReturnType.InferErrorSet => |n| n, | |
| 1388 | .Explicit => |n| n, | |
| 1389 | .InferErrorSet => |n| n, | |
| 1390 | 1390 | }; |
| 1391 | 1391 | const return_type = try comp.analyzeTypeExpr(tree_scope, scope, return_type_node); |
| 1392 | 1392 | return_type.base.deref(comp); |
src-self-hosted/decl.zig+8-11| ... | ... | @@ -29,7 +29,7 @@ pub const Decl = struct { |
| 29 | 29 | |
| 30 | 30 | pub fn isExported(base: *const Decl, tree: *ast.Tree) bool { |
| 31 | 31 | switch (base.id) { |
| 32 | Id.Fn => { | |
| 32 | .Fn => { | |
| 33 | 33 | const fn_decl = @fieldParentPtr(Fn, "base", base); |
| 34 | 34 | return fn_decl.isExported(tree); |
| 35 | 35 | }, |
| ... | ... | @@ -39,7 +39,7 @@ pub const Decl = struct { |
| 39 | 39 | |
| 40 | 40 | pub fn getSpan(base: *const Decl) errmsg.Span { |
| 41 | 41 | switch (base.id) { |
| 42 | Id.Fn => { | |
| 42 | .Fn => { | |
| 43 | 43 | const fn_decl = @fieldParentPtr(Fn, "base", base); |
| 44 | 44 | const fn_proto = fn_decl.fn_proto; |
| 45 | 45 | const start = fn_proto.fn_token; |
| ... | ... | @@ -69,21 +69,18 @@ pub const Decl = struct { |
| 69 | 69 | |
| 70 | 70 | pub const Fn = struct { |
| 71 | 71 | base: Decl, |
| 72 | value: Val, | |
| 73 | fn_proto: *ast.Node.FnProto, | |
| 74 | ||
| 75 | // TODO https://github.com/ziglang/zig/issues/683 and then make this anonymous | |
| 76 | pub const Val = union(enum) { | |
| 77 | Unresolved: void, | |
| 72 | value: union(enum) { | |
| 73 | Unresolved, | |
| 78 | 74 | Fn: *Value.Fn, |
| 79 | 75 | FnProto: *Value.FnProto, |
| 80 | }; | |
| 76 | }, | |
| 77 | fn_proto: *ast.Node.FnProto, | |
| 81 | 78 | |
| 82 | 79 | pub fn externLibName(self: Fn, tree: *ast.Tree) ?[]const u8 { |
| 83 | 80 | return if (self.fn_proto.extern_export_inline_token) |tok_index| x: { |
| 84 | 81 | const token = tree.tokens.at(tok_index); |
| 85 | 82 | break :x switch (token.id) { |
| 86 | Token.Id.Extern => tree.tokenSlicePtr(token), | |
| 83 | .Extern => tree.tokenSlicePtr(token), | |
| 87 | 84 | else => null, |
| 88 | 85 | }; |
| 89 | 86 | } else null; |
| ... | ... | @@ -92,7 +89,7 @@ pub const Decl = struct { |
| 92 | 89 | pub fn isExported(self: Fn, tree: *ast.Tree) bool { |
| 93 | 90 | if (self.fn_proto.extern_export_inline_token) |tok_index| { |
| 94 | 91 | const token = tree.tokens.at(tok_index); |
| 95 | return token.id == Token.Id.Keyword_export; | |
| 92 | return token.id == .Keyword_export; | |
| 96 | 93 | } else { |
| 97 | 94 | return false; |
| 98 | 95 | } |
src-self-hosted/errmsg.zig+16-16| ... | ... | @@ -62,17 +62,17 @@ pub const Msg = struct { |
| 62 | 62 | |
| 63 | 63 | pub fn destroy(self: *Msg) void { |
| 64 | 64 | switch (self.data) { |
| 65 | Data.Cli => |cli| { | |
| 65 | .Cli => |cli| { | |
| 66 | 66 | cli.allocator.free(self.text); |
| 67 | 67 | cli.allocator.free(self.realpath); |
| 68 | 68 | cli.allocator.destroy(self); |
| 69 | 69 | }, |
| 70 | Data.PathAndTree => |path_and_tree| { | |
| 70 | .PathAndTree => |path_and_tree| { | |
| 71 | 71 | path_and_tree.allocator.free(self.text); |
| 72 | 72 | path_and_tree.allocator.free(self.realpath); |
| 73 | 73 | path_and_tree.allocator.destroy(self); |
| 74 | 74 | }, |
| 75 | Data.ScopeAndComp => |scope_and_comp| { | |
| 75 | .ScopeAndComp => |scope_and_comp| { | |
| 76 | 76 | scope_and_comp.tree_scope.base.deref(scope_and_comp.compilation); |
| 77 | 77 | scope_and_comp.compilation.gpa().free(self.text); |
| 78 | 78 | scope_and_comp.compilation.gpa().free(self.realpath); |
| ... | ... | @@ -83,11 +83,11 @@ pub const Msg = struct { |
| 83 | 83 | |
| 84 | 84 | fn getAllocator(self: *const Msg) *mem.Allocator { |
| 85 | 85 | switch (self.data) { |
| 86 | Data.Cli => |cli| return cli.allocator, | |
| 87 | Data.PathAndTree => |path_and_tree| { | |
| 86 | .Cli => |cli| return cli.allocator, | |
| 87 | .PathAndTree => |path_and_tree| { | |
| 88 | 88 | return path_and_tree.allocator; |
| 89 | 89 | }, |
| 90 | Data.ScopeAndComp => |scope_and_comp| { | |
| 90 | .ScopeAndComp => |scope_and_comp| { | |
| 91 | 91 | return scope_and_comp.compilation.gpa(); |
| 92 | 92 | }, |
| 93 | 93 | } |
| ... | ... | @@ -95,11 +95,11 @@ pub const Msg = struct { |
| 95 | 95 | |
| 96 | 96 | pub fn getTree(self: *const Msg) *ast.Tree { |
| 97 | 97 | switch (self.data) { |
| 98 | Data.Cli => unreachable, | |
| 99 | Data.PathAndTree => |path_and_tree| { | |
| 98 | .Cli => unreachable, | |
| 99 | .PathAndTree => |path_and_tree| { | |
| 100 | 100 | return path_and_tree.tree; |
| 101 | 101 | }, |
| 102 | Data.ScopeAndComp => |scope_and_comp| { | |
| 102 | .ScopeAndComp => |scope_and_comp| { | |
| 103 | 103 | return scope_and_comp.tree_scope.tree; |
| 104 | 104 | }, |
| 105 | 105 | } |
| ... | ... | @@ -107,9 +107,9 @@ pub const Msg = struct { |
| 107 | 107 | |
| 108 | 108 | pub fn getSpan(self: *const Msg) Span { |
| 109 | 109 | return switch (self.data) { |
| 110 | Data.Cli => unreachable, | |
| 111 | Data.PathAndTree => |path_and_tree| path_and_tree.span, | |
| 112 | Data.ScopeAndComp => |scope_and_comp| scope_and_comp.span, | |
| 110 | .Cli => unreachable, | |
| 111 | .PathAndTree => |path_and_tree| path_and_tree.span, | |
| 112 | .ScopeAndComp => |scope_and_comp| scope_and_comp.span, | |
| 113 | 113 | }; |
| 114 | 114 | } |
| 115 | 115 | |
| ... | ... | @@ -230,7 +230,7 @@ pub const Msg = struct { |
| 230 | 230 | |
| 231 | 231 | pub fn printToStream(msg: *const Msg, stream: var, color_on: bool) !void { |
| 232 | 232 | switch (msg.data) { |
| 233 | Data.Cli => { | |
| 233 | .Cli => { | |
| 234 | 234 | try stream.print("{}:-:-: error: {}\n", msg.realpath, msg.text); |
| 235 | 235 | return; |
| 236 | 236 | }, |
| ... | ... | @@ -279,9 +279,9 @@ pub const Msg = struct { |
| 279 | 279 | |
| 280 | 280 | pub fn printToFile(msg: *const Msg, file: fs.File, color: Color) !void { |
| 281 | 281 | const color_on = switch (color) { |
| 282 | Color.Auto => file.isTty(), | |
| 283 | Color.On => true, | |
| 284 | Color.Off => false, | |
| 282 | .Auto => file.isTty(), | |
| 283 | .On => true, | |
| 284 | .Off => false, | |
| 285 | 285 | }; |
| 286 | 286 | var stream = &file.outStream().stream; |
| 287 | 287 | return msg.printToStream(stream, color_on); |
src-self-hosted/ir.zig+203-204| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const Compilation = @import("compilation.zig").Compilation; |
| 4 | 3 | const Scope = @import("scope.zig").Scope; |
| 5 | 4 | const ast = std.zig.ast; |
| ... | ... | @@ -33,13 +32,13 @@ pub const IrVal = union(enum) { |
| 33 | 32 | |
| 34 | 33 | pub fn dump(self: IrVal) void { |
| 35 | 34 | switch (self) { |
| 36 | IrVal.Unknown => std.debug.warn("Unknown"), | |
| 37 | IrVal.KnownType => |typ| { | |
| 35 | .Unknown => std.debug.warn("Unknown"), | |
| 36 | .KnownType => |typ| { | |
| 38 | 37 | std.debug.warn("KnownType("); |
| 39 | 38 | typ.dump(); |
| 40 | 39 | std.debug.warn(")"); |
| 41 | 40 | }, |
| 42 | IrVal.KnownValue => |value| { | |
| 41 | .KnownValue => |value| { | |
| 43 | 42 | std.debug.warn("KnownValue("); |
| 44 | 43 | value.dump(); |
| 45 | 44 | std.debug.warn(")"); |
| ... | ... | @@ -113,37 +112,37 @@ pub const Inst = struct { |
| 113 | 112 | |
| 114 | 113 | pub async fn analyze(base: *Inst, ira: *Analyze) Analyze.Error!*Inst { |
| 115 | 114 | switch (base.id) { |
| 116 | Id.Return => return @fieldParentPtr(Return, "base", base).analyze(ira), | |
| 117 | Id.Const => return @fieldParentPtr(Const, "base", base).analyze(ira), | |
| 118 | Id.Call => return @fieldParentPtr(Call, "base", base).analyze(ira), | |
| 119 | Id.DeclRef => return @fieldParentPtr(DeclRef, "base", base).analyze(ira), | |
| 120 | Id.Ref => return @fieldParentPtr(Ref, "base", base).analyze(ira), | |
| 121 | Id.DeclVar => return @fieldParentPtr(DeclVar, "base", base).analyze(ira), | |
| 122 | Id.CheckVoidStmt => return @fieldParentPtr(CheckVoidStmt, "base", base).analyze(ira), | |
| 123 | Id.Phi => return @fieldParentPtr(Phi, "base", base).analyze(ira), | |
| 124 | Id.Br => return @fieldParentPtr(Br, "base", base).analyze(ira), | |
| 125 | Id.AddImplicitReturnType => return @fieldParentPtr(AddImplicitReturnType, "base", base).analyze(ira), | |
| 126 | Id.PtrType => return @fieldParentPtr(PtrType, "base", base).analyze(ira), | |
| 127 | Id.VarPtr => return @fieldParentPtr(VarPtr, "base", base).analyze(ira), | |
| 128 | Id.LoadPtr => return @fieldParentPtr(LoadPtr, "base", base).analyze(ira), | |
| 115 | .Return => return @fieldParentPtr(Return, "base", base).analyze(ira), | |
| 116 | .Const => return @fieldParentPtr(Const, "base", base).analyze(ira), | |
| 117 | .Call => return @fieldParentPtr(Call, "base", base).analyze(ira), | |
| 118 | .DeclRef => return @fieldParentPtr(DeclRef, "base", base).analyze(ira), | |
| 119 | .Ref => return @fieldParentPtr(Ref, "base", base).analyze(ira), | |
| 120 | .DeclVar => return @fieldParentPtr(DeclVar, "base", base).analyze(ira), | |
| 121 | .CheckVoidStmt => return @fieldParentPtr(CheckVoidStmt, "base", base).analyze(ira), | |
| 122 | .Phi => return @fieldParentPtr(Phi, "base", base).analyze(ira), | |
| 123 | .Br => return @fieldParentPtr(Br, "base", base).analyze(ira), | |
| 124 | .AddImplicitReturnType => return @fieldParentPtr(AddImplicitReturnType, "base", base).analyze(ira), | |
| 125 | .PtrType => return @fieldParentPtr(PtrType, "base", base).analyze(ira), | |
| 126 | .VarPtr => return @fieldParentPtr(VarPtr, "base", base).analyze(ira), | |
| 127 | .LoadPtr => return @fieldParentPtr(LoadPtr, "base", base).analyze(ira), | |
| 129 | 128 | } |
| 130 | 129 | } |
| 131 | 130 | |
| 132 | 131 | pub fn render(base: *Inst, ofile: *ObjectFile, fn_val: *Value.Fn) (error{OutOfMemory}!?*llvm.Value) { |
| 133 | 132 | switch (base.id) { |
| 134 | Id.Return => return @fieldParentPtr(Return, "base", base).render(ofile, fn_val), | |
| 135 | Id.Const => return @fieldParentPtr(Const, "base", base).render(ofile, fn_val), | |
| 136 | Id.Call => return @fieldParentPtr(Call, "base", base).render(ofile, fn_val), | |
| 137 | Id.VarPtr => return @fieldParentPtr(VarPtr, "base", base).render(ofile, fn_val), | |
| 138 | Id.LoadPtr => return @fieldParentPtr(LoadPtr, "base", base).render(ofile, fn_val), | |
| 139 | Id.DeclRef => unreachable, | |
| 140 | Id.PtrType => unreachable, | |
| 141 | Id.Ref => @panic("TODO"), | |
| 142 | Id.DeclVar => @panic("TODO"), | |
| 143 | Id.CheckVoidStmt => @panic("TODO"), | |
| 144 | Id.Phi => @panic("TODO"), | |
| 145 | Id.Br => @panic("TODO"), | |
| 146 | Id.AddImplicitReturnType => @panic("TODO"), | |
| 133 | .Return => return @fieldParentPtr(Return, "base", base).render(ofile, fn_val), | |
| 134 | .Const => return @fieldParentPtr(Const, "base", base).render(ofile, fn_val), | |
| 135 | .Call => return @fieldParentPtr(Call, "base", base).render(ofile, fn_val), | |
| 136 | .VarPtr => return @fieldParentPtr(VarPtr, "base", base).render(ofile, fn_val), | |
| 137 | .LoadPtr => return @fieldParentPtr(LoadPtr, "base", base).render(ofile, fn_val), | |
| 138 | .DeclRef => unreachable, | |
| 139 | .PtrType => unreachable, | |
| 140 | .Ref => @panic("TODO"), | |
| 141 | .DeclVar => @panic("TODO"), | |
| 142 | .CheckVoidStmt => @panic("TODO"), | |
| 143 | .Phi => @panic("TODO"), | |
| 144 | .Br => @panic("TODO"), | |
| 145 | .AddImplicitReturnType => @panic("TODO"), | |
| 147 | 146 | } |
| 148 | 147 | } |
| 149 | 148 | |
| ... | ... | @@ -165,7 +164,7 @@ pub const Inst = struct { |
| 165 | 164 | param.ref_count -= 1; |
| 166 | 165 | const child = param.child orelse return error.SemanticAnalysisFailed; |
| 167 | 166 | switch (child.val) { |
| 168 | IrVal.Unknown => return error.SemanticAnalysisFailed, | |
| 167 | .Unknown => return error.SemanticAnalysisFailed, | |
| 169 | 168 | else => return child, |
| 170 | 169 | } |
| 171 | 170 | } |
| ... | ... | @@ -213,9 +212,9 @@ pub const Inst = struct { |
| 213 | 212 | /// asserts that the type is known |
| 214 | 213 | fn getKnownType(self: *Inst) *Type { |
| 215 | 214 | switch (self.val) { |
| 216 | IrVal.KnownType => |typ| return typ, | |
| 217 | IrVal.KnownValue => |value| return value.typ, | |
| 218 | IrVal.Unknown => unreachable, | |
| 215 | .KnownType => |typ| return typ, | |
| 216 | .KnownValue => |value| return value.typ, | |
| 217 | .Unknown => unreachable, | |
| 219 | 218 | } |
| 220 | 219 | } |
| 221 | 220 | |
| ... | ... | @@ -225,14 +224,14 @@ pub const Inst = struct { |
| 225 | 224 | |
| 226 | 225 | pub fn isNoReturn(base: *const Inst) bool { |
| 227 | 226 | switch (base.val) { |
| 228 | IrVal.Unknown => return false, | |
| 229 | IrVal.KnownValue => |x| return x.typ.id == Type.Id.NoReturn, | |
| 230 | IrVal.KnownType => |typ| return typ.id == Type.Id.NoReturn, | |
| 227 | .Unknown => return false, | |
| 228 | .KnownValue => |x| return x.typ.id == .NoReturn, | |
| 229 | .KnownType => |typ| return typ.id == .NoReturn, | |
| 231 | 230 | } |
| 232 | 231 | } |
| 233 | 232 | |
| 234 | 233 | pub fn isCompTime(base: *const Inst) bool { |
| 235 | return base.val == IrVal.KnownValue; | |
| 234 | return base.val == .KnownValue; | |
| 236 | 235 | } |
| 237 | 236 | |
| 238 | 237 | pub fn linkToParent(self: *Inst, parent: *Inst) void { |
| ... | ... | @@ -445,8 +444,8 @@ pub const Inst = struct { |
| 445 | 444 | .child_type = elem_type, |
| 446 | 445 | .mut = self.params.mut, |
| 447 | 446 | .vol = self.params.volatility, |
| 448 | .size = Type.Pointer.Size.One, | |
| 449 | .alignment = Type.Pointer.Align.Abi, | |
| 447 | .size = .One, | |
| 448 | .alignment = .Abi, | |
| 450 | 449 | }); |
| 451 | 450 | // TODO: potentially set the hint that this is a stack pointer. But it might not be - this |
| 452 | 451 | // could be a ref of a global, for example |
| ... | ... | @@ -479,20 +478,20 @@ pub const Inst = struct { |
| 479 | 478 | else => return error.SemanticAnalysisFailed, |
| 480 | 479 | }; |
| 481 | 480 | switch (self.params.decl.id) { |
| 482 | Decl.Id.CompTime => unreachable, | |
| 483 | Decl.Id.Var => return error.Unimplemented, | |
| 484 | Decl.Id.Fn => { | |
| 481 | .CompTime => unreachable, | |
| 482 | .Var => return error.Unimplemented, | |
| 483 | .Fn => { | |
| 485 | 484 | const fn_decl = @fieldParentPtr(Decl.Fn, "base", self.params.decl); |
| 486 | 485 | const decl_val = switch (fn_decl.value) { |
| 487 | Decl.Fn.Val.Unresolved => unreachable, | |
| 488 | Decl.Fn.Val.Fn => |fn_val| &fn_val.base, | |
| 489 | Decl.Fn.Val.FnProto => |fn_proto| &fn_proto.base, | |
| 486 | .Unresolved => unreachable, | |
| 487 | .Fn => |fn_val| &fn_val.base, | |
| 488 | .FnProto => |fn_proto| &fn_proto.base, | |
| 490 | 489 | }; |
| 491 | 490 | switch (self.params.lval) { |
| 492 | LVal.None => { | |
| 491 | .None => { | |
| 493 | 492 | return ira.irb.buildConstValue(self.base.scope, self.base.span, decl_val); |
| 494 | 493 | }, |
| 495 | LVal.Ptr => return error.Unimplemented, | |
| 494 | .Ptr => return error.Unimplemented, | |
| 496 | 495 | } |
| 497 | 496 | }, |
| 498 | 497 | } |
| ... | ... | @@ -519,20 +518,20 @@ pub const Inst = struct { |
| 519 | 518 | |
| 520 | 519 | pub async fn analyze(self: *const VarPtr, ira: *Analyze) !*Inst { |
| 521 | 520 | switch (self.params.var_scope.data) { |
| 522 | Scope.Var.Data.Const => @panic("TODO"), | |
| 523 | Scope.Var.Data.Param => |param| { | |
| 521 | .Const => @panic("TODO"), | |
| 522 | .Param => |param| { | |
| 524 | 523 | const new_inst = try ira.irb.build( |
| 525 | Inst.VarPtr, | |
| 524 | .VarPtr, | |
| 526 | 525 | self.base.scope, |
| 527 | 526 | self.base.span, |
| 528 | 527 | Inst.VarPtr.Params{ .var_scope = self.params.var_scope }, |
| 529 | 528 | ); |
| 530 | 529 | const ptr_type = try Type.Pointer.get(ira.irb.comp, Type.Pointer.Key{ |
| 531 | 530 | .child_type = param.typ, |
| 532 | .mut = Type.Pointer.Mut.Const, | |
| 533 | .vol = Type.Pointer.Vol.Non, | |
| 534 | .size = Type.Pointer.Size.One, | |
| 535 | .alignment = Type.Pointer.Align.Abi, | |
| 531 | .mut = .Const, | |
| 532 | .vol = .Non, | |
| 533 | .size = .One, | |
| 534 | .alignment = .Abi, | |
| 536 | 535 | }); |
| 537 | 536 | new_inst.val = IrVal{ .KnownType = &ptr_type.base }; |
| 538 | 537 | return new_inst; |
| ... | ... | @@ -542,8 +541,8 @@ pub const Inst = struct { |
| 542 | 541 | |
| 543 | 542 | pub fn render(self: *VarPtr, ofile: *ObjectFile, fn_val: *Value.Fn) *llvm.Value { |
| 544 | 543 | switch (self.params.var_scope.data) { |
| 545 | Scope.Var.Data.Const => unreachable, // turned into Inst.Const in analyze pass | |
| 546 | Scope.Var.Data.Param => |param| return param.llvm_value, | |
| 544 | .Const => unreachable, // turned into Inst.Const in analyze pass | |
| 545 | .Param => |param| return param.llvm_value, | |
| 547 | 546 | } |
| 548 | 547 | } |
| 549 | 548 | }; |
| ... | ... | @@ -567,7 +566,7 @@ pub const Inst = struct { |
| 567 | 566 | pub async fn analyze(self: *const LoadPtr, ira: *Analyze) !*Inst { |
| 568 | 567 | const target = try self.params.target.getAsParam(); |
| 569 | 568 | const target_type = target.getKnownType(); |
| 570 | if (target_type.id != Type.Id.Pointer) { | |
| 569 | if (target_type.id != .Pointer) { | |
| 571 | 570 | try ira.addCompileError(self.base.span, "dereference of non pointer type '{}'", target_type.name); |
| 572 | 571 | return error.SemanticAnalysisFailed; |
| 573 | 572 | } |
| ... | ... | @@ -715,7 +714,7 @@ pub const Inst = struct { |
| 715 | 714 | |
| 716 | 715 | pub fn analyze(self: *const CheckVoidStmt, ira: *Analyze) !*Inst { |
| 717 | 716 | const target = try self.params.target.getAsParam(); |
| 718 | if (target.getKnownType().id != Type.Id.Void) { | |
| 717 | if (target.getKnownType().id != .Void) { | |
| 719 | 718 | try ira.addCompileError(self.base.span, "expression value is ignored"); |
| 720 | 719 | return error.SemanticAnalysisFailed; |
| 721 | 720 | } |
| ... | ... | @@ -838,7 +837,7 @@ pub const Inst = struct { |
| 838 | 837 | const target = try self.params.target.getAsParam(); |
| 839 | 838 | const target_type = target.getKnownType(); |
| 840 | 839 | switch (target_type.id) { |
| 841 | Type.Id.ErrorUnion => { | |
| 840 | .ErrorUnion => { | |
| 842 | 841 | return error.Unimplemented; |
| 843 | 842 | // if (instr_is_comptime(value)) { |
| 844 | 843 | // ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| ... | ... | @@ -868,7 +867,7 @@ pub const Inst = struct { |
| 868 | 867 | // ir_build_test_err_from(&ira->new_irb, &instruction->base, value); |
| 869 | 868 | // return ira->codegen->builtin_types.entry_bool; |
| 870 | 869 | }, |
| 871 | Type.Id.ErrorSet => { | |
| 870 | .ErrorSet => { | |
| 872 | 871 | return ira.irb.buildConstBool(self.base.scope, self.base.span, true); |
| 873 | 872 | }, |
| 874 | 873 | else => { |
| ... | ... | @@ -1081,120 +1080,120 @@ pub const Builder = struct { |
| 1081 | 1080 | |
| 1082 | 1081 | pub async fn genNode(irb: *Builder, node: *ast.Node, scope: *Scope, lval: LVal) Error!*Inst { |
| 1083 | 1082 | switch (node.id) { |
| 1084 | ast.Node.Id.Root => unreachable, | |
| 1085 | ast.Node.Id.Use => unreachable, | |
| 1086 | ast.Node.Id.TestDecl => unreachable, | |
| 1087 | ast.Node.Id.VarDecl => return error.Unimplemented, | |
| 1088 | ast.Node.Id.Defer => return error.Unimplemented, | |
| 1089 | ast.Node.Id.InfixOp => return error.Unimplemented, | |
| 1090 | ast.Node.Id.PrefixOp => { | |
| 1083 | .Root => unreachable, | |
| 1084 | .Use => unreachable, | |
| 1085 | .TestDecl => unreachable, | |
| 1086 | .VarDecl => return error.Unimplemented, | |
| 1087 | .Defer => return error.Unimplemented, | |
| 1088 | .InfixOp => return error.Unimplemented, | |
| 1089 | .PrefixOp => { | |
| 1091 | 1090 | const prefix_op = @fieldParentPtr(ast.Node.PrefixOp, "base", node); |
| 1092 | 1091 | switch (prefix_op.op) { |
| 1093 | ast.Node.PrefixOp.Op.AddressOf => return error.Unimplemented, | |
| 1094 | ast.Node.PrefixOp.Op.ArrayType => |n| return error.Unimplemented, | |
| 1095 | ast.Node.PrefixOp.Op.Await => return error.Unimplemented, | |
| 1096 | ast.Node.PrefixOp.Op.BitNot => return error.Unimplemented, | |
| 1097 | ast.Node.PrefixOp.Op.BoolNot => return error.Unimplemented, | |
| 1098 | ast.Node.PrefixOp.Op.Cancel => return error.Unimplemented, | |
| 1099 | ast.Node.PrefixOp.Op.OptionalType => return error.Unimplemented, | |
| 1100 | ast.Node.PrefixOp.Op.Negation => return error.Unimplemented, | |
| 1101 | ast.Node.PrefixOp.Op.NegationWrap => return error.Unimplemented, | |
| 1102 | ast.Node.PrefixOp.Op.Resume => return error.Unimplemented, | |
| 1103 | ast.Node.PrefixOp.Op.PtrType => |ptr_info| { | |
| 1092 | .AddressOf => return error.Unimplemented, | |
| 1093 | .ArrayType => |n| return error.Unimplemented, | |
| 1094 | .Await => return error.Unimplemented, | |
| 1095 | .BitNot => return error.Unimplemented, | |
| 1096 | .BoolNot => return error.Unimplemented, | |
| 1097 | .Cancel => return error.Unimplemented, | |
| 1098 | .OptionalType => return error.Unimplemented, | |
| 1099 | .Negation => return error.Unimplemented, | |
| 1100 | .NegationWrap => return error.Unimplemented, | |
| 1101 | .Resume => return error.Unimplemented, | |
| 1102 | .PtrType => |ptr_info| { | |
| 1104 | 1103 | const inst = try irb.genPtrType(prefix_op, ptr_info, scope); |
| 1105 | 1104 | return irb.lvalWrap(scope, inst, lval); |
| 1106 | 1105 | }, |
| 1107 | ast.Node.PrefixOp.Op.SliceType => |ptr_info| return error.Unimplemented, | |
| 1108 | ast.Node.PrefixOp.Op.Try => return error.Unimplemented, | |
| 1106 | .SliceType => |ptr_info| return error.Unimplemented, | |
| 1107 | .Try => return error.Unimplemented, | |
| 1109 | 1108 | } |
| 1110 | 1109 | }, |
| 1111 | ast.Node.Id.SuffixOp => { | |
| 1110 | .SuffixOp => { | |
| 1112 | 1111 | const suffix_op = @fieldParentPtr(ast.Node.SuffixOp, "base", node); |
| 1113 | 1112 | switch (suffix_op.op) { |
| 1114 | @TagType(ast.Node.SuffixOp.Op).Call => |*call| { | |
| 1113 | .Call => |*call| { | |
| 1115 | 1114 | const inst = try irb.genCall(suffix_op, call, scope); |
| 1116 | 1115 | return irb.lvalWrap(scope, inst, lval); |
| 1117 | 1116 | }, |
| 1118 | @TagType(ast.Node.SuffixOp.Op).ArrayAccess => |n| return error.Unimplemented, | |
| 1119 | @TagType(ast.Node.SuffixOp.Op).Slice => |slice| return error.Unimplemented, | |
| 1120 | @TagType(ast.Node.SuffixOp.Op).ArrayInitializer => |init_list| return error.Unimplemented, | |
| 1121 | @TagType(ast.Node.SuffixOp.Op).StructInitializer => |init_list| return error.Unimplemented, | |
| 1122 | @TagType(ast.Node.SuffixOp.Op).Deref => return error.Unimplemented, | |
| 1123 | @TagType(ast.Node.SuffixOp.Op).UnwrapOptional => return error.Unimplemented, | |
| 1117 | .ArrayAccess => |n| return error.Unimplemented, | |
| 1118 | .Slice => |slice| return error.Unimplemented, | |
| 1119 | .ArrayInitializer => |init_list| return error.Unimplemented, | |
| 1120 | .StructInitializer => |init_list| return error.Unimplemented, | |
| 1121 | .Deref => return error.Unimplemented, | |
| 1122 | .UnwrapOptional => return error.Unimplemented, | |
| 1124 | 1123 | } |
| 1125 | 1124 | }, |
| 1126 | ast.Node.Id.Switch => return error.Unimplemented, | |
| 1127 | ast.Node.Id.While => return error.Unimplemented, | |
| 1128 | ast.Node.Id.For => return error.Unimplemented, | |
| 1129 | ast.Node.Id.If => return error.Unimplemented, | |
| 1130 | ast.Node.Id.ControlFlowExpression => { | |
| 1125 | .Switch => return error.Unimplemented, | |
| 1126 | .While => return error.Unimplemented, | |
| 1127 | .For => return error.Unimplemented, | |
| 1128 | .If => return error.Unimplemented, | |
| 1129 | .ControlFlowExpression => { | |
| 1131 | 1130 | const control_flow_expr = @fieldParentPtr(ast.Node.ControlFlowExpression, "base", node); |
| 1132 | 1131 | return irb.genControlFlowExpr(control_flow_expr, scope, lval); |
| 1133 | 1132 | }, |
| 1134 | ast.Node.Id.Suspend => return error.Unimplemented, | |
| 1135 | ast.Node.Id.VarType => return error.Unimplemented, | |
| 1136 | ast.Node.Id.ErrorType => return error.Unimplemented, | |
| 1137 | ast.Node.Id.FnProto => return error.Unimplemented, | |
| 1138 | ast.Node.Id.PromiseType => return error.Unimplemented, | |
| 1139 | ast.Node.Id.IntegerLiteral => { | |
| 1133 | .Suspend => return error.Unimplemented, | |
| 1134 | .VarType => return error.Unimplemented, | |
| 1135 | .ErrorType => return error.Unimplemented, | |
| 1136 | .FnProto => return error.Unimplemented, | |
| 1137 | .PromiseType => return error.Unimplemented, | |
| 1138 | .IntegerLiteral => { | |
| 1140 | 1139 | const int_lit = @fieldParentPtr(ast.Node.IntegerLiteral, "base", node); |
| 1141 | 1140 | return irb.lvalWrap(scope, try irb.genIntLit(int_lit, scope), lval); |
| 1142 | 1141 | }, |
| 1143 | ast.Node.Id.FloatLiteral => return error.Unimplemented, | |
| 1144 | ast.Node.Id.StringLiteral => { | |
| 1142 | .FloatLiteral => return error.Unimplemented, | |
| 1143 | .StringLiteral => { | |
| 1145 | 1144 | const str_lit = @fieldParentPtr(ast.Node.StringLiteral, "base", node); |
| 1146 | 1145 | const inst = try irb.genStrLit(str_lit, scope); |
| 1147 | 1146 | return irb.lvalWrap(scope, inst, lval); |
| 1148 | 1147 | }, |
| 1149 | ast.Node.Id.MultilineStringLiteral => return error.Unimplemented, | |
| 1150 | ast.Node.Id.CharLiteral => return error.Unimplemented, | |
| 1151 | ast.Node.Id.BoolLiteral => return error.Unimplemented, | |
| 1152 | ast.Node.Id.NullLiteral => return error.Unimplemented, | |
| 1153 | ast.Node.Id.UndefinedLiteral => return error.Unimplemented, | |
| 1154 | ast.Node.Id.Unreachable => return error.Unimplemented, | |
| 1155 | ast.Node.Id.Identifier => { | |
| 1148 | .MultilineStringLiteral => return error.Unimplemented, | |
| 1149 | .CharLiteral => return error.Unimplemented, | |
| 1150 | .BoolLiteral => return error.Unimplemented, | |
| 1151 | .NullLiteral => return error.Unimplemented, | |
| 1152 | .UndefinedLiteral => return error.Unimplemented, | |
| 1153 | .Unreachable => return error.Unimplemented, | |
| 1154 | .Identifier => { | |
| 1156 | 1155 | const identifier = @fieldParentPtr(ast.Node.Identifier, "base", node); |
| 1157 | 1156 | return irb.genIdentifier(identifier, scope, lval); |
| 1158 | 1157 | }, |
| 1159 | ast.Node.Id.GroupedExpression => { | |
| 1158 | .GroupedExpression => { | |
| 1160 | 1159 | const grouped_expr = @fieldParentPtr(ast.Node.GroupedExpression, "base", node); |
| 1161 | 1160 | return irb.genNode(grouped_expr.expr, scope, lval); |
| 1162 | 1161 | }, |
| 1163 | ast.Node.Id.BuiltinCall => return error.Unimplemented, | |
| 1164 | ast.Node.Id.ErrorSetDecl => return error.Unimplemented, | |
| 1165 | ast.Node.Id.ContainerDecl => return error.Unimplemented, | |
| 1166 | ast.Node.Id.Asm => return error.Unimplemented, | |
| 1167 | ast.Node.Id.Comptime => return error.Unimplemented, | |
| 1168 | ast.Node.Id.Block => { | |
| 1162 | .BuiltinCall => return error.Unimplemented, | |
| 1163 | .ErrorSetDecl => return error.Unimplemented, | |
| 1164 | .ContainerDecl => return error.Unimplemented, | |
| 1165 | .Asm => return error.Unimplemented, | |
| 1166 | .Comptime => return error.Unimplemented, | |
| 1167 | .Block => { | |
| 1169 | 1168 | const block = @fieldParentPtr(ast.Node.Block, "base", node); |
| 1170 | 1169 | const inst = try irb.genBlock(block, scope); |
| 1171 | 1170 | return irb.lvalWrap(scope, inst, lval); |
| 1172 | 1171 | }, |
| 1173 | ast.Node.Id.DocComment => return error.Unimplemented, | |
| 1174 | ast.Node.Id.SwitchCase => return error.Unimplemented, | |
| 1175 | ast.Node.Id.SwitchElse => return error.Unimplemented, | |
| 1176 | ast.Node.Id.Else => return error.Unimplemented, | |
| 1177 | ast.Node.Id.Payload => return error.Unimplemented, | |
| 1178 | ast.Node.Id.PointerPayload => return error.Unimplemented, | |
| 1179 | ast.Node.Id.PointerIndexPayload => return error.Unimplemented, | |
| 1180 | ast.Node.Id.ContainerField => return error.Unimplemented, | |
| 1181 | ast.Node.Id.ErrorTag => return error.Unimplemented, | |
| 1182 | ast.Node.Id.AsmInput => return error.Unimplemented, | |
| 1183 | ast.Node.Id.AsmOutput => return error.Unimplemented, | |
| 1184 | ast.Node.Id.ParamDecl => return error.Unimplemented, | |
| 1185 | ast.Node.Id.FieldInitializer => return error.Unimplemented, | |
| 1186 | ast.Node.Id.EnumLiteral => return error.Unimplemented, | |
| 1172 | .DocComment => return error.Unimplemented, | |
| 1173 | .SwitchCase => return error.Unimplemented, | |
| 1174 | .SwitchElse => return error.Unimplemented, | |
| 1175 | .Else => return error.Unimplemented, | |
| 1176 | .Payload => return error.Unimplemented, | |
| 1177 | .PointerPayload => return error.Unimplemented, | |
| 1178 | .PointerIndexPayload => return error.Unimplemented, | |
| 1179 | .ContainerField => return error.Unimplemented, | |
| 1180 | .ErrorTag => return error.Unimplemented, | |
| 1181 | .AsmInput => return error.Unimplemented, | |
| 1182 | .AsmOutput => return error.Unimplemented, | |
| 1183 | .ParamDecl => return error.Unimplemented, | |
| 1184 | .FieldInitializer => return error.Unimplemented, | |
| 1185 | .EnumLiteral => return error.Unimplemented, | |
| 1187 | 1186 | } |
| 1188 | 1187 | } |
| 1189 | 1188 | |
| 1190 | 1189 | async fn genCall(irb: *Builder, suffix_op: *ast.Node.SuffixOp, call: *ast.Node.SuffixOp.Op.Call, scope: *Scope) !*Inst { |
| 1191 | const fn_ref = try irb.genNode(suffix_op.lhs, scope, LVal.None); | |
| 1190 | const fn_ref = try irb.genNode(suffix_op.lhs, scope, .None); | |
| 1192 | 1191 | |
| 1193 | 1192 | const args = try irb.arena().alloc(*Inst, call.params.len); |
| 1194 | 1193 | var it = call.params.iterator(0); |
| 1195 | 1194 | var i: usize = 0; |
| 1196 | 1195 | while (it.next()) |arg_node_ptr| : (i += 1) { |
| 1197 | args[i] = try irb.genNode(arg_node_ptr.*, scope, LVal.None); | |
| 1196 | args[i] = try irb.genNode(arg_node_ptr.*, scope, .None); | |
| 1198 | 1197 | } |
| 1199 | 1198 | |
| 1200 | 1199 | //bool is_async = node->data.fn_call_expr.is_async; |
| ... | ... | @@ -1239,7 +1238,7 @@ pub const Builder = struct { |
| 1239 | 1238 | //} else { |
| 1240 | 1239 | // align_value = nullptr; |
| 1241 | 1240 | //} |
| 1242 | const child_type = try irb.genNode(prefix_op.rhs, scope, LVal.None); | |
| 1241 | const child_type = try irb.genNode(prefix_op.rhs, scope, .None); | |
| 1243 | 1242 | |
| 1244 | 1243 | //uint32_t bit_offset_start = 0; |
| 1245 | 1244 | //if (node->data.pointer_type.bit_offset_start != nullptr) { |
| ... | ... | @@ -1273,9 +1272,9 @@ pub const Builder = struct { |
| 1273 | 1272 | |
| 1274 | 1273 | return irb.build(Inst.PtrType, scope, Span.node(&prefix_op.base), Inst.PtrType.Params{ |
| 1275 | 1274 | .child_type = child_type, |
| 1276 | .mut = Type.Pointer.Mut.Mut, | |
| 1277 | .vol = Type.Pointer.Vol.Non, | |
| 1278 | .size = Type.Pointer.Size.Many, | |
| 1275 | .mut = .Mut, | |
| 1276 | .vol = .Non, | |
| 1277 | .size = .Many, | |
| 1279 | 1278 | .alignment = null, |
| 1280 | 1279 | }); |
| 1281 | 1280 | } |
| ... | ... | @@ -1287,15 +1286,15 @@ pub const Builder = struct { |
| 1287 | 1286 | var scope = target_scope; |
| 1288 | 1287 | while (true) { |
| 1289 | 1288 | switch (scope.id) { |
| 1290 | Scope.Id.CompTime => return true, | |
| 1291 | Scope.Id.FnDef => return false, | |
| 1292 | Scope.Id.Decls => unreachable, | |
| 1293 | Scope.Id.Root => unreachable, | |
| 1294 | Scope.Id.AstTree => unreachable, | |
| 1295 | Scope.Id.Block, | |
| 1296 | Scope.Id.Defer, | |
| 1297 | Scope.Id.DeferExpr, | |
| 1298 | Scope.Id.Var, | |
| 1289 | .CompTime => return true, | |
| 1290 | .FnDef => return false, | |
| 1291 | .Decls => unreachable, | |
| 1292 | .Root => unreachable, | |
| 1293 | .AstTree => unreachable, | |
| 1294 | .Block, | |
| 1295 | .Defer, | |
| 1296 | .DeferExpr, | |
| 1297 | .Var, | |
| 1299 | 1298 | => scope = scope.parent.?, |
| 1300 | 1299 | } |
| 1301 | 1300 | } |
| ... | ... | @@ -1374,8 +1373,8 @@ pub const Builder = struct { |
| 1374 | 1373 | const ptr_val = try Value.Ptr.createArrayElemPtr( |
| 1375 | 1374 | irb.comp, |
| 1376 | 1375 | array_val, |
| 1377 | Type.Pointer.Mut.Const, | |
| 1378 | Type.Pointer.Size.Many, | |
| 1376 | .Const, | |
| 1377 | .Many, | |
| 1379 | 1378 | 0, |
| 1380 | 1379 | ); |
| 1381 | 1380 | defer ptr_val.base.deref(irb.comp); |
| ... | ... | @@ -1438,7 +1437,7 @@ pub const Builder = struct { |
| 1438 | 1437 | child_scope = &defer_child_scope.base; |
| 1439 | 1438 | continue; |
| 1440 | 1439 | } |
| 1441 | const statement_value = try irb.genNode(statement_node, child_scope, LVal.None); | |
| 1440 | const statement_value = try irb.genNode(statement_node, child_scope, .None); | |
| 1442 | 1441 | |
| 1443 | 1442 | is_continuation_unreachable = statement_value.isNoReturn(); |
| 1444 | 1443 | if (is_continuation_unreachable) { |
| ... | ... | @@ -1481,7 +1480,7 @@ pub const Builder = struct { |
| 1481 | 1480 | try block_scope.incoming_values.append( |
| 1482 | 1481 | try irb.buildConstVoid(parent_scope, Span.token(block.rbrace), true), |
| 1483 | 1482 | ); |
| 1484 | _ = try irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit); | |
| 1483 | _ = try irb.genDefersForBlock(child_scope, outer_block_scope, .ScopeExit); | |
| 1485 | 1484 | |
| 1486 | 1485 | _ = try irb.buildGen(Inst.Br, parent_scope, Span.token(block.rbrace), Inst.Br.Params{ |
| 1487 | 1486 | .dest_block = block_scope.end_block, |
| ... | ... | @@ -1496,7 +1495,7 @@ pub const Builder = struct { |
| 1496 | 1495 | }); |
| 1497 | 1496 | } |
| 1498 | 1497 | |
| 1499 | _ = try irb.genDefersForBlock(child_scope, outer_block_scope, Scope.Defer.Kind.ScopeExit); | |
| 1498 | _ = try irb.genDefersForBlock(child_scope, outer_block_scope, .ScopeExit); | |
| 1500 | 1499 | return irb.buildConstVoid(child_scope, Span.token(block.rbrace), true); |
| 1501 | 1500 | } |
| 1502 | 1501 | |
| ... | ... | @@ -1507,9 +1506,9 @@ pub const Builder = struct { |
| 1507 | 1506 | lval: LVal, |
| 1508 | 1507 | ) !*Inst { |
| 1509 | 1508 | switch (control_flow_expr.kind) { |
| 1510 | ast.Node.ControlFlowExpression.Kind.Break => |arg| return error.Unimplemented, | |
| 1511 | ast.Node.ControlFlowExpression.Kind.Continue => |arg| return error.Unimplemented, | |
| 1512 | ast.Node.ControlFlowExpression.Kind.Return => { | |
| 1509 | .Break => |arg| return error.Unimplemented, | |
| 1510 | .Continue => |arg| return error.Unimplemented, | |
| 1511 | .Return => { | |
| 1513 | 1512 | const src_span = Span.token(control_flow_expr.ltoken); |
| 1514 | 1513 | if (scope.findFnDef() == null) { |
| 1515 | 1514 | try irb.comp.addCompileError( |
| ... | ... | @@ -1534,7 +1533,7 @@ pub const Builder = struct { |
| 1534 | 1533 | |
| 1535 | 1534 | const outer_scope = irb.begin_scope.?; |
| 1536 | 1535 | const return_value = if (control_flow_expr.rhs) |rhs| blk: { |
| 1537 | break :blk try irb.genNode(rhs, scope, LVal.None); | |
| 1536 | break :blk try irb.genNode(rhs, scope, .None); | |
| 1538 | 1537 | } else blk: { |
| 1539 | 1538 | break :blk try irb.buildConstVoid(scope, src_span, true); |
| 1540 | 1539 | }; |
| ... | ... | @@ -1545,7 +1544,7 @@ pub const Builder = struct { |
| 1545 | 1544 | const err_block = try irb.createBasicBlock(scope, c"ErrRetErr"); |
| 1546 | 1545 | const ok_block = try irb.createBasicBlock(scope, c"ErrRetOk"); |
| 1547 | 1546 | if (!have_err_defers) { |
| 1548 | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit); | |
| 1547 | _ = try irb.genDefersForBlock(scope, outer_scope, .ScopeExit); | |
| 1549 | 1548 | } |
| 1550 | 1549 | |
| 1551 | 1550 | const is_err = try irb.build( |
| ... | ... | @@ -1568,7 +1567,7 @@ pub const Builder = struct { |
| 1568 | 1567 | |
| 1569 | 1568 | try irb.setCursorAtEndAndAppendBlock(err_block); |
| 1570 | 1569 | if (have_err_defers) { |
| 1571 | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ErrorExit); | |
| 1570 | _ = try irb.genDefersForBlock(scope, outer_scope, .ErrorExit); | |
| 1572 | 1571 | } |
| 1573 | 1572 | if (irb.comp.have_err_ret_tracing and !irb.isCompTime(scope)) { |
| 1574 | 1573 | _ = try irb.build(Inst.SaveErrRetAddr, scope, src_span, Inst.SaveErrRetAddr.Params{}); |
| ... | ... | @@ -1580,7 +1579,7 @@ pub const Builder = struct { |
| 1580 | 1579 | |
| 1581 | 1580 | try irb.setCursorAtEndAndAppendBlock(ok_block); |
| 1582 | 1581 | if (have_err_defers) { |
| 1583 | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit); | |
| 1582 | _ = try irb.genDefersForBlock(scope, outer_scope, .ScopeExit); | |
| 1584 | 1583 | } |
| 1585 | 1584 | _ = try irb.build(Inst.Br, scope, src_span, Inst.Br.Params{ |
| 1586 | 1585 | .dest_block = ret_stmt_block, |
| ... | ... | @@ -1590,7 +1589,7 @@ pub const Builder = struct { |
| 1590 | 1589 | try irb.setCursorAtEndAndAppendBlock(ret_stmt_block); |
| 1591 | 1590 | return irb.genAsyncReturn(scope, src_span, return_value, false); |
| 1592 | 1591 | } else { |
| 1593 | _ = try irb.genDefersForBlock(scope, outer_scope, Scope.Defer.Kind.ScopeExit); | |
| 1592 | _ = try irb.genDefersForBlock(scope, outer_scope, .ScopeExit); | |
| 1594 | 1593 | return irb.genAsyncReturn(scope, src_span, return_value, false); |
| 1595 | 1594 | } |
| 1596 | 1595 | }, |
| ... | ... | @@ -1616,8 +1615,8 @@ pub const Builder = struct { |
| 1616 | 1615 | switch (lval) { |
| 1617 | 1616 | // if (lval == LValPtr) { |
| 1618 | 1617 | // return ir_build_ref(irb, scope, node, value, false, false); |
| 1619 | LVal.Ptr => return error.Unimplemented, | |
| 1620 | LVal.None => return irb.buildConstValue(scope, src_span, &primitive_type.base), | |
| 1618 | .Ptr => return error.Unimplemented, | |
| 1619 | .None => return irb.buildConstValue(scope, src_span, &primitive_type.base), | |
| 1621 | 1620 | } |
| 1622 | 1621 | } |
| 1623 | 1622 | } else |err| switch (err) { |
| ... | ... | @@ -1629,22 +1628,22 @@ pub const Builder = struct { |
| 1629 | 1628 | } |
| 1630 | 1629 | |
| 1631 | 1630 | switch (irb.findIdent(scope, name)) { |
| 1632 | Ident.Decl => |decl| { | |
| 1631 | .Decl => |decl| { | |
| 1633 | 1632 | return irb.build(Inst.DeclRef, scope, src_span, Inst.DeclRef.Params{ |
| 1634 | 1633 | .decl = decl, |
| 1635 | 1634 | .lval = lval, |
| 1636 | 1635 | }); |
| 1637 | 1636 | }, |
| 1638 | Ident.VarScope => |var_scope| { | |
| 1637 | .VarScope => |var_scope| { | |
| 1639 | 1638 | const var_ptr = try irb.build(Inst.VarPtr, scope, src_span, Inst.VarPtr.Params{ .var_scope = var_scope }); |
| 1640 | 1639 | switch (lval) { |
| 1641 | LVal.Ptr => return var_ptr, | |
| 1642 | LVal.None => { | |
| 1640 | .Ptr => return var_ptr, | |
| 1641 | .None => { | |
| 1643 | 1642 | return irb.build(Inst.LoadPtr, scope, src_span, Inst.LoadPtr.Params{ .target = var_ptr }); |
| 1644 | 1643 | }, |
| 1645 | 1644 | } |
| 1646 | 1645 | }, |
| 1647 | Ident.NotFound => {}, | |
| 1646 | .NotFound => {}, | |
| 1648 | 1647 | } |
| 1649 | 1648 | |
| 1650 | 1649 | //if (node->owner->any_imports_failed) { |
| ... | ... | @@ -1671,25 +1670,25 @@ pub const Builder = struct { |
| 1671 | 1670 | var scope = inner_scope; |
| 1672 | 1671 | while (scope != outer_scope) { |
| 1673 | 1672 | switch (scope.id) { |
| 1674 | Scope.Id.Defer => { | |
| 1673 | .Defer => { | |
| 1675 | 1674 | const defer_scope = @fieldParentPtr(Scope.Defer, "base", scope); |
| 1676 | 1675 | switch (defer_scope.kind) { |
| 1677 | Scope.Defer.Kind.ScopeExit => result.scope_exit += 1, | |
| 1678 | Scope.Defer.Kind.ErrorExit => result.error_exit += 1, | |
| 1676 | .ScopeExit => result.scope_exit += 1, | |
| 1677 | .ErrorExit => result.error_exit += 1, | |
| 1679 | 1678 | } |
| 1680 | 1679 | scope = scope.parent orelse break; |
| 1681 | 1680 | }, |
| 1682 | Scope.Id.FnDef => break, | |
| 1681 | .FnDef => break, | |
| 1683 | 1682 | |
| 1684 | Scope.Id.CompTime, | |
| 1685 | Scope.Id.Block, | |
| 1686 | Scope.Id.Decls, | |
| 1687 | Scope.Id.Root, | |
| 1688 | Scope.Id.Var, | |
| 1683 | .CompTime, | |
| 1684 | .Block, | |
| 1685 | .Decls, | |
| 1686 | .Root, | |
| 1687 | .Var, | |
| 1689 | 1688 | => scope = scope.parent orelse break, |
| 1690 | 1689 | |
| 1691 | Scope.Id.DeferExpr => unreachable, | |
| 1692 | Scope.Id.AstTree => unreachable, | |
| 1690 | .DeferExpr => unreachable, | |
| 1691 | .AstTree => unreachable, | |
| 1693 | 1692 | } |
| 1694 | 1693 | } |
| 1695 | 1694 | return result; |
| ... | ... | @@ -1705,18 +1704,18 @@ pub const Builder = struct { |
| 1705 | 1704 | var is_noreturn = false; |
| 1706 | 1705 | while (true) { |
| 1707 | 1706 | switch (scope.id) { |
| 1708 | Scope.Id.Defer => { | |
| 1707 | .Defer => { | |
| 1709 | 1708 | const defer_scope = @fieldParentPtr(Scope.Defer, "base", scope); |
| 1710 | 1709 | const generate = switch (defer_scope.kind) { |
| 1711 | Scope.Defer.Kind.ScopeExit => true, | |
| 1712 | Scope.Defer.Kind.ErrorExit => gen_kind == Scope.Defer.Kind.ErrorExit, | |
| 1710 | .ScopeExit => true, | |
| 1711 | .ErrorExit => gen_kind == .ErrorExit, | |
| 1713 | 1712 | }; |
| 1714 | 1713 | if (generate) { |
| 1715 | 1714 | const defer_expr_scope = defer_scope.defer_expr_scope; |
| 1716 | 1715 | const instruction = try irb.genNode( |
| 1717 | 1716 | defer_expr_scope.expr_node, |
| 1718 | 1717 | &defer_expr_scope.base, |
| 1719 | LVal.None, | |
| 1718 | .None, | |
| 1720 | 1719 | ); |
| 1721 | 1720 | if (instruction.isNoReturn()) { |
| 1722 | 1721 | is_noreturn = true; |
| ... | ... | @@ -1730,32 +1729,32 @@ pub const Builder = struct { |
| 1730 | 1729 | } |
| 1731 | 1730 | } |
| 1732 | 1731 | }, |
| 1733 | Scope.Id.FnDef, | |
| 1734 | Scope.Id.Decls, | |
| 1735 | Scope.Id.Root, | |
| 1732 | .FnDef, | |
| 1733 | .Decls, | |
| 1734 | .Root, | |
| 1736 | 1735 | => return is_noreturn, |
| 1737 | 1736 | |
| 1738 | Scope.Id.CompTime, | |
| 1739 | Scope.Id.Block, | |
| 1740 | Scope.Id.Var, | |
| 1737 | .CompTime, | |
| 1738 | .Block, | |
| 1739 | .Var, | |
| 1741 | 1740 | => scope = scope.parent orelse return is_noreturn, |
| 1742 | 1741 | |
| 1743 | Scope.Id.DeferExpr => unreachable, | |
| 1744 | Scope.Id.AstTree => unreachable, | |
| 1742 | .DeferExpr => unreachable, | |
| 1743 | .AstTree => unreachable, | |
| 1745 | 1744 | } |
| 1746 | 1745 | } |
| 1747 | 1746 | } |
| 1748 | 1747 | |
| 1749 | 1748 | pub fn lvalWrap(irb: *Builder, scope: *Scope, instruction: *Inst, lval: LVal) !*Inst { |
| 1750 | 1749 | switch (lval) { |
| 1751 | LVal.None => return instruction, | |
| 1752 | LVal.Ptr => { | |
| 1750 | .None => return instruction, | |
| 1751 | .Ptr => { | |
| 1753 | 1752 | // We needed a pointer to a value, but we got a value. So we create |
| 1754 | 1753 | // an instruction which just makes a const pointer of it. |
| 1755 | 1754 | return irb.build(Inst.Ref, scope, instruction.span, Inst.Ref.Params{ |
| 1756 | 1755 | .target = instruction, |
| 1757 | .mut = Type.Pointer.Mut.Const, | |
| 1758 | .volatility = Type.Pointer.Vol.Non, | |
| 1756 | .mut = .Const, | |
| 1757 | .volatility = .Non, | |
| 1759 | 1758 | }); |
| 1760 | 1759 | }, |
| 1761 | 1760 | } |
| ... | ... | @@ -1781,9 +1780,9 @@ pub const Builder = struct { |
| 1781 | 1780 | .scope = scope, |
| 1782 | 1781 | .debug_id = self.next_debug_id, |
| 1783 | 1782 | .val = switch (I.ir_val_init) { |
| 1784 | IrVal.Init.Unknown => IrVal.Unknown, | |
| 1785 | IrVal.Init.NoReturn => IrVal{ .KnownValue = &Value.NoReturn.get(self.comp).base }, | |
| 1786 | IrVal.Init.Void => IrVal{ .KnownValue = &Value.Void.get(self.comp).base }, | |
| 1783 | .Unknown => IrVal.Unknown, | |
| 1784 | .NoReturn => IrVal{ .KnownValue = &Value.NoReturn.get(self.comp).base }, | |
| 1785 | .Void => IrVal{ .KnownValue = &Value.Void.get(self.comp).base }, | |
| 1787 | 1786 | }, |
| 1788 | 1787 | .ref_count = 0, |
| 1789 | 1788 | .span = span, |
| ... | ... | @@ -1813,9 +1812,9 @@ pub const Builder = struct { |
| 1813 | 1812 | for (@field(inst.params, @memberName(I.Params, i))) |other| |
| 1814 | 1813 | other.ref(self); |
| 1815 | 1814 | }, |
| 1816 | Type.Pointer.Mut, | |
| 1817 | Type.Pointer.Vol, | |
| 1818 | Type.Pointer.Size, | |
| 1815 | .Mut, | |
| 1816 | .Vol, | |
| 1817 | .Size, | |
| 1819 | 1818 | LVal, |
| 1820 | 1819 | *Decl, |
| 1821 | 1820 | *Scope.Var, |
| ... | ... | @@ -1915,8 +1914,8 @@ pub const Builder = struct { |
| 1915 | 1914 | var s = scope; |
| 1916 | 1915 | while (true) { |
| 1917 | 1916 | switch (s.id) { |
| 1918 | Scope.Id.Root => return Ident.NotFound, | |
| 1919 | Scope.Id.Decls => { | |
| 1917 | .Root => return .NotFound, | |
| 1918 | .Decls => { | |
| 1920 | 1919 | const decls = @fieldParentPtr(Scope.Decls, "base", s); |
| 1921 | 1920 | const locked_table = decls.table.acquireRead(); |
| 1922 | 1921 | defer locked_table.release(); |
| ... | ... | @@ -1924,7 +1923,7 @@ pub const Builder = struct { |
| 1924 | 1923 | return Ident{ .Decl = entry.value }; |
| 1925 | 1924 | } |
| 1926 | 1925 | }, |
| 1927 | Scope.Id.Var => { | |
| 1926 | .Var => { | |
| 1928 | 1927 | const var_scope = @fieldParentPtr(Scope.Var, "base", s); |
| 1929 | 1928 | if (mem.eql(u8, var_scope.name, name)) { |
| 1930 | 1929 | return Ident{ .VarScope = var_scope }; |
| ... | ... | @@ -2047,7 +2046,7 @@ const Analyze = struct { |
| 2047 | 2046 | fn implicitCast(self: *Analyze, target: *Inst, optional_dest_type: ?*Type) Analyze.Error!*Inst { |
| 2048 | 2047 | const dest_type = optional_dest_type orelse return target; |
| 2049 | 2048 | const from_type = target.getKnownType(); |
| 2050 | if (from_type == dest_type or from_type.id == Type.Id.NoReturn) return target; | |
| 2049 | if (from_type == dest_type or from_type.id == .NoReturn) return target; | |
| 2051 | 2050 | return self.analyzeCast(target, target, dest_type); |
| 2052 | 2051 | } |
| 2053 | 2052 | |
| ... | ... | @@ -2311,7 +2310,7 @@ const Analyze = struct { |
| 2311 | 2310 | //} |
| 2312 | 2311 | |
| 2313 | 2312 | // cast from comptime-known integer to another integer where the value fits |
| 2314 | if (target.isCompTime() and (from_type.id == Type.Id.Int or from_type.id == Type.Id.ComptimeInt)) cast: { | |
| 2313 | if (target.isCompTime() and (from_type.id == .Int or from_type.id == .ComptimeInt)) cast: { | |
| 2315 | 2314 | const target_val = target.val.KnownValue; |
| 2316 | 2315 | const from_int = &target_val.cast(Value.Int).?.big_int; |
| 2317 | 2316 | const fits = fits: { |
| ... | ... | @@ -2534,7 +2533,7 @@ pub async fn gen( |
| 2534 | 2533 | entry_block.ref(&irb); // Entry block gets a reference because we enter it to begin. |
| 2535 | 2534 | try irb.setCursorAtEndAndAppendBlock(entry_block); |
| 2536 | 2535 | |
| 2537 | const result = try irb.genNode(body_node, scope, LVal.None); | |
| 2536 | const result = try irb.genNode(body_node, scope, .None); | |
| 2538 | 2537 | if (!result.isNoReturn()) { |
| 2539 | 2538 | // no need for save_err_ret_addr because this cannot return error |
| 2540 | 2539 | _ = try irb.genAsyncReturn(scope, Span.token(body_node.lastToken()), result, true); |
src-self-hosted/libc_installation.zig+8-8| ... | ... | @@ -73,7 +73,7 @@ pub const LibCInstallation = struct { |
| 73 | 73 | if (std.mem.eql(u8, name, key)) { |
| 74 | 74 | found_keys[i].found = true; |
| 75 | 75 | switch (@typeInfo(@typeOf(@field(self, key)))) { |
| 76 | builtin.TypeId.Optional => { | |
| 76 | .Optional => { | |
| 77 | 77 | if (value.len == 0) { |
| 78 | 78 | @field(self, key) = null; |
| 79 | 79 | } else { |
| ... | ... | @@ -208,7 +208,7 @@ pub const LibCInstallation = struct { |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | switch (exec_result.term) { |
| 211 | std.ChildProcess.Term.Exited => |code| { | |
| 211 | .Exited => |code| { | |
| 212 | 212 | if (code != 0) return error.CCompilerExitCode; |
| 213 | 213 | }, |
| 214 | 214 | else => { |
| ... | ... | @@ -284,9 +284,9 @@ pub const LibCInstallation = struct { |
| 284 | 284 | const stream = &std.io.BufferOutStream.init(&result_buf).stream; |
| 285 | 285 | try stream.print("{}\\Lib\\{}\\ucrt\\", search.path, search.version); |
| 286 | 286 | switch (builtin.arch) { |
| 287 | builtin.Arch.i386 => try stream.write("x86"), | |
| 288 | builtin.Arch.x86_64 => try stream.write("x64"), | |
| 289 | builtin.Arch.aarch64 => try stream.write("arm"), | |
| 287 | .i386 => try stream.write("x86"), | |
| 288 | .x86_64 => try stream.write("x64"), | |
| 289 | .aarch64 => try stream.write("arm"), | |
| 290 | 290 | else => return error.UnsupportedArchitecture, |
| 291 | 291 | } |
| 292 | 292 | const ucrt_lib_path = try fs.path.join( |
| ... | ... | @@ -362,9 +362,9 @@ pub const LibCInstallation = struct { |
| 362 | 362 | const stream = &std.io.BufferOutStream.init(&result_buf).stream; |
| 363 | 363 | try stream.print("{}\\Lib\\{}\\um\\", search.path, search.version); |
| 364 | 364 | switch (builtin.arch) { |
| 365 | builtin.Arch.i386 => try stream.write("x86\\"), | |
| 366 | builtin.Arch.x86_64 => try stream.write("x64\\"), | |
| 367 | builtin.Arch.aarch64 => try stream.write("arm\\"), | |
| 365 | .i386 => try stream.write("x86\\"), | |
| 366 | .x86_64 => try stream.write("x64\\"), | |
| 367 | .aarch64 => try stream.write("arm\\"), | |
| 368 | 368 | else => return error.UnsupportedArchitecture, |
| 369 | 369 | } |
| 370 | 370 | const kernel32_path = try fs.path.join( |
src-self-hosted/link.zig+42-43| ... | ... | @@ -1,10 +1,9 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | 3 | const c = @import("c.zig"); |
| 4 | const builtin = @import("builtin"); | |
| 5 | const ObjectFormat = builtin.ObjectFormat; | |
| 6 | 4 | const Compilation = @import("compilation.zig").Compilation; |
| 7 | 5 | const Target = std.Target; |
| 6 | const ObjectFormat = Target.ObjectFormat; | |
| 8 | 7 | const LibCInstallation = @import("libc_installation.zig").LibCInstallation; |
| 9 | 8 | const assert = std.debug.assert; |
| 10 | 9 | |
| ... | ... | @@ -26,7 +25,7 @@ pub async fn link(comp: *Compilation) !void { |
| 26 | 25 | .comp = comp, |
| 27 | 26 | .arena = std.heap.ArenaAllocator.init(comp.gpa()), |
| 28 | 27 | .args = undefined, |
| 29 | .link_in_crt = comp.haveLibC() and comp.kind == Compilation.Kind.Exe, | |
| 28 | .link_in_crt = comp.haveLibC() and comp.kind == .Exe, | |
| 30 | 29 | .link_err = {}, |
| 31 | 30 | .link_msg = undefined, |
| 32 | 31 | .libc = undefined, |
| ... | ... | @@ -41,13 +40,13 @@ pub async fn link(comp: *Compilation) !void { |
| 41 | 40 | } else { |
| 42 | 41 | ctx.out_file_path = try std.Buffer.init(&ctx.arena.allocator, comp.name.toSliceConst()); |
| 43 | 42 | switch (comp.kind) { |
| 44 | Compilation.Kind.Exe => { | |
| 43 | .Exe => { | |
| 45 | 44 | try ctx.out_file_path.append(comp.target.exeFileExt()); |
| 46 | 45 | }, |
| 47 | Compilation.Kind.Lib => { | |
| 46 | .Lib => { | |
| 48 | 47 | try ctx.out_file_path.append(comp.target.libFileExt(comp.is_static)); |
| 49 | 48 | }, |
| 50 | Compilation.Kind.Obj => { | |
| 49 | .Obj => { | |
| 51 | 50 | try ctx.out_file_path.append(comp.target.objFileExt()); |
| 52 | 51 | }, |
| 53 | 52 | } |
| ... | ... | @@ -121,21 +120,21 @@ fn linkDiagCallbackErrorable(ctx: *Context, msg: []const u8) !void { |
| 121 | 120 | |
| 122 | 121 | fn toExternObjectFormatType(ofmt: ObjectFormat) c.ZigLLVM_ObjectFormatType { |
| 123 | 122 | return switch (ofmt) { |
| 124 | ObjectFormat.unknown => c.ZigLLVM_UnknownObjectFormat, | |
| 125 | ObjectFormat.coff => c.ZigLLVM_COFF, | |
| 126 | ObjectFormat.elf => c.ZigLLVM_ELF, | |
| 127 | ObjectFormat.macho => c.ZigLLVM_MachO, | |
| 128 | ObjectFormat.wasm => c.ZigLLVM_Wasm, | |
| 123 | .unknown => c.ZigLLVM_UnknownObjectFormat, | |
| 124 | .coff => c.ZigLLVM_COFF, | |
| 125 | .elf => c.ZigLLVM_ELF, | |
| 126 | .macho => c.ZigLLVM_MachO, | |
| 127 | .wasm => c.ZigLLVM_Wasm, | |
| 129 | 128 | }; |
| 130 | 129 | } |
| 131 | 130 | |
| 132 | 131 | fn constructLinkerArgs(ctx: *Context) !void { |
| 133 | 132 | switch (ctx.comp.target.getObjectFormat()) { |
| 134 | ObjectFormat.unknown => unreachable, | |
| 135 | ObjectFormat.coff => return constructLinkerArgsCoff(ctx), | |
| 136 | ObjectFormat.elf => return constructLinkerArgsElf(ctx), | |
| 137 | ObjectFormat.macho => return constructLinkerArgsMachO(ctx), | |
| 138 | ObjectFormat.wasm => return constructLinkerArgsWasm(ctx), | |
| 133 | .unknown => unreachable, | |
| 134 | .coff => return constructLinkerArgsCoff(ctx), | |
| 135 | .elf => return constructLinkerArgsElf(ctx), | |
| 136 | .macho => return constructLinkerArgsMachO(ctx), | |
| 137 | .wasm => return constructLinkerArgsWasm(ctx), | |
| 139 | 138 | } |
| 140 | 139 | } |
| 141 | 140 | |
| ... | ... | @@ -324,9 +323,9 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 324 | 323 | } |
| 325 | 324 | |
| 326 | 325 | switch (ctx.comp.target.getArch()) { |
| 327 | builtin.Arch.i386 => try ctx.args.append(c"-MACHINE:X86"), | |
| 328 | builtin.Arch.x86_64 => try ctx.args.append(c"-MACHINE:X64"), | |
| 329 | builtin.Arch.aarch64 => try ctx.args.append(c"-MACHINE:ARM"), | |
| 326 | .i386 => try ctx.args.append(c"-MACHINE:X86"), | |
| 327 | .x86_64 => try ctx.args.append(c"-MACHINE:X64"), | |
| 328 | .aarch64 => try ctx.args.append(c"-MACHINE:ARM"), | |
| 330 | 329 | else => return error.UnsupportedLinkArchitecture, |
| 331 | 330 | } |
| 332 | 331 | |
| ... | ... | @@ -336,7 +335,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 336 | 335 | try ctx.args.append(c"/SUBSYSTEM:console"); |
| 337 | 336 | } |
| 338 | 337 | |
| 339 | const is_library = ctx.comp.kind == Compilation.Kind.Lib; | |
| 338 | const is_library = ctx.comp.kind == .Lib; | |
| 340 | 339 | |
| 341 | 340 | const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", ctx.out_file_path.toSliceConst()); |
| 342 | 341 | try ctx.args.append(out_arg.ptr); |
| ... | ... | @@ -349,7 +348,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 349 | 348 | |
| 350 | 349 | if (ctx.link_in_crt) { |
| 351 | 350 | const lib_str = if (ctx.comp.is_static) "lib" else ""; |
| 352 | const d_str = if (ctx.comp.build_mode == builtin.Mode.Debug) "d" else ""; | |
| 351 | const d_str = if (ctx.comp.build_mode == .Debug) "d" else ""; | |
| 353 | 352 | |
| 354 | 353 | if (ctx.comp.is_static) { |
| 355 | 354 | const cmt_lib_name = try std.fmt.allocPrint(&ctx.arena.allocator, "libcmt{}.lib\x00", d_str); |
| ... | ... | @@ -400,7 +399,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 400 | 399 | try addFnObjects(ctx); |
| 401 | 400 | |
| 402 | 401 | switch (ctx.comp.kind) { |
| 403 | Compilation.Kind.Exe, Compilation.Kind.Lib => { | |
| 402 | .Exe, .Lib => { | |
| 404 | 403 | if (!ctx.comp.haveLibC()) { |
| 405 | 404 | @panic("TODO"); |
| 406 | 405 | //Buf *builtin_o_path = build_o(g, "builtin"); |
| ... | ... | @@ -412,7 +411,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 412 | 411 | //Buf *compiler_rt_o_path = build_compiler_rt(g); |
| 413 | 412 | //lj->args.append(buf_ptr(compiler_rt_o_path)); |
| 414 | 413 | }, |
| 415 | Compilation.Kind.Obj => {}, | |
| 414 | .Obj => {}, | |
| 416 | 415 | } |
| 417 | 416 | |
| 418 | 417 | //Buf *def_contents = buf_alloc(); |
| ... | ... | @@ -469,7 +468,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 469 | 468 | try ctx.args.append(c"-export_dynamic"); |
| 470 | 469 | } |
| 471 | 470 | |
| 472 | const is_lib = ctx.comp.kind == Compilation.Kind.Lib; | |
| 471 | const is_lib = ctx.comp.kind == .Lib; | |
| 473 | 472 | const shared = !ctx.comp.is_static and is_lib; |
| 474 | 473 | if (ctx.comp.is_static) { |
| 475 | 474 | try ctx.args.append(c"-static"); |
| ... | ... | @@ -512,14 +511,14 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 512 | 511 | |
| 513 | 512 | const platform = try DarwinPlatform.get(ctx.comp); |
| 514 | 513 | switch (platform.kind) { |
| 515 | DarwinPlatform.Kind.MacOS => try ctx.args.append(c"-macosx_version_min"), | |
| 516 | DarwinPlatform.Kind.IPhoneOS => try ctx.args.append(c"-iphoneos_version_min"), | |
| 517 | DarwinPlatform.Kind.IPhoneOSSimulator => try ctx.args.append(c"-ios_simulator_version_min"), | |
| 514 | .MacOS => try ctx.args.append(c"-macosx_version_min"), | |
| 515 | .IPhoneOS => try ctx.args.append(c"-iphoneos_version_min"), | |
| 516 | .IPhoneOSSimulator => try ctx.args.append(c"-ios_simulator_version_min"), | |
| 518 | 517 | } |
| 519 | 518 | const ver_str = try std.fmt.allocPrint(&ctx.arena.allocator, "{}.{}.{}\x00", platform.major, platform.minor, platform.micro); |
| 520 | 519 | try ctx.args.append(ver_str.ptr); |
| 521 | 520 | |
| 522 | if (ctx.comp.kind == Compilation.Kind.Exe) { | |
| 521 | if (ctx.comp.kind == .Exe) { | |
| 523 | 522 | if (ctx.comp.is_static) { |
| 524 | 523 | try ctx.args.append(c"-no_pie"); |
| 525 | 524 | } else { |
| ... | ... | @@ -542,7 +541,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 542 | 541 | try ctx.args.append(c"-lcrt0.o"); |
| 543 | 542 | } else { |
| 544 | 543 | switch (platform.kind) { |
| 545 | DarwinPlatform.Kind.MacOS => { | |
| 544 | .MacOS => { | |
| 546 | 545 | if (platform.versionLessThan(10, 5)) { |
| 547 | 546 | try ctx.args.append(c"-lcrt1.o"); |
| 548 | 547 | } else if (platform.versionLessThan(10, 6)) { |
| ... | ... | @@ -551,8 +550,8 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 551 | 550 | try ctx.args.append(c"-lcrt1.10.6.o"); |
| 552 | 551 | } |
| 553 | 552 | }, |
| 554 | DarwinPlatform.Kind.IPhoneOS => { | |
| 555 | if (ctx.comp.target.getArch() == builtin.Arch.aarch64) { | |
| 553 | .IPhoneOS => { | |
| 554 | if (ctx.comp.target.getArch() == .aarch64) { | |
| 556 | 555 | // iOS does not need any crt1 files for arm64 |
| 557 | 556 | } else if (platform.versionLessThan(3, 1)) { |
| 558 | 557 | try ctx.args.append(c"-lcrt1.o"); |
| ... | ... | @@ -560,7 +559,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 560 | 559 | try ctx.args.append(c"-lcrt1.3.1.o"); |
| 561 | 560 | } |
| 562 | 561 | }, |
| 563 | DarwinPlatform.Kind.IPhoneOSSimulator => {}, // no crt1.o needed | |
| 562 | .IPhoneOSSimulator => {}, // no crt1.o needed | |
| 564 | 563 | } |
| 565 | 564 | } |
| 566 | 565 | |
| ... | ... | @@ -605,7 +604,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 605 | 604 | try ctx.args.append(c"dynamic_lookup"); |
| 606 | 605 | } |
| 607 | 606 | |
| 608 | if (platform.kind == DarwinPlatform.Kind.MacOS) { | |
| 607 | if (platform.kind == .MacOS) { | |
| 609 | 608 | if (platform.versionLessThan(10, 5)) { |
| 610 | 609 | try ctx.args.append(c"-lgcc_s.10.4"); |
| 611 | 610 | } else if (platform.versionLessThan(10, 6)) { |
| ... | ... | @@ -659,17 +658,17 @@ const DarwinPlatform = struct { |
| 659 | 658 | fn get(comp: *Compilation) !DarwinPlatform { |
| 660 | 659 | var result: DarwinPlatform = undefined; |
| 661 | 660 | const ver_str = switch (comp.darwin_version_min) { |
| 662 | Compilation.DarwinVersionMin.MacOS => |ver| blk: { | |
| 663 | result.kind = Kind.MacOS; | |
| 661 | .MacOS => |ver| blk: { | |
| 662 | result.kind = .MacOS; | |
| 664 | 663 | break :blk ver; |
| 665 | 664 | }, |
| 666 | Compilation.DarwinVersionMin.Ios => |ver| blk: { | |
| 667 | result.kind = Kind.IPhoneOS; | |
| 665 | .Ios => |ver| blk: { | |
| 666 | result.kind = .IPhoneOS; | |
| 668 | 667 | break :blk ver; |
| 669 | 668 | }, |
| 670 | Compilation.DarwinVersionMin.None => blk: { | |
| 669 | .None => blk: { | |
| 671 | 670 | assert(comp.target.getOs() == .macosx); |
| 672 | result.kind = Kind.MacOS; | |
| 671 | result.kind = .MacOS; | |
| 673 | 672 | break :blk "10.14"; |
| 674 | 673 | }, |
| 675 | 674 | }; |
| ... | ... | @@ -686,11 +685,11 @@ const DarwinPlatform = struct { |
| 686 | 685 | return error.InvalidDarwinVersionString; |
| 687 | 686 | } |
| 688 | 687 | |
| 689 | if (result.kind == Kind.IPhoneOS) { | |
| 688 | if (result.kind == .IPhoneOS) { | |
| 690 | 689 | switch (comp.target.getArch()) { |
| 691 | builtin.Arch.i386, | |
| 692 | builtin.Arch.x86_64, | |
| 693 | => result.kind = Kind.IPhoneOSSimulator, | |
| 690 | .i386, | |
| 691 | .x86_64, | |
| 692 | => result.kind = .IPhoneOSSimulator, | |
| 694 | 693 | else => {}, |
| 695 | 694 | } |
| 696 | 695 | } |
src-self-hosted/llvm.zig+1-2| ... | ... | @@ -1,4 +1,3 @@ |
| 1 | const builtin = @import("builtin"); | |
| 2 | 1 | const c = @import("c.zig"); |
| 3 | 2 | const std = @import("std"); |
| 4 | 3 | const assert = std.debug.assert; |
| ... | ... | @@ -269,7 +268,7 @@ pub const FnInline = extern enum { |
| 269 | 268 | }; |
| 270 | 269 | |
| 271 | 270 | fn removeNullability(comptime T: type) type { |
| 272 | comptime assert(@typeInfo(T).Pointer.size == @import("builtin").TypeInfo.Pointer.Size.C); | |
| 271 | comptime assert(@typeInfo(T).Pointer.size == .C); | |
| 273 | 272 | return *T.Child; |
| 274 | 273 | } |
| 275 | 274 |
src-self-hosted/main.zig+12-12| ... | ... | @@ -266,16 +266,16 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 266 | 266 | const build_mode = blk: { |
| 267 | 267 | if (flags.single("mode")) |mode_flag| { |
| 268 | 268 | if (mem.eql(u8, mode_flag, "debug")) { |
| 269 | break :blk builtin.Mode.Debug; | |
| 269 | break :blk std.builtin.Mode.Debug; | |
| 270 | 270 | } else if (mem.eql(u8, mode_flag, "release-fast")) { |
| 271 | break :blk builtin.Mode.ReleaseFast; | |
| 271 | break :blk std.builtin.Mode.ReleaseFast; | |
| 272 | 272 | } else if (mem.eql(u8, mode_flag, "release-safe")) { |
| 273 | break :blk builtin.Mode.ReleaseSafe; | |
| 273 | break :blk std.builtin.Mode.ReleaseSafe; | |
| 274 | 274 | } else if (mem.eql(u8, mode_flag, "release-small")) { |
| 275 | break :blk builtin.Mode.ReleaseSmall; | |
| 275 | break :blk std.builtin.Mode.ReleaseSmall; | |
| 276 | 276 | } else unreachable; |
| 277 | 277 | } else { |
| 278 | break :blk builtin.Mode.Debug; | |
| 278 | break :blk std.builtin.Mode.Debug; | |
| 279 | 279 | } |
| 280 | 280 | }; |
| 281 | 281 | |
| ... | ... | @@ -475,13 +475,13 @@ async fn processBuildEvents(comp: *Compilation, color: errmsg.Color) void { |
| 475 | 475 | count += 1; |
| 476 | 476 | |
| 477 | 477 | switch (build_event) { |
| 478 | Compilation.Event.Ok => { | |
| 478 | .Ok => { | |
| 479 | 479 | stderr.print("Build {} succeeded\n", count) catch process.exit(1); |
| 480 | 480 | }, |
| 481 | Compilation.Event.Error => |err| { | |
| 481 | .Error => |err| { | |
| 482 | 482 | stderr.print("Build {} failed: {}\n", count, @errorName(err)) catch process.exit(1); |
| 483 | 483 | }, |
| 484 | Compilation.Event.Fail => |msgs| { | |
| 484 | .Fail => |msgs| { | |
| 485 | 485 | stderr.print("Build {} compile errors:\n", count) catch process.exit(1); |
| 486 | 486 | for (msgs) |msg| { |
| 487 | 487 | defer msg.destroy(); |
| ... | ... | @@ -795,8 +795,8 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void { |
| 795 | 795 | try stdout.write("Operating Systems:\n"); |
| 796 | 796 | { |
| 797 | 797 | comptime var i: usize = 0; |
| 798 | inline while (i < @memberCount(builtin.Os)) : (i += 1) { | |
| 799 | comptime const os_tag = @memberName(builtin.Os, i); | |
| 798 | inline while (i < @memberCount(Target.Os)) : (i += 1) { | |
| 799 | comptime const os_tag = @memberName(Target.Os, i); | |
| 800 | 800 | // NOTE: Cannot use empty string, see #918. |
| 801 | 801 | comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n"; |
| 802 | 802 | |
| ... | ... | @@ -808,8 +808,8 @@ fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void { |
| 808 | 808 | try stdout.write("C ABIs:\n"); |
| 809 | 809 | { |
| 810 | 810 | comptime var i: usize = 0; |
| 811 | inline while (i < @memberCount(builtin.Abi)) : (i += 1) { | |
| 812 | comptime const abi_tag = @memberName(builtin.Abi, i); | |
| 811 | inline while (i < @memberCount(Target.Abi)) : (i += 1) { | |
| 812 | comptime const abi_tag = @memberName(Target.Abi, i); | |
| 813 | 813 | // NOTE: Cannot use empty string, see #918. |
| 814 | 814 | comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n"; |
| 815 | 815 |
src-self-hosted/scope.zig+45-46| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const Allocator = mem.Allocator; |
| 4 | 3 | const Decl = @import("decl.zig").Decl; |
| 5 | 4 | const Compilation = @import("compilation.zig").Compilation; |
| ... | ... | @@ -28,15 +27,15 @@ pub const Scope = struct { |
| 28 | 27 | if (base.ref_count.decr() == 1) { |
| 29 | 28 | if (base.parent) |parent| parent.deref(comp); |
| 30 | 29 | switch (base.id) { |
| 31 | Id.Root => @fieldParentPtr(Root, "base", base).destroy(comp), | |
| 32 | Id.Decls => @fieldParentPtr(Decls, "base", base).destroy(comp), | |
| 33 | Id.Block => @fieldParentPtr(Block, "base", base).destroy(comp), | |
| 34 | Id.FnDef => @fieldParentPtr(FnDef, "base", base).destroy(comp), | |
| 35 | Id.CompTime => @fieldParentPtr(CompTime, "base", base).destroy(comp), | |
| 36 | Id.Defer => @fieldParentPtr(Defer, "base", base).destroy(comp), | |
| 37 | Id.DeferExpr => @fieldParentPtr(DeferExpr, "base", base).destroy(comp), | |
| 38 | Id.Var => @fieldParentPtr(Var, "base", base).destroy(comp), | |
| 39 | Id.AstTree => @fieldParentPtr(AstTree, "base", base).destroy(comp), | |
| 30 | .Root => @fieldParentPtr(Root, "base", base).destroy(comp), | |
| 31 | .Decls => @fieldParentPtr(Decls, "base", base).destroy(comp), | |
| 32 | .Block => @fieldParentPtr(Block, "base", base).destroy(comp), | |
| 33 | .FnDef => @fieldParentPtr(FnDef, "base", base).destroy(comp), | |
| 34 | .CompTime => @fieldParentPtr(CompTime, "base", base).destroy(comp), | |
| 35 | .Defer => @fieldParentPtr(Defer, "base", base).destroy(comp), | |
| 36 | .DeferExpr => @fieldParentPtr(DeferExpr, "base", base).destroy(comp), | |
| 37 | .Var => @fieldParentPtr(Var, "base", base).destroy(comp), | |
| 38 | .AstTree => @fieldParentPtr(AstTree, "base", base).destroy(comp), | |
| 40 | 39 | } |
| 41 | 40 | } |
| 42 | 41 | } |
| ... | ... | @@ -46,7 +45,7 @@ pub const Scope = struct { |
| 46 | 45 | while (scope.parent) |parent| { |
| 47 | 46 | scope = parent; |
| 48 | 47 | } |
| 49 | assert(scope.id == Id.Root); | |
| 48 | assert(scope.id == .Root); | |
| 50 | 49 | return @fieldParentPtr(Root, "base", scope); |
| 51 | 50 | } |
| 52 | 51 | |
| ... | ... | @@ -54,17 +53,17 @@ pub const Scope = struct { |
| 54 | 53 | var scope = base; |
| 55 | 54 | while (true) { |
| 56 | 55 | switch (scope.id) { |
| 57 | Id.FnDef => return @fieldParentPtr(FnDef, "base", scope), | |
| 58 | Id.Root, Id.Decls => return null, | |
| 59 | ||
| 60 | Id.Block, | |
| 61 | Id.Defer, | |
| 62 | Id.DeferExpr, | |
| 63 | Id.CompTime, | |
| 64 | Id.Var, | |
| 56 | .FnDef => return @fieldParentPtr(FnDef, "base", scope), | |
| 57 | .Root, .Decls => return null, | |
| 58 | ||
| 59 | .Block, | |
| 60 | .Defer, | |
| 61 | .DeferExpr, | |
| 62 | .CompTime, | |
| 63 | .Var, | |
| 65 | 64 | => scope = scope.parent.?, |
| 66 | 65 | |
| 67 | Id.AstTree => unreachable, | |
| 66 | .AstTree => unreachable, | |
| 68 | 67 | } |
| 69 | 68 | } |
| 70 | 69 | } |
| ... | ... | @@ -73,20 +72,20 @@ pub const Scope = struct { |
| 73 | 72 | var scope = base; |
| 74 | 73 | while (true) { |
| 75 | 74 | switch (scope.id) { |
| 76 | Id.DeferExpr => return @fieldParentPtr(DeferExpr, "base", scope), | |
| 75 | .DeferExpr => return @fieldParentPtr(DeferExpr, "base", scope), | |
| 77 | 76 | |
| 78 | Id.FnDef, | |
| 79 | Id.Decls, | |
| 77 | .FnDef, | |
| 78 | .Decls, | |
| 80 | 79 | => return null, |
| 81 | 80 | |
| 82 | Id.Block, | |
| 83 | Id.Defer, | |
| 84 | Id.CompTime, | |
| 85 | Id.Root, | |
| 86 | Id.Var, | |
| 81 | .Block, | |
| 82 | .Defer, | |
| 83 | .CompTime, | |
| 84 | .Root, | |
| 85 | .Var, | |
| 87 | 86 | => scope = scope.parent orelse return null, |
| 88 | 87 | |
| 89 | Id.AstTree => unreachable, | |
| 88 | .AstTree => unreachable, | |
| 90 | 89 | } |
| 91 | 90 | } |
| 92 | 91 | } |
| ... | ... | @@ -123,7 +122,7 @@ pub const Scope = struct { |
| 123 | 122 | const self = try comp.gpa().create(Root); |
| 124 | 123 | self.* = Root{ |
| 125 | 124 | .base = Scope{ |
| 126 | .id = Id.Root, | |
| 125 | .id = .Root, | |
| 127 | 126 | .parent = null, |
| 128 | 127 | .ref_count = std.atomic.Int(usize).init(1), |
| 129 | 128 | }, |
| ... | ... | @@ -155,7 +154,7 @@ pub const Scope = struct { |
| 155 | 154 | .base = undefined, |
| 156 | 155 | .tree = tree, |
| 157 | 156 | }; |
| 158 | self.base.init(Id.AstTree, &root_scope.base); | |
| 157 | self.base.init(.AstTree, &root_scope.base); | |
| 159 | 158 | |
| 160 | 159 | return self; |
| 161 | 160 | } |
| ... | ... | @@ -186,7 +185,7 @@ pub const Scope = struct { |
| 186 | 185 | .base = undefined, |
| 187 | 186 | .table = event.RwLocked(Decl.Table).init(Decl.Table.init(comp.gpa())), |
| 188 | 187 | }; |
| 189 | self.base.init(Id.Decls, parent); | |
| 188 | self.base.init(.Decls, parent); | |
| 190 | 189 | return self; |
| 191 | 190 | } |
| 192 | 191 | |
| ... | ... | @@ -219,15 +218,15 @@ pub const Scope = struct { |
| 219 | 218 | |
| 220 | 219 | fn get(self: Safety, comp: *Compilation) bool { |
| 221 | 220 | return switch (self) { |
| 222 | Safety.Auto => switch (comp.build_mode) { | |
| 223 | builtin.Mode.Debug, | |
| 224 | builtin.Mode.ReleaseSafe, | |
| 221 | .Auto => switch (comp.build_mode) { | |
| 222 | .Debug, | |
| 223 | .ReleaseSafe, | |
| 225 | 224 | => true, |
| 226 | builtin.Mode.ReleaseFast, | |
| 227 | builtin.Mode.ReleaseSmall, | |
| 225 | .ReleaseFast, | |
| 226 | .ReleaseSmall, | |
| 228 | 227 | => false, |
| 229 | 228 | }, |
| 230 | @TagType(Safety).Manual => |man| man.enabled, | |
| 229 | .Manual => |man| man.enabled, | |
| 231 | 230 | }; |
| 232 | 231 | } |
| 233 | 232 | }; |
| ... | ... | @@ -243,7 +242,7 @@ pub const Scope = struct { |
| 243 | 242 | .is_comptime = undefined, |
| 244 | 243 | .safety = Safety.Auto, |
| 245 | 244 | }; |
| 246 | self.base.init(Id.Block, parent); | |
| 245 | self.base.init(.Block, parent); | |
| 247 | 246 | return self; |
| 248 | 247 | } |
| 249 | 248 | |
| ... | ... | @@ -266,7 +265,7 @@ pub const Scope = struct { |
| 266 | 265 | .base = undefined, |
| 267 | 266 | .fn_val = null, |
| 268 | 267 | }; |
| 269 | self.base.init(Id.FnDef, parent); | |
| 268 | self.base.init(.FnDef, parent); | |
| 270 | 269 | return self; |
| 271 | 270 | } |
| 272 | 271 | |
| ... | ... | @@ -282,7 +281,7 @@ pub const Scope = struct { |
| 282 | 281 | pub fn create(comp: *Compilation, parent: *Scope) !*CompTime { |
| 283 | 282 | const self = try comp.gpa().create(CompTime); |
| 284 | 283 | self.* = CompTime{ .base = undefined }; |
| 285 | self.base.init(Id.CompTime, parent); | |
| 284 | self.base.init(.CompTime, parent); | |
| 286 | 285 | return self; |
| 287 | 286 | } |
| 288 | 287 | |
| ... | ... | @@ -314,7 +313,7 @@ pub const Scope = struct { |
| 314 | 313 | .defer_expr_scope = defer_expr_scope, |
| 315 | 314 | .kind = kind, |
| 316 | 315 | }; |
| 317 | self.base.init(Id.Defer, parent); | |
| 316 | self.base.init(.Defer, parent); | |
| 318 | 317 | defer_expr_scope.base.ref(); |
| 319 | 318 | return self; |
| 320 | 319 | } |
| ... | ... | @@ -338,7 +337,7 @@ pub const Scope = struct { |
| 338 | 337 | .expr_node = expr_node, |
| 339 | 338 | .reported_err = false, |
| 340 | 339 | }; |
| 341 | self.base.init(Id.DeferExpr, parent); | |
| 340 | self.base.init(.DeferExpr, parent); | |
| 342 | 341 | return self; |
| 343 | 342 | } |
| 344 | 343 | |
| ... | ... | @@ -404,14 +403,14 @@ pub const Scope = struct { |
| 404 | 403 | .src_node = src_node, |
| 405 | 404 | .data = undefined, |
| 406 | 405 | }; |
| 407 | self.base.init(Id.Var, parent); | |
| 406 | self.base.init(.Var, parent); | |
| 408 | 407 | return self; |
| 409 | 408 | } |
| 410 | 409 | |
| 411 | 410 | pub fn destroy(self: *Var, comp: *Compilation) void { |
| 412 | 411 | switch (self.data) { |
| 413 | Data.Param => {}, | |
| 414 | Data.Const => |value| value.deref(comp), | |
| 412 | .Param => {}, | |
| 413 | .Const => |value| value.deref(comp), | |
| 415 | 414 | } |
| 416 | 415 | comp.gpa().destroy(self); |
| 417 | 416 | } |
src-self-hosted/stage1.zig+5-6| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | // This is Zig code that is used by both stage1 and stage2. |
| 2 | 2 | // The prototypes in src/userland.h must match these definitions. |
| 3 | 3 | |
| 4 | const builtin = @import("builtin"); | |
| 5 | 4 | const std = @import("std"); |
| 6 | 5 | const io = std.io; |
| 7 | 6 | const mem = std.mem; |
| ... | ... | @@ -358,9 +357,9 @@ fn printErrMsgToFile( |
| 358 | 357 | color: errmsg.Color, |
| 359 | 358 | ) !void { |
| 360 | 359 | const color_on = switch (color) { |
| 361 | errmsg.Color.Auto => file.isTty(), | |
| 362 | errmsg.Color.On => true, | |
| 363 | errmsg.Color.Off => false, | |
| 360 | .Auto => file.isTty(), | |
| 361 | .On => true, | |
| 362 | .Off => false, | |
| 364 | 363 | }; |
| 365 | 364 | const lok_token = parse_error.loc(); |
| 366 | 365 | const span = errmsg.Span{ |
| ... | ... | @@ -425,8 +424,8 @@ export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextRes |
| 425 | 424 | const textz = std.Buffer.init(&self.handle.arena.allocator, token.bytes) catch @panic("failed to create .d tokenizer token text"); |
| 426 | 425 | return stage2_DepNextResult{ |
| 427 | 426 | .type_id = switch (token.id) { |
| 428 | .target => stage2_DepNextResult.TypeId.target, | |
| 429 | .prereq => stage2_DepNextResult.TypeId.prereq, | |
| 427 | .target => .target, | |
| 428 | .prereq => .prereq, | |
| 430 | 429 | }, |
| 431 | 430 | .textz = textz.toSlice().ptr, |
| 432 | 431 | }; |
src-self-hosted/test.zig+9-10| ... | ... | @@ -1,6 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const mem = std.mem; |
| 3 | const builtin = @import("builtin"); | |
| 4 | 3 | const Target = std.Target; |
| 5 | 4 | const Compilation = @import("compilation.zig").Compilation; |
| 6 | 5 | const introspect = @import("introspect.zig"); |
| ... | ... | @@ -45,7 +44,7 @@ pub const TestContext = struct { |
| 45 | 44 | errdefer self.zig_compiler.deinit(); |
| 46 | 45 | |
| 47 | 46 | self.group = std.event.Group(anyerror!void).init(allocator); |
| 48 | errdefer self.group.deinit(); | |
| 47 | errdefer self.group.wait(); | |
| 49 | 48 | |
| 50 | 49 | self.zig_lib_dir = try introspect.resolveZigLibDir(allocator); |
| 51 | 50 | errdefer allocator.free(self.zig_lib_dir); |
| ... | ... | @@ -95,7 +94,7 @@ pub const TestContext = struct { |
| 95 | 94 | file1_path, |
| 96 | 95 | Target.Native, |
| 97 | 96 | Compilation.Kind.Obj, |
| 98 | builtin.Mode.Debug, | |
| 97 | .Debug, | |
| 99 | 98 | true, // is_static |
| 100 | 99 | self.zig_lib_dir, |
| 101 | 100 | ); |
| ... | ... | @@ -129,7 +128,7 @@ pub const TestContext = struct { |
| 129 | 128 | file1_path, |
| 130 | 129 | Target.Native, |
| 131 | 130 | Compilation.Kind.Exe, |
| 132 | builtin.Mode.Debug, | |
| 131 | .Debug, | |
| 133 | 132 | false, |
| 134 | 133 | self.zig_lib_dir, |
| 135 | 134 | ); |
| ... | ... | @@ -154,7 +153,7 @@ pub const TestContext = struct { |
| 154 | 153 | const build_event = comp.events.get(); |
| 155 | 154 | |
| 156 | 155 | switch (build_event) { |
| 157 | Compilation.Event.Ok => { | |
| 156 | .Ok => { | |
| 158 | 157 | const argv = []const []const u8{exe_file_2}; |
| 159 | 158 | // TODO use event loop |
| 160 | 159 | const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024); |
| ... | ... | @@ -172,8 +171,8 @@ pub const TestContext = struct { |
| 172 | 171 | return error.OutputMismatch; |
| 173 | 172 | } |
| 174 | 173 | }, |
| 175 | Compilation.Event.Error => |err| return err, | |
| 176 | Compilation.Event.Fail => |msgs| { | |
| 174 | .Error => |err| return err, | |
| 175 | .Fail => |msgs| { | |
| 177 | 176 | var stderr = try std.io.getStdErr(); |
| 178 | 177 | try stderr.write("build incorrectly failed:\n"); |
| 179 | 178 | for (msgs) |msg| { |
| ... | ... | @@ -196,13 +195,13 @@ pub const TestContext = struct { |
| 196 | 195 | const build_event = comp.events.get(); |
| 197 | 196 | |
| 198 | 197 | switch (build_event) { |
| 199 | Compilation.Event.Ok => { | |
| 198 | .Ok => { | |
| 200 | 199 | @panic("build incorrectly succeeded"); |
| 201 | 200 | }, |
| 202 | Compilation.Event.Error => |err| { | |
| 201 | .Error => |err| { | |
| 203 | 202 | @panic("build incorrectly failed"); |
| 204 | 203 | }, |
| 205 | Compilation.Event.Fail => |msgs| { | |
| 204 | .Fail => |msgs| { | |
| 206 | 205 | testing.expect(msgs.len != 0); |
| 207 | 206 | for (msgs) |msg| { |
| 208 | 207 | if (mem.endsWith(u8, msg.realpath, path) and mem.eql(u8, msg.text, text)) { |
src-self-hosted/translate_c.zig+1-2| ... | ... | @@ -2,7 +2,6 @@ |
| 2 | 2 | // and stage2. Currently the only way it is used is with `zig translate-c-2`. |
| 3 | 3 | |
| 4 | 4 | const std = @import("std"); |
| 5 | const builtin = @import("builtin"); | |
| 6 | 5 | const assert = std.debug.assert; |
| 7 | 6 | const ast = std.zig.ast; |
| 8 | 7 | const Token = std.zig.Token; |
| ... | ... | @@ -14,7 +13,7 @@ pub const Mode = enum { |
| 14 | 13 | }; |
| 15 | 14 | |
| 16 | 15 | // TODO merge with Type.Fn.CallingConvention |
| 17 | const CallingConvention = builtin.TypeInfo.CallingConvention; | |
| 16 | const CallingConvention = std.builtin.TypeInfo.CallingConvention; | |
| 18 | 17 | |
| 19 | 18 | pub const ClangErrMsg = Stage2ErrorMsg; |
| 20 | 19 |
src-self-hosted/type.zig+154-154| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 2 | const builtin = std.builtin; | |
| 3 | 3 | const Scope = @import("scope.zig").Scope; |
| 4 | 4 | const Compilation = @import("compilation.zig").Compilation; |
| 5 | 5 | const Value = @import("value.zig").Value; |
| ... | ... | @@ -20,32 +20,32 @@ pub const Type = struct { |
| 20 | 20 | |
| 21 | 21 | pub fn destroy(base: *Type, comp: *Compilation) void { |
| 22 | 22 | switch (base.id) { |
| 23 | Id.Struct => @fieldParentPtr(Struct, "base", base).destroy(comp), | |
| 24 | Id.Fn => @fieldParentPtr(Fn, "base", base).destroy(comp), | |
| 25 | Id.Type => @fieldParentPtr(MetaType, "base", base).destroy(comp), | |
| 26 | Id.Void => @fieldParentPtr(Void, "base", base).destroy(comp), | |
| 27 | Id.Bool => @fieldParentPtr(Bool, "base", base).destroy(comp), | |
| 28 | Id.NoReturn => @fieldParentPtr(NoReturn, "base", base).destroy(comp), | |
| 29 | Id.Int => @fieldParentPtr(Int, "base", base).destroy(comp), | |
| 30 | Id.Float => @fieldParentPtr(Float, "base", base).destroy(comp), | |
| 31 | Id.Pointer => @fieldParentPtr(Pointer, "base", base).destroy(comp), | |
| 32 | Id.Array => @fieldParentPtr(Array, "base", base).destroy(comp), | |
| 33 | Id.ComptimeFloat => @fieldParentPtr(ComptimeFloat, "base", base).destroy(comp), | |
| 34 | Id.ComptimeInt => @fieldParentPtr(ComptimeInt, "base", base).destroy(comp), | |
| 35 | Id.EnumLiteral => @fieldParentPtr(EnumLiteral, "base", base).destroy(comp), | |
| 36 | Id.Undefined => @fieldParentPtr(Undefined, "base", base).destroy(comp), | |
| 37 | Id.Null => @fieldParentPtr(Null, "base", base).destroy(comp), | |
| 38 | Id.Optional => @fieldParentPtr(Optional, "base", base).destroy(comp), | |
| 39 | Id.ErrorUnion => @fieldParentPtr(ErrorUnion, "base", base).destroy(comp), | |
| 40 | Id.ErrorSet => @fieldParentPtr(ErrorSet, "base", base).destroy(comp), | |
| 41 | Id.Enum => @fieldParentPtr(Enum, "base", base).destroy(comp), | |
| 42 | Id.Union => @fieldParentPtr(Union, "base", base).destroy(comp), | |
| 43 | Id.BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp), | |
| 44 | Id.ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp), | |
| 45 | Id.Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp), | |
| 46 | Id.Frame => @fieldParentPtr(Frame, "base", base).destroy(comp), | |
| 47 | Id.AnyFrame => @fieldParentPtr(AnyFrame, "base", base).destroy(comp), | |
| 48 | Id.Vector => @fieldParentPtr(Vector, "base", base).destroy(comp), | |
| 23 | .Struct => @fieldParentPtr(Struct, "base", base).destroy(comp), | |
| 24 | .Fn => @fieldParentPtr(Fn, "base", base).destroy(comp), | |
| 25 | .Type => @fieldParentPtr(MetaType, "base", base).destroy(comp), | |
| 26 | .Void => @fieldParentPtr(Void, "base", base).destroy(comp), | |
| 27 | .Bool => @fieldParentPtr(Bool, "base", base).destroy(comp), | |
| 28 | .NoReturn => @fieldParentPtr(NoReturn, "base", base).destroy(comp), | |
| 29 | .Int => @fieldParentPtr(Int, "base", base).destroy(comp), | |
| 30 | .Float => @fieldParentPtr(Float, "base", base).destroy(comp), | |
| 31 | .Pointer => @fieldParentPtr(Pointer, "base", base).destroy(comp), | |
| 32 | .Array => @fieldParentPtr(Array, "base", base).destroy(comp), | |
| 33 | .ComptimeFloat => @fieldParentPtr(ComptimeFloat, "base", base).destroy(comp), | |
| 34 | .ComptimeInt => @fieldParentPtr(ComptimeInt, "base", base).destroy(comp), | |
| 35 | .EnumLiteral => @fieldParentPtr(EnumLiteral, "base", base).destroy(comp), | |
| 36 | .Undefined => @fieldParentPtr(Undefined, "base", base).destroy(comp), | |
| 37 | .Null => @fieldParentPtr(Null, "base", base).destroy(comp), | |
| 38 | .Optional => @fieldParentPtr(Optional, "base", base).destroy(comp), | |
| 39 | .ErrorUnion => @fieldParentPtr(ErrorUnion, "base", base).destroy(comp), | |
| 40 | .ErrorSet => @fieldParentPtr(ErrorSet, "base", base).destroy(comp), | |
| 41 | .Enum => @fieldParentPtr(Enum, "base", base).destroy(comp), | |
| 42 | .Union => @fieldParentPtr(Union, "base", base).destroy(comp), | |
| 43 | .BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp), | |
| 44 | .ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp), | |
| 45 | .Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp), | |
| 46 | .Frame => @fieldParentPtr(Frame, "base", base).destroy(comp), | |
| 47 | .AnyFrame => @fieldParentPtr(AnyFrame, "base", base).destroy(comp), | |
| 48 | .Vector => @fieldParentPtr(Vector, "base", base).destroy(comp), | |
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| ... | ... | @@ -55,108 +55,108 @@ pub const Type = struct { |
| 55 | 55 | llvm_context: *llvm.Context, |
| 56 | 56 | ) (error{OutOfMemory}!*llvm.Type) { |
| 57 | 57 | switch (base.id) { |
| 58 | Id.Struct => return @fieldParentPtr(Struct, "base", base).getLlvmType(allocator, llvm_context), | |
| 59 | Id.Fn => return @fieldParentPtr(Fn, "base", base).getLlvmType(allocator, llvm_context), | |
| 60 | Id.Type => unreachable, | |
| 61 | Id.Void => unreachable, | |
| 62 | Id.Bool => return @fieldParentPtr(Bool, "base", base).getLlvmType(allocator, llvm_context), | |
| 63 | Id.NoReturn => unreachable, | |
| 64 | Id.Int => return @fieldParentPtr(Int, "base", base).getLlvmType(allocator, llvm_context), | |
| 65 | Id.Float => return @fieldParentPtr(Float, "base", base).getLlvmType(allocator, llvm_context), | |
| 66 | Id.Pointer => return @fieldParentPtr(Pointer, "base", base).getLlvmType(allocator, llvm_context), | |
| 67 | Id.Array => return @fieldParentPtr(Array, "base", base).getLlvmType(allocator, llvm_context), | |
| 68 | Id.ComptimeFloat => unreachable, | |
| 69 | Id.ComptimeInt => unreachable, | |
| 70 | Id.EnumLiteral => unreachable, | |
| 71 | Id.Undefined => unreachable, | |
| 72 | Id.Null => unreachable, | |
| 73 | Id.Optional => return @fieldParentPtr(Optional, "base", base).getLlvmType(allocator, llvm_context), | |
| 74 | Id.ErrorUnion => return @fieldParentPtr(ErrorUnion, "base", base).getLlvmType(allocator, llvm_context), | |
| 75 | Id.ErrorSet => return @fieldParentPtr(ErrorSet, "base", base).getLlvmType(allocator, llvm_context), | |
| 76 | Id.Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context), | |
| 77 | Id.Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context), | |
| 78 | Id.BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context), | |
| 79 | Id.ArgTuple => unreachable, | |
| 80 | Id.Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context), | |
| 81 | Id.Frame => return @fieldParentPtr(Frame, "base", base).getLlvmType(allocator, llvm_context), | |
| 82 | Id.AnyFrame => return @fieldParentPtr(AnyFrame, "base", base).getLlvmType(allocator, llvm_context), | |
| 83 | Id.Vector => return @fieldParentPtr(Vector, "base", base).getLlvmType(allocator, llvm_context), | |
| 58 | .Struct => return @fieldParentPtr(Struct, "base", base).getLlvmType(allocator, llvm_context), | |
| 59 | .Fn => return @fieldParentPtr(Fn, "base", base).getLlvmType(allocator, llvm_context), | |
| 60 | .Type => unreachable, | |
| 61 | .Void => unreachable, | |
| 62 | .Bool => return @fieldParentPtr(Bool, "base", base).getLlvmType(allocator, llvm_context), | |
| 63 | .NoReturn => unreachable, | |
| 64 | .Int => return @fieldParentPtr(Int, "base", base).getLlvmType(allocator, llvm_context), | |
| 65 | .Float => return @fieldParentPtr(Float, "base", base).getLlvmType(allocator, llvm_context), | |
| 66 | .Pointer => return @fieldParentPtr(Pointer, "base", base).getLlvmType(allocator, llvm_context), | |
| 67 | .Array => return @fieldParentPtr(Array, "base", base).getLlvmType(allocator, llvm_context), | |
| 68 | .ComptimeFloat => unreachable, | |
| 69 | .ComptimeInt => unreachable, | |
| 70 | .EnumLiteral => unreachable, | |
| 71 | .Undefined => unreachable, | |
| 72 | .Null => unreachable, | |
| 73 | .Optional => return @fieldParentPtr(Optional, "base", base).getLlvmType(allocator, llvm_context), | |
| 74 | .ErrorUnion => return @fieldParentPtr(ErrorUnion, "base", base).getLlvmType(allocator, llvm_context), | |
| 75 | .ErrorSet => return @fieldParentPtr(ErrorSet, "base", base).getLlvmType(allocator, llvm_context), | |
| 76 | .Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context), | |
| 77 | .Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context), | |
| 78 | .BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context), | |
| 79 | .ArgTuple => unreachable, | |
| 80 | .Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context), | |
| 81 | .Frame => return @fieldParentPtr(Frame, "base", base).getLlvmType(allocator, llvm_context), | |
| 82 | .AnyFrame => return @fieldParentPtr(AnyFrame, "base", base).getLlvmType(allocator, llvm_context), | |
| 83 | .Vector => return @fieldParentPtr(Vector, "base", base).getLlvmType(allocator, llvm_context), | |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | pub fn handleIsPtr(base: *Type) bool { |
| 88 | 88 | switch (base.id) { |
| 89 | Id.Type, | |
| 90 | Id.ComptimeFloat, | |
| 91 | Id.ComptimeInt, | |
| 92 | Id.EnumLiteral, | |
| 93 | Id.Undefined, | |
| 94 | Id.Null, | |
| 95 | Id.BoundFn, | |
| 96 | Id.ArgTuple, | |
| 97 | Id.Opaque, | |
| 89 | .Type, | |
| 90 | .ComptimeFloat, | |
| 91 | .ComptimeInt, | |
| 92 | .EnumLiteral, | |
| 93 | .Undefined, | |
| 94 | .Null, | |
| 95 | .BoundFn, | |
| 96 | .ArgTuple, | |
| 97 | .Opaque, | |
| 98 | 98 | => unreachable, |
| 99 | 99 | |
| 100 | Id.NoReturn, | |
| 101 | Id.Void, | |
| 102 | Id.Bool, | |
| 103 | Id.Int, | |
| 104 | Id.Float, | |
| 105 | Id.Pointer, | |
| 106 | Id.ErrorSet, | |
| 107 | Id.Enum, | |
| 108 | Id.Fn, | |
| 109 | Id.Frame, | |
| 110 | Id.AnyFrame, | |
| 111 | Id.Vector, | |
| 100 | .NoReturn, | |
| 101 | .Void, | |
| 102 | .Bool, | |
| 103 | .Int, | |
| 104 | .Float, | |
| 105 | .Pointer, | |
| 106 | .ErrorSet, | |
| 107 | .Enum, | |
| 108 | .Fn, | |
| 109 | .Frame, | |
| 110 | .AnyFrame, | |
| 111 | .Vector, | |
| 112 | 112 | => return false, |
| 113 | 113 | |
| 114 | Id.Struct => @panic("TODO"), | |
| 115 | Id.Array => @panic("TODO"), | |
| 116 | Id.Optional => @panic("TODO"), | |
| 117 | Id.ErrorUnion => @panic("TODO"), | |
| 118 | Id.Union => @panic("TODO"), | |
| 114 | .Struct => @panic("TODO"), | |
| 115 | .Array => @panic("TODO"), | |
| 116 | .Optional => @panic("TODO"), | |
| 117 | .ErrorUnion => @panic("TODO"), | |
| 118 | .Union => @panic("TODO"), | |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | pub fn hasBits(base: *Type) bool { |
| 123 | 123 | switch (base.id) { |
| 124 | Id.Type, | |
| 125 | Id.ComptimeFloat, | |
| 126 | Id.ComptimeInt, | |
| 127 | Id.EnumLiteral, | |
| 128 | Id.Undefined, | |
| 129 | Id.Null, | |
| 130 | Id.BoundFn, | |
| 131 | Id.ArgTuple, | |
| 132 | Id.Opaque, | |
| 124 | .Type, | |
| 125 | .ComptimeFloat, | |
| 126 | .ComptimeInt, | |
| 127 | .EnumLiteral, | |
| 128 | .Undefined, | |
| 129 | .Null, | |
| 130 | .BoundFn, | |
| 131 | .ArgTuple, | |
| 132 | .Opaque, | |
| 133 | 133 | => unreachable, |
| 134 | 134 | |
| 135 | Id.Void, | |
| 136 | Id.NoReturn, | |
| 135 | .Void, | |
| 136 | .NoReturn, | |
| 137 | 137 | => return false, |
| 138 | 138 | |
| 139 | Id.Bool, | |
| 140 | Id.Int, | |
| 141 | Id.Float, | |
| 142 | Id.Fn, | |
| 143 | Id.Frame, | |
| 144 | Id.AnyFrame, | |
| 145 | Id.Vector, | |
| 139 | .Bool, | |
| 140 | .Int, | |
| 141 | .Float, | |
| 142 | .Fn, | |
| 143 | .Frame, | |
| 144 | .AnyFrame, | |
| 145 | .Vector, | |
| 146 | 146 | => return true, |
| 147 | 147 | |
| 148 | Id.Pointer => { | |
| 148 | .Pointer => { | |
| 149 | 149 | const ptr_type = @fieldParentPtr(Pointer, "base", base); |
| 150 | 150 | return ptr_type.key.child_type.hasBits(); |
| 151 | 151 | }, |
| 152 | 152 | |
| 153 | Id.ErrorSet => @panic("TODO"), | |
| 154 | Id.Enum => @panic("TODO"), | |
| 155 | Id.Struct => @panic("TODO"), | |
| 156 | Id.Array => @panic("TODO"), | |
| 157 | Id.Optional => @panic("TODO"), | |
| 158 | Id.ErrorUnion => @panic("TODO"), | |
| 159 | Id.Union => @panic("TODO"), | |
| 153 | .ErrorSet => @panic("TODO"), | |
| 154 | .Enum => @panic("TODO"), | |
| 155 | .Struct => @panic("TODO"), | |
| 156 | .Array => @panic("TODO"), | |
| 157 | .Optional => @panic("TODO"), | |
| 158 | .ErrorUnion => @panic("TODO"), | |
| 159 | .Union => @panic("TODO"), | |
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
| ... | ... | @@ -172,7 +172,7 @@ pub const Type = struct { |
| 172 | 172 | fn init(base: *Type, comp: *Compilation, id: Id, name: []const u8) void { |
| 173 | 173 | base.* = Type{ |
| 174 | 174 | .base = Value{ |
| 175 | .id = Value.Id.Type, | |
| 175 | .id = .Type, | |
| 176 | 176 | .typ = &MetaType.get(comp).base, |
| 177 | 177 | .ref_count = std.atomic.Int(usize).init(1), |
| 178 | 178 | }, |
| ... | ... | @@ -272,11 +272,11 @@ pub const Type = struct { |
| 272 | 272 | var result: u32 = 0; |
| 273 | 273 | result +%= hashAny(self.alignment, 0); |
| 274 | 274 | switch (self.data) { |
| 275 | Kind.Generic => |generic| { | |
| 275 | .Generic => |generic| { | |
| 276 | 276 | result +%= hashAny(generic.param_count, 1); |
| 277 | 277 | result +%= hashAny(generic.cc, 3); |
| 278 | 278 | }, |
| 279 | Kind.Normal => |normal| { | |
| 279 | .Normal => |normal| { | |
| 280 | 280 | result +%= hashAny(normal.return_type, 4); |
| 281 | 281 | result +%= hashAny(normal.is_var_args, 5); |
| 282 | 282 | result +%= hashAny(normal.cc, 6); |
| ... | ... | @@ -294,14 +294,14 @@ pub const Type = struct { |
| 294 | 294 | if (self.alignment) |self_align| { |
| 295 | 295 | if (self_align != other.alignment.?) return false; |
| 296 | 296 | } |
| 297 | if (@TagType(Data)(self.data) != @TagType(Data)(other.data)) return false; | |
| 297 | if (self.data != other.data) return false; | |
| 298 | 298 | switch (self.data) { |
| 299 | Kind.Generic => |*self_generic| { | |
| 299 | .Generic => |*self_generic| { | |
| 300 | 300 | const other_generic = &other.data.Generic; |
| 301 | 301 | if (self_generic.param_count != other_generic.param_count) return false; |
| 302 | 302 | if (self_generic.cc != other_generic.cc) return false; |
| 303 | 303 | }, |
| 304 | Kind.Normal => |*self_normal| { | |
| 304 | .Normal => |*self_normal| { | |
| 305 | 305 | const other_normal = &other.data.Normal; |
| 306 | 306 | if (self_normal.cc != other_normal.cc) return false; |
| 307 | 307 | if (self_normal.is_var_args != other_normal.is_var_args) return false; |
| ... | ... | @@ -318,8 +318,8 @@ pub const Type = struct { |
| 318 | 318 | |
| 319 | 319 | pub fn deref(key: Key, comp: *Compilation) void { |
| 320 | 320 | switch (key.data) { |
| 321 | Kind.Generic => {}, | |
| 322 | Kind.Normal => |normal| { | |
| 321 | .Generic => {}, | |
| 322 | .Normal => |normal| { | |
| 323 | 323 | normal.return_type.base.deref(comp); |
| 324 | 324 | for (normal.params) |param| { |
| 325 | 325 | param.typ.base.deref(comp); |
| ... | ... | @@ -330,8 +330,8 @@ pub const Type = struct { |
| 330 | 330 | |
| 331 | 331 | pub fn ref(key: Key) void { |
| 332 | 332 | switch (key.data) { |
| 333 | Kind.Generic => {}, | |
| 334 | Kind.Normal => |normal| { | |
| 333 | .Generic => {}, | |
| 334 | .Normal => |normal| { | |
| 335 | 335 | normal.return_type.base.ref(); |
| 336 | 336 | for (normal.params) |param| { |
| 337 | 337 | param.typ.base.ref(); |
| ... | ... | @@ -361,8 +361,8 @@ pub const Type = struct { |
| 361 | 361 | |
| 362 | 362 | pub fn paramCount(self: *Fn) usize { |
| 363 | 363 | return switch (self.key.data) { |
| 364 | Kind.Generic => |generic| generic.param_count, | |
| 365 | Kind.Normal => |normal| normal.params.len, | |
| 364 | .Generic => |generic| generic.param_count, | |
| 365 | .Normal => |normal| normal.params.len, | |
| 366 | 366 | }; |
| 367 | 367 | } |
| 368 | 368 | |
| ... | ... | @@ -396,7 +396,7 @@ pub const Type = struct { |
| 396 | 396 | const name_stream = &std.io.BufferOutStream.init(&name_buf).stream; |
| 397 | 397 | |
| 398 | 398 | switch (key.data) { |
| 399 | Kind.Generic => |generic| { | |
| 399 | .Generic => |generic| { | |
| 400 | 400 | self.non_key = NonKey{ .Generic = {} }; |
| 401 | 401 | const cc_str = ccFnTypeStr(generic.cc); |
| 402 | 402 | try name_stream.write(cc_str); |
| ... | ... | @@ -412,7 +412,7 @@ pub const Type = struct { |
| 412 | 412 | } |
| 413 | 413 | try name_stream.write(" var"); |
| 414 | 414 | }, |
| 415 | Kind.Normal => |normal| { | |
| 415 | .Normal => |normal| { | |
| 416 | 416 | self.non_key = NonKey{ |
| 417 | 417 | .Normal = NonKey.Normal{ .variable_list = std.ArrayList(*Scope.Var).init(comp.gpa()) }, |
| 418 | 418 | }; |
| ... | ... | @@ -435,7 +435,7 @@ pub const Type = struct { |
| 435 | 435 | }, |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | self.base.init(comp, Id.Fn, name_buf.toOwnedSlice()); | |
| 438 | self.base.init(comp, .Fn, name_buf.toOwnedSlice()); | |
| 439 | 439 | |
| 440 | 440 | { |
| 441 | 441 | const held = comp.fn_type_table.acquire(); |
| ... | ... | @@ -449,8 +449,8 @@ pub const Type = struct { |
| 449 | 449 | pub fn destroy(self: *Fn, comp: *Compilation) void { |
| 450 | 450 | self.key.deref(comp); |
| 451 | 451 | switch (self.key.data) { |
| 452 | Kind.Generic => {}, | |
| 453 | Kind.Normal => { | |
| 452 | .Generic => {}, | |
| 453 | .Normal => { | |
| 454 | 454 | self.non_key.Normal.variable_list.deinit(); |
| 455 | 455 | }, |
| 456 | 456 | } |
| ... | ... | @@ -460,7 +460,7 @@ pub const Type = struct { |
| 460 | 460 | pub fn getLlvmType(self: *Fn, allocator: *Allocator, llvm_context: *llvm.Context) !*llvm.Type { |
| 461 | 461 | const normal = &self.key.data.Normal; |
| 462 | 462 | const llvm_return_type = switch (normal.return_type.id) { |
| 463 | Type.Id.Void => llvm.VoidTypeInContext(llvm_context) orelse return error.OutOfMemory, | |
| 463 | .Void => llvm.VoidTypeInContext(llvm_context) orelse return error.OutOfMemory, | |
| 464 | 464 | else => try normal.return_type.getLlvmType(allocator, llvm_context), |
| 465 | 465 | }; |
| 466 | 466 | const llvm_param_types = try allocator.alloc(*llvm.Type, normal.params.len); |
| ... | ... | @@ -588,7 +588,7 @@ pub const Type = struct { |
| 588 | 588 | const name = try std.fmt.allocPrint(comp.gpa(), "{c}{}", u_or_i, key.bit_count); |
| 589 | 589 | errdefer comp.gpa().free(name); |
| 590 | 590 | |
| 591 | self.base.init(comp, Id.Int, name); | |
| 591 | self.base.init(comp, .Int, name); | |
| 592 | 592 | |
| 593 | 593 | { |
| 594 | 594 | const held = comp.int_type_table.acquire(); |
| ... | ... | @@ -650,8 +650,8 @@ pub const Type = struct { |
| 650 | 650 | pub fn hash(self: *const Key) u32 { |
| 651 | 651 | var result: u32 = 0; |
| 652 | 652 | result +%= switch (self.alignment) { |
| 653 | Align.Abi => 0xf201c090, | |
| 654 | Align.Override => |x| hashAny(x, 0), | |
| 653 | .Abi => 0xf201c090, | |
| 654 | .Override => |x| hashAny(x, 0), | |
| 655 | 655 | }; |
| 656 | 656 | result +%= hashAny(self.child_type, 1); |
| 657 | 657 | result +%= hashAny(self.mut, 2); |
| ... | ... | @@ -670,8 +670,8 @@ pub const Type = struct { |
| 670 | 670 | return false; |
| 671 | 671 | } |
| 672 | 672 | switch (self.alignment) { |
| 673 | Align.Abi => return true, | |
| 674 | Align.Override => |x| return x == other.alignment.Override, | |
| 673 | .Abi => return true, | |
| 674 | .Override => |x| return x == other.alignment.Override, | |
| 675 | 675 | } |
| 676 | 676 | } |
| 677 | 677 | }; |
| ... | ... | @@ -714,8 +714,8 @@ pub const Type = struct { |
| 714 | 714 | |
| 715 | 715 | pub async fn getAlignAsInt(self: *Pointer, comp: *Compilation) u32 { |
| 716 | 716 | switch (self.key.alignment) { |
| 717 | Align.Abi => return self.key.child_type.getAbiAlignment(comp), | |
| 718 | Align.Override => |alignment| return alignment, | |
| 717 | .Abi => return self.key.child_type.getAbiAlignment(comp), | |
| 718 | .Override => |alignment| return alignment, | |
| 719 | 719 | } |
| 720 | 720 | } |
| 721 | 721 | |
| ... | ... | @@ -725,11 +725,11 @@ pub const Type = struct { |
| 725 | 725 | ) !*Pointer { |
| 726 | 726 | var normal_key = key; |
| 727 | 727 | switch (key.alignment) { |
| 728 | Align.Abi => {}, | |
| 729 | Align.Override => |alignment| { | |
| 728 | .Abi => {}, | |
| 729 | .Override => |alignment| { | |
| 730 | 730 | const abi_align = try key.child_type.getAbiAlignment(comp); |
| 731 | 731 | if (abi_align == alignment) { |
| 732 | normal_key.alignment = Align.Abi; | |
| 732 | normal_key.alignment = .Abi; | |
| 733 | 733 | } |
| 734 | 734 | }, |
| 735 | 735 | } |
| ... | ... | @@ -752,21 +752,21 @@ pub const Type = struct { |
| 752 | 752 | errdefer comp.gpa().destroy(self); |
| 753 | 753 | |
| 754 | 754 | const size_str = switch (self.key.size) { |
| 755 | Size.One => "*", | |
| 756 | Size.Many => "[*]", | |
| 757 | Size.Slice => "[]", | |
| 758 | Size.C => "[*c]", | |
| 755 | .One => "*", | |
| 756 | .Many => "[*]", | |
| 757 | .Slice => "[]", | |
| 758 | .C => "[*c]", | |
| 759 | 759 | }; |
| 760 | 760 | const mut_str = switch (self.key.mut) { |
| 761 | Mut.Const => "const ", | |
| 762 | Mut.Mut => "", | |
| 761 | .Const => "const ", | |
| 762 | .Mut => "", | |
| 763 | 763 | }; |
| 764 | 764 | const vol_str = switch (self.key.vol) { |
| 765 | Vol.Volatile => "volatile ", | |
| 766 | Vol.Non => "", | |
| 765 | .Volatile => "volatile ", | |
| 766 | .Non => "", | |
| 767 | 767 | }; |
| 768 | 768 | const name = switch (self.key.alignment) { |
| 769 | Align.Abi => try std.fmt.allocPrint( | |
| 769 | .Abi => try std.fmt.allocPrint( | |
| 770 | 770 | comp.gpa(), |
| 771 | 771 | "{}{}{}{}", |
| 772 | 772 | size_str, |
| ... | ... | @@ -774,7 +774,7 @@ pub const Type = struct { |
| 774 | 774 | vol_str, |
| 775 | 775 | self.key.child_type.name, |
| 776 | 776 | ), |
| 777 | Align.Override => |alignment| try std.fmt.allocPrint( | |
| 777 | .Override => |alignment| try std.fmt.allocPrint( | |
| 778 | 778 | comp.gpa(), |
| 779 | 779 | "{}align<{}> {}{}{}", |
| 780 | 780 | size_str, |
| ... | ... | @@ -786,7 +786,7 @@ pub const Type = struct { |
| 786 | 786 | }; |
| 787 | 787 | errdefer comp.gpa().free(name); |
| 788 | 788 | |
| 789 | self.base.init(comp, Id.Pointer, name); | |
| 789 | self.base.init(comp, .Pointer, name); | |
| 790 | 790 | |
| 791 | 791 | { |
| 792 | 792 | const held = comp.ptr_type_table.acquire(); |
| ... | ... | @@ -854,7 +854,7 @@ pub const Type = struct { |
| 854 | 854 | const name = try std.fmt.allocPrint(comp.gpa(), "[{}]{}", key.len, key.elem_type.name); |
| 855 | 855 | errdefer comp.gpa().free(name); |
| 856 | 856 | |
| 857 | self.base.init(comp, Id.Array, name); | |
| 857 | self.base.init(comp, .Array, name); | |
| 858 | 858 | |
| 859 | 859 | { |
| 860 | 860 | const held = comp.array_type_table.acquire(); |
| ... | ... | @@ -1054,7 +1054,7 @@ pub const Type = struct { |
| 1054 | 1054 | |
| 1055 | 1055 | fn hashAny(x: var, comptime seed: u64) u32 { |
| 1056 | 1056 | switch (@typeInfo(@typeOf(x))) { |
| 1057 | builtin.TypeId.Int => |info| { | |
| 1057 | .Int => |info| { | |
| 1058 | 1058 | comptime var rng = comptime std.rand.DefaultPrng.init(seed); |
| 1059 | 1059 | const unsigned_x = @bitCast(@IntType(false, info.bits), x); |
| 1060 | 1060 | if (info.bits <= 32) { |
| ... | ... | @@ -1063,21 +1063,21 @@ fn hashAny(x: var, comptime seed: u64) u32 { |
| 1063 | 1063 | return @truncate(u32, unsigned_x *% comptime rng.random.scalar(@typeOf(unsigned_x))); |
| 1064 | 1064 | } |
| 1065 | 1065 | }, |
| 1066 | builtin.TypeId.Pointer => |info| { | |
| 1066 | .Pointer => |info| { | |
| 1067 | 1067 | switch (info.size) { |
| 1068 | builtin.TypeInfo.Pointer.Size.One => return hashAny(@ptrToInt(x), seed), | |
| 1069 | builtin.TypeInfo.Pointer.Size.Many => @compileError("implement hash function"), | |
| 1070 | builtin.TypeInfo.Pointer.Size.Slice => @compileError("implement hash function"), | |
| 1071 | builtin.TypeInfo.Pointer.Size.C => unreachable, | |
| 1068 | .One => return hashAny(@ptrToInt(x), seed), | |
| 1069 | .Many => @compileError("implement hash function"), | |
| 1070 | .Slice => @compileError("implement hash function"), | |
| 1071 | .C => unreachable, | |
| 1072 | 1072 | } |
| 1073 | 1073 | }, |
| 1074 | builtin.TypeId.Enum => return hashAny(@enumToInt(x), seed), | |
| 1075 | builtin.TypeId.Bool => { | |
| 1074 | .Enum => return hashAny(@enumToInt(x), seed), | |
| 1075 | .Bool => { | |
| 1076 | 1076 | comptime var rng = comptime std.rand.DefaultPrng.init(seed); |
| 1077 | 1077 | const vals = comptime [2]u32{ rng.random.scalar(u32), rng.random.scalar(u32) }; |
| 1078 | 1078 | return vals[@boolToInt(x)]; |
| 1079 | 1079 | }, |
| 1080 | builtin.TypeId.Optional => { | |
| 1080 | .Optional => { | |
| 1081 | 1081 | if (x) |non_opt| { |
| 1082 | 1082 | return hashAny(non_opt, seed); |
| 1083 | 1083 | } else { |
src-self-hosted/value.zig+46-47| ... | ... | @@ -1,5 +1,4 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); | |
| 3 | 2 | const Scope = @import("scope.zig").Scope; |
| 4 | 3 | const Compilation = @import("compilation.zig").Compilation; |
| 5 | 4 | const ObjectFile = @import("codegen.zig").ObjectFile; |
| ... | ... | @@ -24,15 +23,15 @@ pub const Value = struct { |
| 24 | 23 | if (base.ref_count.decr() == 1) { |
| 25 | 24 | base.typ.base.deref(comp); |
| 26 | 25 | switch (base.id) { |
| 27 | Id.Type => @fieldParentPtr(Type, "base", base).destroy(comp), | |
| 28 | Id.Fn => @fieldParentPtr(Fn, "base", base).destroy(comp), | |
| 29 | Id.FnProto => @fieldParentPtr(FnProto, "base", base).destroy(comp), | |
| 30 | Id.Void => @fieldParentPtr(Void, "base", base).destroy(comp), | |
| 31 | Id.Bool => @fieldParentPtr(Bool, "base", base).destroy(comp), | |
| 32 | Id.NoReturn => @fieldParentPtr(NoReturn, "base", base).destroy(comp), | |
| 33 | Id.Ptr => @fieldParentPtr(Ptr, "base", base).destroy(comp), | |
| 34 | Id.Int => @fieldParentPtr(Int, "base", base).destroy(comp), | |
| 35 | Id.Array => @fieldParentPtr(Array, "base", base).destroy(comp), | |
| 26 | .Type => @fieldParentPtr(Type, "base", base).destroy(comp), | |
| 27 | .Fn => @fieldParentPtr(Fn, "base", base).destroy(comp), | |
| 28 | .FnProto => @fieldParentPtr(FnProto, "base", base).destroy(comp), | |
| 29 | .Void => @fieldParentPtr(Void, "base", base).destroy(comp), | |
| 30 | .Bool => @fieldParentPtr(Bool, "base", base).destroy(comp), | |
| 31 | .NoReturn => @fieldParentPtr(NoReturn, "base", base).destroy(comp), | |
| 32 | .Ptr => @fieldParentPtr(Ptr, "base", base).destroy(comp), | |
| 33 | .Int => @fieldParentPtr(Int, "base", base).destroy(comp), | |
| 34 | .Array => @fieldParentPtr(Array, "base", base).destroy(comp), | |
| 36 | 35 | } |
| 37 | 36 | } |
| 38 | 37 | } |
| ... | ... | @@ -59,15 +58,15 @@ pub const Value = struct { |
| 59 | 58 | |
| 60 | 59 | pub fn getLlvmConst(base: *Value, ofile: *ObjectFile) (error{OutOfMemory}!?*llvm.Value) { |
| 61 | 60 | switch (base.id) { |
| 62 | Id.Type => unreachable, | |
| 63 | Id.Fn => return @fieldParentPtr(Fn, "base", base).getLlvmConst(ofile), | |
| 64 | Id.FnProto => return @fieldParentPtr(FnProto, "base", base).getLlvmConst(ofile), | |
| 65 | Id.Void => return null, | |
| 66 | Id.Bool => return @fieldParentPtr(Bool, "base", base).getLlvmConst(ofile), | |
| 67 | Id.NoReturn => unreachable, | |
| 68 | Id.Ptr => return @fieldParentPtr(Ptr, "base", base).getLlvmConst(ofile), | |
| 69 | Id.Int => return @fieldParentPtr(Int, "base", base).getLlvmConst(ofile), | |
| 70 | Id.Array => return @fieldParentPtr(Array, "base", base).getLlvmConst(ofile), | |
| 61 | .Type => unreachable, | |
| 62 | .Fn => return @fieldParentPtr(Fn, "base", base).getLlvmConst(ofile), | |
| 63 | .FnProto => return @fieldParentPtr(FnProto, "base", base).getLlvmConst(ofile), | |
| 64 | .Void => return null, | |
| 65 | .Bool => return @fieldParentPtr(Bool, "base", base).getLlvmConst(ofile), | |
| 66 | .NoReturn => unreachable, | |
| 67 | .Ptr => return @fieldParentPtr(Ptr, "base", base).getLlvmConst(ofile), | |
| 68 | .Int => return @fieldParentPtr(Int, "base", base).getLlvmConst(ofile), | |
| 69 | .Array => return @fieldParentPtr(Array, "base", base).getLlvmConst(ofile), | |
| 71 | 70 | } |
| 72 | 71 | } |
| 73 | 72 | |
| ... | ... | @@ -83,15 +82,15 @@ pub const Value = struct { |
| 83 | 82 | |
| 84 | 83 | pub fn copy(base: *Value, comp: *Compilation) (error{OutOfMemory}!*Value) { |
| 85 | 84 | switch (base.id) { |
| 86 | Id.Type => unreachable, | |
| 87 | Id.Fn => unreachable, | |
| 88 | Id.FnProto => unreachable, | |
| 89 | Id.Void => unreachable, | |
| 90 | Id.Bool => unreachable, | |
| 91 | Id.NoReturn => unreachable, | |
| 92 | Id.Ptr => unreachable, | |
| 93 | Id.Array => unreachable, | |
| 94 | Id.Int => return &(try @fieldParentPtr(Int, "base", base).copy(comp)).base, | |
| 85 | .Type => unreachable, | |
| 86 | .Fn => unreachable, | |
| 87 | .FnProto => unreachable, | |
| 88 | .Void => unreachable, | |
| 89 | .Bool => unreachable, | |
| 90 | .NoReturn => unreachable, | |
| 91 | .Ptr => unreachable, | |
| 92 | .Array => unreachable, | |
| 93 | .Int => return &(try @fieldParentPtr(Int, "base", base).copy(comp)).base, | |
| 95 | 94 | } |
| 96 | 95 | } |
| 97 | 96 | |
| ... | ... | @@ -138,7 +137,7 @@ pub const Value = struct { |
| 138 | 137 | const self = try comp.gpa().create(FnProto); |
| 139 | 138 | self.* = FnProto{ |
| 140 | 139 | .base = Value{ |
| 141 | .id = Value.Id.FnProto, | |
| 140 | .id = .FnProto, | |
| 142 | 141 | .typ = &fn_type.base, |
| 143 | 142 | .ref_count = std.atomic.Int(usize).init(1), |
| 144 | 143 | }, |
| ... | ... | @@ -202,7 +201,7 @@ pub const Value = struct { |
| 202 | 201 | const self = try comp.gpa().create(Fn); |
| 203 | 202 | self.* = Fn{ |
| 204 | 203 | .base = Value{ |
| 205 | .id = Value.Id.Fn, | |
| 204 | .id = .Fn, | |
| 206 | 205 | .typ = &fn_type.base, |
| 207 | 206 | .ref_count = std.atomic.Int(usize).init(1), |
| 208 | 207 | }, |
| ... | ... | @@ -359,7 +358,7 @@ pub const Value = struct { |
| 359 | 358 | const self = try comp.gpa().create(Value.Ptr); |
| 360 | 359 | self.* = Value.Ptr{ |
| 361 | 360 | .base = Value{ |
| 362 | .id = Value.Id.Ptr, | |
| 361 | .id = .Ptr, | |
| 363 | 362 | .typ = &ptr_type.base, |
| 364 | 363 | .ref_count = std.atomic.Int(usize).init(1), |
| 365 | 364 | }, |
| ... | ... | @@ -385,8 +384,8 @@ pub const Value = struct { |
| 385 | 384 | const llvm_type = self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 386 | 385 | // TODO carefully port the logic from codegen.cpp:gen_const_val_ptr |
| 387 | 386 | switch (self.special) { |
| 388 | Special.Scalar => |scalar| @panic("TODO"), | |
| 389 | Special.BaseArray => |base_array| { | |
| 387 | .Scalar => |scalar| @panic("TODO"), | |
| 388 | .BaseArray => |base_array| { | |
| 390 | 389 | // TODO put this in one .o file only, and after that, generate extern references to it |
| 391 | 390 | const array_llvm_value = (try base_array.val.getLlvmConst(ofile)).?; |
| 392 | 391 | const ptr_bit_count = ofile.comp.target_ptr_bits; |
| ... | ... | @@ -401,9 +400,9 @@ pub const Value = struct { |
| 401 | 400 | @intCast(c_uint, indices.len), |
| 402 | 401 | ) orelse return error.OutOfMemory; |
| 403 | 402 | }, |
| 404 | Special.BaseStruct => |base_struct| @panic("TODO"), | |
| 405 | Special.HardCodedAddr => |addr| @panic("TODO"), | |
| 406 | Special.Discard => unreachable, | |
| 403 | .BaseStruct => |base_struct| @panic("TODO"), | |
| 404 | .HardCodedAddr => |addr| @panic("TODO"), | |
| 405 | .Discard => unreachable, | |
| 407 | 406 | } |
| 408 | 407 | } |
| 409 | 408 | }; |
| ... | ... | @@ -437,7 +436,7 @@ pub const Value = struct { |
| 437 | 436 | const self = try comp.gpa().create(Value.Array); |
| 438 | 437 | self.* = Value.Array{ |
| 439 | 438 | .base = Value{ |
| 440 | .id = Value.Id.Array, | |
| 439 | .id = .Array, | |
| 441 | 440 | .typ = &array_type.base, |
| 442 | 441 | .ref_count = std.atomic.Int(usize).init(1), |
| 443 | 442 | }, |
| ... | ... | @@ -450,22 +449,22 @@ pub const Value = struct { |
| 450 | 449 | |
| 451 | 450 | pub fn destroy(self: *Array, comp: *Compilation) void { |
| 452 | 451 | switch (self.special) { |
| 453 | Special.Undefined => {}, | |
| 454 | Special.OwnedBuffer => |buf| { | |
| 452 | .Undefined => {}, | |
| 453 | .OwnedBuffer => |buf| { | |
| 455 | 454 | comp.gpa().free(buf); |
| 456 | 455 | }, |
| 457 | Special.Explicit => {}, | |
| 456 | .Explicit => {}, | |
| 458 | 457 | } |
| 459 | 458 | comp.gpa().destroy(self); |
| 460 | 459 | } |
| 461 | 460 | |
| 462 | 461 | pub fn getLlvmConst(self: *Array, ofile: *ObjectFile) !?*llvm.Value { |
| 463 | 462 | switch (self.special) { |
| 464 | Special.Undefined => { | |
| 463 | .Undefined => { | |
| 465 | 464 | const llvm_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 466 | 465 | return llvm.GetUndef(llvm_type); |
| 467 | 466 | }, |
| 468 | Special.OwnedBuffer => |buf| { | |
| 467 | .OwnedBuffer => |buf| { | |
| 469 | 468 | const dont_null_terminate = 1; |
| 470 | 469 | const llvm_str_init = llvm.ConstStringInContext( |
| 471 | 470 | ofile.context, |
| ... | ... | @@ -482,7 +481,7 @@ pub const Value = struct { |
| 482 | 481 | llvm.SetAlignment(global, llvm.ABIAlignmentOfType(ofile.comp.target_data_ref, str_init_type)); |
| 483 | 482 | return global; |
| 484 | 483 | }, |
| 485 | Special.Explicit => @panic("TODO"), | |
| 484 | .Explicit => @panic("TODO"), | |
| 486 | 485 | } |
| 487 | 486 | |
| 488 | 487 | //{ |
| ... | ... | @@ -517,7 +516,7 @@ pub const Value = struct { |
| 517 | 516 | const self = try comp.gpa().create(Value.Int); |
| 518 | 517 | self.* = Value.Int{ |
| 519 | 518 | .base = Value{ |
| 520 | .id = Value.Id.Int, | |
| 519 | .id = .Int, | |
| 521 | 520 | .typ = typ, |
| 522 | 521 | .ref_count = std.atomic.Int(usize).init(1), |
| 523 | 522 | }, |
| ... | ... | @@ -536,7 +535,7 @@ pub const Value = struct { |
| 536 | 535 | |
| 537 | 536 | pub fn getLlvmConst(self: *Int, ofile: *ObjectFile) !?*llvm.Value { |
| 538 | 537 | switch (self.base.typ.id) { |
| 539 | Type.Id.Int => { | |
| 538 | .Int => { | |
| 540 | 539 | const type_ref = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 541 | 540 | if (self.big_int.len() == 0) { |
| 542 | 541 | return llvm.ConstNull(type_ref); |
| ... | ... | @@ -554,7 +553,7 @@ pub const Value = struct { |
| 554 | 553 | }; |
| 555 | 554 | return if (self.big_int.isPositive()) unsigned_val else llvm.ConstNeg(unsigned_val); |
| 556 | 555 | }, |
| 557 | Type.Id.ComptimeInt => unreachable, | |
| 556 | .ComptimeInt => unreachable, | |
| 558 | 557 | else => unreachable, |
| 559 | 558 | } |
| 560 | 559 | } |
| ... | ... | @@ -566,7 +565,7 @@ pub const Value = struct { |
| 566 | 565 | const new = try comp.gpa().create(Value.Int); |
| 567 | 566 | new.* = Value.Int{ |
| 568 | 567 | .base = Value{ |
| 569 | .id = Value.Id.Int, | |
| 568 | .id = .Int, | |
| 570 | 569 | .typ = old.base.typ, |
| 571 | 570 | .ref_count = std.atomic.Int(usize).init(1), |
| 572 | 571 | }, |