authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-03 12:29:55-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-03 12:50:42-05:00
log6a046c1bcda1d02d4f9a05ea125ef56b50cf6e7c
tree7a92c39cf94ac84b9a9ff8a48b91a214f1ca806f
parentffd21c586dbed40b991c5578b2b2ba7d12c72a8e
signature Commit is signed but in an unrecognized format.

activate start code when pub main exists

and rename LinkType->LinkMode, OutType->OutputMode

4 files changed, 34 insertions(+), 45 deletions(-)

lib/std/builtin.zig+2-3
...@@ -350,8 +350,7 @@ pub const Endian = enum {...@@ -350,8 +350,7 @@ pub const Endian = enum {
350350
351/// This data structure is used by the Zig language code generation and351/// This data structure is used by the Zig language code generation and
352/// therefore must be kept in sync with the compiler implementation.352/// therefore must be kept in sync with the compiler implementation.
353pub const OutType = enum {353pub const OutputMode = enum {
354 Unknown,
355 Exe,354 Exe,
356 Lib,355 Lib,
357 Obj,356 Obj,
...@@ -359,7 +358,7 @@ pub const OutType = enum {...@@ -359,7 +358,7 @@ pub const OutType = enum {
359358
360/// This data structure is used by the Zig language code generation and359/// This data structure is used by the Zig language code generation and
361/// therefore must be kept in sync with the compiler implementation.360/// therefore must be kept in sync with the compiler implementation.
362pub const LinkType = enum {361pub const LinkMode = enum {
363 Static,362 Static,
364 Dynamic,363 Dynamic,
365};364};
lib/std/special/start.zig+21-30
...@@ -19,37 +19,28 @@ const is_mips = switch (builtin.arch) {...@@ -19,37 +19,28 @@ const is_mips = switch (builtin.arch) {
19};19};
2020
21comptime {21comptime {
22 switch (builtin.output_type) {22 if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
23 .Unknown => unreachable,23 if (builtin.os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) {
24 .Exe => {24 @export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong);
25 if (builtin.link_libc) {25 }
26 if (@hasDecl(root, "main") and26 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
27 @typeInfo(@typeOf(root.main)).Fn.calling_convention != .C)27 if (builtin.link_libc and @hasDecl(root, "main") and
28 {28 @typeInfo(@typeOf(root.main)).Fn.calling_convention != .C)
29 @export("main", main, .Weak);29 {
30 }30 @export("main", main, .Weak);
31 } else if (builtin.os == .windows) {31 } else if (builtin.os == .windows) {
32 if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {32 if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) {
33 @export("WinMainCRTStartup", WinMainCRTStartup, .Strong);33 @export("WinMainCRTStartup", WinMainCRTStartup, .Strong);
34 }
35 } else if (is_wasm and builtin.os == .freestanding) {
36 if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong);
37 } else if (builtin.os == .uefi) {
38 if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
39 } else if (is_mips) {
40 if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong);
41 } else {
42 if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong);
43 }
44 },
45 .Lib => {
46 if (builtin.os == .windows and builtin.link_type == .Dynamic and
47 !@hasDecl(root, "_DllMainCRTStartup"))
48 {
49 @export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong);
50 }34 }
51 },35 } else if (is_wasm and builtin.os == .freestanding) {
52 .Obj => {},36 if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong);
37 } else if (builtin.os == .uefi) {
38 if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong);
39 } else if (is_mips) {
40 if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong);
41 } else {
42 if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong);
43 }
53 }44 }
54}45}
5546
src/codegen.cpp+3-4
...@@ -8378,8 +8378,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8378,8 +8378,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8378 const char *out_type = nullptr;8378 const char *out_type = nullptr;
8379 switch (g->out_type) {8379 switch (g->out_type) {
8380 case OutTypeUnknown:8380 case OutTypeUnknown:
8381 out_type = "Unknown";8381 zig_unreachable();
8382 break;
8383 case OutTypeExe:8382 case OutTypeExe:
8384 out_type = "Exe";8383 out_type = "Exe";
8385 break;8384 break;
...@@ -8390,9 +8389,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8390,9 +8389,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8390 out_type = "Obj";8389 out_type = "Obj";
8391 break;8390 break;
8392 }8391 }
8393 buf_appendf(contents, "pub const output_type = OutType.%s;\n", out_type);8392 buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type);
8394 const char *link_type = g->is_dynamic ? "Dynamic" : "Static"; 8393 const char *link_type = g->is_dynamic ? "Dynamic" : "Static";
8395 buf_appendf(contents, "pub const link_type = LinkType.%s;\n", link_type);8394 buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type);
8396 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));8395 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));
8397 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));8396 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
8398 buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);8397 buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);
test/compile_errors.zig+8-8
...@@ -156,7 +156,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -156,7 +156,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
156 "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",156 "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
157 );157 );
158158
159 cases.addExe(159 cases.add(
160 "disallow coercion from non-null-terminated pointer to null-terminated pointer",160 "disallow coercion from non-null-terminated pointer to null-terminated pointer",
161 \\extern fn puts(s: [*:0]const u8) c_int;161 \\extern fn puts(s: [*:0]const u8) c_int;
162 \\pub fn main() void {162 \\pub fn main() void {
...@@ -876,7 +876,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -876,7 +876,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
876 "tmp.zig:3:32: note: cast discards const qualifier",876 "tmp.zig:3:32: note: cast discards const qualifier",
877 );877 );
878878
879 cases.addExe(879 cases.add(
880 "overflow in enum value allocation",880 "overflow in enum value allocation",
881 \\const Moo = enum(u8) {881 \\const Moo = enum(u8) {
882 \\ Last = 255,882 \\ Last = 255,
...@@ -3000,14 +3000,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3000,14 +3000,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3000 "tmp.zig:3:9: error: encountered @panic at compile-time",3000 "tmp.zig:3:9: error: encountered @panic at compile-time",
3001 );3001 );
30023002
3003 cases.addExe(3003 cases.add(
3004 "wrong return type for main",3004 "wrong return type for main",
3005 \\pub fn main() f32 { }3005 \\pub fn main() f32 { }
3006 ,3006 ,
3007 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",3007 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
3008 );3008 );
30093009
3010 cases.addExe(3010 cases.add(
3011 "double ?? on main return value",3011 "double ?? on main return value",
3012 \\pub fn main() ??void {3012 \\pub fn main() ??void {
3013 \\}3013 \\}
...@@ -4900,7 +4900,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4900,7 +4900,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4900 "tmp.zig:3:13: error: cannot assign to constant",4900 "tmp.zig:3:13: error: cannot assign to constant",
4901 );4901 );
49024902
4903 cases.addExe(4903 cases.add(
4904 "main function with bogus args type",4904 "main function with bogus args type",
4905 \\pub fn main(args: [][]bogus) !void {}4905 \\pub fn main(args: [][]bogus) !void {}
4906 ,4906 ,
...@@ -5718,7 +5718,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5718,7 +5718,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5718 "tmp.zig:4:13: error: cannot continue out of defer expression",5718 "tmp.zig:4:13: error: cannot continue out of defer expression",
5719 );5719 );
57205720
5721 cases.addExe(5721 cases.add(
5722 "calling a var args function only known at runtime",5722 "calling a var args function only known at runtime",
5723 \\var foos = [_]fn(...) void { foo1, foo2 };5723 \\var foos = [_]fn(...) void { foo1, foo2 };
5724 \\5724 \\
...@@ -5732,7 +5732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5732,7 +5732,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5732 "tmp.zig:7:9: error: calling a generic function requires compile-time known function value",5732 "tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
5733 );5733 );
57345734
5735 cases.addExe(5735 cases.add(
5736 "calling a generic function only known at runtime",5736 "calling a generic function only known at runtime",
5737 \\var foos = [_]fn(var) void { foo1, foo2 };5737 \\var foos = [_]fn(var) void { foo1, foo2 };
5738 \\5738 \\
...@@ -6850,7 +6850,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6850,7 +6850,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6850 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",6850 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",
6851 );6851 );
68526852
6853 cases.addExe("compileLog of tagged enum doesn't crash the compiler",6853 cases.add("compileLog of tagged enum doesn't crash the compiler",
6854 \\const Bar = union(enum(u32)) {6854 \\const Bar = union(enum(u32)) {
6855 \\ X: i32 = 16855 \\ X: i32 = 1
6856 \\};6856 \\};