adding prefixes to source

They'll be removed on demand in libgen repo
This commit is contained in:
ed
2025-02-12 14:40:11 -05:00
parent aa5c1efb36
commit 0ab226f739
45 changed files with 5811 additions and 5820 deletions
+63 -65
View File
@@ -1,7 +1,5 @@
#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
// ____ _ ______ _ _ ____ _ __ _
@@ -19,42 +17,42 @@
// Additional info: https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/
// --------------------------------------------------------------------------------------------------------------------------------------------
#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.
#ifndef MD_COMMA_OPERATOR
#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.
#endif
// Helper macros for argument selection
#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..
#ifndef md_select_arg_1
#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..
#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 ','.
#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 ','.
#endif
#ifndef generic_call
#define generic_call // Just used to indicate where the call "occurs"
#ifndef md_generic_call
#define md_generic_call // Just used to indicate where the call "occurs"
#endif
// ----------------------------------------------------------------------------------------------------------------------------------
#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).
#ifndef md_if_generic_selector_defined_include_slot
// md_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) <comma_operator: ',' >
// Where generic_sel_entry_comma_delimiter is specifically looking for that <comma> ,
#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, , )
// Where md_generic_sel_entry_comma_delimiter is specifically looking for that <comma> ,
#define md_if_generic_selector_defined_include_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
// 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: <value>" will be set to:
typedef struct UNRESOLVED_GENERIC_SELECTION UNRESOLVED_GENERIC_SELECTION;
struct UNRESOLVED_GENERIC_SELECTION {
typedef struct MD_UNRESOLVED_GENERIC_SELECTION MD_UNRESOLVED_GENERIC_SELECTION;
struct MD_UNRESOLVED_GENERIC_SELECTION {
void* _THE_VOID_SLOT_;
};
UNRESOLVED_GENERIC_SELECTION const assert_generic_sel_fail = {0};
MD_UNRESOLVED_GENERIC_SELECTION const md_assert_generic_sel_fail = {0};
// Which will provide the message: error: called object type 'struct NO_RESOLVED_GENERIC_SELECTION' is not a function or function pointer
// ----------------------------------------------------------------------------------------------------------------------------------
@@ -63,10 +61,10 @@ UNRESOLVED_GENERIC_SELECTION const assert_generic_sel_fail = {0};
#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_sel_fail \
) generic_call( selector_arg )
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__function_sig ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__function_sig ) \
default: md_assert_generic_sel_fail \
) md_generic_call( selector_arg )
// ----------------------------------------------------------------------------------------------------------------------------------
// Then each definiton of a function has an associated define:
@@ -78,56 +76,56 @@ UNRESOLVED_GENERIC_SELECTION const assert_generic_sel_fail = {0};
// Concrete example:
// To add support for long:
#define GENERIC_SLOT_1__example_hash long, generic_example_hash__P_long
size_t generic_example_hash__P_long( long val ) { return val * 2654435761ull; }
#define MD_GENERIC_SLOT_1__example_hash long, md_generic_example_hash__P_long
size_t md_generic_example_hash__P_long( long val ) { return val * 2654435761ull; }
// To add support for long long:
#define GENERIC_SLOT_2__example_hash long long, generic_example_hash__P_long_long
size_t generic_example_hash__P_long_long( long long val ) { return val * 2654435761ull; }
#define GENERIC_SLOT_2__example_hash long long, md_generic_example_hash__P_long_long
size_t md_generic_example_hash__P_long_long( long long val ) { return val * 2654435761ull; }
// If using an Editor with support for syntax hightlighting macros:
// GENERIC_SLOT_1__example_hash and GENERIC_SLOT_2__example_hash should show color highlighting indicating the slot is enabled,
// MD_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 generic_example_hash( 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_sel_fail \
) generic_call( function_arguments )
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_2__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_3__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_4__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_5__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_6__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_7__example_hash ) \
md_if_generic_selector_defined_include_slot( GENERIC_SLOT_8__example_hash ) \
default: md_assert_generic_sel_fail \
) md_generic_call( function_arguments )
// Additional Variations:
// If the function takes more than one argument the following is used:
#define function_generic_example_varadic( selector_arg, ... ) _Generic( \
#define md_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 ) \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__function_sig ) \
md_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_sel_fail \
) generic_call( selector_arg, __VA_ARG__ )
md_if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \
default: md_assert_generic_sel_fail \
) md_generic_call( selector_arg, __VA_ARG__ )
// If the function does not take the arugment as a parameter:
#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 ) \
#define md_function_generic_example_direct_type( selector_arg ) _Generic( \
( md_type_to_expression(selector_arg) ), \
md_if_generic_selector_defined_include_slot( MD_GENERIC_SLOT_1__function_sig ) \
md_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_sel_fail \
) generic_call(selector_arg)
md_if_generic_selector_defined_include_slot(GENERIC_SLOT_N__function_sig ) \
default: md_assert_generic_sel_fail \
) md_generic_call(selector_arg)
#ifndef type_to_expression
#ifndef md_type_to_expression
// Used to keep the _Generic keyword happy as bare types are not considered "expressions"
#define type_to_expression(type) (* (type*)NULL)
#define md_type_to_expression(type) (* (type*)NULL)
// Instead of using this macro, it should be directly expanded by code generation.
#endif
@@ -136,14 +134,14 @@ size_t generic_example_hash__P_long_long( long long val ) { return val * 2654435
#define example_with__l2(expr) _Generic( \
(expr), \
S64 : example_with_s64, \
default: assert_generic_sel_fail \
MD_S64 : example_with_s64, \
default: md_assert_generic_sel_fail \
)
#define example_with(expr) \
_Generic((expr), \
SSIZE : example_with_SSIZEZ \
MD_SSIZE : example_with_SSIZEZ \
default : example_with_not_SSIZE(allocator, in) \
) generic_call(allocator, in)
) md_generic_call(allocator, in)
// This can be made more concise with he following "layer" indicating _Generic macros
@@ -152,21 +150,21 @@ _Generic((expr), \
#define example_with_generic_layers(expr) \
_Generic( (expr), \
S64 : example_with_s64, \
MD_S64 : example_with_s64, \
_Generic_L2((expr), \
SSIZE: example_with_SSIZZE \
default: assert_generic_sel_fail \
MD_SSIZE: example_with_SSIZZE \
default: md_assert_generic_sel_fail \
), \
) generic_call(expr)
) md_generic_call(expr)
// Removing example definitions
#undef example_with
#undef example_with__l2
#undef example_with_generic_layers
#undef function_generic_example
#undef GENERIC_SLOT_1__example_hash
#undef MD_GENERIC_SLOT_1__example_hash
#undef GENERIC_SLOT_2__example_hash
#undef generic_example_hash
#undef function_generic_example_varadic
#undef function_generic_example_direct_type
#undef md_function_generic_example_varadic
#undef md_function_generic_example_direct_type
#undef generic_example_do_something_with