From 27d6acadc7a67b8e5da438f0090afc2357379088 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 16 May 2024 23:50:17 -0500 Subject: [PATCH] minor tweaks --- src/arena.h | 2 +- src/common.h | 6 ++++-- src/inc.c | 4 ++-- src/math.h | 3 ++- src/string.c | 8 ++++---- src/string.h | 2 +- src/sys_win32.c | 2 +- src/util.h | 1 + 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/arena.h b/src/arena.h index daa48c30..38e7e1d0 100644 --- a/src/arena.h +++ b/src/arena.h @@ -85,7 +85,7 @@ INLINE void *_arena_align(struct arena *arena, u64 align) INLINE struct temp_arena arena_temp_begin(struct arena *arena) { - struct temp_arena t; + struct temp_arena t = { 0 }; t.arena = arena; t.start_pos = arena->pos; return t; diff --git a/src/common.h b/src/common.h index 1f9323d5..3066b4e8 100644 --- a/src/common.h +++ b/src/common.h @@ -102,7 +102,9 @@ extern "C" { #if defined(__cplusplus) # define LANGUAGE_CPP 1 +# define LANGUAGE_C 0 #else +# define LANGUAGE_CPP 0 # define LANGUAGE_C 1 #endif @@ -238,7 +240,7 @@ void __asan_unpoison_memory_region(void const volatile *add, size_t); #endif /* Bool */ -#ifndef __cplusplus +#if !LANGUAGE_CPP # define true 1 # define false 0 #endif @@ -353,7 +355,7 @@ INLINE u128 u128_mul(u128 a, u128 b) { return a * b; } #elif COMPILER_MSVC -#ifdef __cplusplus +#if LANGUAGE_CPP # define U128(hi64, lo64) { (hi64), (lo64) } #else # define U128(hi64, lo64) ((u128) { .hi = (hi64), .lo = (lo64) }) diff --git a/src/inc.c b/src/inc.c index 9e15a987..10dd4c62 100644 --- a/src/inc.c +++ b/src/inc.c @@ -7,14 +7,14 @@ * an embedded file. */ #if RESOURCES_EMBEDDED -INCBIN_INCLUDE(res_tar, "../build/res.tar"); +INCBIN_INCLUDE(res_tar, "build/res.tar"); struct buffer inc_res_tar(void) { return INCBIN_GET(res_tar); } #endif -INCBIN_INCLUDE(shaders_tar, "../build/shaders.tar"); +INCBIN_INCLUDE(shaders_tar, "build/shaders.tar"); struct buffer inc_shaders_tar(void) { return INCBIN_GET(shaders_tar); diff --git a/src/math.h b/src/math.h index 62245051..067444cc 100644 --- a/src/math.h +++ b/src/math.h @@ -135,7 +135,8 @@ INLINE i64 math_fsign64(f64 f) * ========================== */ /* Taken from https://gist.github.com/orlp/3551590 */ -INLINE u64 math_pow_u64(u64 base, u8 exp) { +INLINE u64 math_pow_u64(u64 base, u8 exp) +{ LOCAL_PERSIST const u8 highest_bit_set[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, diff --git a/src/string.c b/src/string.c index 462b1c6a..04493e49 100644 --- a/src/string.c +++ b/src/string.c @@ -115,7 +115,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision) /* Add one half of next precision level to round up */ f += 0.5 / (f64)math_pow_u64(10, (u8)precision); - f64 part_whole = math_floor64(f); + f64 part_whole = math_trunc64(f); f64 part_decimal = f - part_whole; /* Print whole part */ @@ -129,7 +129,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision) u64 digit = (u64)math_round_to_int64(math_fmod64(part_whole, 10.0)); string_from_char(scratch.arena, INT_CHARS[digit % 10]); ++backwards_text_len; - part_whole = math_floor64(part_whole / 10.0); + part_whole = math_trunc64(part_whole / 10.0); } while (part_whole > 0); /* Reverse text into final string */ @@ -146,7 +146,7 @@ struct string string_from_float(struct arena *arena, f64 f, u32 precision) string_from_char(arena, '.'); for (u64 i = 0; i < precision; ++i) { part_decimal *= 10.0; - u64 digit = (u64)math_floor_to_int64(part_decimal); + u64 digit = (u64)part_decimal; part_decimal -= digit; string_from_char(arena, INT_CHARS[digit % 10]); } @@ -439,7 +439,7 @@ struct string string_formatv(struct arena *arena, struct string fmt, va_list arg no_more_args = true; } break; - case FMT_TYPE_NONE: { + default: { /* Unknown format type */ ASSERT(false); parsed_str = string_copy(arena, STR("")); diff --git a/src/string.h b/src/string.h index 4a91923f..3aa463a2 100644 --- a/src/string.h +++ b/src/string.h @@ -78,7 +78,7 @@ struct fmt_arg { #define FMT_FLOAT(v) FMT_FLOAT_P(v, DEFAULT_FMT_PRECISION) #define FMT_FLOAT_P(v, p) (struct fmt_arg) {.type = FMT_TYPE_FLOAT, .value.f.val = (v), .value.f.precision = p} -#define string_format(arena, fmt, ...) _string_format(arena, fmt, __VA_ARGS__, FMT_END) +#define string_format(arena, fmt, ...) _string_format((arena), (fmt), __VA_ARGS__, FMT_END) struct string _string_format(struct arena *arena, struct string fmt, ...); struct string string_formatv(struct arena *arena, struct string fmt, va_list args); diff --git a/src/sys_win32.c b/src/sys_win32.c index 57442da8..28ac891b 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -376,7 +376,7 @@ struct sys_file sys_file_open_read(struct string path) ); scratch_end(scratch); - struct sys_file file = (struct sys_file) { (u64)handle }; + struct sys_file file = { (u64)handle }; return file; } diff --git a/src/util.h b/src/util.h index 8ae197db..9c2afcff 100644 --- a/src/util.h +++ b/src/util.h @@ -31,6 +31,7 @@ INLINE u64 hash_fnv64(u64 seed, struct buffer buff) #define HASH_FNV128_BASIS U128(0x6C62272E07BB0142, 0x62B821756295C58D) INLINE u128 hash_fnv128(u128 seed, struct buffer buff) { + /* FIXME: Verify MSVC version of 128 is same */ u128 hash = seed; for (u64 i = 0; i < buff.size; ++i) { u8 c = (u8)buff.data[i];