From c3bf646cc32357ca4f2deb5d5084f66139accad3 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Thu, 21 Jul 2022 22:30:13 +0900 Subject: [PATCH 01/66] Remove free function `invalid_application` Signed-off-by: yamacir-kit --- README.md | 6 +- VERSION | 2 +- include/meevax/kernel/error.hpp | 2 - src/kernel/error.cpp | 6 -- src/kernel/library.cpp | 133 +++++++------------------------- 5 files changed, 33 insertions(+), 116 deletions(-) diff --git a/README.md b/README.md index e461c181a..1c3a9280f 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.166.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.167.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.166_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.167_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.166 +Meevax Lisp System, version 0.4.167 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 362b83357..3eff05ac3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.166 +0.4.167 diff --git a/include/meevax/kernel/error.hpp b/include/meevax/kernel/error.hpp index 155d6efca..5dc227806 100644 --- a/include/meevax/kernel/error.hpp +++ b/include/meevax/kernel/error.hpp @@ -107,8 +107,6 @@ inline namespace kernel return underlying_cast(exit_status::failure); } } - - auto invalid_application(const_reference) -> error; } // namespace kernel } // namespace meevax diff --git a/src/kernel/error.cpp b/src/kernel/error.cpp index 040356877..a6c4f214f 100644 --- a/src/kernel/error.cpp +++ b/src/kernel/error.cpp @@ -65,11 +65,5 @@ inline namespace kernel { throw error(make(message)); } - - auto invalid_application(const_reference irritants) -> error - { - let static const message = make("invalid application"); - return error(message, irritants); - } } // namespace kernel } // namespace meevax diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index dd11043ad..3dd5ce710 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -37,14 +37,7 @@ inline namespace kernel library.define("char->integer", [](let const& xs) { - if (xs.is() and car(xs).is()) - { - return make(car(xs).as().codepoint); - } - else - { - throw invalid_application(string_to_symbol("char->integer") | xs); - } + return make(car(xs).as().codepoint); }); library.define("char-codepoint", [](let const& xs) -> value_type @@ -66,27 +59,18 @@ inline namespace kernel define_library("(meevax context)", [](library & library) { - library.define("emergency-exit", [](let const& xs) -> value_type + library.define("emergency-exit", [](let const& xs) { - switch (length(xs)) + if (let const& status = car(xs); status.is()) { - case 0: - throw exit_status::success; - - case 1: - if (let const& x = car(xs); x.is()) - { - throw select(x) ? exit_status::success : exit_status::failure; - } - else if (x.is()) - { - throw exit_status(static_cast(x.as())); - } - else [[fallthrough]]; - - default: - throw invalid_application(string_to_symbol("emergency-exit") | xs); + throw select(status) ? exit_status::success : exit_status::failure; } + else + { + throw exit_status(static_cast(status.as())); + } + + return unspecified; }); library.export_("emergency-exit"); @@ -282,17 +266,8 @@ inline namespace kernel library.define("log", [](let const& xs) { - switch (length(xs)) - { - case 1: - return car(xs).as().log(); - - case 2: - return car(xs).as().log() / cadr(xs).as().log(); - - default: - throw invalid_application(string_to_symbol("log") | xs); - } + return cdr(xs).is() ? car(xs).as().log() / cadr(xs).as().log() + : car(xs).as().log(); }); library.define("sin", [](let const& xs) @@ -322,17 +297,8 @@ inline namespace kernel library.define("atan", [](let const& xs) { - switch (length(xs)) - { - case 1: - return car(xs).as().atan(); - - case 2: - return car(xs).as().atan2(cadr(xs)); - - default: - throw invalid_application(string_to_symbol("atan") | xs); - } + return cdr(xs).is() ? car(xs).as().atan2(cadr(xs)) + : car(xs).as().atan(); }); library.define("sinh", [](let const& xs) @@ -532,22 +498,11 @@ inline namespace kernel #define DEFINE(SYMBOL, FUNCTION, BASIS) \ library.define(SYMBOL, [](let const& xs) \ { \ - switch (length(xs)) \ - { \ - case 0: \ - throw invalid_application(string_to_symbol(SYMBOL) | xs); \ - \ - case 1: \ - return FUNCTION(BASIS, car(xs)); \ - \ - default: \ - return std::accumulate( \ - std::next(std::begin(xs)), std::end(xs), car(xs), \ - [](let const& a, let const& b) \ - { \ - return FUNCTION(a, b); \ - }); \ - } \ + return cdr(xs).is() ? std::accumulate(std::begin(cdr(xs)), std::end(xs), car(xs), [](auto&& a, auto&& b) \ + { \ + return FUNCTION(a, b); \ + }) \ + : FUNCTION(BASIS, car(xs)); \ }) DEFINE("-", sub, e0); @@ -593,14 +548,7 @@ inline namespace kernel library.define("integer->char", [](let const& xs) { - if (xs.is() and car(xs).is()) - { - return make(car(xs).as()); - } - else - { - throw invalid_application(string_to_symbol("integer->char") | xs); - } + return make(car(xs).as()); }); library.define("number->string", [](let const& xs) @@ -824,32 +772,14 @@ inline namespace kernel library.define("open-input-string", [](let const& xs) { - switch (length(xs)) - { - case 0: - return make(); - - case 1: - return make(car(xs).as()); - - default: - throw invalid_application(string_to_symbol("open-input-string") | xs); - } + return cdr(xs).is() ? make(car(xs).as()) + : make(); }); library.define("open-output-string", [](let const& xs) { - switch (length(xs)) - { - case 0: - return make(); - - case 1: - return make(car(xs).as()); - - default: - throw invalid_application(string_to_symbol("open-output-string") | xs); - } + return cdr(xs).is() ? make(car(xs).as()) + : make(); }); library.define("get-output-string", [](let const& xs) @@ -932,18 +862,13 @@ inline namespace kernel library.define("put-string", [](let const& xs) { - switch (length(xs)) + auto copy = [&]() { - case 2: - cadr(xs).as() << static_cast(car(xs).as()); - break; - - case 3: // TODO - case 4: // TODO + return car(xs).as().copy(list_tail(xs, 2).is() ? list_ref(xs, 2) : e0, + list_tail(xs, 3).is() ? list_ref(xs, 3) : car(xs).as().length()); + }; - default: - throw invalid_application(string_to_symbol("write-string") | xs); - } + cadr(xs).as() << static_cast(copy().as()); return unspecified; }); From fee7f402e3a7d18ca0cf74e593b0a428c402293b Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Thu, 21 Jul 2022 23:58:30 +0900 Subject: [PATCH 02/66] Fix named closures to declared as `inline` Signed-off-by: yamacir-kit --- CMakeLists.txt | 2 +- README.md | 6 +- VERSION | 2 +- include/meevax/functional/combinator.hpp | 6 +- include/meevax/functional/compose.hpp | 2 +- include/meevax/iostream/concatenate.hpp | 2 +- include/meevax/iostream/escape_sequence.hpp | 2 +- include/meevax/iostream/is_console.hpp | 2 +- include/meevax/kernel/equivalence.hpp | 4 +- include/meevax/kernel/list.hpp | 104 +++++++++--------- include/meevax/kernel/number.hpp | 2 +- include/meevax/memory/collector.hpp | 2 +- .../utility/unwrap_reference_wrapper.hpp | 2 +- 13 files changed, 69 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 55b220733..e6291a41c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_VERBOSE_MAKEFILE OFF) -set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wno-parentheses -pipe") +set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -pipe") set(CMAKE_CXX_FLAGS_DEBUG "-Og -g") set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG") diff --git a/README.md b/README.md index 1c3a9280f..90e222c4a 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.167.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.168.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.167_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.168_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.167 +Meevax Lisp System, version 0.4.168 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 3eff05ac3..a78ca67e0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.167 +0.4.168 diff --git a/include/meevax/functional/combinator.hpp b/include/meevax/functional/combinator.hpp index 7d77e63a3..4025f561f 100644 --- a/include/meevax/functional/combinator.hpp +++ b/include/meevax/functional/combinator.hpp @@ -23,12 +23,12 @@ namespace meevax { inline namespace functional { - auto i = [](auto&& x) constexpr + inline auto i = [](auto&& x) constexpr { return std::forward(x); }; - auto y = [](auto&& f) constexpr -> decltype(auto) + inline auto y = [](auto&& f) constexpr -> decltype(auto) { return [&](auto&&... xs) -> decltype(auto) { @@ -36,7 +36,7 @@ inline namespace functional }; }; - auto z = [](auto&& f) constexpr -> decltype(auto) + inline auto z = [](auto&& f) constexpr -> decltype(auto) { return curry(std::forward(f)) (std::forward(f)); diff --git a/include/meevax/functional/compose.hpp b/include/meevax/functional/compose.hpp index 187866047..dcc89168e 100644 --- a/include/meevax/functional/compose.hpp +++ b/include/meevax/functional/compose.hpp @@ -24,7 +24,7 @@ namespace meevax { inline namespace functional { - auto compose = [](auto&& f, auto&& g) constexpr + inline auto compose = [](auto&& f, auto&& g) constexpr { return [fs = std::forward_as_tuple(f, g)](auto&&... xs) constexpr -> decltype(auto) { diff --git a/include/meevax/iostream/concatenate.hpp b/include/meevax/iostream/concatenate.hpp index 7c3abc932..745622a90 100644 --- a/include/meevax/iostream/concatenate.hpp +++ b/include/meevax/iostream/concatenate.hpp @@ -23,7 +23,7 @@ namespace meevax { inline namespace iostream { - auto concatenate = [](auto&&... xs) + inline auto concatenate = [](auto&&... xs) { std::stringstream ss; (ss << ... << xs); diff --git a/include/meevax/iostream/escape_sequence.hpp b/include/meevax/iostream/escape_sequence.hpp index a5c7f9654..48ce97d30 100644 --- a/include/meevax/iostream/escape_sequence.hpp +++ b/include/meevax/iostream/escape_sequence.hpp @@ -70,7 +70,7 @@ inline namespace iostream escape_sequence(T&&, Ts&&...) -> escape_sequence; #define DEFINE(COMMAND, NAME) \ - auto NAME = [](auto&&... xs) \ + inline auto NAME = [](auto&&... xs) \ { \ return escape_sequence(COMMAND, std::forward(xs)...); \ } diff --git a/include/meevax/iostream/is_console.hpp b/include/meevax/iostream/is_console.hpp index 5fc098161..d526e1e72 100644 --- a/include/meevax/iostream/is_console.hpp +++ b/include/meevax/iostream/is_console.hpp @@ -25,7 +25,7 @@ namespace meevax { inline namespace iostream { - auto is_console = [](std::ostream & os) + inline auto is_console = [](std::ostream & os) { if (os.rdbuf() == std::cout.rdbuf()) { diff --git a/include/meevax/kernel/equivalence.hpp b/include/meevax/kernel/equivalence.hpp index 76529d406..3af9ea328 100644 --- a/include/meevax/kernel/equivalence.hpp +++ b/include/meevax/kernel/equivalence.hpp @@ -23,12 +23,12 @@ namespace meevax { inline namespace kernel { - auto eq = [](auto const& x, auto const& y) constexpr + inline auto eq = [](auto const& x, auto const& y) constexpr { return x == y; }; - auto eqv = [](auto const& x, auto const& y) + inline auto eqv = [](auto const& x, auto const& y) { return eq(x, y) or x.compare(y); }; diff --git a/include/meevax/kernel/list.hpp b/include/meevax/kernel/list.hpp index 5617d37fd..57172c2e8 100644 --- a/include/meevax/kernel/list.hpp +++ b/include/meevax/kernel/list.hpp @@ -45,12 +45,12 @@ inline namespace kernel } } - auto car = [](auto&& x) -> decltype(auto) + inline auto car = [](auto&& x) -> decltype(auto) { return field<0>(std::forward(x)); }; - auto cdr = [](auto&& x) -> decltype(auto) + inline auto cdr = [](auto&& x) -> decltype(auto) { return field<1>(std::forward(x)); }; @@ -62,22 +62,22 @@ inline namespace kernel return make(std::forward(x), std::forward(y)); } - auto cons = [](auto&&... xs) constexpr + inline auto cons = [](auto&&... xs) constexpr { return (std::forward(xs) | ...); }; - auto list = [](auto&& ... xs) constexpr + inline auto list = [](auto&& ... xs) constexpr { return (std::forward(xs) | ... | unit); }; - auto xcons = [](auto&& d, auto&& a) constexpr + inline auto xcons = [](auto&& d, auto&& a) constexpr { return cons(std::forward(a), std::forward(d)); }; - auto make_list = [](std::size_t k, const_reference x = unit) + inline auto make_list = [](std::size_t k, const_reference x = unit) { let result = list(); @@ -89,7 +89,7 @@ inline namespace kernel return result; }; - auto list_tabulate = [](auto n, auto&& initialize) + inline auto list_tabulate = [](auto n, auto&& initialize) { let x = list(); @@ -101,7 +101,7 @@ inline namespace kernel return x; }; - auto list_copy = [](auto const& x) + inline auto list_copy = [](auto const& x) { auto copy = [](auto&& rec, const_reference x) -> value_type { @@ -118,7 +118,7 @@ inline namespace kernel return z(copy)(x); }; - auto circular_list = [](auto&&... xs) + inline auto circular_list = [](auto&&... xs) { let x = list(std::forward(xs)...); @@ -130,38 +130,38 @@ inline namespace kernel return x; }; - constexpr auto caar = compose(car, car); - constexpr auto cadr = compose(car, cdr); - constexpr auto cdar = compose(cdr, car); - constexpr auto cddr = compose(cdr, cdr); - - constexpr auto caaar = compose(car, caar); - constexpr auto caadr = compose(car, cadr); - constexpr auto cadar = compose(car, cdar); - constexpr auto caddr = compose(car, cddr); - constexpr auto cdaar = compose(cdr, caar); - constexpr auto cdadr = compose(cdr, cadr); - constexpr auto cddar = compose(cdr, cdar); - constexpr auto cdddr = compose(cdr, cddr); - - constexpr auto caaaar = compose(car, caaar); - constexpr auto caaadr = compose(car, caadr); - constexpr auto caadar = compose(car, cadar); - constexpr auto caaddr = compose(car, caddr); - constexpr auto cadaar = compose(car, cdaar); - constexpr auto cadadr = compose(car, cdadr); - constexpr auto caddar = compose(car, cddar); - constexpr auto cadddr = compose(car, cdddr); - constexpr auto cdaaar = compose(cdr, caaar); - constexpr auto cdaadr = compose(cdr, caadr); - constexpr auto cdadar = compose(cdr, cadar); - constexpr auto cdaddr = compose(cdr, caddr); - constexpr auto cddaar = compose(cdr, cdaar); - constexpr auto cddadr = compose(cdr, cdadr); - constexpr auto cdddar = compose(cdr, cddar); - constexpr auto cddddr = compose(cdr, cdddr); - - auto unpair = [](const_reference x) // a.k.a car+cdr (SRFI 1) + inline constexpr auto caar = compose(car, car); + inline constexpr auto cadr = compose(car, cdr); + inline constexpr auto cdar = compose(cdr, car); + inline constexpr auto cddr = compose(cdr, cdr); + + inline constexpr auto caaar = compose(car, caar); + inline constexpr auto caadr = compose(car, cadr); + inline constexpr auto cadar = compose(car, cdar); + inline constexpr auto caddr = compose(car, cddr); + inline constexpr auto cdaar = compose(cdr, caar); + inline constexpr auto cdadr = compose(cdr, cadr); + inline constexpr auto cddar = compose(cdr, cdar); + inline constexpr auto cdddr = compose(cdr, cddr); + + inline constexpr auto caaaar = compose(car, caaar); + inline constexpr auto caaadr = compose(car, caadr); + inline constexpr auto caadar = compose(car, cadar); + inline constexpr auto caaddr = compose(car, caddr); + inline constexpr auto cadaar = compose(car, cdaar); + inline constexpr auto cadadr = compose(car, cdadr); + inline constexpr auto caddar = compose(car, cddar); + inline constexpr auto cadddr = compose(car, cdddr); + inline constexpr auto cdaaar = compose(cdr, caaar); + inline constexpr auto cdaadr = compose(cdr, caadr); + inline constexpr auto cdadar = compose(cdr, cadar); + inline constexpr auto cdaddr = compose(cdr, caddr); + inline constexpr auto cddaar = compose(cdr, cdaar); + inline constexpr auto cddadr = compose(cdr, cdadr); + inline constexpr auto cdddar = compose(cdr, cddar); + inline constexpr auto cddddr = compose(cdr, cdddr); + + inline auto unpair = [](const_reference x) // a.k.a car+cdr (SRFI 1) { return std::forward_as_tuple(car(x), cdr(x)); }; @@ -172,14 +172,14 @@ inline namespace kernel return 0 < k ? list_tail(cdr(x), k - 1) : x; } - auto list_ref = [](auto&&... xs) constexpr -> const_reference + inline auto list_ref = [](auto&&... xs) constexpr -> const_reference { return car(list_tail(std::forward(xs)...)); }; auto take(const_reference, std::size_t) -> value_type; - auto length = [](auto const& x) constexpr + inline auto length = [](auto const& x) constexpr { return std::distance(std::cbegin(x), std::cend(x)); }; @@ -200,7 +200,7 @@ inline namespace kernel return x.is() ? unit : cons(f(car(x)), map1(f, cdr(x))); } - auto find = [](const_reference xs, auto&& compare) constexpr -> const_reference + inline auto find = [](const_reference xs, auto&& compare) constexpr -> const_reference { if (auto&& iter = std::find_if(std::begin(xs), std::end(xs), compare); iter) { @@ -212,27 +212,27 @@ inline namespace kernel } }; - auto assoc = [](const_reference x, const_reference xs, auto&& compare) + inline auto assoc = [](const_reference x, const_reference xs, auto&& compare) { return find(xs, [&](auto&& each) { return compare(x, car(each)); }); }; - auto assv = [](auto&&... xs) + inline auto assv = [](auto&&... xs) { return assoc(std::forward(xs)..., eqv); }; - auto assq = [](auto&&... xs) + inline auto assq = [](auto&&... xs) { return assoc(std::forward(xs)..., eq); }; - auto alist_cons = [](auto&& key, auto&& datum, auto&& alist) + inline auto alist_cons = [](auto&& key, auto&& datum, auto&& alist) { return cons(cons(key, datum), alist); }; - auto member = [](const_reference x, const_reference xs, auto&& compare) + inline auto member = [](const_reference x, const_reference xs, auto&& compare) { if (auto&& iter = std::find_if(std::begin(xs), std::end(xs), [&](auto&& each) { return compare(x, each); }); iter) { @@ -244,17 +244,17 @@ inline namespace kernel } }; - auto memv = [](auto&&... xs) + inline auto memv = [](auto&&... xs) { return member(std::forward(xs)..., eqv); }; - auto memq = [](auto&&... xs) + inline auto memq = [](auto&&... xs) { return member(std::forward(xs)..., eq); }; - auto filter = [](auto&& satisfy, const_reference xs) + inline auto filter = [](auto&& satisfy, const_reference xs) { auto filter = [&](auto&& filter, let const& xs) { diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 3cc588f52..15bf7c006 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -32,7 +32,7 @@ namespace meevax { inline namespace kernel { - auto make_number = [](auto&& z) + inline auto make_number = [](auto&& z) { if constexpr (std::is_same::type, ratio>::value) { diff --git a/include/meevax/memory/collector.hpp b/include/meevax/memory/collector.hpp index bc4dc489a..a70fe202b 100644 --- a/include/meevax/memory/collector.hpp +++ b/include/meevax/memory/collector.hpp @@ -119,7 +119,7 @@ inline namespace memory template auto reset(Pointer const p) -> void { - reset(p ? locate(p) : nullptr); + reset(p != nullptr ? locate(p) : nullptr); } auto reset(traceable const& other) -> void diff --git a/include/meevax/utility/unwrap_reference_wrapper.hpp b/include/meevax/utility/unwrap_reference_wrapper.hpp index 59ba951a0..a15e546f2 100644 --- a/include/meevax/utility/unwrap_reference_wrapper.hpp +++ b/include/meevax/utility/unwrap_reference_wrapper.hpp @@ -26,7 +26,7 @@ namespace meevax { inline namespace type_traits { - auto unwrap_reference_wrapper = [](auto&& value) -> decltype(auto) + inline auto unwrap_reference_wrapper = [](auto&& value) -> decltype(auto) { if constexpr (is_reference_wrapper>::value) { From 2c55d71fd3c7b772a4d9fb505bb22d16992984da Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 31 Jul 2022 04:03:32 +0900 Subject: [PATCH 03/66] Add new class template `type_index` Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/type_index.hpp | 75 ++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 include/meevax/kernel/type_index.hpp diff --git a/README.md b/README.md index 90e222c4a..83b6e3e3f 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.168.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.169.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.168_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.169_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.168 +Meevax Lisp System, version 0.4.169 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index a78ca67e0..bf1003134 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.168 +0.4.169 diff --git a/include/meevax/kernel/type_index.hpp b/include/meevax/kernel/type_index.hpp new file mode 100644 index 000000000..3b20e6de6 --- /dev/null +++ b/include/meevax/kernel/type_index.hpp @@ -0,0 +1,75 @@ +/* + 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_TYPE_INDEX_HPP +#define INCLUDED_MEEVAX_KERNEL_TYPE_INDEX_HPP + +#include +#include +#include + +namespace meevax +{ +inline namespace kernel +{ + template + struct type_index + { + std::array type_infos; + + template + explicit type_index(Ts&&... xs) + : type_infos { std::addressof(xs)... } + {} + + auto hash_code() const + { + return std::accumulate(std::begin(type_infos), std::end(type_infos), 0, [](auto&& lhs, auto&& rhs) + { + return lhs xor rhs->hash_code(); // BAD HASHING + }); + } + }; + + template + auto operator ==(type_index const& lhs, type_index const& rhs) + { + for (auto i = 0; i < N; ++i) + { + if (lhs.type_infos[i] != rhs.type_infos[i]) + { + return false; + } + } + + return true; + } +} // namespace kernel +} // namespace meevax + +namespace std +{ + template + struct hash> + { + auto operator()(meevax::type_index const& index) const + { + return index.hash_code(); + } + }; +} + +#endif // INCLUDED_MEEVAX_KERNEL_TYPE_INDEX_HPP From befb55723c008809c2b8664d8366bb7597fe3c38 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 31 Jul 2022 04:55:07 +0900 Subject: [PATCH 04/66] Update `operator +` to use new compact double dispatcher Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/floating_point.hpp | 2 +- include/meevax/kernel/number.hpp | 19 +++++++++++++++++++ include/meevax/kernel/overview.hpp | 1 - src/kernel/number.cpp | 20 ++++++++++++++++++++ 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 83b6e3e3f..00406bc92 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.169.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.170.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.169_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.170_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.169 +Meevax Lisp System, version 0.4.170 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index bf1003134..254c658aa 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.169 +0.4.170 diff --git a/include/meevax/kernel/floating_point.hpp b/include/meevax/kernel/floating_point.hpp index 490b2b55e..8e7423b7a 100644 --- a/include/meevax/kernel/floating_point.hpp +++ b/include/meevax/kernel/floating_point.hpp @@ -127,7 +127,7 @@ inline namespace kernel #define DEFINE(NAME) \ auto NAME(const_reference x) const -> value_type override \ { \ - return make(floating_point(std::NAME(value, x.as().inexact().as()))); \ + return make(floating_point(std::NAME(value, x.as().inexact().as>()))); \ } \ static_assert(true) diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 15bf7c006..87a830c9c 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace meevax { @@ -249,6 +250,24 @@ inline namespace kernel template auto operator <=(floating_point const& a, floating_point const& b) -> bool { return a.value <= b.value; } template auto operator > (floating_point const& a, floating_point const& b) -> bool { return a.value > b.value; } template auto operator >=(floating_point const& a, floating_point const& b) -> bool { return a.value >= b.value; } + + namespace experimental + { + template + struct binary_operation + { + static inline constexpr Operator operate {}; + + auto operator ()(const_reference x, const_reference y) -> value_type + { + return make_number(operate(x.as(), y.as())); + } + }; + + extern std::unordered_map, std::function> add; + } + + auto operator +(const_reference, const_reference) -> value_type; } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/overview.hpp b/include/meevax/kernel/overview.hpp index 7875a2e65..9e794a493 100644 --- a/include/meevax/kernel/overview.hpp +++ b/include/meevax/kernel/overview.hpp @@ -106,7 +106,6 @@ inline namespace kernel } \ static_assert(true) - DEFINE(+); DEFINE(-); DEFINE(*); DEFINE(/); diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index 990c7a2ba..86673ed38 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -91,5 +91,25 @@ inline namespace kernel auto operator <=(ratio const& a, ratio const& b) -> bool { return (a.numerator().as() * b.denominator().as()) <= (b.numerator().as() * a.denominator().as()); } auto operator > (ratio const& a, ratio const& b) -> bool { return (a.numerator().as() * b.denominator().as()) > (b.numerator().as() * a.denominator().as()); } auto operator >=(ratio const& a, ratio const& b) -> bool { return (a.numerator().as() * b.denominator().as()) >= (b.numerator().as() * a.denominator().as()); } + + namespace experimental + { + #define ADD(T, U) { type_index<2>(typeid(T), typeid(U)), binary_operation, T, U>() } + + std::unordered_map, std::function> add + { + ADD(exact_integer, exact_integer), ADD(exact_integer, ratio), ADD(exact_integer, single_float), ADD(exact_integer, double_float), + ADD(ratio, exact_integer), ADD(ratio, ratio), ADD(ratio, single_float), ADD(ratio, double_float), + ADD(single_float, exact_integer), ADD(single_float, ratio), ADD(single_float, single_float), ADD(single_float, double_float), + ADD(double_float, exact_integer), ADD(double_float, ratio), ADD(double_float, single_float), ADD(double_float, double_float), + }; + + #undef ADD + } + + auto operator +(const_reference x, const_reference y) -> value_type + { + return experimental::add.at(type_index<2>(x.type(), y.type()))(x, y); + } } // namespace kernel } // namespace meevax From b3bf099144cf947900d9615b601a3be230c057c2 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 31 Jul 2022 05:10:58 +0900 Subject: [PATCH 05/66] Update operator `-` to use new compact double dispatcher Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/complex.hpp | 4 ++-- include/meevax/kernel/exact_integer.hpp | 4 ++-- include/meevax/kernel/floating_point.hpp | 4 ++-- include/meevax/kernel/number.hpp | 6 ++++-- include/meevax/kernel/overview.hpp | 7 ++++--- include/meevax/kernel/ratio.hpp | 4 ++-- src/kernel/number.cpp | 26 ++++++++++++++++-------- 9 files changed, 38 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 00406bc92..73f1eb182 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.170.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.171.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.170_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.171_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.170 +Meevax Lisp System, version 0.4.171 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 254c658aa..d05fd52eb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.170 +0.4.171 diff --git a/include/meevax/kernel/complex.hpp b/include/meevax/kernel/complex.hpp index 246eedd17..847de7e3f 100644 --- a/include/meevax/kernel/complex.hpp +++ b/include/meevax/kernel/complex.hpp @@ -66,8 +66,8 @@ inline namespace kernel #undef DEFINE - auto operator + (const_reference) const -> value_type override { return unspecified; } - auto operator - (const_reference) const -> value_type override { return unspecified; } + // auto operator + (const_reference) const -> value_type override { return unspecified; } + // auto operator - (const_reference) const -> value_type override { return unspecified; } auto operator * (const_reference) const -> value_type override { return unspecified; } auto operator / (const_reference) const -> value_type override { return unspecified; } auto operator % (const_reference) const -> value_type override { return unspecified; } diff --git a/include/meevax/kernel/exact_integer.hpp b/include/meevax/kernel/exact_integer.hpp index 796d11884..45b2a8e62 100644 --- a/include/meevax/kernel/exact_integer.hpp +++ b/include/meevax/kernel/exact_integer.hpp @@ -116,8 +116,8 @@ inline namespace kernel explicit operator external_representation() const; - auto operator + (const_reference) const -> value_type override; - auto operator - (const_reference) const -> value_type override; + // auto operator + (const_reference) const -> value_type override; + // auto operator - (const_reference) const -> value_type override; auto operator * (const_reference) const -> value_type override; auto operator / (const_reference) const -> value_type override; auto operator % (const_reference) const -> value_type override; diff --git a/include/meevax/kernel/floating_point.hpp b/include/meevax/kernel/floating_point.hpp index 8e7423b7a..be1f505c0 100644 --- a/include/meevax/kernel/floating_point.hpp +++ b/include/meevax/kernel/floating_point.hpp @@ -139,8 +139,8 @@ inline namespace kernel constexpr operator T() const noexcept { return value; } constexpr operator T() noexcept { return value; } - auto operator + (const_reference) const -> value_type override; - auto operator - (const_reference) const -> value_type override; + // auto operator + (const_reference) const -> value_type override; + // auto operator - (const_reference) const -> value_type override; auto operator * (const_reference) const -> value_type override; auto operator / (const_reference) const -> value_type override; auto operator % (const_reference) const -> value_type override; diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 87a830c9c..29d1740cd 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -190,8 +190,8 @@ inline namespace kernel template auto operator >=(ratio const& a, floating_point const& b) -> bool { return a.inexact().as() >= b; } template auto floating_point::operator * (const_reference x) const -> value_type { return apply(mul, *this, x); } - template auto floating_point::operator + (const_reference x) const -> value_type { return apply(add, *this, x); } - template auto floating_point::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } + // template auto floating_point::operator + (const_reference x) const -> value_type { return apply(add, *this, x); } + // template auto floating_point::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } template auto floating_point::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } template auto floating_point::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } template auto floating_point::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } @@ -265,9 +265,11 @@ inline namespace kernel }; extern std::unordered_map, std::function> add; + extern std::unordered_map, std::function> sub; } auto operator +(const_reference, const_reference) -> value_type; + auto operator -(const_reference, const_reference) -> value_type; } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/overview.hpp b/include/meevax/kernel/overview.hpp index 9e794a493..29276a778 100644 --- a/include/meevax/kernel/overview.hpp +++ b/include/meevax/kernel/overview.hpp @@ -83,8 +83,8 @@ inline namespace kernel virtual auto is_infinite() const -> bool { return false; } virtual auto is_nan () const -> bool { return false; } - virtual auto operator + (const_reference) const -> value_type = 0; - virtual auto operator - (const_reference) const -> value_type = 0; + // virtual auto operator + (const_reference) const -> value_type = 0; + // virtual auto operator - (const_reference) const -> value_type = 0; virtual auto operator * (const_reference) const -> value_type = 0; virtual auto operator / (const_reference) const -> value_type = 0; virtual auto operator % (const_reference) const -> value_type = 0; @@ -106,7 +106,8 @@ inline namespace kernel } \ static_assert(true) - DEFINE(-); + // DEFINE(+); + // DEFINE(-); DEFINE(*); DEFINE(/); DEFINE(%); diff --git a/include/meevax/kernel/ratio.hpp b/include/meevax/kernel/ratio.hpp index 91bea4870..6d889394e 100644 --- a/include/meevax/kernel/ratio.hpp +++ b/include/meevax/kernel/ratio.hpp @@ -78,8 +78,8 @@ inline namespace kernel #undef DEFINE - auto operator + (const_reference) const -> value_type override; - auto operator - (const_reference) const -> value_type override; + // auto operator + (const_reference) const -> value_type override; + // auto operator - (const_reference) const -> value_type override; auto operator * (const_reference) const -> value_type override; auto operator / (const_reference) const -> value_type override; auto operator % (const_reference) const -> value_type override; diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index 86673ed38..20eff5bcb 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -21,8 +21,8 @@ namespace meevax inline namespace kernel { auto exact_integer::operator * (const_reference b) const -> value_type { return apply(mul, *this, b); } - auto exact_integer::operator + (const_reference b) const -> value_type { return apply(add, *this, b); } - auto exact_integer::operator - (const_reference b) const -> value_type { return apply(sub, *this, b); } + // auto exact_integer::operator + (const_reference b) const -> value_type { return apply(add, *this, b); } + // auto exact_integer::operator - (const_reference b) const -> value_type { return apply(sub, *this, b); } auto exact_integer::operator / (const_reference b) const -> value_type { return apply(div, *this, b); } auto exact_integer::operator % (const_reference b) const -> value_type { return apply(mod, *this, b); } auto exact_integer::operator !=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, b); } @@ -57,8 +57,8 @@ inline namespace kernel auto operator >=(exact_integer const& a, ratio const& b) -> bool { auto const x = b.reduce(); return x.is_integer() ? a >= x.numerator().as() : false; } auto ratio::operator * (const_reference x) const -> value_type { return apply(mul, *this, x); } - auto ratio::operator + (const_reference x) const -> value_type { return apply(add, *this, x); } - auto ratio::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } + // auto ratio::operator + (const_reference x) const -> value_type { return apply(add, *this, x); } + // auto ratio::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } auto ratio::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } auto ratio::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } auto ratio::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } @@ -105,11 +105,21 @@ inline namespace kernel }; #undef ADD - } - auto operator +(const_reference x, const_reference y) -> value_type - { - return experimental::add.at(type_index<2>(x.type(), y.type()))(x, y); + #define SUB(T, U) { type_index<2>(typeid(T), typeid(U)), binary_operation, T, U>() } + + std::unordered_map, std::function> sub + { + SUB(exact_integer, exact_integer), SUB(exact_integer, ratio), SUB(exact_integer, single_float), SUB(exact_integer, double_float), + SUB(ratio, exact_integer), SUB(ratio, ratio), SUB(ratio, single_float), SUB(ratio, double_float), + SUB(single_float, exact_integer), SUB(single_float, ratio), SUB(single_float, single_float), SUB(single_float, double_float), + SUB(double_float, exact_integer), SUB(double_float, ratio), SUB(double_float, single_float), SUB(double_float, double_float), + }; + + #undef SUB } + + auto operator +(const_reference x, const_reference y) -> value_type { return experimental::add.at(type_index<2>(x.type(), y.type()))(x, y); } + auto operator -(const_reference x, const_reference y) -> value_type { return experimental::sub.at(type_index<2>(x.type(), y.type()))(x, y); } } // namespace kernel } // namespace meevax From 190074bc5a69596ba9dc211ada6d2b2e0afe301a Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 31 Jul 2022 05:38:24 +0900 Subject: [PATCH 06/66] Update `operator *`, `operator /` and `operator %` to use new compact double dispatcher Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/complex.hpp | 6 +-- include/meevax/kernel/exact_integer.hpp | 6 +-- include/meevax/kernel/floating_point.hpp | 6 +-- include/meevax/kernel/number.hpp | 12 ++++-- include/meevax/kernel/overview.hpp | 12 +++--- include/meevax/kernel/ratio.hpp | 6 +-- src/kernel/number.cpp | 55 +++++++++++------------- 9 files changed, 57 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 73f1eb182..6163e934b 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.171.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.172.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.171_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.172_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.171 +Meevax Lisp System, version 0.4.172 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index d05fd52eb..d6a41bfae 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.171 +0.4.172 diff --git a/include/meevax/kernel/complex.hpp b/include/meevax/kernel/complex.hpp index 847de7e3f..be2e3168b 100644 --- a/include/meevax/kernel/complex.hpp +++ b/include/meevax/kernel/complex.hpp @@ -68,9 +68,9 @@ inline namespace kernel // auto operator + (const_reference) const -> value_type override { return unspecified; } // auto operator - (const_reference) const -> value_type override { return unspecified; } - auto operator * (const_reference) const -> value_type override { return unspecified; } - auto operator / (const_reference) const -> value_type override { return unspecified; } - auto operator % (const_reference) const -> value_type override { return unspecified; } + // auto operator * (const_reference) const -> value_type override { return unspecified; } + // auto operator / (const_reference) const -> value_type override { return unspecified; } + // auto operator % (const_reference) const -> value_type override { return unspecified; } auto operator ==(const_reference) const -> bool override { return false; }; auto operator !=(const_reference) const -> bool override { return false; }; diff --git a/include/meevax/kernel/exact_integer.hpp b/include/meevax/kernel/exact_integer.hpp index 45b2a8e62..276602aed 100644 --- a/include/meevax/kernel/exact_integer.hpp +++ b/include/meevax/kernel/exact_integer.hpp @@ -118,9 +118,9 @@ inline namespace kernel // auto operator + (const_reference) const -> value_type override; // auto operator - (const_reference) const -> value_type override; - auto operator * (const_reference) const -> value_type override; - auto operator / (const_reference) const -> value_type override; - auto operator % (const_reference) const -> value_type override; + // auto operator * (const_reference) const -> value_type override; + // auto operator / (const_reference) const -> value_type override; + // auto operator % (const_reference) const -> value_type override; auto operator ==(const_reference) const -> bool override; auto operator !=(const_reference) const -> bool override; diff --git a/include/meevax/kernel/floating_point.hpp b/include/meevax/kernel/floating_point.hpp index be1f505c0..4bc975fc1 100644 --- a/include/meevax/kernel/floating_point.hpp +++ b/include/meevax/kernel/floating_point.hpp @@ -141,9 +141,9 @@ inline namespace kernel // auto operator + (const_reference) const -> value_type override; // auto operator - (const_reference) const -> value_type override; - auto operator * (const_reference) const -> value_type override; - auto operator / (const_reference) const -> value_type override; - auto operator % (const_reference) const -> value_type override; + // auto operator * (const_reference) const -> value_type override; + // auto operator / (const_reference) const -> value_type override; + // auto operator % (const_reference) const -> value_type override; auto operator ==(const_reference) const -> bool override; auto operator !=(const_reference) const -> bool override; diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 29d1740cd..703e98faa 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -189,11 +189,11 @@ inline namespace kernel template auto operator > (ratio const& a, floating_point const& b) -> bool { return a.inexact().as() > b; } template auto operator >=(ratio const& a, floating_point const& b) -> bool { return a.inexact().as() >= b; } - template auto floating_point::operator * (const_reference x) const -> value_type { return apply(mul, *this, x); } + // template auto floating_point::operator * (const_reference x) const -> value_type { return apply(mul, *this, x); } // template auto floating_point::operator + (const_reference x) const -> value_type { return apply(add, *this, x); } // template auto floating_point::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } - template auto floating_point::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } - template auto floating_point::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } + // template auto floating_point::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } + // template auto floating_point::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } template auto floating_point::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } template auto floating_point::operator < (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, x); } template auto floating_point::operator <=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, x); } @@ -266,10 +266,16 @@ inline namespace kernel extern std::unordered_map, std::function> add; extern std::unordered_map, std::function> sub; + extern std::unordered_map, std::function> mul; + extern std::unordered_map, std::function> div; + extern std::unordered_map, std::function> mod; } auto operator +(const_reference, const_reference) -> value_type; auto operator -(const_reference, const_reference) -> value_type; + auto operator *(const_reference, const_reference) -> value_type; + auto operator /(const_reference, const_reference) -> value_type; + auto operator %(const_reference, const_reference) -> value_type; } // namespace kernel } // namespace meevax diff --git a/include/meevax/kernel/overview.hpp b/include/meevax/kernel/overview.hpp index 29276a778..65078012c 100644 --- a/include/meevax/kernel/overview.hpp +++ b/include/meevax/kernel/overview.hpp @@ -85,9 +85,9 @@ inline namespace kernel // virtual auto operator + (const_reference) const -> value_type = 0; // virtual auto operator - (const_reference) const -> value_type = 0; - virtual auto operator * (const_reference) const -> value_type = 0; - virtual auto operator / (const_reference) const -> value_type = 0; - virtual auto operator % (const_reference) const -> value_type = 0; + // virtual auto operator * (const_reference) const -> value_type = 0; + // virtual auto operator / (const_reference) const -> value_type = 0; + // virtual auto operator % (const_reference) const -> value_type = 0; virtual auto operator ==(const_reference) const -> bool = 0; virtual auto operator !=(const_reference) const -> bool = 0; @@ -108,9 +108,9 @@ inline namespace kernel // DEFINE(+); // DEFINE(-); - DEFINE(*); - DEFINE(/); - DEFINE(%); + // DEFINE(*); + // DEFINE(/); + // DEFINE(%); #undef DEFINE diff --git a/include/meevax/kernel/ratio.hpp b/include/meevax/kernel/ratio.hpp index 6d889394e..6438ef7e6 100644 --- a/include/meevax/kernel/ratio.hpp +++ b/include/meevax/kernel/ratio.hpp @@ -80,9 +80,9 @@ inline namespace kernel // auto operator + (const_reference) const -> value_type override; // auto operator - (const_reference) const -> value_type override; - auto operator * (const_reference) const -> value_type override; - auto operator / (const_reference) const -> value_type override; - auto operator % (const_reference) const -> value_type override; + // auto operator * (const_reference) const -> value_type override; + // auto operator / (const_reference) const -> value_type override; + // auto operator % (const_reference) const -> value_type override; auto operator ==(const_reference) const -> bool override; auto operator !=(const_reference) const -> bool override; diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index 20eff5bcb..262671e73 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -20,11 +20,11 @@ namespace meevax { inline namespace kernel { - auto exact_integer::operator * (const_reference b) const -> value_type { return apply(mul, *this, b); } + // auto exact_integer::operator * (const_reference b) const -> value_type { return apply(mul, *this, b); } // auto exact_integer::operator + (const_reference b) const -> value_type { return apply(add, *this, b); } // auto exact_integer::operator - (const_reference b) const -> value_type { return apply(sub, *this, b); } - auto exact_integer::operator / (const_reference b) const -> value_type { return apply(div, *this, b); } - auto exact_integer::operator % (const_reference b) const -> value_type { return apply(mod, *this, b); } + // auto exact_integer::operator / (const_reference b) const -> value_type { return apply(div, *this, b); } + // auto exact_integer::operator % (const_reference b) const -> value_type { return apply(mod, *this, b); } auto exact_integer::operator !=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, b); } auto exact_integer::operator < (const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, b); } auto exact_integer::operator <=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, b); } @@ -56,11 +56,11 @@ inline namespace kernel auto operator > (exact_integer const& a, ratio const& b) -> bool { auto const x = b.reduce(); return x.is_integer() ? a > x.numerator().as() : false; } auto operator >=(exact_integer const& a, ratio const& b) -> bool { auto const x = b.reduce(); return x.is_integer() ? a >= x.numerator().as() : false; } - auto ratio::operator * (const_reference x) const -> value_type { return apply(mul, *this, x); } + // auto ratio::operator * (const_reference x) const -> value_type { return apply(mul, *this, x); } // auto ratio::operator + (const_reference x) const -> value_type { return apply(add, *this, x); } // auto ratio::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } - auto ratio::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } - auto ratio::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } + // auto ratio::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } + // auto ratio::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } auto ratio::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } auto ratio::operator < (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, x); } auto ratio::operator <=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, x); } @@ -94,32 +94,29 @@ inline namespace kernel namespace experimental { - #define ADD(T, U) { type_index<2>(typeid(T), typeid(U)), binary_operation, T, U>() } - - std::unordered_map, std::function> add - { - ADD(exact_integer, exact_integer), ADD(exact_integer, ratio), ADD(exact_integer, single_float), ADD(exact_integer, double_float), - ADD(ratio, exact_integer), ADD(ratio, ratio), ADD(ratio, single_float), ADD(ratio, double_float), - ADD(single_float, exact_integer), ADD(single_float, ratio), ADD(single_float, single_float), ADD(single_float, double_float), - ADD(double_float, exact_integer), ADD(double_float, ratio), ADD(double_float, single_float), ADD(double_float, double_float), - }; - - #undef ADD - - #define SUB(T, U) { type_index<2>(typeid(T), typeid(U)), binary_operation, T, U>() } - - std::unordered_map, std::function> sub - { - SUB(exact_integer, exact_integer), SUB(exact_integer, ratio), SUB(exact_integer, single_float), SUB(exact_integer, double_float), - SUB(ratio, exact_integer), SUB(ratio, ratio), SUB(ratio, single_float), SUB(ratio, double_float), - SUB(single_float, exact_integer), SUB(single_float, ratio), SUB(single_float, single_float), SUB(single_float, double_float), - SUB(double_float, exact_integer), SUB(double_float, ratio), SUB(double_float, single_float), SUB(double_float, double_float), - }; - - #undef SUB + #define APPLY(OPERATOR, T, U) \ + { type_index<2>(typeid(T), typeid(U)), binary_operation() } + + #define DEFINE_OVERLOADINGS(NAME, OP) \ + std::unordered_map, std::function> NAME \ + { \ + APPLY(OP, exact_integer, exact_integer), APPLY(OP, exact_integer, ratio), APPLY(OP, exact_integer, single_float), APPLY(OP, exact_integer, double_float), \ + APPLY(OP, ratio, exact_integer), APPLY(OP, ratio, ratio), APPLY(OP, ratio, single_float), APPLY(OP, ratio, double_float), \ + APPLY(OP, single_float, exact_integer), APPLY(OP, single_float, ratio), APPLY(OP, single_float, single_float), APPLY(OP, single_float, double_float), \ + APPLY(OP, double_float, exact_integer), APPLY(OP, double_float, ratio), APPLY(OP, double_float, single_float), APPLY(OP, double_float, double_float), \ + } + + DEFINE_OVERLOADINGS(add, std::plus ); + DEFINE_OVERLOADINGS(sub, std::minus ); + DEFINE_OVERLOADINGS(mul, std::multiplies); + DEFINE_OVERLOADINGS(div, std::divides ); + DEFINE_OVERLOADINGS(mod, std::modulus ); } auto operator +(const_reference x, const_reference y) -> value_type { return experimental::add.at(type_index<2>(x.type(), y.type()))(x, y); } auto operator -(const_reference x, const_reference y) -> value_type { return experimental::sub.at(type_index<2>(x.type(), y.type()))(x, y); } + auto operator *(const_reference x, const_reference y) -> value_type { return experimental::mul.at(type_index<2>(x.type(), y.type()))(x, y); } + auto operator /(const_reference x, const_reference y) -> value_type { return experimental::div.at(type_index<2>(x.type(), y.type()))(x, y); } + auto operator %(const_reference x, const_reference y) -> value_type { return experimental::mod.at(type_index<2>(x.type(), y.type()))(x, y); } } // namespace kernel } // namespace meevax From 16df6cf90ab5fbd44fa6794f4d6ada73d1caaa36 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 31 Jul 2022 06:08:12 +0900 Subject: [PATCH 07/66] Update arithmetic comparisons to use new compact double dispatcher Signed-off-by: yamacir-kit --- README.md | 6 ++--- VERSION | 2 +- include/meevax/kernel/complex.hpp | 12 ++++----- include/meevax/kernel/exact_integer.hpp | 12 ++++----- include/meevax/kernel/floating_point.hpp | 12 ++++----- include/meevax/kernel/number.hpp | 19 +++++++++----- include/meevax/kernel/overview.hpp | 12 ++++----- include/meevax/kernel/ratio.hpp | 12 ++++----- src/kernel/complex.cpp | 2 +- src/kernel/library.cpp | 14 +++++------ src/kernel/number.cpp | 32 +++++++++++++++--------- 11 files changed, 75 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 6163e934b..1b8516414 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.172.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.173.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.172_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.173_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.172 +Meevax Lisp System, version 0.4.173 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index d6a41bfae..3bb742681 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.172 +0.4.173 diff --git a/include/meevax/kernel/complex.hpp b/include/meevax/kernel/complex.hpp index be2e3168b..00bcbdd48 100644 --- a/include/meevax/kernel/complex.hpp +++ b/include/meevax/kernel/complex.hpp @@ -72,12 +72,12 @@ inline namespace kernel // auto operator / (const_reference) const -> value_type override { return unspecified; } // auto operator % (const_reference) const -> value_type override { return unspecified; } - auto operator ==(const_reference) const -> bool override { return false; }; - auto operator !=(const_reference) const -> bool override { return false; }; - auto operator < (const_reference) const -> bool override { return false; }; - auto operator <=(const_reference) const -> bool override { return false; }; - auto operator > (const_reference) const -> bool override { return false; }; - auto operator >=(const_reference) const -> bool override { return false; }; + // auto operator ==(const_reference) const -> bool override { return false; }; + // auto operator !=(const_reference) const -> bool override { return false; }; + // auto operator < (const_reference) const -> bool override { return false; }; + // auto operator <=(const_reference) const -> bool override { return false; }; + // auto operator > (const_reference) const -> bool override { return false; }; + // auto operator >=(const_reference) const -> bool override { return false; }; }; auto operator <<(std::ostream &, complex const&) -> std::ostream &; diff --git a/include/meevax/kernel/exact_integer.hpp b/include/meevax/kernel/exact_integer.hpp index 276602aed..81bf34c0c 100644 --- a/include/meevax/kernel/exact_integer.hpp +++ b/include/meevax/kernel/exact_integer.hpp @@ -122,12 +122,12 @@ inline namespace kernel // auto operator / (const_reference) const -> value_type override; // auto operator % (const_reference) const -> value_type override; - auto operator ==(const_reference) const -> bool override; - auto operator !=(const_reference) const -> bool override; - auto operator < (const_reference) const -> bool override; - auto operator <=(const_reference) const -> bool override; - auto operator > (const_reference) const -> bool override; - auto operator >=(const_reference) const -> bool override; + // auto operator ==(const_reference) const -> bool override; + // auto operator !=(const_reference) const -> bool override; + // auto operator < (const_reference) const -> bool override; + // auto operator <=(const_reference) const -> bool override; + // auto operator > (const_reference) const -> bool override; + // auto operator >=(const_reference) const -> bool override; }; auto operator ==(exact_integer const&, int const) -> bool; diff --git a/include/meevax/kernel/floating_point.hpp b/include/meevax/kernel/floating_point.hpp index 4bc975fc1..8b50cf326 100644 --- a/include/meevax/kernel/floating_point.hpp +++ b/include/meevax/kernel/floating_point.hpp @@ -145,12 +145,12 @@ inline namespace kernel // auto operator / (const_reference) const -> value_type override; // auto operator % (const_reference) const -> value_type override; - auto operator ==(const_reference) const -> bool override; - auto operator !=(const_reference) const -> bool override; - auto operator < (const_reference) const -> bool override; - auto operator <=(const_reference) const -> bool override; - auto operator > (const_reference) const -> bool override; - auto operator >=(const_reference) const -> bool override; + // auto operator ==(const_reference) const -> bool override; + // auto operator !=(const_reference) const -> bool override; + // auto operator < (const_reference) const -> bool override; + // auto operator <=(const_reference) const -> bool override; + // auto operator > (const_reference) const -> bool override; + // auto operator >=(const_reference) const -> bool override; }; template diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 703e98faa..9755a4f7e 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -194,12 +194,12 @@ inline namespace kernel // template auto floating_point::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } // template auto floating_point::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } // template auto floating_point::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } - template auto floating_point::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } - template auto floating_point::operator < (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, x); } - template auto floating_point::operator <=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, x); } - template auto floating_point::operator ==(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a == b; }, *this, x); } - template auto floating_point::operator > (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a > b; }, *this, x); } - template auto floating_point::operator >=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a >= b; }, *this, x); } + // template auto floating_point::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } + // template auto floating_point::operator < (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, x); } + // template auto floating_point::operator <=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, x); } + // template auto floating_point::operator ==(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a == b; }, *this, x); } + // template auto floating_point::operator > (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a > b; }, *this, x); } + // template auto floating_point::operator >=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a >= b; }, *this, x); } template auto operator * (floating_point const& a, exact_integer const& b) { return a * b.inexact().as(); } template auto operator + (floating_point const& a, exact_integer const& b) { return a + b.inexact().as(); } @@ -269,6 +269,13 @@ inline namespace kernel extern std::unordered_map, std::function> mul; extern std::unordered_map, std::function> div; extern std::unordered_map, std::function> mod; + + extern std::unordered_map, std::function> equal_to; + extern std::unordered_map, std::function> not_equal_to; + extern std::unordered_map, std::function> less; + extern std::unordered_map, std::function> less_equal; + extern std::unordered_map, std::function> greater; + extern std::unordered_map, std::function> greater_equal; } auto operator +(const_reference, const_reference) -> value_type; diff --git a/include/meevax/kernel/overview.hpp b/include/meevax/kernel/overview.hpp index 65078012c..82a79f090 100644 --- a/include/meevax/kernel/overview.hpp +++ b/include/meevax/kernel/overview.hpp @@ -89,12 +89,12 @@ inline namespace kernel // virtual auto operator / (const_reference) const -> value_type = 0; // virtual auto operator % (const_reference) const -> value_type = 0; - virtual auto operator ==(const_reference) const -> bool = 0; - virtual auto operator !=(const_reference) const -> bool = 0; - virtual auto operator < (const_reference) const -> bool = 0; - virtual auto operator <=(const_reference) const -> bool = 0; - virtual auto operator > (const_reference) const -> bool = 0; - virtual auto operator >=(const_reference) const -> bool = 0; + // virtual auto operator ==(const_reference) const -> bool = 0; + // virtual auto operator !=(const_reference) const -> bool = 0; + // virtual auto operator < (const_reference) const -> bool = 0; + // virtual auto operator <=(const_reference) const -> bool = 0; + // virtual auto operator > (const_reference) const -> bool = 0; + // virtual auto operator >=(const_reference) const -> bool = 0; }; #define DEFINE(SYMBOL) \ diff --git a/include/meevax/kernel/ratio.hpp b/include/meevax/kernel/ratio.hpp index 6438ef7e6..723acdd42 100644 --- a/include/meevax/kernel/ratio.hpp +++ b/include/meevax/kernel/ratio.hpp @@ -84,12 +84,12 @@ inline namespace kernel // auto operator / (const_reference) const -> value_type override; // auto operator % (const_reference) const -> value_type override; - auto operator ==(const_reference) const -> bool override; - auto operator !=(const_reference) const -> bool override; - auto operator < (const_reference) const -> bool override; - auto operator <=(const_reference) const -> bool override; - auto operator > (const_reference) const -> bool override; - auto operator >=(const_reference) const -> bool override; + // auto operator ==(const_reference) const -> bool override; + // auto operator !=(const_reference) const -> bool override; + // auto operator < (const_reference) const -> bool override; + // auto operator <=(const_reference) const -> bool override; + // auto operator > (const_reference) const -> bool override; + // auto operator >=(const_reference) const -> bool override; }; auto operator <<(std::ostream &, ratio const&) -> std::ostream &; diff --git a/src/kernel/complex.cpp b/src/kernel/complex.cpp index 003a4d771..78133adf6 100644 --- a/src/kernel/complex.cpp +++ b/src/kernel/complex.cpp @@ -43,7 +43,7 @@ inline namespace kernel auto operator <<(std::ostream & os, complex const& z) -> std::ostream & { - return os << z.real() << cyan(e0.as() < z.imag() ? '+' : '-') << z.imag() << cyan("i"); + return os << z.real() << cyan(experimental::less.at(type_index<2>(e0.type(), z.imag().type()))(e0, z.imag()) ? '+' : '-') << z.imag() << cyan("i"); } } // namespace kernel } // namespace meevax diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index 3dd5ce710..c005610a8 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -472,16 +472,16 @@ inline namespace kernel return std::adjacent_find( \ std::begin(xs), std::end(xs), [](let const& a, let const& b) \ { \ - return not COMPARE(a.as(), b); \ + return not experimental::COMPARE.at(type_index<2>(a.type(), b.type()))(a, b).as(); \ }) == std::end(xs); \ }) - DEFINE(= , std::equal_to ()); - DEFINE(!=, std::not_equal_to ()); - DEFINE(< , std::less ()); - DEFINE(<=, std::less_equal ()); - DEFINE(> , std::greater ()); - DEFINE(>=, std::greater_equal()); + DEFINE(= , equal_to ); + DEFINE(!=, not_equal_to ); + DEFINE(< , less ); + DEFINE(<=, less_equal ); + DEFINE(> , greater ); + DEFINE(>=, greater_equal); #undef DEFINE diff --git a/src/kernel/number.cpp b/src/kernel/number.cpp index 262671e73..5f3652e1d 100644 --- a/src/kernel/number.cpp +++ b/src/kernel/number.cpp @@ -14,6 +14,7 @@ limitations under the License. */ +#include #include namespace meevax @@ -25,12 +26,12 @@ inline namespace kernel // auto exact_integer::operator - (const_reference b) const -> value_type { return apply(sub, *this, b); } // auto exact_integer::operator / (const_reference b) const -> value_type { return apply(div, *this, b); } // auto exact_integer::operator % (const_reference b) const -> value_type { return apply(mod, *this, b); } - auto exact_integer::operator !=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, b); } - auto exact_integer::operator < (const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, b); } - auto exact_integer::operator <=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, b); } - auto exact_integer::operator ==(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a == b; }, *this, b); } - auto exact_integer::operator > (const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a > b; }, *this, b); } - auto exact_integer::operator >=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a >= b; }, *this, b); } + // auto exact_integer::operator !=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, b); } + // auto exact_integer::operator < (const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, b); } + // auto exact_integer::operator <=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, b); } + // auto exact_integer::operator ==(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a == b; }, *this, b); } + // auto exact_integer::operator > (const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a > b; }, *this, b); } + // auto exact_integer::operator >=(const_reference b) const -> bool { return apply([](auto&& a, auto&& b) { return a >= b; }, *this, b); } auto operator * (exact_integer const& a, exact_integer const& b) -> exact_integer { return exact_integer(mul, a, b); } auto operator + (exact_integer const& a, exact_integer const& b) -> exact_integer { return exact_integer(add, a, b); } @@ -61,12 +62,12 @@ inline namespace kernel // auto ratio::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } // auto ratio::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } // auto ratio::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } - auto ratio::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } - auto ratio::operator < (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, x); } - auto ratio::operator <=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, x); } - auto ratio::operator ==(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a == b; }, *this, x); } - auto ratio::operator > (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a > b; }, *this, x); } - auto ratio::operator >=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a >= b; }, *this, x); } + // auto ratio::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } + // auto ratio::operator < (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, x); } + // auto ratio::operator <=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, x); } + // auto ratio::operator ==(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a == b; }, *this, x); } + // auto ratio::operator > (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a > b; }, *this, x); } + // auto ratio::operator >=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a >= b; }, *this, x); } auto operator * (ratio const& a, exact_integer const& b) -> ratio { return ratio(make(a.numerator().as() * b), cdr(a)); } auto operator + (ratio const& a, exact_integer const& b) -> ratio { return ratio(make(a.numerator().as() + a.denominator().as() * b), cdr(a)); } @@ -111,6 +112,13 @@ inline namespace kernel DEFINE_OVERLOADINGS(mul, std::multiplies); DEFINE_OVERLOADINGS(div, std::divides ); DEFINE_OVERLOADINGS(mod, std::modulus ); + + DEFINE_OVERLOADINGS(equal_to, std::equal_to ); + DEFINE_OVERLOADINGS(not_equal_to, std::not_equal_to ); + DEFINE_OVERLOADINGS(less, std::less ); + DEFINE_OVERLOADINGS(less_equal, std::less_equal ); + DEFINE_OVERLOADINGS(greater, std::greater ); + DEFINE_OVERLOADINGS(greater_equal, std::greater_equal); } auto operator +(const_reference x, const_reference y) -> value_type { return experimental::add.at(type_index<2>(x.type(), y.type()))(x, y); } From 8ea84ffdb4971802c4af3fae1773032e437a72f4 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 31 Jul 2022 06:21:10 +0900 Subject: [PATCH 08/66] Cleanup Signed-off-by: yamacir-kit --- README.md | 6 +- VERSION | 2 +- include/meevax/kernel/complex.hpp | 13 ---- include/meevax/kernel/exact_integer.hpp | 13 ---- include/meevax/kernel/floating_point.hpp | 13 ---- include/meevax/kernel/number.hpp | 84 ------------------------ include/meevax/kernel/overview.hpp | 30 --------- include/meevax/kernel/ratio.hpp | 13 ---- src/kernel/number.cpp | 24 ------- 9 files changed, 4 insertions(+), 194 deletions(-) diff --git a/README.md b/README.md index 1b8516414..5628a2b1f 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |:-------------------|:-- -| `all` (default) | Build shared-library `libmeevax.0.4.173.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.174.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.173_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.174_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` @@ -122,7 +122,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's ## Usage ``` -Meevax Lisp System, version 0.4.173 +Meevax Lisp System, version 0.4.174 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 3bb742681..64efc0555 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.173 +0.4.174 diff --git a/include/meevax/kernel/complex.hpp b/include/meevax/kernel/complex.hpp index 00bcbdd48..268f3848a 100644 --- a/include/meevax/kernel/complex.hpp +++ b/include/meevax/kernel/complex.hpp @@ -65,19 +65,6 @@ inline namespace kernel DEFINE(pow); #undef DEFINE - - // auto operator + (const_reference) const -> value_type override { return unspecified; } - // auto operator - (const_reference) const -> value_type override { return unspecified; } - // auto operator * (const_reference) const -> value_type override { return unspecified; } - // auto operator / (const_reference) const -> value_type override { return unspecified; } - // auto operator % (const_reference) const -> value_type override { return unspecified; } - - // auto operator ==(const_reference) const -> bool override { return false; }; - // auto operator !=(const_reference) const -> bool override { return false; }; - // auto operator < (const_reference) const -> bool override { return false; }; - // auto operator <=(const_reference) const -> bool override { return false; }; - // auto operator > (const_reference) const -> bool override { return false; }; - // auto operator >=(const_reference) const -> bool override { return false; }; }; auto operator <<(std::ostream &, complex const&) -> std::ostream &; diff --git a/include/meevax/kernel/exact_integer.hpp b/include/meevax/kernel/exact_integer.hpp index 81bf34c0c..76de4ddef 100644 --- a/include/meevax/kernel/exact_integer.hpp +++ b/include/meevax/kernel/exact_integer.hpp @@ -115,19 +115,6 @@ inline namespace kernel explicit operator double() const; explicit operator external_representation() const; - - // auto operator + (const_reference) const -> value_type override; - // auto operator - (const_reference) const -> value_type override; - // auto operator * (const_reference) const -> value_type override; - // auto operator / (const_reference) const -> value_type override; - // auto operator % (const_reference) const -> value_type override; - - // auto operator ==(const_reference) const -> bool override; - // auto operator !=(const_reference) const -> bool override; - // auto operator < (const_reference) const -> bool override; - // auto operator <=(const_reference) const -> bool override; - // auto operator > (const_reference) const -> bool override; - // auto operator >=(const_reference) const -> bool override; }; auto operator ==(exact_integer const&, int const) -> bool; diff --git a/include/meevax/kernel/floating_point.hpp b/include/meevax/kernel/floating_point.hpp index 8b50cf326..a21449b09 100644 --- a/include/meevax/kernel/floating_point.hpp +++ b/include/meevax/kernel/floating_point.hpp @@ -138,19 +138,6 @@ inline namespace kernel constexpr operator T() const noexcept { return value; } constexpr operator T() noexcept { return value; } - - // auto operator + (const_reference) const -> value_type override; - // auto operator - (const_reference) const -> value_type override; - // auto operator * (const_reference) const -> value_type override; - // auto operator / (const_reference) const -> value_type override; - // auto operator % (const_reference) const -> value_type override; - - // auto operator ==(const_reference) const -> bool override; - // auto operator !=(const_reference) const -> bool override; - // auto operator < (const_reference) const -> bool override; - // auto operator <=(const_reference) const -> bool override; - // auto operator > (const_reference) const -> bool override; - // auto operator >=(const_reference) const -> bool override; }; template diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 9755a4f7e..c9bfad6c4 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -45,78 +45,6 @@ inline namespace kernel } }; - /* ---- Binary Numerical Comparator Overloaings Adapter ---------------------- - * - * Dispatch static numeric vs. dynamic numerical operations to static - * overloads. If the rvalue type binds a non-numeric type, an exception is - * thrown. - * - * Usage: - * - * auto operator <(Number const& lhs, const_reference rhs) - * { - * return apply(std::less(), lhs, rhs); - * } - * - * ------------------------------------------------------------------------ */ - template - auto apply(F&& procedure, T const& a, const_reference b) -> decltype(auto) - { - static std::unordered_map< - std::type_index, std::function> const overloads - { - { typeid(single_float), [&](T const& a, const_reference b) { return procedure(a, b.as()); } }, - { typeid(double_float), [&](T const& a, const_reference b) { return procedure(a, b.as()); } }, - { typeid(ratio), [&](T const& a, const_reference b) { return procedure(a, b.as()); } }, - { typeid(exact_integer), [&](T const& a, const_reference b) { return procedure(a, b.as()); } }, - }; - - if (auto const iter = overloads.find(b.type()); iter != std::end(overloads)) - { - return cdr(*iter)(a, b); - } - else - { - throw error(make(concatenate("no viable operation ", demangle(typeid(F)), " with ", a, " and ", b))); - } - } - - /* ---- Binary Numerical Operator Overloaings Adapter ------------------------ - * - * Dispatch static numeric vs. dynamic numerical operations to static - * overloads. If the rvalue type binds a non-numeric type, an exception is - * thrown. - * - * Usage: - * - * let operator +(Number const& lhs, const_reference rhs) - * { - * return apply(add, lhs, rhs); - * } - * - * ------------------------------------------------------------------------ */ - template - auto apply(F&& procedure, T const& a, const_reference b) -> decltype(auto) - { - static std::unordered_map< - std::type_index, std::function> const overloads - { - { typeid(single_float), [&](T const& a, const_reference b) { return make_number(procedure(a, b.as())); } }, - { typeid(double_float), [&](T const& a, const_reference b) { return make_number(procedure(a, b.as())); } }, - { typeid(ratio), [&](T const& a, const_reference b) { return make_number(procedure(a, b.as())); } }, - { typeid(exact_integer), [&](T const& a, const_reference b) { return make_number(procedure(a, b.as())); } }, - }; - - if (auto const iter = overloads.find(b.type()); iter != std::end(overloads)) - { - return cdr(*iter)(a, b); - } - else - { - throw error(make(concatenate("no viable operation ", demangle(typeid(F)), " with ", a, " and ", b))); - } - } - auto operator * (exact_integer const&, exact_integer const&) -> exact_integer; auto operator + (exact_integer const&, exact_integer const&) -> exact_integer; auto operator - (exact_integer const&, exact_integer const&) -> exact_integer; @@ -189,18 +117,6 @@ inline namespace kernel template auto operator > (ratio const& a, floating_point const& b) -> bool { return a.inexact().as() > b; } template auto operator >=(ratio const& a, floating_point const& b) -> bool { return a.inexact().as() >= b; } - // template auto floating_point::operator * (const_reference x) const -> value_type { return apply(mul, *this, x); } - // template auto floating_point::operator + (const_reference x) const -> value_type { return apply(add, *this, x); } - // template auto floating_point::operator - (const_reference x) const -> value_type { return apply(sub, *this, x); } - // template auto floating_point::operator / (const_reference x) const -> value_type { return apply(div, *this, x); } - // template auto floating_point::operator % (const_reference x) const -> value_type { return apply(mod, *this, x); } - // template auto floating_point::operator !=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a != b; }, *this, x); } - // template auto floating_point::operator < (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a < b; }, *this, x); } - // template auto floating_point::operator <=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a <= b; }, *this, x); } - // template auto floating_point::operator ==(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a == b; }, *this, x); } - // template auto floating_point::operator > (const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a > b; }, *this, x); } - // template auto floating_point::operator >=(const_reference x) const -> bool { return apply([](auto&& a, auto&& b) { return a >= b; }, *this, x); } - template auto operator * (floating_point const& a, exact_integer const& b) { return a * b.inexact().as(); } template auto operator + (floating_point const& a, exact_integer const& b) { return a + b.inexact().as(); } template auto operator - (floating_point const& a, exact_integer const& b) { return a - b.inexact().as(); } diff --git a/include/meevax/kernel/overview.hpp b/include/meevax/kernel/overview.hpp index 82a79f090..1da85c7a9 100644 --- a/include/meevax/kernel/overview.hpp +++ b/include/meevax/kernel/overview.hpp @@ -82,38 +82,8 @@ inline namespace kernel virtual auto is_finite () const -> bool { return true ; } virtual auto is_infinite() const -> bool { return false; } virtual auto is_nan () const -> bool { return false; } - - // virtual auto operator + (const_reference) const -> value_type = 0; - // virtual auto operator - (const_reference) const -> value_type = 0; - // virtual auto operator * (const_reference) const -> value_type = 0; - // virtual auto operator / (const_reference) const -> value_type = 0; - // virtual auto operator % (const_reference) const -> value_type = 0; - - // virtual auto operator ==(const_reference) const -> bool = 0; - // virtual auto operator !=(const_reference) const -> bool = 0; - // virtual auto operator < (const_reference) const -> bool = 0; - // virtual auto operator <=(const_reference) const -> bool = 0; - // virtual auto operator > (const_reference) const -> bool = 0; - // virtual auto operator >=(const_reference) const -> bool = 0; }; - #define DEFINE(SYMBOL) \ - template