mirror of
https://github.com/Ed94/metadesk.git
synced 2026-06-12 23:51:37 -07:00
attempting to do a parse on stb_sprintf.h for segregated
This commit is contained in:
Vendored
+21
@@ -19,6 +19,27 @@
|
||||
"compilerArgs": [
|
||||
"/Zc:preprocessor"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Win32 tests",
|
||||
"includePath": [
|
||||
// "${workspaceFolder}",
|
||||
"${workspaceFolder}/gen_c11/gen"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"windowsSdkVersion": "10.0.22621.0",
|
||||
"compilerPath": "cl.exe",
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compilerArgs": [
|
||||
"/Zc:preprocessor"
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
||||
Vendored
+3
-1
@@ -88,7 +88,9 @@
|
||||
"gen_common.h": "c",
|
||||
"processthreadsapi.h": "c",
|
||||
"timeapi.h": "c",
|
||||
"stdlib.h": "c"
|
||||
"stdlib.h": "c",
|
||||
"metadesk_deps.h": "c",
|
||||
"stdbool.h": "c"
|
||||
},
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#713fb8",
|
||||
|
||||
@@ -43,6 +43,7 @@ $release = $null
|
||||
[bool] $code_sanity = $false
|
||||
[bool] $compile_sanity = $false
|
||||
[bool] $gen_c11 = $false
|
||||
[bool] $tests = $false
|
||||
|
||||
[array] $vendors = @( "clang", "msvc" )
|
||||
|
||||
@@ -57,6 +58,7 @@ if ( $args ) { $args | ForEach-Object {
|
||||
"code_sanity" { $code_sanity = $true }
|
||||
"compile_sanity" { $compile_sanity = $true }
|
||||
"gen_c11" { $gen_c11 = $true }
|
||||
"tests" { $tests = $true }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +88,9 @@ else {
|
||||
$cannot_build = $code_sanity -eq $false
|
||||
$cannot_build = $cannot_build -and $compile_sanity -eq $false
|
||||
$cannot_build = $cannot_build -and $gen_c11 -eq $false
|
||||
$cannot_build = $cannot_build -and $test -eq $false
|
||||
if ( $cannot_build ) {
|
||||
Pop-Location
|
||||
throw "No build target specified. One must be specified, this script will not assume one"
|
||||
}
|
||||
|
||||
@@ -190,4 +194,38 @@ if ($gen_c11)
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
|
||||
if ($tests)
|
||||
{
|
||||
write-host " Bulding tests/c11_sanity.c"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += $flag_all_c
|
||||
$compiler_args += $flag_updated_cpp_macro
|
||||
$compiler_args += $flag_c11
|
||||
|
||||
$linker_args = @()
|
||||
$linker_args += $flag_link_win_subsystem_console
|
||||
|
||||
$path_gen = join-path $path_gen_c11 'gen'
|
||||
|
||||
$includes = @( $path_gen, $path_root )
|
||||
$unit = join-path $path_tests 'c11_sanity.c'
|
||||
$executable = join-path $path_build 'c11_sanity.exe'
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_root
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning tests/c11_sanity.exe"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`ntest/code_sanity completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Pop-Location # $path_root
|
||||
|
||||
@@ -27,6 +27,10 @@ namespace OS_, MD_OS_
|
||||
|
||||
word HAS_ATTRIBUTE, MD_HAS_ATTRIBUTE
|
||||
|
||||
// base/platform.h
|
||||
|
||||
include assert, assert
|
||||
|
||||
// base/linkage.h
|
||||
|
||||
word global, md_global
|
||||
@@ -1094,6 +1098,8 @@ namespace FilePropertyFlag_, MD_FilePropertyFlag_
|
||||
namespace OS_, MD_OS_
|
||||
namespace os_, md_os_
|
||||
|
||||
word os_ctx, os_ctx
|
||||
|
||||
namespace entry_point, md_entry_point
|
||||
|
||||
// metadesk module
|
||||
@@ -1168,6 +1174,12 @@ word parse_from_text, md_parse_from_text
|
||||
namespace debug_string_list_from_tree_, md_debug_string_list_from_tree_
|
||||
word debug_string_list_from_tree, md_debug_string_list_from_tree
|
||||
|
||||
word ParseWorkKind, MD_ParseWorkKind
|
||||
word ParseWorkNode, MD_ParseWorkNode
|
||||
|
||||
word parse__work_push, md_parse__work_push
|
||||
word parse__work_pop, md_parse__work_pop
|
||||
|
||||
// metagen module
|
||||
|
||||
|
||||
|
||||
+22
-6
@@ -22,6 +22,8 @@ gen_Code refactor_and_format( gen_Code code ) {
|
||||
int main()
|
||||
{
|
||||
gen_Context ctx = {0};
|
||||
ctx.InitSize_MacrosTable = gen_kilobytes(64);
|
||||
ctx.InitSize_StrCacheTable = gen_kilobytes(64);
|
||||
gen_init(& ctx);
|
||||
|
||||
register_library_macros();
|
||||
@@ -84,7 +86,7 @@ int main()
|
||||
|
||||
gen_Code mdesk_h = gen_scan_file(path_mdesk "mdesk.h");
|
||||
|
||||
gen_Code base_platfom_c = gen_scan_file(path_base "platform.c");
|
||||
gen_Code base_platform_c = gen_scan_file(path_base "platform.c");
|
||||
gen_Code base_debug_c = gen_scan_file(path_base "debug.c");
|
||||
gen_Code base_memory_substrate_c = gen_scan_file(path_base "memory_substrate.c");
|
||||
gen_Code base_arena_c = gen_scan_file(path_base "arena.c");
|
||||
@@ -140,7 +142,7 @@ int main()
|
||||
|
||||
gen_Code r_mdesk_h = refactor_and_format(mdesk_h);
|
||||
|
||||
gen_Code r_base_platform_c = refactor(base_platfom_c);
|
||||
gen_Code r_base_platform_c = refactor(base_platform_c);
|
||||
gen_Code r_base_debug_c = refactor(base_debug_c);
|
||||
gen_Code r_base_memory_substrate_c = refactor(base_memory_substrate_c);
|
||||
gen_Code r_base_arena_c = refactor(base_arena_c);
|
||||
@@ -158,6 +160,7 @@ int main()
|
||||
gen_Code r_os_c = refactor(os_os_c);
|
||||
|
||||
gen_Code r_mdesk_c = refactor_and_format(mdesk_c);
|
||||
|
||||
#pragma endregion Refactored / Formatted
|
||||
|
||||
if (GENERATE_SINGLEHEADER)
|
||||
@@ -295,6 +298,7 @@ int main()
|
||||
new_line();
|
||||
|
||||
print_section(r_base_platform_c, lit("Platform"));
|
||||
print_section(r_base_debug_c, lit("Debug"));
|
||||
print_section(r_base_memory_substrate_c, lit("Memory Substrate"));
|
||||
print_section(r_base_arena_c, lit("Arena"));
|
||||
print_section(r_base_strings_c, lit("Strings"));
|
||||
@@ -344,6 +348,20 @@ int main()
|
||||
|
||||
if (GENERATE_SEGEREGATED)
|
||||
{
|
||||
gen_CodeBody tb_stb_printf_h_parsed = gen_parse_file(path_third_party "stb/stb_sprintf.h");
|
||||
gen_CodeBody tb_stb_printf_header = gen_def_body(CT_Global_Body);
|
||||
gen_CodeBody tb_stb_printf_source = gen_def_body(CT_Global_Body);
|
||||
|
||||
for (gen_Code stb_code = gen_iterator(CodeBody, tb_stb_printf_h_parsed, stb_code)) switch(stb_code->Type)
|
||||
{
|
||||
case CT_Preprocess_Define:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Dependencies
|
||||
|
||||
#define builder header_deps
|
||||
@@ -447,10 +465,7 @@ int main()
|
||||
include(lit("metadesk_deps.h"));
|
||||
|
||||
print(r_mdesk_h);
|
||||
|
||||
print(banner_mdesk);
|
||||
new_line(); new_line();
|
||||
|
||||
new_line();
|
||||
gen_builder_write(header);
|
||||
#undef builder
|
||||
|
||||
@@ -479,6 +494,7 @@ int main()
|
||||
new_line();
|
||||
|
||||
print_section(r_base_platform_c, lit("Platform"));
|
||||
print_section(r_base_debug_c, lit("Debug"));
|
||||
print_section(r_base_memory_substrate_c, lit("Memory Substrate"));
|
||||
print_section(r_base_arena_c, lit("Arena"));
|
||||
print_section(r_base_strings_c, lit("Strings"));
|
||||
|
||||
+52
-1
@@ -26,6 +26,11 @@
|
||||
#define path_scratch_file path_gen "scratch.h"
|
||||
#define path_format_style path_bin ".clang-format "
|
||||
|
||||
#define gen_iterator( Type, container, iter ) \
|
||||
gen_begin_ ## Type(container); \
|
||||
iter != gen_end_ ## Type(container); \
|
||||
iter = gen_next_ ## Type(container, iter)
|
||||
|
||||
// Codegen DSL
|
||||
|
||||
#define lit gen_txt
|
||||
@@ -61,6 +66,53 @@ void print__section(gen_Builder* builder, gen_Code code, gen_Str label) {
|
||||
|
||||
void register_library_macros()
|
||||
{
|
||||
// third_party/stb/stb_sprintf.h
|
||||
gen_register_macros( args(
|
||||
((gen_Macro) { lit("STB_SPRINTF_H_INCLUDE"), MT_Statement, }),
|
||||
((gen_Macro) { lit("STBSP__ASAN"), MT_Statement, }),
|
||||
((gen_Macro) { lit("STBSP__PUBLICDEC"), MT_Statement, MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__ATTRIBUTE_FORMAT"), MT_Statement, MF_Functional | MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__NOTUSED"), MT_Expression, MF_Functional | MF_Allow_As_Attribute }),
|
||||
((gen_Macro) { lit("STBSP__NOTUSED"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("STB_SPRINTF_MIN"), MT_Expression, MF_Allow_As_Identifier }),
|
||||
((gen_Macro) { lit("STB_SPRINTF_DECORATE"), MT_Expression, MF_Functional | MF_Allow_As_Identifier }),
|
||||
((gen_Macro) { lit("stbsp__uint32"), MT_Expression, }),
|
||||
((gen_Macro) { lit("stbsp__int32"), MT_Expression, }),
|
||||
((gen_Macro) { lit("stbsp__uint64"), MT_Expression, }),
|
||||
((gen_Macro) { lit("stbsp__int64"), MT_Expression, }),
|
||||
((gen_Macro) { lit("stbsp__uint16"), MT_Expression, }),
|
||||
((gen_Macro) { lit("stbsp__uintptr"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STB_SPRINTF_MSVC_MODE"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__PUBLICDEF"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__UNALIGNED"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("STBSP__SPECIAL"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__LEFTJUST"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__LEADINGPLUS"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__LEADINGSPACE"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__LEADING_0X"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__LEADINGZERO"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__INTMAX"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__TRIPLET_COMMA"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__NEGATIVE"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__METRIC_SUFFIX"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__HALFWIDTH"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__METRIC_NOSPACE"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__METRIC_1024"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__METRIC_JEDEC"), MT_Expression, }),
|
||||
((gen_Macro) { lit("stbsp__chk_cb_bufL"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__chk_cb_buf"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__flush_cb"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__cb_buf_clamp"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("STBSP__NUMSZ"), MT_Expression, }),
|
||||
((gen_Macro) { lit("STBSP__COPYFP"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__tento19th"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__ddmulthi"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__ddrenorm"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__ddmultlo"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__ddmultlos"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("stbsp__ddtoS64"), MT_Expression, MF_Functional })
|
||||
));
|
||||
|
||||
// These in the same order as metadesk.h
|
||||
|
||||
// base/context_cracking.h
|
||||
@@ -578,7 +630,6 @@ void register_library_macros()
|
||||
gen_register_macro((gen_Macro) { lit("quick_sort"), MT_Expression, MF_Functional });
|
||||
// base/strings.h
|
||||
gen_register_macros(args(
|
||||
((gen_Macro) { lit("STB_SPRINTF_DECORATE"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("cstring_length"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("str8_lit"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro) { lit("str8_lit_comp"), MT_Expression, MF_Functional }),
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// This is tests both the segregated and single-header libraris
|
||||
|
||||
#if TEST_SINGLEHEADER
|
||||
#define MD_IMPLEMENTATION
|
||||
#include "metadesk_singleheader.h"
|
||||
#else
|
||||
#include "metadesk_deps.c"
|
||||
#include "metadesk.c"
|
||||
#endif
|
||||
|
||||
// This program expects to be run from the build directory (where it would be after being built)
|
||||
#define path_root
|
||||
#define path_examples path_root ".examples/"
|
||||
#define path_intro path_examples "intro/"
|
||||
#define path_hello_world_mdesk path_intro "hello_world.mdesk"
|
||||
|
||||
#define lit md_str8_lit
|
||||
|
||||
int main()
|
||||
{
|
||||
MD_Context ctx = {0};
|
||||
ctx.os_ctx.enable_large_pages = true;
|
||||
md_init(& ctx);
|
||||
|
||||
printf("metadesk: got past init!\n");
|
||||
|
||||
MD_Arena* arena = md_arena_alloc();
|
||||
MD_String8 hello_world_mdesk = md_os_data_from_file_path(arena, lit(path_hello_world_mdesk));
|
||||
|
||||
MD_TokenizeResult lexed = md_tokenize_from_text (arena, hello_world_mdesk);
|
||||
MD_ParseResult parsed = md_parse_from_text_tokens(arena, lit(path_hello_world_mdesk), hello_world_mdesk, lexed.tokens);
|
||||
|
||||
#define md_str8_list_iter(list, elem) list.first; elem; elem = elem->next
|
||||
MD_String8List debug_list = md_debug_string_list_from_tree(arena, parsed.root);
|
||||
|
||||
printf("Parsed listing:\n");
|
||||
for (MD_String8Node* elem = md_str8_list_iter(debug_list, elem))
|
||||
{
|
||||
MD_String8 entry = elem->string;
|
||||
if (md_str8_find_needle(entry, 0, lit("\n"), 0) < entry.size) {
|
||||
printf("%*s", (int)entry.size, entry.str);
|
||||
}
|
||||
else {
|
||||
printf("%*s\n", (int)entry.size, entry.str);
|
||||
}
|
||||
}
|
||||
|
||||
md_deinit(& ctx);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user