Differences From
Artifact [def2d33e25]:
1 ---- kcore/type.h.m → <k/type.h>
2 ---- ~ lexi hale <lexi@hale.su>
3 ---- this file gathers information on the environment it's
4 ---- being compiled in, defining types that our code
5 ---- needs. it will be emitted as <k/type.h>.
6 ---- vim: ft=c
1 +dnl kcore/type.h.m → <k/type.h>
2 +dnl ~ lexi hale <lexi@hale.su>
3 +dnl this file gathers information on the environment it's
4 +dnl being compiled in, defining types that our code
5 +dnl needs. it will be emitted as <k/type.h>.
6 +dnl vim: ft=c
7 +changequote(`“',`”')
7 8 #ifndef KItype
8 9 #define KItype
9 10
10 11 /* we define 64-bit types first due to an oddity in how
11 12 * 128-bit types are handled: we want kc_?big to reference
12 13 * the absolute largest type available to the compiler,
13 14 * but in some cases, 128-bits may not be among the
................................................................................
18 19 * that supports the 128-bit extension - but only if a
19 20 * native 128-bit type is not available.
20 21 *
21 22 * once this is done, we can be certain that u128 will
22 23 * reference the largest available integer type and can
23 24 * safely define kc_?big by reference to it. */
24 25
25 -[ifdef type_bit64]
26 - typedef unsigned [type_bit64] u64;
27 - typedef signed [type_bit64] s64;
28 - [ifndef type_bit128]
26 +
27 +ifdef(“type_bit64”,“
28 + typedef unsigned type_bit64 u64;
29 + typedef signed type_bit64 s64;
30 + ifdef(“type_bit128”,,“
29 31 /* even if no native type is 128 bits long, clang and
30 32 * gcc have extensions to support 128 bit arithmetic
31 33 * on 64-bit hardware */
32 34 # if defined(__GNUC__) || defined(__clang__)
33 - typedef unsigned __int128_t u128;
34 - typedef signed __int128_t s128;
35 + typedef __uint128_t u128;
36 + typedef __int128_t s128;
35 37 # else
36 - /* if we don't have access to that extension
38 + /* if we don`'t have access to that extension
37 39 * or native 128-bit types, then we just use
38 40 * the largest native type specified in the
39 41 * C standard */
40 42 typedef unsigned long long u128;
41 43 typedef signed long long s128;
42 44 # endif
43 - [endif]
44 -[else]
45 + ”)”,“dnl
45 46 typedef unsigned long long u64;
46 47 typedef signed long long s64;
47 48
48 49 typedef u64 u128;
49 50 typedef s64 s128;
50 -[endif]
51 +”)dnl
51 52
52 -[ifdef type_bit128]
53 - typedef unsigned [type_bit128] u128;
54 - typedef signed [type_bit128] s128;
55 -[endif]
53 +ifdef(“type_bit128”,“dnl
54 + typedef unsigned type_bit128 u128;
55 + typedef signed type_bit128 s128;
56 +”)dnl
56 57
57 58 typedef unsigned char ubyte;
58 59 typedef signed char sbyte;
59 60 typedef u128 ubig;
60 61 typedef s128 sbig;
61 62
62 -[ifdef type_bit8]
63 - typedef unsigned [type_bit8] u8;
64 - typedef signed [type_bit8] s8;
65 -[else]
63 +ifdef(“type_bit8”,“dnl
64 + typedef unsigned type_bit8 u8;
65 + typedef signed type_bit8 s8;
66 +”,“dnl
66 67 typedef ubyte u8;
67 68 typedef sbyte s8;
68 -[endif]
69 +”)dnl
69 70
70 -[ifdef type_bit16]
71 - typedef unsigned [type_bit16] u16;
72 - typedef signed [type_bit16] s16;
73 -[else]
71 +ifdef(“type_bit16”,“
72 + typedef unsigned type_bit16 u16;
73 + typedef signed type_bit16 s16;
74 +”,“
74 75 typedef ubig u16;
75 76 typedef sbig s16;
76 -[endif]
77 +”)dnl
77 78
78 -[ifdef type_bit32]
79 - typedef unsigned [type_bit32] u32;
80 - typedef signed [type_bit32] s32;
81 -[else]
79 +ifdef(“type_bit32”,“
80 + typedef unsigned type_bit32 u32;
81 + typedef signed type_bit32 s32;
82 +”,“
82 83 typedef ubig u32;
83 84 typedef sbig s32;
84 -[endif]
85 +”)dnl
85 86
86 87 enum /* max-min values of each type */ {
87 - byte_bits = [byte_bits],
88 + byte_bits = arch_byte_bits,
88 89
89 90 u8_min = 0, u8_max = ((u8)-1),
90 91 u16_min = 0, u16_max = ((u16)-1),
91 92 u32_min = 0, u32_max = ((u32)-1),
92 - u64_min = 0, u32_max = ((u64)-1),
93 + u64_min = 0, u64_max = ((u64)-1),
93 94 u128_min = 0, u128_max = ((u128)-1),
94 95
95 96 /* assuming two's complement. TODO: check math */
96 - [define merge: $1$2]
97 - [define [sspec type]:
98 - [merge [type],_min] = 0 - ((1 << sizeof([type]) * kc_byte_bits) / 2),
99 - [merge [type],_max] = (1 << sizeof([type]) * kc_byte_bits) / 2 - 1]
97 + define(“sspec”,“
98 + $1_min = 0 - ((1 << sizeof($1) * byte_bits) / 2),
99 + $1_max = (1 << sizeof($1) * byte_bits) / 2 - 1”)dnl
100 100
101 - [sspec s8], [sspec s16], [sspec s32],
102 - [sspec s64], [sspec s128],
101 + sspec(s8), sspec(s16), sspec(s32),
102 + sspec(s64), sspec(s128),
103 103
104 - kc_uchar_min = 0, kc_uchar_max = [type_max_u_char],
105 - kc_ushort_min = 0, kc_ushort_max = [type_max_u_short],
106 - kc_uint_min = 0, kc_uint_max = [type_max_u_int],
107 - kc_ulong_min = 0, kc_ulong_max = [type_max_u_long],
108 - kc_ullong_min = 0, kc_ullong_max = [type_max_u_llong],
104 + kc_uchar_min = 0, kc_uchar_max = type_max_u_char,
105 + kc_ushort_min = 0, kc_ushort_max = type_max_u_short,
106 + kc_uint_min = 0, kc_uint_max = type_max_u_int,
107 + kc_ulong_min = 0, kc_ulong_max = type_max_u_long,
108 + kc_ullong_min = 0, kc_ullong_max = type_max_u_llong,
109 109
110 - kc_schar_min = [type_min_s_char], kc_schar_max = [type_max_s_char],
111 - kc_sshort_min = [type_min_s_short], kc_sshort_max = [type_max_s_short],
112 - kc_sint_min = [type_min_s_int], kc_sint_max = [type_max_s_int],
113 - kc_slong_min = [type_min_s_long], kc_slong_max = [type_max_s_long],
114 - kc_sllong_min = [type_min_s_llong], kc_sllong_max = [type_max_s_llong],
110 + kc_schar_min = type_min_s_char, kc_schar_max = type_max_s_char,
111 + kc_sshort_min = type_min_s_short, kc_sshort_max = type_max_s_short,
112 + kc_sint_min = type_min_s_int, kc_sint_max = type_max_s_int,
113 + kc_slong_min = type_min_s_long, kc_slong_max = type_max_s_long,
114 + kc_sllong_min = type_min_s_llong, kc_sllong_max = type_max_s_llong,
115 115
116 116 ubig_min = u128_min, ubig_max = u128_max,
117 117 sbig_min = s128_min, sbig_max = s128_max,
118 118
119 119 ubyte_min = kc_uchar_min, ubyte_max = kc_uchar_max,
120 120 sbyte_min = kc_schar_min, sbyte_max = kc_schar_max,
121 121 };
122 122
123 -[ifdef type_sz]
124 - typedef [type_sz] sz;
125 -[else]
123 +ifdef(“type_sz”,“
124 + typedef type_sz sz;
125 +”,“dnl
126 126 # ifdef __cplusplus
127 127 /* C++ gives us a clean, standardized way to do this */
128 128 typedef decltype (sizeof(char)) sz;
129 129 # else
130 130 # if defined(__GNUC__) || defined(__clang__)
131 131 typedef __typeof__ (sizeof(char)) sz;
132 132 # else
................................................................................
133 133 /* we're stumped - set sz to the safest possible value under
134 134 * the circumstances, and warn the user. */
135 135 # warning no authoritative sz (size_t) type definition \
136 136 available; defaulting to largest unsigned integer type
137 137 typedef ubig sz;
138 138 # endif
139 139 # endif
140 -[endif]
140 +”)dnl
141 141
142 -[ifdef type_offset]
143 - typedef [type_offset] offset;
144 -[else]
142 +ifdef(“type_offset”,“
143 + typedef type_offset offset;
144 +”,“dnl
145 145 # ifdef __cplusplus
146 146 /* C++ gives us a clean, standardized way to do this */
147 147 typedef decltype (((void*)-1) - 1) offset;
148 148 # else
149 149 # if defined(__GNUC__) || defined(__clang__)
150 150 typedef __typeof__ (((void*)10) - ((void*)5)) offset;
151 151 # else
................................................................................
152 152 /* no dice - set offset to the safest possible value under
153 153 * the circumstances, and warn the user. */
154 154 # warning no authoritative offset (ptrdiff_t) type definition \
155 155 available; defaulting to largest unsigned integer type
156 156 typedef sbig offset;
157 157 # endif
158 158 # endif
159 -[endif]
159 +”)dnl
160 160
161 161 // exit status integer types - pls use kbad in <k/magic.h> instead
162 -[if [target_posix] == yes]
162 +ifelse(target_posix,“yes”,“
163 163 /* by convention, posix return values are 8-bit,
164 164 * but note that many modern UNIXes do technically
165 165 * support higher-bit values. for this reason,
166 166 * longstat is defined differently under posix. */
167 167 typedef u8 stat;
168 168 typedef u32 stat_long;
169 -[else]
170 - [if ([atom_target_os] == win) ||
171 - ([atom_target_os] == vms)]
169 +”,“dnl
170 + ifelse(atom_target_os,“win”,“
171 + typedef u32 stat;
172 + ”,“dnl
173 + ifelse(atom_target_os,“vms”,“
172 174 typedef u32 stat;
173 - [else]
175 + ”,“dnl
174 176 typedef u8 stat;
175 177 /* we don't know a specific exit status type
176 178 * for your arch so we're going with a sane
177 179 * default. if this is wrong, help us fix it! */
178 - [endif]
180 + ”)”)dnl
179 181 typedef stat stat_long;
180 -[endif]
182 +”)dnl
181 183
182 184 #endif