From 6cfd5bd784f727a408d9b099348668b0441de41a Mon Sep 17 00:00:00 2001 From: krzosa Date: Sun, 29 Dec 2024 11:12:23 +0100 Subject: [PATCH] SWITCH_PLATFORM_WINDOWS_WASM_ELSE --- src/core/intrinsics.c | 26 ++++++++++++-------------- src/core/platform_defines.h | 17 ++++++----------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/core/intrinsics.c b/src/core/intrinsics.c index 76bbd33..de4b325 100644 --- a/src/core/intrinsics.c +++ b/src/core/intrinsics.c @@ -79,28 +79,26 @@ b32 vmem_decommit(void *p, usize size) { return true; } #if PLATFORM_WASM f64 s8_deserial_f64(s8_t string); void write_to_console(char *string); -void core_log_message(char *string) { - write_to_console(string); -} -void core_panic(void) { - if (core_desc.on_exit) core_desc.on_exit(); - debug_break(); -} #else f64 s8_deserial_f64(s8_t string) { return strtod(string.str, NULL); } +#endif + void core_log_message(char *string) { - IF_PLATFORM_WINDOWS(if (IsDebuggerPresent()) OutputDebugStringA(string)); - printf("%s", string); - fflush(stdout); + SWITCH_PLATFORM_WINDOWS_WASM_ELSE( + if (IsDebuggerPresent()) OutputDebugStringA(string), + write_to_console(string), + printf("%s", string); fflush(stdout) + ); } void core_panic(void) { if (core_desc.on_exit) core_desc.on_exit(); - IF_PLATFORM_WINDOWS(ExitProcess(1)); - IF_NOT_PLATFORM_WINDOWS(exit(1)); + SWITCH_PLATFORM_WINDOWS_WASM_ELSE( + ExitProcess(1), + debug_break(), + exit(1) + ); } -#endif - void core_on_exit(void) { debugf("program panicked! exiting..."); diff --git a/src/core/platform_defines.h b/src/core/platform_defines.h index d4afb5f..a507553 100644 --- a/src/core/platform_defines.h +++ b/src/core/platform_defines.h @@ -69,17 +69,12 @@ #endif #if PLATFORM_WINDOWS -#define IF_PLATFORM_WINDOWS(x) x -#define IF_NOT_PLATFORM_WINDOWS(x) +#define SWITCH_PLATFORM_WINDOWS_WASM_ELSE(WINDOWS, WASM, ELSE) WINDOWS +#elif PLATFORM_WASM +#define SWITCH_PLATFORM_WINDOWS_WASM_ELSE(WINDOWS, WASM, ELSE) WASM #else -#define IF_PLATFORM_WINDOWS(x) -#define IF_NOT_PLATFORM_WINDOWS(x) x +#define SWITCH_PLATFORM_WINDOWS_WASM_ELSE(WINDOWS, WASM, ELSE) ELSE #endif -#if PLATFORM_WASM -#define IF_PLATFORM_WASM(x) x -#define IF_NOT_PLATFORM_WASM(x) -#else -#define IF_PLATFORM_WASM(x) -#define IF_NOT_PLATFORM_WASM(x) x -#endif \ No newline at end of file +#define IF_PLATFORM_WINDOWS(x) SWITCH_PLATFORM_WINDOWS_WASM_ELSE(x, ((void)0), ((void)0)) +#define IF_PLATFORM_NOT_WINDOWS(x) SWITCH_PLATFORM_WINDOWS_WASM_ELSE(((void)0), x, x)