From b3d3611a3456da9ca5ecde42afd660ad8c135298 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 13:36:11 +0900 Subject: [PATCH 1/8] Update `configurator::display_version` to be static Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 15 ++++++++------- include/meevax/kernel/machine.hpp | 8 +++++--- include/meevax/kernel/writer.hpp | 6 +++--- include/meevax/utility/module.hpp | 8 ++++++++ src/kernel/environment.cpp | 9 +-------- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 246280a1b..2850bc3ab 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.50.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.51.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.50_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.51_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.50 +Meevax Lisp System, version 0.4.51 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 6aed7c397..e1a99a982 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.50 +0.4.51 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 35ebc1759..f3e883855 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -35,9 +35,10 @@ inline namespace kernel IMPORT(environment, evaluate, NIL); IMPORT(environment, load, NIL); - IMPORT(environment, print, const); IMPORT(environment, read, NIL); + USING_STATIC(environment, print); + template using dispatcher = std::unordered_map; @@ -46,11 +47,11 @@ inline namespace kernel const dispatcher long_options, long_options_with_arguments; public: - bool batch = false; - bool debug = false; - bool interactive = false; - bool trace = false; - bool verbose = false; + static inline auto batch = false; + static inline auto debug = false; + static inline auto interactive = false; + static inline auto trace = false; + static inline auto verbose = false; explicit configurator() : short_options @@ -249,7 +250,7 @@ inline namespace kernel }(); } - auto display_version() const -> void + static auto display_version() -> void { print("Meevax Lisp ", version()); } diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 856cfb14d..a00662782 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -29,15 +29,17 @@ namespace meevax { inline namespace kernel { - template + template class machine // TR-SECD machine. { - friend environment; + friend Environment; machine() {} - IMPORT(environment, fork, const); + IMPORT(Environment, fork, const); + + using environment = Environment; protected: let s, // stack (holding intermediate results and return address) diff --git a/include/meevax/kernel/writer.hpp b/include/meevax/kernel/writer.hpp index 5baecdc38..677fe3313 100644 --- a/include/meevax/kernel/writer.hpp +++ b/include/meevax/kernel/writer.hpp @@ -33,19 +33,19 @@ inline namespace kernel public: template - auto write(std::ostream & os, Ts&&... xs) const -> std::ostream & + static auto write(std::ostream & os, Ts&&... xs) -> std::ostream & { return (os << ... << xs); } template - auto write(const_reference x, Ts&&... xs) const -> decltype(auto) + static auto write(const_reference x, Ts&&... xs) -> decltype(auto) { return write(x.as(), std::forward(xs)...); } template - auto print(Ts&&... xs) const -> decltype(auto) + static auto print(Ts&&... xs) -> decltype(auto) { return write(standard_output, std::forward(xs)..., '\n'); } diff --git a/include/meevax/utility/module.hpp b/include/meevax/utility/module.hpp index 6df353ad8..fea3b9c6c 100644 --- a/include/meevax/utility/module.hpp +++ b/include/meevax/utility/module.hpp @@ -30,4 +30,12 @@ static_assert(true) #define EXPORT(M, SYMBOL) using M::SYMBOL +#define USING_STATIC(TYPE, FUNCTION) \ +template \ +static auto FUNCTION(Ts&&... xs) -> decltype(auto) \ +{ \ + return TYPE::FUNCTION(std::forward(xs)...); \ +} \ +static_assert(true) + #endif // INCLUDED_MEEVAX_UTILITY_MODULE_HPP diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index adc88dea6..0afbb46b0 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -152,14 +152,7 @@ inline namespace kernel auto environment::execute() -> lvalue { - if (trace) - { - return machine::execute(); - } - else - { - return machine::execute(); - } + return trace ? machine::execute() : machine::execute(); } auto environment::execute(const_reference code) -> lvalue From 4d7d8ed8751fda638f7007d000fa2a74d9bfbddd Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 13:48:35 +0900 Subject: [PATCH 2/8] Update `configurator::short_options` to be static Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 58 +++++++++++++------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 2850bc3ab..ad2227afe 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.51.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.52.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.51_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.52_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.51 +Meevax Lisp System, version 0.4.52 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index e1a99a982..e32a889bd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.51 +0.4.52 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index f3e883855..49d6a8b56 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -42,7 +42,7 @@ inline namespace kernel template using dispatcher = std::unordered_map; - const dispatcher short_options, short_options_with_arguments; + const dispatcher short_options_with_arguments; const dispatcher long_options, long_options_with_arguments; @@ -53,38 +53,38 @@ inline namespace kernel static inline auto trace = false; static inline auto verbose = false; - explicit configurator() - : short_options - { - std::make_pair('b', [this](auto&&...) - { - return make(batch = true); - }), + static inline const dispatcher short_options + { + std::make_pair('b', [](auto&&...) + { + return make(batch = true); + }), - std::make_pair('d', [this](auto&&...) - { - return make(debug = true); - }), + std::make_pair('d', [](auto&&...) + { + return make(debug = true); + }), - std::make_pair('h', [this](auto&&...) -> lvalue - { - display_help(); - throw exit_status::success; - }), + std::make_pair('h', [](auto&&...) -> lvalue + { + configurator::display_help(); + throw exit_status::success; + }), - std::make_pair('i', [this](auto&&...) - { - return make(interactive = true); - }), + std::make_pair('i', [](auto&&...) + { + return make(interactive = true); + }), - std::make_pair('v', [this](auto&&...) -> lvalue - { - display_version(); - throw exit_status::success; - }), - } + std::make_pair('v', [](auto&&...) -> lvalue + { + configurator::display_version(); + throw exit_status::success; + }), + }; - , short_options_with_arguments + explicit configurator() + : short_options_with_arguments { std::make_pair('e', [this](const_reference x, auto&&...) { @@ -255,7 +255,7 @@ inline namespace kernel print("Meevax Lisp ", version()); } - auto display_help() const -> void + static auto display_help() -> void { display_version(); print(); From 813e76de7ae3647fbf374453f0822f3ef129b597 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 13:53:42 +0900 Subject: [PATCH 3/8] Fix configurator to be compilable with Clang Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 50 +++++++++++++------------- script/install.sh | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ad2227afe..1cf8ac82d 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.52.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.53.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.52_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.53_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.52 +Meevax Lisp System, version 0.4.53 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index e32a889bd..7e7344150 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.52 +0.4.53 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 49d6a8b56..c4fca8099 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -53,6 +53,31 @@ inline namespace kernel static inline auto trace = false; static inline auto verbose = false; + static auto display_version() -> void + { + print("Meevax Lisp ", version()); + } + + static auto display_help() -> void + { + display_version(); + print(); + print("Usage: meevax [OPTION...] [FILE...]"); + print(); + print("Options:"); + print(" -b, --batch Suppress any system output."); + print(" -d, --debug Display detailed informations for developers."); + print(" -e, --evaluate=STRING Read and evaluate given STRING at configuration step."); + print(" -h, --help Display this help text and exit."); + print(" -i, --interactive Take over control of root environment."); + print(" -l, --load=FILENAME Same as -e '(load FILENAME)'"); + print(" -t, --trace Display stacks of virtual machine for each steps."); + print(" -v, --version Display version information and exit."); + print(" --verbose Display detailed informations."); + print(" -w, --write=OBJECT Same as -e '(write OBJECT)'"); + } + + private: static inline const dispatcher short_options { std::make_pair('b', [](auto&&...) @@ -83,6 +108,7 @@ inline namespace kernel }), }; + public: explicit configurator() : short_options_with_arguments { @@ -249,30 +275,6 @@ inline namespace kernel return unspecified_object; }(); } - - static auto display_version() -> void - { - print("Meevax Lisp ", version()); - } - - static auto display_help() -> void - { - display_version(); - print(); - print("Usage: meevax [OPTION...] [FILE...]"); - print(); - print("Options:"); - print(" -b, --batch Suppress any system output."); - print(" -d, --debug Display detailed informations for developers."); - print(" -e, --evaluate=STRING Read and evaluate given STRING at configuration step."); - print(" -h, --help Display this help text and exit."); - print(" -i, --interactive Take over control of root environment."); - print(" -l, --load=FILENAME Same as -e '(load FILENAME)'"); - print(" -t, --trace Display stacks of virtual machine for each steps."); - print(" -v, --version Display version information and exit."); - print(" --verbose Display detailed informations."); - print(" -w, --write=OBJECT Same as -e '(write OBJECT)'"); - } }; } // namespace kernel } // namespace meevax diff --git a/script/install.sh b/script/install.sh index 713204d58..8d3c9489e 100755 --- a/script/install.sh +++ b/script/install.sh @@ -5,7 +5,7 @@ root="$(git rev-parse --show-toplevel)" make() { rm -rf "$2" - cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ + cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ cmake --build "$2" --target "$1" } From f25d78ad2ccd2198b61463d5c2acac4d8cff4554 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:08:45 +0900 Subject: [PATCH 4/8] Update `configurator::long_options` to be static Signed-off-by: yamacir-kit --- README.md | 6 +- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 82 +++++++++++++------------- include/meevax/kernel/writer.hpp | 10 ++-- script/install.sh | 2 +- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 1cf8ac82d..b2774edfb 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.53.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.54.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.53_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.54_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.53 +Meevax Lisp System, version 0.4.54 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 7e7344150..183c2e41b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.53 +0.4.54 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index c4fca8099..60df5788e 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -44,7 +44,7 @@ inline namespace kernel const dispatcher short_options_with_arguments; - const dispatcher long_options, long_options_with_arguments; + const dispatcher long_options_with_arguments; public: static inline auto batch = false; @@ -108,6 +108,46 @@ inline namespace kernel }), }; + static inline const dispatcher long_options + { + std::make_pair("batch", [](auto&&...) + { + return make(batch = true); + }), + + std::make_pair("debug", [](auto&&...) + { + return make(debug = true); + }), + + std::make_pair("help", [](auto&&...) -> lvalue + { + display_help(); + throw exit_status::success; + }), + + std::make_pair("interactive", [](auto&&...) + { + return make(interactive = true); + }), + + std::make_pair("trace", [](auto&&...) + { + return make(trace = true); + }), + + std::make_pair("verbose", [](auto&&...) + { + return make(verbose = true); + }), + + std::make_pair("version", [](auto&&...) -> lvalue + { + display_version(); + throw exit_status::success; + }), + }; + public: explicit configurator() : short_options_with_arguments @@ -128,46 +168,6 @@ inline namespace kernel }), } - , long_options - { - std::make_pair("batch", [this](auto&&...) - { - return make(batch = true); - }), - - std::make_pair("debug", [this](auto&&...) - { - return make(debug = true); - }), - - std::make_pair("help", [this](auto&&...) -> lvalue - { - display_help(); - throw exit_status::success; - }), - - std::make_pair("interactive", [this](auto&&...) - { - return make(interactive = true); - }), - - std::make_pair("trace", [this](auto&&...) - { - return make(trace = true); - }), - - std::make_pair("verbose", [this](auto&&...) - { - return make(verbose = true); - }), - - std::make_pair("version", [this](auto&&...) -> lvalue - { - display_version(); - throw exit_status::success; - }), - } - , long_options_with_arguments { std::make_pair("evaluate", [this](const_reference x, auto&&...) diff --git a/include/meevax/kernel/writer.hpp b/include/meevax/kernel/writer.hpp index 677fe3313..ed1efa393 100644 --- a/include/meevax/kernel/writer.hpp +++ b/include/meevax/kernel/writer.hpp @@ -51,20 +51,20 @@ inline namespace kernel } public: - auto null_port() const -> const_reference + static auto null_port() -> const_reference { let static port = make("/dev/null"); return port; } - auto verbose_port() const -> const_reference + static auto verbose_port() -> const_reference { - return static_cast(*this).verbose ? standard_output : null_port(); + return Environment::verbose ? standard_output : null_port(); } - auto debug_port() const -> const_reference + static auto debug_port() -> const_reference { - return static_cast(*this).debug ? standard_error : null_port(); + return Environment::debug ? standard_error : null_port(); } }; } // namespace kernel diff --git a/script/install.sh b/script/install.sh index 8d3c9489e..713204d58 100755 --- a/script/install.sh +++ b/script/install.sh @@ -5,7 +5,7 @@ root="$(git rev-parse --show-toplevel)" make() { rm -rf "$2" - cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=clang++ + cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ cmake --build "$2" --target "$1" } From d9ca5bb3242330fcfc5e0a29efb44c7884e2c605 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:31:47 +0900 Subject: [PATCH 5/8] Move free function `interaction_environment` into new header `interaction_environment.hpp` Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 6 ++-- include/meevax/kernel/environment.hpp | 10 +++---- .../meevax/kernel/interaction_environment.hpp | 30 +++++++++++++++++++ include/meevax/kernel/library.hpp | 2 -- src/kernel/interaction_environment.cpp | 30 +++++++++++++++++++ src/kernel/library.cpp | 7 +---- src/main.cpp | 1 + test/environment.cpp | 1 + 10 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 include/meevax/kernel/interaction_environment.hpp create mode 100644 src/kernel/interaction_environment.cpp diff --git a/README.md b/README.md index b2774edfb..bde300f2e 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.54.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.55.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.54_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.55_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.54 +Meevax Lisp System, version 0.4.55 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 183c2e41b..0313ed8e9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.54 +0.4.55 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 60df5788e..a8e620dd7 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -152,9 +153,10 @@ inline namespace kernel explicit configurator() : short_options_with_arguments { - std::make_pair('e', [this](const_reference x, auto&&...) + std::make_pair('e', [](const_reference x, auto&&...) { - return print(evaluate(x)), unspecified_object; + print(interaction_environment().as().evaluate(x)); + return unspecified_object; }), std::make_pair('l', [this](const_reference x, auto&&...) diff --git a/include/meevax/kernel/environment.hpp b/include/meevax/kernel/environment.hpp index f57e8ab41..8c7ee5d37 100644 --- a/include/meevax/kernel/environment.hpp +++ b/include/meevax/kernel/environment.hpp @@ -55,11 +55,11 @@ inline namespace kernel { (import(xs), ...); - define("set-batch!", [this](let const& xs, auto&&...) { return batch = select(car(xs)); }); - define("set-debug!", [this](let const& xs, auto&&...) { return debug = select(car(xs)); }); - define("set-interactive!", [this](let const& xs, auto&&...) { return interactive = select(car(xs)); }); - define("set-trace!", [this](let const& xs, auto&&...) { return trace = select(car(xs)); }); - define("set-verbose!", [this](let const& xs, auto&&...) { return verbose = select(car(xs)); }); + // define("set-batch!", [this](let const& xs, auto&&...) { return batch = select(car(xs)); }); + // define("set-debug!", [this](let const& xs, auto&&...) { return debug = select(car(xs)); }); + // define("set-interactive!", [this](let const& xs, auto&&...) { return interactive = select(car(xs)); }); + // define("set-trace!", [this](let const& xs, auto&&...) { return trace = select(car(xs)); }); + // define("set-verbose!", [this](let const& xs, auto&&...) { return verbose = select(car(xs)); }); } auto operator [](const_reference) -> const_reference; diff --git a/include/meevax/kernel/interaction_environment.hpp b/include/meevax/kernel/interaction_environment.hpp new file mode 100644 index 000000000..cec72e3df --- /dev/null +++ b/include/meevax/kernel/interaction_environment.hpp @@ -0,0 +1,30 @@ +/* + Copyright 2018-2022 Tatsuya Yamasaki. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef INCLUDED_MEEVAX_KERNEL_INTERACTION_ENVIRONMENT_HPP +#define INCLUDED_MEEVAX_KERNEL_INTERACTION_ENVIRONMENT_HPP + +#include + +namespace meevax +{ +inline namespace kernel +{ + auto interaction_environment() -> const_reference; +} // namespace kernel +} // namespace meevax + +#endif // INCLUDED_MEEVAX_KERNEL_INTERACTION_ENVIRONMENT_HPP diff --git a/include/meevax/kernel/library.hpp b/include/meevax/kernel/library.hpp index 45a455887..5c2919261 100644 --- a/include/meevax/kernel/library.hpp +++ b/include/meevax/kernel/library.hpp @@ -24,8 +24,6 @@ namespace meevax { inline namespace kernel { - auto interaction_environment() -> const_reference; - struct library : public environment { std::vector export_specs; diff --git a/src/kernel/interaction_environment.cpp b/src/kernel/interaction_environment.cpp new file mode 100644 index 000000000..34a79151a --- /dev/null +++ b/src/kernel/interaction_environment.cpp @@ -0,0 +1,30 @@ +/* + Copyright 2018-2022 Tatsuya Yamasaki. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include +#include + +namespace meevax +{ +inline namespace kernel +{ + auto interaction_environment() -> const_reference + { + let static const interaction_environment = make(); + return interaction_environment; + } +} // namespace kernel +} // namespace meevax diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index 7ff756f0f..a21b278eb 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -15,18 +15,13 @@ */ #include +#include #include namespace meevax { inline namespace kernel { - auto interaction_environment() -> const_reference - { - let static const interaction_environment = make(); - return interaction_environment; - } - library::library(syntax_library_t) { define("begin", machine::begin); diff --git a/src/main.cpp b/src/main.cpp index c065cde12..0aca95e72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ limitations under the License. */ +#include #include #include diff --git a/test/environment.cpp b/test/environment.cpp index 48bd547bd..e37e87981 100644 --- a/test/environment.cpp +++ b/test/environment.cpp @@ -1,6 +1,7 @@ #undef NDEBUG #include +#include #include auto main() -> int From e2201363a8319a515faeb5467b185c256a222f99 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:43:45 +0900 Subject: [PATCH 6/8] Update `configurator::short_options_with_arguments` to be static Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 43 +++++++++++++------------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index bde300f2e..d90d45e29 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.55.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.56.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.55_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.56_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.55 +Meevax Lisp System, version 0.4.56 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 0313ed8e9..319405ebd 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.55 +0.4.56 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index a8e620dd7..81ce30aad 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -43,8 +43,6 @@ inline namespace kernel template using dispatcher = std::unordered_map; - const dispatcher short_options_with_arguments; - const dispatcher long_options_with_arguments; public: @@ -109,6 +107,26 @@ inline namespace kernel }), }; + static inline const dispatcher short_options_with_arguments + { + std::make_pair('e', [](const_reference x, auto&&...) + { + print(interaction_environment().as().evaluate(x)); + return unspecified_object; + }), + + std::make_pair('l', [](const_reference x, auto&&...) + { + return interaction_environment().as().load(x.as_const()); + }), + + std::make_pair('w', [](const_reference x, auto&&...) + { + print(x); + return unspecified_object; + }), + }; + static inline const dispatcher long_options { std::make_pair("batch", [](auto&&...) @@ -151,26 +169,7 @@ inline namespace kernel public: explicit configurator() - : short_options_with_arguments - { - std::make_pair('e', [](const_reference x, auto&&...) - { - print(interaction_environment().as().evaluate(x)); - return unspecified_object; - }), - - std::make_pair('l', [this](const_reference x, auto&&...) - { - return load(x.as_const()); - }), - - std::make_pair('w', [this](const_reference x, auto&&...) - { - return print(x), unspecified_object; - }), - } - - , long_options_with_arguments + : long_options_with_arguments { std::make_pair("evaluate", [this](const_reference x, auto&&...) { From 01efeb03801c5a9b06de7bcc92cd0be170b4ce13 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 14:52:31 +0900 Subject: [PATCH 7/8] Update `configurator::long_options_with_arguments` to be static Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 41 +++++++++++++------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d90d45e29..7e462a423 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.56.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.57.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.56_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.57_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.56 +Meevax Lisp System, version 0.4.57 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 319405ebd..b0da4c03b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.56 +0.4.57 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 81ce30aad..bbfb073bc 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -34,6 +34,9 @@ inline namespace kernel { friend environment; + explicit configurator() + {} + IMPORT(environment, evaluate, NIL); IMPORT(environment, load, NIL); IMPORT(environment, read, NIL); @@ -43,8 +46,6 @@ inline namespace kernel template using dispatcher = std::unordered_map; - const dispatcher long_options_with_arguments; - public: static inline auto batch = false; static inline auto debug = false; @@ -167,27 +168,27 @@ inline namespace kernel }), }; - public: - explicit configurator() - : long_options_with_arguments - { - std::make_pair("evaluate", [this](const_reference x, auto&&...) - { - return print(evaluate(x)), unspecified_object; - }), + static inline const dispatcher long_options_with_arguments + { + std::make_pair("evaluate", [](const_reference x, auto&&...) + { + print(interaction_environment().as().evaluate(x)); + return unspecified_object; + }), - std::make_pair("load", [this](const_reference x, auto&&...) - { - return load(x.as_const()); - }), + std::make_pair("load", [](const_reference x, auto&&...) + { + return interaction_environment().as().load(x.as_const()); + }), - std::make_pair("write", [this](const_reference x, auto&&...) - { - return print(x), unspecified_object; - }), - } - {} + std::make_pair("write", [](const_reference x, auto&&...) + { + print(x); + return unspecified_object; + }), + }; + public: auto configure(const int argc, char const* const* const argv) { return configure({ argv + 1, argv + argc }); From 62ab16c9756d1dec10a83c75be96f38997b060d4 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 11 Jun 2022 15:38:54 +0900 Subject: [PATCH 8/8] Lipsticks Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 17 ++++++++--------- src/kernel/environment.cpp | 5 ----- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7e462a423..320de8e91 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.57.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.58.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.57_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.58_amd64.deb`. | `install` | Copy files into `/usr/local` __(1)__. | `install.deb` | `all` + `package` + `sudo apt install .deb` | `safe-install.deb` | `all` + `test` + `package` + `sudo apt install .deb` @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.57 +Meevax Lisp System, version 0.4.58 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index b0da4c03b..f96de0bf2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.57 +0.4.58 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index bbfb073bc..6d58d3de6 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -49,7 +49,7 @@ inline namespace kernel public: static inline auto batch = false; static inline auto debug = false; - static inline auto interactive = false; + static inline auto interactive = true; static inline auto trace = false; static inline auto verbose = false; @@ -198,11 +198,7 @@ inline namespace kernel { static std::regex const pattern { R"(--(\w[-\w]+)(=(.*))?|-([\w]+))" }; - if (std::empty(args)) - { - interactive = true; - } - else for (auto current_option = std::begin(args); current_option != std::end(args); ++current_option) [&]() + for (auto current_option = std::begin(args); current_option != std::end(args); ++current_option) [&]() { std::smatch analysis {}; @@ -214,7 +210,7 @@ inline namespace kernel // std::cout << header("") << "analysis[3] = " << analysis[3] << std::endl; // std::cout << header("") << "analysis[4] = " << analysis[4] << std::endl; - if (auto const current_short_options = analysis.str(4); not current_short_options.empty()) + if (auto const& current_short_options = analysis.str(4); not current_short_options.empty()) { for (auto current_short_option = std::cbegin(current_short_options); current_short_option != std::cend(current_short_options); ++current_short_option) { @@ -239,7 +235,8 @@ inline namespace kernel } else { - throw error(make(cat, "unknown short-option -", *current_short_option)); + throw error(make("unknown short-option"), + make(*current_short_option)); } } } @@ -266,11 +263,13 @@ inline namespace kernel } else { - throw error(make(cat, "unknown long-option: ", *current_option)); + throw error(make("unknown long-option"), + make(*current_option)); } } else { + interactive = false; return load(*current_option); } diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index 0afbb46b0..e6697b516 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -90,11 +90,6 @@ inline namespace kernel define(binding.as().symbol(), binding.as().load()); } - - if (interactive) - { - print(faint("; ", length(bindings), " identifiers imported.")); - } } auto environment::define(const_reference name, const_reference value) -> void