Skip to content

Commit

Permalink
Rename set to persistent_set
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed Jan 19, 2024
1 parent a3f98bb commit 24205a4
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ add_library(
src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp
src/cpp/jank/runtime/obj/persistent_array_map.cpp
src/cpp/jank/runtime/obj/persistent_hash_map.cpp
src/cpp/jank/runtime/obj/set.cpp
src/cpp/jank/runtime/obj/persistent_set.cpp
src/cpp/jank/runtime/obj/persistent_string.cpp
src/cpp/jank/runtime/obj/cons.cpp
src/cpp/jank/runtime/obj/range.cpp
Expand Down
6 changes: 3 additions & 3 deletions include/cpp/jank/runtime/erasure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <jank/runtime/obj/symbol.hpp>
#include <jank/runtime/obj/persistent_vector.hpp>
#include <jank/runtime/obj/persistent_list.hpp>
#include <jank/runtime/obj/set.hpp>
#include <jank/runtime/obj/persistent_set.hpp>
#include <jank/runtime/obj/persistent_array_map.hpp>
#include <jank/runtime/obj/persistent_array_map_sequence.hpp>
#include <jank/runtime/obj/persistent_hash_map.hpp>
Expand Down Expand Up @@ -173,9 +173,9 @@ namespace jank::runtime
std::forward<Args>(args)...);
}
break;
case object_type::set:
case object_type::persistent_set:
{
return fn(expect_object<obj::set>(erased), std::forward<Args>(args)...);
return fn(expect_object<obj::persistent_set>(erased), std::forward<Args>(args)...);
}
break;
case object_type::cons:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace jank::runtime
{
template <>
struct static_object<object_type::set> : gc
struct static_object<object_type::persistent_set> : gc
{
using value_type = runtime::detail::native_persistent_set;

Expand Down Expand Up @@ -49,8 +49,11 @@ namespace jank::runtime

native_bool contains(object_ptr o) const;

object base{ object_type::set };
object base{ object_type::persistent_set };
value_type data;
option<object_ptr> meta;
};

using persistent_set = static_object<object_type::persistent_set>;
using persistent_set_ptr = native_box<persistent_set>;
}
4 changes: 2 additions & 2 deletions include/cpp/jank/runtime/obj/persistent_set_sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace jank::runtime
{
namespace obj
{
using set = static_object<object_type::set>;
using set_ptr = native_box<set>;
using persistent_set = static_object<object_type::persistent_set>;
using persistent_set_ptr = native_box<persistent_set>;
}

template <>
Expand Down
2 changes: 1 addition & 1 deletion include/cpp/jank/runtime/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace jank::runtime
persistent_array_map_sequence,
persistent_hash_map,
persistent_hash_map_sequence,
set,
persistent_set,
cons,
range,
iterator,
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/jank/analyze/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ namespace jank::analyze
{
return analyze_map(typed_o, current_frame, expr_type, fn_ctx, needs_box);
}
else if constexpr(std::same_as<T, runtime::obj::set>)
else if constexpr(std::same_as<T, runtime::obj::persistent_set>)
{
return err(error{ "unimplemented analysis: set" });
}
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/jank/codegen/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ namespace jank::codegen
{
return "jank::runtime::obj::persistent_vector_ptr";
}
case jank::runtime::object_type::set:
case jank::runtime::object_type::persistent_set:
{
return "jank::runtime::obj::set_ptr";
return "jank::runtime::obj::persistent_set_ptr";
}
case jank::runtime::object_type::persistent_array_map:
{
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/jank/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ namespace jank::evaluate
}
}
}
else if constexpr(std::same_as<T, runtime::obj::set>)
else if constexpr(std::same_as<T, runtime::obj::persistent_set>)
{
auto const s(expr.arg_exprs.size());
if(s != 1)
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/jank/read/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <jank/runtime/obj/persistent_vector.hpp>
#include <jank/runtime/obj/persistent_list.hpp>
#include <jank/runtime/obj/persistent_array_map.hpp>
#include <jank/runtime/obj/set.hpp>
#include <jank/runtime/obj/persistent_set.hpp>
#include <jank/runtime/obj/symbol.hpp>
#include <jank/runtime/obj/keyword.hpp>
#include <jank/runtime/obj/persistent_string.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/jank/runtime/behavior/callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace jank::runtime
return typed_source->call(a1);
}
}
else if constexpr(std::same_as<T, obj::set> || std::same_as<T, obj::persistent_hash_map>
else if constexpr(std::same_as<T, obj::persistent_set> || std::same_as<T, obj::persistent_hash_map>
|| std::same_as<T, obj::persistent_array_map>
|| std::same_as<T, obj::keyword>)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@

#include <jank/runtime/util.hpp>
#include <jank/runtime/obj/native_function_wrapper.hpp>
#include <jank/runtime/obj/set.hpp>
#include <jank/runtime/obj/persistent_set.hpp>

namespace jank::runtime
{
obj::set::static_object(runtime::detail::native_persistent_set &&d)
obj::persistent_set::static_object(runtime::detail::native_persistent_set &&d)
: data{ std::move(d) }
{
}

obj::set::static_object(runtime::detail::native_persistent_set const &d)
obj::persistent_set::static_object(runtime::detail::native_persistent_set const &d)
: data{ d }
{
}

native_bool obj::set::equal(object const &o) const
native_bool obj::persistent_set::equal(object const &o) const
{
return detail::equal(o, data.begin(), data.end());
}

void obj::set::to_string(fmt::memory_buffer &buff) const
void obj::persistent_set::to_string(fmt::memory_buffer &buff) const
{
return behavior::detail::to_string(data.begin(), data.end(), "#{", '}', buff);
}

native_persistent_string obj::set::to_string() const
native_persistent_string obj::persistent_set::to_string() const
{
fmt::memory_buffer buff;
behavior::detail::to_string(data.begin(), data.end(), "#{", '}', buff);
return native_persistent_string{ buff.data(), buff.size() };
}

/* TODO: Cache this. */
native_hash obj::set::to_hash() const
native_hash obj::persistent_set::to_hash() const
{
return hash::unordered(data.begin(), data.end());
}

obj::persistent_set_sequence_ptr obj::set::seq() const
obj::persistent_set_sequence_ptr obj::persistent_set::seq() const
{
return fresh_seq();
}

obj::persistent_set_sequence_ptr obj::set::fresh_seq() const
obj::persistent_set_sequence_ptr obj::persistent_set::fresh_seq() const
{
if(data.empty())
{
Expand All @@ -54,27 +54,27 @@ namespace jank::runtime
return make_box<obj::persistent_set_sequence>(this, data.begin(), data.end(), data.size());
}

size_t obj::set::count() const
size_t obj::persistent_set::count() const
{
return data.size();
}

object_ptr obj::set::with_meta(object_ptr const m) const
object_ptr obj::persistent_set::with_meta(object_ptr const m) const
{
auto const meta(behavior::detail::validate_meta(m));
auto ret(make_box<obj::set>(data));
auto ret(make_box<obj::persistent_set>(data));
ret->meta = meta;
return ret;
}

obj::set_ptr obj::set::cons(object_ptr const head) const
obj::persistent_set_ptr obj::persistent_set::cons(object_ptr const head) const
{
auto vec(data.insert(head));
auto ret(make_box<obj::set>(std::move(vec)));
auto ret(make_box<obj::persistent_set>(std::move(vec)));
return ret;
}

object_ptr obj::set::call(object_ptr const o) const
object_ptr obj::persistent_set::call(object_ptr const o) const
{
auto const found(data.find(o));
if(!found)
Expand All @@ -84,7 +84,7 @@ namespace jank::runtime
return *found;
}

native_bool obj::set::contains(object_ptr const o) const
native_bool obj::persistent_set::contains(object_ptr const o) const
{
return data.find(o);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/jank/runtime/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ namespace jank::runtime
{
return typed_s->contains(key);
}
if constexpr(std::same_as<S, obj::set>)
if constexpr(std::same_as<S, obj::persistent_set>)
{
return typed_s->contains(key);
}
Expand Down
4 changes: 2 additions & 2 deletions src/jank/clojure/core.jank
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
; Sets.

(defn set? [o]
(native/raw "__value = make_box(#{ o }#->type == object_type::set);"))
(native/raw "__value = make_box(#{ o }#->type == object_type::persistent_set);"))

; Returns a set of the distinct elements of coll.
(defn set [coll]
Expand All @@ -733,7 +733,7 @@
; TODO: Transient
(reduce* (fn [acc e]
(conj acc e))
(native/raw "__value = make_box<obj::set>();")
(native/raw "__value = make_box<obj::persistent_set>();")
coll)))

;; Other.
Expand Down

0 comments on commit 24205a4

Please sign in to comment.