From 1fc35d50e4916edc674f3468f63b46e32c8b4a09 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 00:34:50 -0600 Subject: [PATCH 01/48] wip range equality --- compiler+runtime/CMakeLists.txt | 1 + .../src/cpp/jank/runtime/core.cpp | 2 +- .../src/cpp/jank/runtime/obj/range.cpp | 8 +++++-- .../test/cpp/jank/runtime/obj/range.cpp | 24 +++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 compiler+runtime/test/cpp/jank/runtime/obj/range.cpp diff --git a/compiler+runtime/CMakeLists.txt b/compiler+runtime/CMakeLists.txt index 2810abfaa..2193bc13a 100644 --- a/compiler+runtime/CMakeLists.txt +++ b/compiler+runtime/CMakeLists.txt @@ -438,6 +438,7 @@ if(jank_tests) test/cpp/jank/runtime/obj/ratio.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/persistent_vector.cpp + test/cpp/jank/runtime/obj/range.cpp test/cpp/jank/jit/processor.cpp ) add_executable(jank::test_exe ALIAS jank_test_exe) diff --git a/compiler+runtime/src/cpp/jank/runtime/core.cpp b/compiler+runtime/src/cpp/jank/runtime/core.cpp index d1a3eca6e..3d6123680 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core.cpp @@ -245,7 +245,7 @@ namespace jank::runtime } else if(!rhs) { - return !lhs; + return false; } return visit_object([&](auto const typed_lhs) { return typed_lhs->equal(*rhs); }, lhs); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 6d2b0a99e..f0c7b15e8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -1,3 +1,7 @@ +//debugging +#include +#include + #include #include #include @@ -209,12 +213,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp new file mode 100644 index 000000000..386db90c1 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("range") + { + TEST_CASE("equal") + { + CHECK(equal(make_box(make_box(5)), make_box(make_box(5)))); + CHECK(equal(make_box(make_box(1)), make_box(make_box(1)))); + CHECK(!equal(make_box(make_box(6)), make_box(make_box(5)))); + CHECK(!equal(make_box(make_box(5)), make_box(make_box(6)))); + CHECK(equal(make_box(make_box(0)), make_box(make_box(0)))); + CHECK(!equal(make_box(make_box(0)), make_box(make_box(5)))); + //TODO empty range uses persistent_list + //CHECK(!equal(make_box(make_box(1)), make_box(make_box(0)))); + } + } +} From bbc06d0556cb913438aae2921479d98a2b8e25da Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 00:40:21 -0600 Subject: [PATCH 02/48] wip --- compiler+runtime/CMakeLists.txt | 1 + .../cpp/jank/runtime/obj/integer_range.cpp | 4 ++-- .../cpp/jank/runtime/obj/integer_range.cpp | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp diff --git a/compiler+runtime/CMakeLists.txt b/compiler+runtime/CMakeLists.txt index 2193bc13a..96f4279e8 100644 --- a/compiler+runtime/CMakeLists.txt +++ b/compiler+runtime/CMakeLists.txt @@ -439,6 +439,7 @@ if(jank_tests) test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/persistent_vector.cpp test/cpp/jank/runtime/obj/range.cpp + test/cpp/jank/runtime/obj/integer_range.cpp test/cpp/jank/jit/processor.cpp ) add_executable(jank::test_exe ALIAS jank_test_exe) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp index d1e072d22..719dee43a 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp @@ -137,12 +137,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = it->next_in_place(), seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp new file mode 100644 index 000000000..954749cad --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("integer_range") + { + TEST_CASE("equal") + { + CHECK(equal(make_box(make_box(5)), make_box(make_box(5)))); + CHECK(equal(make_box(make_box(1)), make_box(make_box(1)))); + CHECK(!equal(make_box(make_box(6)), make_box(make_box(5)))); + CHECK(!equal(make_box(make_box(5)), make_box(make_box(6)))); + CHECK(equal(make_box(make_box(0)), make_box(make_box(0)))); + CHECK(!equal(make_box(make_box(0)), make_box(make_box(5)))); + //TODO empty integer_range uses persistent_list + //CHECK(!equal(make_box(make_box(1)), make_box(make_box(0)))); + } + } +} From a059c689e090984d299bac358df5b68f4ede3e5f Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 00:48:07 -0600 Subject: [PATCH 03/48] test core::equal --- compiler+runtime/CMakeLists.txt | 2 ++ .../src/cpp/jank/runtime/obj/repeat.cpp | 4 ++-- .../test/cpp/jank/runtime/core.cpp | 21 ++++++++++++++++ .../test/cpp/jank/runtime/obj/repeat.cpp | 24 +++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 compiler+runtime/test/cpp/jank/runtime/core.cpp create mode 100644 compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp diff --git a/compiler+runtime/CMakeLists.txt b/compiler+runtime/CMakeLists.txt index 96f4279e8..da0d53647 100644 --- a/compiler+runtime/CMakeLists.txt +++ b/compiler+runtime/CMakeLists.txt @@ -433,6 +433,7 @@ if(jank_tests) test/cpp/jank/read/lex.cpp test/cpp/jank/read/parse.cpp test/cpp/jank/analyze/box.cpp + test/cpp/jank/runtime/core.cpp test/cpp/jank/runtime/detail/native_persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/ratio.cpp @@ -440,6 +441,7 @@ if(jank_tests) test/cpp/jank/runtime/obj/persistent_vector.cpp test/cpp/jank/runtime/obj/range.cpp test/cpp/jank/runtime/obj/integer_range.cpp + test/cpp/jank/runtime/obj/repeat.cpp test/cpp/jank/jit/processor.cpp ) add_executable(jank::test_exe ALIAS jank_test_exe) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp index ba49ec034..86fbb6db8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp @@ -88,12 +88,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/test/cpp/jank/runtime/core.cpp b/compiler+runtime/test/cpp/jank/runtime/core.cpp new file mode 100644 index 000000000..ac0dfc5ef --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/core.cpp @@ -0,0 +1,21 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime +{ + TEST_SUITE("repeat") + { + TEST_CASE("equal") + { + CHECK(equal(make_box(42), make_box(42))); + CHECK(equal(nullptr, nullptr)); + CHECK(!equal(nullptr, make_box(42))); + CHECK(!equal(make_box(42), nullptr)); + } + } +} + diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp new file mode 100644 index 000000000..06c2e12e0 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("repeat") + { + TEST_CASE("equal") + { + CHECK(equal(make_box(make_box(5), make_box(5)), make_box(make_box(5), make_box(5)))); + CHECK(equal(make_box(make_box(1), make_box(1)), make_box(make_box(1), make_box(1)))); + CHECK(!equal(make_box(make_box(6), make_box(5)), make_box(make_box(5), make_box(5)))); + CHECK(!equal(make_box(make_box(5), make_box(5)), make_box(make_box(5), make_box(6)))); + CHECK(equal(make_box(make_box(0), make_box(0)), make_box(make_box(0), make_box(0)))); + CHECK(!equal(make_box(make_box(0), make_box(0)), make_box(make_box(5), make_box(0)))); + //TODO empty repeat uses persistent_list + //CHECK(!equal(make_box(make_box(1), make_box(1)), make_box(make_box(0), (make_box(1))))); + } + } +} From 701d79f42e9aa03ca3124a57824c2bfec0ed0416 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 00:49:45 -0600 Subject: [PATCH 04/48] wip --- compiler+runtime/src/cpp/jank/runtime/obj/range.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index f0c7b15e8..18978053f 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -1,7 +1,3 @@ -//debugging -#include -#include - #include #include #include From 8a1472e233e48b7e00df22dda2cceed3e90df35d Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 00:50:37 -0600 Subject: [PATCH 05/48] [skip ci] --- compiler+runtime/test/cpp/jank/runtime/core.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler+runtime/test/cpp/jank/runtime/core.cpp b/compiler+runtime/test/cpp/jank/runtime/core.cpp index ac0dfc5ef..e4d20b80c 100644 --- a/compiler+runtime/test/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/core.cpp @@ -1,4 +1,3 @@ -#include #include #include From cbd354fed485b2f72bfbe3b622b5de8d3d638542 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 00:51:44 -0600 Subject: [PATCH 06/48] [skip ci] rm --- compiler+runtime/test/cpp/jank/runtime/core.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler+runtime/test/cpp/jank/runtime/core.cpp b/compiler+runtime/test/cpp/jank/runtime/core.cpp index e4d20b80c..32a12ee00 100644 --- a/compiler+runtime/test/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/core.cpp @@ -10,7 +10,6 @@ namespace jank::runtime { TEST_CASE("equal") { - CHECK(equal(make_box(42), make_box(42))); CHECK(equal(nullptr, nullptr)); CHECK(!equal(nullptr, make_box(42))); CHECK(!equal(make_box(42), nullptr)); From 3727186c7be150a10330dd7e15d72b1d32bda3ef Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 00:52:16 -0600 Subject: [PATCH 07/48] [skip ci] --- compiler+runtime/test/cpp/jank/runtime/core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler+runtime/test/cpp/jank/runtime/core.cpp b/compiler+runtime/test/cpp/jank/runtime/core.cpp index 32a12ee00..5ece04b53 100644 --- a/compiler+runtime/test/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/core.cpp @@ -6,7 +6,7 @@ namespace jank::runtime { - TEST_SUITE("repeat") + TEST_SUITE("core runtime") { TEST_CASE("equal") { From ddd82ac31740fccf3d44b71a3570e58a5b4a1df4 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 01:03:26 -0600 Subject: [PATCH 08/48] tests --- compiler+runtime/CMakeLists.txt | 1 + .../src/cpp/jank/runtime/core.cpp | 2 +- .../cpp/jank/runtime/obj/persistent_list.cpp | 28 +++++++++++++++++++ .../jank/runtime/obj/persistent_vector.cpp | 15 ++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp diff --git a/compiler+runtime/CMakeLists.txt b/compiler+runtime/CMakeLists.txt index da0d53647..4c13a2841 100644 --- a/compiler+runtime/CMakeLists.txt +++ b/compiler+runtime/CMakeLists.txt @@ -437,6 +437,7 @@ if(jank_tests) test/cpp/jank/runtime/detail/native_persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/ratio.cpp + test/cpp/jank/runtime/obj/persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/persistent_vector.cpp test/cpp/jank/runtime/obj/range.cpp diff --git a/compiler+runtime/src/cpp/jank/runtime/core.cpp b/compiler+runtime/src/cpp/jank/runtime/core.cpp index 3d6123680..d2e3e2c2f 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core.cpp @@ -239,7 +239,7 @@ namespace jank::runtime native_bool equal(object_ptr const lhs, object_ptr const rhs) { - if(!lhs) + if(!lhs) // lhs == rhs ?? { return !rhs; } diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp new file mode 100644 index 000000000..841837b67 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("persistent_list") + { + TEST_CASE("equal") + { + CHECK(equal(make_box(std::in_place), + make_box(std::in_place))); + CHECK(!equal(make_box(std::in_place), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place))); + CHECK(equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f')))); + } + } +} diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp index d0abcc14d..285475234 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp @@ -63,5 +63,20 @@ namespace jank::runtime::obj CHECK(equal(v->get_entry(under), nil)); CHECK(equal(v->get_entry(non_int), nil)); } + TEST_CASE("equal") + { + CHECK(equal(make_box(std::in_place), + make_box(std::in_place))); + CHECK(!equal(make_box(std::in_place), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place))); + CHECK(equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f')))); + } } } From c2da5503518dbbea3e84c7de463b0e2c11c28099 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 01:11:34 -0600 Subject: [PATCH 09/48] wip --- compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp index 72fd2c5ab..e24cff833 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp @@ -30,7 +30,7 @@ namespace jank::runtime return false; } } - return seq == nullptr && it == end; + return seq == nullptr; } }, []() { return false; }, From c035ee850b62ffb152b665660870db7add82a1f0 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 01:52:58 -0600 Subject: [PATCH 10/48] [skip ci] --- compiler+runtime/CMakeLists.txt | 2 ++ .../src/cpp/jank/runtime/core/seq.cpp | 23 ++++--------------- .../test/cpp/jank/runtime/core/seq.cpp | 19 +++++++++++++++ .../cpp/jank/runtime/obj/lazy_sequence.cpp | 20 ++++++++++++++++ 4 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 compiler+runtime/test/cpp/jank/runtime/core/seq.cpp create mode 100644 compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp diff --git a/compiler+runtime/CMakeLists.txt b/compiler+runtime/CMakeLists.txt index 4c13a2841..95cb2bd05 100644 --- a/compiler+runtime/CMakeLists.txt +++ b/compiler+runtime/CMakeLists.txt @@ -434,12 +434,14 @@ if(jank_tests) test/cpp/jank/read/parse.cpp test/cpp/jank/analyze/box.cpp test/cpp/jank/runtime/core.cpp + test/cpp/jank/runtime/core/seq.cpp test/cpp/jank/runtime/detail/native_persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/ratio.cpp test/cpp/jank/runtime/obj/persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/persistent_vector.cpp + test/cpp/jank/runtime/obj/lazy_sequence.cpp test/cpp/jank/runtime/obj/range.cpp test/cpp/jank/runtime/obj/integer_range.cpp test/cpp/jank/runtime/obj/repeat.cpp diff --git a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp index 43702996c..83265d12a 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp @@ -1018,29 +1018,16 @@ namespace jank::runtime [](auto const typed_l, object_ptr const r) -> native_bool { return visit_seqable( [](auto const typed_r, auto const typed_l) -> native_bool { - auto r_it(typed_r->fresh_seq()); - auto l_it(typed_l->fresh_seq()); - if(!r_it) + auto seq(typed_r->fresh_seq()); + for(auto it(typed_l->fresh_seq()); it != nullptr; + it = it->next_in_place(), seq = seq->next_in_place()) { - return l_it == nullptr; - } - if(!l_it) - { - return r_it == nullptr; - } - - for(; l_it != nullptr; l_it = l_it->next_in_place(), r_it = r_it->next_in_place()) - { - if(!r_it) - { - return false; - } - if(!runtime::equal(l_it->first(), r_it->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return r_it == nullptr; + return seq == nullptr; }, r, typed_l); diff --git a/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp new file mode 100644 index 000000000..570e70bd4 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp @@ -0,0 +1,19 @@ +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::core +{ + TEST_SUITE("core runtime for seq") + { + TEST_CASE("sequence_equal") + { + CHECK(equal(nullptr, nullptr)); + CHECK(!equal(nullptr, make_box(42))); + CHECK(!equal(make_box(42), nullptr)); + } + } +} + diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp new file mode 100644 index 000000000..7086c0a93 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("lazy_sequence") + { + TEST_CASE("equal") + { + //CHECK(equal(make_box(make_box(convert_function([]() { return nullptr; }))), + // make_box(make_box(convert_function([]() { return nullptr; }))))); + } + } +} + From 4dc1d92115682f2026e476e035d8d618262097df Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 01:54:45 -0600 Subject: [PATCH 11/48] [skip ci] --- compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp index e24cff833..062dec15d 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp @@ -22,8 +22,7 @@ namespace jank::runtime else { auto seq(typed_o->fresh_seq()); - auto it(begin); - for(; it != end; ++it, seq = seq->next_in_place()) + for(auto it(begin); it != end; ++it, seq = seq->next_in_place()) { if(seq == nullptr || !runtime::equal(*it, seq->first())) { From b6d8889df245ff7915bb61b05fb1bac65d25c2de Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 02:14:09 -0600 Subject: [PATCH 12/48] wip --- compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp | 4 ++-- compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp | 4 ++-- .../src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp index cf9ede269..dde61c883 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp @@ -162,12 +162,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp index e7e70f8fc..74f2f0994 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp @@ -77,12 +77,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp index fc69d27ec..66613f57c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp @@ -28,9 +28,9 @@ namespace jank::runtime::obj::detail for(auto const &entry : static_cast(this)->data) { - auto const found(typed_o->contains(entry.first)); + auto const found(typed_o->get_entry(entry.first)); // alternatively use get(key,fallback) - if(!found || !runtime::equal(entry.second, typed_o->get(entry.first))) + if(found == obj::nil::nil_const() || !runtime::equal(entry.second, expect_object(found)->data[1])) { return false; } From 408ed65105a7eaefa95559f4f7e10d7c450cba0b Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 02:27:44 -0600 Subject: [PATCH 13/48] wip --- .../runtime/obj/detail/base_persistent_map_sequence.cpp | 1 + .../src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp | 2 +- compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp | 4 ++-- .../src/cpp/jank/runtime/obj/persistent_vector.cpp | 8 +++----- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp index 9628ead67..d7362a103 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp @@ -14,6 +14,7 @@ namespace jank::runtime::obj::detail assert(begin != end); } + // FIXME this looks wrong template native_bool base_persistent_map_sequence::equal(object const &o) const { diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp index fa3a80f30..d28e7255c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp @@ -39,7 +39,7 @@ namespace jank::runtime::obj::detail return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp index 6f7a23020..3620fbda5 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp @@ -64,12 +64,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp index 12d5e2c01..5326ee572 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp @@ -96,8 +96,7 @@ namespace jank::runtime::obj if constexpr(behavior::sequential) { size_t i{}; - auto e(typed_o->fresh_seq()); - for(; e != nullptr; e = e->next_in_place()) + for(auto e(typed_o->fresh_seq()); e != nullptr; e = e->next_in_place()) { if(!runtime::equal(data[i], e->first())) { @@ -106,11 +105,10 @@ namespace jank::runtime::obj if(++i == data.size()) { - e = e->next_in_place(); - break; + return e->next_in_place() == nullptr; } } - return e == nullptr && i == data.size(); + return false; } else { From 4529d265adadd4dd18ef879999077da4da8d14cc Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 03:04:00 -0600 Subject: [PATCH 14/48] fix --- .../src/cpp/clojure/core_native.cpp | 4 ++-- .../src/cpp/jank/runtime/core/seq.cpp | 4 ++-- .../cpp/jank/runtime/obj/integer_range.cpp | 2 +- .../src/cpp/jank/runtime/obj/range.cpp | 2 +- .../src/cpp/jank/runtime/obj/repeat.cpp | 5 ++++- .../test/cpp/jank/runtime/obj/repeat.cpp | 22 ++++++++++++------- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/compiler+runtime/src/cpp/clojure/core_native.cpp b/compiler+runtime/src/cpp/clojure/core_native.cpp index bec039e93..9987bdc9e 100644 --- a/compiler+runtime/src/cpp/clojure/core_native.cpp +++ b/compiler+runtime/src/cpp/clojure/core_native.cpp @@ -781,8 +781,8 @@ jank_object_ptr jank_load_clojure_core_native() { auto const fn( make_box(behavior::callable::build_arity_flags(2, false, false))); - fn->arity_1 = [](object * const val) -> object * { return repeat(val); }; - fn->arity_2 = [](object * const n, object * const val) -> object * { return repeat(n, val); }; + fn->arity_1 = [](object * const val) -> object * { return obj::repeat::create(val); }; + fn->arity_2 = [](object * const n, object * const val) -> object * { return obj::repeat::create(n, val); }; intern_fn_obj("repeat", fn); } diff --git a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp index 83265d12a..e2e08c3b6 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp @@ -1159,12 +1159,12 @@ namespace jank::runtime object_ptr repeat(object_ptr const val) { - return make_box(val); + return obj::repeat::create(val); } object_ptr repeat(object_ptr const n, object_ptr const val) { - return make_box(n, val); + return obj::repeat::create(n, val); } object_ptr sort(object_ptr const coll) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp index 719dee43a..a827a29d7 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp @@ -80,7 +80,7 @@ namespace jank::runtime::obj } else if(is_zero(step)) { - return make_box(make_box(start)); + return repeat::create(make_box(start)); } return make_box(start, end, diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 18978053f..4dfd8371c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -90,7 +90,7 @@ namespace jank::runtime::obj } /* TODO: Repeat object. */ //else if(is_zero(step)) - //{ return make_box(start); } + //{ return repeat::create(start); } return make_box(start, end, step, diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp index 86fbb6db8..1d5df2786 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp @@ -16,6 +16,9 @@ namespace jank::runtime::obj : value{ value } , count{ count } { + if(lte(count, make_box(0))) { + throw std::runtime_error{ "use repeat::create" }; + } } object_ptr repeat::create(object_ptr const value) @@ -53,7 +56,7 @@ namespace jank::runtime::obj { return this; } - if(lt(count, make_box(1))) + if(lte(count, make_box(1))) { return nullptr; } diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp index 06c2e12e0..0be8e106c 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -11,14 +11,20 @@ namespace jank::runtime::obj { TEST_CASE("equal") { - CHECK(equal(make_box(make_box(5), make_box(5)), make_box(make_box(5), make_box(5)))); - CHECK(equal(make_box(make_box(1), make_box(1)), make_box(make_box(1), make_box(1)))); - CHECK(!equal(make_box(make_box(6), make_box(5)), make_box(make_box(5), make_box(5)))); - CHECK(!equal(make_box(make_box(5), make_box(5)), make_box(make_box(5), make_box(6)))); - CHECK(equal(make_box(make_box(0), make_box(0)), make_box(make_box(0), make_box(0)))); - CHECK(!equal(make_box(make_box(0), make_box(0)), make_box(make_box(5), make_box(0)))); - //TODO empty repeat uses persistent_list - //CHECK(!equal(make_box(make_box(1), make_box(1)), make_box(make_box(0), (make_box(1))))); + CHECK(equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(5)))); + CHECK(equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(1), make_box(1)))); + CHECK(!equal(repeat::create(make_box(6), make_box(5)), repeat::create(make_box(5), make_box(5)))); + CHECK(!equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(6)))); + CHECK(equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(0), make_box(0)))); + CHECK(!equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(5), make_box(0)))); + CHECK(!equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(0), make_box(1)))); + + //TODO test https://github.com/jank-lang/jank/issues/251 , https://github.com/jank-lang/jank/issues/250 + //clojure.core=> (repeat 0 0) + //() + //clojure.core=> (seq (repeat 0 0)) + //nil + } } } From c227006cf0a96bab084fc96ebaee4b28d57abb6e Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Fri, 7 Feb 2025 03:28:36 -0600 Subject: [PATCH 15/48] [skip ci] --- compiler+runtime/src/cpp/jank/runtime/obj/range.cpp | 1 + compiler+runtime/test/cpp/jank/runtime/obj/range.cpp | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 4dfd8371c..55e01b59c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -18,6 +18,7 @@ namespace jank::runtime::obj return lte(val, end); } + //TODO ban these constructors range::range(object_ptr const end) : start{ make_box(0) } , end{ end } diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp index 386db90c1..8aebf77fa 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp @@ -17,8 +17,7 @@ namespace jank::runtime::obj CHECK(!equal(make_box(make_box(5)), make_box(make_box(6)))); CHECK(equal(make_box(make_box(0)), make_box(make_box(0)))); CHECK(!equal(make_box(make_box(0)), make_box(make_box(5)))); - //TODO empty range uses persistent_list - //CHECK(!equal(make_box(make_box(1)), make_box(make_box(0)))); + CHECK(!equal(make_box(make_box(1)), make_box(make_box(0)))); } } } From f1d6e2c7459dc2155b9bd45216829724496572a6 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sun, 9 Feb 2025 21:58:41 -0600 Subject: [PATCH 16/48] fix --- bin/jank/check_everything.clj | 1 + .../obj/detail/base_persistent_map.cpp | 4 +++- .../test/cpp/jank/runtime/core.cpp | 1 - .../test/cpp/jank/runtime/core/seq.cpp | 1 - .../cpp/jank/runtime/obj/lazy_sequence.cpp | 1 - .../cpp/jank/runtime/obj/persistent_list.cpp | 4 ++-- .../test/cpp/jank/runtime/obj/repeat.cpp | 22 ++++++++++++------- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bin/jank/check_everything.clj b/bin/jank/check_everything.clj index f2e689bc0..8068432ad 100755 --- a/bin/jank/check_everything.clj +++ b/bin/jank/check_everything.clj @@ -35,6 +35,7 @@ (if-not apt? (util/log-warning "Skipping dependency install, since we don't have apt-get") (do + (util/quiet-shell {} "sudo apt-get update -y") ; Install deps required for running our tests. (util/quiet-shell {} "sudo apt-get install -y default-jdk software-properties-common lsb-release npm lcov leiningen") ; TODO: Enable once we're linting Clojure/jank again. diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp index 66613f57c..6a2255422 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp @@ -30,7 +30,9 @@ namespace jank::runtime::obj::detail { auto const found(typed_o->get_entry(entry.first)); // alternatively use get(key,fallback) - if(found == obj::nil::nil_const() || !runtime::equal(entry.second, expect_object(found)->data[1])) + if(found == obj::nil::nil_const() + || !runtime::equal(entry.second, + expect_object(found)->data[1])) { return false; } diff --git a/compiler+runtime/test/cpp/jank/runtime/core.cpp b/compiler+runtime/test/cpp/jank/runtime/core.cpp index 5ece04b53..e3b4ad9ab 100644 --- a/compiler+runtime/test/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/core.cpp @@ -16,4 +16,3 @@ namespace jank::runtime } } } - diff --git a/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp index 570e70bd4..f6f3fd409 100644 --- a/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp @@ -16,4 +16,3 @@ namespace jank::runtime::core } } } - diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp index 7086c0a93..be7a635a8 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp @@ -17,4 +17,3 @@ namespace jank::runtime::obj } } } - diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp index 841837b67..81acadca8 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp @@ -11,8 +11,8 @@ namespace jank::runtime::obj { TEST_CASE("equal") { - CHECK(equal(make_box(std::in_place), - make_box(std::in_place))); + CHECK( + equal(make_box(std::in_place), make_box(std::in_place))); CHECK(!equal(make_box(std::in_place), make_box(std::in_place, make_box('f'), make_box('o')))); CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp index 0be8e106c..ebe1e5ca3 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -11,20 +11,26 @@ namespace jank::runtime::obj { TEST_CASE("equal") { - CHECK(equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(5)))); - CHECK(equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(1), make_box(1)))); - CHECK(!equal(repeat::create(make_box(6), make_box(5)), repeat::create(make_box(5), make_box(5)))); - CHECK(!equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(6)))); - CHECK(equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(0), make_box(0)))); - CHECK(!equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(5), make_box(0)))); - CHECK(!equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(0), make_box(1)))); + CHECK( + equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(5)))); + CHECK( + equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(1), make_box(1)))); + CHECK( + !equal(repeat::create(make_box(6), make_box(5)), repeat::create(make_box(5), make_box(5)))); + CHECK( + !equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(6)))); + CHECK( + equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(0), make_box(0)))); + CHECK( + !equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(5), make_box(0)))); + CHECK( + !equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(0), make_box(1)))); //TODO test https://github.com/jank-lang/jank/issues/251 , https://github.com/jank-lang/jank/issues/250 //clojure.core=> (repeat 0 0) //() //clojure.core=> (seq (repeat 0 0)) //nil - } } } From ca229f835541e3fb8ed2aa2d63024db377e002b4 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sun, 9 Feb 2025 22:09:13 -0600 Subject: [PATCH 17/48] [skip ci] --- compiler+runtime/src/cpp/clojure/core_native.cpp | 4 +++- compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp | 3 ++- compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler+runtime/src/cpp/clojure/core_native.cpp b/compiler+runtime/src/cpp/clojure/core_native.cpp index 9987bdc9e..00e779b35 100644 --- a/compiler+runtime/src/cpp/clojure/core_native.cpp +++ b/compiler+runtime/src/cpp/clojure/core_native.cpp @@ -782,7 +782,9 @@ jank_object_ptr jank_load_clojure_core_native() auto const fn( make_box(behavior::callable::build_arity_flags(2, false, false))); fn->arity_1 = [](object * const val) -> object * { return obj::repeat::create(val); }; - fn->arity_2 = [](object * const n, object * const val) -> object * { return obj::repeat::create(n, val); }; + fn->arity_2 = [](object * const n, object * const val) -> object * { + return obj::repeat::create(n, val); + }; intern_fn_obj("repeat", fn); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp index 1d5df2786..9d12a26de 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp @@ -16,7 +16,8 @@ namespace jank::runtime::obj : value{ value } , count{ count } { - if(lte(count, make_box(0))) { + if(lte(count, make_box(0))) + { throw std::runtime_error{ "use repeat::create" }; } } diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp index ebe1e5ca3..4aabdf986 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -32,5 +32,10 @@ namespace jank::runtime::obj //clojure.core=> (seq (repeat 0 0)) //nil } + TEST_CASE("seq") + { + CHECK( + equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); + } } } From 3afba55f4c22060409269fdca99a95399791222a Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sun, 9 Feb 2025 22:43:47 -0600 Subject: [PATCH 18/48] wip --- .../src/cpp/jank/runtime/obj/range.cpp | 2 ++ .../test/cpp/jank/runtime/obj/integer_range.cpp | 15 +++++++-------- .../test/cpp/jank/runtime/obj/range.cpp | 14 +++++++------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 55e01b59c..46f0c5123 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -6,6 +6,8 @@ #include #include +#include //temp + namespace jank::runtime::obj { static native_bool positive_step_bounds_check(object_ptr const val, object_ptr const end) diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp index 954749cad..94498feed 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp @@ -11,14 +11,13 @@ namespace jank::runtime::obj { TEST_CASE("equal") { - CHECK(equal(make_box(make_box(5)), make_box(make_box(5)))); - CHECK(equal(make_box(make_box(1)), make_box(make_box(1)))); - CHECK(!equal(make_box(make_box(6)), make_box(make_box(5)))); - CHECK(!equal(make_box(make_box(5)), make_box(make_box(6)))); - CHECK(equal(make_box(make_box(0)), make_box(make_box(0)))); - CHECK(!equal(make_box(make_box(0)), make_box(make_box(5)))); - //TODO empty integer_range uses persistent_list - //CHECK(!equal(make_box(make_box(1)), make_box(make_box(0)))); + CHECK(equal(integer_range::create(make_box(5)), integer_range::create(make_box(5)))); + CHECK(equal(integer_range::create(make_box(1)), integer_range::create(make_box(1)))); + CHECK(!equal(integer_range::create(make_box(6)), integer_range::create(make_box(5)))); + CHECK(!equal(integer_range::create(make_box(5)), integer_range::create(make_box(6)))); + CHECK(equal(integer_range::create(make_box(0)), integer_range::create(make_box(0)))); + CHECK(!equal(integer_range::create(make_box(0)), integer_range::create(make_box(5)))); + CHECK(!equal(integer_range::create(make_box(1)), integer_range::create(make_box(0)))); } } } diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp index 8aebf77fa..ee363cde3 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp @@ -11,13 +11,13 @@ namespace jank::runtime::obj { TEST_CASE("equal") { - CHECK(equal(make_box(make_box(5)), make_box(make_box(5)))); - CHECK(equal(make_box(make_box(1)), make_box(make_box(1)))); - CHECK(!equal(make_box(make_box(6)), make_box(make_box(5)))); - CHECK(!equal(make_box(make_box(5)), make_box(make_box(6)))); - CHECK(equal(make_box(make_box(0)), make_box(make_box(0)))); - CHECK(!equal(make_box(make_box(0)), make_box(make_box(5)))); - CHECK(!equal(make_box(make_box(1)), make_box(make_box(0)))); + //CHECK(equal(range::create(make_box(5)), range::create(make_box(5)))); + //CHECK(equal(range::create(make_box(1)), range::create(make_box(1)))); + //CHECK(!equal(range::create(make_box(6)), range::create(make_box(5)))); + //CHECK(!equal(range::create(make_box(5)), range::create(make_box(6)))); + //CHECK(equal(range::create(make_box(0)), range::create(make_box(0)))); + //CHECK(!equal(range::create(make_box(0)), range::create(make_box(5)))); + CHECK(!equal(range::create(make_box(1)), range::create(make_box(0)))); } } } From c5f2e332e15d3717fc73714003cff3a1f0989881 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Mon, 10 Feb 2025 12:38:07 -0600 Subject: [PATCH 19/48] [skip ci] --- compiler+runtime/src/cpp/jank/runtime/core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/core.cpp b/compiler+runtime/src/cpp/jank/runtime/core.cpp index d2e3e2c2f..3d6123680 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core.cpp @@ -239,7 +239,7 @@ namespace jank::runtime native_bool equal(object_ptr const lhs, object_ptr const rhs) { - if(!lhs) // lhs == rhs ?? + if(!lhs) { return !rhs; } From 2dbbca6a4d96e8972ec046303e5607c1277d4944 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Mon, 10 Feb 2025 14:17:55 -0600 Subject: [PATCH 20/48] fmt --- compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp index 4aabdf986..f160ba32e 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -34,8 +34,7 @@ namespace jank::runtime::obj } TEST_CASE("seq") { - CHECK( - equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); + CHECK(equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); } } } From fe6f1ddcbb34ee47833f3562f72808fd2c8fccb4 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Wed, 12 Feb 2025 19:18:12 -0600 Subject: [PATCH 21/48] assert --- compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp | 5 +---- compiler+runtime/test/cpp/jank/runtime/obj/range.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp index 9d12a26de..88cbcf030 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp @@ -16,10 +16,7 @@ namespace jank::runtime::obj : value{ value } , count{ count } { - if(lte(count, make_box(0))) - { - throw std::runtime_error{ "use repeat::create" }; - } + assert(0 < to_int(count)); } object_ptr repeat::create(object_ptr const value) diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp index ee363cde3..41aab4a9d 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp @@ -11,12 +11,12 @@ namespace jank::runtime::obj { TEST_CASE("equal") { - //CHECK(equal(range::create(make_box(5)), range::create(make_box(5)))); - //CHECK(equal(range::create(make_box(1)), range::create(make_box(1)))); - //CHECK(!equal(range::create(make_box(6)), range::create(make_box(5)))); - //CHECK(!equal(range::create(make_box(5)), range::create(make_box(6)))); - //CHECK(equal(range::create(make_box(0)), range::create(make_box(0)))); - //CHECK(!equal(range::create(make_box(0)), range::create(make_box(5)))); + CHECK(equal(range::create(make_box(5)), range::create(make_box(5)))); + CHECK(equal(range::create(make_box(1)), range::create(make_box(1)))); + CHECK(!equal(range::create(make_box(6)), range::create(make_box(5)))); + CHECK(!equal(range::create(make_box(5)), range::create(make_box(6)))); + CHECK(equal(range::create(make_box(0)), range::create(make_box(0)))); + CHECK(!equal(range::create(make_box(0)), range::create(make_box(5)))); CHECK(!equal(range::create(make_box(1)), range::create(make_box(0)))); } } From c36ca8d3dfa721d062ca4230e492fac488242ea1 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 00:15:45 -0600 Subject: [PATCH 22/48] [skip ci] --- .../cpp/jank/runtime/behavior/conjable.hpp | 2 +- .../cpp/jank/runtime/behavior/seqable.hpp | 8 +-- .../cpp/jank/runtime/core/make_box.hpp | 12 ++-- .../include/cpp/jank/runtime/core/seq_ext.hpp | 11 ++-- .../cpp/jank/runtime/core/to_string.hpp | 6 +- .../include/cpp/jank/runtime/native_box.hpp | 44 +++++++------- .../src/cpp/clojure/core_native.cpp | 6 +- .../src/cpp/jank/analyze/processor.cpp | 16 +++-- compiler+runtime/src/cpp/jank/hash.cpp | 6 +- compiler+runtime/src/cpp/jank/read/parse.cpp | 14 ++--- .../src/cpp/jank/runtime/context.cpp | 3 +- .../src/cpp/jank/runtime/core.cpp | 15 +++-- .../src/cpp/jank/runtime/core/seq.cpp | 58 +++++++++++-------- .../src/cpp/jank/runtime/obj/chunked_cons.cpp | 21 ++++--- .../src/cpp/jank/runtime/obj/cons.cpp | 23 ++++---- .../obj/detail/base_persistent_map.cpp | 4 +- .../detail/base_persistent_map_sequence.cpp | 11 ++-- .../runtime/obj/detail/iterator_sequence.cpp | 9 +-- .../cpp/jank/runtime/obj/integer_range.cpp | 12 ++-- .../src/cpp/jank/runtime/obj/iterator.cpp | 8 ++- 20 files changed, 162 insertions(+), 127 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp b/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp index a78a27eb7..b3f72a500 100644 --- a/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp @@ -5,7 +5,7 @@ namespace jank::runtime::behavior template concept conjable = requires(T * const t) { /* Appends the specified object to the beginning of the current sequence. However, if - * the current sequence is empty, it must create a cons onto nullptr. It's invalid to + * the current sequence is empty, it must create a cons onto nil. It's invalid to * have a cons onto an empty sequence. */ { t->conj(object_ptr{}) } -> std::convertible_to; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp b/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp index 23a09f011..f068e3a4b 100644 --- a/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp @@ -9,13 +9,13 @@ namespace jank::runtime::behavior template concept seqable = requires(T * const t) { /* Returns a (potentially shared) seq, which could just be `this`, if we're already a - * seq. However, must return a nullptr for empty seqs. Returning a non-null pointer to + * seq. However, must return nil for empty seqs. Returning non-nil to * an empty seq is UB. */ { t->seq() } -> std::convertible_to; /* Returns a unique seq which can be updated in place. This is an optimization which allows * one allocation for a fresh seq which can then be mutated any number of times to traverse - * the data. Also must return nullptr when the sequence is empty. */ + * the data. Also must return nil when the sequence is empty. */ { t->fresh_seq() } -> std::convertible_to; }; @@ -24,7 +24,7 @@ namespace jank::runtime::behavior concept sequenceable = requires(T * const t) { { t->first() } -> std::convertible_to; - /* Steps the sequence forward and returns nullptr if there is no more remaining + /* Steps the sequence forward and returns nil if there is no more remaining * or a pointer to the remaining sequence. * * Next must always return a fresh seq. */ @@ -61,7 +61,7 @@ namespace jank::runtime::behavior * * This ownership transfer enables next_in_place() optimizations where the input * sequenceable_in_place can sometimes be left in an inconsistent state. For example, if returning - * nullptr, the ownership of the input sequenceable_in_place has been transferred to nullptr. + * nil, the ownership of the input sequenceable_in_place has been transferred to nil. * The input sequenceable_in_place is thus made unreachable. This assumption can be used * to elide certain cleanup code. This also applies if (a carefully considered!) allocation * is made to return a new sequenceable_in_place, making the input sequenceable_in_place unreachable. diff --git a/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp b/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp index a25fa6ec9..8e926a72e 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp @@ -11,12 +11,12 @@ namespace jank::runtime { - /* TODO: Constexpr these. */ - [[gnu::always_inline, gnu::flatten, gnu::hot]] - inline auto make_box(std::nullptr_t const &) - { - return runtime::obj::nil::nil_const(); - } + ///* TODO: Constexpr these. */ + //[[gnu::always_inline, gnu::flatten, gnu::hot]] + //inline auto make_box(std::nullptr_t const &) + //{ + // return runtime::obj::nil::nil_const(); + //} [[gnu::always_inline, gnu::flatten, gnu::hot]] inline auto make_box(native_bool const b) diff --git a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp index 062dec15d..b18994c4c 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp @@ -24,12 +24,13 @@ namespace jank::runtime auto seq(typed_o->fresh_seq()); for(auto it(begin); it != end; ++it, seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(*it, seq->first())) + assert(seq); + if(seq == obj::nil::nil_const() || !runtime::equal(*it, seq->first())) { return false; } } - return seq == nullptr; + return seq == obj::nil::nil_const(); } }, []() { return false; }, @@ -42,12 +43,14 @@ namespace jank::runtime requires behavior::sequenceable auto rest(native_box const seq) { - if(!seq || seq == obj::nil::nil_const()) + assert(seq); + if(seq == obj::nil::nil_const()) { return obj::persistent_list::empty(); } auto const ret(seq->next()); - if(ret == nullptr) + assert(ret); + if(ret == obj::nil::nil_const()) { return obj::persistent_list::empty(); } diff --git a/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp b/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp index dfca04f7e..834a4f85c 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp @@ -48,8 +48,9 @@ namespace jank::runtime buff('('); native_bool needs_space{}; - for(auto i(s->fresh_seq()); i != nullptr; i = i->next_in_place()) + for(auto i(s->fresh_seq()); i != obj::nil::nil_const(); i = i->next_in_place()) { + assert(i); if(needs_space) { buff(' '); @@ -104,8 +105,9 @@ namespace jank::runtime buff('('); native_bool needs_space{}; - for(auto i(s->fresh_seq()); i != nullptr; i = i->next_in_place()) + for(auto i(s->fresh_seq()); i != obj::nil::nil_const(); i = i->next_in_place()) { + assert(i); if(needs_space) { buff(' '); diff --git a/compiler+runtime/include/cpp/jank/runtime/native_box.hpp b/compiler+runtime/include/cpp/jank/runtime/native_box.hpp index 66be7c85f..665fd5bd6 100644 --- a/compiler+runtime/include/cpp/jank/runtime/native_box.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/native_box.hpp @@ -11,9 +11,9 @@ namespace jank::runtime native_box() = default; - native_box(std::nullptr_t) - { - } + //native_box(std::nullptr_t) + //{ + //} native_box(std::remove_const_t * const data) : data{ data } @@ -49,20 +49,20 @@ namespace jank::runtime return *data; } - native_bool operator==(std::nullptr_t) const - { - return data == nullptr; - } + //native_bool operator==(std::nullptr_t) const + //{ + // return data == nullptr; + //} native_bool operator==(native_box const &rhs) const { return data == rhs.data; } - native_bool operator!=(std::nullptr_t) const - { - return data != nullptr; - } + //native_bool operator!=(std::nullptr_t) const + //{ + // return data != nullptr; + //} native_bool operator!=(native_box const &rhs) const { @@ -104,9 +104,9 @@ namespace jank::runtime native_box() = default; - native_box(std::nullptr_t) - { - } + //native_box(std::nullptr_t) + //{ + //} native_box(value_type * const data) : data{ data } @@ -156,10 +156,10 @@ namespace jank::runtime return *data; } - native_bool operator==(std::nullptr_t) const - { - return data == nullptr; - } + //native_bool operator==(std::nullptr_t) const + //{ + // return data == nullptr; + //} native_bool operator==(native_box const &rhs) const { @@ -180,10 +180,10 @@ namespace jank::runtime return data == &rhs->base; } - native_bool operator!=(std::nullptr_t) const - { - return data != nullptr; - } + //native_bool operator!=(std::nullptr_t) const + //{ + // return data != nullptr; + //} native_bool operator!=(native_box const &rhs) const { diff --git a/compiler+runtime/src/cpp/clojure/core_native.cpp b/compiler+runtime/src/cpp/clojure/core_native.cpp index ec971e516..7b626ba36 100644 --- a/compiler+runtime/src/cpp/clojure/core_native.cpp +++ b/compiler+runtime/src/cpp/clojure/core_native.cpp @@ -550,8 +550,9 @@ jank_object_ptr jank_load_clojure_core_native() return visit_seqable( [](auto const typed_rest, object_ptr const l) { - for(auto it(typed_rest->fresh_seq()); it != nullptr; it = it->next_in_place()) + for(auto it(typed_rest->fresh_seq()); it != obj::nil::nil_const(); it = it->next_in_place()) { + assert(it); if(!equal(l, it->first())) { return obj::boolean::false_const(); @@ -578,8 +579,9 @@ jank_object_ptr jank_load_clojure_core_native() return obj::boolean::false_const(); } - for(auto it(fresh_seq(rest)); it != nullptr; it = next_in_place(it)) + for(auto it(fresh_seq(rest)); it != obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); if(!is_equiv(l, first(it))) { return obj::boolean::false_const(); diff --git a/compiler+runtime/src/cpp/jank/analyze/processor.cpp b/compiler+runtime/src/cpp/jank/analyze/processor.cpp index 6260087d9..ac53343c1 100644 --- a/compiler+runtime/src/cpp/jank/analyze/processor.cpp +++ b/compiler+runtime/src/cpp/jank/analyze/processor.cpp @@ -241,8 +241,9 @@ namespace jank::analyze auto const keys_exprs{ visit_map_like( [&](auto const typed_imap_obj) -> string_result { keys_and_exprs ret{}; - for(auto seq{ typed_imap_obj->seq() }; seq != nullptr; seq = seq->next()) + for(auto seq{ typed_imap_obj->seq() }; seq != runtime::obj::nil::nil_const(); seq = seq->next()) { + assert(seq); auto const e{ seq->first() }; auto const k_obj{ runtime::nth(e, make_box(0)) }; auto const v_obj{ runtime::nth(e, make_box(1)) }; @@ -1158,8 +1159,9 @@ namespace jank::analyze static runtime::obj::symbol catch_{ "catch" }, finally_{ "finally" }; native_bool has_catch{}, has_finally{}; - for(auto it(next_in_place(list->fresh_seq())); it != nullptr; it = next_in_place(it)) + for(auto it(next_in_place(list->fresh_seq())); it != runtime::obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); auto const item(it->first()); auto const type(runtime::visit_seqable( [](auto const typed_item) { @@ -1200,7 +1202,9 @@ namespace jank::analyze meta_source(item)); } - auto const is_last(it->next() == nullptr); + auto const nxt(it->next()); + assert(nxt); + auto const is_last(nxt == runtime::obj::nil::nil_const()); auto const form_type(is_last ? position : expression_position::statement); auto form(analyze(item, try_frame, form_type, fn_ctx, is_last)); if(form.is_err()) @@ -1339,8 +1343,9 @@ namespace jank::analyze native_vector exprs; exprs.reserve(o->count()); native_bool literal{ true }; - for(auto d = o->fresh_seq(); d != nullptr; d = next_in_place(d)) + for(auto d = o->fresh_seq(); d != runtime::obj::nil::nil_const(); d = next_in_place(d)) { + assert(d); auto res(analyze(d->first(), current_frame, expression_position::value, fn_ctx, true)); if(res.is_err()) { @@ -1446,8 +1451,9 @@ namespace jank::analyze native_vector exprs; exprs.reserve(typed_o->count()); native_bool literal{ true }; - for(auto d = typed_o->fresh_seq(); d != nullptr; d = next_in_place(d)) + for(auto d = typed_o->fresh_seq(); d != runtime::obj::nil::nil_const(); d = next_in_place(d)) { + assert(d); auto res(analyze(d->first(), current_frame, expression_position::value, fn_ctx, true)); if(res.is_err()) { diff --git a/compiler+runtime/src/cpp/jank/hash.cpp b/compiler+runtime/src/cpp/jank/hash.cpp index 38cd02d81..a6ce4d6ae 100644 --- a/compiler+runtime/src/cpp/jank/hash.cpp +++ b/compiler+runtime/src/cpp/jank/hash.cpp @@ -168,8 +168,9 @@ namespace jank::hash { uint32_t n{}; uint32_t hash{ 1 }; - for(auto it(fresh_seq(typed_sequence)); it != nullptr; it = next_in_place(it)) + for(auto it(fresh_seq(typed_sequence)); it != runtime::obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); hash = 31 * hash + visit(it->first()); ++n; } @@ -194,8 +195,9 @@ namespace jank::hash { uint32_t n{}; uint32_t hash{ 1 }; - for(auto it(fresh_seq(typed_sequence)); it != nullptr; it = next_in_place(it)) + for(auto it(fresh_seq(typed_sequence)); it != runtime::obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); hash += visit(it->first()); ++n; } diff --git a/compiler+runtime/src/cpp/jank/read/parse.cpp b/compiler+runtime/src/cpp/jank/read/parse.cpp index e7791c81e..2d755ff8e 100644 --- a/compiler+runtime/src/cpp/jank/read/parse.cpp +++ b/compiler+runtime/src/cpp/jank/read/parse.cpp @@ -783,8 +783,9 @@ namespace jank::read::parse auto const jank_keyword(__rt_ctx->intern_keyword("", "jank").expect_ok()); auto const default_keyword(__rt_ctx->intern_keyword("", "default").expect_ok()); - for(auto it(list->fresh_seq()); it != nullptr;) + for(auto it(list->fresh_seq()); it != obj::nil::nil_const(); it = next_in_place(next_in_place(it))) { + assert(it); auto const kw(it->first()); /* We take the first match, checking for :jank first. If there are duplicates, it doesn't * matter. If :default comes first, we'll always take it. In short, order is important. This @@ -810,8 +811,9 @@ namespace jank::read::parse auto const first(seq->first()); auto const front(pending_forms.begin()); - for(auto it(next_in_place(seq)); it != nullptr; it = next_in_place(it)) + for(auto it(next_in_place(seq)); it != obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); pending_forms.insert(front, it->first()); } @@ -829,8 +831,6 @@ namespace jank::read::parse return object_source_info{ next_in_place(it)->first(), start_token, list_end }; } } - - it = next_in_place(next_in_place(it)); } return ok(none); @@ -846,8 +846,9 @@ namespace jank::read::parse return visit_seqable( [this](auto const typed_seq) -> result { runtime::detail::native_transient_vector ret; - for(auto it(typed_seq->fresh_seq()); it != nullptr; it = next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); auto const item(it->first()); if(syntax_quote_is_unquote(item, false)) @@ -872,8 +873,7 @@ namespace jank::read::parse quoted_item.expect_ok())); } } - auto const vec(make_box(ret.persistent())->seq()); - return vec ?: obj::nil::nil_const(); + return make_box(ret.persistent())->seq(); }, []() -> result { return err(error::internal_parse_failure("syntax_quote_expand_seq arg not seqable")); diff --git a/compiler+runtime/src/cpp/jank/runtime/context.cpp b/compiler+runtime/src/cpp/jank/runtime/context.cpp index e461e0706..7ffc8d0fc 100644 --- a/compiler+runtime/src/cpp/jank/runtime/context.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/context.cpp @@ -643,8 +643,9 @@ namespace jank::runtime auto const thread_id(std::this_thread::get_id()); - for(auto it(bindings->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) + for(auto it(bindings->fresh_seq()); it != obj::nil::nil_const(); it = runtime::next_in_place(it)) { + assert(it); auto const entry(it->first()); auto const var(expect_object(entry->data[0])); if(!var->dynamic.load()) diff --git a/compiler+runtime/src/cpp/jank/runtime/core.cpp b/compiler+runtime/src/cpp/jank/runtime/core.cpp index 3e83e95b4..7fe2df811 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core.cpp @@ -108,8 +108,9 @@ namespace jank::runtime { util::string_builder buff; runtime::to_string(typed_args->first(), buff); - for(auto it(next_in_place(typed_args)); it != nullptr; it = next_in_place(it)) + for(auto it(next_in_place(typed_args)); it != obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); buff(' '); runtime::to_string(it->first(), buff); } @@ -139,8 +140,9 @@ namespace jank::runtime { util::string_builder buff; runtime::to_string(typed_more->first(), buff); - for(auto it(next_in_place(typed_more)); it != nullptr; it = next_in_place(it)) + for(auto it(next_in_place(typed_more)); it != obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); buff(' '); runtime::to_string(it->first(), buff); } @@ -167,8 +169,9 @@ namespace jank::runtime { util::string_builder buff; runtime::to_code_string(typed_args->first(), buff); - for(auto it(next_in_place(typed_args)); it != nullptr; it = next_in_place(it)) + for(auto it(next_in_place(typed_args)); it != obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); buff(' '); runtime::to_code_string(it->first(), buff); } @@ -198,8 +201,9 @@ namespace jank::runtime { util::string_builder buff; runtime::to_code_string(typed_more->first(), buff); - for(auto it(next_in_place(typed_more)); it != nullptr; it = next_in_place(it)) + for(auto it(next_in_place(typed_more)); it != obj::nil::nil_const(); it = next_in_place(it)) { + assert(it); buff(' '); runtime::to_code_string(it->first(), buff); } @@ -253,7 +257,8 @@ namespace jank::runtime object_ptr meta(object_ptr const m) { - if(m == nullptr || m == obj::nil::nil_const()) + assert(m); + if(m == obj::nil::nil_const()) { return obj::nil::nil_const(); } diff --git a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp index 4ed7069a4..7c59f7b8a 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp @@ -34,7 +34,7 @@ namespace jank::runtime } else if constexpr(behavior::seqable) { - return typed_o->seq() == nullptr; + return is_nil(typed_o->seq()); } else if constexpr(behavior::countable) { @@ -447,7 +447,7 @@ namespace jank::runtime return obj::persistent_list::empty(); } auto const ret(seq->next()); - if(ret == nullptr) + if(is_nil(ret)) { return obj::persistent_list::empty(); } @@ -612,8 +612,9 @@ namespace jank::runtime if constexpr(behavior::seqable) { object_ptr ret{ typed_m }; - for(auto seq(typed_keys->fresh_seq()); seq != nullptr; seq = next_in_place(seq)) + for(auto seq(typed_keys->fresh_seq()); seq != obj::nil::nil_const(); seq = next_in_place(seq)) { + assert(seq); ret = get(ret, seq->first()); } return ret; @@ -648,8 +649,9 @@ namespace jank::runtime if constexpr(behavior::seqable) { object_ptr ret{ typed_m }; - for(auto seq(typed_keys->fresh_seq()); seq != nullptr; seq = next_in_place(seq)) + for(auto seq(typed_keys->fresh_seq()); seq != obj::nil::nil_const(); seq = next_in_place(seq)) { + assert(seq); ret = get(ret, seq->first()); } @@ -676,8 +678,9 @@ namespace jank::runtime object_ptr find(object_ptr const s, object_ptr const key) { + assert(s); auto const nil(obj::nil::nil_const()); - if(s == nullptr || s == nil) + if(s == nil) { return nil; } @@ -700,7 +703,8 @@ namespace jank::runtime native_bool contains(object_ptr const s, object_ptr const key) { - if(s == nullptr || s == obj::nil::nil_const()) + assert(s); + if(s == obj::nil::nil_const()) { return false; } @@ -807,8 +811,9 @@ namespace jank::runtime else if constexpr(behavior::seqable) { native_integer i{}; - for(auto it(typed_o->fresh_seq()); it != nullptr; it = next_in_place(it), ++i) + for(auto it(typed_o->fresh_seq()); it != obj::nil::nil_const(); it = next_in_place(it), ++i) { + assert(it); if(i == index) { return it->first(); @@ -847,8 +852,9 @@ namespace jank::runtime else if constexpr(behavior::seqable) { native_integer i{}; - for(auto it(typed_o->fresh_seq()); it != nullptr; it = next_in_place(it), ++i) + for(auto it(typed_o->fresh_seq()); !is_nil(it); it = next_in_place(it), ++i) { + assert(it); if(i == index) { return it->first(); @@ -866,7 +872,7 @@ namespace jank::runtime object_ptr peek(object_ptr const o) { - if(o == obj::nil::nil_const()) + if(is_nil(o)) { return o; } @@ -938,8 +944,9 @@ namespace jank::runtime } return visit_seqable( [](auto const typed_args, util::string_builder &buff) -> native_persistent_string { - for(auto it(typed_args->fresh_seq()); it != nullptr; it = it->next_in_place()) + for(auto it(typed_args->fresh_seq()); !is_nil(it); it = it->next_in_place()) { + assert(it); auto const fst(it->first()); if(is_nil(fst)) { @@ -978,7 +985,8 @@ namespace jank::runtime size_t sequence_length(object_ptr const s, size_t const max) { - if(s == nullptr) + assert(s); + if(is_nil(s)) { return 0; } @@ -987,19 +995,16 @@ namespace jank::runtime [&](auto const typed_s) -> size_t { using T = typename decltype(typed_s)::value_type; - if constexpr(std::same_as) - { - return 0; - } - else if constexpr(behavior::countable) + if constexpr(behavior::countable) { return typed_s->count(); } else if constexpr(behavior::seqable) { size_t length{ 0 }; - for(auto i(typed_s->fresh_seq()); i != nullptr && length < max; i = next_in_place(i)) + for(auto i(typed_s->fresh_seq()); !is_nil(i) && length < max; i = next_in_place(i)) { + assert(i); ++length; } return length; @@ -1025,15 +1030,17 @@ namespace jank::runtime return visit_seqable( [](auto const typed_r, auto const typed_l) -> native_bool { auto seq(typed_r->fresh_seq()); - for(auto it(typed_l->fresh_seq()); it != nullptr; + for(auto it(typed_l->fresh_seq()); !is_nil(it); it = it->next_in_place(), seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(it->first(), seq->first())) + assert(it); + assert(seq); + if(is_nil(seq) || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nullptr; + return is_nil(seq); }, r, typed_l); @@ -1047,8 +1054,9 @@ namespace jank::runtime return visit_seqable( [](auto const typed_coll, object_ptr const f, object_ptr const init) -> object_ptr { object_ptr res{ init }; - for(auto it(typed_coll->fresh_seq()); it != nullptr; it = it->next_in_place()) + for(auto it(typed_coll->fresh_seq()); !is_nil(it); it = it->next_in_place()) { + assert(it); res = dynamic_call(f, res, it->first()); if(res->type == object_type::reduced) { @@ -1116,7 +1124,7 @@ namespace jank::runtime if constexpr(behavior::chunkable) { - return typed_o->chunked_next() ?: obj::nil::nil_const(); + return typed_o->chunked_next(); } { throw std::runtime_error{ fmt::format("not chunkable: {}", typed_o->to_string()) }; @@ -1178,8 +1186,9 @@ namespace jank::runtime return visit_seqable( [](auto const typed_coll) -> object_ptr { native_vector vec; - for(auto it(typed_coll->fresh_seq()); it != nullptr; it = it->next_in_place()) + for(auto it(typed_coll->fresh_seq()); !is_nil(it); it = it->next_in_place()) { + assert(it); vec.push_back(it->first()); } @@ -1206,8 +1215,9 @@ namespace jank::runtime return visit_seqable( [](auto const typed_coll) -> object_ptr { native_vector vec; - for(auto it(typed_coll->fresh_seq()); it != nullptr; it = it->next_in_place()) + for(auto it(typed_coll->fresh_seq()); !is_nil(it); it = it->next_in_place()) { + assert(it); vec.push_back(it->first()); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp index dde61c883..28caaacd1 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp @@ -11,17 +11,19 @@ namespace jank::runtime::obj { chunked_cons::chunked_cons(object_ptr const head, object_ptr const tail) : head{ head } - , tail{ tail == nil::nil_const() ? nullptr : tail } + , tail{ tail } { assert(head); + assert(tail); } chunked_cons::chunked_cons(object_ptr const meta, object_ptr const head, object_ptr const tail) : head{ head } - , tail{ tail == nil::nil_const() ? nullptr : tail } + , tail{ tail } , meta{ meta } { assert(head); + assert(tail); assert(meta); } @@ -79,9 +81,9 @@ namespace jank::runtime::obj static chunked_cons_ptr next_in_place_non_chunked(chunked_cons_ptr const o) { - if(!o->tail) + if(o->tail == nil::nil_const()) { - return nullptr; + return nil::nil_const(); } return visit_object( @@ -92,10 +94,6 @@ namespace jank::runtime::obj { o->head = typed_tail->first(); o->tail = typed_tail->next(); - if(o->tail == nil::nil_const()) - { - o->tail = nullptr; - } return o; } else @@ -159,15 +157,16 @@ namespace jank::runtime::obj return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != nullptr; + for(auto it(fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it->first(), seq->first())) + assert(it); + if(seq == nil::nil_const() || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nullptr; + return seq == nil::nil_const(); }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp index 74f2f0994..e82737384 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp @@ -9,9 +9,10 @@ namespace jank::runtime::obj { cons::cons(object_ptr const head, object_ptr const tail) : head{ head } - , tail{ tail == nil::nil_const() ? nullptr : tail } + , tail{ tail } { assert(head); + assert(tail); } cons_ptr cons::seq() const @@ -31,9 +32,9 @@ namespace jank::runtime::obj object_ptr cons::next() const { - if(!tail) + if(tail == nil::nil_const()) { - return nullptr; + return nil::nil_const(); } return runtime::seq(tail); @@ -41,9 +42,9 @@ namespace jank::runtime::obj cons_ptr cons::next_in_place() { - if(!tail) + if(tail == nil::nil_const()) { - return nullptr; + return nil::nil_const(); } visit_object( @@ -54,10 +55,6 @@ namespace jank::runtime::obj { head = typed_tail->first(); tail = typed_tail->next(); - if(tail == nil::nil_const()) - { - tail = nullptr; - } } else { @@ -74,15 +71,17 @@ namespace jank::runtime::obj return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != nullptr; + for(auto it(fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it->first(), seq->first())) + assert(it); + assert(seq); + if(seq == nil::nil_const() || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nullptr; + return seq == nil::nil_const(); }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp index 6a2255422..e724e0d85 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp @@ -131,7 +131,7 @@ namespace jank::runtime::obj::detail { if(static_cast(this)->data.empty()) { - return nullptr; + return obj::nil::nil_const(); } return make_box(static_cast(this), static_cast(this)->data.begin(), @@ -143,7 +143,7 @@ namespace jank::runtime::obj::detail { if(static_cast(this)->data.empty()) { - return nullptr; + return obj::nil::nil_const(); } return make_box(static_cast(this), static_cast(this)->data.begin(), diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp index d7362a103..740d0f7e2 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp @@ -14,17 +14,18 @@ namespace jank::runtime::obj::detail assert(begin != end); } - // FIXME this looks wrong template native_bool base_persistent_map_sequence::equal(object const &o) const { return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != nullptr; + for(auto it(fresh_seq()); it != obj::nil::nil_const(); it = it->next_in_place(), seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + assert(it); + assert(seq); + if(seq == obj::nil::nil_const() || !runtime::equal(it->first(), seq->first())) { return false; } @@ -132,7 +133,7 @@ namespace jank::runtime::obj::detail if(n == end) { - return nullptr; + return obj::nil::nil_const(); } return make_box(coll, n, end); @@ -145,7 +146,7 @@ namespace jank::runtime::obj::detail if(begin == end) { - return nullptr; + return obj::nil::nil_const(); } return static_cast(this); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp index d28e7255c..532af3def 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp @@ -34,12 +34,13 @@ namespace jank::runtime::obj::detail auto seq(typed_o->fresh_seq()); for(auto it(begin); it != end; ++it, seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(*it, seq->first())) + assert(seq); + if(seq == obj::nil::nil_const() || !runtime::equal(*it, seq->first())) { return false; } } - return seq == nullptr; + return seq == obj::nil::nil_const(); }, []() { return false; }, &o); @@ -105,7 +106,7 @@ namespace jank::runtime::obj::detail if(n == end) { - return nullptr; + return obj::nil::nil_const(); } return make_box(coll, n, end, size); @@ -118,7 +119,7 @@ namespace jank::runtime::obj::detail if(begin == end) { - return nullptr; + return obj::nil::nil_const(); } return static_cast(this); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp index a827a29d7..0f9dbd1a6 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp @@ -108,7 +108,7 @@ namespace jank::runtime::obj { if(count() <= 1) { - return nullptr; + return obj::nil::nil_const(); } return make_box(make_box(add(start, step)), end, step, bounds_check); } @@ -117,7 +117,7 @@ namespace jank::runtime::obj { if(count() <= 1) { - return nullptr; + return obj::nil::nil_const(); } start = make_box(add(start, step)); return this; @@ -134,15 +134,17 @@ namespace jank::runtime::obj [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); /* TODO: This is common code; can it be shared? */ - for(auto it(fresh_seq()); it != nullptr; + for(auto it(fresh_seq()); it != obj::nil::nil_const(); it = it->next_in_place(), seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(it->first(), seq->first())) + assert(it); + assert(seq); + if(seq == obj::nil::nil_const() || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nullptr; + return seq == obj::nil::nil_const(); }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp index 3620fbda5..7d34276ef 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp @@ -61,15 +61,17 @@ namespace jank::runtime::obj return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != nullptr; + for(auto it(fresh_seq()); it != obj::nil::nil_const(); it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it->first(), seq->first())) + assert(it); + assert(seq); + if(seq == obj::nil::nil_const() || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nullptr; + return seq == obj::nil::nil_const(); }, []() { return false; }, &o); From acb06a421512c6552256ca5be9c83589bc287654 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:04:16 -0600 Subject: [PATCH 23/48] wip --- .../src/cpp/jank/runtime/obj/iterator.cpp | 3 ++ .../cpp/jank/runtime/obj/lazy_sequence.cpp | 43 +++++++++---------- .../cpp/jank/runtime/obj/multi_function.cpp | 17 +++++--- .../runtime/obj/native_array_sequence.cpp | 6 +-- .../runtime/obj/native_vector_sequence.cpp | 14 +++--- .../src/cpp/jank/runtime/obj/nil.cpp | 8 ++-- .../jank/runtime/obj/persistent_hash_map.cpp | 6 ++- .../jank/runtime/obj/persistent_hash_set.cpp | 5 ++- .../cpp/jank/runtime/obj/persistent_list.cpp | 19 +++----- .../runtime/obj/persistent_sorted_map.cpp | 6 ++- .../runtime/obj/persistent_sorted_set.cpp | 5 ++- .../jank/runtime/obj/persistent_string.cpp | 8 +--- .../obj/persistent_string_sequence.cpp | 6 +-- .../jank/runtime/obj/persistent_vector.cpp | 24 ++++------- .../obj/persistent_vector_sequence.cpp | 2 +- 15 files changed, 83 insertions(+), 89 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp index 7d34276ef..3ac4f3fbb 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp @@ -84,16 +84,19 @@ namespace jank::runtime::obj native_persistent_string iterator::to_string() { + /* Runs forever. */ return runtime::to_string(seq()); } native_persistent_string iterator::to_code_string() { + /* Runs forever. */ return runtime::to_code_string(seq()); } native_hash iterator::to_hash() const { + /* Runs forever. */ return hash::ordered(&base); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp index fb2ee6e5b..c158a6032 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp @@ -20,22 +20,24 @@ namespace jank::runtime::obj : fn{ fn } , sequence{ sequence } { + assert(sequence); } lazy_sequence_ptr lazy_sequence::seq() const { resolve_seq(); - return sequence ? this : nullptr; + return sequence != nil::nil_const() ? this : nil::nil_const(); } lazy_sequence_ptr lazy_sequence::fresh_seq() const { resolve_seq(); - if(!sequence) + if(sequence == nil::nil_const()) { - return nullptr; + return nil::nil_const(); } auto const s(runtime::fresh_seq(sequence)); + assert(s); assert(s != nil::nil_const()); return make_box(nullptr, s); } @@ -43,26 +45,19 @@ namespace jank::runtime::obj object_ptr lazy_sequence::first() const { resolve_seq(); - if(sequence) - { - return runtime::first(sequence); - } - return nil::nil_const(); + return runtime::first(sequence); } lazy_sequence_ptr lazy_sequence::next() const { resolve_seq(); - if(sequence) + auto const n(runtime::next(sequence)); + assert(n); + if(n == nil::nil_const()) { - auto const n(runtime::next(sequence)); - if(n == nil::nil_const()) - { - return nullptr; - } - return make_box(nullptr, n); + return nil::nil_const(); } - return nullptr; + return make_box(nullptr, n); } lazy_sequence_ptr lazy_sequence::next_in_place() @@ -71,7 +66,7 @@ namespace jank::runtime::obj auto const n(runtime::next_in_place(sequence)); if(n == nil::nil_const()) { - return nullptr; + return nil::nil_const(); } sequence = n; return this; @@ -100,7 +95,8 @@ namespace jank::runtime::obj native_hash lazy_sequence::to_hash() const { auto const s(seq()); - if(!s) + assert(s); + if(s == nil::nil_const()) { return 1; } @@ -110,7 +106,7 @@ namespace jank::runtime::obj cons_ptr lazy_sequence::conj(object_ptr const head) const { resolve_seq(); - return make_box(head, sequence ? this : nullptr); + return make_box(head, sequence != nil::nil_const() ? this : nil::nil_const()); } object_ptr lazy_sequence::resolve_fn() const @@ -145,12 +141,13 @@ namespace jank::runtime::obj if(lazy) { sequence = runtime::seq(lazy); - if(sequence == nil::nil_const()) - { - sequence = nullptr; - } + } + else + { + sequence = obj::nil::nil_const(); } } + assert(sequence); return sequence; } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp index 211216613..3de3d5e7c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp @@ -267,9 +267,10 @@ namespace jank::runtime::obj }; for(auto it(fresh_seq(dynamic_call(parents, hierarchy, y))); - it != nullptr && it != nil::nil_const(); + it != nil::nil_const(); it = next_in_place(it)) { + assert(it); if(is_preferred(hierarchy, x, first(it))) { return true; @@ -277,9 +278,10 @@ namespace jank::runtime::obj } for(auto it(fresh_seq(dynamic_call(parents, hierarchy, x))); - it != nullptr && it != nil::nil_const(); + it != nil::nil_const(); it = next_in_place(it)) { + assert(it); if(is_preferred(hierarchy, first(it), y)) { return true; @@ -340,16 +342,19 @@ namespace jank::runtime::obj object_ptr best_value{ nil::nil_const() }; persistent_vector_sequence_ptr best_entry{}; - for(auto it(fresh_seq(method_table)); it != nullptr; it = it->next_in_place()) + for(auto it(fresh_seq(method_table)); it != nil::nil_const(); it = it->next_in_place()) { - auto const entry(it->first()); - auto const entry_key(entry->seq()->first()); + assert(it); + auto const entry(it->first()->seq()); + assert(entry); + assert(entry != nil::nil_const()); + auto const entry_key(entry->first()); if(is_a(cached_hierarchy, dispatch_val, entry_key)) { if(best_entry == nullptr || is_dominant(cached_hierarchy, entry_key, best_entry->first())) { - best_entry = entry->seq(); + best_entry = entry; } if(!is_dominant(cached_hierarchy, best_entry->first(), entry_key)) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp index 368893b20..c250416fc 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp @@ -23,7 +23,7 @@ namespace jank::runtime::obj assert(size > 0); } - /* behavior::objectable */ + /* behavior::object_like */ native_bool native_array_sequence::equal(object const &o) const { return runtime::equal(o, arr + index, arr + size); @@ -84,7 +84,7 @@ namespace jank::runtime::obj if(size <= n) { - return nullptr; + return nil::nil_const(); } return make_box(arr, n, size); @@ -96,7 +96,7 @@ namespace jank::runtime::obj if(size <= index) { - return nullptr; + return nil::nil_const(); } return this; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp index 60f176815..f3fe5d80a 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp @@ -32,7 +32,7 @@ namespace jank::runtime::obj { } - /* behavior::objectable */ + /* behavior::object_like */ native_bool native_vector_sequence::equal(object const &o) const { return runtime::equal(o, data.begin(), data.end()); @@ -65,12 +65,12 @@ namespace jank::runtime::obj /* behavior::seqable */ native_vector_sequence_ptr native_vector_sequence::seq() { - return data.empty() ? nullptr : this; + return data.empty() ? nil::nil_const() : this; } native_vector_sequence_ptr native_vector_sequence::fresh_seq() const { - return data.empty() ? nullptr : make_box(data, index); + return data.empty() ? nil::nil_const() : make_box(data, index); } /* behavior::countable */ @@ -93,7 +93,7 @@ namespace jank::runtime::obj if(n == data.size()) { - return nullptr; + return nil::nil_const(); } return make_box(data, n); @@ -105,7 +105,7 @@ namespace jank::runtime::obj if(index == data.size()) { - return nullptr; + return nil::nil_const(); } return this; @@ -113,13 +113,13 @@ namespace jank::runtime::obj cons_ptr native_vector_sequence::conj(object_ptr const head) { - return make_box(head, data.empty() ? nullptr : this); + return make_box(head, data.empty() ? nil::nil_const() : this); } native_vector_sequence_ptr native_vector_sequence::with_meta(object_ptr const m) const { auto const meta(behavior::detail::validate_meta(m)); - auto ret(fresh_seq()); + auto ret(make_box(data, index)); ret->meta = meta; return ret; } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp index dacedc6fd..5fdc30046 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp @@ -80,12 +80,12 @@ namespace jank::runtime::obj nil_ptr nil::seq() { - return nullptr; + return this; } nil_ptr nil::fresh_seq() const { - return nullptr; + return this; } nil_ptr nil::first() const @@ -95,11 +95,11 @@ namespace jank::runtime::obj nil_ptr nil::next() const { - return nullptr; + return this; } nil_ptr nil::next_in_place() { - return nullptr; + return this; } } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp index d5a2c5b8e..c46644894 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp @@ -52,11 +52,13 @@ namespace jank::runtime::obj return make_box(visit_seqable( [](auto const typed_seq) -> persistent_hash_map::value_type { runtime::detail::native_transient_hash_map transient; - for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) { + assert(it); auto const key(it->first()); it = runtime::next_in_place(it); - if(!it) + assert(it); + if(it == nil::nil_const()) { throw std::runtime_error{ fmt::format("Odd number of elements: {}", typed_seq->to_string()) }; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp index 18b3d5599..25ccd48fb 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp @@ -37,8 +37,9 @@ namespace jank::runtime::obj return make_box(visit_seqable( [](auto const typed_seq) -> persistent_hash_set::value_type { runtime::detail::native_transient_hash_set transient; - for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) { + assert(it); transient.insert(it->first()); } return transient.persistent(); @@ -108,7 +109,7 @@ namespace jank::runtime::obj { if(data.empty()) { - return nullptr; + return nil::nil_const(); } return make_box(this, data.begin(), data.end(), data.size()); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp index dbcd92967..2e992da6d 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp @@ -22,11 +22,7 @@ namespace jank::runtime::obj persistent_list_ptr persistent_list::create(object_ptr const s) { - if(s == nullptr) - { - return make_box(); - } - + assert(s); return visit_object( [](auto const typed_s) -> persistent_list_ptr { using T = typename decltype(typed_s)::value_type; @@ -34,8 +30,9 @@ namespace jank::runtime::obj if constexpr(behavior::sequenceable || std::same_as) { native_vector v; - for(auto i(typed_s->fresh_seq()); i != nullptr; i = runtime::next_in_place(i)) + for(auto i(typed_s->fresh_seq()); i != nil::nil_const(); i = runtime::next_in_place(i)) { + assert(i); v.emplace_back(i->first()); } return make_box( @@ -86,18 +83,14 @@ namespace jank::runtime::obj persistent_list_sequence_ptr persistent_list::seq() const { - if(data.empty()) - { - return nullptr; - } - return make_box(this, data.begin(), data.end(), data.size()); + return fresh_seq(); } persistent_list_sequence_ptr persistent_list::fresh_seq() const { if(data.empty()) { - return nullptr; + return nil::nil_const(); } return make_box(this, data.begin(), data.end(), data.size()); } @@ -128,7 +121,7 @@ namespace jank::runtime::obj { if(data.size() < 2) { - return nullptr; + return nil::nil_const(); } return make_box(this, ++data.begin(), data.end(), data.size() - 1); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp index e037e1959..27a58dc65 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp @@ -40,11 +40,13 @@ namespace jank::runtime::obj if constexpr(behavior::seqable) { runtime::detail::native_transient_sorted_map transient; - for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) { + assert(it); auto const key(it->first()); it = runtime::next_in_place(it); - if(!it) + assert(it); + if(it == nil::nil_const()) { throw std::runtime_error{ fmt::format("Odd number of elements: {}", typed_seq->to_string()) }; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp index 9f59f1542..4a4477e57 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp @@ -32,8 +32,9 @@ namespace jank::runtime::obj return make_box(visit_seqable( [](auto const typed_seq) -> persistent_sorted_set::value_type { runtime::detail::native_transient_sorted_set transient; - for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) { + assert(it); transient.insert_v(it->first()); } return transient.persistent(); @@ -103,7 +104,7 @@ namespace jank::runtime::obj { if(data.empty()) { - return nullptr; + return nil::nil_const(); } return make_box(this, data.begin(), data.end(), data.size()); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp index dad7697b6..17bf31514 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp @@ -156,18 +156,14 @@ namespace jank::runtime::obj persistent_string_sequence_ptr persistent_string::seq() const { - if(data.empty()) - { - return nullptr; - } - return make_box(const_cast(this)); + return fresh_seq(); } persistent_string_sequence_ptr persistent_string::fresh_seq() const { if(data.empty()) { - return nullptr; + return nil::nil_const(); } return make_box(const_cast(this)); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp index 0785819f5..7b63a4392 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp @@ -19,7 +19,7 @@ namespace jank::runtime::obj assert(!s->data.empty() && i < s->data.size()); } - /* behavior::objectable */ + /* behavior::object_like */ native_bool persistent_string_sequence::equal(object const &o) const { return runtime::equal(o, str->data.begin() + index, str->data.end()); @@ -79,7 +79,7 @@ namespace jank::runtime::obj if(n == str->data.size()) { - return nullptr; + return nil::nil_const(); } return make_box(str, n); @@ -91,7 +91,7 @@ namespace jank::runtime::obj if(index == str->data.size()) { - return nullptr; + return nil::nil_const(); } return this; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp index 5326ee572..3e3af76d3 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp @@ -34,7 +34,8 @@ namespace jank::runtime::obj persistent_vector_ptr persistent_vector::create(object_ptr const s) { - if(s == nullptr) + assert(s); + if(s == nil::nil_const()) { return make_box(); } @@ -46,8 +47,9 @@ namespace jank::runtime::obj if constexpr(behavior::sequenceable) { runtime::detail::native_transient_vector v; - for(auto i(typed_s->fresh_seq()); i != nullptr; i = runtime::next_in_place(i)) + for(auto i(typed_s->fresh_seq()); i != nil::nil_const(); i = runtime::next_in_place(i)) { + assert(i); v.push_back(i->first()); } return make_box(v.persistent()); @@ -96,19 +98,15 @@ namespace jank::runtime::obj if constexpr(behavior::sequential) { size_t i{}; - for(auto e(typed_o->fresh_seq()); e != nullptr; e = e->next_in_place()) + for(auto e(typed_o->fresh_seq()); e != nil::nil_const() && i < data.size(); e = e->next_in_place(), ++i) { + assert(e); if(!runtime::equal(data[i], e->first())) { return false; } - - if(++i == data.size()) - { - return e->next_in_place() == nullptr; - } } - return false; + return e == nil::nil_const() && i == data.size(); } else { @@ -182,18 +180,14 @@ namespace jank::runtime::obj persistent_vector_sequence_ptr persistent_vector::seq() const { - if(data.empty()) - { - return nullptr; - } - return make_box(const_cast(this)); + return fresh_seq(); } persistent_vector_sequence_ptr persistent_vector::fresh_seq() const { if(data.empty()) { - return nullptr; + return nil::nil_const(); } return make_box(const_cast(this)); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp index c4d28a9b0..447453ffa 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp @@ -20,7 +20,7 @@ namespace jank::runtime::obj assert(0 < v->data.size() - index); } - /* behavior::objectable */ + /* behavior::object_like */ native_bool persistent_vector_sequence::equal(object const &o) const { return runtime::equal( From 4a1620fef16a257ba3f7247e2e402c35aaeb2c76 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:15:54 -0600 Subject: [PATCH 24/48] [skip ci] --- .../include/cpp/jank/runtime/obj/range.hpp | 26 +++++++++---------- .../src/cpp/jank/runtime/obj/range.cpp | 17 ++++++------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp index 62e403173..c2ce5ed6d 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp @@ -21,19 +21,19 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(object_ptr, object_ptr); - range() = default; - range(range &&) noexcept = default; - range(range const &) = default; - range(object_ptr end); - range(object_ptr start, object_ptr end); - range(object_ptr start, object_ptr end, object_ptr step); - range(object_ptr start, object_ptr end, object_ptr step, bounds_check_t bounds_check); - range(object_ptr start, - object_ptr end, - object_ptr step, - bounds_check_t bounds_check, - obj::array_chunk_ptr chunk, - range_ptr chunk_next); + //range() = default; + //range(range &&) noexcept = default; + //range(range const &) = default; + //range(object_ptr end); + //range(object_ptr start, object_ptr end); + //range(object_ptr start, object_ptr end, object_ptr step); + //range(object_ptr start, object_ptr end, object_ptr step, bounds_check_t bounds_check); + //range(object_ptr start, + // object_ptr end, + // object_ptr step, + // bounds_check_t bounds_check, + // obj::array_chunk_ptr chunk, + // range_ptr chunk_next); static object_ptr create(object_ptr end); static object_ptr create(object_ptr start, object_ptr end); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 46f0c5123..63fc24c23 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -20,7 +20,7 @@ namespace jank::runtime::obj return lte(val, end); } - //TODO ban these constructors + /* Never use constructors outside of this file. Use range::create. */ range::range(object_ptr const end) : start{ make_box(0) } , end{ end } @@ -69,6 +69,7 @@ namespace jank::runtime::obj , chunk{ chunk } , chunk_next{ chunk_next } { + assert(chunk_next); } object_ptr range::create(object_ptr const end) @@ -191,10 +192,6 @@ namespace jank::runtime::obj range_ptr range::chunked_next() const { force_chunk(); - if(!chunk_next) - { - return nullptr; - } return chunk_next; } @@ -209,15 +206,17 @@ namespace jank::runtime::obj [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); /* TODO: This is common code; can it be shared? */ - for(auto it(fresh_seq()); it != nullptr; + for(auto it(fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it->first(), seq->first())) + assert(it); + assert(seq); + if(seq == nil::nil_const() || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nullptr; + return seq == nil::nil_const(); }, []() { return false; }, &o); @@ -246,7 +245,7 @@ namespace jank::runtime::obj range_ptr range::with_meta(object_ptr const m) const { auto const meta(behavior::detail::validate_meta(m)); - auto ret(fresh_seq()); + auto ret(make_box(start, end, step, bounds_check)); ret->meta = meta; return ret; } From b3ffc63a8ebae001ab8c112f21ebc56d35dc0eba Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:21:41 -0600 Subject: [PATCH 25/48] [skip ci] --- .../cpp/jank/runtime/core/to_string.hpp | 1 + .../include/cpp/jank/runtime/native_box.hpp | 44 +++++++++---------- .../jank/runtime/obj/persistent_vector.cpp | 3 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp b/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp index 834a4f85c..b6c8d1f15 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace jank::runtime { diff --git a/compiler+runtime/include/cpp/jank/runtime/native_box.hpp b/compiler+runtime/include/cpp/jank/runtime/native_box.hpp index 665fd5bd6..66be7c85f 100644 --- a/compiler+runtime/include/cpp/jank/runtime/native_box.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/native_box.hpp @@ -11,9 +11,9 @@ namespace jank::runtime native_box() = default; - //native_box(std::nullptr_t) - //{ - //} + native_box(std::nullptr_t) + { + } native_box(std::remove_const_t * const data) : data{ data } @@ -49,20 +49,20 @@ namespace jank::runtime return *data; } - //native_bool operator==(std::nullptr_t) const - //{ - // return data == nullptr; - //} + native_bool operator==(std::nullptr_t) const + { + return data == nullptr; + } native_bool operator==(native_box const &rhs) const { return data == rhs.data; } - //native_bool operator!=(std::nullptr_t) const - //{ - // return data != nullptr; - //} + native_bool operator!=(std::nullptr_t) const + { + return data != nullptr; + } native_bool operator!=(native_box const &rhs) const { @@ -104,9 +104,9 @@ namespace jank::runtime native_box() = default; - //native_box(std::nullptr_t) - //{ - //} + native_box(std::nullptr_t) + { + } native_box(value_type * const data) : data{ data } @@ -156,10 +156,10 @@ namespace jank::runtime return *data; } - //native_bool operator==(std::nullptr_t) const - //{ - // return data == nullptr; - //} + native_bool operator==(std::nullptr_t) const + { + return data == nullptr; + } native_bool operator==(native_box const &rhs) const { @@ -180,10 +180,10 @@ namespace jank::runtime return data == &rhs->base; } - //native_bool operator!=(std::nullptr_t) const - //{ - // return data != nullptr; - //} + native_bool operator!=(std::nullptr_t) const + { + return data != nullptr; + } native_bool operator!=(native_box const &rhs) const { diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp index 3e3af76d3..e5d7f4021 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp @@ -98,7 +98,8 @@ namespace jank::runtime::obj if constexpr(behavior::sequential) { size_t i{}; - for(auto e(typed_o->fresh_seq()); e != nil::nil_const() && i < data.size(); e = e->next_in_place(), ++i) + auto e(typed_o->fresh_seq()) + for(; e != nil::nil_const() && i < data.size(); e = e->next_in_place(), ++i) { assert(e); if(!runtime::equal(data[i], e->first())) From 8bf2c341615b388aec76b83751f9b4edda751df7 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:34:28 -0600 Subject: [PATCH 26/48] [skip ci] undo --- bin/jank/check_everything.clj | 1 - .../include/cpp/jank/runtime/behavior/conjable.hpp | 2 +- .../include/cpp/jank/runtime/behavior/seqable.hpp | 8 ++++---- .../include/cpp/jank/runtime/core/make_box.hpp | 12 ++++++------ .../include/cpp/jank/runtime/core/seq_ext.hpp | 14 ++++++-------- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/bin/jank/check_everything.clj b/bin/jank/check_everything.clj index cd9a3ce84..2e41db64f 100755 --- a/bin/jank/check_everything.clj +++ b/bin/jank/check_everything.clj @@ -35,7 +35,6 @@ (if-not apt? (util/log-warning "Skipping dependency install, since we don't have apt-get") (do - (util/quiet-shell {} "sudo apt-get update -y") ; Install deps required for running our tests. (util/quiet-shell {} "sudo apt-get update -y") (util/quiet-shell {} "sudo apt-get install -y default-jdk software-properties-common lsb-release npm lcov leiningen") diff --git a/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp b/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp index b3f72a500..a78a27eb7 100644 --- a/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/behavior/conjable.hpp @@ -5,7 +5,7 @@ namespace jank::runtime::behavior template concept conjable = requires(T * const t) { /* Appends the specified object to the beginning of the current sequence. However, if - * the current sequence is empty, it must create a cons onto nil. It's invalid to + * the current sequence is empty, it must create a cons onto nullptr. It's invalid to * have a cons onto an empty sequence. */ { t->conj(object_ptr{}) } -> std::convertible_to; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp b/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp index f068e3a4b..23a09f011 100644 --- a/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp @@ -9,13 +9,13 @@ namespace jank::runtime::behavior template concept seqable = requires(T * const t) { /* Returns a (potentially shared) seq, which could just be `this`, if we're already a - * seq. However, must return nil for empty seqs. Returning non-nil to + * seq. However, must return a nullptr for empty seqs. Returning a non-null pointer to * an empty seq is UB. */ { t->seq() } -> std::convertible_to; /* Returns a unique seq which can be updated in place. This is an optimization which allows * one allocation for a fresh seq which can then be mutated any number of times to traverse - * the data. Also must return nil when the sequence is empty. */ + * the data. Also must return nullptr when the sequence is empty. */ { t->fresh_seq() } -> std::convertible_to; }; @@ -24,7 +24,7 @@ namespace jank::runtime::behavior concept sequenceable = requires(T * const t) { { t->first() } -> std::convertible_to; - /* Steps the sequence forward and returns nil if there is no more remaining + /* Steps the sequence forward and returns nullptr if there is no more remaining * or a pointer to the remaining sequence. * * Next must always return a fresh seq. */ @@ -61,7 +61,7 @@ namespace jank::runtime::behavior * * This ownership transfer enables next_in_place() optimizations where the input * sequenceable_in_place can sometimes be left in an inconsistent state. For example, if returning - * nil, the ownership of the input sequenceable_in_place has been transferred to nil. + * nullptr, the ownership of the input sequenceable_in_place has been transferred to nullptr. * The input sequenceable_in_place is thus made unreachable. This assumption can be used * to elide certain cleanup code. This also applies if (a carefully considered!) allocation * is made to return a new sequenceable_in_place, making the input sequenceable_in_place unreachable. diff --git a/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp b/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp index 8e926a72e..a25fa6ec9 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/make_box.hpp @@ -11,12 +11,12 @@ namespace jank::runtime { - ///* TODO: Constexpr these. */ - //[[gnu::always_inline, gnu::flatten, gnu::hot]] - //inline auto make_box(std::nullptr_t const &) - //{ - // return runtime::obj::nil::nil_const(); - //} + /* TODO: Constexpr these. */ + [[gnu::always_inline, gnu::flatten, gnu::hot]] + inline auto make_box(std::nullptr_t const &) + { + return runtime::obj::nil::nil_const(); + } [[gnu::always_inline, gnu::flatten, gnu::hot]] inline auto make_box(native_bool const b) diff --git a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp index b18994c4c..72fd2c5ab 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/seq_ext.hpp @@ -22,15 +22,15 @@ namespace jank::runtime else { auto seq(typed_o->fresh_seq()); - for(auto it(begin); it != end; ++it, seq = seq->next_in_place()) + auto it(begin); + for(; it != end; ++it, seq = seq->next_in_place()) { - assert(seq); - if(seq == obj::nil::nil_const() || !runtime::equal(*it, seq->first())) + if(seq == nullptr || !runtime::equal(*it, seq->first())) { return false; } } - return seq == obj::nil::nil_const(); + return seq == nullptr && it == end; } }, []() { return false; }, @@ -43,14 +43,12 @@ namespace jank::runtime requires behavior::sequenceable auto rest(native_box const seq) { - assert(seq); - if(seq == obj::nil::nil_const()) + if(!seq || seq == obj::nil::nil_const()) { return obj::persistent_list::empty(); } auto const ret(seq->next()); - assert(ret); - if(ret == obj::nil::nil_const()) + if(ret == nullptr) { return obj::persistent_list::empty(); } From 6b760d1e7ce708a2c7cf8ec94c97355925fc7c41 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:36:25 -0600 Subject: [PATCH 27/48] [skip ci] --- compiler+runtime/src/cpp/clojure/core_native.cpp | 6 ++---- .../src/cpp/jank/analyze/processor.cpp | 16 +++++----------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/compiler+runtime/src/cpp/clojure/core_native.cpp b/compiler+runtime/src/cpp/clojure/core_native.cpp index 7b626ba36..ec971e516 100644 --- a/compiler+runtime/src/cpp/clojure/core_native.cpp +++ b/compiler+runtime/src/cpp/clojure/core_native.cpp @@ -550,9 +550,8 @@ jank_object_ptr jank_load_clojure_core_native() return visit_seqable( [](auto const typed_rest, object_ptr const l) { - for(auto it(typed_rest->fresh_seq()); it != obj::nil::nil_const(); it = it->next_in_place()) + for(auto it(typed_rest->fresh_seq()); it != nullptr; it = it->next_in_place()) { - assert(it); if(!equal(l, it->first())) { return obj::boolean::false_const(); @@ -579,9 +578,8 @@ jank_object_ptr jank_load_clojure_core_native() return obj::boolean::false_const(); } - for(auto it(fresh_seq(rest)); it != obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(fresh_seq(rest)); it != nullptr; it = next_in_place(it)) { - assert(it); if(!is_equiv(l, first(it))) { return obj::boolean::false_const(); diff --git a/compiler+runtime/src/cpp/jank/analyze/processor.cpp b/compiler+runtime/src/cpp/jank/analyze/processor.cpp index ac53343c1..6260087d9 100644 --- a/compiler+runtime/src/cpp/jank/analyze/processor.cpp +++ b/compiler+runtime/src/cpp/jank/analyze/processor.cpp @@ -241,9 +241,8 @@ namespace jank::analyze auto const keys_exprs{ visit_map_like( [&](auto const typed_imap_obj) -> string_result { keys_and_exprs ret{}; - for(auto seq{ typed_imap_obj->seq() }; seq != runtime::obj::nil::nil_const(); seq = seq->next()) + for(auto seq{ typed_imap_obj->seq() }; seq != nullptr; seq = seq->next()) { - assert(seq); auto const e{ seq->first() }; auto const k_obj{ runtime::nth(e, make_box(0)) }; auto const v_obj{ runtime::nth(e, make_box(1)) }; @@ -1159,9 +1158,8 @@ namespace jank::analyze static runtime::obj::symbol catch_{ "catch" }, finally_{ "finally" }; native_bool has_catch{}, has_finally{}; - for(auto it(next_in_place(list->fresh_seq())); it != runtime::obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(next_in_place(list->fresh_seq())); it != nullptr; it = next_in_place(it)) { - assert(it); auto const item(it->first()); auto const type(runtime::visit_seqable( [](auto const typed_item) { @@ -1202,9 +1200,7 @@ namespace jank::analyze meta_source(item)); } - auto const nxt(it->next()); - assert(nxt); - auto const is_last(nxt == runtime::obj::nil::nil_const()); + auto const is_last(it->next() == nullptr); auto const form_type(is_last ? position : expression_position::statement); auto form(analyze(item, try_frame, form_type, fn_ctx, is_last)); if(form.is_err()) @@ -1343,9 +1339,8 @@ namespace jank::analyze native_vector exprs; exprs.reserve(o->count()); native_bool literal{ true }; - for(auto d = o->fresh_seq(); d != runtime::obj::nil::nil_const(); d = next_in_place(d)) + for(auto d = o->fresh_seq(); d != nullptr; d = next_in_place(d)) { - assert(d); auto res(analyze(d->first(), current_frame, expression_position::value, fn_ctx, true)); if(res.is_err()) { @@ -1451,9 +1446,8 @@ namespace jank::analyze native_vector exprs; exprs.reserve(typed_o->count()); native_bool literal{ true }; - for(auto d = typed_o->fresh_seq(); d != runtime::obj::nil::nil_const(); d = next_in_place(d)) + for(auto d = typed_o->fresh_seq(); d != nullptr; d = next_in_place(d)) { - assert(d); auto res(analyze(d->first(), current_frame, expression_position::value, fn_ctx, true)); if(res.is_err()) { From 0bbcbc13ac9331a6d44daa898fa52cd8be779586 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:45:31 -0600 Subject: [PATCH 28/48] [skip ci] --- compiler+runtime/src/cpp/jank/hash.cpp | 6 +- compiler+runtime/src/cpp/jank/read/parse.cpp | 12 ++- .../src/cpp/jank/runtime/context.cpp | 3 +- .../src/cpp/jank/runtime/core.cpp | 15 ++-- .../src/cpp/jank/runtime/core/seq.cpp | 75 ++++++++++--------- 5 files changed, 52 insertions(+), 59 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/hash.cpp b/compiler+runtime/src/cpp/jank/hash.cpp index a6ce4d6ae..38cd02d81 100644 --- a/compiler+runtime/src/cpp/jank/hash.cpp +++ b/compiler+runtime/src/cpp/jank/hash.cpp @@ -168,9 +168,8 @@ namespace jank::hash { uint32_t n{}; uint32_t hash{ 1 }; - for(auto it(fresh_seq(typed_sequence)); it != runtime::obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(fresh_seq(typed_sequence)); it != nullptr; it = next_in_place(it)) { - assert(it); hash = 31 * hash + visit(it->first()); ++n; } @@ -195,9 +194,8 @@ namespace jank::hash { uint32_t n{}; uint32_t hash{ 1 }; - for(auto it(fresh_seq(typed_sequence)); it != runtime::obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(fresh_seq(typed_sequence)); it != nullptr; it = next_in_place(it)) { - assert(it); hash += visit(it->first()); ++n; } diff --git a/compiler+runtime/src/cpp/jank/read/parse.cpp b/compiler+runtime/src/cpp/jank/read/parse.cpp index 2d755ff8e..170069cd3 100644 --- a/compiler+runtime/src/cpp/jank/read/parse.cpp +++ b/compiler+runtime/src/cpp/jank/read/parse.cpp @@ -783,9 +783,8 @@ namespace jank::read::parse auto const jank_keyword(__rt_ctx->intern_keyword("", "jank").expect_ok()); auto const default_keyword(__rt_ctx->intern_keyword("", "default").expect_ok()); - for(auto it(list->fresh_seq()); it != obj::nil::nil_const(); it = next_in_place(next_in_place(it))) + for(auto it(list->fresh_seq()); it != nullptr; it = next_in_place(next_in_place(it))) { - assert(it); auto const kw(it->first()); /* We take the first match, checking for :jank first. If there are duplicates, it doesn't * matter. If :default comes first, we'll always take it. In short, order is important. This @@ -811,9 +810,8 @@ namespace jank::read::parse auto const first(seq->first()); auto const front(pending_forms.begin()); - for(auto it(next_in_place(seq)); it != obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(next_in_place(seq)); it != nullptr; it = next_in_place(it)) { - assert(it); pending_forms.insert(front, it->first()); } @@ -846,9 +844,8 @@ namespace jank::read::parse return visit_seqable( [this](auto const typed_seq) -> result { runtime::detail::native_transient_vector ret; - for(auto it(typed_seq->fresh_seq()); it != obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nullptr; it = next_in_place(it)) { - assert(it); auto const item(it->first()); if(syntax_quote_is_unquote(item, false)) @@ -873,7 +870,8 @@ namespace jank::read::parse quoted_item.expect_ok())); } } - return make_box(ret.persistent())->seq(); + auto const vec(make_box(ret.persistent())->seq()); + return vec ?: obj::nil::nil_const(); }, []() -> result { return err(error::internal_parse_failure("syntax_quote_expand_seq arg not seqable")); diff --git a/compiler+runtime/src/cpp/jank/runtime/context.cpp b/compiler+runtime/src/cpp/jank/runtime/context.cpp index 7ffc8d0fc..e461e0706 100644 --- a/compiler+runtime/src/cpp/jank/runtime/context.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/context.cpp @@ -643,9 +643,8 @@ namespace jank::runtime auto const thread_id(std::this_thread::get_id()); - for(auto it(bindings->fresh_seq()); it != obj::nil::nil_const(); it = runtime::next_in_place(it)) + for(auto it(bindings->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) { - assert(it); auto const entry(it->first()); auto const var(expect_object(entry->data[0])); if(!var->dynamic.load()) diff --git a/compiler+runtime/src/cpp/jank/runtime/core.cpp b/compiler+runtime/src/cpp/jank/runtime/core.cpp index 7fe2df811..3e83e95b4 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core.cpp @@ -108,9 +108,8 @@ namespace jank::runtime { util::string_builder buff; runtime::to_string(typed_args->first(), buff); - for(auto it(next_in_place(typed_args)); it != obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(next_in_place(typed_args)); it != nullptr; it = next_in_place(it)) { - assert(it); buff(' '); runtime::to_string(it->first(), buff); } @@ -140,9 +139,8 @@ namespace jank::runtime { util::string_builder buff; runtime::to_string(typed_more->first(), buff); - for(auto it(next_in_place(typed_more)); it != obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(next_in_place(typed_more)); it != nullptr; it = next_in_place(it)) { - assert(it); buff(' '); runtime::to_string(it->first(), buff); } @@ -169,9 +167,8 @@ namespace jank::runtime { util::string_builder buff; runtime::to_code_string(typed_args->first(), buff); - for(auto it(next_in_place(typed_args)); it != obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(next_in_place(typed_args)); it != nullptr; it = next_in_place(it)) { - assert(it); buff(' '); runtime::to_code_string(it->first(), buff); } @@ -201,9 +198,8 @@ namespace jank::runtime { util::string_builder buff; runtime::to_code_string(typed_more->first(), buff); - for(auto it(next_in_place(typed_more)); it != obj::nil::nil_const(); it = next_in_place(it)) + for(auto it(next_in_place(typed_more)); it != nullptr; it = next_in_place(it)) { - assert(it); buff(' '); runtime::to_code_string(it->first(), buff); } @@ -257,8 +253,7 @@ namespace jank::runtime object_ptr meta(object_ptr const m) { - assert(m); - if(m == obj::nil::nil_const()) + if(m == nullptr || m == obj::nil::nil_const()) { return obj::nil::nil_const(); } diff --git a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp index 7c59f7b8a..a6cae170e 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp @@ -34,7 +34,7 @@ namespace jank::runtime } else if constexpr(behavior::seqable) { - return is_nil(typed_o->seq()); + return typed_o->seq() == nullptr; } else if constexpr(behavior::countable) { @@ -447,7 +447,7 @@ namespace jank::runtime return obj::persistent_list::empty(); } auto const ret(seq->next()); - if(is_nil(ret)) + if(ret == nullptr) { return obj::persistent_list::empty(); } @@ -612,9 +612,8 @@ namespace jank::runtime if constexpr(behavior::seqable) { object_ptr ret{ typed_m }; - for(auto seq(typed_keys->fresh_seq()); seq != obj::nil::nil_const(); seq = next_in_place(seq)) + for(auto seq(typed_keys->fresh_seq()); seq != nullptr; seq = next_in_place(seq)) { - assert(seq); ret = get(ret, seq->first()); } return ret; @@ -649,9 +648,8 @@ namespace jank::runtime if constexpr(behavior::seqable) { object_ptr ret{ typed_m }; - for(auto seq(typed_keys->fresh_seq()); seq != obj::nil::nil_const(); seq = next_in_place(seq)) + for(auto seq(typed_keys->fresh_seq()); seq != nullptr; seq = next_in_place(seq)) { - assert(seq); ret = get(ret, seq->first()); } @@ -678,9 +676,8 @@ namespace jank::runtime object_ptr find(object_ptr const s, object_ptr const key) { - assert(s); auto const nil(obj::nil::nil_const()); - if(s == nil) + if(s == nullptr || s == nil) { return nil; } @@ -703,8 +700,7 @@ namespace jank::runtime native_bool contains(object_ptr const s, object_ptr const key) { - assert(s); - if(s == obj::nil::nil_const()) + if(s == nullptr || s == obj::nil::nil_const()) { return false; } @@ -811,9 +807,8 @@ namespace jank::runtime else if constexpr(behavior::seqable) { native_integer i{}; - for(auto it(typed_o->fresh_seq()); it != obj::nil::nil_const(); it = next_in_place(it), ++i) + for(auto it(typed_o->fresh_seq()); it != nullptr; it = next_in_place(it), ++i) { - assert(it); if(i == index) { return it->first(); @@ -852,9 +847,8 @@ namespace jank::runtime else if constexpr(behavior::seqable) { native_integer i{}; - for(auto it(typed_o->fresh_seq()); !is_nil(it); it = next_in_place(it), ++i) + for(auto it(typed_o->fresh_seq()); it != nullptr; it = next_in_place(it), ++i) { - assert(it); if(i == index) { return it->first(); @@ -872,7 +866,7 @@ namespace jank::runtime object_ptr peek(object_ptr const o) { - if(is_nil(o)) + if(o == obj::nil::nil_const()) { return o; } @@ -944,9 +938,8 @@ namespace jank::runtime } return visit_seqable( [](auto const typed_args, util::string_builder &buff) -> native_persistent_string { - for(auto it(typed_args->fresh_seq()); !is_nil(it); it = it->next_in_place()) + for(auto it(typed_args->fresh_seq()); it != nullptr; it = it->next_in_place()) { - assert(it); auto const fst(it->first()); if(is_nil(fst)) { @@ -985,8 +978,7 @@ namespace jank::runtime size_t sequence_length(object_ptr const s, size_t const max) { - assert(s); - if(is_nil(s)) + if(s == nullptr) { return 0; } @@ -995,16 +987,19 @@ namespace jank::runtime [&](auto const typed_s) -> size_t { using T = typename decltype(typed_s)::value_type; - if constexpr(behavior::countable) + if constexpr(std::same_as) + { + return 0; + } + else if constexpr(behavior::countable) { return typed_s->count(); } else if constexpr(behavior::seqable) { size_t length{ 0 }; - for(auto i(typed_s->fresh_seq()); !is_nil(i) && length < max; i = next_in_place(i)) + for(auto i(typed_s->fresh_seq()); i != nullptr && length < max; i = next_in_place(i)) { - assert(i); ++length; } return length; @@ -1029,18 +1024,29 @@ namespace jank::runtime [](auto const typed_l, object_ptr const r) -> native_bool { return visit_seqable( [](auto const typed_r, auto const typed_l) -> native_bool { - auto seq(typed_r->fresh_seq()); - for(auto it(typed_l->fresh_seq()); !is_nil(it); - it = it->next_in_place(), seq = seq->next_in_place()) + auto r_it(typed_r->fresh_seq()); + auto l_it(typed_l->fresh_seq()); + if(!r_it) + { + return l_it == nullptr; + } + if(!l_it) { - assert(it); - assert(seq); - if(is_nil(seq) || !runtime::equal(it->first(), seq->first())) + return false; + } + + for(; l_it != nullptr; l_it = l_it->next_in_place(), r_it = r_it->next_in_place()) + { + if(!r_it) + { + return false; + } + if(!runtime::equal(l_it->first(), r_it->first())) { return false; } } - return is_nil(seq); + return r_it == nullptr; }, r, typed_l); @@ -1054,9 +1060,8 @@ namespace jank::runtime return visit_seqable( [](auto const typed_coll, object_ptr const f, object_ptr const init) -> object_ptr { object_ptr res{ init }; - for(auto it(typed_coll->fresh_seq()); !is_nil(it); it = it->next_in_place()) + for(auto it(typed_coll->fresh_seq()); it != nullptr; it = it->next_in_place()) { - assert(it); res = dynamic_call(f, res, it->first()); if(res->type == object_type::reduced) { @@ -1124,7 +1129,7 @@ namespace jank::runtime if constexpr(behavior::chunkable) { - return typed_o->chunked_next(); + return typed_o->chunked_next() ?: obj::nil::nil_const(); } { throw std::runtime_error{ fmt::format("not chunkable: {}", typed_o->to_string()) }; @@ -1186,9 +1191,8 @@ namespace jank::runtime return visit_seqable( [](auto const typed_coll) -> object_ptr { native_vector vec; - for(auto it(typed_coll->fresh_seq()); !is_nil(it); it = it->next_in_place()) + for(auto it(typed_coll->fresh_seq()); it != nullptr; it = it->next_in_place()) { - assert(it); vec.push_back(it->first()); } @@ -1215,9 +1219,8 @@ namespace jank::runtime return visit_seqable( [](auto const typed_coll) -> object_ptr { native_vector vec; - for(auto it(typed_coll->fresh_seq()); !is_nil(it); it = it->next_in_place()) + for(auto it(typed_coll->fresh_seq()); it != nullptr; it = it->next_in_place()) { - assert(it); vec.push_back(it->first()); } From 5a08204068b37bc487054ce5ed28360bb59a8b14 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:50:36 -0600 Subject: [PATCH 29/48] [skip ci] --- .../src/cpp/jank/runtime/obj/chunked_cons.cpp | 21 +++++++++-------- .../src/cpp/jank/runtime/obj/cons.cpp | 23 ++++++++++--------- .../obj/detail/base_persistent_map.cpp | 10 ++++---- .../detail/base_persistent_map_sequence.cpp | 12 ++++------ 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp index 28caaacd1..6dc12cd33 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp @@ -11,19 +11,17 @@ namespace jank::runtime::obj { chunked_cons::chunked_cons(object_ptr const head, object_ptr const tail) : head{ head } - , tail{ tail } + , tail{ tail == nil::nil_const() ? nullptr : tail } { assert(head); - assert(tail); } chunked_cons::chunked_cons(object_ptr const meta, object_ptr const head, object_ptr const tail) : head{ head } - , tail{ tail } + , tail{ tail == nil::nil_const() ? nullptr : tail } , meta{ meta } { assert(head); - assert(tail); assert(meta); } @@ -81,9 +79,9 @@ namespace jank::runtime::obj static chunked_cons_ptr next_in_place_non_chunked(chunked_cons_ptr const o) { - if(o->tail == nil::nil_const()) + if(!o->tail) { - return nil::nil_const(); + return nullptr; } return visit_object( @@ -94,6 +92,10 @@ namespace jank::runtime::obj { o->head = typed_tail->first(); o->tail = typed_tail->next(); + if(o->tail == nil::nil_const()) + { + o->tail = nullptr; + } return o; } else @@ -157,16 +159,15 @@ namespace jank::runtime::obj return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != nil::nil_const(); + for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - assert(it); - if(seq == nil::nil_const() || !runtime::equal(it->first(), seq->first())) + if(seq == nullptr || !runtime::equal(it, seq->first())) { return false; } } - return seq == nil::nil_const(); + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp index e82737384..74f2f0994 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp @@ -9,10 +9,9 @@ namespace jank::runtime::obj { cons::cons(object_ptr const head, object_ptr const tail) : head{ head } - , tail{ tail } + , tail{ tail == nil::nil_const() ? nullptr : tail } { assert(head); - assert(tail); } cons_ptr cons::seq() const @@ -32,9 +31,9 @@ namespace jank::runtime::obj object_ptr cons::next() const { - if(tail == nil::nil_const()) + if(!tail) { - return nil::nil_const(); + return nullptr; } return runtime::seq(tail); @@ -42,9 +41,9 @@ namespace jank::runtime::obj cons_ptr cons::next_in_place() { - if(tail == nil::nil_const()) + if(!tail) { - return nil::nil_const(); + return nullptr; } visit_object( @@ -55,6 +54,10 @@ namespace jank::runtime::obj { head = typed_tail->first(); tail = typed_tail->next(); + if(tail == nil::nil_const()) + { + tail = nullptr; + } } else { @@ -71,17 +74,15 @@ namespace jank::runtime::obj return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != nil::nil_const(); + for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - assert(it); - assert(seq); - if(seq == nil::nil_const() || !runtime::equal(it->first(), seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nil::nil_const(); + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp index e724e0d85..fc69d27ec 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map.cpp @@ -28,11 +28,9 @@ namespace jank::runtime::obj::detail for(auto const &entry : static_cast(this)->data) { - auto const found(typed_o->get_entry(entry.first)); // alternatively use get(key,fallback) + auto const found(typed_o->contains(entry.first)); - if(found == obj::nil::nil_const() - || !runtime::equal(entry.second, - expect_object(found)->data[1])) + if(!found || !runtime::equal(entry.second, typed_o->get(entry.first))) { return false; } @@ -131,7 +129,7 @@ namespace jank::runtime::obj::detail { if(static_cast(this)->data.empty()) { - return obj::nil::nil_const(); + return nullptr; } return make_box(static_cast(this), static_cast(this)->data.begin(), @@ -143,7 +141,7 @@ namespace jank::runtime::obj::detail { if(static_cast(this)->data.empty()) { - return obj::nil::nil_const(); + return nullptr; } return make_box(static_cast(this), static_cast(this)->data.begin(), diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp index 740d0f7e2..373e7c5ce 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp @@ -20,17 +20,15 @@ namespace jank::runtime::obj::detail return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != obj::nil::nil_const(); + for(auto it(fresh_seq()); it != nullptr; it = it->next_in_place(), seq = seq->next_in_place()) { - assert(it); - assert(seq); - if(seq == obj::nil::nil_const() || !runtime::equal(it->first(), seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); @@ -133,7 +131,7 @@ namespace jank::runtime::obj::detail if(n == end) { - return obj::nil::nil_const(); + return nullptr; } return make_box(coll, n, end); @@ -146,7 +144,7 @@ namespace jank::runtime::obj::detail if(begin == end) { - return obj::nil::nil_const(); + return nullptr; } return static_cast(this); From e9c761f417673085915a4d04e0ecbb696815d0f6 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:51:45 -0600 Subject: [PATCH 30/48] [skip ci] --- .../cpp/jank/runtime/obj/detail/iterator_sequence.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp index 532af3def..d28e7255c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp @@ -34,13 +34,12 @@ namespace jank::runtime::obj::detail auto seq(typed_o->fresh_seq()); for(auto it(begin); it != end; ++it, seq = seq->next_in_place()) { - assert(seq); - if(seq == obj::nil::nil_const() || !runtime::equal(*it, seq->first())) + if(seq == nullptr || !runtime::equal(*it, seq->first())) { return false; } } - return seq == obj::nil::nil_const(); + return seq == nullptr; }, []() { return false; }, &o); @@ -106,7 +105,7 @@ namespace jank::runtime::obj::detail if(n == end) { - return obj::nil::nil_const(); + return nullptr; } return make_box(coll, n, end, size); @@ -119,7 +118,7 @@ namespace jank::runtime::obj::detail if(begin == end) { - return obj::nil::nil_const(); + return nullptr; } return static_cast(this); From a695a90c6397bf0d64519befa4cf3447b1b11c70 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:52:45 -0600 Subject: [PATCH 31/48] [skip ci] --- .../src/cpp/jank/runtime/obj/integer_range.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp index 0f9dbd1a6..a46a6539d 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp @@ -134,17 +134,15 @@ namespace jank::runtime::obj [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); /* TODO: This is common code; can it be shared? */ - for(auto it(fresh_seq()); it != obj::nil::nil_const(); + for(auto it(fresh_seq()); it != nullptr; it = it->next_in_place(), seq = seq->next_in_place()) { - assert(it); - assert(seq); - if(seq == obj::nil::nil_const() || !runtime::equal(it->first(), seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == obj::nil::nil_const(); + return seq == nullptr; }, []() { return false; }, &o); From 31216fc6a908ca2a79883e20424be1d8a2870645 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:54:05 -0600 Subject: [PATCH 32/48] [skip ci] --- .../src/cpp/jank/runtime/obj/integer_range.cpp | 4 ++-- compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp index a46a6539d..a827a29d7 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp @@ -108,7 +108,7 @@ namespace jank::runtime::obj { if(count() <= 1) { - return obj::nil::nil_const(); + return nullptr; } return make_box(make_box(add(start, step)), end, step, bounds_check); } @@ -117,7 +117,7 @@ namespace jank::runtime::obj { if(count() <= 1) { - return obj::nil::nil_const(); + return nullptr; } start = make_box(add(start, step)); return this; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp index 3ac4f3fbb..f8b812b30 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp @@ -61,17 +61,15 @@ namespace jank::runtime::obj return visit_seqable( [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); - for(auto it(fresh_seq()); it != obj::nil::nil_const(); + for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - assert(it); - assert(seq); - if(seq == obj::nil::nil_const() || !runtime::equal(it->first(), seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == obj::nil::nil_const(); + return seq == nullptr; }, []() { return false; }, &o); From e8fc0b5bed676a59befc92ea0dccd635bb835ef6 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:57:49 -0600 Subject: [PATCH 33/48] [skip ci] --- .../cpp/jank/runtime/obj/lazy_sequence.cpp | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp index c158a6032..8cce7f416 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp @@ -20,24 +20,22 @@ namespace jank::runtime::obj : fn{ fn } , sequence{ sequence } { - assert(sequence); } lazy_sequence_ptr lazy_sequence::seq() const { resolve_seq(); - return sequence != nil::nil_const() ? this : nil::nil_const(); + return sequence ? this : nullptr; } lazy_sequence_ptr lazy_sequence::fresh_seq() const { resolve_seq(); - if(sequence == nil::nil_const()) + if(!sequence) { - return nil::nil_const(); + return nullptr; } auto const s(runtime::fresh_seq(sequence)); - assert(s); assert(s != nil::nil_const()); return make_box(nullptr, s); } @@ -45,28 +43,36 @@ namespace jank::runtime::obj object_ptr lazy_sequence::first() const { resolve_seq(); - return runtime::first(sequence); + if(sequence) + { + return runtime::first(sequence); + } + return nil::nil_const(); } lazy_sequence_ptr lazy_sequence::next() const { resolve_seq(); - auto const n(runtime::next(sequence)); - assert(n); - if(n == nil::nil_const()) + if(sequence) { - return nil::nil_const(); + auto const n(runtime::next(sequence)); + if(n == nil::nil_const()) + { + return nullptr; + } + return make_box(nullptr, n); } - return make_box(nullptr, n); + return nullptr; } lazy_sequence_ptr lazy_sequence::next_in_place() { assert(sequence); auto const n(runtime::next_in_place(sequence)); + assert(n); if(n == nil::nil_const()) { - return nil::nil_const(); + return nullptr; } sequence = n; return this; @@ -95,8 +101,7 @@ namespace jank::runtime::obj native_hash lazy_sequence::to_hash() const { auto const s(seq()); - assert(s); - if(s == nil::nil_const()) + if(!s) { return 1; } @@ -106,7 +111,7 @@ namespace jank::runtime::obj cons_ptr lazy_sequence::conj(object_ptr const head) const { resolve_seq(); - return make_box(head, sequence != nil::nil_const() ? this : nil::nil_const()); + return make_box(head, sequence ? this : nullptr); } object_ptr lazy_sequence::resolve_fn() const @@ -141,13 +146,12 @@ namespace jank::runtime::obj if(lazy) { sequence = runtime::seq(lazy); - } - else - { - sequence = obj::nil::nil_const(); + if(sequence == nil::nil_const()) + { + sequence = nullptr; + } } } - assert(sequence); return sequence; } From 6e26023d14f025bc3f81046e0c4380c349121b72 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 01:59:38 -0600 Subject: [PATCH 34/48] [skip ci] --- .../src/cpp/jank/runtime/obj/multi_function.cpp | 17 ++++++----------- .../jank/runtime/obj/native_array_sequence.cpp | 4 ++-- .../jank/runtime/obj/native_vector_sequence.cpp | 10 +++++----- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp index 3de3d5e7c..c0a5309d3 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp @@ -267,10 +267,9 @@ namespace jank::runtime::obj }; for(auto it(fresh_seq(dynamic_call(parents, hierarchy, y))); - it != nil::nil_const(); + it != nullptr; it = next_in_place(it)) { - assert(it); if(is_preferred(hierarchy, x, first(it))) { return true; @@ -278,10 +277,9 @@ namespace jank::runtime::obj } for(auto it(fresh_seq(dynamic_call(parents, hierarchy, x))); - it != nil::nil_const(); + it != nullptr; it = next_in_place(it)) { - assert(it); if(is_preferred(hierarchy, first(it), y)) { return true; @@ -342,19 +340,16 @@ namespace jank::runtime::obj object_ptr best_value{ nil::nil_const() }; persistent_vector_sequence_ptr best_entry{}; - for(auto it(fresh_seq(method_table)); it != nil::nil_const(); it = it->next_in_place()) + for(auto it(fresh_seq(method_table)); it != nullptr; it = it->next_in_place()) { - assert(it); - auto const entry(it->first()->seq()); - assert(entry); - assert(entry != nil::nil_const()); - auto const entry_key(entry->first()); + auto const entry(it->first()); + auto const entry_key(entry->seq()->first()); if(is_a(cached_hierarchy, dispatch_val, entry_key)) { if(best_entry == nullptr || is_dominant(cached_hierarchy, entry_key, best_entry->first())) { - best_entry = entry; + best_entry = entry->seq(); } if(!is_dominant(cached_hierarchy, best_entry->first(), entry_key)) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp index c250416fc..dc38e595e 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp @@ -84,7 +84,7 @@ namespace jank::runtime::obj if(size <= n) { - return nil::nil_const(); + return nullptr; } return make_box(arr, n, size); @@ -96,7 +96,7 @@ namespace jank::runtime::obj if(size <= index) { - return nil::nil_const(); + return nullptr; } return this; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp index f3fe5d80a..925b21d1d 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp @@ -65,12 +65,12 @@ namespace jank::runtime::obj /* behavior::seqable */ native_vector_sequence_ptr native_vector_sequence::seq() { - return data.empty() ? nil::nil_const() : this; + return data.empty() ? nullptr : this; } native_vector_sequence_ptr native_vector_sequence::fresh_seq() const { - return data.empty() ? nil::nil_const() : make_box(data, index); + return data.empty() ? nullptr : make_box(data, index); } /* behavior::countable */ @@ -93,7 +93,7 @@ namespace jank::runtime::obj if(n == data.size()) { - return nil::nil_const(); + return nullptr; } return make_box(data, n); @@ -105,7 +105,7 @@ namespace jank::runtime::obj if(index == data.size()) { - return nil::nil_const(); + return nullptr; } return this; @@ -113,7 +113,7 @@ namespace jank::runtime::obj cons_ptr native_vector_sequence::conj(object_ptr const head) { - return make_box(head, data.empty() ? nil::nil_const() : this); + return make_box(head, data.empty() ? nullptr : this); } native_vector_sequence_ptr native_vector_sequence::with_meta(object_ptr const m) const From 02d217d6b51d62d478f2ef61a6b9c4e9d1898726 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:05:36 -0600 Subject: [PATCH 35/48] [skip ci] --- .../cpp/jank/runtime/obj/persistent_hash_map.cpp | 6 ++---- .../cpp/jank/runtime/obj/persistent_hash_set.cpp | 5 ++--- .../src/cpp/jank/runtime/obj/persistent_list.cpp | 13 ++++++++----- .../jank/runtime/obj/persistent_sorted_map.cpp | 6 ++---- .../jank/runtime/obj/persistent_sorted_set.cpp | 5 ++--- .../cpp/jank/runtime/obj/persistent_string.cpp | 2 +- .../runtime/obj/persistent_string_sequence.cpp | 4 ++-- .../cpp/jank/runtime/obj/persistent_vector.cpp | 13 +++++-------- .../src/cpp/jank/runtime/obj/range.cpp | 15 +++++++++------ 9 files changed, 33 insertions(+), 36 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp index c46644894..d5a2c5b8e 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_map.cpp @@ -52,13 +52,11 @@ namespace jank::runtime::obj return make_box(visit_seqable( [](auto const typed_seq) -> persistent_hash_map::value_type { runtime::detail::native_transient_hash_map transient; - for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) { - assert(it); auto const key(it->first()); it = runtime::next_in_place(it); - assert(it); - if(it == nil::nil_const()) + if(!it) { throw std::runtime_error{ fmt::format("Odd number of elements: {}", typed_seq->to_string()) }; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp index 25ccd48fb..18b3d5599 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_hash_set.cpp @@ -37,9 +37,8 @@ namespace jank::runtime::obj return make_box(visit_seqable( [](auto const typed_seq) -> persistent_hash_set::value_type { runtime::detail::native_transient_hash_set transient; - for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) { - assert(it); transient.insert(it->first()); } return transient.persistent(); @@ -109,7 +108,7 @@ namespace jank::runtime::obj { if(data.empty()) { - return nil::nil_const(); + return nullptr; } return make_box(this, data.begin(), data.end(), data.size()); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp index 2e992da6d..f85b4a5eb 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp @@ -22,7 +22,11 @@ namespace jank::runtime::obj persistent_list_ptr persistent_list::create(object_ptr const s) { - assert(s); + if(s == nullptr) + { + return make_box(); + } + return visit_object( [](auto const typed_s) -> persistent_list_ptr { using T = typename decltype(typed_s)::value_type; @@ -30,9 +34,8 @@ namespace jank::runtime::obj if constexpr(behavior::sequenceable || std::same_as) { native_vector v; - for(auto i(typed_s->fresh_seq()); i != nil::nil_const(); i = runtime::next_in_place(i)) + for(auto i(typed_s->fresh_seq()); i != nullptr; i = runtime::next_in_place(i)) { - assert(i); v.emplace_back(i->first()); } return make_box( @@ -90,7 +93,7 @@ namespace jank::runtime::obj { if(data.empty()) { - return nil::nil_const(); + return nullptr; } return make_box(this, data.begin(), data.end(), data.size()); } @@ -121,7 +124,7 @@ namespace jank::runtime::obj { if(data.size() < 2) { - return nil::nil_const(); + return nullptr; } return make_box(this, ++data.begin(), data.end(), data.size() - 1); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp index 27a58dc65..e037e1959 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_map.cpp @@ -40,13 +40,11 @@ namespace jank::runtime::obj if constexpr(behavior::seqable) { runtime::detail::native_transient_sorted_map transient; - for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) { - assert(it); auto const key(it->first()); it = runtime::next_in_place(it); - assert(it); - if(it == nil::nil_const()) + if(!it) { throw std::runtime_error{ fmt::format("Odd number of elements: {}", typed_seq->to_string()) }; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp index 4a4477e57..9f59f1542 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_sorted_set.cpp @@ -32,9 +32,8 @@ namespace jank::runtime::obj return make_box(visit_seqable( [](auto const typed_seq) -> persistent_sorted_set::value_type { runtime::detail::native_transient_sorted_set transient; - for(auto it(typed_seq->fresh_seq()); it != nil::nil_const(); it = runtime::next_in_place(it)) + for(auto it(typed_seq->fresh_seq()); it != nullptr; it = runtime::next_in_place(it)) { - assert(it); transient.insert_v(it->first()); } return transient.persistent(); @@ -104,7 +103,7 @@ namespace jank::runtime::obj { if(data.empty()) { - return nil::nil_const(); + return nullptr; } return make_box(this, data.begin(), data.end(), data.size()); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp index 17bf31514..549dcaf5f 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp @@ -163,7 +163,7 @@ namespace jank::runtime::obj { if(data.empty()) { - return nil::nil_const(); + return nullptr; } return make_box(const_cast(this)); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp index 7b63a4392..8ebf7b4e8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp @@ -79,7 +79,7 @@ namespace jank::runtime::obj if(n == str->data.size()) { - return nil::nil_const(); + return nullptr; } return make_box(str, n); @@ -91,7 +91,7 @@ namespace jank::runtime::obj if(index == str->data.size()) { - return nil::nil_const(); + return nullptr; } return this; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp index e5d7f4021..941f5d3e4 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp @@ -34,8 +34,7 @@ namespace jank::runtime::obj persistent_vector_ptr persistent_vector::create(object_ptr const s) { - assert(s); - if(s == nil::nil_const()) + if(s == nullptr) { return make_box(); } @@ -47,9 +46,8 @@ namespace jank::runtime::obj if constexpr(behavior::sequenceable) { runtime::detail::native_transient_vector v; - for(auto i(typed_s->fresh_seq()); i != nil::nil_const(); i = runtime::next_in_place(i)) + for(auto i(typed_s->fresh_seq()); i != nullptr; i = runtime::next_in_place(i)) { - assert(i); v.push_back(i->first()); } return make_box(v.persistent()); @@ -99,15 +97,14 @@ namespace jank::runtime::obj { size_t i{}; auto e(typed_o->fresh_seq()) - for(; e != nil::nil_const() && i < data.size(); e = e->next_in_place(), ++i) + for(; e != nullptr && i < data.size(); e = e->next_in_place(), ++i) { - assert(e); if(!runtime::equal(data[i], e->first())) { return false; } } - return e == nil::nil_const() && i == data.size(); + return e == nullptr && i == data.size(); } else { @@ -188,7 +185,7 @@ namespace jank::runtime::obj { if(data.empty()) { - return nil::nil_const(); + return nullptr; } return make_box(const_cast(this)); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 63fc24c23..1615dc3fb 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -192,6 +192,10 @@ namespace jank::runtime::obj range_ptr range::chunked_next() const { force_chunk(); + if(!chunk_next) + { + return nullptr; + } return chunk_next; } @@ -206,17 +210,15 @@ namespace jank::runtime::obj [this](auto const typed_o) { auto seq(typed_o->fresh_seq()); /* TODO: This is common code; can it be shared? */ - for(auto it(fresh_seq()); it != nil::nil_const(); + for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - assert(it); - assert(seq); - if(seq == nil::nil_const() || !runtime::equal(it->first(), seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return seq == nil::nil_const(); + return seq == nullptr; }, []() { return false; }, &o); @@ -245,7 +247,8 @@ namespace jank::runtime::obj range_ptr range::with_meta(object_ptr const m) const { auto const meta(behavior::detail::validate_meta(m)); - auto ret(make_box(start, end, step, bounds_check)); + auto ret(fresh_seq()); + assert(ret); ret->meta = meta; return ret; } From 4979e26d2ad7b5808c99c934a0f819d0cd09f78d Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:09:46 -0600 Subject: [PATCH 36/48] [skip ci] --- .../include/cpp/jank/runtime/obj/range.hpp | 27 ++++++++++--------- .../jank/runtime/obj/persistent_vector.cpp | 2 +- .../src/cpp/jank/runtime/obj/range.cpp | 1 - 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp index c2ce5ed6d..a5c91451c 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp @@ -21,19 +21,20 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(object_ptr, object_ptr); - //range() = default; - //range(range &&) noexcept = default; - //range(range const &) = default; - //range(object_ptr end); - //range(object_ptr start, object_ptr end); - //range(object_ptr start, object_ptr end, object_ptr step); - //range(object_ptr start, object_ptr end, object_ptr step, bounds_check_t bounds_check); - //range(object_ptr start, - // object_ptr end, - // object_ptr step, - // bounds_check_t bounds_check, - // obj::array_chunk_ptr chunk, - // range_ptr chunk_next); + /* Constructors are only to be used in range.cpp. Prefer range::create. */ + range() = default; + range(range &&) noexcept = default; + range(range const &) = default; + range(object_ptr end); + range(object_ptr start, object_ptr end); + range(object_ptr start, object_ptr end, object_ptr step); + range(object_ptr start, object_ptr end, object_ptr step, bounds_check_t bounds_check); + range(object_ptr start, + object_ptr end, + object_ptr step, + bounds_check_t bounds_check, + obj::array_chunk_ptr chunk, + range_ptr chunk_next); static object_ptr create(object_ptr end); static object_ptr create(object_ptr start, object_ptr end); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp index 941f5d3e4..5cf8d752e 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp @@ -96,7 +96,7 @@ namespace jank::runtime::obj if constexpr(behavior::sequential) { size_t i{}; - auto e(typed_o->fresh_seq()) + auto e(typed_o->fresh_seq()); for(; e != nullptr && i < data.size(); e = e->next_in_place(), ++i) { if(!runtime::equal(data[i], e->first())) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 1615dc3fb..ab1e0ce59 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -20,7 +20,6 @@ namespace jank::runtime::obj return lte(val, end); } - /* Never use constructors outside of this file. Use range::create. */ range::range(object_ptr const end) : start{ make_box(0) } , end{ end } From 5e1e9c36ea10cecf72712da914cba937abfcb395 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:10:47 -0600 Subject: [PATCH 37/48] [skip ci] --- compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp index f8b812b30..2395a9888 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp @@ -82,13 +82,11 @@ namespace jank::runtime::obj native_persistent_string iterator::to_string() { - /* Runs forever. */ return runtime::to_string(seq()); } native_persistent_string iterator::to_code_string() { - /* Runs forever. */ return runtime::to_code_string(seq()); } From fc1ff00cd8519063208ebd53dff106392b79eb88 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:12:50 -0600 Subject: [PATCH 38/48] [skip ci] --- .../include/cpp/jank/runtime/core/to_string.hpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp b/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp index b6c8d1f15..dfca04f7e 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/to_string.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace jank::runtime { @@ -49,9 +48,8 @@ namespace jank::runtime buff('('); native_bool needs_space{}; - for(auto i(s->fresh_seq()); i != obj::nil::nil_const(); i = i->next_in_place()) + for(auto i(s->fresh_seq()); i != nullptr; i = i->next_in_place()) { - assert(i); if(needs_space) { buff(' '); @@ -106,9 +104,8 @@ namespace jank::runtime buff('('); native_bool needs_space{}; - for(auto i(s->fresh_seq()); i != obj::nil::nil_const(); i = i->next_in_place()) + for(auto i(s->fresh_seq()); i != nullptr; i = i->next_in_place()) { - assert(i); if(needs_space) { buff(' '); From 6a1919f3fdf0a0bfaf3f39810cf40b62ff8f269d Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:16:45 -0600 Subject: [PATCH 39/48] [skip ci] --- .../src/cpp/jank/runtime/obj/lazy_sequence.cpp | 1 + .../src/cpp/jank/runtime/obj/multi_function.cpp | 4 ++-- .../src/cpp/jank/runtime/obj/native_vector_sequence.cpp | 3 ++- compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp index 8cce7f416..a14c31646 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp @@ -56,6 +56,7 @@ namespace jank::runtime::obj if(sequence) { auto const n(runtime::next(sequence)); + assert(n); if(n == nil::nil_const()) { return nullptr; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp index c0a5309d3..211216613 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp @@ -267,7 +267,7 @@ namespace jank::runtime::obj }; for(auto it(fresh_seq(dynamic_call(parents, hierarchy, y))); - it != nullptr; + it != nullptr && it != nil::nil_const(); it = next_in_place(it)) { if(is_preferred(hierarchy, x, first(it))) @@ -277,7 +277,7 @@ namespace jank::runtime::obj } for(auto it(fresh_seq(dynamic_call(parents, hierarchy, x))); - it != nullptr; + it != nullptr && it != nil::nil_const(); it = next_in_place(it)) { if(is_preferred(hierarchy, first(it), y)) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp index 925b21d1d..2dc258503 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp @@ -119,7 +119,8 @@ namespace jank::runtime::obj native_vector_sequence_ptr native_vector_sequence::with_meta(object_ptr const m) const { auto const meta(behavior::detail::validate_meta(m)); - auto ret(make_box(data, index)); + auto ret(fresh_seq()); + assert(ret); ret->meta = meta; return ret; } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp index 5fdc30046..dacedc6fd 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp @@ -80,12 +80,12 @@ namespace jank::runtime::obj nil_ptr nil::seq() { - return this; + return nullptr; } nil_ptr nil::fresh_seq() const { - return this; + return nullptr; } nil_ptr nil::first() const @@ -95,11 +95,11 @@ namespace jank::runtime::obj nil_ptr nil::next() const { - return this; + return nullptr; } nil_ptr nil::next_in_place() { - return this; + return nullptr; } } From 10f479805217905a30ddcd173629158ec44c1516 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:18:59 -0600 Subject: [PATCH 40/48] [skip ci] --- compiler+runtime/src/cpp/jank/runtime/obj/range.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index ab1e0ce59..b70fe0a60 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -6,8 +6,6 @@ #include #include -#include //temp - namespace jank::runtime::obj { static native_bool positive_step_bounds_check(object_ptr const val, object_ptr const end) @@ -68,7 +66,6 @@ namespace jank::runtime::obj , chunk{ chunk } , chunk_next{ chunk_next } { - assert(chunk_next); } object_ptr range::create(object_ptr const end) From bdecaf0cacea55afa4b700701148ac9625a5af42 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:20:56 -0600 Subject: [PATCH 41/48] [skip ci] --- compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp index 0cf41f3c1..9f408fdaf 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp @@ -19,6 +19,7 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(integer_ptr, integer_ptr); + /* Constructors are only to be used in range.cpp. Prefer range::create. */ integer_range() = default; integer_range(integer_range &&) noexcept = default; integer_range(integer_range const &) = default; From 2dc83fe23354b35b4ff81586a6c9ea9966820a0c Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:32:55 -0600 Subject: [PATCH 42/48] wip --- compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp index f160ba32e..c409a2476 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -26,11 +26,10 @@ namespace jank::runtime::obj CHECK( !equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(0), make_box(1)))); - //TODO test https://github.com/jank-lang/jank/issues/251 , https://github.com/jank-lang/jank/issues/250 - //clojure.core=> (repeat 0 0) - //() - //clojure.core=> (seq (repeat 0 0)) - //nil + CHECK( + equal(repeat::create(make_box(0), make_box(0)), persistent_list::empty())); + CHECK( + equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); } TEST_CASE("seq") { From 99728fa1a642405aa6a4ff5f78377a6b9cf4d8b0 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:33:07 -0600 Subject: [PATCH 43/48] [skip ci] fmt --- compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp index c409a2476..3d7bec719 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -26,10 +26,8 @@ namespace jank::runtime::obj CHECK( !equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(0), make_box(1)))); - CHECK( - equal(repeat::create(make_box(0), make_box(0)), persistent_list::empty())); - CHECK( - equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); + CHECK(equal(repeat::create(make_box(0), make_box(0)), persistent_list::empty())); + CHECK(equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); } TEST_CASE("seq") { From 0b8c535e3bbca81b8f0d6080ab1efc058015bfcb Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:34:38 -0600 Subject: [PATCH 44/48] wip --- .../cpp/jank/runtime/obj/lazy_sequence.cpp | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp deleted file mode 100644 index be7a635a8..000000000 --- a/compiler+runtime/test/cpp/jank/runtime/obj/lazy_sequence.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -#include -#include - -/* This must go last; doctest and glog both define CHECK and family. */ -#include - -namespace jank::runtime::obj -{ - TEST_SUITE("lazy_sequence") - { - TEST_CASE("equal") - { - //CHECK(equal(make_box(make_box(convert_function([]() { return nullptr; }))), - // make_box(make_box(convert_function([]() { return nullptr; }))))); - } - } -} From dd3649e8fdf73f52556dc2e4083d0458391c5aa0 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 02:36:34 -0600 Subject: [PATCH 45/48] wip --- compiler+runtime/CMakeLists.txt | 1 - compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler+runtime/CMakeLists.txt b/compiler+runtime/CMakeLists.txt index 2d3cdbceb..f7be9303a 100644 --- a/compiler+runtime/CMakeLists.txt +++ b/compiler+runtime/CMakeLists.txt @@ -457,7 +457,6 @@ if(jank_tests) test/cpp/jank/runtime/obj/persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/persistent_vector.cpp - test/cpp/jank/runtime/obj/lazy_sequence.cpp test/cpp/jank/runtime/obj/range.cpp test/cpp/jank/runtime/obj/integer_range.cpp test/cpp/jank/runtime/obj/repeat.cpp diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp index 9f408fdaf..e39f79b45 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp @@ -19,7 +19,7 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(integer_ptr, integer_ptr); - /* Constructors are only to be used in range.cpp. Prefer range::create. */ + /* Constructors are only to be used in integer_range.cpp. Prefer range::create. */ integer_range() = default; integer_range(integer_range &&) noexcept = default; integer_range(integer_range const &) = default; From 674a8e980ce3b7f0bfa0606925eeea1428ee5286 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 13:45:13 -0600 Subject: [PATCH 46/48] [skip ci] revert equal null check --- compiler+runtime/src/cpp/jank/runtime/core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/core.cpp b/compiler+runtime/src/cpp/jank/runtime/core.cpp index 3e83e95b4..1bbad2af8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core.cpp @@ -245,7 +245,7 @@ namespace jank::runtime } else if(!rhs) { - return false; + return !lhs; } return visit_object([&](auto const typed_lhs) { return typed_lhs->equal(*rhs); }, lhs); From d754b74ef180d73de6a888980358972a6c68af89 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 13:52:16 -0600 Subject: [PATCH 47/48] [skip ci] fix first half of chunked cons --- compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp index 6dc12cd33..dde61c883 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp @@ -162,7 +162,7 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } From 613209975a376c7e752767b4774aae1602c274b7 Mon Sep 17 00:00:00 2001 From: Ambrose Bonnaire-Sergeant Date: Sat, 22 Feb 2025 14:24:55 -0600 Subject: [PATCH 48/48] [skip ci] add bang to next-in-place, fix comments --- .../cpp/jank/runtime/behavior/seqable.hpp | 8 +++---- .../cpp/jank/runtime/obj/integer_range.hpp | 2 +- .../include/cpp/jank/runtime/obj/range.hpp | 2 +- .../src/cpp/clojure/core_native.cpp | 2 +- .../src/cpp/jank/runtime/core/seq.cpp | 23 ++++--------------- .../src/cpp/jank/runtime/obj/chunked_cons.cpp | 3 +++ compiler+runtime/src/jank/clojure/core.jank | 4 ++-- 7 files changed, 16 insertions(+), 28 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp b/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp index 23a09f011..e75bd1da9 100644 --- a/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/behavior/seqable.hpp @@ -46,16 +46,16 @@ namespace jank::runtime::behavior * Don't do this: * * (let [s (fresh-seq ...) - * s' (-> s next-in-place) - * s'' (-> s next-in-place next-in-place)] + * s' (-> s next-in-place!) + * s'' (-> s next-in-place! next-in-place!)] * ^---- UB!! s' owns seq * ...) * * Do this instead: * * (let [s (fresh-seq ...) - * s' (-> s next-in-place) - * s'' (-> s' next-in-place)] + * s' (-> s next-in-place!) + * s'' (-> s' next-in-place!)] * ^---- OK: seq ownership transferred from s' to s'' * ...) * diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp index e39f79b45..672cf15f8 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp @@ -19,7 +19,7 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(integer_ptr, integer_ptr); - /* Constructors are only to be used in integer_range.cpp. Prefer range::create. */ + /* Constructors are only to be used within integer_range.cpp. Prefer integer_range::create. */ integer_range() = default; integer_range(integer_range &&) noexcept = default; integer_range(integer_range const &) = default; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp index a5c91451c..c8cf228b3 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp @@ -21,7 +21,7 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(object_ptr, object_ptr); - /* Constructors are only to be used in range.cpp. Prefer range::create. */ + /* Constructors are only to be used within range.cpp. Prefer range::create. */ range() = default; range(range &&) noexcept = default; range(range const &) = default; diff --git a/compiler+runtime/src/cpp/clojure/core_native.cpp b/compiler+runtime/src/cpp/clojure/core_native.cpp index ec971e516..fdc268d66 100644 --- a/compiler+runtime/src/cpp/clojure/core_native.cpp +++ b/compiler+runtime/src/cpp/clojure/core_native.cpp @@ -341,7 +341,7 @@ jank_object_ptr jank_load_clojure_core_native() intern_fn("first", static_cast(&first)); intern_fn("second", static_cast(&second)); intern_fn("next", static_cast(&next)); - intern_fn("next-in-place", static_cast(&next_in_place)); + intern_fn("next-in-place!", static_cast(&next_in_place)); intern_fn("rest", static_cast(&rest)); intern_fn("cons", &cons); intern_fn("coll?", &is_collection); diff --git a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp index a6cae170e..06bfd4750 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp @@ -397,6 +397,7 @@ namespace jank::runtime s); } + /* Returns nullptr or a non-empty seq. */ object_ptr next_in_place(object_ptr const s) { return visit_object( @@ -478,21 +479,13 @@ namespace jank::runtime { return make_box(std::in_place, o); } - else if constexpr(behavior::conjable_in_place) - { - return typed_s->conj_in_place(o); - } else if constexpr(behavior::conjable) { return typed_s->conj(o); } - else if constexpr(behavior::seqable) - { - return typed_s->seq()->conj(o); - } else { - throw std::runtime_error{ fmt::format("not seqable: {}", typed_s->to_string()) }; + throw std::runtime_error{ fmt::format("not conjable: {}", typed_s->to_string()) }; } }, s); @@ -521,11 +514,7 @@ namespace jank::runtime [&](auto const typed_m) -> object_ptr { using T = typename decltype(typed_m)::value_type; - if constexpr(behavior::associatively_writable_in_place) - { - return typed_m->assoc_in_place(k, v); - } - else if constexpr(behavior::associatively_writable) + if constexpr(behavior::associatively_writable) { return typed_m->assoc(k, v); } @@ -544,11 +533,7 @@ namespace jank::runtime [&](auto const typed_m) -> object_ptr { using T = typename decltype(typed_m)::value_type; - if constexpr(behavior::associatively_writable_in_place) - { - return typed_m->dissoc_in_place(k); - } - else if constexpr(behavior::associatively_writable) + if constexpr(behavior::associatively_writable) { return typed_m->dissoc(k); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp index dde61c883..23d27c3c7 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp @@ -162,11 +162,14 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { + assert(it != nil::nil_const()); + assert(seq != nil::nil_const()); if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } + assert(seq != nil::nil_const()); return seq == nullptr; }, []() { return false; }, diff --git a/compiler+runtime/src/jank/clojure/core.jank b/compiler+runtime/src/jank/clojure/core.jank index 227a17381..b670286a1 100644 --- a/compiler+runtime/src/jank/clojure/core.jank +++ b/compiler+runtime/src/jank/clojure/core.jank @@ -123,8 +123,8 @@ "Returns a seq of the items after the first. Calls seq on its argument. If there are no more items, returns nil." clojure.core-native/next) -(def next-in-place - clojure.core-native/next-in-place) +(def next-in-place! + clojure.core-native/next-in-place!) (def nnext "Same as (next (next x))" (fn* nnext [o]