From 3f5d4a96a9a6bdaaa0928263e1a8c351684f59fc Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 25 Sep 2021 17:37:33 -0700 Subject: [PATCH] [bld] setup new feature for include path management --- bin/bld_core.sh | 26 +++++++----- bin/build_examples.sh | 3 +- bin/compiler_flags.txt | 1 + bin/compiler_inc_paths.txt | 2 + bin/run_examples.sh | 3 +- bin/type_info_example.sh | 40 +++++++++++++++++++ .../type_metadata/type_info_final_program.c | 4 +- examples/type_metadata/type_metadata.c | 7 +++- project.4coder | 22 ++++++++-- 9 files changed, 88 insertions(+), 20 deletions(-) create mode 100644 bin/compiler_inc_paths.txt create mode 100644 bin/type_info_example.sh diff --git a/bin/bld_core.sh b/bin/bld_core.sh index d2b8b66..53236f0 100755 --- a/bin/bld_core.sh +++ b/bin/bld_core.sh @@ -186,21 +186,29 @@ function bld_compile { ###### finith in file ##################################################### local final_in_file=$root_path/$in_file - ###### finish options ##################################################### - local src_opts=($(bld_opts_from_src $final_in_file)) - local all_opts=($(bld_dedup ${opts[@]} ${src_opts[@]})) - - ###### diagnostics ######################################################## - local diagnostics=$(bld_has_opt diagnostics ${all_opts[@]}) - ###### out file name ###################################################### local file_base=${final_in_file##*/} local file_base_no_ext=${file_base%.*} local out_file="$file_base_no_ext$dot_ext_obj" + ###### finish options ##################################################### + local src_opts=($(bld_opts_from_src $final_in_file)) + local all_opts=($(bld_dedup $file_base ${opts[@]} ${src_opts[@]})) + + ###### diagnostics ######################################################## + local diagnostics=$(bld_has_opt diagnostics ${all_opts[@]}) + ###### get real flags ##################################################### local flags_file=$bin_path/compiler_flags.txt - local flags=$(bld_flags_from_opts $flags_file ${all_opts[@]}) + local flags=($(bld_flags_from_opts $flags_file ${all_opts[@]})) + + ###### get inc paths ###################################################### + local paths_file=$bin_path/compiler_inc_paths.txt + local paths=($(bld_flags_from_opts $paths_file ${all_opts[@]})) + local incs=() + for ((i=0; i<${#paths[@]}; i+=1)); do + incs+=("-I$root_path/${paths[i]}") + done ###### move to output folder ############################################## mkdir -p "$build_path" @@ -211,7 +219,7 @@ function bld_compile { rm -f "$out_file_base.obj" ###### get flags ########################################################## - local all_flags="-c -I$src_path ${flags}" + local all_flags="-c -I$src_path ${incs[@]} ${flags[@]}" ###### diagnostic output ################################################## if [ "$diagnostics" == "1" ]; then diff --git a/bin/build_examples.sh b/bin/build_examples.sh index e798cc0..ab7b9cd 100755 --- a/bin/build_examples.sh +++ b/bin/build_examples.sh @@ -11,16 +11,17 @@ bin/bld_core.sh show_ctx examps="examples" -bin/bld_core.sh unit type_metadata $examps/type_metadata/type_metadata.c 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 datadesk_like $examps/intro/datadesk_like_template.c bin/bld_core.sh unit user_errors $examps/user_errors/user_errors.c +bin/bld_core.sh unit type_metadata $examps/type_metadata/type_metadata.c 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 + echo ###### Restore Path ########################################################### diff --git a/bin/compiler_flags.txt b/bin/compiler_flags.txt index 63391f9..f64d365 100644 --- a/bin/compiler_flags.txt +++ b/bin/compiler_flags.txt @@ -14,3 +14,4 @@ clang>-Wno-unknown-warning-option ###### Debug ################################################################## debug>cl>-Zi debug>clang>-g + diff --git a/bin/compiler_inc_paths.txt b/bin/compiler_inc_paths.txt new file mode 100644 index 0000000..be603ee --- /dev/null +++ b/bin/compiler_inc_paths.txt @@ -0,0 +1,2 @@ +###### Examples ############################################################### +type_info_final_program.c>examples/type_metadata diff --git a/bin/run_examples.sh b/bin/run_examples.sh index 63e65a5..331a8c3 100755 --- a/bin/run_examples.sh +++ b/bin/run_examples.sh @@ -6,10 +6,9 @@ cd "$(dirname "$0")" cd .. root_path=$PWD build_path=$root_path/build - examps=$root_path/examples -echo ~~~ Running Type Metadata Example ~~~ +echo ~~~ Running Type Metadata Generator Example ~~~ cd $examps/type_metadata/generated $build_path/type_metadata.exe $examps/type_metadata/types.mdesk echo diff --git a/bin/type_info_example.sh b/bin/type_info_example.sh new file mode 100644 index 0000000..1b41764 --- /dev/null +++ b/bin/type_info_example.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +###### Get Paths ############################################################## +og_path=$PWD +cd "$(dirname "$0")" +cd .. +root_path=$PWD +build_path=$root_path/build +bin_path=$root_path/bin + +# TODO(allen): IMPORTANT!! Build scripts here are a bit of a mess. They force +# us to use non-absolute paths for builds, but then we need absolute paths for +# other things. Not good! +examps_path=$root_path/examples +examps=examples + + +###### Script ################################################################# +echo ~~~ Type Info Example ~~~ +$bin_path/bld_core.sh show_ctx + +echo ~~~ Building Metaprogram ~~~ +$bin_path/bld_core.sh unit type_metadata $examps/type_metadata/type_metadata.c + +echo ~~~ Running Metaprogram ~~~ +cd $examps/type_metadata/generated +$build_path/type_metadata.exe $examps_path/type_metadata/types.mdesk +echo + +if [ -f $examps_path/type_metadata/generated/meta_types.h ]; then +echo ~~~ Building Program ~~~ +$bin_path/bld_core.sh unit type_info $examps/type_metadata/type_info_final_program.c +else +echo !!! Skipping Program !!! +fi + +echo + +###### Restore Path ########################################################### +cd $og_path diff --git a/examples/type_metadata/type_info_final_program.c b/examples/type_metadata/type_info_final_program.c index 410b749..96912f2 100644 --- a/examples/type_metadata/type_info_final_program.c +++ b/examples/type_metadata/type_info_final_program.c @@ -6,8 +6,8 @@ ** */ -#include "generated/type_info_meta.h" -#include "generated/type_info_meta.c" +#include "generated/meta_types.h" +#include "generated/meta_types.c" #include diff --git a/examples/type_metadata/type_metadata.c b/examples/type_metadata/type_metadata.c index ee84a3e..67e0c44 100644 --- a/examples/type_metadata/type_metadata.c +++ b/examples/type_metadata/type_metadata.c @@ -276,7 +276,7 @@ main(int argc, char **argv) if (!MD_S8Match(arrow->string, MD_S8Lit("->"), 0) || MD_NodeIsNil(out)) { - // TODO(allen): error map type + // TODO: error map type } int is_complete = MD_NodeHasChild(map_tag, MD_S8Lit("complete"), 0); @@ -352,7 +352,10 @@ main(int argc, char **argv) if (!MD_NodeIsNil(array_tag)) { array_count = array_tag->first_child; - // TODO(allen): error if array_count is nil + if (MD_NodeIsNil(array_count)) + { + // TODO: error array count + } } TypeMember *member = MD_PushArray(arena, TypeMember, 1); diff --git a/project.4coder b/project.4coder index 2575a47..ad07c0f 100644 --- a/project.4coder +++ b/project.4coder @@ -76,8 +76,8 @@ command_list = .cmd = { { "git_bash bin\\build_examples.sh", .os = "win" }, - { "bin/build_tests.sh", .os = "linux" }, - { "bin/build_tests.sh", .os = "mac" }, + { "bin/build_examples.sh", .os = "linux" }, + { "bin/build_examples.sh", .os = "mac" }, }, }, { @@ -89,8 +89,21 @@ command_list = .cmd = { { "git_bash bin\\run_examples.sh", .os = "win" }, - { "bin/build_tests.sh", .os = "linux" }, - { "bin/build_tests.sh", .os = "mac" }, + { "bin/run_examples.sh", .os = "linux" }, + { "bin/run_examples.sh", .os = "mac" }, + }, + }, + { + .name = "type_info_example", + .out = "*run*", + .footer_panel = false, + .save_dirty_files = true, + .cursor_at_end = false, + .cmd = + { + { "git_bash bin\\type_info_example.sh", .os = "win" }, + { "bin/type_info_example.sh", .os = "linux" }, + { "bin/type_info_example.sh", .os = "mac" }, }, }, }; @@ -99,3 +112,4 @@ fkey_command[1] = "build_tests"; fkey_command[2] = "run_tests"; fkey_command[3] = "build_examples"; fkey_command[4] = "run_examples"; +fkey_command[5] = "type_info_example";