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