mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
gen_c11.c: generates base
This commit is contained in:
+1
-1
@@ -99,7 +99,7 @@ BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakStringLiterals: true
|
||||
|
||||
ColumnLimit: 160
|
||||
ColumnLimit: 180
|
||||
|
||||
CompactNamespaces: true
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ typedef distinct(S16, B16);
|
||||
typedef distinct(S32, B32);
|
||||
|
||||
typedef void VoidProc(void);
|
||||
typedef_generic_selector(VoidProc);
|
||||
distinct_register_selector(VoidProc);
|
||||
|
||||
////////////////////////////////
|
||||
//~ NOTE(allen): Constants
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region Build Options
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Build Options
|
||||
|
||||
@@ -68,6 +70,8 @@
|
||||
|
||||
#define BUILD_TITLE_STRING_LITERAL BUILD_TITLE " (" BUILD_VERSION_STRING_LITERAL " " BUILD_RELEASE_PHASE_STRING_LITERAL ") - " __DATE__ "" BUILD_GIT_HASH_STRING_LITERAL_APPEND BUILD_MODE_STRING_LITERAL_APPEND
|
||||
|
||||
#pragma endregion Build Options
|
||||
|
||||
#pragma region Compiler Vendor
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
@@ -126,7 +130,7 @@
|
||||
|
||||
#pragma endregion Compiler Vendor
|
||||
|
||||
#pragma endregion Language
|
||||
#pragma region Language
|
||||
|
||||
#if ! defined(LANG_C)
|
||||
# ifdef __cplusplus
|
||||
@@ -265,9 +269,6 @@
|
||||
|
||||
#pragma endregion Operating System
|
||||
|
||||
#pragma region Language
|
||||
#pragma endregion Langage
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Zero All Undefined Options
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
// or have their usage removed during the library generation pass.
|
||||
#endif
|
||||
|
||||
#pragma region _Generic Macros
|
||||
// ____ _ ______ _ _ ____ _ __ _
|
||||
// / ___} (_) | ____} | | (_) / __ \ | | | |(_)
|
||||
// | | ___ ___ _ __ ___ _ __ _ ___ | |__ _ _ _ __ ___| |_ _ ___ _ __ | | | |_ _____ _ __ | | ___ __ _ __| | _ _ __ __ _
|
||||
@@ -172,4 +171,3 @@ size_t generic_example_hash__P_long_long( long long val ) { return val * 2654435
|
||||
#undef function_generic_example_varadic
|
||||
#undef function_generic_example_direct_type
|
||||
#undef generic_example_do_something_with
|
||||
#pragma endregion _Generic Macros
|
||||
|
||||
+1
-1
@@ -1129,7 +1129,7 @@ indented_from_string__ainfo(AllocatorInfo ainfo, String8 string)
|
||||
{
|
||||
TempArena scratch = scratch_begin(ainfo);
|
||||
|
||||
read_only local_persist U8 indentation_bytes[] = " ";
|
||||
local_persist U8 indentation_bytes[] = " ";
|
||||
String8List indented_strings = {0};
|
||||
|
||||
S64 depth = 0;
|
||||
|
||||
+6
-6
@@ -153,7 +153,7 @@ struct FuzzyMatchRangeList
|
||||
|
||||
inline U8
|
||||
integer_symbols(U8 value) {
|
||||
read_only local_persist
|
||||
local_persist
|
||||
U8 lookup_table[16] = {
|
||||
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
|
||||
};
|
||||
@@ -162,7 +162,7 @@ integer_symbols(U8 value) {
|
||||
|
||||
inline U8
|
||||
base64(U8 value) {
|
||||
read_only local_persist
|
||||
local_persist
|
||||
U8 lookup_table[64] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
@@ -176,7 +176,7 @@ base64(U8 value) {
|
||||
|
||||
inline U8
|
||||
base64_reverse(U8 value) {
|
||||
read_only local_persist
|
||||
local_persist
|
||||
U8 lookup_table[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
@@ -193,8 +193,8 @@ base64_reverse(U8 value) {
|
||||
// NOTE(allen): Includes reverses for uppercase and lowercase hex.
|
||||
inline U8
|
||||
integer_symbol_reverse(U8 value) {
|
||||
read_only local_persist
|
||||
lookup_table[128] = {
|
||||
local_persist
|
||||
U8 lookup_table[128] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
|
||||
@@ -839,7 +839,7 @@ force_inline String8 str8_path_list_join_by_style__arena(Arena* arena, String8Li
|
||||
inline U8
|
||||
utf8_class(U8 value)
|
||||
{
|
||||
read_only local_persist
|
||||
local_persist
|
||||
U8 lookup_table[32] = {
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,2,2,2,2,3,3,4,5,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/*
|
||||
▀██▀▀█▄
|
||||
██ ██ ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
|
||||
██▀▀▀█▄ ▀▀ ▄██ ██▄ ▀ ▄█▄▄▄██
|
||||
██ ██ ▄█▀ ██ ▄ ▀█▄▄ ██
|
||||
▄██▄▄▄█▀ ▀█▄▄▀█▀ █▀▄▄█▀ ▀█▄▄▄▀
|
||||
*/
|
||||
@@ -38,12 +38,12 @@ word expect, md_expect
|
||||
word likely, md_likely
|
||||
word unlikely, md_unlikely
|
||||
|
||||
word ccast, word md_ccast
|
||||
word pcast, word md_pcast
|
||||
word rcast, word md_rcast
|
||||
word scast, word md_scast
|
||||
word ccast, md_ccast
|
||||
word pcast, md_pcast
|
||||
word rcast, md_rcast
|
||||
word scast, md_scast
|
||||
|
||||
// word typeof, word md_typeof
|
||||
// word typeof, md_typeof
|
||||
|
||||
word enum_underlying, md_enum_underlying
|
||||
word nullptr, md_nullptr
|
||||
@@ -1078,9 +1078,6 @@ word tag_count_from_node, md_tag_count_from_node
|
||||
|
||||
namespace string_from_children_, md_string_from_children_
|
||||
|
||||
word tree_match, md_tree_match
|
||||
word node_match, md_node_match
|
||||
|
||||
namespace tree_copy_, md_tree_copy_
|
||||
word tree_copy, md_treecopy
|
||||
namespace tokenize_from_text_, md_tokenize_from_text_
|
||||
|
||||
+120
-13
@@ -2,7 +2,11 @@
|
||||
|
||||
#include "gen_common.h"
|
||||
|
||||
#define path_refactor_script "./c11.refactor"
|
||||
#ifndef PRINT_SECTION_REGION_PRAGMAS
|
||||
#define PRINT_SECTION_REGION_PRAGMAS 1
|
||||
#endif
|
||||
|
||||
#define path_refactor_script path_gen_c11 "c11.refactor"
|
||||
|
||||
gen_Code refactor( gen_Code code ) {
|
||||
return code_refactor_and_format(code, path_scratch_file, path_refactor_script, nullptr );
|
||||
@@ -11,6 +15,15 @@ gen_Code refactor_and_format( gen_Code code ) {
|
||||
return code_refactor_and_format(code, path_scratch_file, path_refactor_script, path_format_style );
|
||||
}
|
||||
|
||||
#define str_fmt(fmt, ...) gen_strbuilder_to_str(gen_strbuilder_fmt_buf(gen_get_context()->Allocator_Temp, fmt, __VA_ARGS__))
|
||||
|
||||
void print_section(gen_Builder* builder, gen_Code code, gen_Str label) {
|
||||
if (PRINT_SECTION_REGION_PRAGMAS) gen_builder_print(builder, gen_def_pragma(str_fmt("region %S", label)) );
|
||||
gen_builder_print(builder, code);
|
||||
if (PRINT_SECTION_REGION_PRAGMAS) gen_builder_print(builder, gen_def_pragma(str_fmt("endregion %S", label)) );
|
||||
gen_builder_print(builder, gen_fmt_newline);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
gen_Context ctx = {0};
|
||||
@@ -65,35 +78,129 @@ int main()
|
||||
gen_Code base_entry_point_h = gen_scan_file(path_base "entry_point.h");
|
||||
gen_Code base_file_h = gen_scan_file(path_base "file.h");
|
||||
|
||||
gen_Code os_h = gen_scan_file(path_os "os.h");
|
||||
gen_Code os_win32_includes_h = gen_scan_file(path_os_win32 "os_win32_includes.h");
|
||||
gen_Code os_win32_h = gen_scan_file(path_os_win32 "os_win32.h");
|
||||
gen_Code os_linux_includes_h = gen_scan_file(path_os_linux "os_linux_includes.h");
|
||||
gen_Code os_linux_h = gen_scan_file(path_os_linux "os_linux.h");
|
||||
gen_Code os_h = gen_scan_file(path_os "os.h");
|
||||
gen_Code os_win32_includes_h = gen_scan_file(path_os_win32 "os_win32_includes.h");
|
||||
gen_Code os_win32_h = gen_scan_file(path_os_win32 "os_win32.h");
|
||||
gen_Code os_linux_includes_h = gen_scan_file(path_os_linux "os_linux_includes.h");
|
||||
gen_Code os_linux_h = gen_scan_file(path_os_linux "os_linux.h");
|
||||
|
||||
#pragma region Refactored / Formatted
|
||||
gen_Code r_tp_stb_sprintf_h = refactor(tp_stb_sprintf_h);
|
||||
|
||||
gen_Code r_base_context_cracking_h = refactor(base_context_cracking_h);
|
||||
gen_Code r_base_platform_h = refactor(base_platform_h);
|
||||
gen_Code r_base_linkage_h = refactor(base_linkage_h);
|
||||
gen_Code r_base_macros_h = refactor(base_macros_h);
|
||||
gen_Code r_base_generic_macros_h = refactor(base_generic_macros_h);
|
||||
gen_Code r_base_profiling_h = refactor(base_profiling_h);
|
||||
gen_Code r_base_base_types_h = refactor(base_base_types_h);
|
||||
gen_Code r_base_ring_h = refactor(base_ring_h);
|
||||
gen_Code r_base_debug_h = refactor(base_debug_h);
|
||||
gen_Code r_base_memory_h = refactor(base_memory_h);
|
||||
gen_Code r_base_memory_substrate_h = refactor(base_memory_substrate_h);
|
||||
gen_Code r_base_arena_h = refactor(base_arena_h);
|
||||
gen_Code r_base_space_h = refactor(base_space_h);
|
||||
gen_Code r_base_math_h = refactor_and_format(base_math_h);
|
||||
gen_Code r_base_sort_h = refactor(base_sort_h);
|
||||
gen_Code r_base_toolchain_h = refactor(base_toolchain_h);
|
||||
gen_Code r_base_time_h = refactor(base_time_h);
|
||||
gen_Code r_base_strings_h = refactor_and_format(base_strings_h);
|
||||
gen_Code r_base_text_h = refactor(base_text_h);
|
||||
gen_Code r_base_thread_context_h = refactor(base_thread_context_h);
|
||||
gen_Code r_base_command_line_h = refactor(base_command_line_h);
|
||||
gen_Code r_base_markup_h = refactor(base_markup_h);
|
||||
gen_Code r_base_logger_h = refactor(base_logger_h);
|
||||
gen_Code r_base_entry_point_h = refactor(base_entry_point_h);
|
||||
gen_Code r_base_file_h = refactor(base_file_h);
|
||||
|
||||
gen_Code r_os_h = refactor(os_h);
|
||||
gen_Code r_os_win32_includes_h = refactor(os_win32_includes_h);
|
||||
gen_Code r_os_win32_h = refactor(os_win32_h);
|
||||
gen_Code r_os_linux_includes_h = refactor(os_linux_includes_h);
|
||||
gen_Code r_os_linux_h = refactor(os_linux_h);
|
||||
#pragma endregion Refactored / Formatted
|
||||
|
||||
// Singleheader
|
||||
{
|
||||
gen_Builder header_ = gen_builder_open(path_gen "metadesk_singleheader.h");
|
||||
gen_Builder* header = & header_;
|
||||
|
||||
#define print(code) gen_builder_print(header, code);
|
||||
#define print_fmt(fmt, ...) gen_builder_print_fmt(header, fmt, __VA_ARGS__)
|
||||
#define new_line() gen_builder_print(header, gen_fmt_newline)
|
||||
#define pragma_region(label) print(gen_def_pragma(str_fmt("region %S", lit(label))))
|
||||
#define pragma_endregion(label) print(gen_def_pragma(str_fmt("endregion %S", lit(label))))
|
||||
#define define gen_def_define
|
||||
#define preprocess_cond(type, expr) gen_def_preprocess_cond(type, expr)
|
||||
|
||||
gen_Str implementation_guard_start = lit(
|
||||
"\n"
|
||||
"#pragma region METADESK IMPLEMENTATION GUARD\n"
|
||||
// "#pragma region METADESK IMPLEMENTATION GUARD\n"
|
||||
"#if defined(MD_IMPLEMENTATION) && ! defined(MD_IMPLEMENTED)\n"
|
||||
"#define MD_IMPLEMENTED\n"
|
||||
"\n"
|
||||
);
|
||||
gen_Str implementation_guard_end = lit(
|
||||
"\n"
|
||||
"// END: MD_IMPLEMENTATION\n"
|
||||
"#endif\n"
|
||||
"#pragma endregion METADESK IMPLEMENTATION GUARD\n"
|
||||
"\n"
|
||||
// "#pragma endregion METADESK IMPLEMENTATION GUARD\n"
|
||||
);
|
||||
|
||||
// Header files
|
||||
|
||||
gen_builder_print_fmt(header, "%S", generation_notice);
|
||||
print_fmt("%S", generation_notice);
|
||||
print_fmt("%S", lit("#pragma once\n\n"));
|
||||
|
||||
print(gen_scan_file(path_gen_c11 "header_start.h"));
|
||||
new_line();
|
||||
|
||||
pragma_region("Base");
|
||||
print(gen_scan_file(path_gen_c11 "base_banner.h"));
|
||||
new_line();
|
||||
new_line();
|
||||
|
||||
print_section(header, r_base_context_cracking_h, lit("Context Cracking"));
|
||||
print_section(header, r_base_platform_h, lit("platform"));
|
||||
print_section(header, r_base_linkage_h, lit("Linkage"));
|
||||
print_section(header, r_base_macros_h, lit("Macros"));
|
||||
print_section(header, r_base_generic_macros_h, lit("_Generic Macros"));
|
||||
print_section(header, r_base_profiling_h, lit("Profiling"));
|
||||
|
||||
define(lit("STB_SPRINTF_IMPLEMENTATION"), MT_Statement);
|
||||
print_fmt("%S", implementation_guard_start);
|
||||
print(gen_def_define(lit("STB_SPRINTF_DECORATE(name)"), MT_Expression, .content = lit("md_##name")));
|
||||
// print();
|
||||
print(preprocess_cond(PreprocessCond_If, lit("MD_BUILD_STATIC"))); new_line(); {
|
||||
define(lit("STB_BUILD_STATIC"), MT_Statement);
|
||||
}
|
||||
print(gen_preprocess_endif);
|
||||
new_line();
|
||||
|
||||
print_section(header, r_tp_stb_sprintf_h, lit("STB snprintf Header"));
|
||||
print_fmt("%S", implementation_guard_end);
|
||||
new_line();
|
||||
|
||||
print_section(header, r_base_base_types_h, lit("Types"));
|
||||
print_section(header, r_base_ring_h, lit("Ring"));
|
||||
print_section(header, r_base_debug_h, lit("Debug"));
|
||||
print_section(header, r_base_memory_h, lit("Memory"));
|
||||
print_section(header, r_base_memory_substrate_h, lit("Memory Substrate"));
|
||||
print_section(header, r_base_arena_h, lit("Arena"));
|
||||
print_section(header, r_base_space_h, lit("Space"));
|
||||
print_section(header, r_base_math_h, lit("Math"));
|
||||
print_section(header, r_base_sort_h, lit("Sort"));
|
||||
print_section(header, r_base_toolchain_h, lit("Toolchain"));
|
||||
print_section(header, r_base_time_h, lit("Time"));
|
||||
print_section(header, r_base_strings_h, lit("strings"));
|
||||
print_section(header, r_base_text_h, lit("Text"));
|
||||
print_section(header, r_base_thread_context_h, lit("Thread Context"));
|
||||
print_section(header, r_base_command_line_h, lit("Command Line"));
|
||||
print_section(header, r_base_markup_h, lit("Markup"));
|
||||
print_section(header, r_base_logger_h, lit("Logger"));
|
||||
print_section(header, r_base_entry_point_h, lit("Entry Point"));
|
||||
print_section(header, r_base_file_h, lit("File"));
|
||||
|
||||
pragma_endregion("Base");
|
||||
|
||||
|
||||
|
||||
gen_builder_write(header);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
╔────────────────────────────────────────────────────────────────────────────────────────────────────────────╗
|
||||
│ │
|
||||
│ 88b d88 88 88 │
|
||||
│ 888b d888 ,d 88 88 │
|
||||
│ 88`8b d8'88 88 88 88 │
|
||||
│ 88 `8b d8' 88 ,adPPYba, MM88MMM ,adPPYYba, ,adPPYb,88 ,adPPYba, ,adPPYba, 88 ,d8 │
|
||||
│ 88 `8b d8' 88 a8P_____88 88 "" `Y8 a8" `Y88 a8P_____88 I8[ "" 88 ,a8" │
|
||||
│ 88 `8b d8' 88 8PP""""""" 88 ,adPPPPP88 8b 88 8PP""""""" `"Y8ba, 8888[ │
|
||||
│ 88 `888' 88 "8b, ,aa 88, 88, ,88 "8a, ,d88 "8b, ,aa aa ]8I 88`"Yba, │
|
||||
│ 88 `8' 88 `"Ybbd8"' "Y888 `"8bbdP"Y8 `"8bbdP"Y8 `"Ybbd8"' `"YbbdP"' 88 `Y8a │
|
||||
│ │
|
||||
╚────────────────────────────────────────────────────────────────────────────────────────────────────────────╝
|
||||
/ \-------------------------,
|
||||
\_,| |
|
||||
| Single-header C11 |
|
||||
| ,-----------------------
|
||||
\_/______________________/
|
||||
*/
|
||||
Vendored
+5
-3
@@ -9634,8 +9634,8 @@ struct gen_Opts_def_define
|
||||
};
|
||||
typedef struct gen_Opts_def_define gen_Opts_def_define;
|
||||
|
||||
GEN_API gen_CodeDefine gen_def__define(gen_Str name, gen_MacroType type, gen_Opts_def_define opts GEN_PARAM_DEFAULT);
|
||||
#define gen_def_define(name, type, ...) gen_def__define(name, type, (gen_Opts_def_define) { __VA_ARGS__ })
|
||||
GEN_API gen_CodeDefine gen_def__define(gen_Str name, gen_MacroType type, gen_Opts_def_define* opts GEN_PARAM_DEFAULT);
|
||||
#define gen_def_define(name, type, ...) gen_def__define(name, type, & (gen_Opts_def_define) { __VA_ARGS__ })
|
||||
|
||||
struct gen_Opts_def_destructor
|
||||
{
|
||||
@@ -18579,8 +18579,10 @@ gen_CodeClass gen_def__class(gen_Str name, gen_Opts_def_struct p)
|
||||
return result;
|
||||
}
|
||||
|
||||
gen_CodeDefine gen_def__define(gen_Str name, gen_MacroType type, gen_Opts_def_define p)
|
||||
gen_CodeDefine gen_def__define(gen_Str name, gen_MacroType type, gen_Opts_def_define* opts)
|
||||
{
|
||||
gen_Opts_def_define p = opts ? *opts : (gen_Opts_def_define){0};
|
||||
|
||||
if (! name_check(gen_def_define, name))
|
||||
{
|
||||
GEN_DEBUG_TRAP();
|
||||
|
||||
Reference in New Issue
Block a user