Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence equality #249

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
1fc35d5
wip range equality
frenchy64 Feb 7, 2025
bbc06d0
wip
frenchy64 Feb 7, 2025
a059c68
test core::equal
frenchy64 Feb 7, 2025
701d79f
wip
frenchy64 Feb 7, 2025
8a1472e
[skip ci]
frenchy64 Feb 7, 2025
cbd354f
[skip ci] rm
frenchy64 Feb 7, 2025
3727186
[skip ci]
frenchy64 Feb 7, 2025
ddd82ac
tests
frenchy64 Feb 7, 2025
c2da550
wip
frenchy64 Feb 7, 2025
c035ee8
[skip ci]
frenchy64 Feb 7, 2025
4dc1d92
[skip ci]
frenchy64 Feb 7, 2025
b6d8889
wip
frenchy64 Feb 7, 2025
408ed65
wip
frenchy64 Feb 7, 2025
4529d26
fix
frenchy64 Feb 7, 2025
c227006
[skip ci]
frenchy64 Feb 7, 2025
f1d6e2c
fix
frenchy64 Feb 10, 2025
ca229f8
[skip ci]
frenchy64 Feb 10, 2025
3afba55
wip
frenchy64 Feb 10, 2025
c5f2e33
[skip ci]
frenchy64 Feb 10, 2025
2dbbca6
fmt
frenchy64 Feb 10, 2025
d081d74
Merge branch 'main' into sequence-equality
frenchy64 Feb 10, 2025
4819593
Merge branch 'main' into sequence-equality
frenchy64 Feb 13, 2025
fe6f1dd
assert
frenchy64 Feb 13, 2025
2deb82d
Merge branch 'main' into sequence-equality
frenchy64 Feb 22, 2025
c36ca8d
[skip ci]
frenchy64 Feb 22, 2025
acb06a4
wip
frenchy64 Feb 22, 2025
4a1620f
[skip ci]
frenchy64 Feb 22, 2025
b3ffc63
[skip ci]
frenchy64 Feb 22, 2025
8bf2c34
[skip ci] undo
frenchy64 Feb 22, 2025
6b760d1
[skip ci]
frenchy64 Feb 22, 2025
0bbcbc1
[skip ci]
frenchy64 Feb 22, 2025
5a08204
[skip ci]
frenchy64 Feb 22, 2025
e9c761f
[skip ci]
frenchy64 Feb 22, 2025
a695a90
[skip ci]
frenchy64 Feb 22, 2025
31216fc
[skip ci]
frenchy64 Feb 22, 2025
e8fc0b5
[skip ci]
frenchy64 Feb 22, 2025
6e26023
[skip ci]
frenchy64 Feb 22, 2025
02d217d
[skip ci]
frenchy64 Feb 22, 2025
4979e26
[skip ci]
frenchy64 Feb 22, 2025
5e1e9c3
[skip ci]
frenchy64 Feb 22, 2025
fc1ff00
[skip ci]
frenchy64 Feb 22, 2025
6a1919f
[skip ci]
frenchy64 Feb 22, 2025
10f4798
[skip ci]
frenchy64 Feb 22, 2025
bdecaf0
[skip ci]
frenchy64 Feb 22, 2025
2dc83fe
wip
frenchy64 Feb 22, 2025
99728fa
[skip ci] fmt
frenchy64 Feb 22, 2025
0b8c535
wip
frenchy64 Feb 22, 2025
dd3649e
wip
frenchy64 Feb 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler+runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,17 @@ 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/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/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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 integer_range.cpp. Prefer range::create. */
integer_range() = default;
integer_range(integer_range &&) noexcept = default;
integer_range(integer_range const &) = default;
Expand Down
1 change: 1 addition & 0 deletions compiler+runtime/include/cpp/jank/runtime/obj/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +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. */
range() = default;
range(range &&) noexcept = default;
range(range const &) = default;
Expand Down
6 changes: 4 additions & 2 deletions compiler+runtime/src/cpp/clojure/core_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,10 @@ jank_object_ptr jank_load_clojure_core_native()
{
auto const fn(
make_box<obj::jit_function>(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);
}

Expand Down
4 changes: 1 addition & 3 deletions compiler+runtime/src/cpp/jank/read/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ 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 != nullptr; it = next_in_place(next_in_place(it)))
{
auto const kw(it->first());
/* We take the first match, checking for :jank first. If there are duplicates, it doesn't
Expand Down Expand Up @@ -829,8 +829,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);
Expand Down
2 changes: 1 addition & 1 deletion compiler+runtime/src/cpp/jank/runtime/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions compiler+runtime/src/cpp/jank/runtime/core/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ namespace jank::runtime
}
if(!l_it)
{
return r_it == nullptr;
return false;
}

for(; l_it != nullptr; l_it = l_it->next_in_place(), r_it = r_it->next_in_place())
Expand Down Expand Up @@ -1178,12 +1178,12 @@ namespace jank::runtime

object_ptr repeat(object_ptr const val)
{
return make_box<obj::repeat>(val);
return obj::repeat::create(val);
}

object_ptr repeat(object_ptr const n, object_ptr const val)
{
return make_box<obj::repeat>(n, val);
return obj::repeat::create(n, val);
}

object_ptr sort(object_ptr const coll)
Expand Down
2 changes: 1 addition & 1 deletion compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace jank::runtime::obj
return false;
}
}
return true;
return seq == nullptr;
},
[]() { return false; },
&o);
Expand Down
4 changes: 2 additions & 2 deletions compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ namespace jank::runtime::obj::detail
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace jank::runtime::obj::detail
return false;
}
}
return true;
return seq == nullptr;
},
[]() { return false; },
&o);
Expand Down
6 changes: 3 additions & 3 deletions compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace jank::runtime::obj
}
else if(is_zero(step))
{
return make_box<repeat>(make_box<integer>(start));
return repeat::create(make_box<integer>(start));
}
return make_box<integer_range>(start,
end,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -92,6 +92,7 @@ namespace jank::runtime::obj

native_hash iterator::to_hash() const
{
/* Runs forever. */
return hash::ordered(&base);
}

