Commit d856c89

kravantokh <kravantokh@noreply.codeberg.org>
2026-07-19 14:11:08
Eliminate some more debugging-unfriendly macros.
1 parent f95d147
memory/memory.h
@@ -3,11 +3,13 @@
 
 #include "../platform/platform.h"
 
-#define PLATFORM_MEMORY_HEADER \
-	LINUX("./linux/memory.h") \
-	WINDOWS("./windows/memory.h")
+/* Platform memory header */
+#if PLATFORM == PLATFORM_LINUX
+	#include "./linux/memory.h"
+#elif PLATFORM == PLATFORM_WINDOWS
+	#include "./windows/memory.h"
+#endif
 
-#include PLATFORM_MEMORY_HEADER
 
 /* Memory units */
 
platform/common/arch.h
@@ -21,6 +21,7 @@
 	#error Failed to identify architecture. Please specify it via -DARCH=number (choose the most compatible option from above) and -DARCH_NAME=name to override the automatic detection.
 #endif
 
+/* These are only for in-macro use, in case they are absolutely necessary. Not to be abused. They lead to messy code in debuggers */
 #ifndef X86_64
 #define X86_64(...)
 #endif
platform/common/os.h
@@ -8,11 +8,11 @@
 	#if defined(__linux__)
 		#define OS OS_LINUX
 		#define OS_NAME "linux"
-		#define LINUX(...) __VA_ARGS__
+
 	#elif defined(_WIN32) || defined(_WIN64) 
 		#define OS OS_WINDOWS
 		#define OS_NAME "windows"
-		#define WINDOWS(...) __VA_ARGS__
+
 	#endif
 #endif
 
@@ -20,12 +20,4 @@
 	#error Failed to identify operating system. Please specify it via -DOS=number (choose the most compatible option from above) and -DOS_NAME=name to override the automatic detection.
 #endif
 
-#ifndef WINDOWS
-#define WINDOWS(...)
-#endif
-
-#ifndef LINUX
-#define LINUX(...)
-#endif
-
 #endif
platform/linux/coretypes.h
@@ -16,23 +16,24 @@ typedef signed long long s64;
 typedef float  f32;
 typedef double f64;
 
-X86_64(
+#if ARCH == ARCH_X86_64
+
 	typedef u64 usize;
 	typedef s64 isize;
 
 	typedef struct _Page {
 		u8 data[4096];
 	} Page;
-)
 
+#elif ARCH == ARCH_I386
 
-I386(
 	typedef u32 usize;
 	typedef s32 isize;
 
 	typedef struct _Page {
 		u8 data[4096];
 	} Page;
-)
+
+#endif
 
 #endif
platform/linux/entry.h
@@ -8,7 +8,7 @@ u8* linux_startup_sp = 0;
 
 void entry(void); /* aka main */
 
-X86_64(
+#if ARCH == ARCH_X86_64
 	__asm__ (
 		".section .text\n"
 		".global _start\n"
@@ -19,10 +19,8 @@ X86_64(
 			"xor %rax, %rax\n"
 			"call entry\n"
 	);
-)
-
-I386(
-	ERROR("i386 entrypoint not implemented")
-)
+#elif ARCH == ARCH_I386
+	#error "i386 entrypoint not implemented"
+#endif
 
 #endif
platform/linux/syscall_wrappers_gcclike.h
@@ -3,8 +3,7 @@
 
 #include "./coretypes.h"
 
-X86_64(
-
+#if ARCH == ARCH_X86_64
 	/* All this mess, just so *maybe* the compiler can optimize register usage when inlining. Check the generic wrappers for a more typical way of going about this. This here is unusual, from what I have seen. */
 	static inline isize linux_syscall1(usize num, usize arg1) {
 			register usize ret __asm__("rax") = num;
@@ -101,10 +100,9 @@ X86_64(
 			);
 		return ret;
 	}
-)
 
-I386(
-	ERROR("Linux syscalls not implemented for I386.");
-)
+#elif ARCH == ARCH_I386
+	#error "Linux syscalls not implemented for I386."
+#endif
 
 #endif
platform/linux/syscall_wrappers_generic.h
@@ -81,11 +81,9 @@
 		);
 		return num;
 	}
