diff --git a/README.md b/README.md index 83e04d3fb..409ef7a61 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.207.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.208.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.207_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.208_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.207 +Meevax Lisp System, version 0.4.208 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 3e33edbc5..cab5b51e7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.207 +0.4.208 diff --git a/include/meevax/kernel/exact_integer.hpp b/include/meevax/kernel/exact_integer.hpp index 261666dd9..daba883ea 100644 --- a/include/meevax/kernel/exact_integer.hpp +++ b/include/meevax/kernel/exact_integer.hpp @@ -29,13 +29,15 @@ inline namespace kernel { mpz_t value; - explicit exact_integer() noexcept; - - explicit exact_integer(mpz_t const) noexcept; + exact_integer() noexcept; exact_integer(exact_integer const&) noexcept; - explicit exact_integer(exact_integer &&) noexcept; + exact_integer(exact_integer &&) noexcept; + + ~exact_integer(); + + explicit exact_integer(mpz_t const) noexcept; explicit exact_integer(int); @@ -47,18 +49,12 @@ inline namespace kernel explicit exact_integer(external_representation const&, int = 0); - ~exact_integer(); - auto operator=(exact_integer const&) -> exact_integer &; auto operator=(exact_integer &&) noexcept -> exact_integer &; auto operator=(external_representation const&) -> exact_integer &; - auto swap(exact_integer &) noexcept -> void; - - explicit operator bool() const; - operator int() const; operator signed long() const; @@ -68,6 +64,8 @@ inline namespace kernel explicit operator float() const; explicit operator double() const; + + explicit operator bool() const; }; auto operator ==(exact_integer const&, int const) -> bool; diff --git a/include/meevax/kernel/number.hpp b/include/meevax/kernel/number.hpp index 8e3957d7f..0363d66ff 100644 --- a/include/meevax/kernel/number.hpp +++ b/include/meevax/kernel/number.hpp @@ -195,9 +195,9 @@ inline namespace kernel } else if constexpr (std::is_same_v, ratio>) { - if (auto i = exact_integer(mpq_denref(z.value)); i == 1) + if (z.denominator() == 1) { - return z.numerator(); + return make(z.numerator()); } else { @@ -380,7 +380,7 @@ inline namespace kernel } else if constexpr (std::is_same_v, ratio>) { - return x.denominator().template as() == 1; + return x.denominator() == 1; } else { diff --git a/include/meevax/kernel/ratio.hpp b/include/meevax/kernel/ratio.hpp index d4d97163d..1b6a04d5f 100644 --- a/include/meevax/kernel/ratio.hpp +++ b/include/meevax/kernel/ratio.hpp @@ -18,7 +18,6 @@ #define INCLUDED_MEEVAX_KERNEL_RATIO_HPP #include - #include namespace meevax @@ -35,6 +34,8 @@ inline namespace kernel ratio(ratio &&); + ~ratio(); + explicit ratio(exact_integer const&); explicit ratio(exact_integer const&, exact_integer const&); @@ -43,11 +44,9 @@ inline namespace kernel explicit ratio(external_representation const&, int = 10); - ~ratio(); - - auto denominator() const -> value_type; + auto denominator() const -> exact_integer; - auto numerator() const -> value_type; + auto numerator() const -> exact_integer; explicit operator double() const; }; diff --git a/src/kernel/exact_integer.cpp b/src/kernel/exact_integer.cpp index 62ab132cb..38e20a53d 100644 --- a/src/kernel/exact_integer.cpp +++ b/src/kernel/exact_integer.cpp @@ -31,11 +31,6 @@ inline namespace kernel mpz_init(value); } - exact_integer::exact_integer(mpz_t const z) noexcept - { - mpz_init_set(value, z); - } - exact_integer::exact_integer(exact_integer const& other) noexcept { mpz_init_set(value, other.value); @@ -47,6 +42,16 @@ inline namespace kernel mpz_swap(value, other.value); } + exact_integer::~exact_integer() + { + mpz_clear(value); + } + + exact_integer::exact_integer(mpz_t const z) noexcept + { + mpz_init_set(value, z); + } + exact_integer::exact_integer(int rhs) : exact_integer(static_cast(rhs)) {} @@ -75,20 +80,15 @@ inline namespace kernel } } - exact_integer::~exact_integer() - { - mpz_clear(value); - } - auto exact_integer::operator=(exact_integer const& rhs) -> exact_integer & { mpz_set(value, rhs.value); return *this; } - auto exact_integer::operator=(exact_integer && rhs) noexcept -> exact_integer & + auto exact_integer::operator=(exact_integer && other) noexcept -> exact_integer & { - swap(rhs); + mpz_swap(value, other.value); return *this; } @@ -104,11 +104,6 @@ inline namespace kernel } } - auto exact_integer::swap(exact_integer & rhs) noexcept -> void - { - std::swap(*value, *rhs.value); - } - exact_integer::operator bool() const { return (*value)._mp_size; diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index cd0cb8110..e4bb7750d 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -571,12 +571,12 @@ inline namespace kernel library.define("ratio-numerator", [](let const& xs) { - return car(xs).as().numerator(); + return make(car(xs).as().numerator()); }); library.define("ratio-denominator", [](let const& xs) { - return car(xs).as().denominator(); + return make(car(xs).as().denominator()); }); library.define("floor", [](let const& xs) diff --git a/src/kernel/ratio.cpp b/src/kernel/ratio.cpp index 06a1192b1..fc5880337 100644 --- a/src/kernel/ratio.cpp +++ b/src/kernel/ratio.cpp @@ -63,14 +63,14 @@ inline namespace kernel ratio::ratio(external_representation const& token, int radix) { - std::regex static const pattern { "([+-]?[0-9a-f]+)/([0-9a-f]+)" }; + // std::regex static const pattern { "([+-]?[0-9a-f]+)/([0-9a-f]+)" }; - if (mpq_init(value); not std::regex_match(token, pattern) or mpq_set_str(value, token.c_str(), radix)) + if (mpq_init(value); mpq_set_str(value, token.c_str(), radix)) { mpq_clear(value); throw error(); } - else // TEMPORARY!!! + else { mpq_canonicalize(value); } @@ -81,19 +81,19 @@ inline namespace kernel mpq_clear(value); } - auto ratio::denominator() const -> value_type + auto ratio::denominator() const -> exact_integer { - return make(mpq_denref(value)); + return exact_integer(mpq_denref(value)); } - auto ratio::numerator() const -> value_type + auto ratio::numerator() const -> exact_integer { - return make(mpq_numref(value)); + return exact_integer(mpq_numref(value)); } ratio::operator double() const { - return static_cast(numerator().as()) / static_cast(denominator().as()); + return mpq_get_d(value); } auto operator <<(std::ostream & os, ratio const& datum) -> std::ostream &