libk  type.h.m at [e794c5edef]

File kcore/type.h.m artifact 8b1f2e0cb2 part of check-in e794c5edef


--- kcore/type.h.m → <k/def.h>
--- ~ lexi hale <lexi@hale.su>
--- this file gathers information on the environment it's
--- being compiled in, defining types that our code
--- needs. it will be emitted as <k/type.h>.
--- vim: ft=c

// arch bit length [atom_target_bits]
--- make some gigantic fucking assumptions
[if [atom_target_bits] >= 8]
    typedef unsigned char  u8;
    typedef signed char    s8;
    [if [atom_target_bits] >= 16]
        typedef unsigned short u16;
        typedef signed short   s16;
        [if [atom_target_bits] >= 32]
            typedef unsigned long  u32;
            typedef signed long    s32;
            [if [atom_target_bits] >= 64]
                typedef unsigned long long u64;
                typedef signed long long s64;
                [if [atom_target_arch] == x86]
                    #if defined(__GNUC__) || defined(__clang__)
                        typedef __uint128_t u128;
                        typedef __int128_t  s128;
                    #endif
                [endif]
            [endif]
        [endif]
    [endif]
[endif]

typedef u[atom_target_bits]  sz;
typedef s[atom_target_bits] ssz;

--- make sure something unlikely doesn't happen
[define [maxtype name, n]:
	[if [n] > [atom_target_bits]]
		typedef u[atom_target_bits] [name]
	[else]
		typedef u[n] [name]
	[endif]]

// exit status integer types - pls use kbad in <k/magic.h> instead
[if [target_posix] == yes]
	/* by convention, posix return values are 8-bit,
	 * but note that many modern UNIXes do technically
	 * support higher-bit values. for this reason,
	 * longstat is defined differently under posix. */
	typedef u8 stat;
	[maxtype longstat, 32];
[else]
	[if ([atom_target_os] == win) ||
		([atom_target_os] == vms)]
		[maxtype stat, 32]
	[else]
		typedef u8 stat;
		/* we don't know a specific exit status type
		 * for your arch so we're going with a sane
		 * default. if this is wrong, help us fix it! */
	[endif]
	typedef stat longstat;
[endif]