From b67dc566c665334ba921fbe86a1a89261dda0c2c Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 9 Oct 2021 22:34:41 -0700 Subject: [PATCH] [examples] tweaks to overrides example and commentary --- bin/build_examples.sh | 8 +++----- bin/run_examples.sh | 18 ++++++++---------- examples/expr/expr_intro.mdesk | 2 +- examples/integration/overrides.c | 26 ++++++++++++++++++++++---- source/md.c | 2 +- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/bin/build_examples.sh b/bin/build_examples.sh index 2bd4f5a..9b27674 100755 --- a/bin/build_examples.sh +++ b/bin/build_examples.sh @@ -11,11 +11,6 @@ bin/bld_core.sh show_ctx examps="examples" -bin/bld_core.sh unit expr_intro $examps/expr/expr_intro.c -bin/bld_core.sh unit expr_c_like $examps/expr/expr_c_like.c - -exit - bin/bld_core.sh unit hello_world $examps/intro/hello_world.c bin/bld_core.sh unit parse_check $examps/intro/parse_check.c bin/bld_core.sh unit data_desk_like $examps/intro/data_desk_like_template.c @@ -26,6 +21,9 @@ if [ -d $examps/type_metadata/generated/type_info_meta.h ]; then bin/bld_core.sh unit type_info $examps/type_metadata/type_info_final_program.c fi +bin/bld_core.sh unit expr_intro $examps/expr/expr_intro.c +bin/bld_core.sh unit expr_c_like $examps/expr/expr_c_like.c + bin/bld_core.sh unit overrides $examps/integration/overrides.c echo diff --git a/bin/run_examples.sh b/bin/run_examples.sh index c507880..54c6d51 100755 --- a/bin/run_examples.sh +++ b/bin/run_examples.sh @@ -8,16 +8,6 @@ root_path=$PWD build_path=$root_path/build examps=$root_path/examples -echo ~~~ Running Expression Intro ~~~ -$build_path/expr_intro.exe $examps/expr/expr_intro.mdesk -echo - -echo ~~~ Running C Like Expression ~~~ -$build_path/expr_c_like.exe $examps/expr/expr_c_like.mdesk -echo - -exit - echo ~~~ Running Type Metadata Generator Example ~~~ cd $examps/type_metadata/generated $build_path/type_metadata.exe $examps/type_metadata/types.mdesk @@ -26,5 +16,13 @@ echo echo ~~~ Running Error Generation Example ~~~ $build_path/user_errors.exe $examps/user_errors/user_errors.mdesk +echo ~~~ Running Expression Intro ~~~ +$build_path/expr_intro.exe $examps/expr/expr_intro.mdesk +echo + +echo ~~~ Running C Like Expression ~~~ +$build_path/expr_c_like.exe $examps/expr/expr_c_like.mdesk +echo + ###### Restore Path ########################################################### cd $og_path diff --git a/examples/expr/expr_intro.mdesk b/examples/expr/expr_intro.mdesk index 8bebe5f..f8f4012 100644 --- a/examples/expr/expr_intro.mdesk +++ b/examples/expr/expr_intro.mdesk @@ -11,4 +11,4 @@ c: 3; w: 100; x: a; y: b + w*a; -z: (c + w*(b + w*a)); +z: c + w*b + w*w*a; diff --git a/examples/integration/overrides.c b/examples/integration/overrides.c index c48c038..1068746 100644 --- a/examples/integration/overrides.c +++ b/examples/integration/overrides.c @@ -40,11 +40,24 @@ void examp_free(ExampleAllocator *a, void *ptr); //~ include metadesk header /////////////////////////////////////////////////// +// @notes Disabling print helpers removes any APIs from the library that depend +// on FILE from stdio.h. +#define MD_DISABLE_PRINT_HELPERS 1 + +// @notes Here is also a good place to disable the default implementations of +// anything that is overriden to avoid extra includes. +#define MD_DEFAULT_MEMORY 0 +#define MD_DEFAULT_FILE_LOAD 0 + +// @notes We can also disable default implementations for "optional" parts, +// here we disable the default file iterator without replacing it, which gets +// this example off of direct OS header dependencies. +#define MD_DEFAULT_FILE_ITER 0 + // @notes We include the metadesk header before we define the overrides because // some overrides require that metadesk base types be visible. There are // exceptions to this pattern, in particular overrides for types need to be // defined before including md.h, we aren't going that far here. - #include "md.h" @@ -126,6 +139,8 @@ md_release_by_example_allocator(void *ptr, unsigned long long ignore) // override file loading +#include + MD_String8 md_load_entire_file_by_stdio(MD_Arena *arena, MD_String8 filename) { @@ -151,16 +166,19 @@ md_load_entire_file_by_stdio(MD_Arena *arena, MD_String8 filename) int main(int argc, char **argv) { + // ... where ever program init stuff is happening ... + // initialize the example allocator ExampleAllocator allocator = {0}; - // configure the allocator context + // metadesk allocator context gets setup before a call to MD_ArenaAlloc md_example_allocator = &allocator; - // setup the global arena arena = MD_ArenaAlloc(); - // ... any normal metadesk usage may go here ... + + + // ... any normal metadesk usage may now happen ... return 0; diff --git a/source/md.c b/source/md.c index 9e17ed8..b8754f6 100644 --- a/source/md.c +++ b/source/md.c @@ -127,7 +127,7 @@ MD_CRT_LoadEntireFile(MD_Arena *arena, MD_String8 filename) //////////////////////////////////////////////////////////////////////////////// //- win32 header -#if (MD_DEFAULT_FILE_ITER || MD_DEFAULT_MEMORY) && MD_OS_WINDOWS +#if (MD_DEFAULT_FILE_ITER || MD_2DEFAULT_MEMORY) && MD_OS_WINDOWS # include # pragma comment(lib, "User32.lib") #endif