From c06444f90c22d5464f40872e3f9081ad3e4cc600 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 00:38:07 +0200 Subject: [PATCH 01/35] project: add LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 7f81f5fa7c818385cd3f13dab41e2c90143d733a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 00:51:07 +0200 Subject: [PATCH 02/35] nix: use checkInputs for GTest --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index f5b2bcf..56d4ecf 100644 --- a/flake.nix +++ b/flake.nix @@ -60,7 +60,7 @@ devShell = pkgs.mkShell { inherit (self.defaultPackage.${system}) - buildInputs + checkInputs nativeBuildInputs ; @@ -82,7 +82,7 @@ pkg-config ]; - buildInputs = with pkgs; [ + checkInputs = with pkgs; [ gtest ]; From f64c8775f3e0ae117594da93d46063dfad47afef Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 01:04:13 +0200 Subject: [PATCH 03/35] nix: mark package as broken For some reason I get an error when building under nix... --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 56d4ecf..b2d50ed 100644 --- a/flake.nix +++ b/flake.nix @@ -87,6 +87,7 @@ ]; meta = with pkgs.lib; { + broken = true; # Only breaks under nix description = "A simple calculator using big numbers"; homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; license = licenses.mit; From 2046d1ec4b6caa02a4eb4d571c5ca254b671d9be Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 16:12:53 +0200 Subject: [PATCH 04/35] abacus: bignum: fix style of assignment Using `auto = ` is more consistent with the rest. --- src/bignum/bignum.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index c3588a9..6b739e0 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -413,8 +413,8 @@ std::pair div_mod(BigNum const& lhs, BigNum const& rhs) { return std::make_pair(BigNum(), BigNum()); } - BigNum quotient; - BigNum remainder; + auto quotient = BigNum(0); + auto remainder = BigNum(0); std::tie(quotient.digits_, remainder.digits_) = do_div_mod(lhs.digits_, rhs.digits_); @@ -439,7 +439,7 @@ BigNum pow(BigNum const& lhs, BigNum const& rhs) { return BigNum(); } - BigNum res; + auto res = BigNum(0); res.digits_ = do_pow(lhs.digits_, rhs.digits_); res.sign_ = is_odd(rhs.digits_) ? lhs.sign_ : 1; @@ -458,7 +458,7 @@ BigNum sqrt(BigNum const& num) { "attempt to take the square root of a negative number"); } - BigNum res; + auto res = BigNum(0); res.digits_ = do_sqrt(num.digits_); res.sign_ = 1; From c9811fce441050b6cf04d56ae05c5aa08c0ab579 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 16:14:22 +0200 Subject: [PATCH 05/35] abacus: bignum: rename do_trim_leading_zeros It works in-place, unlike the rest of the `do_*` functions. --- src/bignum/bignum.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 6b739e0..0f78275 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -24,7 +24,7 @@ bool do_less_than(digits_type const& lhs, digits_type const& rhs) { rhs.rend()); } -void do_trim_leading_zeros(digits_type& num) { +void trim_leading_zeros(digits_type& num) { auto const it = std::find_if(num.rbegin(), num.rend(), [](auto v) { return v != 0; }); num.erase(it.base(), num.end()); @@ -82,7 +82,7 @@ digits_type do_substraction(digits_type const& lhs, digits_type const& rhs) { std::transform(complement.begin(), complement.end(), complement.begin(), take_complement); - do_trim_leading_zeros(complement); + trim_leading_zeros(complement); return complement; } @@ -150,7 +150,7 @@ digits_type do_halve(digits_type num) { } } - do_trim_leading_zeros(num); + trim_leading_zeros(num); return num; } @@ -361,7 +361,7 @@ bool BigNum::less_than(BigNum const& rhs) const { } void BigNum::canonicalize() { - do_trim_leading_zeros(digits_); + trim_leading_zeros(digits_); if (digits_.size() == 0) { sign_ = 0; From 4b85d229236b82f1a5cfdc5a8681a0b0831b541c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 16:30:10 +0200 Subject: [PATCH 06/35] abacus: bignum: add operator bool --- src/bignum/bignum.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bignum/bignum.hh b/src/bignum/bignum.hh index 1880af0..c75e042 100644 --- a/src/bignum/bignum.hh +++ b/src/bignum/bignum.hh @@ -115,6 +115,10 @@ public: return !(lhs < rhs); } + explicit operator bool() { + return !is_zero(); + } + bool is_zero() const; bool is_positive() const; bool is_negative() const; From c730705a13e27d02a5b3173c9348ea178a6bc8e7 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 16:33:05 +0200 Subject: [PATCH 07/35] abacus: bignum: add log2 --- src/bignum/bignum.cc | 24 ++++++++++++++++++++++++ src/bignum/bignum.hh | 2 ++ tests/unit/bignum.cc | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 0f78275..677191b 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -468,4 +468,28 @@ BigNum sqrt(BigNum const& num) { return res; } +BigNum log2(BigNum const& num) { + assert(num.is_canonicalized()); + + if (num.is_zero()) { + throw std::invalid_argument("attempt to take the log2 of zero"); + } else if (num.is_negative()) { + throw std::invalid_argument( + "attempt to take the log2 of a negative number"); + } + + auto tmp = num; + auto res = BigNum(0); + auto one = BigNum(1); + + while (tmp > one) { + tmp.digits_ = do_halve(tmp.digits_); + res += one; + } + + assert(res.is_canonicalized()); + + return res; +} + } // namespace abacus::bignum diff --git a/src/bignum/bignum.hh b/src/bignum/bignum.hh index c75e042..1c5529e 100644 --- a/src/bignum/bignum.hh +++ b/src/bignum/bignum.hh @@ -91,6 +91,8 @@ public: friend BigNum sqrt(BigNum const& num); + friend BigNum log2(BigNum const& num); + friend bool operator==(BigNum const& lhs, BigNum const& rhs) { return lhs.equal(rhs); } diff --git a/tests/unit/bignum.cc b/tests/unit/bignum.cc index 8040ed0..61ae839 100644 --- a/tests/unit/bignum.cc +++ b/tests/unit/bignum.cc @@ -376,3 +376,24 @@ TEST(BigNum, sqrt) { EXPECT_EQ(sqrt(ninety_nine), nine); EXPECT_EQ(sqrt(hundred), ten); } + +TEST(BigNum, log2) { + auto const zero = BigNum(0); + auto const one = BigNum(1); + auto const two = BigNum(2); + auto const three = BigNum(3); + auto const four = BigNum(4); + auto const five = BigNum(5); + auto const seven = BigNum(7); + auto const eight = BigNum(8); + auto const nine = BigNum(9); + + EXPECT_EQ(log2(one), zero); + EXPECT_EQ(log2(two), one); + EXPECT_EQ(log2(three), one); + EXPECT_EQ(log2(four), two); + EXPECT_EQ(log2(five), two); + EXPECT_EQ(log2(seven), two); + EXPECT_EQ(log2(eight), three); + EXPECT_EQ(log2(nine), three); +} From 31dcb91a2666158414c28c724029543aa9069a36 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 16:38:25 +0200 Subject: [PATCH 08/35] abacus: bignum: add log10 --- src/bignum/bignum.cc | 18 ++++++++++++++++++ src/bignum/bignum.hh | 2 ++ tests/unit/bignum.cc | 20 ++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 677191b..db9c922 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -492,4 +492,22 @@ BigNum log2(BigNum const& num) { return res; } +BigNum log10(BigNum const& num) { + assert(num.is_canonicalized()); + assert(BASE == 10); + + if (num.is_zero()) { + throw std::invalid_argument("attempt to take the log10 of zero"); + } else if (num.is_negative()) { + throw std::invalid_argument( + "attempt to take the log10 of a negative number"); + } + + auto res = BigNum(num.digits_.size() - 1); + + assert(res.is_canonicalized()); + + return res; +} + } // namespace abacus::bignum diff --git a/src/bignum/bignum.hh b/src/bignum/bignum.hh index 1c5529e..6a7a009 100644 --- a/src/bignum/bignum.hh +++ b/src/bignum/bignum.hh @@ -93,6 +93,8 @@ public: friend BigNum log2(BigNum const& num); + friend BigNum log10(BigNum const& num); + friend bool operator==(BigNum const& lhs, BigNum const& rhs) { return lhs.equal(rhs); } diff --git a/tests/unit/bignum.cc b/tests/unit/bignum.cc index 61ae839..f584778 100644 --- a/tests/unit/bignum.cc +++ b/tests/unit/bignum.cc @@ -397,3 +397,23 @@ TEST(BigNum, log2) { EXPECT_EQ(log2(eight), three); EXPECT_EQ(log2(nine), three); } + +TEST(BigNum, log10) { + auto const zero = BigNum(0); + auto const one = BigNum(1); + auto const two = BigNum(2); + auto const nine = BigNum(9); + auto const ten = BigNum(10); + auto const eleven = BigNum(11); + auto const ninety_nine = BigNum(99); + auto const hundred = BigNum(100); + auto const hundred_one = BigNum(101); + + EXPECT_EQ(log10(one), zero); + EXPECT_EQ(log10(nine), zero); + EXPECT_EQ(log10(ten), one); + EXPECT_EQ(log10(eleven), one); + EXPECT_EQ(log10(ninety_nine), one); + EXPECT_EQ(log10(hundred), two); + EXPECT_EQ(log10(hundred_one), two); +} From a99f60dcd4c1f6ae03a7e764edffe7dadd6c0db6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 18:59:43 +0200 Subject: [PATCH 09/35] abacus: bignum: move do_halve & is_odd up --- src/bignum/bignum.cc | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index db9c922..c567b09 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -30,6 +30,33 @@ void trim_leading_zeros(digits_type& num) { num.erase(it.base(), num.end()); } +// More optimised than full-on div_mod +digits_type do_halve(digits_type num) { + assert(num.size() != 0); + + int carry = 0; + for (auto i = num.rbegin(); i != num.rend(); ++i) { + auto const was_odd = (*i % 2) == 1; + *i /= 2; + *i += carry; + if (was_odd) { + carry = BASE / 2; + } + } + + trim_leading_zeros(num); + + return num; +} + +bool is_odd(digits_type const& num) { + if (num.size() == 0) { + return false; + } + + return (num.front() % 2) == 1; +} + digits_type do_addition(digits_type const& lhs, digits_type const& rhs) { int carry = 0; digits_type res; @@ -136,33 +163,6 @@ std::pair do_div_mod(digits_type const& lhs, return std::make_pair(quotient, remainder); } -// More optimised than full-on div_mod -digits_type do_halve(digits_type num) { - assert(num.size() != 0); - - int carry = 0; - for (auto i = num.rbegin(); i != num.rend(); ++i) { - auto const was_odd = (*i % 2) == 1; - *i /= 2; - *i += carry; - if (was_odd) { - carry = BASE / 2; - } - } - - trim_leading_zeros(num); - - return num; -} - -bool is_odd(digits_type const& num) { - if (num.size() == 0) { - return false; - } - - return (num.front() % 2) == 1; -} - digits_type do_pow(digits_type lhs, digits_type rhs) { assert(rhs.size() != 0); From 1521d2b232a28fccf629e1716880b284c5337ced Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 19:10:48 +0200 Subject: [PATCH 10/35] abacus: bignum: fix do_halve --- src/bignum/bignum.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index c567b09..b311545 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -41,6 +41,8 @@ digits_type do_halve(digits_type num) { *i += carry; if (was_odd) { carry = BASE / 2; + } else { + carry = 0; } } From c675b15248e9f7d04e0b6ff50ffd39f9345ec797 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 19:12:35 +0200 Subject: [PATCH 11/35] abacus: bignum: optimize div_mod --- src/bignum/bignum.cc | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index b311545..0aa102f 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -139,27 +139,28 @@ std::pair do_div_mod(digits_type const& lhs, throw std::invalid_argument("attempt to divide by zero"); } + digits_type multiple = rhs; + digits_type rank; + rank.push_back(1); + + while (!do_less_than(lhs, multiple)) { + multiple = do_addition(multiple, multiple); + rank = do_addition(rank, rank); + } + digits_type quotient; digits_type remainder = lhs; while (!do_less_than(remainder, rhs)) { - // TODO: use `do_halve` to back down after calculate highest multiple - digits_type multiple = rhs; - digits_type rank; - rank.push_back(1); - - digits_type prev_multiple = multiple; - digits_type prev_rank = rank; - - while (!do_less_than(remainder, multiple)) { - prev_multiple = multiple; - prev_rank = rank; - multiple = do_addition(multiple, multiple); - rank = do_addition(rank, rank); + while (do_less_than(remainder, multiple)) { + multiple = do_halve(multiple); + rank = do_halve(rank); } - quotient = do_addition(quotient, prev_rank); - remainder = do_substraction(remainder, prev_multiple); + assert(!do_less_than(multiple, rhs)); + + quotient = do_addition(quotient, rank); + remainder = do_substraction(remainder, multiple); } return std::make_pair(quotient, remainder); From 9d8d3fa864edb5b7edb3946fc26c4ec1c7210cec Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 23 Aug 2021 19:24:53 +0200 Subject: [PATCH 12/35] abacus: bignum: extract do_dump Useful when debugging. --- src/bignum/bignum.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 0aa102f..2121cdc 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -30,6 +30,11 @@ void trim_leading_zeros(digits_type& num) { num.erase(it.base(), num.end()); } +std::ostream& do_dump(digits_type const& num, std::ostream& out) { + std::copy(num.rbegin(), num.rend(), std::ostream_iterator(out)); + return out; +} + // More optimised than full-on div_mod digits_type do_halve(digits_type num) { assert(num.size() != 0); @@ -229,10 +234,8 @@ std::ostream& BigNum::dump(std::ostream& out) const { if (is_negative()) { out << '-'; } - std::copy(digits_.rbegin(), digits_.rend(), - std::ostream_iterator(out)); - return out; + return do_dump(digits_, out); } std::istream& BigNum::read(std::istream& in) { From be781b0d2f78b4fcbcc7e10d23de829452ad32ec Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 31 Aug 2021 20:20:09 +0200 Subject: [PATCH 13/35] abacus: use static libraries We do not want to install those libraries in any way. --- src/bignum/meson.build | 2 +- src/parse/meson.build | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bignum/meson.build b/src/bignum/meson.build index 7346d21..af1e4e5 100644 --- a/src/bignum/meson.build +++ b/src/bignum/meson.build @@ -5,7 +5,7 @@ bignum_sources = files( bignum_inc = include_directories('.') -bignum_lib = library( +bignum_lib = static_library( 'bignum', sources: bignum_sources, ) diff --git a/src/parse/meson.build b/src/parse/meson.build index 254d868..1a3bdcb 100644 --- a/src/parse/meson.build +++ b/src/parse/meson.build @@ -31,7 +31,7 @@ parser_sources = custom_target( parse_inc = include_directories('.') -parse_lib = library( +parse_lib = static_library( 'parser', 'parser-driver.cc', 'parser-driver.hh', From edd8d1f329570bc01842d48052bf7548b1d6c463 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 31 Aug 2021 20:20:22 +0200 Subject: [PATCH 14/35] abacus: fix install --- src/meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/src/meson.build b/src/meson.build index 182500e..a6c5cb2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -12,4 +12,5 @@ abacus = executable( bignum, parse, ], + install: true, ) From ac6b633c893d150f838170857eaa564497d62c1d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 31 Aug 2021 20:20:30 +0200 Subject: [PATCH 15/35] nix: remove 'meta.broken' Now that we actually install the program... --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index b2d50ed..56d4ecf 100644 --- a/flake.nix +++ b/flake.nix @@ -87,7 +87,6 @@ ]; meta = with pkgs.lib; { - broken = true; # Only breaks under nix description = "A simple calculator using big numbers"; homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; license = licenses.mit; From fa092f8876527f9b0d9c0f48105d2a38d331e4c0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 31 Aug 2021 20:21:12 +0200 Subject: [PATCH 16/35] ci: add Drone CI --- .drone.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..e52d282 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,27 @@ +--- +kind: pipeline +type: exec +name: abacus checks + +steps: +- name: flake check + commands: + - nix flake check + +- name: notifiy + commands: + - nix run github:ambroisie/matrix-notifier + environment: + ADDRESS: + from_secret: matrix_homeserver + ROOM: + from_secret: matrix_roomid + USER: + from_secret: matrix_username + PASS: + from_secret: matrix_password + when: + status: + - failure + - success +... From 549c1f057451911e0758bbb4319ec8a46da794bf Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 31 Aug 2021 20:40:34 +0200 Subject: [PATCH 17/35] git: ignore 'result' --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 8a15123..9a65324 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Generated by Nix /.pre-commit-config.yaml +/result # Meson /build From 331089d10158553e4d056624d311e4fc9914f86e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:00:51 +0200 Subject: [PATCH 18/35] abacus: add cmake-based build system --- CMakeLists.txt | 15 +++++++++++++++ src/CMakeLists.txt | 12 ++++++++++++ src/bignum/CMakeLists.txt | 9 +++++++++ src/parse/CMakeLists.txt | 23 +++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/unit/CMakeLists.txt | 16 ++++++++++++++++ 6 files changed, 76 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 src/bignum/CMakeLists.txt create mode 100644 src/parse/CMakeLists.txt create mode 100644 tests/CMakeLists.txt create mode 100644 tests/unit/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4ef9a7b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.10) +project(abacus VERSION 0.0.0 LANGUAGES CXX) +enable_testing() + +add_library(common_options INTERFACE) +target_compile_features(common_options INTERFACE + cxx_std_17 +) +target_compile_options(common_options INTERFACE + -Wall + -Wextra +) + +add_subdirectory(src) +add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..531ca47 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(abacus abacus.cc) +target_link_libraries(abacus PRIVATE common_options) + +add_subdirectory(bignum) +add_subdirectory(parse) + +target_link_libraries(abacus PRIVATE + bignum + parse +) + +install(TARGETS abacus) diff --git a/src/bignum/CMakeLists.txt b/src/bignum/CMakeLists.txt new file mode 100644 index 0000000..b2434b7 --- /dev/null +++ b/src/bignum/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library(bignum STATIC + bignum.cc + bignum.hh +) +target_link_libraries(bignum PRIVATE common_options) + +target_include_directories(bignum PUBLIC + $ +) diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt new file mode 100644 index 0000000..3c87a92 --- /dev/null +++ b/src/parse/CMakeLists.txt @@ -0,0 +1,23 @@ +find_package(BISON REQUIRED) +find_package(FLEX REQUIRED) + +bison_target(parser_sources parser.yy ${CMAKE_CURRENT_BINARY_DIR}/parser.cc DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.hh) +flex_target(scanner_sources scanner.ll ${CMAKE_CURRENT_BINARY_DIR}/scanner.cc) +add_flex_bison_dependency(scanner_sources parser_sources) + +add_library(parse STATIC + parser-driver.cc + parser-driver.hh + ${BISON_parser_sources_OUTPUTS} + ${FLEX_scanner_sources_OUTPUTS} +) +target_link_libraries(parse PRIVATE common_options) + +target_link_libraries(parse PRIVATE + bignum +) + +target_include_directories(parse PUBLIC + $ + $ +) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..269aea0 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(unit) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt new file mode 100644 index 0000000..bdf51ae --- /dev/null +++ b/tests/unit/CMakeLists.txt @@ -0,0 +1,16 @@ +find_package(GTest) + +if (${GTest_FOUND}) +include(GoogleTest) + +add_executable(bignum_test bignum.cc) +target_link_libraries(bignum_test PRIVATE common_options) + +target_link_libraries(bignum_test PRIVATE + bignum + GTest::gtest + GTest::gtest_main +) + +gtest_discover_tests(bignum_test) +endif (${GTest_FOUND}) From 09c628be6055a97edee8dd94458e712170828151 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:34:33 +0200 Subject: [PATCH 19/35] nix: set 'doCheck' It ensures that the `checkInputs` are being made part of `nativeBuildInputs`. --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 56d4ecf..5173318 100644 --- a/flake.nix +++ b/flake.nix @@ -86,6 +86,8 @@ gtest ]; + doCheck = true; + meta = with pkgs.lib; { description = "A simple calculator using big numbers"; homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; From 6c0950dbe15af558c2ba6fe2ad47f26d5dd44847 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:35:54 +0200 Subject: [PATCH 20/35] nix: use cmake instead of meson --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5173318..cdf39b2 100644 --- a/flake.nix +++ b/flake.nix @@ -76,8 +76,8 @@ nativeBuildInputs = with pkgs; [ bison + cmake flex - meson ninja pkg-config ]; From eb9295cfcdf89ade8b65f5fc9afc695ce30b7f68 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:37:00 +0200 Subject: [PATCH 21/35] abacus: remove meson build system --- meson.build | 13 ------------ src/bignum/meson.build | 16 -------------- src/meson.build | 16 -------------- src/parse/meson.build | 48 ------------------------------------------ tests/meson.build | 1 - tests/unit/meson.build | 26 ----------------------- 6 files changed, 120 deletions(-) delete mode 100644 meson.build delete mode 100644 src/bignum/meson.build delete mode 100644 src/meson.build delete mode 100644 src/parse/meson.build delete mode 100644 tests/meson.build delete mode 100644 tests/unit/meson.build diff --git a/meson.build b/meson.build deleted file mode 100644 index 4910f6a..0000000 --- a/meson.build +++ /dev/null @@ -1,13 +0,0 @@ -project( - 'abacus', - 'cpp', - version: '0.0.0', - license: 'MIT', - default_options: [ - 'warning_level=3', - 'cpp_std=c++17', - ], -) - -subdir('src') -subdir('tests') diff --git a/src/bignum/meson.build b/src/bignum/meson.build deleted file mode 100644 index af1e4e5..0000000 --- a/src/bignum/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -bignum_sources = files( - 'bignum.cc', - 'bignum.hh', -) - -bignum_inc = include_directories('.') - -bignum_lib = static_library( - 'bignum', - sources: bignum_sources, -) - -bignum = declare_dependency( - link_with: bignum_lib, - include_directories: bignum_inc, -) diff --git a/src/meson.build b/src/meson.build deleted file mode 100644 index a6c5cb2..0000000 --- a/src/meson.build +++ /dev/null @@ -1,16 +0,0 @@ -abacus_sources = files( - 'abacus.cc', -) - -subdir('bignum') -subdir('parse') - -abacus = executable( - 'abacus', - sources: abacus_sources, - dependencies: [ - bignum, - parse, - ], - install: true, -) diff --git a/src/parse/meson.build b/src/parse/meson.build deleted file mode 100644 index 1a3bdcb..0000000 --- a/src/parse/meson.build +++ /dev/null @@ -1,48 +0,0 @@ -flex_binary = find_program('flex', required: true) -lexer_sources = custom_target( - 'lexer_sources', - input: 'scanner.ll', - output: 'scanner.cc', - command: [ - flex_binary, - '-o', - '@OUTPUT@', - '@INPUT@', - ], -) - -bison_binary = find_program('bison', required: true) -parser_sources = custom_target( - 'parser_sources', - input: 'parser.yy', - output: [ - 'parser.cc', - 'parser.hh', - ], - command: [ - bison_binary, - '@INPUT@', - '--output=@OUTPUT0@', - '--defines=@OUTPUT1@', - '--graph', - # FIXME: html output in bison 3.7.90 - ], -) - -parse_inc = include_directories('.') - -parse_lib = static_library( - 'parser', - 'parser-driver.cc', - 'parser-driver.hh', - lexer_sources, - parser_sources, - dependencies: [ - bignum, - ], -) - -parse = declare_dependency( - link_with: parse_lib, - include_directories: parse_inc, -) diff --git a/tests/meson.build b/tests/meson.build deleted file mode 100644 index 082b746..0000000 --- a/tests/meson.build +++ /dev/null @@ -1 +0,0 @@ -subdir('unit') diff --git a/tests/unit/meson.build b/tests/unit/meson.build deleted file mode 100644 index db8eddd..0000000 --- a/tests/unit/meson.build +++ /dev/null @@ -1,26 +0,0 @@ -gtest = dependency( - 'gtest', - main: true, - required: false, -) - -if gtest.found() - unit_test_sources = files( - 'bignum.cc', - ) - - unit_tests = executable( - 'unit_tests', - sources: unit_test_sources, - dependencies: [ - bignum, - gtest, - ], - ) - - test( - 'unit tests', - unit_tests, - protocol: 'gtest', - ) -endif From 171ef10a6d8f0626e1e3e289b868f2a1dfd23c9b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 1 Sep 2021 19:42:58 +0200 Subject: [PATCH 22/35] abacus: fix include directories This cleans up one of my major pain points with the Meson way of doing things. The Meson solution to have nice includes would have been to create an `include/` directory per library I create... --- CMakeLists.txt | 3 +++ src/abacus.cc | 2 +- src/bignum/CMakeLists.txt | 4 ---- src/parse/CMakeLists.txt | 2 +- src/parse/parser-driver.hh | 2 +- src/parse/parser.yy | 2 +- tests/unit/bignum.cc | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef9a7b..d343e5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ target_compile_options(common_options INTERFACE -Wall -Wextra ) +target_include_directories(common_options INTERFACE + src +) add_subdirectory(src) add_subdirectory(tests) diff --git a/src/abacus.cc b/src/abacus.cc index 3e735a0..45d2394 100644 --- a/src/abacus.cc +++ b/src/abacus.cc @@ -1,4 +1,4 @@ -#include "parser-driver.hh" // FIXME: I would like `parse/parser-driver.hh` path instead... +#include "parse/parser-driver.hh" int main() { abacus::parse::ParserDriver driver{}; diff --git a/src/bignum/CMakeLists.txt b/src/bignum/CMakeLists.txt index b2434b7..6b64eb6 100644 --- a/src/bignum/CMakeLists.txt +++ b/src/bignum/CMakeLists.txt @@ -3,7 +3,3 @@ add_library(bignum STATIC bignum.hh ) target_link_libraries(bignum PRIVATE common_options) - -target_include_directories(bignum PUBLIC - $ -) diff --git a/src/parse/CMakeLists.txt b/src/parse/CMakeLists.txt index 3c87a92..22a706c 100644 --- a/src/parse/CMakeLists.txt +++ b/src/parse/CMakeLists.txt @@ -18,6 +18,6 @@ target_link_libraries(parse PRIVATE ) target_include_directories(parse PUBLIC - $ $ + $ ) diff --git a/src/parse/parser-driver.hh b/src/parse/parser-driver.hh index d5ba7ea..ad88efd 100644 --- a/src/parse/parser-driver.hh +++ b/src/parse/parser-driver.hh @@ -4,7 +4,7 @@ #include "parser.hh" -#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... +#include "bignum/bignum.hh" namespace abacus::parse { diff --git a/src/parse/parser.yy b/src/parse/parser.yy index d8fbc87..07e3e3a 100644 --- a/src/parse/parser.yy +++ b/src/parse/parser.yy @@ -36,7 +36,7 @@ namespace abacus::parse { class ParserDriver; } // namespace abacus::parse -#include "bignum.hh" // FIXME: I would like `bignum/bignum.hh` path instead... +#include "bignum/bignum.hh" } %code provides { diff --git a/tests/unit/bignum.cc b/tests/unit/bignum.cc index f584778..b7306f4 100644 --- a/tests/unit/bignum.cc +++ b/tests/unit/bignum.cc @@ -2,7 +2,7 @@ #include -#include "bignum.hh" +#include "bignum/bignum.hh" using namespace abacus::bignum; From 5c7c2af2896f9895962bd0cff4df99fd05125609 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 8 Oct 2021 15:47:26 +0200 Subject: [PATCH 23/35] nix: use 'inputsFrom' --- flake.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index cdf39b2..c5c0dd4 100644 --- a/flake.nix +++ b/flake.nix @@ -59,10 +59,9 @@ defaultPackage = self.packages.${system}.abacus; devShell = pkgs.mkShell { - inherit (self.defaultPackage.${system}) - checkInputs - nativeBuildInputs - ; + inputsFrom = with self.packages.${system}; [ + abacus + ]; inherit (self.checks.${system}.pre-commit) shellHook; }; From da8b08e4e3d7c189c11b1db6abf10926ba8373f7 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 12 Oct 2021 15:02:33 +0200 Subject: [PATCH 24/35] abacus: bignum: use IIFE I think it looks cleaner to use Immediately Invoked Function Expressions in such cases. --- src/bignum/bignum.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 2121cdc..6b6987e 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -82,12 +82,12 @@ digits_type do_addition(digits_type const& lhs, digits_type const& rhs) { ++it2; } - auto it = it1; - auto end = end1; - if (it1 == end1) { - it = it2; - end = end2; - } + auto [it, end] = [=]() { + if (it1 != end1) { + return std::make_pair(it1, end1); + } + return std::make_pair(it2, end2); + }(); while (it != end) { int addition = *it + carry; From 4ea7a38b614fdef27423a340c85459ce151fdf70 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 12 Oct 2021 15:05:38 +0200 Subject: [PATCH 25/35] abacus: use C++20 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d343e5a..7d72bf3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ enable_testing() add_library(common_options INTERFACE) target_compile_features(common_options INTERFACE - cxx_std_17 + cxx_std_20 ) target_compile_options(common_options INTERFACE -Wall From 8cb26ee31611287cc32d8cf042bac47198e5c5f0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 12 Oct 2021 15:05:21 +0200 Subject: [PATCH 26/35] abacus: bignum: use span Once again, the code looks cleaner that way. --- src/bignum/bignum.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 6b6987e..cadc170 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -82,18 +83,17 @@ digits_type do_addition(digits_type const& lhs, digits_type const& rhs) { ++it2; } - auto [it, end] = [=]() { + auto leftover = [=]() { if (it1 != end1) { - return std::make_pair(it1, end1); + return std::span(it1, end1); } - return std::make_pair(it2, end2); + return std::span(it2, end2); }(); - while (it != end) { - int addition = *it + carry; + for (auto value : leftover) { + int addition = value + carry; carry = addition / BASE; res.push_back(addition % BASE); - ++it; } if (carry != 0) { From 3e5133da1ae0fa0eac384a81a23e02877113b5e0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 12 Oct 2021 15:37:18 +0200 Subject: [PATCH 27/35] ci: add package check phase This takes care of launching the test suite. --- .drone.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.drone.yml b/.drone.yml index e52d282..7037529 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,6 +8,10 @@ steps: commands: - nix flake check +- name: package check + commands: + - nix build + - name: notifiy commands: - nix run github:ambroisie/matrix-notifier From a382b299b0addf3873778aa5430cbd0ffc35b14c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 17 Feb 2022 10:03:21 +0100 Subject: [PATCH 28/35] abacus: bignum: fix comparison of negative numbers --- src/bignum/bignum.cc | 6 +++++- tests/unit/bignum.cc | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index cadc170..c6b2c6c 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -363,7 +363,11 @@ bool BigNum::less_than(BigNum const& rhs) const { return sign_ < rhs.sign_; } - return do_less_than(digits_, rhs.digits_); + if (is_positive()) { + return do_less_than(digits_, rhs.digits_); + } else { + return do_less_than(rhs.digits_, digits_); + } } void BigNum::canonicalize() { diff --git a/tests/unit/bignum.cc b/tests/unit/bignum.cc index b7306f4..1126a17 100644 --- a/tests/unit/bignum.cc +++ b/tests/unit/bignum.cc @@ -68,6 +68,34 @@ TEST(BigNum, comparisons_digits) { EXPECT_GT(ten, nine); } +TEST(BigNum, comparisons_negative) { + auto const zero = BigNum(0); + auto const minus_one = BigNum(-1); + auto const minus_two = BigNum(-2); + + EXPECT_LT(minus_one, zero); + EXPECT_LE(minus_one, zero); + EXPECT_LT(minus_two, minus_one); + EXPECT_LE(minus_two, minus_one); + EXPECT_LE(minus_one, minus_one); + EXPECT_GE(minus_two, minus_two); + + EXPECT_GT(zero, minus_one); + EXPECT_GE(zero, minus_one); + EXPECT_GT(minus_one, minus_two); + EXPECT_GE(minus_one, minus_two); + EXPECT_GE(minus_one, minus_one); + EXPECT_GE(minus_two, minus_two); +} + +TEST(BigNum, comparisons_digits_negative) { + auto const minus_nine = BigNum(-9); + auto const minus_ten = BigNum(-10); + + EXPECT_LT(minus_ten, minus_nine); + EXPECT_GT(minus_nine, minus_ten); +} + TEST(BigNum, unary) { auto const zero = BigNum(0); auto const one = BigNum(1); From c9460c09d5e0938d6e09330460d785f35ac7dbb8 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 17 Feb 2022 10:13:11 +0100 Subject: [PATCH 29/35] abacus: bignum: simplify is_canonicalized --- src/bignum/bignum.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index c6b2c6c..3fce460 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -385,15 +385,15 @@ bool BigNum::is_canonicalized() const { return sign_ == 0; } - auto const leading_zeros = std::find_if(digits_.rbegin(), digits_.rend(), - [](auto v) { return v != 0; }); - if (leading_zeros != digits_.rbegin()) { + // `back` is valid since there is at least one element + auto const has_leading_zero = digits_.back() == 0; + if (has_leading_zero) { return false; } - auto const overflow = std::find_if(digits_.begin(), digits_.end(), - [](auto v) { return v >= BASE; }); - if (overflow != digits_.end()) { + auto const has_overflow = std::any_of(digits_.begin(), digits_.end(), + [](auto v) { return v >= BASE; }); + if (has_overflow) { return false; } From d5507dce2d7399efc8db7818b0728e1357de5d7b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 17 Feb 2022 10:27:11 +0100 Subject: [PATCH 30/35] nix: use overlay --- flake.nix | 64 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/flake.nix b/flake.nix index c5c0dd4..e5531d2 100644 --- a/flake.nix +++ b/flake.nix @@ -29,9 +29,40 @@ }; outputs = { self, futils, nixpkgs, pre-commit-hooks }: - futils.lib.eachDefaultSystem (system: + { + overlay = final: prev: { + abacus = final.stdenv.mkDerivation { + pname = "abacus"; + version = "0.0.0"; + + src = self; + + nativeBuildInputs = with final; [ + bison + cmake + flex + ninja + pkg-config + ]; + + checkInputs = with final; [ + gtest + ]; + + doCheck = true; + + meta = with final.lib; { + description = "A simple calculator using big numbers"; + homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; + license = licenses.mit; + maintainers = [ ambroisie ]; + platforms = platforms.unix; + }; + }; + }; + } // futils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; }; + pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; }; in { checks = { @@ -67,34 +98,7 @@ }; packages = futils.lib.flattenTree { - abacus = pkgs.stdenv.mkDerivation { - pname = "abacus"; - version = "0.0.0"; - - src = self; - - nativeBuildInputs = with pkgs; [ - bison - cmake - flex - ninja - pkg-config - ]; - - checkInputs = with pkgs; [ - gtest - ]; - - doCheck = true; - - meta = with pkgs.lib; { - description = "A simple calculator using big numbers"; - homepage = "https://gitea.belanyi.fr/ambroisie/abacus"; - license = licenses.mit; - maintainers = [ ambroisie ]; - platforms = platforms.unix; - }; - }; + inherit (pkgs) abacus; }; }); } From 33de39b62a424b1c2e48e1c78f3ac636ad7be86f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 1 Apr 2023 16:46:32 +0100 Subject: [PATCH 31/35] ci: add Woodpecker CI workflow --- .woodpecker/check.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .woodpecker/check.yml diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml new file mode 100644 index 0000000..921c363 --- /dev/null +++ b/.woodpecker/check.yml @@ -0,0 +1,31 @@ +labels: + type: exec + +pipeline: +- name: flake check + image: bash + commands: + - nix flake check + +- name: package check + image: bash + commands: + - nix build + +- name: notify + image: bash + secrets: + - source: matrix_roomid + target: room + - source: matrix_username + target: user + - source: matrix_password + target: pass + - source: matrix_homeserver + target: address + commands: + - nix run github:ambroisie/matrix-notifier + when: + status: + - failure + - success From 8b3288c1ce190951926f015c730f7290dfdf3270 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 1 Apr 2023 17:13:24 +0100 Subject: [PATCH 32/35] ci: remove Drone CI --- .drone.yml | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 7037529..0000000 --- a/.drone.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -kind: pipeline -type: exec -name: abacus checks - -steps: -- name: flake check - commands: - - nix flake check - -- name: package check - commands: - - nix build - -- name: notifiy - commands: - - nix run github:ambroisie/matrix-notifier - environment: - ADDRESS: - from_secret: matrix_homeserver - ROOM: - from_secret: matrix_roomid - USER: - from_secret: matrix_username - PASS: - from_secret: matrix_password - when: - status: - - failure - - success -... From 2e29dea2b6c946466ce3b2c9f56593acf7156bb2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 6 Dec 2023 11:54:21 +0000 Subject: [PATCH 33/35] abacus: bignum: use base to compute complement Instead of hard-coding 9 for base-10 computations. --- src/bignum/bignum.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bignum/bignum.cc b/src/bignum/bignum.cc index 3fce460..f38159f 100644 --- a/src/bignum/bignum.cc +++ b/src/bignum/bignum.cc @@ -107,7 +107,7 @@ digits_type do_substraction(digits_type const& lhs, digits_type const& rhs) { assert(!do_less_than(lhs, rhs)); digits_type complement; - auto const take_complement = [](auto num) { return 9 - num; }; + auto const take_complement = [](auto num) { return BASE - 1 - num; }; std::transform(lhs.begin(), lhs.end(), std::back_inserter(complement), take_complement); From 34df20cdb7e702360d6c3793f19ad83096d1f4ae Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 6 Dec 2023 11:58:17 +0000 Subject: [PATCH 34/35] nix: fix deprecated flake attributes --- flake.nix | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index e5531d2..a697e6b 100644 --- a/flake.nix +++ b/flake.nix @@ -30,7 +30,7 @@ outputs = { self, futils, nixpkgs, pre-commit-hooks }: { - overlay = final: prev: { + overlays.default = final: prev: { abacus = final.stdenv.mkDerivation { pname = "abacus"; version = "0.0.0"; @@ -62,7 +62,7 @@ }; } // futils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; }; + pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; }; in { checks = { @@ -87,9 +87,7 @@ }; }; - defaultPackage = self.packages.${system}.abacus; - - devShell = pkgs.mkShell { + devShells.default = pkgs.mkShell { inputsFrom = with self.packages.${system}; [ abacus ]; @@ -99,6 +97,7 @@ packages = futils.lib.flattenTree { inherit (pkgs) abacus; + default = pkgs.abacus; }; }); } From c72032f0ce417db0047582bbab004ba36adc2c60 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 6 Dec 2023 11:59:16 +0000 Subject: [PATCH 35/35] ci: fix deprecated syntax --- .woodpecker/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml index 921c363..0901624 100644 --- a/.woodpecker/check.yml +++ b/.woodpecker/check.yml @@ -1,7 +1,7 @@ labels: type: exec -pipeline: +steps: - name: flake check image: bash commands: