From da28d83c0a3a056b854d78c3c2843e5705c84119 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 May 2022 12:39:36 +0900 Subject: [PATCH 01/40] Update benchmark scripts Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- benchmark/ack.ss | 3 +++ benchmark/tarai.ss | 3 +++ script/benchmark.sh | 28 ++++++++++++++++++++-------- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4791a7999..b729fe4dd 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.0.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.1.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.0_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.1_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.0 +Meevax Lisp System, version 0.4.1 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 1d0ba9ea1..267577d47 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.0 +0.4.1 diff --git a/benchmark/ack.ss b/benchmark/ack.ss index be261c365..6ac974da6 100644 --- a/benchmark/ack.ss +++ b/benchmark/ack.ss @@ -1,3 +1,6 @@ +(import (scheme r5rs) + (scheme process-context)) + (define (ack m n) (cond ((= m 0) (+ n 1)) ((= n 0) (ack (- m 1) 1)) diff --git a/benchmark/tarai.ss b/benchmark/tarai.ss index 24d634266..8460d3780 100644 --- a/benchmark/tarai.ss +++ b/benchmark/tarai.ss @@ -1,3 +1,6 @@ +(import (scheme r5rs) + (scheme process-context)) + (define (tarai x y z) (if (not (< y x)) y (tarai (tarai (- x 1) y z) diff --git a/script/benchmark.sh b/script/benchmark.sh index 0320329d1..471f5ac2e 100755 --- a/script/benchmark.sh +++ b/script/benchmark.sh @@ -13,15 +13,27 @@ real() (time -p "$@") 2>&1 | grep -e 'real' | sed -e 's/real\s//' } -ratio() +quotient() { - time_meevax=$(real meevax "$@") - time_gauche=$(real gosh "$@") + echo "scale = 1; $1 / $2" | bc -s +} + +tsv() +{ + printf " \tMeevax\tGauche\tChibi\n" + + for each in $(scripts) + do + time_m=$(real meevax "$root/benchmark/$each.ss") + time_g=$(real gosh "$root/benchmark/$each.ss") + time_c=$(real chibi-scheme "$root/benchmark/$each.ss") - echo "scale = 1; $time_meevax / $time_gauche" | bc -s + printf "%s\t%s\t%s\t%s\n" \ + "$each" \ + "$time_m" \ + "$time_g ($(quotient "$time_m" "$time_g"))" \ + "$time_c ($(quotient "$time_m" "$time_c"))" + done } -for each in $(scripts) -do - printf "%s\t%s\n" "$each" "$(ratio "$root/benchmark/$each.ss")" -done +tsv | column -t -s"$(printf '\t')" From cbdf3fc007d609a562e8f963479aea980ff96fc1 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 May 2022 13:24:25 +0900 Subject: [PATCH 02/40] Remove file `src/library/meevax.cpp` Signed-off-by: yamacir-kit --- README.md | 6 ++--- VERSION | 2 +- src/library/meevax.cpp | 53 ------------------------------------------ 3 files changed, 4 insertions(+), 57 deletions(-) delete mode 100644 src/library/meevax.cpp diff --git a/README.md b/README.md index b729fe4dd..3318ba621 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.1.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.2.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.1_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.2_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.1 +Meevax Lisp System, version 0.4.2 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 267577d47..2b7c5ae01 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.1 +0.4.2 diff --git a/src/library/meevax.cpp b/src/library/meevax.cpp deleted file mode 100644 index 6863d803f..000000000 --- a/src/library/meevax.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - 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 -#include - -namespace meevax -{ - // environment::environment(master_t) - // { - // // std::vector const codes { - // // srfi_211, - // // r4rs_essential, - // // srfi_45, - // // r4rs, - // // srfi_149, - // // r5rs, - // // srfi_6, // Basic String Ports - // // srfi_34, // Exception Handling for Programs - // // srfi_23, // Error reporting mechanism - // // srfi_39, // Parameter objects - // // r7rs, - // // srfi_8, // receive: Binding to multiple values - // // srfi_1, // List Library - // // srfi_78, // Lightweight testing - // // }; - // // - // // for (auto const& code : codes) - // // { - // // // NOTE: Since read performs a putback operation on a given stream, it must be copied and used. - // // auto port = std::stringstream(std::string(code)); - // // - // // for (let e = read(port); e != eof_object; e = read(port)) - // // { - // // evaluate(e); - // // } - // // } - // } -} // namespace meevax From 5058c0d154cfb87d46a923591dfc6ac5fa9fdf6e Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 May 2022 14:10:01 +0900 Subject: [PATCH 03/40] Rename some `region`'s member function Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/memory/region.hpp | 16 ++++++++-------- src/memory/collector.cpp | 4 ++-- src/memory/region.cpp | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3318ba621..6d4a478da 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.2.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.3.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.2_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.3_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.2 +Meevax Lisp System, version 0.4.3 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 2b7c5ae01..17b2ccd9b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.2 +0.4.3 diff --git a/include/meevax/memory/region.hpp b/include/meevax/memory/region.hpp index 37bf02082..9b9935dd6 100644 --- a/include/meevax/memory/region.hpp +++ b/include/meevax/memory/region.hpp @@ -45,28 +45,28 @@ inline namespace memory auto assigned() const noexcept -> bool; + auto begin() const noexcept -> std::uintptr_t + { + return reinterpret_cast(base); + } + auto contains(std::uintptr_t const) const noexcept -> bool; auto contains(void const* const) const noexcept -> bool; - auto lower_bound() const noexcept -> std::uintptr_t + auto end() const noexcept -> std::uintptr_t { - return reinterpret_cast(base); + return begin() + size; } auto release() -> void; auto reset(void const* const = nullptr, deallocator::signature const = nullptr) noexcept -> region *; - - auto upper_bound() const noexcept -> std::uintptr_t - { - return lower_bound() + size; - } }; inline auto operator <(region const& x, region const& y) { - return x.upper_bound() < y.lower_bound(); + return x.end() < y.begin(); } } // namespace memory } // namespace meevax diff --git a/src/memory/collector.cpp b/src/memory/collector.cpp index 80a8997ec..4e344e419 100644 --- a/src/memory/collector.cpp +++ b/src/memory/collector.cpp @@ -216,8 +216,8 @@ inline namespace memory { the_region->mark(); - const auto lower = objects.lower_bound(reinterpret_cast(the_region->lower_bound())); - const auto upper = objects.lower_bound(reinterpret_cast(the_region->upper_bound())); + const auto lower = objects.lower_bound(reinterpret_cast(the_region->begin())); + const auto upper = objects.lower_bound(reinterpret_cast(the_region->end())); for (auto iter = lower; iter != upper; ++iter) { diff --git a/src/memory/region.cpp b/src/memory/region.cpp index 49759d183..0a1f8d985 100644 --- a/src/memory/region.cpp +++ b/src/memory/region.cpp @@ -40,7 +40,7 @@ inline namespace memory auto region::contains(std::uintptr_t const k) const noexcept -> bool { - return lower_bound() <= k and k < upper_bound(); + return begin() <= k and k < end(); } auto region::contains(void const* const derived) const noexcept -> bool From a68266eee9a5501bd05132d1b7cd5cd7eeee5d67 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 May 2022 15:15:54 +0900 Subject: [PATCH 04/40] Lipsticks Signed-off-by: yamacir-kit --- README.md | 6 ++--- VERSION | 2 +- include/meevax/memory/collector.hpp | 21 ++++++++---------- src/memory/collector.cpp | 34 ++++++++++++++--------------- 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 6d4a478da..a66c79e41 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.3.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.4.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.3_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.4_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.3 +Meevax Lisp System, version 0.4.4 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 17b2ccd9b..6f2743d65 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.3 +0.4.4 diff --git a/include/meevax/memory/collector.hpp b/include/meevax/memory/collector.hpp index cedbbe07c..2b2f98cf4 100644 --- a/include/meevax/memory/collector.hpp +++ b/include/meevax/memory/collector.hpp @@ -82,18 +82,15 @@ inline namespace memory private: static inline std::mutex resource; - static inline std::set< - region *, - std::less, - simple_allocator - > regions; - - static inline std::map< - interior * const, - region *, - std::less, - simple_allocator> - > objects; + template + using fast_set = std::set, simple_allocator>; + + static inline fast_set regions; + + template + using fast_map = std::map, simple_allocator>>; + + static inline fast_map objects; static inline std::size_t allocation; diff --git a/src/memory/collector.cpp b/src/memory/collector.cpp index 4e344e419..cba90e362 100644 --- a/src/memory/collector.cpp +++ b/src/memory/collector.cpp @@ -117,15 +117,9 @@ inline namespace memory auto collector::deallocate(void * const data, std::size_t const) -> void { - try - { - if (auto const iter = region_of(data); *iter) - { - regions.erase(iter); - } - } - catch (...) - {} + assert(*region_of(data)); + + regions.erase(region_of(data)); ::operator delete(data); } @@ -136,7 +130,9 @@ inline namespace memory for (auto&& [derived, region] : objects) { - if (region and not region->marked() and region_of(derived) == std::cend(regions)) + assert(region); // NOTE: objects always hold a valid region pointer. + + if (not region->marked() and region_of(derived) == std::cend(regions)) { traverse(region); } @@ -147,15 +143,17 @@ inline namespace memory { region dummy { interior, 0 }; - auto invalid = std::cend(regions); + assert(interior); + + auto not_found = std::cend(regions); - if (auto iter = regions.lower_bound(std::addressof(dummy)); iter != invalid and (*iter)->contains(interior)) + if (auto iter = regions.lower_bound(std::addressof(dummy)); iter != not_found and (*iter)->contains(interior)) { return iter; } else { - return invalid; + return not_found; } } @@ -210,14 +208,14 @@ inline namespace memory } } - auto collector::traverse(region * const the_region) -> void + auto collector::traverse(region * const region) -> void { - if (the_region and not the_region->marked()) + if (region and not region->marked()) { - the_region->mark(); + region->mark(); - const auto lower = objects.lower_bound(reinterpret_cast(the_region->begin())); - const auto upper = objects.lower_bound(reinterpret_cast(the_region->end())); + const auto lower = objects.lower_bound(reinterpret_cast(region->begin())); + const auto upper = objects.lower_bound(reinterpret_cast(region->end())); for (auto iter = lower; iter != upper; ++iter) { From cf1456e0cb967941b1184ac9309b8a75e2c1bf01 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 May 2022 19:34:24 +0900 Subject: [PATCH 05/40] Simplify profiler Signed-off-by: yamacir-kit --- README.md | 6 +-- VERSION | 2 +- include/meevax/kernel/heterogeneous.hpp | 2 +- include/meevax/kernel/overview.hpp | 2 +- include/meevax/kernel/profiler.hpp | 12 +++-- src/kernel/profiler.cpp | 66 ++++++------------------- 6 files changed, 28 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index a66c79e41..b433c97f7 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.4.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.5.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.4_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.5_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.4 +Meevax Lisp System, version 0.4.5 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 6f2743d65..0bfccb080 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.4 +0.4.5 diff --git a/include/meevax/kernel/heterogeneous.hpp b/include/meevax/kernel/heterogeneous.hpp index 9c7714f98..442e90ffb 100644 --- a/include/meevax/kernel/heterogeneous.hpp +++ b/include/meevax/kernel/heterogeneous.hpp @@ -81,7 +81,7 @@ inline namespace kernel static auto allocate(Ts&&... xs) { #if PROFILE_ALLOCATION - current_profiler()[typeid(typename std::decay::type)].allocation++; + current_profiler().by_type[typeid(typename std::decay::type)].allocation++; #endif return static_cast( diff --git a/include/meevax/kernel/overview.hpp b/include/meevax/kernel/overview.hpp index e6d398b10..b4525c04c 100644 --- a/include/meevax/kernel/overview.hpp +++ b/include/meevax/kernel/overview.hpp @@ -23,7 +23,7 @@ #define NIL /* nothing */ -#define PROFILE_ALLOCATION false +#define PROFILE_ALLOCATION true namespace meevax { diff --git a/include/meevax/kernel/profiler.hpp b/include/meevax/kernel/profiler.hpp index 2622e0bd7..58ac9fed2 100644 --- a/include/meevax/kernel/profiler.hpp +++ b/include/meevax/kernel/profiler.hpp @@ -24,13 +24,15 @@ namespace meevax { inline namespace kernel { - struct topic + struct profiler { - std::size_t allocation = 0; - }; + struct topic + { + std::size_t allocation = 0; + }; + + std::unordered_map by_type; - struct profiler : public std::unordered_map - { ~profiler(); }; diff --git a/src/kernel/profiler.cpp b/src/kernel/profiler.cpp index d9a1bed04..af7ce3b53 100644 --- a/src/kernel/profiler.cpp +++ b/src/kernel/profiler.cpp @@ -14,11 +14,7 @@ limitations under the License. */ -#include -#include -#include -#include -#include +#include #include #include @@ -27,61 +23,29 @@ namespace meevax { inline namespace kernel { - struct column : public topic + auto sh(std::string const& command) { - std::string name; - - template - explicit column(std::type_index const& id, Ts&&... xs) - : topic { std::forward(xs)... } - , name { demangle(id.name()) } - {} - }; + if (auto status = std::system(command.c_str()); status < 0) + { + std::exit(EXIT_FAILURE); + } + else + { + return WIFEXITED(status); + } + } profiler::~profiler() { - auto make_table = [this]() + if (auto file = std::ofstream("/tmp/meevax-profile-by-type.txt"); file) { - std::vector result; - - for (auto const& [key, value] : *this) + for (auto&& [type, topic] : by_type) { - result.emplace_back(key, value); + file << topic.allocation << " " << demangle(type.name()) << "\n"; } - - return result; - }; - - auto table = make_table(); - - std::sort(std::begin(table), std::end(table), [](auto&& a, auto&& b) - { - return a.allocation > b.allocation; - }); - - std::vector column_width; - - column_width.push_back(std::max_element(std::begin(table), std::end(table), [](auto&& a, auto&& b) { return a.name.length() < b.name.length(); })->name.length()); - column_width.push_back(12); - - std::cout << std::string(80, '-') << "\n" - << std::left << std::setw(column_width[0]) << "Typename" - << std::right << std::setw(column_width[1]) << "Allocations" - << "\n" - << std::string(80, '-') << "\n"; - - for (auto const& each : table) - { - std::cout << std::left << std::setw(column_width[0]) << each.name - << std::right << std::setw(column_width[1]) << each.allocation - << std::endl; } - std::cout << std::string(80, '-') << "\n" - << std::left << std::setw(column_width[0]) << "Total" - << std::right << std::setw(column_width[1]) << std::accumulate(std::begin(table), std::end(table), 0, [](auto&& a, auto&& b) { return a + b.allocation; }) - << "\n" - << std::string(80, '-') << "\n"; + sh("cat /tmp/meevax-profile-by-type.txt | sed 's/meevax::kernel:://g' | sort -rn | column -t"); } auto current_profiler() -> profiler & From fe3125e9f1865fc56affcbc46fe074e26f82de6d Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 May 2022 21:34:34 +0900 Subject: [PATCH 06/40] Update `iterator` to inherit `reference_wrapper` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/iterator.hpp | 11 +++++++++-- include/meevax/kernel/list.hpp | 8 +++++--- include/meevax/kernel/machine.hpp | 6 +++--- include/meevax/kernel/overview.hpp | 2 +- src/kernel/iterator.cpp | 3 +-- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b433c97f7..d8603d602 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.5.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.6.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.5_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.6_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.5 +Meevax Lisp System, version 0.4.6 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 0bfccb080..ef52a6480 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.5 +0.4.6 diff --git a/include/meevax/kernel/iterator.hpp b/include/meevax/kernel/iterator.hpp index 23e6530e6..0d498c837 100644 --- a/include/meevax/kernel/iterator.hpp +++ b/include/meevax/kernel/iterator.hpp @@ -25,7 +25,7 @@ namespace meevax { inline namespace kernel { - struct iterator : public object + struct iterator : public std::reference_wrapper { using iterator_category = std::forward_iterator_tag; @@ -41,7 +41,9 @@ inline namespace kernel using size_type = std::size_t; - using object::object; + iterator(const_reference x) + : std::reference_wrapper { std::cref(x) } + {} auto operator *() const -> const_reference; @@ -50,6 +52,11 @@ inline namespace kernel auto operator ++() -> iterator &; auto operator ++(int) -> iterator; + + operator bool() const + { + return static_cast(get()); + } }; auto operator ==(iterator const&, iterator const&) noexcept -> bool; diff --git a/include/meevax/kernel/list.hpp b/include/meevax/kernel/list.hpp index 6829ad9ac..2b5029a03 100644 --- a/include/meevax/kernel/list.hpp +++ b/include/meevax/kernel/list.hpp @@ -30,11 +30,13 @@ inline namespace kernel { auto unwrap = [](auto&& x) -> decltype(auto) { - static_assert(std::is_convertible::value); - using type = typename std::decay::type; - if constexpr (std::is_convertible::value) + if constexpr (std::is_same::value) + { + return x.get().template as(); + } + else if constexpr (std::is_same::value) { return x.template as(); } diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index 72149eb10..d6c8e6683 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -692,11 +692,11 @@ inline namespace kernel { for (auto inner = std::begin(*outer); inner != std::end(*outer); ++inner) { - if (inner.is() and (*inner).is() and eq((*inner).as().symbol(), variable)) + if (inner.get().is() and (*inner).is() and eq((*inner).as().symbol(), variable)) { return *inner; } - else if (inner.is() and eq(*inner, variable)) + else if (inner.get().is() and eq(*inner, variable)) { // NOTE: A class that inherits from pair behaves as if it were `cons*` when given three or more arguments. static_assert(std::is_base_of::value); @@ -705,7 +705,7 @@ inline namespace kernel make(std::distance(std::begin(scope), outer)), make(std::distance(std::begin(*outer), inner))); } - else if (inner.is() and eq(inner, variable)) + else if (inner.get().is() and eq(inner, variable)) { // NOTE: A class that inherits from pair behaves as if it were `cons*` when given three or more arguments. static_assert(std::is_base_of::value); diff --git a/include/meevax/kernel/overview.hpp b/include/meevax/kernel/overview.hpp index b4525c04c..e6d398b10 100644 --- a/include/meevax/kernel/overview.hpp +++ b/include/meevax/kernel/overview.hpp @@ -23,7 +23,7 @@ #define NIL /* nothing */ -#define PROFILE_ALLOCATION true +#define PROFILE_ALLOCATION false namespace meevax { diff --git a/src/kernel/iterator.cpp b/src/kernel/iterator.cpp index 566877961..d36db6786 100644 --- a/src/kernel/iterator.cpp +++ b/src/kernel/iterator.cpp @@ -32,8 +32,7 @@ inline namespace kernel auto iterator::operator ++() -> iterator & { - static_cast(*this) = cdr(*this); - return *this; + return *this = cdr(*this); } auto iterator::operator ++(int) -> iterator From 4994b52c072bec3737479734d739735d38f4fac5 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 21 May 2022 22:18:23 +0900 Subject: [PATCH 07/40] Remove header `kernel/stack.hpp` Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/list.hpp | 2 +- include/meevax/kernel/machine.hpp | 16 +++++++---- include/meevax/kernel/stack.hpp | 48 ------------------------------- script/install.sh | 2 +- src/kernel/vector.cpp | 1 - 7 files changed, 17 insertions(+), 60 deletions(-) delete mode 100644 include/meevax/kernel/stack.hpp diff --git a/README.md b/README.md index d8603d602..f889ca4be 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.6.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.7.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.6_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.7_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.6 +Meevax Lisp System, version 0.4.7 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index ef52a6480..f90568270 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.6 +0.4.7 diff --git a/include/meevax/kernel/list.hpp b/include/meevax/kernel/list.hpp index 2b5029a03..d1097238d 100644 --- a/include/meevax/kernel/list.hpp +++ b/include/meevax/kernel/list.hpp @@ -168,7 +168,7 @@ inline namespace kernel }; template - auto list_tail(T&& x, std::size_t const k) -> T + auto list_tail(T&& x, std::size_t const k) -> decltype(x) { return 0 < k ? list_tail(cdr(x), k - 1) : x; } diff --git a/include/meevax/kernel/machine.hpp b/include/meevax/kernel/machine.hpp index d6c8e6683..a7bd6a006 100644 --- a/include/meevax/kernel/machine.hpp +++ b/include/meevax/kernel/machine.hpp @@ -24,7 +24,6 @@ #include #include #include -#include #include namespace meevax @@ -628,9 +627,10 @@ inline namespace kernel * (x . s) e (%return . c) (s' e' c' . d) => (x . s') e' c' d * * ------------------------------------------------------------------- */ - s = cons(car(s), pop(d)); - e = pop(d); - c = pop(d); + s = cons(car(s), car(d)); + e = cadr(d); + c = caddr(d); + d = cdddr(d); goto decode; case mnemonic::cons: /* -------------------------------------------------- @@ -682,7 +682,13 @@ inline namespace kernel * (x . s) e (%stop . c) d => s e (%stop . c) d * * ------------------------------------------------------------------- */ - return pop(s); // return car(s); + return [this]() + { + assert(cdr(s).template is()); + let const x = car(s); + s = unit; + return x; + }(); } } diff --git a/include/meevax/kernel/stack.hpp b/include/meevax/kernel/stack.hpp deleted file mode 100644 index 65c1191a3..000000000 --- a/include/meevax/kernel/stack.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - 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_STACK_HPP -#define INCLUDED_MEEVAX_KERNEL_STACK_HPP - -#include - -namespace meevax -{ -inline namespace kernel -{ - template - auto push(T&& stack, Ts&&... xs) -> decltype(auto) - { - return stack = cons(std::forward(xs)..., stack); - } - - template - auto pop(T&& stack) -> decltype(auto) - { - return stack = std::next(std::begin(stack), N); - } - - template - auto pop(T&& stack) - { - let const x = car(stack); - pop<1>(stack); - return x; - } -} // namespace kernel -} // namespace meevax - -#endif // INCLUDED_MEEVAX_KERNEL_STACK_HPP diff --git a/script/install.sh b/script/install.sh index 713204d58..a0c600565 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=Debug -DCMAKE_CXX_COMPILER=g++ cmake --build "$2" --target "$1" } diff --git a/src/kernel/vector.cpp b/src/kernel/vector.cpp index 337a5fe18..a9f5f4685 100644 --- a/src/kernel/vector.cpp +++ b/src/kernel/vector.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include From f90312f4fe924bcab20957aa0a5056389f8bde5f Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 22 May 2022 01:12:23 +0900 Subject: [PATCH 08/40] Update `collector` to allocate `region` type object via `simple_allocator` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/memory/collector.hpp | 12 ++++++------ include/meevax/memory/simple_allocator.hpp | 12 ++++++++++++ script/install.sh | 2 +- src/memory/collector.cpp | 22 +++++++++++----------- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index f889ca4be..7725c73b9 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.7.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.8.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.7_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.8_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.7 +Meevax Lisp System, version 0.4.8 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index f90568270..cb498ab2c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.7 +0.4.8 diff --git a/include/meevax/memory/collector.hpp b/include/meevax/memory/collector.hpp index 2b2f98cf4..fe97f3b21 100644 --- a/include/meevax/memory/collector.hpp +++ b/include/meevax/memory/collector.hpp @@ -45,8 +45,6 @@ inline namespace memory class collector { public: - using is_always_equal = std::true_type; - struct interior { protected: @@ -82,19 +80,21 @@ inline namespace memory private: static inline std::mutex resource; + static inline simple_allocator regions_ {}; + template using fast_set = std::set, simple_allocator>; - static inline fast_set regions; + static inline fast_set regions {}; template using fast_map = std::map, simple_allocator>>; - static inline fast_map objects; + static inline fast_map objects {}; - static inline std::size_t allocation; + static inline std::size_t allocation = 0; - static inline std::size_t threshold; + static inline std::size_t threshold = 8_MiB; public: explicit collector(); diff --git a/include/meevax/memory/simple_allocator.hpp b/include/meevax/memory/simple_allocator.hpp index 888cb1be5..b042ca9cf 100644 --- a/include/meevax/memory/simple_allocator.hpp +++ b/include/meevax/memory/simple_allocator.hpp @@ -122,6 +122,18 @@ class simple_allocator reinterpret_cast(p)->next = recycled_chunk; recycled_chunk = reinterpret_cast(p); } + + template + auto new_(Ts&&... xs) + { + return ::new (allocate()) T(std::forward(xs)...); + } + + auto delete_(pointer p) -> void + { + (*p).~T(); + deallocate(p); + } }; } // namespace memory } // namespace meevax diff --git a/script/install.sh b/script/install.sh index a0c600565..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=Debug -DCMAKE_CXX_COMPILER=g++ + cmake -B "$2" -S "$(dirname "$2")" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=g++ cmake --build "$2" --target "$1" } diff --git a/src/memory/collector.cpp b/src/memory/collector.cpp index cba90e362..03a330eb1 100644 --- a/src/memory/collector.cpp +++ b/src/memory/collector.cpp @@ -27,14 +27,14 @@ inline namespace memory { if (not reference_count++) { - objects = {}; - - regions = {}; - - allocation = 0; - - // threshold = std::numeric_limits::max(); - threshold = 8_MiB; + // objects = {}; + // + // regions = {}; + // + // allocation = 0; + // + // // threshold = std::numeric_limits::max(); + // threshold = 8_MiB; } } @@ -68,7 +68,7 @@ inline namespace memory allocation += size; - regions.insert(new region(data, size)); + regions.insert(regions_.new_(data, size)); return data; } @@ -86,7 +86,7 @@ inline namespace memory if (auto region = *iter; region->assigned()) { - delete region; + regions_.delete_(region); iter = regions.erase(iter); } else @@ -194,7 +194,7 @@ inline namespace memory { if (region->assigned()) { - delete region; + regions_.delete_(region); iter = regions.erase(iter); continue; } From 34a52fbd745227b77f84e5a2bc414375f859ccc5 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 22 May 2022 20:12:49 +0900 Subject: [PATCH 09/40] Lipsticks Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/memory/collector.hpp | 14 +++++++------- src/memory/collector.cpp | 21 ++++++++++----------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 7725c73b9..ad0e63680 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.8.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.9.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.8_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.9_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.8 +Meevax Lisp System, version 0.4.9 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index cb498ab2c..76914ddc0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.8 +0.4.9 diff --git a/include/meevax/memory/collector.hpp b/include/meevax/memory/collector.hpp index fe97f3b21..67b354ce9 100644 --- a/include/meevax/memory/collector.hpp +++ b/include/meevax/memory/collector.hpp @@ -80,21 +80,21 @@ inline namespace memory private: static inline std::mutex resource; - static inline simple_allocator regions_ {}; + static inline simple_allocator region_allocator {}; template - using fast_set = std::set, simple_allocator>; + using set = std::set, simple_allocator>; - static inline fast_set regions {}; + static inline set regions; template - using fast_map = std::map, simple_allocator>>; + using map = std::map, simple_allocator>>; - static inline fast_map objects {}; + static inline map objects; - static inline std::size_t allocation = 0; + static inline std::size_t allocation; - static inline std::size_t threshold = 8_MiB; + static inline std::size_t threshold; public: explicit collector(); diff --git a/src/memory/collector.cpp b/src/memory/collector.cpp index 03a330eb1..c6c543bed 100644 --- a/src/memory/collector.cpp +++ b/src/memory/collector.cpp @@ -27,14 +27,13 @@ inline namespace memory { if (not reference_count++) { - // objects = {}; - // - // regions = {}; - // - // allocation = 0; - // - // // threshold = std::numeric_limits::max(); - // threshold = 8_MiB; + objects = {}; + + regions = {}; + + allocation = 0; + + threshold = 8_MiB; } } @@ -68,7 +67,7 @@ inline namespace memory allocation += size; - regions.insert(regions_.new_(data, size)); + regions.insert(region_allocator.new_(data, size)); return data; } @@ -86,7 +85,7 @@ inline namespace memory if (auto region = *iter; region->assigned()) { - regions_.delete_(region); + region_allocator.delete_(region); iter = regions.erase(iter); } else @@ -194,7 +193,7 @@ inline namespace memory { if (region->assigned()) { - regions_.delete_(region); + region_allocator.delete_(region); iter = regions.erase(iter); continue; } From 63412d5ac23d8d6d41e5a8b6b07fc73425f35c22 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Wed, 25 May 2022 00:31:11 +0900 Subject: [PATCH 10/40] Rename procedure `default-exception-handler` to `throw` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- basis/srfi-34.ss | 4 ++-- include/meevax/kernel/error.hpp | 2 +- src/kernel/library.cpp | 27 +++++++++++++++++++++------ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ad0e63680..b92ddf823 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.9.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.10.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.9_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.10_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.9 +Meevax Lisp System, version 0.4.10 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 76914ddc0..e8423da87 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.9 +0.4.10 diff --git a/basis/srfi-34.ss b/basis/srfi-34.ss index 404b73064..b15fe5830 100644 --- a/basis/srfi-34.ss +++ b/basis/srfi-34.ss @@ -19,7 +19,7 @@ ; IN THE SOFTWARE. (define-library (srfi 34) - (import (only (meevax exception) default-exception-handler) + (import (only (meevax exception) throw) (scheme r5rs) ) @@ -29,7 +29,7 @@ guard ) - (begin (define %current-exception-handlers (list default-exception-handler)) + (begin (define %current-exception-handlers (list throw)) (define (%with-exception-handlers new-handlers thunk) (let ((old-handlers %current-exception-handlers)) diff --git a/include/meevax/kernel/error.hpp b/include/meevax/kernel/error.hpp index 0442e3917..0b66b18ef 100644 --- a/include/meevax/kernel/error.hpp +++ b/include/meevax/kernel/error.hpp @@ -82,7 +82,7 @@ inline namespace kernel return underlying_cast(value); } - catch (const_reference error) // NOTE: default-exception-handler (Terminate the program without running any outstanding dynamic-wind after procedures) + catch (const_reference error) // NOTE: procedure `throw` (Terminate the program without running any outstanding dynamic-wind after procedures) { std::cerr << "; " << error << std::endl; return underlying_cast(exit_status::failure); diff --git a/src/kernel/library.cpp b/src/kernel/library.cpp index 6b25b0375..2708d35b3 100644 --- a/src/kernel/library.cpp +++ b/src/kernel/library.cpp @@ -688,7 +688,7 @@ inline namespace kernel library::library(exception_library_t) { - define("default-exception-handler", [](let const& xs) -> object + define("throw", [](let const& xs) -> object { throw car(xs); }); @@ -698,12 +698,27 @@ inline namespace kernel return make(car(xs), cdr(xs)); }); - define( "error?", [](let const& xs) { return car(xs).is< error>(); }); - define( "read-error?", [](let const& xs) { return car(xs).is< read_error>(); }); - define( "file-error?", [](let const& xs) { return car(xs).is< file_error>(); }); - define("syntax-error?", [](let const& xs) { return car(xs).is(); }); + define("error?", [](let const& xs) + { + return car(xs).is(); + }); + + define("read-error?", [](let const& xs) + { + return car(xs).is(); + }); + + define("file-error?", [](let const& xs) + { + return car(xs).is(); + }); + + define("syntax-error?", [](let const& xs) + { + return car(xs).is(); + }); - declare_export("default-exception-handler", + declare_export("throw", "make-error", "error?", "read-error?", From a687c70b622ba0c27cc011971d5abdd6dd113888 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Wed, 25 May 2022 02:06:02 +0900 Subject: [PATCH 11/40] Lipsticks Signed-off-by: yamacir-kit --- README.md | 6 +- VERSION | 2 +- include/meevax/kernel/list.hpp | 6 +- test/sicp-1.ss | 327 ++++++++++++++------------------- 4 files changed, 145 insertions(+), 196 deletions(-) diff --git a/README.md b/README.md index b92ddf823..3a4489840 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.10.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.11.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.10_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.11_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.10 +Meevax Lisp System, version 0.4.11 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index e8423da87..5f749c136 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.10 +0.4.11 diff --git a/include/meevax/kernel/list.hpp b/include/meevax/kernel/list.hpp index d1097238d..915b2e745 100644 --- a/include/meevax/kernel/list.hpp +++ b/include/meevax/kernel/list.hpp @@ -168,13 +168,13 @@ inline namespace kernel }; template - auto list_tail(T&& x, std::size_t const k) -> decltype(x) + auto list_tail(T&& x, std::size_t const k) -> const_reference { return 0 < k ? list_tail(cdr(x), k - 1) : x; } template - auto list_tail(T&& x, const_reference k) -> decltype(auto) + auto list_tail(T&& x, const_reference k) -> const_reference { assert(k.is()); return list_tail(std::forward(x), static_cast(k.as())); @@ -187,7 +187,7 @@ inline namespace kernel // return std::next(std::cbegin(x), static_cast(k.template as())); // }; - auto list_ref = [](auto&&... xs) constexpr -> decltype(auto) + auto list_ref = [](auto&&... xs) constexpr -> const_reference { return car(list_tail(std::forward(xs)...)); }; diff --git a/test/sicp-1.ss b/test/sicp-1.ss index 69a0967ea..65dc0b89d 100644 --- a/test/sicp-1.ss +++ b/test/sicp-1.ss @@ -1,3 +1,7 @@ +; Structure and Interpretation of Computer Programs by Harold Abelson and +; Gerald Jay Sussman with Julie Sussman is licensed under a Creative Commons +; Attribution-ShareAlike 4.0 International License by the MIT Press. + (import (scheme base) (scheme process-context) (srfi 78)) @@ -44,10 +48,7 @@ ; ---- Section 1.1.3 ----------------------------------------------------------- -(check - (* (+ 2 (* 4 6)) - (+ 3 5 7)) - => 390) +(check (* (+ 2 (* 4 6)) (+ 3 5 7)) => 390) ; ---- Section 1.1.4 ----------------------------------------------------------- @@ -74,6 +75,14 @@ (check (f 5) => 136) +(check (sum-of-squares (+ 5 1) (* 5 2)) => 136) + +(check (+ (square 6) (square 10)) => 136) + +(check (+ (* 6 6) (* 10 10)) => 136) + +(check (+ 36 100) => 136) + ; ---- Section 1.1.6 ----------------------------------------------------------- (define (abs x) @@ -90,9 +99,12 @@ (- x) x)) -(define (>= x y) (or (> x y) (= x y))) +(define (>= x y) + (or (> x y) + (= x y))) -(define (>= x y) (not (< x y))) +(define (>= x y) + (not (< x y))) ; ---- Exercise 1.1 ------------------------------------------------------------ @@ -112,30 +124,24 @@ (check (+ a b (* a b)) => 19) -(check (= a b) => #false) +(check (= a b) => #f) (check (if (and (> b a) (< b (* a b))) b a) => 4) -(check - (cond ((= a 4) 6) - ((= b 4) (+ 6 7 a)) - (else 25)) - => 16) +(check (cond ((= a 4) 6) + ((= b 4) (+ 6 7 a)) + (else 25)) => 16) (check (+ 2 (if (> b a) b a)) => 6) -(check - (* (cond ((> a b) a) - ((< a b) b) - (else -1)) - (+ a 1)) - => 16) +(check (* (cond ((> a b) a) + ((< a b) b) + (else -1)) + (+ a 1)) => 16) ; ---- Exercise 1.2 ------------------------------------------------------------ -; TODO -; (check (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7))) -; => -37/150) +(check (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7))) => -37/150) ; ---- Exercise 1.3 ------------------------------------------------------------ @@ -192,26 +198,37 @@ (check (square (sqrt 1000)) => 1000.000369924366) -; ---- Exercise 1.7 ------------------------------------------------------------ +; ---- Exercise 1.6 ------------------------------------------------------------ -(define (good-enough? guess x) - (= (improve guess x) guess)) +(define (new-if predicate then-clause else-clause) + (cond (predicate then-clause) + (else else-clause))) -(check (sqrt 9) => 3.0) +(check (new-if (= 2 3) 0 5) => 5) -(check (sqrt 0.0001) => 0.01) +(check (new-if (= 1 1) 0 5) => 0) -(check (sqrt 10000000000000.0001) => 3162277.6601683795) +(define (sqrt-iter guess x) + (new-if (good-enough? guess x) + guess + (sqrt-iter (improve guess x) + x))) + +; ---- Exercise 1.7 ------------------------------------------------------------ + +; (check (sqrt 9) => 3.0) -; (check (sqrt 100000000000000000000) => 10000000000.0) ; BUG: MEMORY-LEAK +; (check (sqrt 0.0000000000001) => 3.162277660168379e-007) ; SEGV -; (check (sqrt 100000000000000000000000000) => 10000000000000.0) ; BUG: MEMORY-LEAK +; (check (sqrt 0.0001) => 0.01) -; TODO -; (check (sqrt 0.0000000000001) => 3.162277660168379e-007) +; (check (sqrt 0) => 0.0) ; SEGV -; TODO -; (check (sqrt 0) => 0.0) +; (check (sqrt 10000000000000.0001) => 3162277.6601683795) + +; (check (sqrt 100000000000000000000) => 10000000000.0) ; SEGV + +; (check (sqrt 100000000000000000000000000) => 10000000000000.0) ; SEGV ; ---- Exercise 1.8 ------------------------------------------------------------ @@ -245,9 +262,14 @@ ; ---- Section 1.1.8 ----------------------------------------------------------- -(define (square x) (* x x)) -(define (square x) (exp (double (log x)))) -(define (double x) (+ x x)) +(define (square x) + (* x x)) + +(define (square x) + (exp (double (log x)))) + +(define (double x) + (+ x x)) (define (square x) (* x x)) (define (square y) (* y y)) @@ -255,64 +277,55 @@ (define (sqrt x) (define (good-enough? guess x) (< (abs (- (square guess) x)) 0.001)) - (define (improve guess x) (average guess (/ x guess))) - (define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x))) - (sqrt-iter 1.0 x)) (define (sqrt x) (define (good-enough? guess) (< (abs (- (square guess) x)) 0.001)) - (define (improve guess) (average guess (/ x guess))) - (define (sqrt-iter guess) (if (good-enough? guess) guess (sqrt-iter (improve guess)))) - (sqrt-iter 1.0)) ; ---- Section 1.2.1 ----------------------------------------------------------- -(let () - (define (factorial n) - (if (= n 1) 1 - (* n (factorial (- n 1))))) - - (check (factorial 6) => 720)) +(define (factorial n) + (if (= n 1) + 1 + (* n (factorial (- n 1))))) -(let () - (define (factorial n) - (fact-iter 1 1 n)) +(check (factorial 6) => 720) - (define (fact-iter product counter max-count) - (if (> counter max-count) product - (fact-iter (* counter product) - (+ counter 1) - max-count))) +(define (factorial n) + (fact-iter 1 1 n)) - (check (factorial 6) => 720)) +(define (fact-iter product counter max-count) + (if (> counter max-count) + product + (fact-iter (* counter product) + (+ counter 1) + max-count))) -; ---- Exercise 1.9 ------------------------------------------------------------ +(check (factorial 6) => 720) -(define (inc n) (+ n 1)) -(define (dec n) (- n 1)) +(define (factorial n) + (define (iter product counter) + (if (> counter n) + product + (iter (* counter product) + (+ counter 1)))) + (iter 1 1)) -(let () - (define (+ a b) - (if (= a 0) b (inc (+ (dec a) b)))) - (check (+ 4 5) => 9)) +(check (factorial 6) => 720) -(let () - (define (+ a b) - (if (= a 0) b (+ (dec a) (inc b)))) - (check (+ 4 5) => 9)) +; ---- Exercise 1.9 ------------------------------------------------------------ ; ---- Exercise 1.10 ----------------------------------------------------------- @@ -335,153 +348,89 @@ ; ---- Section 1.2.2 ----------------------------------------------------------- -(let () - (define (fib n) - (cond ((= n 0) 0) - ((= n 1) 1) - (else (+ (fib (- n 1)) - (fib (- n 2)))))) - (check (fib 5) => 5)) +(define (fib n) + (cond ((= n 0) 0) + ((= n 1) 1) + (else (+ (fib (- n 1)) + (fib (- n 2)))))) +(check (fib 5) => 5) -(let () - (define (fib n) - (fib-iter 1 0 n)) - (define (fib-iter a b count) - (if (= count 0) b - (fib-iter (+ a b) a (- count 1)))) - (check (fib 5) => 5)) +(define (fib n) + (fib-iter 1 0 n)) -(let () - (define (count-change amount) - (cc amount 5)) - - (define (cc amount kinds-of-coins) - (cond ((= amount 0) 1) - ((or (< amount 0) (= kinds-of-coins 0)) 0) - (else (+ (cc amount - (- kinds-of-coins 1)) - (cc (- amount - (first-denomination kinds-of-coins)) - kinds-of-coins))))) - - (define (first-denomination kinds-of-coins) - (cond ((= kinds-of-coins 1) 1) - ((= kinds-of-coins 2) 5) - ((= kinds-of-coins 3) 10) - ((= kinds-of-coins 4) 25) - ((= kinds-of-coins 5) 50))) - - (check (count-change 100) => 292)) +(define (fib-iter a b count) + (if (= count 0) b + (fib-iter (+ a b) a (- count 1)))) -; ---- Exercise 1.11 ----------------------------------------------------------- +(check (fib 5) => 5) -(let () - (define (f n) - (cond ((< n 3) n) - (else (+ (f (- n 1)) - (* 2 (f (- n 2))) - (* 3 (f (- n 3))))))) - - (check (f -1) => -1) - (check (f 0) => 0) - (check (f 5) => 25) - ; (check (f 1000) => 1200411335581569104197621183222182410228690281055710781687044573790661709343985308756380381850406620666042607564631605876156610535933789714780132607755663854744223225249491730428647795602251203632973677695221003056803565827035107926395650932180708300409716979009255557336360673626403040863408122386349183735643342985009827495351241264386090544972951146415009560371824341466875) - ) - -; (let () ; BUG: MEMORY-LEAK -; (define (f n) -; (define (f-i a b c count) -; (cond ((< n 3) n) -; ((<= count 0) a) -; (else (f-i (+ a (* 2 b) (* 3 c)) a b (- count 1))))) -; (f-i 2 1 0 (- n 2))) -; -; (check (f -1) => -1) -; (check (f 0) => 0) -; (check (f 5) => 25) -; (check (f 1000) => 1200411335581569104197621183222182410228690281055710781687044573790661709343985308756380381850406620666042607564631605876156610535933789714780132607755663854744223225249491730428647795602251203632973677695221003056803565827035107926395650932180708300409716979009255557336360673626403040863408122386349183735643342985009827495351241264386090544972951146415009560371824341466875) -; ) +(define (count-change amount) + (cc amount 5)) -; ---- Exercise 1.12 ----------------------------------------------------------- +(define (cc amount kinds-of-coins) + (cond ((= amount 0) 1) + ((or (< amount 0) (= kinds-of-coins 0)) 0) + (else (+ (cc amount + (- kinds-of-coins 1)) + (cc (- amount + (first-denomination kinds-of-coins)) + kinds-of-coins))))) -(let () - (define (pascal r c) - (if (or (= c 1) - (= c r)) - 1 - (+ (pascal (- r 1) (- c 1)) - (pascal (- r 1) c)))) - - (check (pascal 1 1) => 1) - (check (pascal 2 2) => 1) - (check (pascal 3 2) => 2) - (check (pascal 4 2) => 3) - (check (pascal 5 2) => 4) - (check (pascal 5 3) => 6)) +(define (first-denomination kinds-of-coins) + (cond ((= kinds-of-coins 1) 1) + ((= kinds-of-coins 2) 5) + ((= kinds-of-coins 3) 10) + ((= kinds-of-coins 4) 25) + ((= kinds-of-coins 5) 50))) -; ---- Exercise 1.13 ----------------------------------------------------------- +(check (count-change 100) => 292) -; ---- Section 1.2.3 ----------------------------------------------------------- +; ---- Exercise 1.11 ----------------------------------------------------------- -; ---- Exercise 1.14 ----------------------------------------------------------- +; ---- Exercise 1.12 ----------------------------------------------------------- -(let () - (define (cube x) - (* x x x)) +; ---- Exercise 1.13 ----------------------------------------------------------- - (define (p x) - (- (* 3 x) - (* 4 (cube x)))) +; ---- Section 1.2.3 ----------------------------------------------------------- - (define (sine angle) - (if (not (> (abs angle) 0.1)) angle - (p (sine (/ angle 3.0))))) +; ---- Exercise 1.14 ----------------------------------------------------------- - ; (check (sine 12.15) => 0) - ) +; ---- Exercise 1.15 ----------------------------------------------------------- ; ---- Section 1.2.4 ----------------------------------------------------------- -(let () - (define (expt b n) - (if (= n 0) - 1 - (* b (expt b (- n 1))))) +(define (%expt b n) + (if (= n 0) + 1 + (* b (%expt b (- n 1))))) - (check (expt 1 1) => 1) - (check (expt 2 2) => 4) - (check (expt 2 8) => 256) - (check (expt 2 16) => 65536)) +(define (%expt b n) + (expt-iter b n 1)) -(let () - (define (expt b n) - (expt-iter b n 1)) - - (define (expt-iter b counter product) - (if (= counter 0) product - (expt-iter b - (- counter 1) - (* b product)))) - - (check (expt 1 1) => 1) - (check (expt 2 2) => 4) - (check (expt 2 8) => 256) - (check (expt 2 16) => 65536)) +(define (expt-iter b counter product) + (if (= counter 0) product + (expt-iter b + (- counter 1) + (* b product)))) (define (fast-expt b n) (cond ((= n 0) 1) ((even? n) (square (fast-expt b (/ n 2)))) (else (* b (fast-expt b (- n 1)))))) -(let () - (define (even? n) - (= (remainder n 2) 0)) +(define (%even? n) + (= (remainder n 2) 0)) + +; ---- Exercise 1.16 ----------------------------------------------------------- + +; ---- Exercise 1.17 ----------------------------------------------------------- + +; ---- Exercise 1.18 ----------------------------------------------------------- - (check (even? 1) => #f) - (check (even? 2) => #t) - ) +; ---- Exercise 1.19 ----------------------------------------------------------- +; ---- Section 1.2.5 ----------------------------------------------------------- (check-report) -(exit (check-passed? 78)) +(exit (check-passed? 62)) From 9603487c9caafacc58aabeaa600a3d882b2df1b8 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Wed, 25 May 2022 22:26:58 +0900 Subject: [PATCH 12/40] Update `collector` member functions to be static Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/memory/collector.hpp | 18 +++++++++--------- src/memory/collector.cpp | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3a4489840..397234bcc 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.11.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.12.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.11_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.12_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.11 +Meevax Lisp System, version 0.4.12 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 5f749c136..75274d832 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.11 +0.4.12 diff --git a/include/meevax/memory/collector.hpp b/include/meevax/memory/collector.hpp index 67b354ce9..94a1e1225 100644 --- a/include/meevax/memory/collector.hpp +++ b/include/meevax/memory/collector.hpp @@ -109,27 +109,27 @@ inline namespace memory auto operator =(collector const&) -> collector & = delete; - auto allocate(std::size_t const) -> void *; + static auto allocate(std::size_t const) -> void *; - auto clear() -> void; + static auto clear() -> void; - auto collect() -> std::size_t; + static auto collect() -> std::size_t; - auto count() const noexcept -> std::size_t; + static auto count() noexcept -> std::size_t; - auto deallocate(void * const, std::size_t const = 0) -> void; + static auto deallocate(void * const, std::size_t const = 0) -> void; - auto mark() -> void; + static auto mark() -> void; static auto region_of(void const* const) -> decltype(regions)::iterator; static auto reset(void * const, deallocator::signature const) -> region *; - auto reset_threshold(std::size_t const = std::numeric_limits::max()) -> void; + static auto reset_threshold(std::size_t const = std::numeric_limits::max()) -> void; - auto sweep() -> void; + static auto sweep() -> void; - auto traverse(region * const) -> void; + static auto traverse(region * const) -> void; } static gc; } // namespace memory } // namespace meevax diff --git a/src/memory/collector.cpp b/src/memory/collector.cpp index c6c543bed..c3f40e2c1 100644 --- a/src/memory/collector.cpp +++ b/src/memory/collector.cpp @@ -109,7 +109,7 @@ inline namespace memory return before - count(); } - auto collector::count() const noexcept -> std::size_t + auto collector::count() noexcept -> std::size_t { return std::size(regions); } From 467cb01f4279362ed5f1461f03eb616e09394b5a Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Thu, 26 May 2022 00:09:34 +0900 Subject: [PATCH 13/40] Update `make(...)` to return new type `xvalue` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/heterogeneous.hpp | 13 +++++++++---- include/meevax/kernel/machine.hpp | 19 ++++++++++++------- include/meevax/kernel/object.hpp | 8 ++++---- include/meevax/kernel/overview.hpp | 2 ++ src/kernel/library.cpp | 4 ++-- 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 397234bcc..d68eeee45 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.12.so` and executable `meevax`. +| `all` (default) | Build shared-library `libmeevax.0.4.13.so` and executable `meevax`. | `test` | Test executable `meevax`. -| `package` | Generate debian package `meevax_0.4.12_amd64.deb`. +| `package` | Generate debian package `meevax_0.4.13_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.12 +Meevax Lisp System, version 0.4.13 Usage: meevax [OPTION...] [FILE...] diff --git a/VERSION b/VERSION index 75274d832..1f7716999 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.12 +0.4.13 diff --git a/include/meevax/kernel/heterogeneous.hpp b/include/meevax/kernel/heterogeneous.hpp index 442e90ffb..3c61c4091 100644 --- a/include/meevax/kernel/heterogeneous.hpp +++ b/include/meevax/kernel/heterogeneous.hpp @@ -43,13 +43,13 @@ inline namespace kernel ~binder() override = default; - auto compare(heterogeneous const& x) const -> bool override + auto compare([[maybe_unused]] Top const* top) const -> bool override { if constexpr (is_equality_comparable::value) { - if (auto const* address = dynamic_cast(x.get()); address) + if (auto const* bound = dynamic_cast(top); bound) { - return *address == static_cast(*this); + return *bound == static_cast(*this); } else { @@ -77,6 +77,11 @@ inline namespace kernel using Pointer::Pointer; using Pointer::get; + template