summaryrefslogtreecommitdiff
path: root/src/codegen/compat.h
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-17 16:33:36 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-17 16:33:36 +0000
commit6b2545224752be74de35166c3dcda9ff5bdb79e3 (patch)
treeaa2765253769a0a1635d9ffc22738ec6598254c1 /src/codegen/compat.h
parentb885629239d04d2860a8853799a3d335d8bec154 (diff)
Add C++ interop support.
Diffstat (limited to 'src/codegen/compat.h')
-rw-r--r--src/codegen/compat.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/codegen/compat.h b/src/codegen/compat.h
new file mode 100644
index 0000000..423b1d9
--- /dev/null
+++ b/src/codegen/compat.h
@@ -0,0 +1,100 @@
+
+#ifndef ZC_COMPAT_H
+#define ZC_COMPAT_H
+
+#ifdef __cplusplus
+/* C++ mode */
+#define ZC_AUTO auto
+#define ZC_CAST(T, x) static_cast<T>(x)
+#define ZC_REINTERPRET(T, x) reinterpret_cast<T>(x)
+#define ZC_EXTERN_C extern "C"
+#define ZC_EXTERN_C_BEGIN \
+ extern "C" \
+ {
+#define ZC_EXTERN_C_END }
+#else
+/* C mode */
+#define ZC_AUTO __auto_type
+#define ZC_CAST(T, x) ((T)(x))
+#define ZC_REINTERPRET(T, x) ((T)(x))
+#define ZC_EXTERN_C
+#define ZC_EXTERN_C_BEGIN
+#define ZC_EXTERN_C_END
+#endif
+
+#ifdef __cplusplus
+#include <type_traits>
+
+inline const char *_zc_fmt(bool)
+{
+ return "%d";
+}
+inline const char *_zc_fmt(char)
+{
+ return "%c";
+}
+inline const char *_zc_fmt(signed char)
+{
+ return "%c";
+}
+inline const char *_zc_fmt(unsigned char)
+{
+ return "%u";
+}
+inline const char *_zc_fmt(short)
+{
+ return "%d";
+}
+inline const char *_zc_fmt(unsigned short)
+{
+ return "%u";
+}
+inline const char *_zc_fmt(int)
+{
+ return "%d";
+}
+inline const char *_zc_fmt(unsigned int)
+{
+ return "%u";
+}
+inline const char *_zc_fmt(long)
+{
+ return "%ld";
+}
+inline const char *_zc_fmt(unsigned long)
+{
+ return "%lu";
+}
+inline const char *_zc_fmt(long long)
+{
+ return "%lld";
+}
+inline const char *_zc_fmt(unsigned long long)
+{
+ return "%llu";
+}
+inline const char *_zc_fmt(float)
+{
+ return "%f";
+}
+inline const char *_zc_fmt(double)
+{
+ return "%f";
+}
+inline const char *_zc_fmt(char *)
+{
+ return "%s";
+}
+inline const char *_zc_fmt(const char *)
+{
+ return "%s";
+}
+inline const char *_zc_fmt(void *)
+{
+ return "%p";
+}
+
+#define _z_str(x) _zc_fmt(x)
+#endif
+
+#endif