Expand Down
2 changes: 2 additions & 0 deletions compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -69,6 +70,7 @@ namespace jank::runtime::obj
{
assert(sequence);
auto const n(runtime::next_in_place(sequence));
assert(n);
if(n == nil::nil_const())
{
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -120,6 +120,7 @@ namespace jank::runtime::obj
{
auto const meta(behavior::detail::validate_meta(m));
auto ret(fresh_seq());
assert(ret);
ret->meta = meta;
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ namespace jank::runtime::obj

persistent_list_sequence_ptr persistent_list::seq() const
{
if(data.empty())
{
return nullptr;
}
return make_box<persistent_list_sequence>(this, data.begin(), data.end(), data.size());
return fresh_seq();
}

persistent_list_sequence_ptr persistent_list::fresh_seq() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ namespace jank::runtime::obj

persistent_string_sequence_ptr persistent_string::seq() const
{
if(data.empty())
{
return nullptr;
}
return make_box<persistent_string_sequence>(const_cast<persistent_string *>(this));
return fresh_seq();
}

persistent_string_sequence_ptr persistent_string::fresh_seq() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 2 additions & 12 deletions compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,12 @@ namespace jank::runtime::obj
{
size_t i{};
auto e(typed_o->fresh_seq());
for(; e != nullptr; e = e->next_in_place())
for(; e != nullptr && i < data.size(); e = e->next_in_place(), ++i)
{
if(!runtime::equal(data[i], e->first()))
{
return false;
}

if(++i == data.size())
{
e = e->next_in_place();
break;
}
}
return e == nullptr && i == data.size();
}
Expand Down Expand Up @@ -184,11 +178,7 @@ namespace jank::runtime::obj

persistent_vector_sequence_ptr persistent_vector::seq() const
{
if(data.empty())
{
return nullptr;
}
return make_box<persistent_vector_sequence>(const_cast<persistent_vector *>(this));
return fresh_seq();
}

persistent_vector_sequence_ptr persistent_vector::fresh_seq() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions compiler+runtime/src/cpp/jank/runtime/obj/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace jank::runtime::obj
}
/* TODO: Repeat object. */
//else if(is_zero(step))
//{ return make_box<repeat>(start); }
//{ return repeat::create(start); }
return make_box<range>(start,
end,
step,
Expand Down Expand Up @@ -209,12 +209,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);
Expand Down Expand Up @@ -244,6 +244,7 @@ namespace jank::runtime::obj
{
auto const meta(behavior::detail::validate_meta(m));
auto ret(fresh_seq());
assert(ret);
ret->meta = meta;
return ret;
}
Expand Down
7 changes: 4 additions & 3 deletions compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace jank::runtime::obj
: value{ value }
, count{ count }
{
assert(0 < to_int(count));
}

object_ptr repeat::create(object_ptr const value)
Expand Down Expand Up @@ -53,7 +54,7 @@ namespace jank::runtime::obj
{
return this;
}
if(lt(count, make_box(1)))
if(lte(count, make_box(1)))
{
return nullptr;
}
Expand Down Expand Up @@ -88,12 +89,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);
Expand Down
18 changes: 18 additions & 0 deletions compiler+runtime/test/cpp/jank/runtime/core.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <jank/runtime/core.hpp>
#include <jank/runtime/core/make_box.hpp>

/* This must go last; doctest and glog both define CHECK and family. */
#include <doctest/doctest.h>

namespace jank::runtime
{
TEST_SUITE("core runtime")
{
TEST_CASE("equal")
{
CHECK(equal(nullptr, nullptr));
CHECK(!equal(nullptr, make_box(42)));
CHECK(!equal(make_box(42), nullptr));
}
}
}
Loading