From 0d93eeb3fecb16e1f3e0c6c8820140e67e947eb0 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 8 Jan 2020 18:57:41 +0200 Subject: [PATCH] compiler: move prelude files to tools/preludes/ --- tools/modules/testing/common.v | 2 +- tools/preludes/README.md | 28 +++++++++++++++++++ {vlib/compiler => tools}/preludes/live_main.v | 0 .../compiler => tools}/preludes/live_shared.v | 0 .../preludes/tests_assertions.v | 0 .../preludes/tests_with_stats.v | 0 tools/vtest-fmt.v | 8 +++--- vlib/compiler/main.v | 6 +++- 8 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tools/preludes/README.md rename {vlib/compiler => tools}/preludes/live_main.v (100%) rename {vlib/compiler => tools}/preludes/live_shared.v (100%) rename {vlib/compiler => tools}/preludes/tests_assertions.v (100%) rename {vlib/compiler => tools}/preludes/tests_with_stats.v (100%) diff --git a/tools/modules/testing/common.v b/tools/modules/testing/common.v index 8a30631c6a..0710050322 100644 --- a/tools/modules/testing/common.v +++ b/tools/modules/testing/common.v @@ -140,7 +140,7 @@ pub fn v_build_failing(zargs string, folder string) bool { eprintln(' v compiler args: "$vargs"') mut session := new_test_session(vargs) files := os.walk_ext(filepath.join(parent_dir,folder), '.v') - mains := files.filter(!it.contains('modules')) + mains := files.filter(!it.contains('modules') && !it.contains('preludes')) session.files << mains session.test() eprintln(session.benchmark.total_message(finish_label)) diff --git a/tools/preludes/README.md b/tools/preludes/README.md new file mode 100644 index 0000000000..b2cfb52005 --- /dev/null +++ b/tools/preludes/README.md @@ -0,0 +1,28 @@ +# V preludes: + +The tools/preludes/ contains small v code snippets, that V uses when +compiling certain v programs. V adds the files below automatically itself. +Each file is used in different situations (see below). + +NB: preludes are *NOT* intended to be used by user programs/modules. +The folder tools/preludes/ is *NOT* a v module. + +## Details: + +### tools/preludes/live_main.v +Used when compiling live programs. This file is used by the main executable +live program, that starts the file change monitoring thread. Each live program +needs module `os` and module `time`, in order for the background file change +monitoring thread to work properly. + +### tools/preludes/live_shared.v +Used when compiling live programs, for the shared library portion of the live +programs, that is reloaded each time the code is changed. + +### tools/preludes/tests_assertions.v +Used when compiling `_test.v` programs. +It specifies how failed assertions will look. + +### tools/preludes/tests_with_stats.v +Used when compiling `_test.v` programs with -stats option. +It specifies how the result will appear ('assert' vs 'asserts' and so on). diff --git a/vlib/compiler/preludes/live_main.v b/tools/preludes/live_main.v similarity index 100% rename from vlib/compiler/preludes/live_main.v rename to tools/preludes/live_main.v diff --git a/vlib/compiler/preludes/live_shared.v b/tools/preludes/live_shared.v similarity index 100% rename from vlib/compiler/preludes/live_shared.v rename to tools/preludes/live_shared.v diff --git a/vlib/compiler/preludes/tests_assertions.v b/tools/preludes/tests_assertions.v similarity index 100% rename from vlib/compiler/preludes/tests_assertions.v rename to tools/preludes/tests_assertions.v diff --git a/vlib/compiler/preludes/tests_with_stats.v b/tools/preludes/tests_with_stats.v similarity index 100% rename from vlib/compiler/preludes/tests_with_stats.v rename to tools/preludes/tests_with_stats.v diff --git a/tools/vtest-fmt.v b/tools/vtest-fmt.v index 45dae6fac2..939f85ddac 100644 --- a/tools/vtest-fmt.v +++ b/tools/vtest-fmt.v @@ -15,10 +15,10 @@ const ( './vlib/builtin/js/hashmap.v', './vlib/compiler/tests/fn_variadic_test.v', './vlib/compiler/tests/generic_test.v', - './vlib/compiler/preludes/live_main.v', - './vlib/compiler/preludes/live_shared.v', - './vlib/compiler/preludes/tests_assertions.v', - './vlib/compiler/preludes/tests_with_stats.v', + './tools/preludes/live_main.v', + './tools/preludes/live_shared.v', + './tools/preludes/tests_assertions.v', + './tools/preludes/tests_with_stats.v', './vlib/crypto/aes/aes.v', './vlib/crypto/aes/aes_cbc.v', './vlib/crypto/aes/block_generic.v', diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 26b75c1f26..005db3ad65 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -828,7 +828,10 @@ pub fn (v &V) get_user_files() []string { // Need to store user files separately, because they have to be added after // libs, but we dont know which libs need to be added yet mut user_files := []string - preludes_path := filepath.join(v.pref.vlib_path,'compiler','preludes') + + // See tools/preludes/README.md for more info about what preludes are + vroot := filepath.dir(vexe_path()) + preludes_path := filepath.join(vroot,'tools','preludes') if v.pref.is_live { user_files << filepath.join(preludes_path,'live_main.v') } @@ -841,6 +844,7 @@ pub fn (v &V) get_user_files() []string { if v.pref.is_test && v.pref.is_stats { user_files << filepath.join(preludes_path,'tests_with_stats.v') } + is_test := dir.ends_with('_test.v') mut is_internal_module_test := false if is_test {