From 546c50885ffbb33ba9050bfaa2fa6c440e969bae Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 9 Feb 2025 19:14:33 -0500 Subject: [PATCH] progress on collaping arena->allocator info code paths (did some generic selection changes) Going to offload prefix naming to the c11.refactor and cpp17.refactor --- bin/.clang-format | 2 +- code/base/arena.c | 4 +- code/base/arena.h | 4 +- code/base/base_types.h | 60 +++++----- code/base/command_line.c | 8 +- code/base/command_line.h | 8 +- code/base/generic_macros.h | 178 ++++++++++++++++++---------- code/base/logger.c | 4 +- code/base/macros.h | 4 +- code/base/markup.h | 2 +- code/base/math.h | 4 +- code/base/memory_substrate.c | 6 +- code/base/memory_substrate.h | 10 +- code/base/strings.c | 131 ++++++++++---------- code/base/strings.h | 142 +++++++++++++--------- code/base/thread_context.h | 22 +++- code/mdesk/mdesk.c | 16 +-- code/mdesk/mdesk.h | 4 +- code/os/os.c | 10 +- code/os/os.h | 4 +- code/os/win32/os_win32.c | 58 ++++----- code/os/win32/os_win32.h | 6 +- third_party/gencpp_c11/gencpp_c11.h | 6 +- 23 files changed, 403 insertions(+), 290 deletions(-) diff --git a/bin/.clang-format b/bin/.clang-format index b30a8c8..4ff0d81 100644 --- a/bin/.clang-format +++ b/bin/.clang-format @@ -9,7 +9,7 @@ StatementMacros: [ MD_NS_END, MD_API_C_BEGIN, MD_API_C_END, - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT + if_generic_selector_defined_include_slot ] Macros: - enum_underlying(type)=type diff --git a/code/base/arena.c b/code/base/arena.c index f06a0db..8d1ed3c 100644 --- a/code/base/arena.c +++ b/code/base/arena.c @@ -12,8 +12,10 @@ //- rjf: arena creation/destruction Arena* -arena__alloc(ArenaParams params) +arena__alloc(ArenaParams* optional_params) { + ArenaParams params = optional_params ? *optional_params : (ArenaParams){0}; + SPTR const varena_header_size = align_pow2(size_of(VArena), MD_DEFAULT_MEMORY_ALIGNMENT); SPTR const header_size = align_pow2(size_of(Arena), MD_DEFAULT_MEMORY_ALIGNMENT); diff --git a/code/base/arena.h b/code/base/arena.h index 0b14182..347208b 100644 --- a/code/base/arena.h +++ b/code/base/arena.h @@ -81,8 +81,8 @@ extract_arena(AllocatorInfo ainfo) { //- rjf: arena creation/destruction -MD_API Arena* arena__alloc(ArenaParams params); -#define arena_alloc(...) arena__alloc( (ArenaParams){ __VA_ARGS__ } ) +MD_API Arena* arena__alloc(ArenaParams* params); +#define arena_alloc(...) arena__alloc( &(ArenaParams){ __VA_ARGS__ } ) void arena_release(Arena *arena); diff --git a/code/base/base_types.h b/code/base/base_types.h index 7c64ac2..6c48d25 100644 --- a/code/base/base_types.h +++ b/code/base/base_types.h @@ -3,38 +3,39 @@ # include "context_cracking.h" # include "linkage.h" # include "macros.h" +# include "generic_macros.h" # include "platform.h" #endif #if defined( COMPILER_MSVC ) # if _MSC_VER < 1300 -typedef unsigned char U8; -typedef signed char S8; -typedef unsigned short U16; -typedef signed short S16; -typedef unsigned int U32; -typedef signed int S32; +typedef distinct(unsigned char, U8); +typedef distinct(signed char, S8); +typedef distinct(unsigned short, U16); +typedef distinct(signed short, S16); +typedef distinct(unsigned int, U32); +typedef distinct(signed int, S32); # else -typedef unsigned __int8 U8; -typedef signed __int8 S8; -typedef unsigned __int16 U16; -typedef signed __int16 S16; -typedef unsigned __int32 U32; -typedef signed __int32 S32; +typedef distinct(unsigned __int8, U8); +typedef distinct(signed __int8, S8); +typedef distinct(unsigned __int16, U16); +typedef distinct(signed __int16, S16); +typedef distinct(unsigned __int32, U32); +typedef distinct(signed __int32, S32); # endif -typedef unsigned __int64 U64; -typedef signed __int64 S64; +typedef distinct(unsigned __int64, U64); +typedef distinct(signed __int64, S64); #else # include -typedef uint8_t U8; -typedef int8_t S8; -typedef uint16_t U16; -typedef int16_t S16; -typedef uint32_t U32; -typedef int32_t S32; -typedef uint64_t U64; -typedef int64_t S64; +typedef distinct(uint8_t, U8); +typedef distinct(int8_t, S8); +typedef distinct(uint16_t, U16); +typedef distinct(int16_t, S16); +typedef distinct(uint32_t, U32); +typedef distinct(int32_t, S32); +typedef distinct(uint64_t, U64); +typedef distinct(int64_t, S64); #endif typedef struct U128 U128; @@ -52,8 +53,8 @@ static_assert( sizeof( U16 ) == 2, "sizeof(U16) != 2" ); static_assert( sizeof( U32 ) == 4, "sizeof(U32) != 4" ); static_assert( sizeof( U64 ) == 8, "sizeof(U64) != 8" ); -typedef size_t USIZE; -typedef ptrdiff_t SSIZE; +typedef distinct(size_t, USIZE); +typedef distinct(ptrdiff_t, SSIZE); static_assert( sizeof( USIZE ) == sizeof( SSIZE ), "sizeof(USIZE) != sizeof(SSIZE)" ); @@ -83,17 +84,18 @@ typedef intptr_t SPTR; static_assert( sizeof( UPTR ) == sizeof( SPTR ), "sizeof(UPTR) != sizeof(SPTR)" ); -typedef float F32; -typedef double F64; +typedef distinct(float, F32); +typedef distinct(double, F64); static_assert( sizeof( F32 ) == 4, "sizeof(F32) != 4" ); static_assert( sizeof( F64 ) == 8, "sizeof(F64) != 8" ); -typedef S8 B8; -typedef S16 B16; -typedef S32 B32; +typedef distinct(S8, B8); +typedef distinct(S16, B16); +typedef distinct(S32, B32); typedef void VoidProc(void); +typedef_generic_selector(VoidProc); //////////////////////////////// //~ NOTE(allen): Constants diff --git a/code/base/command_line.c b/code/base/command_line.c index 45fdcd0..c237805 100644 --- a/code/base/command_line.c +++ b/code/base/command_line.c @@ -49,7 +49,7 @@ cmd_line_insert_opt_alloc(AllocatorInfo ainfo, CmdLine* cmd_line, String8 string var = alloc_array(ainfo, CmdLineOpt, 1); var->hash_next = *slot; var->hash = cmd_line_hash_from_string(string); - var->string = alloc_str8_copy(ainfo, string); + var->string = str8_copy(ainfo, string); var->value_strings = values; StringJoin join = {0}; @@ -57,7 +57,7 @@ cmd_line_insert_opt_alloc(AllocatorInfo ainfo, CmdLine* cmd_line, String8 string join.sep = str8_lit(","); join.post = str8_lit(""); - var->value_string = str8_list_join_alloc(ainfo, &var->value_strings, &join); + var->value_string = str8_list_join(ainfo, &var->value_strings, &join); *slot = var; cmd_line_push_opt(&cmd_line->options, var); } @@ -139,9 +139,9 @@ cmd_line_from_string_list_alloc(AllocatorInfo ainfo, String8List command_line) } U8 splits[] = { ',' }; - String8List args_in_this_string = str8_split_alloc(ainfo, string, splits, array_count(splits), 0); + String8List args_in_this_string = str8_split(ainfo, string, splits, array_count(splits), 0); for (String8Node* sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next) { - str8_list_alloc(ainfo, &arguments, sub_arg->string); + str8_list(ainfo, &arguments, sub_arg->string); } if ( !str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) && (n != node || arg_portion_this_string.size != 0)) { break; diff --git a/code/base/command_line.h b/code/base/command_line.h index c475c05..7698faa 100644 --- a/code/base/command_line.h +++ b/code/base/command_line.h @@ -61,15 +61,15 @@ MD_API CmdLine cmd_line_from_string_list_alloc(AllocatorInfo ainfo, String8 _Generic(allocator, \ Arena*: cmd_line_insert_opt_push, \ AllocatorInfo: cmd_line_insert_opt_alloc, \ - default: MD_generic_selection_fail \ -) MD_RESOLVED_FUNCTION_CALL(allocator, cmd_line, string, values) + default: assert_generic_selection_fail \ +) resolved_function_call(allocator, cmd_line, string, values) #define cmd_line_from_string_list(allocator, arguments) \ _Generic(allocator, \ Arena*: cmd_line_from_string_list_push, \ AllocatorInfo: cmd_line_from_string_list_alloc, \ - default: MD_generic_selection_fail \ -) MD_RESOLVED_FUNCTION_CALL(allocator, arguments) + default: assert_generic_selection_fail \ +) resolved_function_call(allocator, arguments) inline U64 cmd_line_hash_from_string(String8 string) { diff --git a/code/base/generic_macros.h b/code/base/generic_macros.h index d6dfec1..3c6d7bc 100644 --- a/code/base/generic_macros.h +++ b/code/base/generic_macros.h @@ -1,3 +1,8 @@ +#ifdef INTELLISENSE_DIRECTIVES +# pragma once +// NOTE(Ed): For C++ generation, this file will not be injected, any macros that are used will either be injected as transparent defines +// or have their usage removed during the library generation pass. +#endif #pragma region _Generic Macros // ____ _ ______ _ _ ____ _ __ _ @@ -10,49 +15,59 @@ // https://github.com/JacksonAllan/CC/blob/main/articles/Better_C_Generics_Part_1_The_Extendible_Generic.md {___/ // It was choosen over the more novel implementations to keep the macros as easy to understand and unobfuscated as possible. // -------------------------------------------------------------------------------------------------------------------------------------------- -// NOTE: For explanation of intended usage with staged metaprogramming see: https://github.com/Ed94/gencpp/tree/main/gen_c_library#macro-usage +// For explanation of intended usage with staged metaprogramming see: https://github.com/Ed94/gencpp/tree/main/gen_c_library#macro-usage +// Techncially this can be used for more than just implementing function overloading. +// Additional info: https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/ // -------------------------------------------------------------------------------------------------------------------------------------------- -#define MD_COMMA_OPERATOR , // The comma operator is used by preprocessor macros to delimit arguments, so we have to represent it via a macro to prevent parsing incorrectly. +#ifndef COMMA_OPERATOR +#define COMMA_OPERATOR , // The comma operator is used by preprocessor macros to delimit arguments, so we have to represent it via a macro to prevent parsing incorrectly. +#endif // Helper macros for argument selection -#define MD_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1. -#define MD_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2. -#define MD_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc.. +#ifndef select_arg_1 +#define select_arg_1( _1, ... ) _1 // <-- Of all th args passed pick _1. +#define select_arg_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2. +#define select_arg_3( _1, _2, _3, ... ) _3 // etc.. -#define MD_GENERIC_SEL_ENTRY_TYPE MD_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type. -#define MD_GENERIC_SEL_ENTRY_FUNCTION MD_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function. -#define MD_GENERIC_SEL_ENTRY_COMMA_DELIMITER MD_SELECT_ARG_3 // Use the arg expansion macro to select arg 3 which should have the comma delimiter ','. +#define generic_sel_entry_type select_arg_1 // Use the arg expansion macro to select arg 1 which should have the type. +#define generic_sel_entry_function select_arg_2 // Use the arg expansion macro to select arg 2 which should have the function. +#define generic_sel_entry_comma_delimiter select_arg_3 // Use the arg expansion macro to select arg 3 which should have the comma delimiter ','. +#endif -#define MD_RESOLVED_FUNCTION_CALL // Just used to indicate where the call "occurs" +#ifndef resolved_function_call +#define resolved_function_call // Just used to indicate where the call "occurs" +#endif // ---------------------------------------------------------------------------------------------------------------------------------- -// MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( macro ) includes a _Generic slot only if the specified macro is defined (as type, function_name). +#ifndef if_generic_selector_defined_include_slot +// if_generic_selector_defined_include_slot( macro ) includes a _Generic slot only if the specified macro is defined (as type, function_name). // It takes advantage of the fact that if the macro is defined, then the expanded text will contain a comma. // Expands to ',' if it can find (type): (function) -// Where MD_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that , -#define MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) MD_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, MD_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): MD_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) MD_COMMA_OPERATOR, , ) -// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma +// Where generic_sel_entry_comma_delimiter is specifically looking for that , +#define if_generic_selector_defined_include_slot( slot_exp ) generic_sel_entry_comma_delimiter( slot_exp, generic_sel_entry_type( slot_exp, ): generic_sel_entry_function( slot_exp, ) COMMA_OPERATOR, , ) +// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma // The slot won't exist if that comma is not found. +#endif // For the occastion where an expression didn't resolve to a selection option the "default: " will be set to: -typedef struct METADESK_UNRESOLVED_GENERIC_SELECTION METADESK_UNRESOLVED_GENERIC_SELECTION; -struct METADESK_UNRESOLVED_GENERIC_SELECTION { +typedef struct UNRESOLVED_GENERIC_SELECTION UNRESOLVED_GENERIC_SELECTION; +struct UNRESOLVED_GENERIC_SELECTION { void* _THE_VOID_SLOT_; }; -METADESK_UNRESOLVED_GENERIC_SELECTION const MD_generic_selection_fail = {0}; +UNRESOLVED_GENERIC_SELECTION const assert_generic_selection_fail = {0}; // Which will provide the message: error: called object type 'struct NO_RESOLVED_GENERIC_SELECTION' is not a function or function pointer // ---------------------------------------------------------------------------------------------------------------------------------- // Below are generated on demand for an overlaod depdendent on a type: // ---------------------------------------------------------------------------------------------------------------------------------- -#define MD_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \ -(selector_arg), /* Select Via Expression*/ \ - /* Extendibility slots: */ \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \ - default: MD_generic_selection_fail \ -) MD_RESOLVED_FUNCTION_CALL( selector_arg ) +#define function_generic_example( selector_arg ) _Generic( \ +(selector_arg), /* Select Via Expression*/ \ + /* Extendibility slots: */ \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_1__function_sig ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \ + default: assert_generic_selection_fail \ +) resolved_function_call( selector_arg ) // ---------------------------------------------------------------------------------------------------------------------------------- // Then each definiton of a function has an associated define: @@ -64,56 +79,97 @@ METADESK_UNRESOLVED_GENERIC_SELECTION const MD_generic_selection_fail = {0}; // Concrete example: // To add support for long: -#define GENERIC_SLOT_1_MD_example_hash long, MD_example_hash__P_long -size_t MD_example_hash__P_long( long val ) { return val * 2654435761ull; } +#define GENERIC_SLOT_1__example_hash long, example_hash__P_long +size_t example_hash__P_long( long val ) { return val * 2654435761ull; } // To add support for long long: -#define GENERIC_SLOT_2_MD_example_hash long long, MD_example_hash__P_long_long -size_t MD_example_hash__P_long_long( long long val ) { return val * 2654435761ull; } +#define GENERIC_SLOT_2__example_hash long long, example_hash__P_long_long +size_t example_hash__P_long_long( long long val ) { return val * 2654435761ull; } // If using an Editor with support for syntax hightlighting macros: -// GENERIC_SLOT_1_MD_example_hash and GENERIC_SLOT_2_MD_example_hash should show color highlighting indicating the slot is enabled, +// GENERIC_SLOT_1__example_hash and GENERIC_SLOT_2__example_hash should show color highlighting indicating the slot is enabled, // or, "defined" for usage during the compilation pass that handles the _Generic instrinsic. -#define MD_hash_example( function_arguments ) _Generic( \ -(function_arguments), /* Select Via Expression*/ \ - /* Extendibility slots: */ \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1_MD_example_hash ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2_MD_example_hash ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_3_MD_example_hash ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_4_MD_example_hash ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_5_MD_example_hash ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_6_MD_example_hash ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_7_MD_example_hash ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_8_MD_example_hash ) \ - default: MD_generic_selection_fail \ -) MD_RESOLVED_FUNCTION_CALL( function_arguments ) +#define hash_example( function_arguments ) _Generic( \ +(function_arguments), /* Select Via Expression*/ \ + /* Extendibility slots: */ \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_1__example_hash ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_2__example_hash ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_3__example_hash ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_4__example_hash ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_5__example_hash ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_6__example_hash ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_7__example_hash ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_8__example_hash ) \ + default: assert_generic_selection_fail \ +) resolved_function_call( function_arguments ) // Additional Variations: // If the function takes more than one argument the following is used: -#define MD_FUNCTION_GENERIC_EXAMPLE_VARADIC( selector_arg, ... ) _Generic( \ -(selector_arg), \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \ - /* ... */ \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(GENERIC_SLOT_N__function_sig ) \ - default: MD_generic_selection_fail \ -) MD_RESOLVED_FUNCTION_CALL( selector_arg, __VA_ARG__ ) +#define function_generic_example_varadic( selector_arg, ... ) _Generic( \ +(selector_arg), \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_1__function_sig ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \ + /* ... */ \ + if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \ + default: assert_generic_selection_fail \ +) resolved_function_call( selector_arg, __VA_ARG__ ) // If the function does not take the arugment as a parameter: -#define MD_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( selector_arg ) _Generic( \ -( MD_TYPE_TO_EXP(selector_arg) ), \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \ - /* ... */ \ - MD_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(GENERIC_SLOT_N__function_sig ) \ - default: MD_generic_selection_fail \ -) MD_RESOLVED_FUNCTION_CALL() +#define function_generic_example_direct_type( selector_arg ) _Generic( \ +( type_to_expression(selector_arg) ), \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_1__function_sig ) \ + if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \ + /* ... */ \ + if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \ + default: assert_generic_selection_fail \ +) resolved_function_call() + +#ifndef type_to_expression // Used to keep the _Generic keyword happy as bare types are not considered "expressions" -#define MD_TYPE_TO_EXP(type) (* (type*)NULL) -// Instead of using this macro, you'll see it directly expanded by the code generation. +#define type_to_expression(type) (* (type*)NULL) +#endif +// Instead of using this macro, it should be directly expanded by code generation. -// typedef void* MD_GenericExampleType; -// MD_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( MD_GenericExampleType ); +// _Generic also suffers from type compability flatting distinctions between typedef by resolving the selection to the underling type and qualifier. +// To resolve this these distinctions must be enforced using structs that enforce the typedef + +#ifndef distinct_register_selector +// Will define the metadata struct for generic selection usage with the distinct_lookup function macro +// Generally does not need to be used unless getting an error similar to: "_Generic association compatible with previous association type" +#define distinct_register_selector(type) typedef struct { type* UNUSED__; } Generic_Enforce__ ## type +#endif + +#ifndef distinct_lookup +// This is used by a generic selector to lookup a unique struct typeid of a typedef if distinct_register_selector function macro was utilized +// Only necessary to use with _Generic if getting an error similar to: "_Generic association compatible with previous association type" +#define distinct_lookup(type) Generic_Enforce__ ## type +#endif + +// Example: ------------------------------------------------------------------------------------------------------------------------- +// Now this can work so long as typedef_generic_selector was used on the S64 && SSIZE typedefs +#define do_something_with(selector_arg, in) _Generic( \ +(selector_arg), \ + distinct_lookup(S64) : do_something_with_s64, default: assert_generic_selection_fail, \ + distinct_lookup(SSIZE): do_something_with_ssize, default: assert_generic_selection_fail, \ + default : assert_generic_selection_fail \ +) resolved_function_call(selector_arg) +// ---------------------------------------------------------------------------------------------------------------------------------- + +#ifndef distinct +// Can inlay with typedef and a distinct_register_selector. Usage: typedef distinct(int, SomeType); +// Generally does not need to be used unless getting an error similar to: "_Generic association compatible with previous association type" +// Use distinct_lookup, to resolve the distinct type for the generic selection entry. +#define distinct(underlying_type, type) underlying_type type; distinct_register_selector(type) +#endif + +// Removing example definitions +#undef function_generic_example +#undef GENERIC_SLOT_1__example_hash +#undef GENERIC_SLOT_2__example_hash +#undef hash_example +#undef function_generic_example_varadic +#undef function_generic_example_direct_type +#undef do_something_with #pragma endregion _Generic Macros diff --git a/code/base/logger.c b/code/base/logger.c index 31c79d5..72af63b 100644 --- a/code/base/logger.c +++ b/code/base/logger.c @@ -28,7 +28,7 @@ log_select(Log* log) { void log_msg(LogMsgKind kind, String8 string) { if(log_active != 0 && log_active->top_scope != 0) { - String8 string_copy = push_str8_copy(log_active->arena, string); + String8 string_copy = str8_copy(log_active->arena, string); str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy); } } @@ -41,7 +41,7 @@ log_msgf(LogMsgKind kind, char *fmt, ...) { va_list args; va_start(args, fmt); - String8 string = push_str8fv(scratch.arena, fmt, args); + String8 string = str8fv(scratch.arena, fmt, args); log_msg(kind, string); va_end(args); diff --git a/code/base/macros.h b/code/base/macros.h index cc9b996..e3ae984 100644 --- a/code/base/macros.h +++ b/code/base/macros.h @@ -151,8 +151,8 @@ #endif #ifndef glue -#define glue_(A,B) A ## B -#define glue(A,B) glue_(A,B) +#define glue_(A, B) A ## B +#define glue(A, B) glue_(A,B) #endif #define src_line_str stringify(__LINE__) diff --git a/code/base/markup.h b/code/base/markup.h index 4a14b67..268d808 100644 --- a/code/base/markup.h +++ b/code/base/markup.h @@ -17,7 +17,7 @@ set_thread_namef(char *fmt, ...) va_list args; va_start(args, fmt); - String8 string = push_str8fv(scratch.arena, fmt, args); + String8 string = str8fv(scratch.arena, fmt, args); set_thread_name(string); va_end(args); diff --git a/code/base/math.h b/code/base/math.h index de456dd..66aeee4 100644 --- a/code/base/math.h +++ b/code/base/math.h @@ -972,8 +972,8 @@ void rng1s64_list_push__ainfo (AllocatorInfo ainfo, Rng1S64Lis Rng1S64Array rng1s64_array_from_list_push__arena(Arena* arena, Rng1S64List* list); Rng1S64Array rng1s64_array_from_list_push__ainfo(AllocatorInfo ainfo, Rng1S64List* list); -#define rng1s64_list_push(allocator, list, rng) _Generic(allocator, Arena*: rng1s64_list_push__arena, AllocatorInfo: rng1s64_list_push__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, rng) -#define rng1s64_array_from_list_push(allocator, list) _Generic(allocator, Arena*: rng1s64_array_from_list_push__arena, AllocatorInfo: rng1s64_array_from_list_push__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list) +#define rng1s64_list_push(allocator, list, rng) _Generic(allocator, Arena*: rng1s64_list_push__arena, AllocatorInfo: rng1s64_list_push__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, rng) +#define rng1s64_array_from_list_push(allocator, list) _Generic(allocator, Arena*: rng1s64_array_from_list_push__arena, AllocatorInfo: rng1s64_array_from_list_push__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list) force_inline void rng1s64_list_push__arena (Arena* arena, Rng1S64List* list, Rng1S64 rng) { rng1s64_list_push__ainfo (arena_allocator(arena), list, rng); } force_inline Rng1S64Array rng1s64_array_from_list_push__arena(Arena* arena, Rng1S64List* list) { return rng1s64_array_from_list_push__ainfo(arena_allocator(arena), list); } diff --git a/code/base/memory_substrate.c b/code/base/memory_substrate.c index 1042f8e..57ff219 100644 --- a/code/base/memory_substrate.c +++ b/code/base/memory_substrate.c @@ -200,7 +200,7 @@ heap_allocator_proc( void* allocator_data, AllocatorMode mode, SSIZE size, SSIZE case AllocatorMode_QuerySupport: return (void*) ( - AllocatorQuery_Alloc | AllocatorQuery_Free | AllocatorQuery_Resize + AllocatorQuery_Alloc | AllocatorQuery_Free | AllocatorQuery_Resize | AllocatorQuery_ResizeGrow | AllocatorQuery_ResizeShrink ); } @@ -404,8 +404,8 @@ varena_allocator_proc(void* allocator_data, AllocatorMode mode, SSIZE requested_ case AllocatorMode_QuerySupport: { - return (void*) (AllocatorQuery_Alloc | AllocatorQuery_FreeAll | AllocatorQuery_Resize - // | AllocatorQuery_Pop | AllocatorQuery_Pop_To + return (void*) ( + AllocatorQuery_Alloc | AllocatorQuery_FreeAll | AllocatorQuery_Resize | AllocatorQuery_ResizeGrow | AllocatorQuery_ResizeShrink ); } break; diff --git a/code/base/memory_substrate.h b/code/base/memory_substrate.h index f95fa86..c0f3944 100644 --- a/code/base/memory_substrate.h +++ b/code/base/memory_substrate.h @@ -42,10 +42,12 @@ enum AllocatorMode typedef U64 AllocatorQueryFlags; enum { - AllocatorQuery_Alloc = (1 << 0), - AllocatorQuery_Free = (1 << 1), - AllocatorQuery_FreeAll = (1 << 2), - AllocatorQuery_Resize = (1 << 3), + AllocatorQuery_Alloc = (1 << 0), + AllocatorQuery_Free = (1 << 1), + AllocatorQuery_FreeAll = (1 << 2), + AllocatorQuery_Resize = (1 << 3), // Supports both grow and shrink + AllocatorQuery_ResizeShrink = (1 << 4), + AllocatorQuery_ResizeGrow = (1 << 5), }; typedef void*(AllocatorProc)( void* allocator_data, AllocatorMode type, SSIZE size, SSIZE alignment, void* old_memory, SSIZE old_size, U64 flags ); diff --git a/code/base/strings.c b/code/base/strings.c index ae56fa0..dc0c47f 100644 --- a/code/base/strings.c +++ b/code/base/strings.c @@ -239,19 +239,19 @@ try_u64_from_str8_c_rules(String8 string, U64 *x) //- rjf: integer -> string String8 -str8_from_memory_size__ainfo(AllocatorInfo ainfo, U64 z) { +str8_from_memory_size__ainfo(AllocatorInfo ainfo, SSIZE z) { String8 result = {0}; if (z < KB(1)) { result = str8f(ainfo, "%llu b", z); } else if (z < MB(1)) { - result = str8f(ainfo, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100); + result = str8f(ainfo, "%llu.%02llu Kb", z / KB(1), ((100 * z) / KB(1)) % 100); } else if (z < GB(1)) { - result = str8f(ainfo, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100); + result = str8f(ainfo, "%llu.%02llu Mb", z / MB(1), ((100 * z) / MB(1)) % 100); } else{ - result = str8f(ainfo, "%llu.%02llu Gb", z/GB(1), ((100*z)/GB(1))%100); + result = str8f(ainfo, "%llu.%02llu Gb", z / GB(1), ((100 * z) / GB(1)) % 100); } return(result); } @@ -503,9 +503,12 @@ str8_split__ainfo(AllocatorInfo ainfo, String8 string, U8* split_chars, U64 spli } String8 -str8_list_join__ainfo(AllocatorInfo ainfo, String8List* list, StringJoin optional_params) +str8_list_join__ainfo(AllocatorInfo ainfo, String8List* list, StringJoin* optional_params) { - StringJoin join = optional_params; + StringJoin join = {0}; + if (optional_params != nullptr) { + memory_copy_struct(&join, optional_params); + } U64 sep_count = 0; if (list->node_count > 0){ sep_count = list->node_count - 1; @@ -690,10 +693,8 @@ str8_path_list_resolve_dots_in_place(String8List* path, PathStyle style) scratch_end(scratch); } -force_inline String8 str8_path_list_join_by_style(Arena* arena, String8List* path, PathStyle style) { return str8_path_list_join_by_style_alloc(arena_allocator(arena), path, style); } - String8 -str8_path_list_join_by_style_alloc(AllocatorInfo ainfo, String8List* path, PathStyle style) { +str8_path_list_join_by_style__ainfo(AllocatorInfo ainfo, String8List* path, PathStyle style) { StringJoin params = {0}; switch (style) { @@ -711,7 +712,7 @@ str8_path_list_join_by_style_alloc(AllocatorInfo ainfo, String8List* path, PathS } break; } - String8 result = str8_list_join_alloc(ainfo, path, ¶ms); + String8 result = str8_list_join(ainfo, path, ¶ms ); return(result); } @@ -842,7 +843,7 @@ utf16_encode(U16* str, U32 codepoint) { // NOTE(Ed): These utilize arena's pop rewinding, so we'll keep the codepath diverged from _alloc paths String8 -str8_from_16(Arena* arena, String16 in) { +str8_from_str16__arena(Arena* arena, String16 in) { U64 cap = in.size * 3; U8* str = push_array_no_zero(arena, U8, cap + 1); U16* ptr = in.str; @@ -859,7 +860,7 @@ str8_from_16(Arena* arena, String16 in) { } String16 -str16_from_8(Arena* arena, String8 in) { +str16_from_str8__arena(Arena* arena, String8 in) { U64 cap = in.size * 2; U16* str = push_array_no_zero(arena, U16, cap + 1); U8* ptr = in.str; @@ -876,7 +877,7 @@ str16_from_8(Arena* arena, String8 in) { } String8 -str8_from_32(Arena *arena, String32 in){ +str8_from_str32__arena(Arena* arena, String32 in){ U64 cap = in.size * 4; U8* str = push_array_no_zero(arena, U8, cap + 1); U32* ptr = in.str; @@ -891,7 +892,7 @@ str8_from_32(Arena *arena, String32 in){ } String32 -str32_from_8(Arena *arena, String8 in){ +str32_from_str8__arena(Arena* arena, String8 in){ U64 cap = in.size; U32* str = push_array_no_zero(arena, U32, cap + 1); U8* ptr = in.str; @@ -909,7 +910,7 @@ str32_from_8(Arena *arena, String8 in){ } String8 -str8_from_16_alloc(AllocatorInfo ainfo, String16 in) { +str8_from_str16__ainfo(AllocatorInfo ainfo, String16 in) { U64 cap = in.size * 3; U8* str = alloc_array_no_zero(ainfo, U8, cap + 1); U16* ptr = in.str; @@ -921,12 +922,14 @@ str8_from_16_alloc(AllocatorInfo ainfo, String16 in) { size += utf8_encode(str + size, consume.codepoint); } str[size] = 0; - resize(ainfo, str, cap + 1, (cap - size)); + if (allocator_query_support(ainfo) & AllocatorQuery_ResizeShrink) { + resize(ainfo, str, cap + 1, (cap - size)); + } return(str8(str, size)); } String16 -str16_from_8_alloc(AllocatorInfo ainfo, String8 in) { +str16_from_str8__ainfo(AllocatorInfo ainfo, String8 in) { U64 cap = in.size * 2; U16* str = alloc_array_no_zero(ainfo, U16, cap + 1); U8* ptr = in.str; @@ -938,12 +941,14 @@ str16_from_8_alloc(AllocatorInfo ainfo, String8 in) { size += utf16_encode(str + size, consume.codepoint); } str[size] = 0; - resize(ainfo, str, cap + 1, (cap - size)); + if (allocator_query_support(ainfo) & AllocatorQuery_ResizeShrink) { + resize(ainfo, str, cap + 1, (cap - size)); + } return(str16(str, size)); } String8 -str8_from_32_alloc(AllocatorInfo ainfo, String32 in){ +str8_from_str32__ainfo(AllocatorInfo ainfo, String32 in){ U64 cap = in.size * 4; U8* str = alloc_array_no_zero(ainfo, U8, cap + 1); U32* ptr = in.str; @@ -953,12 +958,14 @@ str8_from_32_alloc(AllocatorInfo ainfo, String32 in){ size += utf8_encode(str + size, *ptr); } str[size] = 0; - resize(ainfo, str, cap + 1, (cap - size)); + if (allocator_query_support(ainfo) & AllocatorQuery_ResizeShrink) { + resize(ainfo, str, cap + 1, (cap - size)); + } return(str8(str, size)); } String32 -str32_from_8_alloc(AllocatorInfo ainfo, String8 in){ +str32_from_str8__ainfo(AllocatorInfo ainfo, String8 in){ U64 cap = in.size; U32* str = alloc_array_no_zero(ainfo, U32, cap + 1); U8* ptr = in.str; @@ -971,7 +978,9 @@ str32_from_8_alloc(AllocatorInfo ainfo, String8 in){ size += 1; } str[size] = 0; - resize(ainfo, str, cap + 1, (cap - size)); + if (allocator_query_support(ainfo) & AllocatorQuery_ResizeShrink) { + resize(ainfo, str, cap + 1, (cap - size)); + } return(str32(str, size)); } @@ -1013,7 +1022,7 @@ force_inline String8 push_file_name_date_time_string(Arena* arena, DateTime* dat force_inline String8 string_from_elapsed_time (Arena* arena, DateTime dt) { return string_from_elapsed_time_alloc (arena_allocator(arena), dt); } String8 -alloc_date_time_string(AllocatorInfo ainfo, DateTime* date_time) { +date_time_string__ainfo(AllocatorInfo ainfo, DateTime* date_time) { char* mon_str = (char*)string_from_month(date_time->month).str; U32 adjusted_hour = date_time->hour % 12; @@ -1026,7 +1035,7 @@ alloc_date_time_string(AllocatorInfo ainfo, DateTime* date_time) { ampm = "pm"; } - String8 result = alloc_str8f(ainfo, + String8 result = str8f(ainfo, "%d %s %d, %02d:%02d:%02d %s", date_time->day, mon_str, date_time->year, adjusted_hour, date_time->min, date_time->sec, ampm @@ -1035,10 +1044,10 @@ alloc_date_time_string(AllocatorInfo ainfo, DateTime* date_time) { } String8 -alloc_file_name_date_time_string(AllocatorInfo ainfo, DateTime* date_time) { +file_name_date_time_string__ainfo(AllocatorInfo ainfo, DateTime* date_time) { char* mon_str = (char*)string_from_month(date_time->month).str; - String8 result = alloc_str8f(ainfo, + String8 result = str8f(ainfo, "%d-%s-%0d--%02d-%02d-%02d", date_time->year, mon_str, date_time->day, date_time->hour, date_time->min, date_time->sec @@ -1047,8 +1056,8 @@ alloc_file_name_date_time_string(AllocatorInfo ainfo, DateTime* date_time) { } String8 -string_from_elapsed_time_alloc(AllocatorInfo ainfo, DateTime dt) { - TempArena scratch = scratch_begin_alloc(ainfo); +string_from_elapsed_time__ainfo(AllocatorInfo ainfo, DateTime dt) { + TempArena scratch = scratch_begin(ainfo); String8List list = {0}; if (dt.year) { @@ -1064,15 +1073,15 @@ string_from_elapsed_time_alloc(AllocatorInfo ainfo, DateTime dt) { str8_list_pushf(scratch.arena, &list, "%u:%u:%u:%u ms", dt.hour, dt.min, dt.sec, dt.msec); StringJoin join = { str8_lit_comp(""), str8_lit_comp(" "), str8_lit_comp("") }; - String8 result = str8_list_join_alloc(ainfo, &list, &join); + String8 result = str8_list_join(ainfo, &list, &join); return(result); } //////////////////////////////// -//~ Globally UNique Ids +//~ Globally Unique Ids B32 -try_guid_from_string(String8 string, Guid *guid_out) +try_guid_from_string(String8 string, Guid* guid_out) { TempArena scratch = scratch_begin(0,0); B32 is_parsed = 0; @@ -1119,12 +1128,12 @@ try_guid_from_string(String8 string, Guid *guid_out) //////////////////////////////// //~ rjf: Basic Text Indentation -force_inline String8 indented_from_string(Arena* arena, String8 string) { return indented_from_string_alloc(arena_allocator(arena), string); } +force_inline String8 indented_from_string__arena(Arena* arena, String8 string) { return indented_from_string_alloc(arena_allocator(arena), string); } String8 -indented_from_string_alloc(AllocatorInfo ainfo, String8 string) +indented_from_string__ainfo(AllocatorInfo ainfo, String8 string) { - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); read_only local_persist U8 indentation_bytes[] = " "; String8List indented_strings = {0}; @@ -1153,7 +1162,7 @@ indented_from_string_alloc(AllocatorInfo ainfo, String8 string) } } - String8 result = str8_list_join_alloc(ainfo, &indented_strings, 0); + String8 result = str8_list_join(ainfo, &indented_strings, 0); scratch_end(scratch); return result; } @@ -1161,13 +1170,13 @@ indented_from_string_alloc(AllocatorInfo ainfo, String8 string) //////////////////////////////// //~ rjf: Text Escaping -force_inline String8 escaped_from_raw_str8(Arena* arena, String8 string) { return escaped_from_raw_str8_alloc(arena_allocator(arena), string); } -force_inline String8 raw_from_escaped_str8(Arena* arena, String8 string) { return raw_from_escaped_str8_alloc(arena_allocator(arena), string); } +force_inline String8 escaped_from_raw_str8__arena(Arena* arena, String8 string) { return escaped_from_raw_str8_alloc(arena_allocator(arena), string); } +force_inline String8 raw_from_escaped_str8__arena(Arena* arena, String8 string) { return raw_from_escaped_str8_alloc(arena_allocator(arena), string); } String8 -escaped_from_raw_str8_alloc(AllocatorInfo ainfo, String8 string) +escaped_from_raw_str8__ainfo(AllocatorInfo ainfo, String8 string) { - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); String8List parts = {0}; U64 start_split_idx = 0; @@ -1204,16 +1213,16 @@ escaped_from_raw_str8_alloc(AllocatorInfo ainfo, String8 string) } StringJoin join = {0}; - String8 result = str8_list_join_alloc(ainfo, &parts, &join); + String8 result = str8_list_join(ainfo, &parts, &join); scratch_end(scratch); return result; } String8 -raw_from_escaped_str8_alloc(AllocatorInfo ainfo, String8 string) +raw_from_escaped_str8__ainfo(AllocatorInfo ainfo, String8 string) { - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); String8List strs = {0}; U64 start = 0; @@ -1246,14 +1255,14 @@ raw_from_escaped_str8_alloc(AllocatorInfo ainfo, String8 string) case '?': replace_byte = '?'; break; } - String8 replace_string = push_str8_copy(scratch.arena, str8(&replace_byte, 1)); + String8 replace_string = str8_copy(scratch.arena, str8(&replace_byte, 1)); str8_list_push(scratch.arena, &strs, replace_string); idx += 1; start += 1; } } - String8 result = str8_list_join_alloc(ainfo, &strs, 0); + String8 result = str8_list_join(ainfo, &strs, 0); scratch_end(scratch); return result; } @@ -1261,10 +1270,10 @@ raw_from_escaped_str8_alloc(AllocatorInfo ainfo, String8 string) //////////////////////////////// //~ rjf: Text Wrapping -force_inline String8List wrapped_lines_from_string(Arena* arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent) { return wrapped_lines_from_string_alloc(arena_allocator(arena), string, first_line_max_width, max_width, wrap_indent); } +force_inline String8List wrapped_lines_from_string__arena(Arena* arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent) { return wrapped_lines_from_string_alloc(arena_allocator(arena), string, first_line_max_width, max_width, wrap_indent); } String8List -wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent) +wrapped_lines_from_string__ainfo(AllocatorInfo ainfo, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent) { String8List list = {0}; Rng1U64 line_range = r1u64(0, 0); @@ -1307,7 +1316,7 @@ wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8 string, U64 first_l { String8 line = str8_substr(string, line_range); if (wrapped_indent_level > 0){ - line = alloc_str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line); + line = str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line); } str8_list_alloc(ainfo, &list, line); line_range = r1u64(line_range.max + 1, candidate_line_range.max); @@ -1321,7 +1330,7 @@ wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8 string, U64 first_l if (line_range.min < string.size && line_range.max > line_range.min) { String8 line = str8_substr(string, line_range); if (wrapped_indent_level > 0) { - line = alloc_str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line); + line = str8f(ainfo, "%.*s%S", wrapped_indent_level, spaces, line); } str8_list_alloc(ainfo, &list, line); } @@ -1354,13 +1363,13 @@ rgba_from_hex_string_4f32(String8 hex_string) //////////////////////////////// //~ rjf: String Fuzzy Matching -force_inline FuzzyMatchRangeList fuzzy_match_find (Arena *arena, String8 needle, String8 haystack) { return fuzzy_match_find_alloc (arena_allocator(arena), needle, haystack); } -force_inline FuzzyMatchRangeList fuzzy_match_range_list_copy(Arena* arena, FuzzyMatchRangeList* src) { return fuzzy_match_range_list_copy_alloc(arena_allocator(arena), src); } +force_inline FuzzyMatchRangeList fuzzy_match_find__arena (Arena *arena, String8 needle, String8 haystack) { return fuzzy_match_find_alloc (arena_allocator(arena), needle, haystack); } +force_inline FuzzyMatchRangeList fuzzy_match_range_list_copy__arena(Arena* arena, FuzzyMatchRangeList* src) { return fuzzy_match_range_list_copy_alloc(arena_allocator(arena), src); } FuzzyMatchRangeList -fuzzy_match_find_alloc(AllocatorInfo ainfo, String8 needle, String8 haystack) +fuzzy_match_find__ainfo(AllocatorInfo ainfo, String8 needle, String8 haystack) { - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); String8List needles = str8_split(scratch.arena, needle, (U8*)" ", 1, 0); FuzzyMatchRangeList result = {0}; @@ -1398,7 +1407,7 @@ fuzzy_match_find_alloc(AllocatorInfo ainfo, String8 needle, String8 haystack) } FuzzyMatchRangeList -fuzzy_match_range_list_copy_alloc(AllocatorInfo ainfo, FuzzyMatchRangeList* src) +fuzzy_match_range_list_copy__ainfo(AllocatorInfo ainfo, FuzzyMatchRangeList* src) { FuzzyMatchRangeList dst = {0}; for(FuzzyMatchRangeNode* src_n = src->first; src_n != 0; src_n = src_n->next) @@ -1416,13 +1425,13 @@ fuzzy_match_range_list_copy_alloc(AllocatorInfo ainfo, FuzzyMatchRangeList* src) //////////////////////////////// //~ NOTE(allen): Serialization Helpers -force_inline U64 str8_serial_push_align(Arena* arena, String8List* srl, U64 align) { return str8_serial_alloc_align(arena_allocator(arena), srl, align); } -force_inline void* str8_serial_push_size (Arena* arena, String8List* srl, U64 size) { return str8_serial_alloc_size (arena_allocator(arena), srl, size); } -force_inline void str8_serial_push_u64 (Arena* arena, String8List* srl, U64 x) { str8_serial_alloc_u64(arena_allocator(arena), srl, x); } -force_inline void str8_serial_push_u32 (Arena* arena, String8List* srl, U32 x) { str8_serial_alloc_u32(arena_allocator(arena), srl, x); } +force_inline U64 str8_serial_push_align__arena(Arena* arena, String8List* srl, U64 align) { return str8_serial_alloc_align(arena_allocator(arena), srl, align); } +force_inline void* str8_serial_push_size__arena (Arena* arena, String8List* srl, U64 size) { return str8_serial_alloc_size (arena_allocator(arena), srl, size); } +force_inline void str8_serial_push_u64__arena (Arena* arena, String8List* srl, U64 x) { str8_serial_alloc_u64 (arena_allocator(arena), srl, x); } +force_inline void str8_serial_push_u32__arena (Arena* arena, String8List* srl, U32 x) { str8_serial_alloc_u32 (arena_allocator(arena), srl, x); } U64 -str8_serial_alloc_align(AllocatorInfo ainfo, String8List* srl, U64 align) { +str8_serial_push_align__ainfo(AllocatorInfo ainfo, String8List* srl, U64 align) { assert(is_pow2(align)); U64 pos = srl->total_size; U64 new_pos = align_pow2(pos, align); @@ -1445,7 +1454,7 @@ str8_serial_alloc_align(AllocatorInfo ainfo, String8List* srl, U64 align) { } void* -str8_serial_alloc_size(AllocatorInfo ainfo, String8List* srl, U64 size) { +str8_serial_push_size__ainfo(AllocatorInfo ainfo, String8List* srl, U64 size) { void* result = 0; if(size != 0) { @@ -1464,7 +1473,7 @@ str8_serial_alloc_size(AllocatorInfo ainfo, String8List* srl, U64 size) { } void -str8_serial_alloc_u64(AllocatorInfo ainfo, String8List* srl, U64 x) { +str8_serial_alloc_u64__ainfo(AllocatorInfo ainfo, String8List* srl, U64 x) { U8* buf = alloc_array_no_zero(ainfo, U8, 8); memory_copy(buf, &x, 8); String8* str = &srl->last->string; @@ -1478,7 +1487,7 @@ str8_serial_alloc_u64(AllocatorInfo ainfo, String8List* srl, U64 x) { } void -str8_serial_alloc_u32(AllocatorInfo ainfo, String8List* srl, U32 x) { +str8_serial_alloc_u32__ainfo(AllocatorInfo ainfo, String8List* srl, U32 x) { U8* buf = alloc_array_no_zero(ainfo, U8, 4); memory_copy(buf, &x, 4); String8 *str = &srl->last->string; diff --git a/code/base/strings.h b/code/base/strings.h index 47740b5..043a475 100644 --- a/code/base/strings.h +++ b/code/base/strings.h @@ -322,10 +322,10 @@ MD_API String8 str8_copy__ainfo(AllocatorInfo ainfo, String8 s); MD_API String8 str8fv__ainfo (AllocatorInfo ainfo, char* fmt, va_list args); String8 str8f__ainfo (AllocatorInfo ainfo, char* fmt, ...); -#define str8_cat(allocator, s1, s2) _Generic(allocator, Arena*: str8_cat__arena, AllocatorInfo: str8_cat__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, s1, s2) -#define str8_copy(allocator, s) _Generic(allocator, Arena*: str8_copy__arena, AllocatorInfo: str8_copy__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, s) -#define str8fv(allocator, fmt, args) _Generic(allocator, Arena*: str8fv__arena, AllocatorInfo: str8fv__ainfo , default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, fmt, args) -#define str8f(allocator, fmt, ...) _Generic(allocator, Arena*: str8f__arena, AllocatorInfo: str8f__ainfo , default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, fmt, __VA_ARGS__) +#define str8_cat(allocator, s1, s2) _Generic(allocator, Arena*: str8_cat__arena, AllocatorInfo: str8_cat__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, s1, s2) +#define str8_copy(allocator, s) _Generic(allocator, Arena*: str8_copy__arena, AllocatorInfo: str8_copy__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, s) +#define str8fv(allocator, fmt, args) _Generic(allocator, Arena*: str8fv__arena, AllocatorInfo: str8fv__ainfo , default: assert_generic_selection_fail) resolved_function_call(allocator, fmt, args) +#define str8f(allocator, fmt, ...) _Generic(allocator, Arena*: str8f__arena, AllocatorInfo: str8f__ainfo , default: assert_generic_selection_fail) resolved_function_call(allocator, fmt, __VA_ARGS__) force_inline String8 str8_cat__arena (Arena* arena, String8 s1, String8 s2) { return str8_cat__ainfo (arena_allocator(arena), s1, s2); } force_inline String8 str8_copy__arena(Arena* arena, String8 s) { return str8_copy__ainfo(arena_allocator(arena), s); } @@ -409,9 +409,9 @@ inline String8 upper_from_str8__ainfo (AllocatorInfo ainfo, String8 string) inline String8 lower_from_str8__ainfo (AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_to_lower(string.str[idx]); } return string; } inline String8 backslashed_from_str8__ainfo(AllocatorInfo ainfo, String8 string) { string = str8_copy(ainfo, string); for(U64 idx = 0; idx < string.size; idx += 1) { string.str[idx] = char_is_slash(string.str[idx]) ? '\\' : string.str[idx]; } return string; } -#define upper_from_str8(allocator, string) _Generic(allocator, Arena*: upper_from_str8__arena, AllocatorInfo: upper_from_str8__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, string) -#define lower_from_str8(allocator, string) _Generic(allocator, Arena*: lower_from_str8__arena, AllocatorInfo: lower_from_str8__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, string) -#define backslashed_from_str8(allocator, string) _Generic(allocator, Arena*: backslashed_from_str8__arena, AllocatorInfo: backslashed_from_str8__ainfo , default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, string) +#define upper_from_str8(allocator, string) _Generic(allocator, Arena*: upper_from_str8__arena, AllocatorInfo: upper_from_str8__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string) +#define lower_from_str8(allocator, string) _Generic(allocator, Arena*: lower_from_str8__arena, AllocatorInfo: lower_from_str8__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string) +#define backslashed_from_str8(allocator, string) _Generic(allocator, Arena*: backslashed_from_str8__arena, AllocatorInfo: backslashed_from_str8__ainfo , default: assert_generic_selection_fail) resolved_function_call(allocator, string) //////////////////////////////// //~ rjf: String Matching @@ -447,25 +447,25 @@ MD_API B32 try_u64_from_str8_c_rules(String8 string, U64* x); B32 try_s64_from_str8_c_rules(String8 string, S64* x); //- rjf: integer -> string -String8 str8_from_memory_size__arena(Arena* arena, U64 z); +String8 str8_from_memory_size__arena(Arena* arena, SSIZE z); String8 str8_from_u64__arena (Arena* arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator); String8 str8_from_s64__arena (Arena* arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator); String8 str8_from_bits_u32__arena(Arena* arena, U32 x); String8 str8_from_bits_u64__arena(Arena* arena, U64 x); -MD_API String8 str8_from_memory_size__ainfo(AllocatorInfo ainfo, U64 z); +MD_API String8 str8_from_memory_size__ainfo(AllocatorInfo ainfo, SSIZE z); MD_API String8 str8_from_u64__ainfo (AllocatorInfo ainfo, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator); MD_API String8 str8_from_s64__ainfo (AllocatorInfo ainfo, S64 u64, U32 radix, U8 min_digits, U8 digit_group_separator); String8 str8_from_bits_u32__ainfo(AllocatorInfo ainfo, U32 x); String8 str8_from_bits_u64__ainfo(AllocatorInfo ainfo, U64 x); -#define str8_from_memory_size(allocator, z) _Generic(allocator, Arena*: str8_from_memory_size__arena, AllocatorInfo: str8_from_memory_size__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, z) -#define str8_from_u64(allocator, u64, radix, min_digits, digit_group_separator) _Generic(allocator, Arena*: str8_from_u64__arena, AllocatorInfo: str8_from_u64__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, u64, radix, min_digits, digit_group_separator) -#define str8_from_s64(allocator, s64, radix, min_digits, digit_group_separator) _Generic(allocator, Arena*: str8_from_s64__arena, AllocatorInfo: str8_from_s64__ainfo , default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, s64, radix, min_digits, digit_group_separator) +#define str8_from_memory_size(allocator, z) _Generic(allocator, Arena*: str8_from_memory_size__arena, AllocatorInfo: str8_from_memory_size__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, z) +#define str8_from_u64(allocator, u64, radix, min_digits, digit_group_separator) _Generic(allocator, Arena*: str8_from_u64__arena, AllocatorInfo: str8_from_u64__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, u64, radix, min_digits, digit_group_separator) +#define str8_from_s64(allocator, s64, radix, min_digits, digit_group_separator) _Generic(allocator, Arena*: str8_from_s64__arena, AllocatorInfo: str8_from_s64__ainfo , default: assert_generic_selection_fail) resolved_function_call(allocator, s64, radix, min_digits, digit_group_separator) -force_inline String8 str8_from_memory_size__arena(Arena* arena, U64 z) { return str8_from_memory_size__ainfo(arena_allocator(arena), z); } +force_inline String8 str8_from_memory_size__arena(Arena* arena, SSIZE z) { return str8_from_memory_size__ainfo(arena_allocator(arena), z); } force_inline String8 str8_from_u64__arena (Arena* arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator) { return str8_from_u64__ainfo (arena_allocator(arena), u64, radix, min_digits, digit_group_separator); } force_inline String8 str8_from_s64__arena (Arena* arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator) { return str8_from_s64__ainfo (arena_allocator(arena), s64, radix, min_digits, digit_group_separator); } @@ -644,8 +644,8 @@ str8_list_push_node_front_set_string(String8List* list, String8Node* node, Strin return(node); } -MD_API String8Node* str8_list_aligner__arena(Arena* arena, String8List* list, U64 min, U64 align); -MD_API String8List str8_list_copy__arena (Arena* arena, String8List* list); +String8Node* str8_list_aligner__arena(Arena* arena, String8List* list, U64 min, U64 align); +String8List str8_list_copy__arena (Arena* arena, String8List* list); String8Node* str8_list_push__arena (Arena* arena, String8List* list, String8 string); String8Node* str8_list_push_front__arena (Arena* arena, String8List* list, String8 string); @@ -660,12 +660,12 @@ String8Node* str8_list_push_front__ainfo (AllocatorInfo ainfo, String8List* list String8Node* str8_list_pushf__ainfo (AllocatorInfo ainfo, String8List* list, char* fmt, ...); String8Node* str8_list_push_frontf__ainfo(AllocatorInfo ainfo, String8List* list, char* fmt, ...); -#define str8_list_aligner(allocator, list, min, align) _Generic(allocator, Arena*: str8_list_aligner__arena, AllocatorInfo: str8_list_aligner__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, min, align) -#define str8_list_copy(allocator, list) _Generic(allocator, Arena*: str8_list_copy__arena, AllocatorInfo: str8_list_copy__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list) -#define str8_list_push(allocator, list, string) _Generic(allocator, Arena*: str8_list_push__arena, AllocatorInfo: str8_list_push__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, string) -#define str8_list_push_front(allocator, list, string) _Generic(allocator, Arena*: str8_list_push_front__arena, AllocatorInfo: str8_list_push_front__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, string) -#define str8_list_pushf(allocaotr, list, fmt, ...) _Generic(allocator, Arena*: str8_list_pushf__arena, AllocatorInfo: str8_list_pushf__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, fmt, __VA_ARGS__) -#define str8_list_push_frontf(allocaotr, list, fmt, ...) _Generic(allocator, Arena*: str8_list_push_frontf__arena, AllocatorInfo: str8_list_push_frontf__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, fmt, __VA_ARGS__) +#define str8_list_aligner(allocator, list, min, align) _Generic(allocator, Arena*: str8_list_aligner__arena, AllocatorInfo: str8_list_aligner__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, min, align) +#define str8_list_copy(allocator, list) _Generic(allocator, Arena*: str8_list_copy__arena, AllocatorInfo: str8_list_copy__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list) +#define str8_list_push(allocator, list, string) _Generic(allocator, Arena*: str8_list_push__arena, AllocatorInfo: str8_list_push__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, string) +#define str8_list_push_front(allocator, list, string) _Generic(allocator, Arena*: str8_list_push_front__arena, AllocatorInfo: str8_list_push_front__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, string) +#define str8_list_pushf(allocator, list, fmt, ...) _Generic(allocator, Arena*: str8_list_pushf__arena, AllocatorInfo: str8_list_pushf__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, fmt, __VA_ARGS__) +#define str8_list_push_frontf(allocaotr, list, fmt, ...) _Generic(allocator, Arena*: str8_list_push_frontf__arena, AllocatorInfo: str8_list_push_frontf__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, fmt, __VA_ARGS__) force_inline String8Node* str8_list_ligner__arena (Arena* arena, String8List* list, U64 min, U64 align) { return str8_list_aligner__ainfo (arena_allocator(arena), list, min, align); } force_inline String8List str8_list_copy__arena (Arena* arena, String8List* list) { return str8_list_copy__ainfo (arena_allocator(arena), list); } @@ -687,7 +687,7 @@ str8_list_push_frontf__arena(Arena *arena, String8List *list, char *fmt, ...) { va_list args; va_start(args, fmt); String8 string = str8fv(arena, fmt, args); - String8Node* result = str8_list_front(arena, list, string); + String8Node* result = str8_list_push_front(arena, list, string); va_end(args); return(result); } @@ -711,7 +711,7 @@ str8_list_pushf__ainfo(AllocatorInfo ainfo, String8List* list, char* fmt, ...) { va_list args; va_start(args, fmt); String8 string = str8fv(ainfo, fmt, args); - String8Node* result = str8_list(ainfo, list, string); + String8Node* result = str8_list_push(ainfo, list, string); va_end(args); return(result); } @@ -721,7 +721,7 @@ str8_list_push_frontf__ainfo(AllocatorInfo ainfo, String8List* list, char* fmt, va_list args; va_start(args, fmt); String8 string = str8fv(ainfo, fmt, args); - String8Node* result = str8_list_alloc_front(ainfo, list, string); + String8Node* result = str8_list_push_front(ainfo, list, string); va_end(args); return(result); } @@ -729,7 +729,7 @@ str8_list_push_frontf__ainfo(AllocatorInfo ainfo, String8List* list, char* fmt, //////////////////////////////// //~ rjf: String Splitting & Joining -MD_API String8List str8_split__arena(Arena* arena, String8 string, U8* split_chars, U64 split_char_count, StringSplitFlags flags); + String8List str8_split__arena(Arena* arena, String8 string, U8* split_chars, U64 split_char_count, StringSplitFlags flags); MD_API String8List str8_split__ainfo(AllocatorInfo ainfo, String8 string, U8* split_chars, U64 split_char_count, StringSplitFlags flags); String8List str8_split_by_string_chars__arena (Arena* arena, String8 string, String8 split_chars, StringSplitFlags flags); @@ -737,21 +737,21 @@ String8List str8_split_by_string_chars__ainfo (AllocatorInfo ainfo, String8 String8List str8_list_split_by_string_chars__arena(Arena* arena, String8List list, String8 split_chars, StringSplitFlags flags); String8List str8_list_split_by_string_chars__ainfo(AllocatorInfo ainfo, String8List list, String8 split_chars, StringSplitFlags flags); -MD_API String8 str8_list_join__arena (Arena* arena, String8List* list, StringJoin optional_params); -MD_API String8 str8_list_join__ainfo (AllocatorInfo ainfo, String8List* list, StringJoin optional_params); + String8 str8_list_join__arena (Arena* arena, String8List* list, StringJoin* optional_params); +MD_API String8 str8_list_join__ainfo (AllocatorInfo ainfo, String8List* list, StringJoin* optional_params); void str8_list_from_flags__arena(Arena* arena, String8List* list, U32 flags, String8* flag_string_table, U32 flag_string_count); void str8_list_from_flags__ainfo(AllocatorInfo ainfo, String8List* list, U32 flags, String8* flag_string_table, U32 flag_string_count); -#define str8_split(allocator, string, split_chars, split_char_count, flags) _Generic(allocator, Arena*: str8_split__arena, AllocatorInfo: str8_split__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, string, split_chars, split_char_count, flags) -#define str8_split_by_string_chars(allocator, string, split_chars, flags) _Generic(allocator, Arena*: str8_split_by_string_chars__arena, AllocatorInfo: str8_split_by_string_chars__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, string, split_chars, flags) -#define str8_list_split_by_string_chars(allocator, list, split_chars, flags) _Generic(allocator, Arena*: str8_list_split_by_string_chars__arena, AllocatorInfo: str8_list_split_by_string_chars__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, split_chars, flags) -#define str8_list_join(allocator, list, ...) _Generic(allocator, Arena*: str8_list_join__arena, AllocatorInfo: str8_list_join__ainfo, default: MD_generic_selection_fail) MD_RESOLVED_FUNCTION_CALL(allocator, list, (StringJoin){ __VA_ARGS__ }) +#define str8_split(allocator, string, split_chars, split_char_count, flags) _Generic(allocator, Arena*: str8_split__arena, AllocatorInfo: str8_split__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string, split_chars, split_char_count, flags) +#define str8_split_by_string_chars(allocator, string, split_chars, flags) _Generic(allocator, Arena*: str8_split_by_string_chars__arena, AllocatorInfo: str8_split_by_string_chars__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string, split_chars, flags) +#define str8_list_split_by_string_chars(allocator, list, split_chars, flags) _Generic(allocator, Arena*: str8_list_split_by_string_chars__arena, AllocatorInfo: str8_list_split_by_string_chars__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, split_chars, flags) +#define str8_list_join(allocator, list, params) _Generic(allocator, Arena*: str8_list_join__arena, AllocatorInfo: str8_list_join__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, params ) -force_inline String8List str8_split__arena (Arena* arena, String8 string, U8* split_chars, U64 split_char_count, StringSplitFlags flags) { return str8_split__ainfo (arena_allocator(arena), string, split_chars, split_char_count, flags); } -force_inline String8List str8_split_by_string_chars__arena (Arena* arena, String8 string, String8 split_chars, StringSplitFlags flags) { return str8_split_by_string_chars__ainfo (arena_allocator(arena), string, split_chars, flags); } -force_inline String8List str8_list_split_by_string_chars__arena(Arena* arena, String8List list, String8 split_chars, StringSplitFlags flags) { return str8_list_split_by_string_chars__ainfo (arena_allocator(arena), list, split_chars, flags); } -force_inline void str8_list_from_flags__arena (Arena* arena, String8List* list, U32 flags, String8* flag_string_table, U32 flag_string_count) { str8_list_from_flags__ainfo (arena_allocator(arena), list, flags, flag_string_table, flag_string_count); } -force_inline String8 str8_list_join__arena (Arena* arena, String8List* list, StringJoin optional_params) { return str8_list_join__ainfo (arena_allocator(arena), list, optional_params); } +force_inline String8List str8_split__arena (Arena* arena, String8 string, U8* split_chars, U64 split_char_count, StringSplitFlags flags) { return str8_split__ainfo (arena_allocator(arena), string, split_chars, split_char_count, flags); } +force_inline String8List str8_split_by_string_chars__arena (Arena* arena, String8 string, String8 split_chars, StringSplitFlags flags) { return str8_split_by_string_chars__ainfo (arena_allocator(arena), string, split_chars, flags); } +force_inline String8List str8_list_split_by_string_chars__arena(Arena* arena, String8List list, String8 split_chars, StringSplitFlags flags) { return str8_list_split_by_string_chars__ainfo (arena_allocator(arena), list, split_chars, flags); } +force_inline void str8_list_from_flags__arena (Arena* arena, String8List* list, U32 flags, String8* flag_string_table, U32 flag_string_count) { str8_list_from_flags__ainfo (arena_allocator(arena), list, flags, flag_string_table, flag_string_count); } +force_inline String8 str8_list_join__arena (Arena* arena, String8List* list, StringJoin* optional_params) { return str8_list_join__ainfo (arena_allocator(arena), list, optional_params); } inline String8List str8_split_by_string_chars__ainfo(AllocatorInfo ainfo, String8 string, String8 split_chars, StringSplitFlags flags) { @@ -782,8 +782,10 @@ str8_list_from_flags__ainfo(AllocatorInfo ainfo, String8List* list, U32 flags, S //////////////////////////////// //~ rjf; String Arrays +#define str8_array_from_list(allocator, list) _Generic(allocator, Arena*: str8_array_from_list__arena, AllocatorInfo: str8_array_from_list__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list) + inline String8Array -str8_array_from_list_alloc(AllocatorInfo ainfo, String8List* list) { +str8_array_from_list__ainfo(AllocatorInfo ainfo, String8List* list) { String8Array array; array.count = list->node_count; array.v = alloc_array_no_zero(ainfo, String8, array.count); @@ -795,15 +797,15 @@ str8_array_from_list_alloc(AllocatorInfo ainfo, String8List* list) { } inline String8Array -str8_array_reserve_alloc(AllocatorInfo ainfo, U64 count) { +str8_array_reserve__ainfo(AllocatorInfo ainfo, U64 count) { String8Array arr; arr.count = 0; arr.v = alloc_array(ainfo, String8, count); return arr; } -inline String8Array str8_array_from_list(Arena* arena, String8List* list) { return str8_array_from_list_alloc(arena_allocator(arena), list); } -inline String8Array str8_array_reserve(Arena *arena, U64 count) { return str8_array_reserve_alloc(arena_allocator(arena), count); } +force_inline String8Array str8_array_from_list__arena(Arena* arena, String8List* list) { return str8_array_from_list__ainfo(arena_allocator(arena), list); } +force_inline String8Array str8_array_reserve__arena (Arena* arena, U64 count) { return str8_array_reserve__ainfo (arena_allocator(arena), count); } //////////////////////////////// //~ rjf: String Path Helpers @@ -813,12 +815,19 @@ MD_API String8 str8_skip_last_slash(String8 string); MD_API String8 str8_chop_last_dot (String8 string); MD_API String8 str8_skip_last_dot (String8 string); -inline String8List str8_split_path(Arena* arena, String8 string) { String8List result = str8_split(arena, string, (U8*)"/\\", 2, 0); return(result); } +force_inline String8List str8_split_path__arena(Arena* arena, String8 string) { String8List result = str8_split(arena, string, (U8*)"/\\", 2, 0); return(result); } +force_inline String8List str8_split_path__ainfo(AllocatorInfo ainfo, String8 string) { String8List result = str8_split(ainfo, string, (U8*)"/\\", 2, 0); return(result); } + +#define str8_split_path(allocator, string) _Generic(allocator, Arena*: str8_split_path__arena, AllocatorInfo: str8_split_path__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string) MD_API PathStyle path_style_from_str8 (String8 string); MD_API void str8_path_list_resolve_dots_in_place( String8List* path, PathStyle style); -MD_API String8 str8_path_list_join_by_style (Arena* arena, String8List* path, PathStyle style); -MD_API String8 str8_path_list_join_by_style_alloc (AllocatorInfo ainfo, String8List* path, PathStyle style); +MD_API String8 str8_path_list_join_by_style__arena (Arena* arena, String8List* path, PathStyle style); +MD_API String8 str8_path_list_join_by_style__ainfo (AllocatorInfo ainfo, String8List* path, PathStyle style); + +#define str8_path_list_join_by_style(allocator, path, style) _Generic(allocator, Arena*: str8_path_list_join_by_style__arena, AllocatorInfo: str8_split_path__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, path, style) + +force_inline String8 str8_path_list_join_by_style__arena(Arena* arena, String8List* path, PathStyle style) { return str8_path_list_join_by_style__ainfo(arena_allocator(arena), path, style); } //////////////////////////////// //~ rjf: UTF-8 & UTF-16 Decoding/Encoding @@ -857,15 +866,20 @@ inline U32 utf8_from_utf32_single(U8* buffer, U32 character){ return(utf8_encode //////////////////////////////// //~ rjf: Unicode String Conversions -MD_API String8 str8_from_16(Arena* arena, String16 in); -MD_API String16 str16_from_8(Arena* arena, String8 in); -MD_API String8 str8_from_32(Arena* arena, String32 in); -MD_API String32 str32_from_8(Arena* arena, String8 in); +#define str8_from_str16(allocator, string_in) _Generic(allocator, Arena*: str8_from_str16__arena, AllocatorInfo: str8_from_str16__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string_in) +#define str16_from_str8(allocator, string_in) _Generic(allocator, Arena*: str16_from_str8__arena, AllocatorInfo: str16_from_str8__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string_in) +#define str8_from_str32(allocator, string_in) _Generic(allocator, Arena*: str8_from_str32__arena, AllocatorInfo: str8_from_str32__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string_in) +#define str32_from_str8(allocator, string_in) _Generic(allocator, Arena*: str32_from_str8__arena, AllocatorInfo: str32_from_str8__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string_in) -MD_API String8 str8_from_16_alloc(AllocatorInfo ainfo, String16 in); -MD_API String16 str16_from_8_alloc(AllocatorInfo ainfo, String8 in); -MD_API String8 str8_from_32_alloc(AllocatorInfo ainfo, String32 in); -MD_API String32 str32_from_8_alloc(AllocatorInfo ainfo, String8 in); +MD_API String8 str8_from_str16__arena(Arena* arena, String16 in); +MD_API String16 str16_from_str8__arena(Arena* arena, String8 in); +MD_API String8 str8_from_str32__arena(Arena* arena, String32 in); +MD_API String32 str32_from_str8__arena(Arena* arena, String8 in); + +MD_API String8 str8_from_str16__ainfo(AllocatorInfo ainfo, String16 in); +MD_API String16 str16_from_str8__ainfo(AllocatorInfo ainfo, String8 in); +MD_API String8 str8_from_str32__ainfo(AllocatorInfo ainfo, String32 in); +MD_API String32 str32_from_str8__ainfo(AllocatorInfo ainfo, String8 in); //////////////////////////////// //~ String -> Enum Conversions @@ -993,7 +1007,7 @@ MD_API String8 string_from_elapsed_time_alloc (AllocatorInfo ainfo, DateTime d inline String8 string_from_guid(Arena* arena, Guid guid) { - String8 result = push_str8f(arena, + String8 result = str8f(arena, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.data1, guid.data2, @@ -1037,8 +1051,8 @@ MD_API String8List wrapped_lines_from_string_alloc(AllocatorInfo ainfo, String8 //////////////////////////////// //~ rjf: String <-> Color -inline String8 hex_string_from_rgba_4f32 (Arena* arena, Vec4F32 rgba) { String8 hex_string = push_str8f (arena, "%02x%02x%02x%02x", (U8)(rgba.x * 255.f), (U8)(rgba.y * 255.f), (U8)(rgba.z * 255.f), (U8)(rgba.w * 255.f)); return hex_string; } -inline String8 hex_string_from_rgba_4f32_alloc(AllocatorInfo ainfo, Vec4F32 rgba) { String8 hex_string = alloc_str8f(ainfo, "%02x%02x%02x%02x", (U8)(rgba.x * 255.f), (U8)(rgba.y * 255.f), (U8)(rgba.z * 255.f), (U8)(rgba.w * 255.f)); return hex_string; } +inline String8 hex_string_from_rgba_4f32 (Arena* arena, Vec4F32 rgba) { String8 hex_string = str8f (arena, "%02x%02x%02x%02x", (U8)(rgba.x * 255.f), (U8)(rgba.y * 255.f), (U8)(rgba.z * 255.f), (U8)(rgba.w * 255.f)); return hex_string; } +inline String8 hex_string_from_rgba_4f32_alloc(AllocatorInfo ainfo, Vec4F32 rgba) { String8 hex_string = str8f(ainfo, "%02x%02x%02x%02x", (U8)(rgba.x * 255.f), (U8)(rgba.y * 255.f), (U8)(rgba.z * 255.f), (U8)(rgba.w * 255.f)); return hex_string; } MD_API Vec4F32 rgba_from_hex_string_4f32(String8 hex_string); @@ -1067,7 +1081,6 @@ str8_serial_write_to_dst(String8List* srl, void* out) { } } - void str8_serial_begin_alloc (AllocatorInfo ainfo, String8List* srl); String8 str8_serial_end_alloc (AllocatorInfo ainfo, String8List* srl); MD_API U64 str8_serial_alloc_align (AllocatorInfo ainfo, String8List* srl, U64 align); @@ -1188,3 +1201,22 @@ MD_API U64 str8_deserial_read_sleb128 (String8 string, U64 off, inline void* str8_deserial_get_raw_ptr(String8 string, U64 off, U64 size) { void* raw_ptr = 0; if (off + size <= string.size) { raw_ptr = string.str + off; } return raw_ptr; } inline U64 str8_deserial_read_block (String8 string, U64 off, U64 size, String8* block_out) { Rng1U64 range = rng_1u64(off, off + size); *block_out = str8_substr(string, range); return block_out->size; } + +//////////////////////////////// +// Second-order Generic Selectors + +#define str8_from(allocator, in) \ +_Generic(in, \ + String16 : _Generic(allocator, Arena*: str8_from_str16__arena, AllocatorInfo: str8_from_str16__ainfo, default: assert_generic_selection_fail), \ + String32 : _Generic(allocator, Arena*: str8_from_str32__arena, AllocatorInfo: str8_from_str32__ainfo, default: assert_generic_selection_fail), \ + distinct_lookup(U64) : _Generic(allocator, Arena*: str8_from_u64__arena, AllocatorInfo: str8_from_s64__ainfo, default: assert_generic_selection_fail), \ + distinct_lookup(S64) : _Generic(allocator, Arena*: str8_from_s64__arena, AllocatorInfo: str8_from_s64__ainfo, default: assert_generic_selection_fail), \ + distinct_lookup(SSIZE): _Generic(allocator, Arena*: str8_from_memory_size__arena, AllocatorInfo: str8_from_memory_size__ainfo, default: assert_generic_selection_fail), \ + default : assert_generic_selection_fail \ +) resolved_function_call(allocator, in) + +#define str16_from(allocator, in) \ +_Generic(in, \ + String8 : _Generic(allocator, Arena*: str16_from_str8__arena, AllocatorInfo: str16_from_str8__ainfo, default: assert_generic_selection_fail), \ + default : assert_generic_selection_fail \ +) resolved_function_call(allocator, in) diff --git a/code/base/thread_context.h b/code/base/thread_context.h index 3c2b76e..da1e68b 100644 --- a/code/base/thread_context.h +++ b/code/base/thread_context.h @@ -39,16 +39,30 @@ void tctx_write_srcloc(char* file_name, U64 line_number); void tctx_read_srcloc (char** file_name, U64* line_number); #define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__) +typedef struct { U64 count; } Opt_ScratchBegin; + inline TempArena -scratch__begin_alloc(AllocatorInfo ainfo) { +scratch_begin__ainfo(AllocatorInfo ainfo, Opt_ScratchBegin opt) { Arena* arena = extract_arena(ainfo); TempArena scratch = temp_begin(tctx_get_scratch(&arena, arena != nullptr)); return scratch; } -#define scratch_begin_alloc(ainfo) scratch__begin_alloc(ainfo) -#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count))) -#define scratch_end(scratch) temp_end(scratch) +inline TempArena +scratch_begin__arena(Arena** arena, Opt_ScratchBegin opt) { + TempArena scratch = temp_begin(tctx_get_scratch(arena, opt.count)); + return scratch; +} + +#define scratch_begin(conflicts, ...) \ +_Generic(conflicts, \ + int : scratch_begin__arena, \ + Arena** : scratch_begin__arena, \ + AllocatorInfo: scratch_begin__ainfo, \ + default : assert_generic_selection_fail \ +) resolved_function_call(conflicts, (Opt_ScratchBegin){__VA_ARGS__}) + +#define scratch_end(scratch) temp_end(scratch) inline void tctx_set_thread_name(String8 string){ diff --git a/code/mdesk/mdesk.c b/code/mdesk/mdesk.c index 6147712..e1926e4 100644 --- a/code/mdesk/mdesk.c +++ b/code/mdesk/mdesk.c @@ -302,8 +302,8 @@ tree_copy_alloc(AllocatorInfo ainfo, Node* src_root) dst->first_tag = dst->last_tag = nil_node(); dst->kind = src->kind; dst->flags = src->flags; - dst->string = alloc_str8_copy(ainfo, src->string); - dst->raw_string = alloc_str8_copy(ainfo, src->raw_string); + dst->string = str8_copy(ainfo, src->string); + dst->raw_string = str8_copy(ainfo, src->raw_string); dst->src_offset = src->src_offset; dst->parent = dst_parent; if (dst_parent != nil_node()) { @@ -336,7 +336,7 @@ tokenize_from_text(Arena* arena, String8 text) { TokenizeResult tokenize_from_text_alloc(AllocatorInfo ainfo, String8 text) { - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); TokenChunkList tokens = {0}; MsgList msgs = {0}; @@ -720,7 +720,7 @@ parse_from_text_tokens_push(Arena* arena, String8 filename, String8 text, TokenA ParseResult parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text, TokenArray tokens) { - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); //- rjf: set up outputs MsgList msgs = {0}; @@ -820,7 +820,7 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text //- rjf: [main, main_implicit] unexpected reserved tokens if (mode_main_or_main_implict && found_unexpected) { Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min); - String8 error_string = alloc_str8f(ainfo, "Unexpected reserved symbol \"%S\".", token_string); + String8 error_string = str8f(ainfo, "Unexpected reserved symbol \"%S\".", token_string); msg_list_alloc(ainfo, &msgs, error, MsgKind_Error, error_string); token += 1; goto end_consume; @@ -961,7 +961,7 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text { Node* node = work_top->parent; Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min); - String8 error_string = alloc_str8f(ainfo, "More than two newlines following \"%S\", which has implicitly-delimited children, resulting in an empty list of children.", node->string); + String8 error_string = str8f(ainfo, "More than two newlines following \"%S\", which has implicitly-delimited children, resulting in an empty list of children.", node->string); msg_list_alloc(ainfo, &msgs, error, MsgKind_Warning, error_string); parse_work_pop(); } @@ -1010,7 +1010,7 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text //- rjf: no consumption -> unexpected token! we don't know what to do with this. { Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min); - String8 error_string = alloc_str8f(ainfo, "Unexpected \"%S\" token.", token_string); + String8 error_string = str8f(ainfo, "Unexpected \"%S\" token.", token_string); msg_list_alloc(ainfo, &msgs, error, MsgKind_Error, error_string); token += 1; // ??? @@ -1044,7 +1044,7 @@ parse_from_text(Arena* arena, String8 filename, String8 text) { ParseResult parse_from_text_alloc(AllocatorInfo ainfo, String8 filename, String8 text) { - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); TokenizeResult tokenize = tokenize_from_text(scratch.arena, text); ParseResult parse = parse_from_text_tokens_alloc(ainfo, filename, text, tokenize.tokens); scratch_end(scratch); diff --git a/code/mdesk/mdesk.h b/code/mdesk/mdesk.h index 2e1b00d..52609da 100644 --- a/code/mdesk/mdesk.h +++ b/code/mdesk/mdesk.h @@ -287,7 +287,7 @@ inline void msg_list_pushf(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, char* fmt, ...) { va_list args; va_start(args, fmt); - String8 string = push_str8fv(arena, fmt, args); + String8 string = str8fv(arena, fmt, args); msg_list_push(arena, msgs, node, kind, string); va_end(args); } @@ -296,7 +296,7 @@ inline void msg_list_allocf(AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, char* fmt, ...) { va_list args; va_start(args, fmt); - String8 string = alloc_str8fv(ainfo, fmt, args); + String8 string = str8fv(ainfo, fmt, args); msg_list_alloc(ainfo, msgs, node, kind, string); va_end(args); } diff --git a/code/os/os.c b/code/os/os.c index 116fb69..cba69af 100644 --- a/code/os/os.c +++ b/code/os/os.c @@ -60,7 +60,7 @@ os_append_data_to_file_path(String8 path, String8 data) } String8 -os_string_from_file_range(Arena* arena, OS_Handle file, Rng1U64 range) +os_string_from_file_range__arena(Arena* arena, OS_Handle file, Rng1U64 range) { U64 pre_pos = arena_pos(arena); String8 result; @@ -76,16 +76,12 @@ os_string_from_file_range(Arena* arena, OS_Handle file, Rng1U64 range) } String8 -os_string_from_file_range_alloc(AllocatorInfo ainfo, OS_Handle file, Rng1U64 range) { +os_string_from_file_range__ainfo(AllocatorInfo ainfo, OS_Handle file, Rng1U64 range) { String8 result; result.size = dim_1u64(range); result.str = alloc_array_no_zero(ainfo, U8, result.size); U64 actual_read_size = os_file_read(file, range, result.str); - if(actual_read_size < result.size) - { - // TODO(Ed): It may be better to actually wrap the alloation in an arena and then rewind it. - // This would ensure resize isn't doing an expensive shrink (from a bad heap realloc, or something else) - // That or we just leave it up to the user to make sure to pass in an arena. + if ((allocator_query_support(ainfo) & AllocatorQuery_ResizeShrink) && actual_read_size < result.size) { resize(ainfo, result.str, result.size, scast(U64, result.str) + actual_read_size); result.size = actual_read_size; } diff --git a/code/os/os.h b/code/os/os.h index bbbb287..09c1e5c 100644 --- a/code/os/os.h +++ b/code/os/os.h @@ -313,7 +313,7 @@ inline S64 os_file_id_compare(OS_FileID a, OS_FileID b) { S64 cmp = memory_compa inline String8 os_string_from_guid_alloc(AllocatorInfo ainfo, OS_Guid guid) { - String8 result = alloc_str8f(ainfo, + String8 result = str8f(ainfo, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.data1, guid.data2, @@ -332,7 +332,7 @@ os_string_from_guid_alloc(AllocatorInfo ainfo, OS_Guid guid) { inline String8 os_string_from_guid(Arena* arena, OS_Guid guid) { - String8 result = push_str8f(arena, + String8 result = str8f(arena, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", guid.data1, guid.data2, diff --git a/code/os/win32/os_win32.c b/code/os/win32/os_win32.c index 3291ee9..52c0845 100644 --- a/code/os/win32/os_win32.c +++ b/code/os/win32/os_win32.c @@ -111,13 +111,13 @@ os_set_thread_name(String8 name) // rjf: windows 10 style if (w32_SetThreadDescription_func) { - String16 name16 = str16_from_8(scratch.arena, name); + String16 name16 = str16_from(scratch.arena, name); HRESULT hr = w32_SetThreadDescription_func(GetCurrentThread(), (WCHAR*)name16.str); } // rjf: raise-exception style { - String8 name_copy = push_str8_copy(scratch.arena, name); + String8 name_copy = str8_copy(scratch.arena, name); #pragma pack(push,8) typedef struct THREADNAME_INFO THREADNAME_INFO; @@ -167,7 +167,7 @@ os_file_open(OS_AccessFlags flags, String8 path) OS_Handle result = {0}; TempArena scratch = scratch_begin(0, 0); { - String16 path16 = str16_from_8(scratch.arena, path); + String16 path16 = str16_from(scratch.arena, path); DWORD access_flags = 0; DWORD share_mode = 0; @@ -328,7 +328,7 @@ B32 os_delete_file_at_path(String8 path) { TempArena scratch = scratch_begin(0, 0); - String16 path16 = str16_from_8(scratch.arena, path); + String16 path16 = str16_from(scratch.arena, path); B32 result = DeleteFileW((WCHAR*)path16.str); scratch_end(scratch); return result; @@ -338,8 +338,8 @@ B32 os_copy_file_path(String8 dst, String8 src) { TempArena scratch = scratch_begin(0, 0); - String16 dst16 = str16_from_8(scratch.arena, dst); - String16 src16 = str16_from_8(scratch.arena, src); + String16 dst16 = str16_from(scratch.arena, dst); + String16 src16 = str16_from(scratch.arena, src); B32 result = CopyFileW((WCHAR*)src16.str, (WCHAR*)dst16.str, 0); scratch_end(scratch); return result; @@ -351,9 +351,9 @@ os_full_path_from_path(Arena* arena, String8 path) TempArena scratch = scratch_begin(&arena, 1); DWORD buffer_size = MAX_PATH + 1; U16* buffer = push_array_no_zero(scratch.arena, U16, buffer_size); - String16 path16 = str16_from_8(scratch.arena, path); + String16 path16 = str16_from(scratch.arena, path); DWORD path16_size = GetFullPathNameW((WCHAR*)path16.str, buffer_size, (WCHAR*)buffer, NULL); - String8 full_path = str8_from_16(arena, str16(buffer, path16_size)); + String8 full_path = str8_from(arena, str16(buffer, path16_size)); scratch_end(scratch); return full_path; } @@ -362,7 +362,7 @@ B32 os_file_path_exists(String8 path) { TempArena scratch = scratch_begin(0,0); - String16 path16 = str16_from_8(scratch.arena, path); + String16 path16 = str16_from(scratch.arena, path); DWORD attributes = GetFileAttributesW((WCHAR *)path16.str); B32 exists = (attributes != INVALID_FILE_ATTRIBUTES) && !!(~attributes & FILE_ATTRIBUTE_DIRECTORY); scratch_end(scratch); @@ -375,7 +375,7 @@ os_properties_from_file_path(String8 path) FileProperties props = {0}; WIN32_FIND_DATAW find_data = {0}; TempArena scratch = scratch_begin(0, 0); - String16 path16 = str16_from_8(scratch.arena, path); + String16 path16 = str16_from(scratch.arena, path); HANDLE handle = FindFirstFileW((WCHAR *)path16.str, &find_data); if (handle != INVALID_HANDLE_VALUE) { @@ -480,8 +480,8 @@ os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags) { TempArena scratch = scratch_begin(&arena, 1); - String8 path_with_wildcard = push_str8_cat(scratch.arena, path, str8_lit("\\*")); - String16 path16 = str16_from_8(scratch.arena, path_with_wildcard); + String8 path_with_wildcard = str8_cat(scratch.arena, path, str8_lit("\\*")); + String16 path16 = str16_from(scratch.arena, path_with_wildcard); OS_FileIter* iter = push_array(arena, OS_FileIter, 1); @@ -500,7 +500,7 @@ os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags) { String16 next_drive_string_16 = str16_cstring((U16*)buffer + off); off += next_drive_string_16.size + 1; - String8 next_drive_string = str8_from_16(arena, next_drive_string_16); + String8 next_drive_string = str8_from(arena, next_drive_string_16); next_drive_string = str8_chop_last_slash(next_drive_string); str8_list_push(scratch.arena, &drive_strings, next_drive_string); } @@ -566,7 +566,7 @@ os_file_iter_next(Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out) // emit if usable if (usable_file) { - info_out->name = str8_from_16(arena, str16_cstring((U16*)file_name)); + info_out->name = str8_from(arena, str16_cstring((U16*)file_name)); info_out->props.size = (U64)w32_iter->find_data.nFileSizeLow | (((U64)w32_iter->find_data.nFileSizeHigh) << 32); os_w32_dense_time_from_file_time(&info_out->props.created, &w32_iter->find_data.ftCreationTime); os_w32_dense_time_from_file_time(&info_out->props.modified, &w32_iter->find_data.ftLastWriteTime); @@ -620,7 +620,7 @@ os_make_directory(String8 path) B32 result = 0; TempArena scratch = scratch_begin(0, 0); { - String16 name16 = str16_from_8(scratch.arena, path); + String16 name16 = str16_from(scratch.arena, path); WIN32_FILE_ATTRIBUTE_DATA attributes = {0}; GetFileAttributesExW((WCHAR*)name16.str, GetFileExInfoStandard, &attributes); if (attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { @@ -641,7 +641,7 @@ OS_Handle os_shared_memory_alloc(U64 size, String8 name) { TempArena scratch = scratch_begin(0, 0); - String16 name16 = str16_from_8(scratch.arena, name); + String16 name16 = str16_from(scratch.arena, name); HANDLE file = CreateFileMappingW(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, @@ -658,7 +658,7 @@ OS_Handle os_shared_memory_open(String8 name) { TempArena scratch = scratch_begin(0, 0); - String16 name16 = str16_from_8(scratch.arena, name); + String16 name16 = str16_from(scratch.arena, name); HANDLE file = OpenFileMappingW(FILE_MAP_ALL_ACCESS, 0, (WCHAR *)name16.str); scratch_end(scratch); OS_Handle result = {(U64)file}; @@ -809,11 +809,11 @@ os_process_launch(OS_ProcessLaunchParams* params) } //- rjf: utf-8 -> utf-16 - String16 cmd16 = str16_from_8(scratch.arena, cmd); - String16 dir16 = str16_from_8(scratch.arena, params->path); + String16 cmd16 = str16_from(scratch.arena, cmd); + String16 dir16 = str16_from(scratch.arena, params->path); String16 env16 = {0}; if (use_null_env_arg == 0) { - env16 = str16_from_8(scratch.arena, env); + env16 = str16_from(scratch.arena, env); } //- rjf: determine creation flags @@ -1023,7 +1023,7 @@ os_condition_variable_broadcast(OS_Handle cv) { OS_Handle os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name) { TempArena scratch = scratch_begin(0, 0); - String16 name16 = str16_from_8(scratch.arena, name); + String16 name16 = str16_from(scratch.arena, name); HANDLE handle = CreateSemaphoreW(0, initial_count, max_count, (WCHAR *)name16.str); OS_Handle result = {(U64)handle}; scratch_end(scratch); @@ -1039,7 +1039,7 @@ os_semaphore_release(OS_Handle semaphore) { OS_Handle os_semaphore_open(String8 name) { TempArena scratch = scratch_begin(0, 0); - String16 name16 = str16_from_8(scratch.arena, name); + String16 name16 = str16_from(scratch.arena, name); HANDLE handle = OpenSemaphoreW(SEMAPHORE_ALL_ACCESS , 0, (WCHAR *)name16.str); OS_Handle result = {(U64)handle}; scratch_end(scratch); @@ -1074,7 +1074,7 @@ OS_Handle os_library_open(String8 path) { TempArena scratch = scratch_begin(0, 0); - String16 path16 = str16_from_8(scratch.arena, path); + String16 path16 = str16_from(scratch.arena, path); HMODULE mod = LoadLibraryW((LPCWSTR)path16.str); OS_Handle result = { (U64)mod }; scratch_end(scratch); @@ -1086,7 +1086,7 @@ os_library_load_proc(OS_Handle lib, String8 name) { TempArena scratch = scratch_begin(0, 0); HMODULE mod = (HMODULE)lib.u64[0]; - name = push_str8_copy(scratch.arena, name); + name = str8_copy(scratch.arena, name); VoidProc* result = (VoidProc*)GetProcAddress(mod, (LPCSTR)name.str); scratch_end(scratch); return result; @@ -1598,7 +1598,7 @@ void os_init(OS_Context* ctx, TCTX* thread_ctx) DWORD size = MAX_COMPUTERNAME_LENGTH + 1; if(GetComputerNameA((char*)buffer, &size)) { - info->machine_name = push_str8_copy(state_arena, str8(buffer, size)); + info->machine_name = str8_copy(state_arena, str8(buffer, size)); } } } @@ -1609,9 +1609,9 @@ void os_init(OS_Context* ctx, TCTX* thread_ctx) DWORD size = KB(32); U16* buffer = push_array_no_zero(scratch.arena, U16, size); DWORD length = GetModuleFileNameW(0, (WCHAR*)buffer, size); - String8 name8 = str8_from_16(scratch.arena, str16(buffer, length)); + String8 name8 = str8_from(scratch.arena, str16(buffer, length)); String8 name_chopped = str8_chop_last_slash(name8); - info->binary_path = push_str8_copy(state_arena, name_chopped); + info->binary_path = str8_copy(state_arena, name_chopped); scratch_end(scratch); } @@ -1621,7 +1621,7 @@ void os_init(OS_Context* ctx, TCTX* thread_ctx) U64 size = KB(32); U16* buffer = push_array_no_zero(scratch.arena, U16, size); if (SUCCEEDED(SHGetFolderPathW(0, CSIDL_APPDATA, 0, 0, (WCHAR*)buffer))) { - info->user_program_data_path = str8_from_16(state_arena, str16_cstring(buffer)); + info->user_program_data_path = str8_from(state_arena, str16_cstring(buffer)); } scratch_end(scratch); } @@ -1639,7 +1639,7 @@ void os_init(OS_Context* ctx, TCTX* thread_ctx) else { String16 string16 = str16((U16 *)this_proc_env + start_idx, idx - start_idx); - String8 string = str8_from_16(state_arena, string16); + String8 string = str8_from(state_arena, string16); str8_list_push(state_arena, &info->environment, string); start_idx = idx+1; } diff --git a/code/os/win32/os_win32.h b/code/os/win32/os_win32.h index 6d78309..02441f7 100644 --- a/code/os/win32/os_win32.h +++ b/code/os/win32/os_win32.h @@ -166,12 +166,12 @@ MD_API DWORD os_w32_thread_entry_point(void* ptr); inline String8 os_get_current_path_alloc(AllocatorInfo ainfo) { String8 name; - TempArena scratch = scratch_begin_alloc(ainfo); + TempArena scratch = scratch_begin(ainfo); { DWORD length = GetCurrentDirectoryW(0, 0); U16* memory = push_array_no_zero(scratch.arena, U16, length + 1); length = GetCurrentDirectoryW(length + 1, (WCHAR*)memory); - name = str8_from_16_alloc(ainfo, str16(memory, length)); + name = str8_from(ainfo, str16(memory, length)); } scratch_end(scratch); return name; @@ -185,7 +185,7 @@ os_get_current_path(Arena* arena) { DWORD length = GetCurrentDirectoryW(0, 0); U16* memory = push_array_no_zero(scratch.arena, U16, length + 1); length = GetCurrentDirectoryW(length + 1, (WCHAR*)memory); - name = str8_from_16(arena, str16(memory, length)); + name = str8_from(arena, str16(memory, length)); } scratch_end(scratch); return name; diff --git a/third_party/gencpp_c11/gencpp_c11.h b/third_party/gencpp_c11/gencpp_c11.h index 24aff1f..abae730 100644 --- a/third_party/gencpp_c11/gencpp_c11.h +++ b/third_party/gencpp_c11/gencpp_c11.h @@ -616,7 +616,7 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u // Additional Variations: // If the function takes more than one argument the following is used: -#define GEN_FUNCTION_GENERIC_EXAMPLE_VARADIC( selector_arg, ... ) _Generic( \ +#define GEN_function_generic_example_varadic( selector_arg, ... ) _Generic( \ (selector_arg), \ GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \ GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \ @@ -626,7 +626,7 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u ) GEN_RESOLVED_FUNCTION_CALL( selector_arg, __VA_ARG__ ) // If the function does not take the arugment as a parameter: -#define GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( selector_arg ) _Generic( \ +#define GEN_function_generic_example_direct_type( selector_arg ) _Generic( \ ( GEN_TYPE_TO_EXP(selector_arg) ), \ GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig ) \ GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_2__function_sig ) \ @@ -640,7 +640,7 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u // Instead of using this macro, you'll see it directly expanded by the code generation. // typedef void* GEN_GenericExampleType; -// GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( GEN_GenericExampleType ); +// GEN_function_generic_example_direct_type( GEN_GenericExampleType ); #pragma endregion _Generic Macros GEN_API_C_BEGIN