DoxigAlpha

callMain

Functions in this namespace

Functions

#

= switch (builtin.zig_backend) { .stage2_aarch64, .stage2_arm, .stage2_powerpc, .stage2_sparc64, .stage2_spirv, .stage2_x86, => true, else => false, }

Values

#
simplified_logic
= switch (builtin.zig_backend) { .stage2_aarch64, .stage2_arm, .stage2_powerpc, .stage2_sparc64, .stage2_spirv, .stage2_x86, => true, else => false, }

Source

Implementation

#
pub inline fn callMain() u8 {
    const ReturnType = @typeInfo(@TypeOf(root.main)).@"fn".return_type.?;

    switch (ReturnType) {
        void => {
            root.main();
            return 0;
        },
        noreturn, u8 => {
            return root.main();
        },
        else => {
            if (@typeInfo(ReturnType) != .error_union) @compileError(bad_main_ret);

            const result = root.main() catch |err| {
                switch (builtin.zig_backend) {
                    .stage2_powerpc,
                    .stage2_riscv64,
                    => {
                        _ = std.posix.write(std.posix.STDERR_FILENO, "error: failed with error\n") catch {};
                        return 1;
                    },
                    else => {},
                }
                std.log.err("{s}", .{@errorName(err)});
                if (@errorReturnTrace()) |trace| {
                    std.debug.dumpStackTrace(trace.*);
                }
                return 1;
            };

            return switch (@TypeOf(result)) {
                void => 0,
                u8 => result,
                else => @compileError(bad_main_ret),
            };
        },
    }
}