mirror of
https://github.com/ziglang/zig.git
synced 2025-02-12 23:50:18 +00:00
parent
98b633ff17
commit
047d6d996e
209
lib/zig.h
209
lib/zig.h
@ -25,11 +25,15 @@ typedef char bool;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define zig_concat(lhs, rhs) lhs##rhs
|
||||
#define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs)
|
||||
|
||||
#if defined(__has_builtin)
|
||||
#define zig_has_builtin(builtin) __has_builtin(__builtin_##builtin)
|
||||
#else
|
||||
#define zig_has_builtin(builtin) 0
|
||||
#endif
|
||||
#define zig_expand_has_builtin(b) zig_has_builtin(b)
|
||||
|
||||
#if defined(__has_attribute)
|
||||
#define zig_has_attribute(attribute) __has_attribute(attribute)
|
||||
@ -180,49 +184,51 @@ typedef char bool;
|
||||
#define zig_extern extern
|
||||
#endif
|
||||
|
||||
#if _MSC_VER
|
||||
#define zig_extern_mangled zig_extern
|
||||
#else
|
||||
#if zig_has_attribute(visibility)
|
||||
#define zig_extern_mangled zig_extern __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define zig_extern_mangled zig_extern
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if _MSC_VER
|
||||
#if _M_X64
|
||||
#define zig_export(sig, symbol, name) zig_extern sig;\
|
||||
__pragma(comment(linker, "/alternatename:" name "=" #symbol ))
|
||||
#define zig_mangle_c(symbol) symbol
|
||||
#else /*_M_X64 */
|
||||
#define zig_export(sig, symbol, name) zig_extern sig;\
|
||||
__pragma(comment(linker, "/alternatename:" name "=" #symbol ))
|
||||
#define zig_mangle_c(symbol) "_" symbol
|
||||
#endif /*_M_X64 */
|
||||
#else /* _MSC_VER */
|
||||
#if __APPLE__
|
||||
#define zig_export(sig, symbol, name) zig_extern sig;\
|
||||
__asm("_" name " = _" #symbol)
|
||||
#define zig_mangle_c(symbol) "_" symbol
|
||||
#else /* __APPLE__ */
|
||||
#define zig_export(sig, symbol, name) zig_extern sig;\
|
||||
__asm(name " = " #symbol)
|
||||
#define zig_mangle_c(symbol) symbol
|
||||
#endif /* __APPLE__ */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#if zig_has_attribute(alias) && !__APPLE__
|
||||
#define zig_export(symbol, name) __attribute__((alias(symbol)))
|
||||
#elif _MSC_VER
|
||||
#define zig_export(symbol, name) ; \
|
||||
__pragma(comment(linker, "/alternatename:" zig_mangle_c(name) "=" zig_mangle_c(symbol)))
|
||||
#else
|
||||
#define zig_export(symbol, name) ; \
|
||||
__asm(zig_mangle_c(name) " = " zig_mangle_c(symbol))
|
||||
#endif
|
||||
|
||||
#if _MSC_VER
|
||||
#define zig_mangled_tentative(mangled, unmangled)
|
||||
#define zig_mangled_final(mangled, unmangled) ; \
|
||||
zig_export(#mangled, unmangled)
|
||||
#define zig_mangled_export(mangled, unmangled, symbol) \
|
||||
zig_export(unmangled, #mangled) \
|
||||
zig_export(symbol, unmangled)
|
||||
#else /* _MSC_VER */
|
||||
#define zig_mangled_tentative(mangled, unmangled) __asm(zig_mangle_c(unmangled))
|
||||
#define zig_mangled_final(mangled, unmangled) zig_mangled_tentative(mangled, unmangled)
|
||||
#define zig_mangled_export(mangled, unmangled, symbol) \
|
||||
zig_mangled_final(mangled, unmangled) \
|
||||
zig_export(symbol, unmangled)
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#if _MSC_VER
|
||||
#if _M_X64
|
||||
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\
|
||||
__pragma(comment(linker, "/alternatename:" #fn_name "=" #libc_name ));
|
||||
#else /*_M_X64 */
|
||||
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args;\
|
||||
__pragma(comment(linker, "/alternatename:_" #fn_name "=_" #libc_name ));
|
||||
#endif /*_M_X64 */
|
||||
__pragma(comment(linker, "/alternatename:" zig_mangle_c(#fn_name) "=" zig_mangle_c(#libc_name)));
|
||||
#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_import(Type, fn_name, sig_args, call_args)
|
||||
#else /* _MSC_VER */
|
||||
#if __APPLE__
|
||||
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm("_" #libc_name);
|
||||
#else /* __APPLE__ */
|
||||
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(#libc_name);
|
||||
#endif /* __APPLE__ */
|
||||
#define zig_import(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type fn_name sig_args __asm(zig_mangle_c(#libc_name));
|
||||
#define zig_import_builtin(Type, fn_name, libc_name, sig_args, call_args) zig_extern Type libc_name sig_args; \
|
||||
static inline Type fn_name sig_args { return libc_name call_args; }
|
||||
#endif
|
||||
@ -303,9 +309,6 @@ typedef char bool;
|
||||
#define zig_wasm_memory_grow(index, delta) zig_unimplemented()
|
||||
#endif
|
||||
|
||||
#define zig_concat(lhs, rhs) lhs##rhs
|
||||
#define zig_expand_concat(lhs, rhs) zig_concat(lhs, rhs)
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L
|
||||
#define zig_noreturn _Noreturn
|
||||
#elif zig_has_attribute(noreturn) || defined(zig_gnuc)
|
||||
@ -2199,7 +2202,7 @@ static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
const uint8_t *rhs_bytes = rhs;
|
||||
uint16_t byte_offset = 0;
|
||||
uint16_t remaining_bytes = zig_int_bytes(bits);
|
||||
uint16_t top_bits = remaining_bytes * 8 - bits;
|
||||
uint8_t top_bits = (uint8_t)(remaining_bytes * 8 - bits);
|
||||
bool overflow = false;
|
||||
|
||||
#if zig_big_endian
|
||||
@ -2207,7 +2210,7 @@ static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
#endif
|
||||
|
||||
while (remaining_bytes >= 128 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 128 / CHAR_BIT;
|
||||
@ -2247,7 +2250,7 @@ static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 64 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 64 / CHAR_BIT;
|
||||
@ -2287,7 +2290,7 @@ static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 32 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 32 / CHAR_BIT;
|
||||
@ -2327,7 +2330,7 @@ static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 16 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 16 / CHAR_BIT;
|
||||
@ -2367,7 +2370,7 @@ static inline bool zig_addo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 8 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 8 / CHAR_BIT;
|
||||
@ -2415,7 +2418,7 @@ static inline bool zig_subo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
const uint8_t *rhs_bytes = rhs;
|
||||
uint16_t byte_offset = 0;
|
||||
uint16_t remaining_bytes = zig_int_bytes(bits);
|
||||
uint16_t top_bits = remaining_bytes * 8 - bits;
|
||||
uint8_t top_bits = (uint8_t)(remaining_bytes * 8 - bits);
|
||||
bool overflow = false;
|
||||
|
||||
#if zig_big_endian
|
||||
@ -2423,7 +2426,7 @@ static inline bool zig_subo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
#endif
|
||||
|
||||
while (remaining_bytes >= 128 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 128 - (remaining_bytes == 128 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 128 / CHAR_BIT;
|
||||
@ -2463,7 +2466,7 @@ static inline bool zig_subo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 64 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 64 - (remaining_bytes == 64 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 64 / CHAR_BIT;
|
||||
@ -2503,7 +2506,7 @@ static inline bool zig_subo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 32 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 32 - (remaining_bytes == 32 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 32 / CHAR_BIT;
|
||||
@ -2543,7 +2546,7 @@ static inline bool zig_subo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 16 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 16 - (remaining_bytes == 16 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 16 / CHAR_BIT;
|
||||
@ -2583,7 +2586,7 @@ static inline bool zig_subo_big(void *res, const void *lhs, const void *rhs, boo
|
||||
}
|
||||
|
||||
while (remaining_bytes >= 8 / CHAR_BIT) {
|
||||
uint16_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0);
|
||||
uint8_t limb_bits = 8 - (remaining_bytes == 8 / CHAR_BIT ? top_bits : 0);
|
||||
|
||||
#if zig_big_endian
|
||||
byte_offset -= 8 / CHAR_BIT;
|
||||
@ -3355,7 +3358,6 @@ zig_float_negate_builtin(128, zig_make_u128, (UINT64_C(1) << 63, UINT64_C(0)))
|
||||
return lhs operator rhs; \
|
||||
}
|
||||
|
||||
#define zig_expand_has_builtin(b) zig_has_builtin(b)
|
||||
#define zig_common_float_builtins(w) \
|
||||
zig_convert_builtin( int64_t, int64_t, fix, zig_f##w, zig_f##w, ) \
|
||||
zig_convert_builtin(zig_i128, zig_i128, fix, zig_f##w, zig_f##w, ) \
|
||||
@ -3475,129 +3477,134 @@ zig_float_builtins(64)
|
||||
/* Note that zig_atomicrmw_expected is needed to handle aliasing between res and arg. */
|
||||
#define zig_atomicrmw_xchg_float(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, memory_order_relaxed, Type, ReprType)); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_add_float(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_add_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_sub_float(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_sub_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_min_float(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_float_fn_##Type##_fmin(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_max_float(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_float_fn_##Type##_fmax(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
|
||||
#define zig_atomicrmw_xchg_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, memory_order_relaxed, Type, ReprType)); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, arg, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_add_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_add_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_sub_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_sub_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_and_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_and_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_nand_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_not_##Type(zig_and_##Type(zig_atomicrmw_expected, arg), 128); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_or_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_or_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_xor_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_xor_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_min_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_min_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
#define zig_atomicrmw_max_int128(res, obj, arg, order, Type, ReprType) do { \
|
||||
zig_##Type zig_atomicrmw_expected; \
|
||||
zig_##Type zig_atomicrmw_desired; \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, memory_order_relaxed, Type, ReprType); \
|
||||
zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \
|
||||
do { \
|
||||
zig_atomicrmw_desired = zig_max_##Type(zig_atomicrmw_expected, arg); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, memory_order_relaxed, Type, ReprType)); \
|
||||
} while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \
|
||||
res = zig_atomicrmw_expected; \
|
||||
} while (0)
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
|
||||
#include <stdatomic.h>
|
||||
typedef enum memory_order zig_memory_order;
|
||||
#define zig_memory_order_relaxed memory_order_relaxed
|
||||
#define zig_memory_order_acquire memory_order_acquire
|
||||
#define zig_memory_order_release memory_order_release
|
||||
#define zig_memory_order_acq_rel memory_order_acq_rel
|
||||
#define zig_memory_order_seq_cst memory_order_seq_cst
|
||||
#define zig_atomic(Type) _Atomic(Type)
|
||||
#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail)
|
||||
#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) atomic_compare_exchange_weak_explicit (obj, &(expected), desired, succ, fail)
|
||||
@ -3621,12 +3628,11 @@ typedef enum memory_order zig_memory_order;
|
||||
#define zig_fence(order) atomic_thread_fence(order)
|
||||
#elif defined(__GNUC__)
|
||||
typedef int zig_memory_order;
|
||||
#define memory_order_relaxed __ATOMIC_RELAXED
|
||||
#define memory_order_consume __ATOMIC_CONSUME
|
||||
#define memory_order_acquire __ATOMIC_ACQUIRE
|
||||
#define memory_order_release __ATOMIC_RELEASE
|
||||
#define memory_order_acq_rel __ATOMIC_ACQ_REL
|
||||
#define memory_order_seq_cst __ATOMIC_SEQ_CST
|
||||
#define zig_memory_order_relaxed __ATOMIC_RELAXED
|
||||
#define zig_memory_order_acquire __ATOMIC_ACQUIRE
|
||||
#define zig_memory_order_release __ATOMIC_RELEASE
|
||||
#define zig_memory_order_acq_rel __ATOMIC_ACQ_REL
|
||||
#define zig_memory_order_seq_cst __ATOMIC_SEQ_CST
|
||||
#define zig_atomic(Type) Type
|
||||
#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), false, succ, fail)
|
||||
#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), true, succ, fail)
|
||||
@ -3645,12 +3651,11 @@ typedef int zig_memory_order;
|
||||
#define zig_atomicrmw_xchg_float zig_atomicrmw_xchg
|
||||
#define zig_fence(order) __atomic_thread_fence(order)
|
||||
#elif _MSC_VER && (_M_IX86 || _M_X64)
|
||||
#define memory_order_relaxed 0
|
||||
#define memory_order_consume 1
|
||||
#define memory_order_acquire 2
|
||||
#define memory_order_release 3
|
||||
#define memory_order_acq_rel 4
|
||||
#define memory_order_seq_cst 5
|
||||
#define zig_memory_order_relaxed 0
|
||||
#define zig_memory_order_acquire 2
|
||||
#define zig_memory_order_release 3
|
||||
#define zig_memory_order_acq_rel 4
|
||||
#define zig_memory_order_seq_cst 5
|
||||
#define zig_atomic(Type) Type
|
||||
#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) zig_msvc_cmpxchg_##Type(obj, &(expected), desired)
|
||||
#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) zig_cmpxchg_strong(obj, expected, desired, succ, fail, Type, ReprType)
|
||||
@ -3672,12 +3677,11 @@ typedef int zig_memory_order;
|
||||
#endif
|
||||
/* TODO: _MSC_VER && (_M_ARM || _M_ARM64) */
|
||||
#else
|
||||
#define memory_order_relaxed 0
|
||||
#define memory_order_consume 1
|
||||
#define memory_order_acquire 2
|
||||
#define memory_order_release 3
|
||||
#define memory_order_acq_rel 4
|
||||
#define memory_order_seq_cst 5
|
||||
#define zig_memory_order_relaxed 0
|
||||
#define zig_memory_order_acquire 2
|
||||
#define zig_memory_order_release 3
|
||||
#define zig_memory_order_acq_rel 4
|
||||
#define zig_memory_order_seq_cst 5
|
||||
#define zig_atomic(Type) Type
|
||||
#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) zig_atomics_unavailable
|
||||
#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) zig_atomics_unavailable
|
||||
@ -3868,9 +3872,32 @@ static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expec
|
||||
return _InterlockedCompareExchange128((__int64 volatile*)obj, (__int64)zig_hi_u128(desired), (__int64)zig_lo_u128(desired), (__int64*)expected);
|
||||
}
|
||||
|
||||
static inline zig_u128 zig_msvc_atomic_load_u128(zig_u128 volatile* obj) {
|
||||
zig_u128 expected = zig_make_u128(UINT64_C(0), UINT64_C(0));
|
||||
(void)zig_cmpxchg_strong(obj, expected, expected, zig_memory_order_seq_cst, zig_memory_order_seq_cst, u128, zig_u128);
|
||||
return expected;
|
||||
}
|
||||
|
||||
static inline void zig_msvc_atomic_store_u128(zig_u128 volatile* obj, zig_u128 arg) {
|
||||
zig_u128 expected = zig_make_u128(UINT64_C(0), UINT64_C(0));
|
||||
while (!zig_cmpxchg_weak(obj, expected, arg, zig_memory_order_seq_cst, zig_memory_order_seq_cst, u128, zig_u128));
|
||||
}
|
||||
|
||||
static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) {
|
||||
return _InterlockedCompareExchange128((__int64 volatile*)obj, (__int64)zig_hi_i128(desired), (__int64)zig_lo_i128(desired), (__int64*)expected);
|
||||
}
|
||||
|
||||
static inline zig_i128 zig_msvc_atomic_load_i128(zig_i128 volatile* obj) {
|
||||
zig_i128 expected = zig_make_i128(INT64_C(0), UINT64_C(0));
|
||||
(void)zig_cmpxchg_strong(obj, expected, expected, zig_memory_order_seq_cst, zig_memory_order_seq_cst, i128, zig_i128);
|
||||
return expected;
|
||||
}
|
||||
|
||||
static inline void zig_msvc_atomic_store_i128(zig_i128 volatile* obj, zig_i128 arg) {
|
||||
zig_i128 expected = zig_make_i128(INT64_C(0), UINT64_C(0));
|
||||
while (!zig_cmpxchg_weak(obj, expected, arg, zig_memory_order_seq_cst, zig_memory_order_seq_cst, i128, zig_i128));
|
||||
}
|
||||
|
||||
#endif /* _M_IX86 */
|
||||
|
||||
#endif /* _MSC_VER && (_M_IX86 || _M_X64) */
|
||||
|
@ -4456,6 +4456,7 @@ fn globalVarDecl(
|
||||
.align_inst = .none, // passed via the decls data
|
||||
.init = init_inst,
|
||||
.is_extern = false,
|
||||
.is_const = !is_mutable,
|
||||
.is_threadlocal = is_threadlocal,
|
||||
});
|
||||
break :vi var_inst;
|
||||
@ -4474,6 +4475,7 @@ fn globalVarDecl(
|
||||
.align_inst = .none, // passed via the decls data
|
||||
.init = .none,
|
||||
.is_extern = true,
|
||||
.is_const = !is_mutable,
|
||||
.is_threadlocal = is_threadlocal,
|
||||
});
|
||||
break :vi var_inst;
|
||||
@ -11495,6 +11497,7 @@ const GenZir = struct {
|
||||
var_type: Zir.Inst.Ref,
|
||||
init: Zir.Inst.Ref,
|
||||
is_extern: bool,
|
||||
is_const: bool,
|
||||
is_threadlocal: bool,
|
||||
}) !Zir.Inst.Ref {
|
||||
const astgen = gz.astgen;
|
||||
@ -11533,6 +11536,7 @@ const GenZir = struct {
|
||||
.has_align = args.align_inst != .none,
|
||||
.has_init = args.init != .none,
|
||||
.is_extern = args.is_extern,
|
||||
.is_const = args.is_const,
|
||||
.is_threadlocal = args.is_threadlocal,
|
||||
}),
|
||||
.operand = payload_index,
|
||||
|
@ -1005,11 +1005,11 @@ pub const Key = union(enum) {
|
||||
ty: Index,
|
||||
init: Index,
|
||||
decl: DeclIndex,
|
||||
lib_name: OptionalNullTerminatedString = .none,
|
||||
is_extern: bool = false,
|
||||
is_const: bool = false,
|
||||
is_threadlocal: bool = false,
|
||||
is_weak_linkage: bool = false,
|
||||
lib_name: OptionalNullTerminatedString,
|
||||
is_extern: bool,
|
||||
is_const: bool,
|
||||
is_threadlocal: bool,
|
||||
is_weak_linkage: bool,
|
||||
};
|
||||
|
||||
pub const ExternFunc = struct {
|
||||
|
10
src/Sema.zig
10
src/Sema.zig
@ -24758,7 +24758,9 @@ fn zirVarExtended(
|
||||
.decl = sema.owner_decl_index,
|
||||
.lib_name = try mod.intern_pool.getOrPutStringOpt(sema.gpa, lib_name),
|
||||
.is_extern = small.is_extern,
|
||||
.is_const = small.is_const,
|
||||
.is_threadlocal = small.is_threadlocal,
|
||||
.is_weak_linkage = false,
|
||||
} })));
|
||||
}
|
||||
|
||||
@ -25262,6 +25264,7 @@ fn zirBuiltinExtern(
|
||||
if (options.linkage == .Weak and !ty.ptrAllowsZero(mod)) {
|
||||
ty = try mod.optionalType(ty.toIntern());
|
||||
}
|
||||
const ptr_info = ty.ptrInfo(mod);
|
||||
|
||||
// TODO check duplicate extern
|
||||
|
||||
@ -25272,11 +25275,12 @@ fn zirBuiltinExtern(
|
||||
|
||||
{
|
||||
const new_var = try mod.intern(.{ .variable = .{
|
||||
.ty = ty.toIntern(),
|
||||
.ty = ptr_info.child,
|
||||
.init = .none,
|
||||
.decl = sema.owner_decl_index,
|
||||
.lib_name = options.library_name,
|
||||
.is_extern = true,
|
||||
.is_const = true,
|
||||
.is_const = ptr_info.flags.is_const,
|
||||
.is_threadlocal = options.is_thread_local,
|
||||
.is_weak_linkage = options.linkage == .Weak,
|
||||
} });
|
||||
@ -25284,7 +25288,7 @@ fn zirBuiltinExtern(
|
||||
new_decl.src_line = sema.owner_decl.src_line;
|
||||
// We only access this decl through the decl_ref with the correct type created
|
||||
// below, so this type doesn't matter
|
||||
new_decl.ty = ty;
|
||||
new_decl.ty = Type.fromInterned(ptr_info.child);
|
||||
new_decl.val = Value.fromInterned(new_var);
|
||||
new_decl.alignment = .none;
|
||||
new_decl.@"linksection" = .none;
|
||||
|
@ -2610,8 +2610,9 @@ pub const Inst = struct {
|
||||
has_align: bool,
|
||||
has_init: bool,
|
||||
is_extern: bool,
|
||||
is_const: bool,
|
||||
is_threadlocal: bool,
|
||||
_: u11 = undefined,
|
||||
_: u10 = undefined,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -272,28 +272,6 @@ pub fn isMangledIdent(ident: []const u8, solo: bool) bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
const DeclVisibility = enum {
|
||||
global,
|
||||
global_mangled,
|
||||
local,
|
||||
|
||||
fn renderFwd(visibility: DeclVisibility, w: anytype) !void {
|
||||
try w.writeAll(switch (visibility) {
|
||||
.global => "zig_extern ",
|
||||
// MSVC doesn't support exporting `static` functions, so they need special treatment
|
||||
.global_mangled => "zig_extern_mangled ",
|
||||
.local => "static ",
|
||||
});
|
||||
}
|
||||
|
||||
fn renderDef(visibility: DeclVisibility, w: anytype) !void {
|
||||
return switch (visibility) {
|
||||
.global => {},
|
||||
else => visibility.renderFwd(w),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/// This data is available when outputting .c code for a `InternPool.Index`
|
||||
/// that corresponds to `func`.
|
||||
/// It is not available when generating .h file.
|
||||
@ -566,7 +544,6 @@ pub const DeclGen = struct {
|
||||
is_naked_fn: bool,
|
||||
/// This is a borrowed reference from `link.C`.
|
||||
fwd_decl: std.ArrayList(u8),
|
||||
|
||||
error_msg: ?*Module.ErrorMsg,
|
||||
ctypes: CType.Store,
|
||||
/// Keeps track of anonymous decls that need to be rendered before this
|
||||
@ -683,7 +660,7 @@ pub const DeclGen = struct {
|
||||
if (decl.val.getExternFunc(mod)) |extern_func| if (extern_func.decl != decl_index)
|
||||
return dg.renderDeclValue(writer, ty, val, extern_func.decl, location);
|
||||
|
||||
if (decl.val.getVariable(mod)) |variable| try dg.renderFwdDecl(decl_index, variable);
|
||||
if (decl.val.getVariable(mod)) |variable| try dg.renderFwdDecl(decl_index, variable, .tentative);
|
||||
|
||||
// We shouldn't cast C function pointers as this is UB (when you call
|
||||
// them). The analysis until now should ensure that the C function
|
||||
@ -1630,7 +1607,7 @@ pub const DeclGen = struct {
|
||||
kind: CType.Kind,
|
||||
name: union(enum) {
|
||||
export_index: u32,
|
||||
string: []const u8,
|
||||
ident: []const u8,
|
||||
},
|
||||
) !void {
|
||||
const store = &dg.ctypes.set;
|
||||
@ -1652,23 +1629,28 @@ pub const DeclGen = struct {
|
||||
try w.writeAll("zig_cold ");
|
||||
if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");
|
||||
|
||||
const trailing = try renderTypePrefix(dg.pass, store.*, mod, w, fn_cty_idx, .suffix, .{});
|
||||
try w.print("{}", .{trailing});
|
||||
var trailing = try renderTypePrefix(dg.pass, store.*, mod, w, fn_cty_idx, .suffix, .{});
|
||||
|
||||
if (toCallingConvention(fn_info.cc)) |call_conv| {
|
||||
try w.print("zig_callconv({s}) ", .{call_conv});
|
||||
try w.print("{}zig_callconv({s})", .{ trailing, call_conv });
|
||||
trailing = .maybe_space;
|
||||
}
|
||||
|
||||
switch (kind) {
|
||||
.forward => {},
|
||||
.complete => if (fn_info.alignment.toByteUnitsOptional()) |a|
|
||||
try w.print(" zig_align_fn({})", .{a}),
|
||||
.complete => if (fn_info.alignment.toByteUnitsOptional()) |a| {
|
||||
try w.print("{}zig_align_fn({})", .{ trailing, a });
|
||||
trailing = .maybe_space;
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
switch (name) {
|
||||
.export_index => |export_index| try dg.renderDeclName(w, fn_decl_index, export_index),
|
||||
.string => |string| try w.print("{ }", .{fmtIdent(string)}),
|
||||
.export_index => |export_index| {
|
||||
try w.print("{}", .{trailing});
|
||||
try dg.renderDeclName(w, fn_decl_index, export_index);
|
||||
},
|
||||
.ident => |ident| try w.print("{}{ }", .{ trailing, fmtIdent(ident) }),
|
||||
}
|
||||
|
||||
try renderTypeSuffix(
|
||||
@ -1686,8 +1668,49 @@ pub const DeclGen = struct {
|
||||
);
|
||||
|
||||
switch (kind) {
|
||||
.forward => if (fn_info.alignment.toByteUnitsOptional()) |a|
|
||||
try w.print(" zig_align_fn({})", .{a}),
|
||||
.forward => {
|
||||
if (fn_info.alignment.toByteUnitsOptional()) |a| {
|
||||
try w.print(" zig_align_fn({})", .{a});
|
||||
}
|
||||
switch (name) {
|
||||
.export_index => |export_index| mangled: {
|
||||
const maybe_exports = mod.decl_exports.get(fn_decl_index);
|
||||
const external_name = ip.stringToSlice(
|
||||
if (maybe_exports) |exports|
|
||||
exports.items[export_index].opts.name
|
||||
else if (fn_decl.isExtern(mod))
|
||||
fn_decl.name
|
||||
else
|
||||
break :mangled,
|
||||
);
|
||||
const is_mangled = isMangledIdent(external_name, true);
|
||||
const is_export = export_index > 0;
|
||||
if (is_mangled and is_export) {
|
||||
try w.print(" zig_mangled_export({ }, {s}, {s})", .{
|
||||
fmtIdent(external_name),
|
||||
fmtStringLiteral(external_name, null),
|
||||
fmtStringLiteral(
|
||||
ip.stringToSlice(maybe_exports.?.items[0].opts.name),
|
||||
null,
|
||||
),
|
||||
});
|
||||
} else if (is_mangled) {
|
||||
try w.print(" zig_mangled_final({ }, {s})", .{
|
||||
fmtIdent(external_name), fmtStringLiteral(external_name, null),
|
||||
});
|
||||
} else if (is_export) {
|
||||
try w.print(" zig_export({s}, {s})", .{
|
||||
fmtStringLiteral(
|
||||
ip.stringToSlice(maybe_exports.?.items[0].opts.name),
|
||||
null,
|
||||
),
|
||||
fmtStringLiteral(external_name, null),
|
||||
});
|
||||
}
|
||||
},
|
||||
.ident => {},
|
||||
}
|
||||
},
|
||||
.complete => {},
|
||||
else => unreachable,
|
||||
}
|
||||
@ -1880,26 +1903,12 @@ pub const DeclGen = struct {
|
||||
try renderTypeSuffix(dg.pass, store.*, mod, w, cty_idx, .suffix, .{});
|
||||
}
|
||||
|
||||
fn declVisibility(dg: *DeclGen, tv: TypedValue) DeclVisibility {
|
||||
fn declIsGlobal(dg: *DeclGen, tv: TypedValue) bool {
|
||||
const mod = dg.module;
|
||||
return switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {
|
||||
.variable => |variable| {
|
||||
if (mod.decl_exports.get(variable.decl)) |exports| {
|
||||
return if (isMangledIdent(dg.module.intern_pool.stringToSlice(exports.items[0].opts.name), true))
|
||||
.global_mangled
|
||||
else
|
||||
.global;
|
||||
} else return .local;
|
||||
},
|
||||
.extern_func => .global,
|
||||
.func => |func| {
|
||||
if (mod.decl_exports.get(func.owner_decl)) |exports| {
|
||||
return if (isMangledIdent(dg.module.intern_pool.stringToSlice(exports.items[0].opts.name), true))
|
||||
.global_mangled
|
||||
else
|
||||
.global;
|
||||
} else return .local;
|
||||
},
|
||||
.variable => |variable| mod.decl_exports.contains(variable.decl),
|
||||
.extern_func => true,
|
||||
.func => |func| mod.decl_exports.contains(func.owner_decl),
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
@ -1981,12 +1990,18 @@ pub const DeclGen = struct {
|
||||
try dg.writeCValue(writer, member);
|
||||
}
|
||||
|
||||
fn renderFwdDecl(dg: *DeclGen, decl_index: InternPool.DeclIndex, variable: InternPool.Key.Variable) !void {
|
||||
fn renderFwdDecl(
|
||||
dg: *DeclGen,
|
||||
decl_index: InternPool.DeclIndex,
|
||||
variable: InternPool.Key.Variable,
|
||||
fwd_kind: enum { tentative, final },
|
||||
) !void {
|
||||
const decl = dg.module.declPtr(decl_index);
|
||||
const fwd = dg.fwd_decl.writer();
|
||||
const visibility = if (variable.is_extern) .global else dg.declVisibility(.{ .ty = decl.ty, .val = decl.val });
|
||||
try visibility.renderFwd(fwd);
|
||||
const export_weak_linkage = if (dg.module.decl_exports.get(decl_index)) |exports|
|
||||
const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.ty, .val = decl.val });
|
||||
try fwd.writeAll(if (is_global) "zig_extern " else "static ");
|
||||
const maybe_exports = dg.module.decl_exports.get(decl_index);
|
||||
const export_weak_linkage = if (maybe_exports) |exports|
|
||||
exports.items[0].opts.linkage == .Weak
|
||||
else
|
||||
false;
|
||||
@ -2000,6 +2015,21 @@ pub const DeclGen = struct {
|
||||
decl.alignment,
|
||||
.complete,
|
||||
);
|
||||
mangled: {
|
||||
const external_name = dg.module.intern_pool.stringToSlice(if (maybe_exports) |exports|
|
||||
exports.items[0].opts.name
|
||||
else if (variable.is_extern)
|
||||
decl.name
|
||||
else
|
||||
break :mangled);
|
||||
if (isMangledIdent(external_name, true)) {
|
||||
try fwd.print(" zig_mangled_{s}({ }, {s})", .{
|
||||
@tagName(fwd_kind),
|
||||
fmtIdent(external_name),
|
||||
fmtStringLiteral(external_name, null),
|
||||
});
|
||||
}
|
||||
}
|
||||
try fwd.writeAll(";\n");
|
||||
}
|
||||
|
||||
@ -2009,9 +2039,13 @@ pub const DeclGen = struct {
|
||||
try mod.markDeclAlive(decl);
|
||||
|
||||
if (mod.decl_exports.get(decl_index)) |exports| {
|
||||
try writer.print("{ }", .{fmtIdent(mod.intern_pool.stringToSlice(exports.items[export_index].opts.name))});
|
||||
try writer.print("{ }", .{
|
||||
fmtIdent(mod.intern_pool.stringToSlice(exports.items[export_index].opts.name)),
|
||||
});
|
||||
} else if (decl.getExternDecl(mod).unwrap()) |extern_decl_index| {
|
||||
try writer.print("{}", .{mod.declPtr(extern_decl_index).name.fmt(&mod.intern_pool)});
|
||||
try writer.print("{ }", .{
|
||||
fmtIdent(mod.intern_pool.stringToSlice(mod.declPtr(extern_decl_index).name)),
|
||||
});
|
||||
} else {
|
||||
// MSVC has a limit of 4095 character token length limit, and fmtIdent can (worst case),
|
||||
// expand to 3x the length of its input, but let's cut it off at a much shorter limit.
|
||||
@ -2643,54 +2677,61 @@ fn genExports(o: *Object) !void {
|
||||
|
||||
const mod = o.dg.module;
|
||||
const ip = &mod.intern_pool;
|
||||
const decl_index = o.dg.pass.decl;
|
||||
const decl_index = switch (o.dg.pass) {
|
||||
.decl => |decl| decl,
|
||||
.anon, .flush => return,
|
||||
};
|
||||
const decl = mod.declPtr(decl_index);
|
||||
const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) };
|
||||
const fwd = o.dg.fwd_decl.writer();
|
||||
|
||||
const exports = mod.decl_exports.get(decl_index) orelse return;
|
||||
if (exports.items.len < 2) return;
|
||||
|
||||
const is_mangled = isMangledIdent(ip.stringToSlice(exports.items[0].opts.name), true);
|
||||
if (exports.items.len < 2 and !is_mangled) return;
|
||||
|
||||
switch (ip.indexToKey(tv.val.toIntern())) {
|
||||
.func => {
|
||||
const start_i = 1 - @intFromBool(is_mangled);
|
||||
for (exports.items[start_i..], start_i..) |@"export", i| {
|
||||
try fwd.writeAll("zig_export(");
|
||||
if (exports.items[i].opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage_fn ");
|
||||
try o.dg.renderFunctionSignature(fwd, decl_index, .forward, .{ .export_index = @as(u32, @intCast(i)) });
|
||||
try fwd.print(", { }, {s});\n", .{
|
||||
fmtIdent(ip.stringToSlice(exports.items[0].opts.name)),
|
||||
fmtStringLiteral(ip.stringToSlice(@"export".opts.name), null),
|
||||
});
|
||||
}
|
||||
const is_variable_const = switch (ip.indexToKey(tv.val.toIntern())) {
|
||||
.func => return for (exports.items[1..], 1..) |@"export", i| {
|
||||
try fwd.writeAll("zig_extern ");
|
||||
if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage_fn ");
|
||||
try o.dg.renderFunctionSignature(
|
||||
fwd,
|
||||
decl_index,
|
||||
.forward,
|
||||
.{ .export_index = @intCast(i) },
|
||||
);
|
||||
try fwd.writeAll(";\n");
|
||||
},
|
||||
.extern_func => {
|
||||
// TODO: when sema allows re-exporting extern decls
|
||||
unreachable;
|
||||
},
|
||||
.variable => |variable| {
|
||||
const start_i = 1 - @intFromBool(is_mangled);
|
||||
for (exports.items[start_i..], start_i..) |@"export", i| {
|
||||
try fwd.writeAll("zig_export(");
|
||||
if (exports.items[i].opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage ");
|
||||
const alias = ip.stringToSlice(@"export".opts.name);
|
||||
try o.dg.renderTypeAndName(
|
||||
fwd,
|
||||
decl.ty,
|
||||
.{ .identifier = alias },
|
||||
CQualifiers.init(.{ .@"const" = variable.is_const }),
|
||||
decl.alignment,
|
||||
.complete,
|
||||
);
|
||||
try fwd.print(", { }, {s});\n", .{
|
||||
fmtIdent(ip.stringToSlice(exports.items[0].opts.name)),
|
||||
fmtStringLiteral(alias, null),
|
||||
});
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
.variable => |variable| variable.is_const,
|
||||
else => true,
|
||||
};
|
||||
for (exports.items[1..]) |@"export"| {
|
||||
try fwd.writeAll("zig_extern ");
|
||||
if (@"export".opts.linkage == .Weak) try fwd.writeAll("zig_weak_linkage ");
|
||||
const export_name = ip.stringToSlice(@"export".opts.name);
|
||||
try o.dg.renderTypeAndName(
|
||||
fwd,
|
||||
decl.ty,
|
||||
.{ .identifier = export_name },
|
||||
CQualifiers.init(.{ .@"const" = is_variable_const }),
|
||||
decl.alignment,
|
||||
.complete,
|
||||
);
|
||||
if (isMangledIdent(export_name, true)) {
|
||||
try fwd.print(" zig_mangled_export({ }, {s}, {s})", .{
|
||||
fmtIdent(export_name),
|
||||
fmtStringLiteral(export_name, null),
|
||||
fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),
|
||||
});
|
||||
} else {
|
||||
try fwd.print(" zig_export({s}, {s})", .{
|
||||
fmtStringLiteral(ip.stringToSlice(exports.items[0].opts.name), null),
|
||||
fmtStringLiteral(export_name, null),
|
||||
});
|
||||
}
|
||||
try fwd.writeAll(";\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2762,12 +2803,12 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
|
||||
fwd_decl_writer,
|
||||
fn_decl_index,
|
||||
.forward,
|
||||
.{ .string = fn_name },
|
||||
.{ .ident = fn_name },
|
||||
);
|
||||
try fwd_decl_writer.writeAll(";\n");
|
||||
|
||||
try w.print("static zig_{s} ", .{@tagName(key)});
|
||||
try o.dg.renderFunctionSignature(w, fn_decl_index, .complete, .{ .string = fn_name });
|
||||
try o.dg.renderFunctionSignature(w, fn_decl_index, .complete, .{ .ident = fn_name });
|
||||
try w.writeAll(" {\n return ");
|
||||
try o.dg.renderDeclName(w, fn_decl_index, 0);
|
||||
try w.writeByte('(');
|
||||
@ -2797,9 +2838,9 @@ pub fn genFunc(f: *Function) !void {
|
||||
o.code_header = std.ArrayList(u8).init(gpa);
|
||||
defer o.code_header.deinit();
|
||||
|
||||
const visibility = o.dg.declVisibility(tv);
|
||||
const is_global = o.dg.declIsGlobal(tv);
|
||||
const fwd_decl_writer = o.dg.fwd_decl.writer();
|
||||
try visibility.renderFwd(fwd_decl_writer);
|
||||
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
|
||||
|
||||
if (mod.decl_exports.get(decl_index)) |exports|
|
||||
if (exports.items[0].opts.linkage == .Weak) try fwd_decl_writer.writeAll("zig_weak_linkage_fn ");
|
||||
@ -2808,7 +2849,7 @@ pub fn genFunc(f: *Function) !void {
|
||||
try genExports(o);
|
||||
|
||||
try o.indent_writer.insertNewline();
|
||||
try visibility.renderDef(o.writer());
|
||||
if (!is_global) try o.writer().writeAll("static ");
|
||||
try o.dg.renderFunctionSignature(o.writer(), decl_index, .complete, .{ .export_index = 0 });
|
||||
try o.writer().writeByte(' ');
|
||||
|
||||
@ -2887,14 +2928,14 @@ pub fn genDecl(o: *Object) !void {
|
||||
try fwd_decl_writer.writeAll(";\n");
|
||||
try genExports(o);
|
||||
} else if (tv.val.getVariable(mod)) |variable| {
|
||||
try o.dg.renderFwdDecl(decl_index, variable);
|
||||
try o.dg.renderFwdDecl(decl_index, variable, .final);
|
||||
try genExports(o);
|
||||
|
||||
if (variable.is_extern) return;
|
||||
|
||||
const visibility = if (variable.is_extern) .global else o.dg.declVisibility(tv);
|
||||
const is_global = variable.is_extern or o.dg.declIsGlobal(tv);
|
||||
const w = o.writer();
|
||||
try visibility.renderDef(w);
|
||||
if (!is_global) try w.writeAll("static ");
|
||||
if (variable.is_weak_linkage) try w.writeAll("zig_weak_linkage ");
|
||||
if (variable.is_threadlocal) try w.writeAll("zig_threadlocal ");
|
||||
if (mod.intern_pool.stringToSliceUnwrap(decl.@"linksection")) |s|
|
||||
@ -2907,21 +2948,16 @@ pub fn genDecl(o: *Object) !void {
|
||||
try w.writeByte(';');
|
||||
try o.indent_writer.insertNewline();
|
||||
} else {
|
||||
const visibility: DeclVisibility = if (o.dg.module.decl_exports.get(decl_index)) |exports| b: {
|
||||
break :b if (isMangledIdent(o.dg.module.intern_pool.stringToSlice(exports.items[0].opts.name), true))
|
||||
.global_mangled
|
||||
else
|
||||
.global;
|
||||
} else .local;
|
||||
const is_global = o.dg.module.decl_exports.contains(decl_index);
|
||||
const decl_c_value = .{ .decl = decl_index };
|
||||
return genDeclValue(o, tv, visibility, decl_c_value, decl.alignment, decl.@"linksection");
|
||||
try genDeclValue(o, tv, is_global, decl_c_value, decl.alignment, decl.@"linksection");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn genDeclValue(
|
||||
o: *Object,
|
||||
tv: TypedValue,
|
||||
visibility: DeclVisibility,
|
||||
is_global: bool,
|
||||
decl_c_value: CValue,
|
||||
alignment: Alignment,
|
||||
link_section: InternPool.OptionalNullTerminatedString,
|
||||
@ -2929,12 +2965,27 @@ pub fn genDeclValue(
|
||||
const mod = o.dg.module;
|
||||
const fwd_decl_writer = o.dg.fwd_decl.writer();
|
||||
|
||||
try visibility.renderFwd(fwd_decl_writer);
|
||||
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
|
||||
try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, Const, alignment, .complete);
|
||||
switch (o.dg.pass) {
|
||||
.decl => |decl_index| {
|
||||
if (mod.decl_exports.get(decl_index)) |exports| {
|
||||
const export_name = mod.intern_pool.stringToSlice(exports.items[0].opts.name);
|
||||
if (isMangledIdent(export_name, true)) {
|
||||
try fwd_decl_writer.print(" zig_mangled_final({ }, {s})", .{
|
||||
fmtIdent(export_name), fmtStringLiteral(export_name, null),
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
.anon => {},
|
||||
.flush => unreachable,
|
||||
}
|
||||
try fwd_decl_writer.writeAll(";\n");
|
||||
try genExports(o);
|
||||
|
||||
const w = o.writer();
|
||||
try visibility.renderDef(w);
|
||||
if (!is_global) try w.writeAll("static ");
|
||||
|
||||
if (mod.intern_pool.stringToSliceUnwrap(link_section)) |s|
|
||||
try w.print("zig_linksection(\"{s}\", ", .{s});
|
||||
@ -2959,16 +3010,10 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
|
||||
const writer = dg.fwd_decl.writer();
|
||||
|
||||
switch (tv.ty.zigTypeTag(mod)) {
|
||||
.Fn => {
|
||||
const visibility = dg.declVisibility(tv);
|
||||
switch (visibility) {
|
||||
.global, .global_mangled => {
|
||||
try visibility.renderFwd(writer);
|
||||
try dg.renderFunctionSignature(writer, dg.pass.decl, .complete, .{ .export_index = 0 });
|
||||
try dg.fwd_decl.appendSlice(";\n");
|
||||
},
|
||||
.local => {},
|
||||
}
|
||||
.Fn => if (dg.declIsGlobal(tv)) {
|
||||
try writer.writeAll("zig_extern ");
|
||||
try dg.renderFunctionSignature(writer, dg.pass.decl, .complete, .{ .export_index = 0 });
|
||||
try dg.fwd_decl.appendSlice(";\n");
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
@ -7451,11 +7496,11 @@ fn airCVaCopy(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
fn toMemoryOrder(order: std.builtin.AtomicOrder) [:0]const u8 {
|
||||
return switch (order) {
|
||||
// Note: unordered is actually even less atomic than relaxed
|
||||
.Unordered, .Monotonic => "memory_order_relaxed",
|
||||
.Acquire => "memory_order_acquire",
|
||||
.Release => "memory_order_release",
|
||||
.AcqRel => "memory_order_acq_rel",
|
||||
.SeqCst => "memory_order_seq_cst",
|
||||
.Unordered, .Monotonic => "zig_memory_order_relaxed",
|
||||
.Acquire => "zig_memory_order_acquire",
|
||||
.Release => "zig_memory_order_release",
|
||||
.AcqRel => "zig_memory_order_acq_rel",
|
||||
.SeqCst => "zig_memory_order_seq_cst",
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {
|
||||
};
|
||||
const c_value: codegen.CValue = .{ .constant = anon_decl };
|
||||
const alignment: Alignment = self.aligned_anon_decls.get(anon_decl) orelse .none;
|
||||
codegen.genDeclValue(&object, tv, .local, c_value, alignment, .none) catch |err| switch (err) {
|
||||
codegen.genDeclValue(&object, tv, false, c_value, alignment, .none) catch |err| switch (err) {
|
||||
error.AnalysisFail => {
|
||||
@panic("TODO: C backend AnalysisFail on anonymous decl");
|
||||
//try module.failed_decls.put(gpa, decl_index, object.dg.error_msg.?);
|
||||
|
@ -110,7 +110,6 @@ test {
|
||||
_ = @import("behavior/bugs/12551.zig");
|
||||
_ = @import("behavior/bugs/12571.zig");
|
||||
_ = @import("behavior/bugs/12644.zig");
|
||||
_ = @import("behavior/bugs/12680.zig");
|
||||
_ = @import("behavior/bugs/12723.zig");
|
||||
_ = @import("behavior/bugs/12776.zig");
|
||||
_ = @import("behavior/bugs/12786.zig");
|
||||
@ -175,6 +174,7 @@ test {
|
||||
_ = @import("behavior/hasfield.zig");
|
||||
_ = @import("behavior/if.zig");
|
||||
_ = @import("behavior/import.zig");
|
||||
_ = @import("behavior/import_c_keywords.zig");
|
||||
_ = @import("behavior/incomplete_struct_param_tld.zig");
|
||||
_ = @import("behavior/inline_switch.zig");
|
||||
_ = @import("behavior/int128.zig");
|
||||
@ -251,9 +251,7 @@ test {
|
||||
}
|
||||
|
||||
if (builtin.zig_backend != .stage2_arm and
|
||||
builtin.zig_backend != .stage2_x86_64 and
|
||||
builtin.zig_backend != .stage2_aarch64 and
|
||||
builtin.zig_backend != .stage2_c and
|
||||
builtin.zig_backend != .stage2_spirv64)
|
||||
{
|
||||
_ = @import("behavior/export_keyword.zig");
|
||||
|
@ -1,17 +0,0 @@
|
||||
const std = @import("std");
|
||||
const expectEqual = std.testing.expectEqual;
|
||||
const other_file = @import("12680_other_file.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
extern fn test_func() callconv(.C) usize;
|
||||
|
||||
test "export a function twice" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
|
||||
|
||||
// If it exports the function correctly, `test_func` and `testFunc` will points to the same address.
|
||||
try expectEqual(test_func(), other_file.testFunc());
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// export this function twice
|
||||
pub export fn testFunc() callconv(.C) usize {
|
||||
return @intFromPtr(&testFunc);
|
||||
}
|
||||
|
||||
comptime {
|
||||
@export(testFunc, .{ .name = "test_func", .linkage = .Strong });
|
||||
}
|
44
test/behavior/export_c_keywords.zig
Normal file
44
test/behavior/export_c_keywords.zig
Normal file
@ -0,0 +1,44 @@
|
||||
pub const Id = enum(c_int) {
|
||||
c_keyword_variable = 12,
|
||||
non_c_keyword_variable = 34,
|
||||
c_keyword_constant = 56,
|
||||
non_c_keyword_constant = 78,
|
||||
c_keyword_function = 910,
|
||||
non_c_keyword_function = 1112,
|
||||
};
|
||||
|
||||
export var int: Id = .c_keyword_variable;
|
||||
|
||||
export var some_non_c_keyword_variable: Id = .non_c_keyword_variable;
|
||||
|
||||
export const @"if": Id = .c_keyword_constant;
|
||||
|
||||
export const some_non_c_keyword_constant: Id = .non_c_keyword_constant;
|
||||
|
||||
export fn float() Id {
|
||||
return .c_keyword_function;
|
||||
}
|
||||
|
||||
export fn some_non_c_keyword_function() Id {
|
||||
return .non_c_keyword_function;
|
||||
}
|
||||
|
||||
comptime {
|
||||
@export(int, .{ .name = "long" });
|
||||
@export(int, .{ .name = "an_alias_of_int" });
|
||||
|
||||
@export(some_non_c_keyword_variable, .{ .name = "void" });
|
||||
@export(some_non_c_keyword_variable, .{ .name = "an_alias_of_some_non_c_keyword_variable" });
|
||||
|
||||
@export(@"if", .{ .name = "else" });
|
||||
@export(@"if", .{ .name = "an_alias_of_if" });
|
||||
|
||||
@export(some_non_c_keyword_constant, .{ .name = "switch" });
|
||||
@export(some_non_c_keyword_constant, .{ .name = "an_alias_of_some_non_c_keyword_constant" });
|
||||
|
||||
@export(float, .{ .name = "double" });
|
||||
@export(float, .{ .name = "an_alias_of_float" });
|
||||
|
||||
@export(some_non_c_keyword_function, .{ .name = "break" });
|
||||
@export(some_non_c_keyword_function, .{ .name = "an_alias_of_some_non_c_keyword_function" });
|
||||
}
|
92
test/behavior/import_c_keywords.zig
Normal file
92
test/behavior/import_c_keywords.zig
Normal file
@ -0,0 +1,92 @@
|
||||
const builtin = @import("builtin");
|
||||
const Id = @import("export_c_keywords.zig").Id;
|
||||
const std = @import("std");
|
||||
|
||||
extern var int: Id;
|
||||
extern var long: Id;
|
||||
extern var an_alias_of_int: Id;
|
||||
|
||||
extern var some_non_c_keyword_variable: Id;
|
||||
extern var @"void": Id;
|
||||
extern var an_alias_of_some_non_c_keyword_variable: Id;
|
||||
|
||||
extern const @"if": Id;
|
||||
extern const @"else": Id;
|
||||
extern const an_alias_of_if: Id;
|
||||
|
||||
extern const some_non_c_keyword_constant: Id;
|
||||
extern const @"switch": Id;
|
||||
extern const an_alias_of_some_non_c_keyword_constant: Id;
|
||||
|
||||
extern fn float() Id;
|
||||
extern fn double() Id;
|
||||
extern fn an_alias_of_float() Id;
|
||||
|
||||
extern fn some_non_c_keyword_function() Id;
|
||||
extern fn @"break"() Id;
|
||||
extern fn an_alias_of_some_non_c_keyword_function() Id;
|
||||
|
||||
test "import c keywords" {
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
|
||||
if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf) return error.SkipZigTest;
|
||||
|
||||
try std.testing.expect(int == .c_keyword_variable);
|
||||
try std.testing.expect(long == .c_keyword_variable);
|
||||
try std.testing.expect(an_alias_of_int == .c_keyword_variable);
|
||||
|
||||
try std.testing.expect(some_non_c_keyword_variable == .non_c_keyword_variable);
|
||||
try std.testing.expect(@"void" == .non_c_keyword_variable);
|
||||
try std.testing.expect(an_alias_of_some_non_c_keyword_variable == .non_c_keyword_variable);
|
||||
|
||||
try std.testing.expect(@"if" == .c_keyword_constant);
|
||||
try std.testing.expect(@"else" == .c_keyword_constant);
|
||||
try std.testing.expect(an_alias_of_if == .c_keyword_constant);
|
||||
|
||||
try std.testing.expect(some_non_c_keyword_constant == .non_c_keyword_constant);
|
||||
try std.testing.expect(@"switch" == .non_c_keyword_constant);
|
||||
try std.testing.expect(an_alias_of_some_non_c_keyword_constant == .non_c_keyword_constant);
|
||||
|
||||
try std.testing.expect(float() == .c_keyword_function);
|
||||
try std.testing.expect(double() == .c_keyword_function);
|
||||
try std.testing.expect(an_alias_of_float() == .c_keyword_function);
|
||||
|
||||
try std.testing.expect(some_non_c_keyword_function() == .non_c_keyword_function);
|
||||
try std.testing.expect(@"break"() == .non_c_keyword_function);
|
||||
try std.testing.expect(an_alias_of_some_non_c_keyword_function() == .non_c_keyword_function);
|
||||
|
||||
var ptr_id: *const Id = &long;
|
||||
try std.testing.expect(ptr_id == &int);
|
||||
ptr_id = &an_alias_of_int;
|
||||
try std.testing.expect(ptr_id == &int);
|
||||
|
||||
ptr_id = &@"void";
|
||||
try std.testing.expect(ptr_id == &some_non_c_keyword_variable);
|
||||
ptr_id = &an_alias_of_some_non_c_keyword_variable;
|
||||
try std.testing.expect(ptr_id == &some_non_c_keyword_variable);
|
||||
|
||||
ptr_id = &@"else";
|
||||
try std.testing.expect(ptr_id == &@"if");
|
||||
ptr_id = &an_alias_of_if;
|
||||
try std.testing.expect(ptr_id == &@"if");
|
||||
|
||||
ptr_id = &@"switch";
|
||||
try std.testing.expect(ptr_id == &some_non_c_keyword_constant);
|
||||
ptr_id = &an_alias_of_some_non_c_keyword_constant;
|
||||
try std.testing.expect(ptr_id == &some_non_c_keyword_constant);
|
||||
|
||||
if (builtin.target.ofmt != .coff and builtin.target.os.tag != .windows) {
|
||||
var ptr_fn: *const fn () callconv(.C) Id = &double;
|
||||
try std.testing.expect(ptr_fn == &float);
|
||||
ptr_fn = &an_alias_of_float;
|
||||
try std.testing.expect(ptr_fn == &float);
|
||||
|
||||
ptr_fn = &@"break";
|
||||
try std.testing.expect(ptr_fn == &some_non_c_keyword_function);
|
||||
ptr_fn = &an_alias_of_some_non_c_keyword_function;
|
||||
try std.testing.expect(ptr_fn == &some_non_c_keyword_function);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user