| author | |
| committer | |
| log | 38791ac616069963fd808ec724161b93cbc564c1 |
| tree | 1f4c254a76a3c5d016574c1e124a392973383964 |
| parent | fd7c7be33c95fd1bd77010378b407fc9fb4933e2 |
| parent | 521744bb91b486bfab7d9a6bd74dd658da95ea18 |
| signature | Commit is signed but in an unrecognized format. |
closes #3810
closes #3793
closes #379810 files changed, 87 insertions(+), 124 deletions(-)
lib/std/builtin.zig+17-1| ... | @@ -26,7 +26,8 @@ pub const subsystem: ?SubSystem = blk: { | ... | @@ -26,7 +26,8 @@ pub const subsystem: ?SubSystem = blk: { |
| 26 | if (is_test) { | 26 | if (is_test) { |
| 27 | break :blk SubSystem.Console; | 27 | break :blk SubSystem.Console; |
| 28 | } | 28 | } |
| 29 | if (@hasDecl(root, "WinMain") or | 29 | if (@hasDecl(root, "main") or |
| 30 | @hasDecl(root, "WinMain") or | ||
| 30 | @hasDecl(root, "wWinMain") or | 31 | @hasDecl(root, "wWinMain") or |
| 31 | @hasDecl(root, "WinMainCRTStartup") or | 32 | @hasDecl(root, "WinMainCRTStartup") or |
| 32 | @hasDecl(root, "wWinMainCRTStartup")) | 33 | @hasDecl(root, "wWinMainCRTStartup")) |
| ... | @@ -348,6 +349,21 @@ pub const Endian = enum { | ... | @@ -348,6 +349,21 @@ pub const Endian = enum { |
| 348 | Little, | 349 | Little, |
| 349 | }; | 350 | }; |
| 350 | 351 | ||
| 352 | /// This data structure is used by the Zig language code generation and | ||
| 353 | /// therefore must be kept in sync with the compiler implementation. | ||
| 354 | pub const OutputMode = enum { | ||
| 355 | Exe, | ||
| 356 | Lib, | ||
| 357 | Obj, | ||
| 358 | }; | ||
| 359 | |||
| 360 | /// This data structure is used by the Zig language code generation and | ||
| 361 | /// therefore must be kept in sync with the compiler implementation. | ||
| 362 | pub const LinkMode = enum { | ||
| 363 | Static, | ||
| 364 | Dynamic, | ||
| 365 | }; | ||
| 366 | |||
| 351 | /// This data structure is used by the Zig language code generation and | 367 | /// This data structure is used by the Zig language code generation and |
| 352 | /// therefore must be kept in sync with the compiler implementation. | 368 | /// therefore must be kept in sync with the compiler implementation. |
| 353 | pub const Version = struct { | 369 | pub const Version = struct { |
lib/std/special/start.zig+35-13| ... | @@ -19,21 +19,43 @@ const is_mips = switch (builtin.arch) { | ... | @@ -19,21 +19,43 @@ const is_mips = switch (builtin.arch) { |
| 19 | }; | 19 | }; |
| 20 | 20 | ||
| 21 | comptime { | 21 | comptime { |
| 22 | if (builtin.link_libc) { | 22 | if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { |
| 23 | @export("main", main, .Strong); | 23 | if (builtin.os == .windows and !@hasDecl(root, "_DllMainCRTStartup")) { |
| 24 | } else if (builtin.os == .windows) { | 24 | @export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong); |
| 25 | @export("WinMainCRTStartup", WinMainCRTStartup, .Strong); | 25 | } |
| 26 | } else if (is_wasm and builtin.os == .freestanding) { | 26 | } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) { |
| 27 | @export("_start", wasm_freestanding_start, .Strong); | 27 | if (builtin.link_libc and @hasDecl(root, "main")) { |
| 28 | } else if (builtin.os == .uefi) { | 28 | if (@typeInfo(@typeOf(root.main)).Fn.calling_convention != .C) { |
| 29 | @export("EfiMain", EfiMain, .Strong); | 29 | @export("main", main, .Weak); |
| 30 | } else if (is_mips) { | 30 | } |
| 31 | if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong); | 31 | } else if (builtin.os == .windows) { |
| 32 | } else { | 32 | if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) { |
| 33 | if (!@hasDecl(root, "_start")) @export("_start", _start, .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 | } | ||
| 34 | } | 44 | } |
| 35 | } | 45 | } |
| 36 | 46 | ||
| 47 | stdcallcc fn _DllMainCRTStartup( | ||
| 48 | hinstDLL: std.os.windows.HINSTANCE, | ||
| 49 | fdwReason: std.os.windows.DWORD, | ||
| 50 | lpReserved: std.os.windows.LPVOID, | ||
| 51 | ) std.os.windows.BOOL { | ||
| 52 | if (@hasDecl(root, "DllMain")) { | ||
| 53 | return root.DllMain(hinstDLL, fdwReason, lpReserved); | ||
| 54 | } | ||
| 55 | |||
| 56 | return std.os.windows.TRUE; | ||
| 57 | } | ||
| 58 | |||
| 37 | extern fn wasm_freestanding_start() void { | 59 | extern fn wasm_freestanding_start() void { |
| 38 | // This is marked inline because for some reason LLVM in release mode fails to inline it, | 60 | // This is marked inline because for some reason LLVM in release mode fails to inline it, |
| 39 | // and we want fewer call frames in stack traces. | 61 | // and we want fewer call frames in stack traces. |
| ... | @@ -106,7 +128,7 @@ nakedcc fn _start() noreturn { | ... | @@ -106,7 +128,7 @@ nakedcc fn _start() noreturn { |
| 106 | @noInlineCall(posixCallMainAndExit); | 128 | @noInlineCall(posixCallMainAndExit); |
| 107 | } | 129 | } |
| 108 | 130 | ||
| 109 | extern fn WinMainCRTStartup() noreturn { | 131 | stdcallcc fn WinMainCRTStartup() noreturn { |
| 110 | @setAlignStack(16); | 132 | @setAlignStack(16); |
| 111 | if (!builtin.single_threaded) { | 133 | if (!builtin.single_threaded) { |
| 112 | _ = @import("start_windows_tls.zig"); | 134 | _ = @import("start_windows_tls.zig"); |
lib/std/special/start_lib.zig deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | // This file is included in the compilation unit when exporting a DLL on windows. | ||
| 2 | |||
| 3 | const root = @import("root"); | ||
| 4 | const std = @import("std"); | ||
| 5 | const builtin = @import("builtin"); | ||
| 6 | |||
| 7 | comptime { | ||
| 8 | @export("_DllMainCRTStartup", _DllMainCRTStartup, builtin.GlobalLinkage.Strong); | ||
| 9 | } | ||
| 10 | |||
| 11 | stdcallcc fn _DllMainCRTStartup( | ||
| 12 | hinstDLL: std.os.windows.HINSTANCE, | ||
| 13 | fdwReason: std.os.windows.DWORD, | ||
| 14 | lpReserved: std.os.windows.LPVOID, | ||
| 15 | ) std.os.windows.BOOL { | ||
| 16 | if (@hasDecl(root, "DllMain")) { | ||
| 17 | return root.DllMain(hinstDLL, fdwReason, lpReserved); | ||
| 18 | } | ||
| 19 | |||
| 20 | return std.os.windows.TRUE; | ||
| 21 | } | ||
src/all_types.hpp-2| ... | @@ -2061,7 +2061,6 @@ struct CodeGen { | ... | @@ -2061,7 +2061,6 @@ struct CodeGen { |
| 2061 | ZigList<TldVar *> global_vars; | 2061 | ZigList<TldVar *> global_vars; |
| 2062 | 2062 | ||
| 2063 | ZigFn *cur_fn; | 2063 | ZigFn *cur_fn; |
| 2064 | ZigFn *main_fn; | ||
| 2065 | ZigFn *panic_fn; | 2064 | ZigFn *panic_fn; |
| 2066 | 2065 | ||
| 2067 | ZigFn *largest_frame_fn; | 2066 | ZigFn *largest_frame_fn; |
| ... | @@ -2081,7 +2080,6 @@ struct CodeGen { | ... | @@ -2081,7 +2080,6 @@ struct CodeGen { |
| 2081 | uint32_t target_abi_index; | 2080 | uint32_t target_abi_index; |
| 2082 | uint32_t target_oformat_index; | 2081 | uint32_t target_oformat_index; |
| 2083 | bool is_big_endian; | 2082 | bool is_big_endian; |
| 2084 | bool have_pub_main; | ||
| 2085 | bool have_c_main; | 2083 | bool have_c_main; |
| 2086 | bool have_winmain; | 2084 | bool have_winmain; |
| 2087 | bool have_winmain_crt_startup; | 2085 | bool have_winmain_crt_startup; |
src/analyze.cpp-38| ... | @@ -3304,17 +3304,6 @@ ZigFn *create_fn(CodeGen *g, AstNode *proto_node) { | ... | @@ -3304,17 +3304,6 @@ ZigFn *create_fn(CodeGen *g, AstNode *proto_node) { |
| 3304 | return fn_entry; | 3304 | return fn_entry; |
| 3305 | } | 3305 | } |
| 3306 | 3306 | ||
| 3307 | static bool scope_is_root_decls(Scope *scope) { | ||
| 3308 | while (scope) { | ||
| 3309 | if (scope->id == ScopeIdDecls) { | ||
| 3310 | ScopeDecls *scope_decls = (ScopeDecls *)scope; | ||
| 3311 | return is_top_level_struct(scope_decls->container_type); | ||
| 3312 | } | ||
| 3313 | scope = scope->parent; | ||
| 3314 | } | ||
| 3315 | zig_unreachable(); | ||
| 3316 | } | ||
| 3317 | |||
| 3318 | ZigType *get_test_fn_type(CodeGen *g) { | 3307 | ZigType *get_test_fn_type(CodeGen *g) { |
| 3319 | if (g->test_fn_type) | 3308 | if (g->test_fn_type) |
| 3320 | return g->test_fn_type; | 3309 | return g->test_fn_type; |
| ... | @@ -3353,7 +3342,6 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, G | ... | @@ -3353,7 +3342,6 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, G |
| 3353 | } | 3342 | } |
| 3354 | 3343 | ||
| 3355 | static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { | 3344 | static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3356 | ZigType *import = tld_fn->base.import; | ||
| 3357 | AstNode *source_node = tld_fn->base.source_node; | 3345 | AstNode *source_node = tld_fn->base.source_node; |
| 3358 | if (source_node->type == NodeTypeFnProto) { | 3346 | if (source_node->type == NodeTypeFnProto) { |
| 3359 | AstNodeFnProto *fn_proto = &source_node->data.fn_proto; | 3347 | AstNodeFnProto *fn_proto = &source_node->data.fn_proto; |
| ... | @@ -3433,12 +3421,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { | ... | @@ -3433,12 +3421,6 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { |
| 3433 | if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) { | 3421 | if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) { |
| 3434 | fn_table_entry->inferred_async_node = fn_table_entry->proto_node; | 3422 | fn_table_entry->inferred_async_node = fn_table_entry->proto_node; |
| 3435 | } | 3423 | } |
| 3436 | |||
| 3437 | if (scope_is_root_decls(tld_fn->base.parent_scope) && import == g->root_import) { | ||
| 3438 | if (g->have_pub_main && buf_eql_str(tld_fn->base.name, "main")) { | ||
| 3439 | g->main_fn = fn_table_entry; | ||
| 3440 | } | ||
| 3441 | } | ||
| 3442 | } else if (source_node->type == NodeTypeTestDecl) { | 3424 | } else if (source_node->type == NodeTypeTestDecl) { |
| 3443 | ZigFn *fn_table_entry = create_fn_raw(g, FnInlineAuto); | 3425 | ZigFn *fn_table_entry = create_fn_raw(g, FnInlineAuto); |
| 3444 | 3426 | ||
| ... | @@ -4813,26 +4795,6 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu | ... | @@ -4813,26 +4795,6 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu |
| 4813 | ast_print(stderr, root_node, 0); | 4795 | ast_print(stderr, root_node, 0); |
| 4814 | } | 4796 | } |
| 4815 | 4797 | ||
| 4816 | if (source_kind == SourceKindRoot) { | ||
| 4817 | // Look for main | ||
| 4818 | for (size_t decl_i = 0; decl_i < root_node->data.container_decl.decls.length; decl_i += 1) { | ||
| 4819 | AstNode *top_level_decl = root_node->data.container_decl.decls.at(decl_i); | ||
| 4820 | |||
| 4821 | if (top_level_decl->type == NodeTypeFnDef) { | ||
| 4822 | AstNode *proto_node = top_level_decl->data.fn_def.fn_proto; | ||
| 4823 | assert(proto_node->type == NodeTypeFnProto); | ||
| 4824 | Buf *proto_name = proto_node->data.fn_proto.name; | ||
| 4825 | |||
| 4826 | bool is_pub = (proto_node->data.fn_proto.visib_mod == VisibModPub); | ||
| 4827 | if (is_pub) { | ||
| 4828 | if (buf_eql_str(proto_name, "main")) { | ||
| 4829 | g->have_pub_main = true; | ||
| 4830 | } | ||
| 4831 | } | ||
| 4832 | } | ||
| 4833 | } | ||
| 4834 | } | ||
| 4835 | |||
| 4836 | for (size_t decl_i = 0; decl_i < root_node->data.container_decl.decls.length; decl_i += 1) { | 4798 | for (size_t decl_i = 0; decl_i < root_node->data.container_decl.decls.length; decl_i += 1) { |
| 4837 | AstNode *top_level_decl = root_node->data.container_decl.decls.at(decl_i); | 4799 | AstNode *top_level_decl = root_node->data.container_decl.decls.at(decl_i); |
| 4838 | scan_decls(g, import_entry->data.structure.decls_scope, top_level_decl); | 4800 | scan_decls(g, import_entry->data.structure.decls_scope, top_level_decl); |
src/codegen.cpp+21-42| ... | @@ -8229,9 +8229,9 @@ TargetSubsystem detect_subsystem(CodeGen *g) { | ... | @@ -8229,9 +8229,9 @@ TargetSubsystem detect_subsystem(CodeGen *g) { |
| 8229 | if (g->zig_target->os == OsWindows) { | 8229 | if (g->zig_target->os == OsWindows) { |
| 8230 | if (g->have_dllmain_crt_startup || (g->out_type == OutTypeLib && g->is_dynamic)) | 8230 | if (g->have_dllmain_crt_startup || (g->out_type == OutTypeLib && g->is_dynamic)) |
| 8231 | return TargetSubsystemAuto; | 8231 | return TargetSubsystemAuto; |
| 8232 | if (g->have_c_main || g->have_pub_main || g->is_test_build) | 8232 | if (g->have_c_main || g->is_test_build || g->have_winmain_crt_startup) |
| 8233 | return TargetSubsystemConsole; | 8233 | return TargetSubsystemConsole; |
| 8234 | if (g->have_winmain || g->have_winmain_crt_startup) | 8234 | if (g->have_winmain) |
| 8235 | return TargetSubsystemWindows; | 8235 | return TargetSubsystemWindows; |
| 8236 | } else if (g->zig_target->os == OsUefi) { | 8236 | } else if (g->zig_target->os == OsUefi) { |
| 8237 | return TargetSubsystemEfiApplication; | 8237 | return TargetSubsystemEfiApplication; |
| ... | @@ -8375,6 +8375,22 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { | ... | @@ -8375,6 +8375,22 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { |
| 8375 | const char *endian_str = g->is_big_endian ? "Endian.Big" : "Endian.Little"; | 8375 | const char *endian_str = g->is_big_endian ? "Endian.Big" : "Endian.Little"; |
| 8376 | buf_appendf(contents, "pub const endian = %s;\n", endian_str); | 8376 | buf_appendf(contents, "pub const endian = %s;\n", endian_str); |
| 8377 | } | 8377 | } |
| 8378 | const char *out_type = nullptr; | ||
| 8379 | switch (g->out_type) { | ||
| 8380 | case OutTypeExe: | ||
| 8381 | out_type = "Exe"; | ||
| 8382 | break; | ||
| 8383 | case OutTypeLib: | ||
| 8384 | out_type = "Lib"; | ||
| 8385 | break; | ||
| 8386 | case OutTypeObj: | ||
| 8387 | case OutTypeUnknown: // This happens when running the `zig builtin` command. | ||
| 8388 | out_type = "Obj"; | ||
| 8389 | break; | ||
| 8390 | } | ||
| 8391 | buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type); | ||
| 8392 | const char *link_type = g->is_dynamic ? "Dynamic" : "Static"; | ||
| 8393 | buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type); | ||
| 8378 | buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build)); | 8394 | buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build)); |
| 8379 | buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded)); | 8395 | buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded)); |
| 8380 | buf_appendf(contents, "pub const os = Os.%s;\n", cur_os); | 8396 | buf_appendf(contents, "pub const os = Os.%s;\n", cur_os); |
| ... | @@ -8441,6 +8457,8 @@ static Error define_builtin_compile_vars(CodeGen *g) { | ... | @@ -8441,6 +8457,8 @@ static Error define_builtin_compile_vars(CodeGen *g) { |
| 8441 | cache_buf(&cache_hash, compiler_id); | 8457 | cache_buf(&cache_hash, compiler_id); |
| 8442 | cache_int(&cache_hash, g->build_mode); | 8458 | cache_int(&cache_hash, g->build_mode); |
| 8443 | cache_bool(&cache_hash, g->strip_debug_symbols); | 8459 | cache_bool(&cache_hash, g->strip_debug_symbols); |
| 8460 | cache_int(&cache_hash, g->out_type); | ||
| 8461 | cache_bool(&cache_hash, g->is_dynamic); | ||
| 8444 | cache_bool(&cache_hash, g->is_test_build); | 8462 | cache_bool(&cache_hash, g->is_test_build); |
| 8445 | cache_bool(&cache_hash, g->is_single_threaded); | 8463 | cache_bool(&cache_hash, g->is_single_threaded); |
| 8446 | cache_int(&cache_hash, g->zig_target->is_native); | 8464 | cache_int(&cache_hash, g->zig_target->is_native); |
| ... | @@ -9148,38 +9166,6 @@ static Buf *get_resolved_root_src_path(CodeGen *g) { | ... | @@ -9148,38 +9166,6 @@ static Buf *get_resolved_root_src_path(CodeGen *g) { |
| 9148 | return resolved_path; | 9166 | return resolved_path; |
| 9149 | } | 9167 | } |
| 9150 | 9168 | ||
| 9151 | static bool want_startup_code(CodeGen *g) { | ||
| 9152 | // Test builds get handled separately. | ||
| 9153 | if (g->is_test_build) | ||
| 9154 | return false; | ||
| 9155 | |||
| 9156 | // WASM freestanding can still have an entry point but other freestanding targets do not. | ||
| 9157 | if (g->zig_target->os == OsFreestanding && !target_is_wasm(g->zig_target)) | ||
| 9158 | return false; | ||
| 9159 | |||
| 9160 | // Declaring certain export functions means skipping the start code | ||
| 9161 | if (g->have_c_main || g->have_winmain || g->have_winmain_crt_startup) | ||
| 9162 | return false; | ||
| 9163 | |||
| 9164 | // If there is a pub main in the root source file, that means we need start code. | ||
| 9165 | if (g->have_pub_main) { | ||
| 9166 | return true; | ||
| 9167 | } else { | ||
| 9168 | if (g->zig_target->os == OsUefi) | ||
| 9169 | return false; | ||
| 9170 | } | ||
| 9171 | |||
| 9172 | if (g->out_type == OutTypeExe) { | ||
| 9173 | // For build-exe, we might add start code even though there is no pub main, so that the | ||
| 9174 | // programmer gets the "no pub main" compile error. However if linking libc and there is | ||
| 9175 | // a C source file, that might have main(). | ||
| 9176 | return g->c_source_files.length == 0 || g->libc_link_lib == nullptr; | ||
| 9177 | } | ||
| 9178 | |||
| 9179 | // For objects and libraries, and we don't have pub main, no start code. | ||
| 9180 | return false; | ||
| 9181 | } | ||
| 9182 | |||
| 9183 | static void gen_root_source(CodeGen *g) { | 9169 | static void gen_root_source(CodeGen *g) { |
| 9184 | Buf *resolved_path = get_resolved_root_src_path(g); | 9170 | Buf *resolved_path = get_resolved_root_src_path(g); |
| 9185 | if (resolved_path == nullptr) | 9171 | if (resolved_path == nullptr) |
| ... | @@ -9241,21 +9227,14 @@ static void gen_root_source(CodeGen *g) { | ... | @@ -9241,21 +9227,14 @@ static void gen_root_source(CodeGen *g) { |
| 9241 | assert(g->panic_fn != nullptr); | 9227 | assert(g->panic_fn != nullptr); |
| 9242 | } | 9228 | } |
| 9243 | 9229 | ||
| 9244 | |||
| 9245 | if (!g->error_during_imports) { | 9230 | if (!g->error_during_imports) { |
| 9246 | semantic_analyze(g); | 9231 | semantic_analyze(g); |
| 9247 | } | 9232 | } |
| 9248 | report_errors_and_maybe_exit(g); | 9233 | report_errors_and_maybe_exit(g); |
| 9249 | 9234 | ||
| 9250 | if (want_startup_code(g)) { | 9235 | if (!g->is_test_build) { |
| 9251 | g->start_import = add_special_code(g, create_start_pkg(g, g->root_package), "start.zig"); | 9236 | g->start_import = add_special_code(g, create_start_pkg(g, g->root_package), "start.zig"); |
| 9252 | } | 9237 | } |
| 9253 | if (g->zig_target->os == OsWindows && !g->have_dllmain_crt_startup && | ||
| 9254 | g->out_type == OutTypeLib && g->is_dynamic) | ||
| 9255 | { | ||
| 9256 | g->start_import = add_special_code(g, create_start_pkg(g, g->root_package), "start_lib.zig"); | ||
| 9257 | } | ||
| 9258 | |||
| 9259 | if (!g->error_during_imports) { | 9238 | if (!g->error_during_imports) { |
| 9260 | semantic_analyze(g); | 9239 | semantic_analyze(g); |
| 9261 | } | 9240 | } |
test/compare_output.zig+4-4| ... | @@ -6,7 +6,7 @@ const tests = @import("tests.zig"); | ... | @@ -6,7 +6,7 @@ const tests = @import("tests.zig"); |
| 6 | pub fn addCases(cases: *tests.CompareOutputContext) void { | 6 | pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 7 | cases.addC("hello world with libc", | 7 | cases.addC("hello world with libc", |
| 8 | \\const c = @cImport(@cInclude("stdio.h")); | 8 | \\const c = @cImport(@cInclude("stdio.h")); |
| 9 | \\export fn main(argc: c_int, argv: [*][*]u8) c_int { | 9 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { |
| 10 | \\ _ = c.puts("Hello, world!"); | 10 | \\ _ = c.puts("Hello, world!"); |
| 11 | \\ return 0; | 11 | \\ return 0; |
| 12 | \\} | 12 | \\} |
| ... | @@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -139,7 +139,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 139 | \\ @cInclude("stdio.h"); | 139 | \\ @cInclude("stdio.h"); |
| 140 | \\}); | 140 | \\}); |
| 141 | \\ | 141 | \\ |
| 142 | \\export fn main(argc: c_int, argv: [*][*]u8) c_int { | 142 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { |
| 143 | \\ if (is_windows) { | 143 | \\ if (is_windows) { |
| 144 | \\ // we want actual \n, not \r\n | 144 | \\ // we want actual \n, not \r\n |
| 145 | \\ _ = c._setmode(1, c._O_BINARY); | 145 | \\ _ = c._setmode(1, c._O_BINARY); |
| ... | @@ -286,7 +286,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -286,7 +286,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 286 | \\ } | 286 | \\ } |
| 287 | \\} | 287 | \\} |
| 288 | \\ | 288 | \\ |
| 289 | \\export fn main() c_int { | 289 | \\pub export fn main() c_int { |
| 290 | \\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; | 290 | \\ var array = [_]u32{ 1, 7, 3, 2, 0, 9, 4, 8, 6, 5 }; |
| 291 | \\ | 291 | \\ |
| 292 | \\ c.qsort(@ptrCast(?*c_void, array[0..].ptr), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn); | 292 | \\ c.qsort(@ptrCast(?*c_void, array[0..].ptr), @intCast(c_ulong, array.len), @sizeOf(i32), compare_fn); |
| ... | @@ -314,7 +314,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { | ... | @@ -314,7 +314,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { |
| 314 | \\ @cInclude("stdio.h"); | 314 | \\ @cInclude("stdio.h"); |
| 315 | \\}); | 315 | \\}); |
| 316 | \\ | 316 | \\ |
| 317 | \\export fn main(argc: c_int, argv: [*][*]u8) c_int { | 317 | \\pub export fn main(argc: c_int, argv: [*][*]u8) c_int { |
| 318 | \\ if (is_windows) { | 318 | \\ if (is_windows) { |
| 319 | \\ // we want actual \n, not \r\n | 319 | \\ // we want actual \n, not \r\n |
| 320 | \\ _ = c._setmode(1, c._O_BINARY); | 320 | \\ _ = c._setmode(1, c._O_BINARY); |
test/compile_errors.zig+7| ... | @@ -6,6 +6,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { | ... | @@ -6,6 +6,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6 | \\export async fn foo() void {} | 6 | \\export async fn foo() void {} |
| 7 | , "tmp.zig:1:1: error: exported function cannot be async"); | 7 | , "tmp.zig:1:1: error: exported function cannot be async"); |
| 8 | 8 | ||
| 9 | cases.addExe( | ||
| 10 | "main missing name", | ||
| 11 | \\pub fn (main) void {} | ||
| 12 | , | ||
| 13 | "tmp.zig:1:5: error: missing function name", | ||
| 14 | ); | ||
| 15 | |||
| 9 | cases.addCase(x: { | 16 | cases.addCase(x: { |
| 10 | var tc = cases.create("@newStackCall on unsupported target", | 17 | var tc = cases.create("@newStackCall on unsupported target", |
| 11 | \\export fn entry() void { | 18 | \\export fn entry() void { |
test/stage2/compare_output.zig+2-2| ... | @@ -5,7 +5,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -5,7 +5,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 5 | // hello world | 5 | // hello world |
| 6 | try ctx.testCompareOutputLibC( | 6 | try ctx.testCompareOutputLibC( |
| 7 | \\extern fn puts([*]const u8) void; | 7 | \\extern fn puts([*]const u8) void; |
| 8 | \\export fn main() c_int { | 8 | \\pub export fn main() c_int { |
| 9 | \\ puts("Hello, world!"); | 9 | \\ puts("Hello, world!"); |
| 10 | \\ return 0; | 10 | \\ return 0; |
| 11 | \\} | 11 | \\} |
| ... | @@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void { | ... | @@ -14,7 +14,7 @@ pub fn addCases(ctx: *TestContext) !void { |
| 14 | // function calling another function | 14 | // function calling another function |
| 15 | try ctx.testCompareOutputLibC( | 15 | try ctx.testCompareOutputLibC( |
| 16 | \\extern fn puts(s: [*]const u8) void; | 16 | \\extern fn puts(s: [*]const u8) void; |
| 17 | \\export fn main() c_int { | 17 | \\pub export fn main() c_int { |
| 18 | \\ return foo("OK"); | 18 | \\ return foo("OK"); |
| 19 | \\} | 19 | \\} |
| 20 | \\fn foo(s: [*]const u8) c_int { | 20 | \\fn foo(s: [*]const u8) c_int { |
test/standalone/hello_world/hello_libc.zig+1-1| ... | @@ -7,7 +7,7 @@ const c = @cImport({ | ... | @@ -7,7 +7,7 @@ const c = @cImport({ |
| 7 | 7 | ||
| 8 | const msg = "Hello, world!\n"; | 8 | const msg = "Hello, world!\n"; |
| 9 | 9 | ||
| 10 | export fn main(argc: c_int, argv: **u8) c_int { | 10 | pub export fn main(argc: c_int, argv: **u8) c_int { |
| 11 | if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1; | 11 | if (c.printf(msg) != @intCast(c_int, c.strlen(msg))) return -1; |
| 12 | return 0; | 12 | return 0; |
| 13 | } | 13 | } |