-#endif
-
 
-I386(
-	ERROR("Linux syscalls not implemented for I386.");
-)
+#elif ARCH == ARCH_I386
+	#error "Linux syscalls not implemented for I386."
+#endif
 
 #endif
platform/platform.h
@@ -6,12 +6,12 @@
 #include "./common/arch.h"
 #include "./common/os.h"
 
-#define HEADER_PLATFORM_CORETYPES \
-	LINUX("linux/coretypes.h") \
-	WINDOWS("windows/coretypes.h")
-
-/* Basic types */
-#include HEADER_PLATFORM_CORETYPES
+/* Core types header */
+#if PLATFORM == PLATFORM_LINUX
+	#include "linux/coretypes.h"
+#elif PLATFORM == PLATFORM_WINDOWS
+	#include "windows/coretypes.h"
+#endif
 
 /* Type sanity checks */
 ASSERT( sizeof( u8 ) == 1 );
@@ -30,18 +30,18 @@ ASSERT( sizeof( f64 ) == 8 );
 /* Core platform functions */
 #include "./common/corefunc.h"
 
-#define HEADER_PLATFORM_COREFUNC   \
-	LINUX("./linux/corefunc.h")     \
-	WINDOWS("./windows/corefunc.h")
-
-#include HEADER_PLATFORM_COREFUNC
+#if PLATFORM == PLATFORM_LINUX
+	#include "./linux/corefunc.h"
+#elif PLATFORM == PLATFORM_WINDOWS
+	#include "./windows/corefunc.h"
+#endif
 
 /* Platform-dependent entrypoint function */
-#define HEADER_PLATFORM_ENTRY \
-	LINUX("./linux/entry.h") \
-	WINDOWS("./windows/entry.h")
-
-#include HEADER_PLATFORM_ENTRY
+#if PLATFORM == PLATFORM_LINUX
+	#include "./linux/entry.h"
+#elif PLATFORM == PLATFORM_WINDOWS
+	#include "./windows/entry.h"
+#endif
 
 /* Error handling types and macros. */
 #include "./common/error.h"
@@ -49,12 +49,12 @@ ASSERT( sizeof( f64 ) == 8 );
 
 /* Compiler-specific tricks */
 
-GCCLIKE( IMPL(
+#if (COMPILER == COMPILER_GCC || COMPILER == COMPILER_CLANG) && defined(NOTLIBC_IMPLEMENT) 
 	/* This is so that GCC can detect stack smashing via canaries and crash the program when it happens. */
 	void __stack_chk_fail(void) {
 		assert(0);
 	}
-))
+#endif
 
 
 #endif
util/safemath.h
@@ -23,12 +23,11 @@ static inline Status s64_add(s64 n1, s64 n2, s64 *out);
 
 
 #ifdef NOTLIBC_IMPLEMENT
-	#define SAFEMATH_IMPL_HEADER \
-		GCCLIKE("./safemath_gcclike.h") \
-		TCC("./safemath_generic.h") \
-		MSVC("./safemath_generic.h")
-
-	#include SAFEMATH_IMPL_HEADER
+	#if COMPILER == COMPILER_GCC || COPMILER == COMPILER_CLANG
+		#include "./safemath_gcclike.h"
+	#else
+		#include "./safemath_generic.h"
+	#endif
 #endif
 
 #endif
util/safemath_generic.h
@@ -2,7 +2,7 @@
 #define NOTLIBC_HEADER_UTIL_SAFEMATH_GENERIC_INCLUDED
 
 #include "../platform/platform.h"
-#include "util/limits.h"
+#include "./limits.h"
 
 /* Unsigned addition */