diff --git a/compiler+runtime/include/cpp/jank/runtime/behavior/callable.hpp b/compiler+runtime/include/cpp/jank/runtime/behavior/callable.hpp index 832d753ff..da00391cd 100644 --- a/compiler+runtime/include/cpp/jank/runtime/behavior/callable.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/behavior/callable.hpp @@ -137,6 +137,7 @@ namespace jank::runtime /* Callables need a way to get back to the root object so we can do helpful * error reporting on failed calls. */ + /* TODO: Remove this. */ virtual object_ref this_object_ref() = 0; /* When dynamically calling a function, we need to know three things: diff --git a/compiler+runtime/include/cpp/jank/runtime/ns.hpp b/compiler+runtime/include/cpp/jank/runtime/ns.hpp index 32111a62e..e11069634 100644 --- a/compiler+runtime/include/cpp/jank/runtime/ns.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/ns.hpp @@ -15,7 +15,7 @@ namespace jank::runtime using ns_ref = oref; - struct ns : gc + struct ns : object { static constexpr object_type obj_type{ object_type::ns }; static constexpr bool pointer_free{ false }; @@ -38,11 +38,11 @@ namespace jank::runtime obj::persistent_hash_map_ref get_mappings() const; /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - void to_string(jtl::string_builder &buff) const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + void to_string(jtl::string_builder &buff) const override; + uhash to_hash() const override; bool operator==(ns const &rhs) const; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/array_chunk.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/array_chunk.hpp index c51f9a2f5..10f9fe319 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/array_chunk.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/array_chunk.hpp @@ -6,22 +6,22 @@ namespace jank::runtime::obj { using array_chunk_ref = oref; - struct array_chunk : gc + struct array_chunk : object { static constexpr object_type obj_type{ object_type::array_chunk }; static constexpr bool pointer_free{ false }; - array_chunk() = default; + array_chunk(); array_chunk(native_vector const &buffer); array_chunk(native_vector const &buffer, usize offset); array_chunk(native_vector &&buffer, usize offset); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::chunk_like */ array_chunk_ref chunk_next() const; @@ -30,7 +30,6 @@ namespace jank::runtime::obj object_ref nth(object_ref index) const; object_ref nth(object_ref index, object_ref fallback) const; - object base{ obj_type }; native_vector buffer; usize offset{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/atom.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/atom.hpp index 9153f4f00..32a1c8aa7 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/atom.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/atom.hpp @@ -7,20 +7,20 @@ namespace jank::runtime::obj using atom_ref = oref; using persistent_vector_ref = oref; - struct atom : gc + struct atom : object { static constexpr object_type obj_type{ object_type::atom }; static constexpr bool pointer_free{ false }; - atom() = default; + atom(); atom(object_ref o); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::derefable */ object_ref deref() const; @@ -44,7 +44,6 @@ namespace jank::runtime::obj object_ref compare_and_set(object_ref old_val, object_ref new_val); - object base{ obj_type }; std::atomic val{}; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/big_integer.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/big_integer.hpp index dfd88120c..6a5714998 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/big_integer.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/big_integer.hpp @@ -30,12 +30,12 @@ namespace jank::runtime::obj { using big_integer_ref = oref; - struct big_integer : gc + struct big_integer : object { static constexpr object_type obj_type{ object_type::big_integer }; static constexpr bool pointer_free{ true }; - big_integer() = default; + big_integer(); big_integer(big_integer &&) noexcept = default; big_integer(big_integer const &) = default; @@ -46,11 +46,11 @@ namespace jank::runtime::obj explicit big_integer(jtl::immutable_string const &, i64, bool); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -70,7 +70,6 @@ namespace jank::runtime::obj void init(jtl::immutable_string const &); - object base{ obj_type }; native_big_integer data{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/character.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/character.hpp index 9bb3245f7..3427c6801 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/character.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/character.hpp @@ -6,25 +6,24 @@ namespace jank::runtime::obj { using character_ref = oref; - struct character : gc + struct character : object { static constexpr object_type obj_type{ object_type::character }; static constexpr bool pointer_free{ false }; - character() = default; + character(); character(character &&) noexcept = default; character(character const &) = default; character(jtl::immutable_string const &); character(char); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; - object base{ obj_type }; /* Holds the raw form of the character bytes. Supports Unicode. */ jtl::immutable_string data; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/chunk_buffer.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/chunk_buffer.hpp index e1cb56d42..2df26eac3 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/chunk_buffer.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/chunk_buffer.hpp @@ -7,21 +7,21 @@ namespace jank::runtime::obj using array_chunk_ref = oref; using chunk_buffer_ref = oref; - struct chunk_buffer : gc + struct chunk_buffer : object { static constexpr object_type obj_type{ object_type::chunk_buffer }; static constexpr bool pointer_free{ false }; - chunk_buffer() = default; + chunk_buffer(); chunk_buffer(usize capacity); chunk_buffer(object_ref capacity); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -29,7 +29,6 @@ namespace jank::runtime::obj void append(object_ref o); obj::array_chunk_ref chunk(); - object base{ obj_type }; native_vector buffer; usize capacity{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/chunked_cons.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/chunked_cons.hpp index d4cc84e27..b9750bef5 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/chunked_cons.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/chunked_cons.hpp @@ -9,24 +9,24 @@ namespace jank::runtime::obj using cons_ref = oref; using chunked_cons_ref = oref; - struct chunked_cons : gc + struct chunked_cons : object { static constexpr object_type obj_type{ object_type::chunked_cons }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - chunked_cons() = default; + chunked_cons(); chunked_cons(chunked_cons &&) noexcept = default; chunked_cons(chunked_cons const &) = default; chunked_cons(object_ref head, object_ref tail); chunked_cons(object_ref meta, object_ref head, object_ref tail); /* behavior::object_like */ - bool equal(object const &) const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::metadatable */ chunked_cons_ref with_meta(object_ref m) const; @@ -47,7 +47,6 @@ namespace jank::runtime::obj object_ref chunked_first() const; object_ref chunked_next() const; - object base{ obj_type }; object_ref head{}; object_ref tail{}; jtl::option meta; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/cons.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/cons.hpp index ce1728b0c..6d8c9fa3b 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/cons.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/cons.hpp @@ -8,23 +8,23 @@ namespace jank::runtime::obj { using cons_ref = oref; - struct cons : gc + struct cons : object { static constexpr object_type obj_type{ object_type::cons }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - cons() = default; + cons(); cons(cons &&) noexcept = default; cons(cons const &) = default; cons(object_ref const head, object_ref const tail); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::metadatable */ cons_ref with_meta(object_ref m) const; @@ -40,7 +40,6 @@ namespace jank::runtime::obj /* behavior::conjable */ cons_ref conj(object_ref head) const; - object base{ obj_type }; object_ref head{}; object_ref tail{}; mutable uhash hash{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/delay.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/delay.hpp index 1686d4604..bdbce1279 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/delay.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/delay.hpp @@ -6,25 +6,24 @@ namespace jank::runtime::obj { using delay_ref = oref; - struct delay : gc + struct delay : object { static constexpr object_type obj_type{ object_type::delay }; static constexpr bool pointer_free{ false }; - delay() = default; + delay(); delay(object_ref fn); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::derefable */ object_ref deref(); - object base{ obj_type }; object_ref val{}; object_ref fn{}; object_ref error{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map.hpp index 7b5400d8c..a0d212cc7 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map.hpp @@ -22,27 +22,27 @@ namespace jank::runtime::obj::detail /* Array maps and hash maps share a lot of common code, so we have a common base. * No virtual fns are used, so this structure won't survive release optimizations. */ template - struct base_persistent_map : gc + struct base_persistent_map : object { static constexpr bool pointer_free{ false }; static constexpr bool is_map_like{ true }; using value_type = V; - base_persistent_map() = default; + base_persistent_map(); base_persistent_map(jtl::option const &meta); /* behavior::object_like */ - bool equal(object const &o) const; + bool equal(object const &o) const override; static void to_string_impl(typename V::const_iterator const &begin, typename V::const_iterator const &end, jtl::string_builder &buff, bool const to_code); - void to_string(jtl::string_builder &buff) const; + void to_string(jtl::string_builder &buff) const override; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ oref seq() const; @@ -57,7 +57,6 @@ namespace jank::runtime::obj::detail /* behavior::conjable */ object_ref conj(object_ref const head) const; - object base{ PT::obj_type }; jtl::option meta; mutable uhash hash{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.hpp index 00a75c3f4..258d862fd 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.hpp @@ -17,23 +17,22 @@ namespace jank::runtime namespace jank::runtime::obj::detail { template - struct base_persistent_map_sequence : gc + struct base_persistent_map_sequence : object { static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - base_persistent_map_sequence() = default; base_persistent_map_sequence(base_persistent_map_sequence &&) = default; base_persistent_map_sequence(base_persistent_map_sequence const &) = default; base_persistent_map_sequence(object_ref const c, IT const &b, IT const &e); /* behavior::object_like */ - bool equal(object const &o) const; + bool equal(object const &o) const override; void to_string_impl(jtl::string_builder &buff, bool const to_code) const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -52,7 +51,6 @@ namespace jank::runtime::obj::detail /* behavior::conjable */ obj::cons_ref conj(object_ref const head); - object base{ PT::obj_type }; object_ref coll{}; IT begin{}, end{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/detail/iterator_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/detail/iterator_sequence.hpp index 6dc8f22f4..48714b768 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/detail/iterator_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/detail/iterator_sequence.hpp @@ -10,20 +10,17 @@ namespace jank::runtime::obj namespace jank::runtime::obj::detail { template - struct iterator_sequence + struct iterator_sequence : object { - /* NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility) */ - iterator_sequence() = default; - /* NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility) */ iterator_sequence(object_ref const &c, It const &b, It const &e, usize const s); /* behavior::object_like */ - bool equal(object const &o) const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &o) const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ oref seq(); diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/inst.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/inst.hpp index 1ede41f1a..8c28707e0 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/inst.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/inst.hpp @@ -9,7 +9,7 @@ namespace jank::runtime::obj using inst_ref = oref; using inst_time_point = std::chrono::time_point; - struct inst : gc + struct inst : object { static constexpr object_type obj_type{ object_type::inst }; static constexpr bool pointer_free{ true }; @@ -18,13 +18,12 @@ namespace jank::runtime::obj inst(jtl::immutable_string const &s); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; - object base{ obj_type }; inst_time_point value; mutable uhash hash{}; }; 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 45b99a23a..b9e8d80de 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp @@ -12,7 +12,7 @@ namespace jank::runtime::obj /* An integer range from X to Y, exclusive, incrementing by S. */ /* For non-integer values, use the range object */ - struct integer_range + struct integer_range : object { static constexpr object_type obj_type{ object_type::integer_range }; static constexpr bool pointer_free{ false }; @@ -21,7 +21,7 @@ namespace jank::runtime::obj using bounds_check_t = bool (*)(integer_ref, integer_ref); /* Constructors are only to be used within integer_range.cpp. Prefer integer_range::create. */ - integer_range() = default; + integer_range(); integer_range(integer_range &&) noexcept = default; integer_range(integer_range const &) = default; integer_range(integer_ref end); @@ -43,11 +43,11 @@ namespace jank::runtime::obj static object_ref create(integer_ref start, obj::integer_ref end, obj::integer_ref step); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ integer_range_ref seq() const; @@ -74,7 +74,6 @@ namespace jank::runtime::obj /* behavior::countable */ usize count() const; - object base{ object_type::integer_range }; integer_ref start{}; integer_ref end{}; integer_ref step{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/iterator.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/iterator.hpp index 2ed4522d3..7e5747eb1 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/iterator.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/iterator.hpp @@ -9,23 +9,23 @@ namespace jank::runtime::obj using iterator_ref = oref; /* TODO: Rename to iterator_sequence. */ - struct iterator : gc + struct iterator : object { static constexpr object_type obj_type{ object_type::iterator }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - iterator() = default; + iterator(); iterator(iterator &&) noexcept = default; iterator(iterator const &) = default; iterator(object_ref const fn, object_ref const start); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string(); - void to_string(jtl::string_builder &buff); - jtl::immutable_string to_code_string(); - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ iterator_ref seq(); @@ -39,7 +39,6 @@ namespace jank::runtime::obj /* behavior::sequenceable_in_place */ iterator_ref next_in_place(); - object base{ obj_type }; /* TODO: Support chunking. */ object_ref fn{}; object_ref current{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/jit_closure.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/jit_closure.hpp index 5d7160be5..8efee0018 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/jit_closure.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/jit_closure.hpp @@ -8,24 +8,24 @@ namespace jank::runtime::obj using jit_closure_ref = oref; struct jit_closure - : gc + : object , behavior::callable { static constexpr object_type obj_type{ object_type::jit_closure }; static constexpr bool pointer_free{ false }; - jit_closure() = default; + jit_closure(); jit_closure(jit_closure &&) noexcept = default; jit_closure(jit_closure const &) = default; jit_closure(arity_flag_t arity_flags, void *context); jit_closure(object_ref meta); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string(); - void to_string(jtl::string_builder &buff); - jtl::immutable_string to_code_string(); - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::metadatable */ jit_closure_ref with_meta(object_ref m); @@ -73,7 +73,6 @@ namespace jank::runtime::obj object_ref this_object_ref() final; - object base{ obj_type }; void *context{}; object *(*arity_0)(void *){}; object *(*arity_1)(void *, object *){}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/jit_function.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/jit_function.hpp index 63efd81ab..2d23ddf18 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/jit_function.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/jit_function.hpp @@ -8,24 +8,24 @@ namespace jank::runtime::obj using jit_function_ref = oref; struct jit_function - : gc + : object , behavior::callable { static constexpr object_type obj_type{ object_type::jit_function }; static constexpr bool pointer_free{ false }; - jit_function() = default; + jit_function(); jit_function(jit_function &&) noexcept = default; jit_function(jit_function const &) = default; jit_function(arity_flag_t arity_flags); jit_function(object_ref meta); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string(); - void to_string(jtl::string_builder &buff); - jtl::immutable_string to_code_string(); - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::metadatable */ jit_function_ref with_meta(object_ref m); @@ -73,7 +73,6 @@ namespace jank::runtime::obj arity_flag_t get_arity_flags() const override; object_ref this_object_ref() override; - object base{ obj_type }; object *(*arity_0)(){}; object *(*arity_1)(object *){}; object *(*arity_2)(object *, object *){}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/keyword.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/keyword.hpp index 73b260716..c73aa24f6 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/keyword.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/keyword.hpp @@ -10,14 +10,14 @@ namespace jank::runtime::obj using keyword_ref = oref; /* The correct way to create a keyword for normal use is through interning via the RT context. */ - struct keyword : gc + struct keyword : object { static constexpr object_type obj_type{ object_type::keyword }; static constexpr bool pointer_free{ false }; /* Clojure uses this. No idea. https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Keyword.java */ static constexpr usize hash_magic{ 0x9e3779b9 }; - keyword() = default; + keyword(); keyword(keyword &&) noexcept = default; keyword(keyword const &) = default; keyword(runtime::detail::must_be_interned, jtl::immutable_string_view const &s); @@ -26,11 +26,11 @@ namespace jank::runtime::obj jtl::immutable_string_view const &n); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -48,7 +48,6 @@ namespace jank::runtime::obj bool operator==(keyword const &rhs) const; - object base{ obj_type }; symbol_ref sym; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/lazy_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/lazy_sequence.hpp index 919651d9b..26b68dc83 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/lazy_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/lazy_sequence.hpp @@ -11,24 +11,24 @@ namespace jank::runtime::obj using lazy_sequence_ref = oref; /* TODO: IPending analog, to implement `realized?`. */ - struct lazy_sequence : gc + struct lazy_sequence : object { static constexpr object_type obj_type{ object_type::lazy_sequence }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - lazy_sequence() = default; + lazy_sequence(); lazy_sequence(lazy_sequence &&) noexcept = default; lazy_sequence(lazy_sequence const &) = default; lazy_sequence(object_ref fn); lazy_sequence(object_ref fn, object_ref sequence); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ object_ref seq() const; @@ -57,7 +57,6 @@ namespace jank::runtime::obj public: /* TODO: Synchronize. */ - object base{ obj_type }; mutable object_ref fn{}; mutable object_ref sv{}; mutable object_ref s{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/multi_function.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/multi_function.hpp index 13f00fa4c..03a5aea7e 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/multi_function.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/multi_function.hpp @@ -12,7 +12,7 @@ namespace jank::runtime::obj using multi_function_ref = oref; struct multi_function - : gc + : object , behavior::callable { static constexpr object_type obj_type{ object_type::multi_function }; @@ -22,11 +22,11 @@ namespace jank::runtime::obj multi_function(object_ref name, object_ref dispatch, object_ref default_, object_ref hierarchy); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string(); - void to_string(jtl::string_builder &buff); - jtl::immutable_string to_code_string(); - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::callable */ object_ref call() override; @@ -83,7 +83,6 @@ namespace jank::runtime::obj object_ref get_method(object_ref dispatch_val); object_ref find_and_cache_best_method(object_ref dispatch_val); - object base{ obj_type }; object_ref dispatch{}; object_ref default_dispatch_value{}; object_ref hierarchy{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/native_array_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/native_array_sequence.hpp index 65b4df1f6..fa7cbf1dd 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/native_array_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/native_array_sequence.hpp @@ -7,7 +7,7 @@ namespace jank::runtime::obj using native_array_sequence_ref = oref; using cons_ref = oref; - struct native_array_sequence : gc + struct native_array_sequence : object { static constexpr object_type obj_type{ object_type::native_array_sequence }; static constexpr bool pointer_free{ false }; @@ -21,17 +21,18 @@ namespace jank::runtime::obj template native_array_sequence(object_ref const first, Args const... rest) - : arr{ make_array_box(first, rest...) } + : object{ obj_type } + , arr{ make_array_box(first, rest...) } , size{ sizeof...(Args) + 1 } { } /* behavior::object_like */ - bool equal(object const &o) const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &o) const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ native_array_sequence_ref seq(); @@ -48,7 +49,6 @@ namespace jank::runtime::obj /* behavior::sequenceable_in_place */ native_array_sequence_ref next_in_place(); - object base{ obj_type }; jtl::ptr arr{}; usize index{}; usize size{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/native_function_wrapper.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/native_function_wrapper.hpp index 0b3be7035..3ae6c36af 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/native_function_wrapper.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/native_function_wrapper.hpp @@ -65,24 +65,24 @@ namespace jank::runtime using native_function_wrapper_ref = oref; struct native_function_wrapper - : gc + : object , behavior::callable { static constexpr object_type obj_type{ object_type::native_function_wrapper }; static constexpr bool pointer_free{ false }; - native_function_wrapper() = default; + native_function_wrapper(); native_function_wrapper(native_function_wrapper &&) noexcept = default; native_function_wrapper(native_function_wrapper const &) = default; native_function_wrapper(obj::detail::function_type &&d); native_function_wrapper(obj::detail::function_type const &d); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::callable */ object_ref call() final; @@ -128,7 +128,6 @@ namespace jank::runtime /* behavior::metadatable */ native_function_wrapper_ref with_meta(object_ref m) const; - object base{ obj_type }; obj::detail::function_type data{}; jtl::option meta; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/native_pointer_wrapper.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/native_pointer_wrapper.hpp index 353adde85..f3b1dcf31 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/native_pointer_wrapper.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/native_pointer_wrapper.hpp @@ -6,22 +6,22 @@ namespace jank::runtime::obj { using native_pointer_wrapper_ref = oref; - struct native_pointer_wrapper : gc + struct native_pointer_wrapper : object { static constexpr object_type obj_type{ object_type::native_pointer_wrapper }; static constexpr bool pointer_free{ false }; - native_pointer_wrapper() = default; + native_pointer_wrapper(); native_pointer_wrapper(native_pointer_wrapper &&) noexcept = default; native_pointer_wrapper(native_pointer_wrapper const &) = default; native_pointer_wrapper(void * const); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; template T *as() const @@ -29,7 +29,6 @@ namespace jank::runtime::obj return reinterpret_cast(data); } - object base{ obj_type }; void *data{}; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/native_vector_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/native_vector_sequence.hpp index a586e2e02..0883203b1 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/native_vector_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/native_vector_sequence.hpp @@ -9,13 +9,13 @@ namespace jank::runtime::obj using cons_ref = oref; using native_vector_sequence_ref = oref; - struct native_vector_sequence : gc + struct native_vector_sequence : object { static constexpr object_type obj_type{ object_type::native_vector_sequence }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - native_vector_sequence() = default; + native_vector_sequence(); native_vector_sequence(native_vector_sequence &&) noexcept = default; native_vector_sequence(native_vector_sequence const &) = default; native_vector_sequence(native_vector const &data, usize index); @@ -24,11 +24,11 @@ namespace jank::runtime::obj native_vector_sequence(native_vector &&data, usize index); /* behavior::object_like */ - bool equal(object const &o) const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash(); + bool equal(object const &o) const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ native_vector_sequence_ref seq(); @@ -48,7 +48,6 @@ namespace jank::runtime::obj /* behavior::metadatable */ native_vector_sequence_ref with_meta(object_ref const m) const; - object base{ obj_type }; native_vector data{}; usize index{}; jtl::option meta; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/nil.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/nil.hpp index 6aa29abe5..e58bb6f3b 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/nil.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/nil.hpp @@ -8,19 +8,19 @@ namespace jank::runtime::obj using cons_ref = oref; using nil_ref = oref; - struct nil : gc + struct nil : object { static constexpr object_type obj_type{ object_type::nil }; static constexpr bool pointer_free{ true }; - nil() = default; + nil(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string const &to_string() const; - jtl::immutable_string const &to_code_string() const; - void to_string(jtl::string_builder &buff) const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + void to_string(jtl::string_builder &buff) const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -48,8 +48,6 @@ namespace jank::runtime::obj /* behavior::sequenceable_in_place */ nil_ref next_in_place(); - - object base{ obj_type }; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/number.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/number.hpp index 4e3ac2c19..99b6d5a88 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/number.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/number.hpp @@ -6,22 +6,22 @@ namespace jank::runtime::obj { using boolean_ref = oref; - struct boolean : gc + struct boolean : object { static constexpr object_type obj_type{ object_type::boolean }; static constexpr bool pointer_free{ true }; - boolean() = default; + boolean(); boolean(boolean &&) noexcept = default; boolean(boolean const &) = default; boolean(bool const d); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -29,28 +29,27 @@ namespace jank::runtime::obj /* behavior::comparable extended */ i64 compare(boolean const &) const; - object base{ obj_type }; bool data{}; }; using integer_ref = oref; - struct integer : gc + struct integer : object { static constexpr object_type obj_type{ object_type::integer }; static constexpr bool pointer_free{ true }; - integer() = default; + integer(); integer(integer &&) noexcept = default; integer(integer const &) = default; integer(i64 const d); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -62,29 +61,27 @@ namespace jank::runtime::obj i64 to_integer() const; f64 to_real() const; - object base{ obj_type }; - /* TODO: Is it faster to have the data first or the base first? */ i64 data{}; }; using real_ref = oref; - struct real : gc + struct real : object { static constexpr object_type obj_type{ object_type::real }; static constexpr bool pointer_free{ true }; - real() = default; + real(); real(real &&) noexcept = default; real(real const &) = default; real(f64 const d); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -97,7 +94,6 @@ namespace jank::runtime::obj f64 to_real() const; f64 data{}; - object base{ obj_type }; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/opaque_box.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/opaque_box.hpp index 22497875a..eda439d7a 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/opaque_box.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/opaque_box.hpp @@ -6,7 +6,7 @@ namespace jank::runtime::obj { using opaque_box_ref = oref; - struct opaque_box : gc + struct opaque_box : object { static constexpr object_type obj_type{ object_type::opaque_box }; static constexpr bool pointer_free{ false }; @@ -14,13 +14,12 @@ namespace jank::runtime::obj opaque_box(jtl::ptr data); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; - object base{ obj_type }; jtl::ptr data{}; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set.hpp index 6dc4fee59..ed9f2e89b 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set.hpp @@ -9,7 +9,7 @@ namespace jank::runtime::obj using persistent_hash_set_ref = oref; using persistent_hash_set_sequence_ref = oref; - struct persistent_hash_set : gc + struct persistent_hash_set : object { static constexpr object_type obj_type{ object_type::persistent_hash_set }; static constexpr bool pointer_free{ false }; @@ -17,7 +17,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_persistent_hash_set; - persistent_hash_set() = default; + persistent_hash_set(); persistent_hash_set(persistent_hash_set &&) noexcept = default; persistent_hash_set(persistent_hash_set const &) = default; persistent_hash_set(value_type &&d); @@ -26,13 +26,15 @@ namespace jank::runtime::obj template persistent_hash_set(std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } { } template persistent_hash_set(object_ref const meta, std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } , meta{ meta } { } @@ -42,11 +44,11 @@ namespace jank::runtime::obj static persistent_hash_set_ref create_from_seq(object_ref const seq); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::metadatable */ persistent_hash_set_ref with_meta(object_ref m) const; @@ -70,7 +72,6 @@ namespace jank::runtime::obj bool contains(object_ref o) const; persistent_hash_set_ref disj(object_ref o) const; - object base{ obj_type }; value_type data; jtl::option meta; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set_sequence.hpp index 08c427dab..5b45489ad 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_hash_set_sequence.hpp @@ -11,8 +11,7 @@ namespace jank::runtime::obj using persistent_hash_set_sequence_ref = oref; struct persistent_hash_set_sequence - : gc - , obj::detail::iterator_sequence { static constexpr object_type obj_type{ object_type::persistent_hash_set_sequence }; @@ -24,7 +23,5 @@ namespace jank::runtime::obj using obj::detail::iterator_sequence< persistent_hash_set_sequence, runtime::detail::native_persistent_hash_set::iterator>::iterator_sequence; - - object base{ obj_type }; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_list.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_list.hpp index a7e56b147..48b342d25 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_list.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_list.hpp @@ -8,7 +8,7 @@ namespace jank::runtime::obj using nil_ref = oref; using persistent_list_ref = oref; - struct persistent_list : gc + struct persistent_list : object { using value_type = runtime::detail::native_persistent_list; @@ -22,7 +22,7 @@ namespace jank::runtime::obj static persistent_list_ref create(persistent_list_ref s); static persistent_list_ref create(nil_ref s); - persistent_list() = default; + persistent_list(); persistent_list(persistent_list &&) noexcept = default; persistent_list(persistent_list const &) = default; persistent_list(value_type const &d); @@ -32,13 +32,15 @@ namespace jank::runtime::obj * It just uses the copy ctor. */ template persistent_list(std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } { } template persistent_list(object_ref const meta, std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } , meta{ meta } { } @@ -50,11 +52,11 @@ namespace jank::runtime::obj } /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::metadatable */ persistent_list_ref with_meta(object_ref m) const; @@ -80,7 +82,6 @@ namespace jank::runtime::obj object_ref peek() const; persistent_list_ref pop() const; - object base{ obj_type }; value_type data; jtl::option meta; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set.hpp index 28efff3ce..86eadd1b7 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set.hpp @@ -9,7 +9,7 @@ namespace jank::runtime::obj using persistent_sorted_set_ref = oref; using persistent_sorted_set_sequence_ref = oref; - struct persistent_sorted_set : gc + struct persistent_sorted_set : object { static constexpr object_type obj_type{ object_type::persistent_sorted_set }; static constexpr bool pointer_free{ false }; @@ -17,7 +17,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_persistent_sorted_set; - persistent_sorted_set() = default; + persistent_sorted_set(); persistent_sorted_set(persistent_sorted_set &&) noexcept = default; persistent_sorted_set(persistent_sorted_set const &) = default; persistent_sorted_set(value_type &&d); @@ -27,13 +27,15 @@ namespace jank::runtime::obj template persistent_sorted_set(std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } { } template persistent_sorted_set(object_ref const meta, std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } , meta{ meta } { } @@ -42,11 +44,11 @@ namespace jank::runtime::obj static persistent_sorted_set_ref create_from_seq(object_ref const seq); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::metadatable */ persistent_sorted_set_ref with_meta(object_ref m) const; @@ -70,7 +72,6 @@ namespace jank::runtime::obj bool contains(object_ref o) const; persistent_sorted_set_ref disj(object_ref o) const; - object base{ obj_type }; value_type data; jtl::option meta; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set_sequence.hpp index 05c655004..c3a4b8711 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_sorted_set_sequence.hpp @@ -11,8 +11,7 @@ namespace jank::runtime::obj using persistent_sorted_set_sequence_ref = oref; struct persistent_sorted_set_sequence - : gc - , obj::detail::iterator_sequence { static constexpr object_type obj_type{ object_type::persistent_sorted_set_sequence }; @@ -24,7 +23,5 @@ namespace jank::runtime::obj using obj::detail::iterator_sequence< persistent_sorted_set_sequence, runtime::detail::native_persistent_sorted_set::const_iterator>::iterator_sequence; - - object base{ obj_type }; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string.hpp index ff51d1704..4eef9dc07 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string.hpp @@ -9,12 +9,12 @@ namespace jank::runtime::obj using persistent_string_ref = oref; using persistent_string_sequence_ref = oref; - struct persistent_string : gc + struct persistent_string : object { static constexpr object_type obj_type{ object_type::persistent_string }; static constexpr bool pointer_free{ false }; - persistent_string() = default; + persistent_string(); persistent_string(persistent_string &&) noexcept = default; persistent_string(persistent_string const &) = default; persistent_string(jtl::immutable_string const &d); @@ -27,11 +27,11 @@ namespace jank::runtime::obj } /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string const &to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -64,7 +64,6 @@ namespace jank::runtime::obj obj::persistent_string_sequence_ref seq() const; obj::persistent_string_sequence_ref fresh_seq() const; - object base{ obj_type }; jtl::immutable_string data; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string_sequence.hpp index 7d2e353a3..28402eb17 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_string_sequence.hpp @@ -8,24 +8,24 @@ namespace jank::runtime::obj using persistent_string_ref = oref; using persistent_string_sequence_ref = oref; - struct persistent_string_sequence : gc + struct persistent_string_sequence : object { static constexpr object_type obj_type{ object_type::persistent_string_sequence }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - persistent_string_sequence() = default; + persistent_string_sequence(); persistent_string_sequence(persistent_string_sequence &&) noexcept = default; persistent_string_sequence(persistent_string_sequence const &) = default; persistent_string_sequence(obj::persistent_string_ref const s); persistent_string_sequence(obj::persistent_string_ref const s, usize const i); /* behavior::object_like */ - bool equal(object const &) const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -42,7 +42,6 @@ namespace jank::runtime::obj /* behavior::sequenceable_in_place */ persistent_string_sequence_ref next_in_place(); - object base{ obj_type }; obj::persistent_string_ref str{}; usize index{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector.hpp index bf3d1a4be..5fcc82418 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector.hpp @@ -9,7 +9,7 @@ namespace jank::runtime::obj using persistent_vector_ref = oref; using persistent_vector_sequence_ref = oref; - struct persistent_vector : gc + struct persistent_vector : object { static constexpr object_type obj_type{ object_type::persistent_vector }; static constexpr bool pointer_free{ false }; @@ -18,7 +18,7 @@ namespace jank::runtime::obj using transient_type = transient_vector; using value_type = runtime::detail::native_persistent_vector; - persistent_vector() = default; + persistent_vector(); persistent_vector(persistent_vector &&) noexcept = default; persistent_vector(persistent_vector const &) = default; persistent_vector(value_type &&d); @@ -27,13 +27,15 @@ namespace jank::runtime::obj template persistent_vector(std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } { } template persistent_vector(object_ref const meta, std::in_place_t, Args &&...args) - : data{ std::forward(args)... } + : object{ obj_type } + , data{ std::forward(args)... } , meta{ meta } { } @@ -43,11 +45,11 @@ namespace jank::runtime::obj static persistent_vector_ref empty(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -85,7 +87,6 @@ namespace jank::runtime::obj /* behavior::transientable */ obj::transient_vector_ref to_transient() const; - object base{ obj_type }; value_type data; jtl::option meta; mutable uhash hash{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector_sequence.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector_sequence.hpp index 0cc124287..85b80f486 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector_sequence.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/persistent_vector_sequence.hpp @@ -8,24 +8,24 @@ namespace jank::runtime::obj using persistent_vector_ref = oref; using persistent_vector_sequence_ref = oref; - struct persistent_vector_sequence : gc + struct persistent_vector_sequence : object { static constexpr object_type obj_type{ object_type::persistent_vector_sequence }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; - persistent_vector_sequence() = default; + persistent_vector_sequence(); persistent_vector_sequence(persistent_vector_sequence &&) noexcept = default; persistent_vector_sequence(persistent_vector_sequence const &) = default; persistent_vector_sequence(obj::persistent_vector_ref v); persistent_vector_sequence(obj::persistent_vector_ref v, usize i); /* behavior::object_like */ - bool equal(object const &) const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -42,7 +42,6 @@ namespace jank::runtime::obj /* behavior::sequenceable_in_place */ persistent_vector_sequence_ref next_in_place(); - object base{ obj_type }; obj::persistent_vector_ref vec{}; usize index{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp index bbfe5a2be..765665f63 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp @@ -13,7 +13,7 @@ namespace jank::runtime::obj /* A range from X to Y, exclusive, incrementing by S. This is for non-integer values. * For integer values, use integer_range. This is not countable in constant time, due * to floating point shenanigans. */ - struct range : gc + struct range : object { static constexpr object_type obj_type{ object_type::range }; static constexpr bool pointer_free{ false }; @@ -23,7 +23,7 @@ namespace jank::runtime::obj using bounds_check_t = bool (*)(object_ref, object_ref); /* Constructors are only to be used within range.cpp. Prefer range::create. */ - range() = default; + range(); range(range &&) noexcept = default; range(range const &) = default; range(object_ref end); @@ -42,11 +42,11 @@ namespace jank::runtime::obj static object_ref create(object_ref start, object_ref end, object_ref step); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string(); - void to_string(jtl::string_builder &buff); - jtl::immutable_string to_code_string(); - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ range_ptr seq(); @@ -70,7 +70,6 @@ namespace jank::runtime::obj /* behavior::metadatable */ range_ptr with_meta(object_ref m) const; - object base{ obj_type }; object_ref start{}; object_ref end{}; object_ref step{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/ratio.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/ratio.hpp index e23ed901e..c1fd146c9 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/ratio.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/ratio.hpp @@ -24,7 +24,7 @@ namespace jank::runtime::obj using real_ref = oref; using ratio_ref = oref; - struct ratio : gc + struct ratio : object { static constexpr object_type obj_type{ object_type::ratio }; static constexpr bool pointer_free{ true }; @@ -37,11 +37,11 @@ namespace jank::runtime::obj static object_ref create(native_big_integer const &, native_big_integer const &); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::comparable */ i64 compare(object const &) const; @@ -53,7 +53,6 @@ namespace jank::runtime::obj i64 to_integer() const; f64 to_real() const; - object base{ obj_type }; ratio_data data; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/re_matcher.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/re_matcher.hpp index f01792d55..1b9b03928 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/re_matcher.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/re_matcher.hpp @@ -10,7 +10,7 @@ namespace jank::runtime::obj { using re_matcher_ref = oref; - struct re_matcher : gc_cleanup + struct re_matcher : object { static constexpr object_type obj_type{ object_type::re_matcher }; static constexpr bool pointer_free{ false }; @@ -18,14 +18,13 @@ namespace jank::runtime::obj re_matcher(re_pattern_ref re, jtl::immutable_string const &s); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; object base{ obj_type }; - re_pattern_ref re; std::string match_input{}; object_ref groups{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/re_pattern.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/re_pattern.hpp index f3024aa20..65d1b7456 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/re_pattern.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/re_pattern.hpp @@ -9,7 +9,7 @@ namespace jank::runtime::obj { using re_pattern_ref = oref; - struct re_pattern : gc_cleanup + struct re_pattern : object { static constexpr object_type obj_type{ object_type::re_pattern }; static constexpr bool pointer_free{ false }; @@ -17,14 +17,13 @@ namespace jank::runtime::obj re_pattern(jtl::immutable_string const &s); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; object base{ obj_type }; - jtl::immutable_string pattern{}; std::regex regex{}; }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/reduced.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/reduced.hpp index 1a1306001..74e48739e 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/reduced.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/reduced.hpp @@ -6,25 +6,24 @@ namespace jank::runtime::obj { using reduced_ref = oref; - struct reduced : gc + struct reduced : object { static constexpr object_type obj_type{ object_type::reduced }; static constexpr bool pointer_free{ false }; - reduced() = default; + reduced(); reduced(object_ref o); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::derefable */ object_ref deref() const; - object base{ obj_type }; object_ref val{}; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/repeat.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/repeat.hpp index 050b5a072..bf7a64cfc 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/repeat.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/repeat.hpp @@ -9,14 +9,14 @@ namespace jank::runtime::obj using cons_ref = oref; using repeat_ref = oref; - struct repeat : gc + struct repeat : object { static constexpr object_type obj_type{ object_type::repeat }; static constexpr bool pointer_free{ false }; static constexpr bool is_sequential{ true }; static constexpr i64 infinite{ -1 }; - repeat() = default; + repeat(); repeat(object_ref value); repeat(object_ref count, object_ref value); @@ -24,11 +24,11 @@ namespace jank::runtime::obj static object_ref create(object_ref count, object_ref value); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string(); - void to_string(jtl::string_builder &buff); - jtl::immutable_string to_code_string(); - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::seqable */ repeat_ref seq(); @@ -47,7 +47,6 @@ namespace jank::runtime::obj /* behavior::metadatable */ repeat_ref with_meta(object_ref m) const; - object base{ obj_type }; object_ref value{}; object_ref count{}; jtl::option meta{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/symbol.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/symbol.hpp index 10df7eb5d..6496048bb 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/symbol.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/symbol.hpp @@ -9,12 +9,12 @@ namespace jank::runtime::obj using persistent_array_map_ref = oref; using symbol_ref = oref; - struct symbol : gc + struct symbol : object { static constexpr object_type obj_type{ object_type::symbol }; static constexpr bool pointer_free{ false }; - symbol() = default; + symbol(); symbol(symbol &&) noexcept = default; symbol(symbol const &) = default; symbol(jtl::immutable_string const &d); @@ -28,11 +28,11 @@ namespace jank::runtime::obj symbol &operator=(symbol &&) = default; /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::object_like extended */ bool equal(symbol const &) const; @@ -56,8 +56,6 @@ namespace jank::runtime::obj void set_ns(jtl::immutable_string const &); void set_name(jtl::immutable_string const &); - object base{ obj_type }; - /* These require mutation fns, since changing them will affect the hash. */ jtl::immutable_string ns; jtl::immutable_string name; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/tagged_literal.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/tagged_literal.hpp index 39a241f0a..e1165a6a8 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/tagged_literal.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/tagged_literal.hpp @@ -6,7 +6,7 @@ namespace jank::runtime::obj { using tagged_literal_ref = oref; - struct tagged_literal : gc + struct tagged_literal : object { static constexpr object_type obj_type{ object_type::tagged_literal }; static constexpr bool pointer_free{ false }; @@ -14,11 +14,11 @@ namespace jank::runtime::obj tagged_literal(object_ref tag, object_ref form); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::associatively_readable */ object_ref get(object_ref const key) const; @@ -26,8 +26,6 @@ namespace jank::runtime::obj object_ref get_entry(object_ref key) const; bool contains(object_ref key) const; - object base{ obj_type }; - object_ref tag{}; object_ref form{}; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/transient_array_map.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/transient_array_map.hpp index 9eb6e32b3..1fc21a46d 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/transient_array_map.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/transient_array_map.hpp @@ -8,7 +8,7 @@ namespace jank::runtime::obj using transient_array_map_ref = oref; /* TODO: Benchmark how fast is the transient array map vs the transient hash map for small maps? */ - struct transient_array_map : gc + struct transient_array_map : object { static constexpr object_type obj_type{ object_type::transient_array_map }; static constexpr bool pointer_free{ false }; @@ -16,7 +16,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_array_map; using persistent_type_ref = oref; - transient_array_map() = default; + transient_array_map(); transient_array_map(transient_array_map &&) noexcept = default; transient_array_map(transient_array_map const &) = default; transient_array_map(runtime::detail::native_array_map const &d); @@ -25,11 +25,11 @@ namespace jank::runtime::obj static transient_array_map_ref empty(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ u8 count() const; @@ -56,7 +56,6 @@ namespace jank::runtime::obj void assert_active() const; - object base{ obj_type }; value_type data; mutable uhash hash{}; bool active{ true }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_map.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_map.hpp index 19ef8fd54..cb0da67cc 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_map.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_map.hpp @@ -12,7 +12,7 @@ namespace jank::runtime::obj { using transient_hash_map_ref = oref; - struct transient_hash_map : gc + struct transient_hash_map : object { static constexpr object_type obj_type{ object_type::transient_hash_map }; static constexpr bool pointer_free{ false }; @@ -20,7 +20,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_transient_hash_map; using persistent_type_ref = oref; - transient_hash_map() = default; + transient_hash_map(); transient_hash_map(transient_hash_map &&) noexcept = default; transient_hash_map(transient_hash_map const &) = default; transient_hash_map(runtime::detail::native_persistent_hash_map const &d); @@ -31,11 +31,11 @@ namespace jank::runtime::obj static transient_hash_map_ref empty(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -62,7 +62,6 @@ namespace jank::runtime::obj void assert_active() const; - object base{ obj_type }; value_type data; mutable uhash hash{}; bool active{ true }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_set.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_set.hpp index 4cae8df4a..cc973a02c 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_set.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/transient_hash_set.hpp @@ -7,7 +7,7 @@ namespace jank::runtime::obj { using transient_hash_set_ref = oref; - struct transient_hash_set : gc + struct transient_hash_set : object { static constexpr object_type obj_type{ object_type::transient_hash_set }; static constexpr bool pointer_free{ false }; @@ -15,7 +15,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_transient_hash_set; using persistent_type_ref = oref; - transient_hash_set() = default; + transient_hash_set(); transient_hash_set(transient_hash_set &&) noexcept = default; transient_hash_set(transient_hash_set const &) = default; transient_hash_set(runtime::detail::native_persistent_hash_set const &d); @@ -25,11 +25,11 @@ namespace jank::runtime::obj static transient_hash_set_ref empty(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -54,7 +54,6 @@ namespace jank::runtime::obj void assert_active() const; - object base{ obj_type }; value_type data; mutable uhash hash{}; bool active{ true }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_map.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_map.hpp index 97e3fdcc1..d5f3342bf 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_map.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_map.hpp @@ -7,7 +7,7 @@ namespace jank::runtime::obj { using transient_sorted_map_ref = oref; - struct transient_sorted_map : gc + struct transient_sorted_map : object { static constexpr object_type obj_type{ object_type::transient_sorted_map }; static constexpr bool pointer_free{ false }; @@ -15,7 +15,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_transient_sorted_map; using persistent_type_ref = oref; - transient_sorted_map() = default; + transient_sorted_map(); transient_sorted_map(transient_sorted_map &&) noexcept = default; transient_sorted_map(transient_sorted_map const &) = default; transient_sorted_map(runtime::detail::native_persistent_sorted_map const &d); @@ -25,11 +25,11 @@ namespace jank::runtime::obj static transient_sorted_map_ref empty(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -56,7 +56,6 @@ namespace jank::runtime::obj void assert_active() const; - object base{ obj_type }; value_type data; mutable uhash hash{}; bool active{ true }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_set.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_set.hpp index e2d679eaf..5fe9abebf 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_set.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/transient_sorted_set.hpp @@ -7,7 +7,7 @@ namespace jank::runtime::obj { using transient_sorted_set_ref = oref; - struct transient_sorted_set : gc + struct transient_sorted_set : object { static constexpr object_type obj_type{ object_type::transient_sorted_set }; static constexpr bool pointer_free{ false }; @@ -15,7 +15,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_transient_sorted_set; using persistent_type_ref = oref; - transient_sorted_set() = default; + transient_sorted_set(); transient_sorted_set(transient_sorted_set &&) noexcept = default; transient_sorted_set(transient_sorted_set const &) = default; transient_sorted_set(runtime::detail::native_persistent_sorted_set const &d); @@ -25,11 +25,11 @@ namespace jank::runtime::obj static transient_sorted_set_ref empty(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; @@ -54,7 +54,6 @@ namespace jank::runtime::obj void assert_active() const; - object base{ obj_type }; value_type data; mutable uhash hash{}; bool active{ true }; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/transient_vector.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/transient_vector.hpp index cfb586f73..d71ee19e0 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/transient_vector.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/transient_vector.hpp @@ -7,7 +7,7 @@ namespace jank::runtime::obj { using transient_vector_ref = oref; - struct transient_vector : gc + struct transient_vector : object { static constexpr object_type obj_type{ object_type::transient_vector }; static constexpr bool pointer_free{ false }; @@ -15,7 +15,7 @@ namespace jank::runtime::obj using value_type = runtime::detail::native_transient_vector; using persistent_type_ref = oref; - transient_vector() = default; + transient_vector(); transient_vector(transient_vector &&) noexcept = default; transient_vector(transient_vector const &) = default; transient_vector(runtime::detail::native_persistent_vector const &d); @@ -25,11 +25,11 @@ namespace jank::runtime::obj static transient_vector_ref empty(); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::countable */ usize count() const; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/uuid.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/uuid.hpp index f5f04b1e6..626c64fda 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/uuid.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/uuid.hpp @@ -11,7 +11,7 @@ namespace jank::runtime::obj { using uuid_ref = oref; - struct uuid : gc + struct uuid : object { static constexpr object_type obj_type{ object_type::uuid }; static constexpr bool pointer_free{ false }; @@ -20,11 +20,11 @@ namespace jank::runtime::obj uuid(jtl::immutable_string const &s); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; object base{ obj_type }; jtl::ref value; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/volatile.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/volatile.hpp index f80517541..072f27333 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/volatile.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/volatile.hpp @@ -6,20 +6,20 @@ namespace jank::runtime::obj { using volatile_ref = oref; - struct volatile_ : gc + struct volatile_ : object { static constexpr object_type obj_type{ object_type::volatile_ }; static constexpr bool pointer_free{ false }; - volatile_() = default; + volatile_(); volatile_(object_ref o); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; /* behavior::derefable */ object_ref deref() const; diff --git a/compiler+runtime/include/cpp/jank/runtime/object.hpp b/compiler+runtime/include/cpp/jank/runtime/object.hpp index 333fdad9c..43a7dff94 100644 --- a/compiler+runtime/include/cpp/jank/runtime/object.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/object.hpp @@ -238,8 +238,18 @@ namespace jank::runtime return "unknown"; } - struct object + struct object : gc { + object() = delete; + object(object_type); + virtual ~object() = default; + + virtual bool equal(object const &) const; + virtual jtl::immutable_string to_string() const; + virtual void to_string(jtl::string_builder &) const; + virtual jtl::immutable_string to_code_string() const; + virtual uhash to_hash() const; + object_type type{}; }; @@ -278,12 +288,6 @@ namespace jank::runtime::behavior * based on the value, or values, within the object. There are a set of hash functions * which should be used for this in hash.hpp. */ { t->to_hash() } -> std::convertible_to; - - /* Every object needs to have this base field, which is the actual object field. - * When we pass around object pointers, we pass around pointers to this field within - * the overall object. This field stores the type of the object and we use that - * type to shift the object pointer and cast it into the fully typed object. */ - { t->base } -> std::same_as; }; } diff --git a/compiler+runtime/include/cpp/jank/runtime/oref.hpp b/compiler+runtime/include/cpp/jank/runtime/oref.hpp index ca84151b5..7c7c84b3b 100644 --- a/compiler+runtime/include/cpp/jank/runtime/oref.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/oref.hpp @@ -59,7 +59,7 @@ namespace jank::runtime template requires behavior::object_like constexpr oref(T * const typed_data) - : data{ &typed_data->base } + : data{ typed_data } { jank_assert_throw(this->data); } @@ -67,7 +67,7 @@ namespace jank::runtime template requires behavior::object_like constexpr oref(T const * const typed_data) - : data{ const_cast(&typed_data->base) } + : data{ const_cast(typed_data) } { jank_assert_throw(this->data); } @@ -263,7 +263,7 @@ namespace jank::runtime { return std::bit_cast(detail::jank_nil_ptr); } - return &reinterpret_cast(data)->base; + return reinterpret_cast(data); } constexpr bool is_some() const noexcept diff --git a/compiler+runtime/include/cpp/jank/runtime/rtti.hpp b/compiler+runtime/include/cpp/jank/runtime/rtti.hpp index 0576f3217..392679f6e 100644 --- a/compiler+runtime/include/cpp/jank/runtime/rtti.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/rtti.hpp @@ -18,11 +18,7 @@ namespace jank::runtime [[gnu::always_inline, gnu::flatten, gnu::hot]] constexpr oref dyn_cast(object_ref const o) { - if(o->type != T::obj_type) - { - return {}; - } - return reinterpret_cast(reinterpret_cast(o.data) - offsetof(T, base)); + return dynamic_cast(o.data) ?: oref{}; } template @@ -40,7 +36,7 @@ namespace jank::runtime sb(")"); throw std::runtime_error{ sb.str() }; } - return reinterpret_cast(reinterpret_cast(o.data) - offsetof(T, base)); + return dynamic_cast(o.data) ?: oref{}; } /* This is dangerous. You probably don't want it. Just use `try_object` or `visit_object`. @@ -56,7 +52,7 @@ namespace jank::runtime jank_debug_assert(o.is_some()); } jank_debug_assert(o->type == T::obj_type); - return reinterpret_cast(reinterpret_cast(o.data) - offsetof(T, base)); + return dynamic_cast(o.data) ?: oref{}; } template @@ -66,7 +62,6 @@ namespace jank::runtime { jank_debug_assert(o); jank_debug_assert(o->type == T::obj_type); - return reinterpret_cast(reinterpret_cast(const_cast(o)) - - offsetof(T, base)); + return dynamic_cast(o) ?: oref{}; } } diff --git a/compiler+runtime/include/cpp/jank/runtime/var.hpp b/compiler+runtime/include/cpp/jank/runtime/var.hpp index 4a8c5b442..ccd733f49 100644 --- a/compiler+runtime/include/cpp/jank/runtime/var.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/var.hpp @@ -20,7 +20,7 @@ namespace jank::runtime using persistent_hash_map_ref = oref; } - struct var : gc + struct var : object { static constexpr object_type obj_type{ object_type::var }; static constexpr bool pointer_free{ false }; @@ -35,11 +35,11 @@ namespace jank::runtime bool thread_bound); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - jtl::immutable_string to_code_string() const; - void to_string(jtl::string_builder &buff) const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + jtl::immutable_string to_code_string() const override; + void to_string(jtl::string_builder &buff) const override; + uhash to_hash() const override; /* behavior::object_like extended */ bool equal(var const &) const; @@ -82,7 +82,7 @@ namespace jank::runtime std::atomic_bool thread_bound{ false }; }; - struct var_thread_binding : gc + struct var_thread_binding : object { static constexpr object_type obj_type{ object_type::var_thread_binding }; static constexpr bool pointer_free{ false }; @@ -90,11 +90,11 @@ namespace jank::runtime var_thread_binding(object_ref value, std::thread::id id); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; object base{ obj_type }; object_ref value{}; @@ -106,7 +106,7 @@ namespace jank::runtime obj::persistent_hash_map_ref bindings{}; }; - struct var_unbound_root : gc + struct var_unbound_root : object { static constexpr object_type obj_type{ object_type::var_unbound_root }; static constexpr bool pointer_free{ true }; @@ -114,11 +114,11 @@ namespace jank::runtime var_unbound_root(var_ref var); /* behavior::object_like */ - bool equal(object const &) const; - jtl::immutable_string to_string() const; - void to_string(jtl::string_builder &buff) const; - jtl::immutable_string to_code_string() const; - uhash to_hash() const; + bool equal(object const &) const override; + jtl::immutable_string to_string() const override; + void to_string(jtl::string_builder &buff) const override; + jtl::immutable_string to_code_string() const override; + uhash to_hash() const override; object base{ obj_type }; var_ref var; diff --git a/compiler+runtime/include/cpp/jank/runtime/visit.hpp b/compiler+runtime/include/cpp/jank/runtime/visit.hpp index 9f80e7c48..41fdab1a3 100644 --- a/compiler+runtime/include/cpp/jank/runtime/visit.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/visit.hpp @@ -69,7 +69,7 @@ namespace jank::runtime [[gnu::hot]] constexpr auto visit_object(F const &fn, oref const not_erased, Args &&...args) { - return fn(const_cast(¬_erased->base), std::forward(args)...); + return fn(const_cast(not_erased.data), std::forward(args)...); } template diff --git a/compiler+runtime/src/cpp/jank/analyze/cpp_util.cpp b/compiler+runtime/src/cpp/jank/analyze/cpp_util.cpp index 0815503f1..91188ca23 100644 --- a/compiler+runtime/src/cpp/jank/analyze/cpp_util.cpp +++ b/compiler+runtime/src/cpp/jank/analyze/cpp_util.cpp @@ -600,13 +600,12 @@ namespace jank::analyze::cpp_util usize offset_to_typed_object_base(jtl::ptr const type) { jank_debug_assert(is_typed_object(type)); + static auto const base{ Cpp::GetScopeFromCompleteName("jank::runtime::object") }; auto const can_type{ Cpp::GetCanonicalType(type) }; auto const scope{ Cpp::GetUnderlyingScope( Cpp::GetNamed("value_type", Cpp::GetScopeFromType(can_type))) }; jank_debug_assert(scope); - auto const base{ Cpp::LookupDatamember("base", scope) }; - jank_debug_assert(base); - auto const offset{ Cpp::GetVariableOffset(base, scope) }; + auto const offset{ Cpp::GetBaseClassOffset(scope, base) }; return offset; } diff --git a/compiler+runtime/src/cpp/jank/analyze/processor.cpp b/compiler+runtime/src/cpp/jank/analyze/processor.cpp index 890a0bf93..d8cb105e8 100644 --- a/compiler+runtime/src/cpp/jank/analyze/processor.cpp +++ b/compiler+runtime/src/cpp/jank/analyze/processor.cpp @@ -4397,7 +4397,7 @@ namespace jank::analyze { return error::internal_analyze_failure( util::format("Unimplemented analysis for object type '{}'.", - object_type_str(typed_o->base.type)), + object_type_str(typed_o->type)), object_source(o), latest_expansion(macro_expansions)); } diff --git a/compiler+runtime/src/cpp/jank/read/parse.cpp b/compiler+runtime/src/cpp/jank/read/parse.cpp index e1a476585..018e76c97 100644 --- a/compiler+runtime/src/cpp/jank/read/parse.cpp +++ b/compiler+runtime/src/cpp/jank/read/parse.cpp @@ -1380,7 +1380,7 @@ namespace jank::read::parse return err( error::internal_parse_failure(util::format("Unsupported collection: {} [{}]", typed_form->to_code_string(), - object_type_str(typed_form->base.type)))); + object_type_str(typed_form->type)))); } }, /* For anything else, do nothing special aside from quoting. Hopefully that works. */ diff --git a/compiler+runtime/src/cpp/jank/runtime/core/math.cpp b/compiler+runtime/src/cpp/jank/runtime/core/math.cpp index cd21a1046..231c2629a 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/math.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/math.cpp @@ -8,6 +8,490 @@ namespace jank::runtime { + struct integer_ops; + struct real_ops; + + struct number_ops + { + virtual ~number_ops() = default; + + virtual number_ops const &combine(number_ops const &) const = 0; + virtual number_ops const &with(integer_ops const &) const = 0; + virtual number_ops const &with(real_ops const &) const = 0; + + virtual object_ref add() const = 0; + virtual f64 add_real() const = 0; + virtual object_ref subtract() const = 0; + virtual f64 sub_real() const = 0; + virtual object_ref multiply() const = 0; + virtual f64 mul_real() const = 0; + virtual object_ref divide() const = 0; + virtual f64 div_real() const = 0; + virtual object_ref remainder() const = 0; + virtual object_ref inc() const = 0; + virtual object_ref dec() const = 0; + virtual object_ref negate() const = 0; + virtual object_ref abs() const = 0; + virtual object_ref min() const = 0; + virtual f64 min_real() const = 0; + virtual object_ref max() const = 0; + virtual f64 max_real() const = 0; + virtual f64 pow() const = 0; + virtual bool lt() const = 0; + virtual bool lte() const = 0; + virtual bool gte() const = 0; + virtual bool equal() const = 0; + virtual bool is_positive() const = 0; + virtual bool is_negative() const = 0; + virtual bool is_zero() const = 0; + }; + + number_ops &left_ops(object_ref n); + number_ops &right_ops(object_ref n); + + struct integer_ops : number_ops + { + number_ops const &combine(number_ops const &l) const final + { + return l.with(*this); + } + + number_ops const &with(integer_ops const &) const final; + number_ops const &with(real_ops const &) const final; + + object_ref add() const final + { + return make_box(left + right); + } + + f64 add_real() const final + { + return left + right; + } + + object_ref subtract() const final + { + return make_box(left - right); + } + + f64 sub_real() const final + { + return left - right; + } + + object_ref multiply() const final + { + return make_box(left * right); + } + + f64 mul_real() const final + { + return left * right; + } + + object_ref divide() const final + { + return make_box(left / right); + } + + f64 div_real() const final + { + return static_cast(left) / right; + } + + object_ref remainder() const final + { + return make_box(left % right); + } + + object_ref inc() const final + { + return make_box(left + 1); + } + + object_ref dec() const final + { + return make_box(left - 1); + } + + object_ref negate() const final + { + return make_box(-left); + } + + object_ref abs() const final + { + return make_box(std::labs(left)); + } + + object_ref min() const final + { + return make_box(std::min(left, right)); + } + + f64 min_real() const final + { + return std::min(left, right); + } + + object_ref max() const final + { + return make_box(std::max(left, right)); + } + + f64 max_real() const final + { + return std::max(left, right); + } + + f64 pow() const final + { + return std::pow(left, right); + } + + bool lt() const final + { + return left < right; + } + + bool lte() const final + { + return left <= right; + } + + bool gte() const final + { + return left >= right; + } + + bool equal() const final + { + return left == right; + } + + bool is_positive() const final + { + return left > 0; + } + + bool is_negative() const final + { + return left < 0; + } + + bool is_zero() const final + { + return left == 0; + } + + i64 left{}, right{}; + }; + + struct real_ops : number_ops + { + number_ops const &combine(number_ops const &l) const final + { + return l.with(*this); + } + + number_ops const &with(integer_ops const &) const final; + number_ops const &with(real_ops const &) const final; + + object_ref add() const final + { + return make_box(left + right); + } + + f64 add_real() const final + { + return left + right; + } + + object_ref subtract() const final + { + return make_box(left - right); + } + + f64 sub_real() const final + { + return left - right; + } + + object_ref multiply() const final + { + return make_box(left * right); + } + + f64 mul_real() const final + { + return left * right; + } + + object_ref divide() const final + { + return make_box(left / right); + } + + f64 div_real() const final + { + return left / right; + } + + object_ref remainder() const final + { + return make_box(std::fmod(left, right)); + } + + object_ref inc() const final + { + return make_box(left + 1); + } + + object_ref dec() const final + { + return make_box(right + 1); + } + + object_ref negate() const final + { + return make_box(-left); + } + + object_ref abs() const final + { + return make_box(std::fabs(left)); + } + + object_ref min() const final + { + return make_box(std::min(left, right)); + } + + f64 min_real() const final + { + return std::min(left, right); + } + + object_ref max() const final + { + return make_box(std::max(left, right)); + } + + f64 max_real() const final + { + return std::max(left, right); + } + + f64 pow() const final + { + return std::pow(left, right); + } + + bool lt() const final + { + return left < right; + } + + bool lte() const final + { + return left <= right; + } + + bool gte() const final + { + return left >= right; + } + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + + bool equal() const final + { + return left == right; + } + +#pragma clang diagnostic pop + + bool is_positive() const final + { + return left > 0; + } + + bool is_negative() const final + { + return left < 0; + } + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" + + bool is_zero() const final + { + return left == 0; + } + +#pragma clang diagnostic pop + + f64 left{}, right{}; + }; + + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables): These are thread-local. + static thread_local integer_ops i_ops; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables): These are thread-local. + static thread_local real_ops r_ops; + + number_ops const &integer_ops::with(integer_ops const &) const + { + return i_ops; + } + + number_ops const &integer_ops::with(real_ops const &) const + { + r_ops.left = left; + return r_ops; + } + + number_ops const &real_ops::with(integer_ops const &r) const + { + r_ops.right = r.right; + return r_ops; + } + + number_ops const &real_ops::with(real_ops const &) const + { + return r_ops; + } + + number_ops &left_ops(object_ref const n) + { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wswitch-enum" + switch(n->type) + { + case object_type::integer: + { + i_ops.left = expect_object(n)->data; + return i_ops; + } + case object_type::real: + { + r_ops.left = expect_object(n)->data; + return r_ops; + } + default: + /* TODO: Exception type. */ + { + throw std::runtime_error{ util::format("(left_ops) not a number: {}", + runtime::to_code_string(n)) }; + } + } +#pragma clang diagnostic pop + } + + static integer_ops &left_ops(obj::integer_ref const n) + { + i_ops.left = n->data; + return i_ops; + } + + static real_ops &left_ops(obj::real_ref const n) + { + r_ops.left = n->data; + return r_ops; + } + + static integer_ops &left_ops(i64 const n) + { + i_ops.left = n; + return i_ops; + } + + static real_ops &left_ops(f64 const n) + { + r_ops.left = n; + return r_ops; + } + + number_ops &right_ops(object_ref const n) + { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wswitch-enum" + switch(n->type) + { + case object_type::integer: + { + i_ops.right = expect_object(n)->data; + return i_ops; + } + case object_type::real: + { + r_ops.right = expect_object(n)->data; + return r_ops; + } + default: + /* TODO: Exception type. */ + { + throw std::runtime_error{ util::format("(right_ops) not a number: {}", + runtime::to_code_string(n)) }; + } + } +#pragma clang diagnostic pop + } + + static integer_ops &right_ops(obj::integer_ref const n) + { + i_ops.right = n->data; + return i_ops; + } + + static real_ops &right_ops(obj::real_ref const n) + { + r_ops.right = n->data; + return r_ops; + } + + static integer_ops &right_ops(i64 const n) + { + i_ops.right = n; + return i_ops; + } + + static real_ops &right_ops(f64 const n) + { + r_ops.right = n; + return r_ops; + } + + /* This version of `with` avoids two dynamic dispatches per operation, so it's + * preferable over `number_ops.combine`. */ + [[maybe_unused]] + static integer_ops const &with(integer_ops const &, integer_ops const &) + { + return i_ops; + } + + [[maybe_unused]] + static real_ops const &with(real_ops const &, real_ops const &) + { + return r_ops; + } + + static real_ops const &with(integer_ops const &, real_ops const &) + { + r_ops.left = i_ops.left; + return r_ops; + } + + static real_ops const &with(real_ops const &, integer_ops const &) + { + r_ops.right = i_ops.right; + return r_ops; + } + + static number_ops const &with(number_ops const &l, number_ops const &r) + { + return r.combine(l); + } template static f64 to_real(T const &val) @@ -16,6 +500,10 @@ namespace jank::runtime { return static_cast(val); } + else if constexpr(std::is_same_v) + { + return val.template convert_to(); + } else if constexpr(std::is_same_v) { return val.template convert_to(); @@ -35,40 +523,19 @@ namespace jank::runtime } } - /* TODO: visit_number_like */ object_ref add(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> object_ref { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> object_ref { - return make_box(typed_l + typed_r->data).erase(); - }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).add(); } object_ref add(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l + typed_r->data); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).add(); } object_ref add(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data + typed_r); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).add(); } i64 add(obj::integer_ref const l, obj::integer_ref const r) @@ -83,44 +550,32 @@ namespace jank::runtime f64 add(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l + typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).add_real(); } f64 add(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data + typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).add_real(); } f64 add(obj::real_ref const l, obj::integer_ref const r) { - return l->data + static_cast(r->data); + return l->data + r->data; } f64 add(obj::integer_ref const l, obj::real_ref const r) { - return static_cast(l->data) + r->data; + return l->data + r->data; } f64 add(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data + typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).add_real(); } f64 add(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l + typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).add_real(); } f64 add(f64 const l, f64 const r) @@ -130,72 +585,27 @@ namespace jank::runtime f64 add(i64 const l, f64 const r) { - return static_cast(l) + r; + return l + r; } f64 add(f64 const l, i64 const r) - { - return l + static_cast(r); - } - - object_ref add(object_ref const l, i64 const r) - { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data + typed_r); - }, - l, - r); - } - - object_ref add(i64 const l, object_ref const r) - { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l + typed_r->data); - }, - r, - l); - } - - i64 add(i64 const l, i64 const r) { return l + r; } object_ref sub(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> object_ref { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> object_ref { - return make_box(typed_l - typed_r->data).erase(); - }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).subtract(); } object_ref sub(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l - typed_r->data); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).subtract(); } object_ref sub(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data - typed_r); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).subtract(); } i64 sub(obj::integer_ref const l, obj::integer_ref const r) @@ -210,44 +620,32 @@ namespace jank::runtime f64 sub(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l - typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).sub_real(); } f64 sub(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data - typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).sub_real(); } f64 sub(obj::real_ref const l, obj::integer_ref const r) { - return l->data - static_cast(r->data); + return l->data - r->data; } f64 sub(obj::integer_ref const l, obj::real_ref const r) { - return static_cast(l->data) - r->data; + return l->data - r->data; } f64 sub(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data - typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).sub_real(); } f64 sub(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l - typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).sub_real(); } f64 sub(f64 const l, f64 const r) @@ -257,32 +655,22 @@ namespace jank::runtime f64 sub(i64 const l, f64 const r) { - return static_cast(l) - r; + return l - r; } f64 sub(f64 const l, i64 const r) { - return l - static_cast(r); + return l - r; } object_ref sub(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data - typed_r); - }, - l, - r); + return with(left_ops(l), right_ops(r)).subtract(); } object_ref sub(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l - typed_r->data); - }, - r, - l); + return with(left_ops(l), right_ops(r)).subtract(); } i64 sub(i64 const l, i64 const r) @@ -292,37 +680,17 @@ namespace jank::runtime object_ref div(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> object_ref { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> object_ref { - return make_box(typed_l / typed_r->data).erase(); - }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).divide(); } object_ref div(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l / typed_r->data); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).divide(); } object_ref div(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data / typed_r); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).divide(); } i64 div(obj::integer_ref const l, obj::integer_ref const r) @@ -337,44 +705,32 @@ namespace jank::runtime f64 div(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l / typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).div_real(); } f64 div(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data / typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).div_real(); } f64 div(obj::real_ref const l, obj::integer_ref const r) { - return l->data / static_cast(r->data); + return l->data / r->data; } f64 div(obj::integer_ref const l, obj::real_ref const r) { - return static_cast(l->data) / r->data; + return l->data / r->data; } f64 div(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data / typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).div_real(); } f64 div(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l / typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).div_real(); } f64 div(f64 const l, f64 const r) @@ -384,32 +740,22 @@ namespace jank::runtime f64 div(i64 const l, f64 const r) { - return static_cast(l) / r; + return l / r; } f64 div(f64 const l, i64 const r) { - return l / static_cast(r); + return l / r; } object_ref div(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data / typed_r); - }, - l, - r); + return with(left_ops(l), right_ops(r)).divide(); } object_ref div(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l / typed_r->data); - }, - r, - l); + return with(left_ops(l), right_ops(r)).divide(); } i64 div(i64 const l, i64 const r) @@ -419,37 +765,17 @@ namespace jank::runtime object_ref mul(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> object_ref { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> object_ref { - return make_box(typed_l * typed_r->data).erase(); - }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).multiply(); } object_ref mul(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l * typed_r->data); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).multiply(); } object_ref mul(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data * typed_r); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).multiply(); } i64 mul(obj::integer_ref const l, obj::integer_ref const r) @@ -464,44 +790,32 @@ namespace jank::runtime f64 mul(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l * typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).mul_real(); } f64 mul(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data * typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).mul_real(); } f64 mul(obj::real_ref const l, obj::integer_ref const r) { - return l->data * static_cast(r->data); + return l->data * r->data; } f64 mul(obj::integer_ref const l, obj::real_ref const r) { - return static_cast(l->data) * r->data; + return l->data * r->data; } f64 mul(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { return typed_l->data * typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).mul_real(); } f64 mul(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { return typed_l * typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).mul_real(); } f64 mul(f64 const l, f64 const r) @@ -511,32 +825,22 @@ namespace jank::runtime f64 mul(i64 const l, f64 const r) { - return static_cast(l) * r; + return l * r; } f64 mul(f64 const l, i64 const r) { - return l * static_cast(r); + return l * r; } object_ref mul(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return make_box(typed_l->data * typed_r); - }, - l, - r); + return with(left_ops(l), right_ops(r)).multiply(); } object_ref mul(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return make_box(typed_l * typed_r->data); - }, - r, - l); + return with(left_ops(l), right_ops(r)).multiply(); } i64 mul(i64 const l, i64 const r) @@ -880,31 +1184,17 @@ namespace jank::runtime bool lt(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> bool { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> bool { return typed_l < typed_r->data; }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l < typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data < typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(obj::integer_ref const l, obj::integer_ref const r) @@ -919,44 +1209,32 @@ namespace jank::runtime bool lt(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l < typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data < typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(obj::real_ref const l, obj::integer_ref const r) { - return l->data < static_cast(r->data); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(obj::integer_ref const l, obj::real_ref const r) { - return static_cast(l->data) < r->data; + return with(left_ops(l), right_ops(r)).lt(); } bool lt(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data < typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l < typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(f64 const l, f64 const r) @@ -966,28 +1244,22 @@ namespace jank::runtime bool lt(i64 const l, f64 const r) { - return static_cast(l) < r; + return l < r; } bool lt(f64 const l, i64 const r) { - return l < static_cast(r); + return l < r; } bool lt(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data < typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l < typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).lt(); } bool lt(i64 const l, i64 const r) @@ -997,31 +1269,17 @@ namespace jank::runtime bool lte(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> bool { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> bool { return typed_l <= typed_r->data; }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l <= typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data <= typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(obj::integer_ref const l, obj::integer_ref const r) @@ -1036,118 +1294,77 @@ namespace jank::runtime bool lte(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l <= typed_r->data; }, - r, - l->data); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data <= typed_r; }, - l, - r->data); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(obj::real_ref const l, obj::integer_ref const r) { - return l->data <= static_cast(r->data); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(obj::integer_ref const l, obj::real_ref const r) { - return static_cast(l->data) <= r->data; + return with(left_ops(l), right_ops(r)).lte(); } bool lte(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data <= typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l <= typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(f64 const l, f64 const r) { - return l <= r; + return l < r; } bool lte(i64 const l, f64 const r) { - return static_cast(l) <= r; + return l < r; } bool lte(f64 const l, i64 const r) { - return l <= static_cast(r); + return l < r; } bool lte(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> bool { return typed_l->data <= typed_r; }, - l, - r); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> bool { return typed_l <= typed_r->data; }, - r, - l); + return with(left_ops(l), right_ops(r)).lte(); } bool lte(i64 const l, i64 const r) { - return l <= r; + return l < r; } object_ref min(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> object_ref { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> object_ref { - return typed_l < typed_r->data ? make_box(typed_l).erase() - : make_box(typed_r->data).erase(); - }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).min(); } object_ref min(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return typed_l < typed_r->data ? make_box(typed_l).erase() - : make_box(typed_r->data).erase(); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).min(); } object_ref min(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return typed_l->data < typed_r ? make_box(typed_l->data).erase() - : make_box(typed_r).erase(); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).min(); } i64 min(obj::integer_ref const l, obj::integer_ref const r) @@ -1162,26 +1379,12 @@ namespace jank::runtime f64 min(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - using C = std::common_type_t; - return std::min(static_cast(typed_l), static_cast(typed_r_data)); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).min_real(); } f64 min(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::min(static_cast(typed_l_data), static_cast(typed_r)); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).min_real(); } f64 min(obj::real_ref const l, obj::integer_ref const r) @@ -1196,26 +1399,12 @@ namespace jank::runtime f64 min(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::min(static_cast(typed_l_data), static_cast(typed_r)); - }, - l, - r); + return with(left_ops(l), right_ops(r)).min_real(); } f64 min(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - using C = std::common_type_t; - return std::min(static_cast(typed_r_data), static_cast(typed_l)); - }, - r, - l); + return with(left_ops(l), right_ops(r)).min_real(); } f64 min(f64 const l, f64 const r) @@ -1235,22 +1424,12 @@ namespace jank::runtime object_ref min(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return typed_l->data < typed_r ? make_box(typed_l).erase() : make_box(typed_r).erase(); - }, - l, - r); + return with(left_ops(l), right_ops(r)).min(); } object_ref min(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return typed_l < typed_r->data ? make_box(typed_l).erase() : make_box(typed_r).erase(); - }, - r, - l); + return with(left_ops(l), right_ops(r)).min(); } i64 min(i64 const l, i64 const r) @@ -1260,37 +1439,17 @@ namespace jank::runtime object_ref max(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> object_ref { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> object_ref { - return typed_r->data > typed_l ? make_box(typed_r).erase() : make_box(typed_l).erase(); - }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).max(); } object_ref max(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return typed_l > typed_r->data ? make_box(typed_l).erase() : make_box(typed_r).erase(); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).max(); } object_ref max(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return typed_l->data > typed_r ? make_box(typed_l).erase() : make_box(typed_r).erase(); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).max(); } i64 max(obj::integer_ref const l, obj::integer_ref const r) @@ -1305,26 +1464,12 @@ namespace jank::runtime f64 max(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - using C = std::common_type_t; - return std::max(static_cast(typed_l), static_cast(typed_r_data)); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).max_real(); } f64 max(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::max(static_cast(typed_r), static_cast(typed_l_data)); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).max_real(); } f64 max(obj::real_ref const l, obj::integer_ref const r) @@ -1339,26 +1484,12 @@ namespace jank::runtime f64 max(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::max(static_cast(typed_r), static_cast(typed_l_data)); - }, - l, - r); + return with(left_ops(l), right_ops(r)).max_real(); } f64 max(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - using C = std::common_type_t; - return std::max(static_cast(typed_l), static_cast(typed_r_data)); - }, - r, - l); + return with(left_ops(l), right_ops(r)).max_real(); } f64 max(f64 const l, f64 const r) @@ -1378,22 +1509,12 @@ namespace jank::runtime object_ref max(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> object_ref { - return typed_l->data > typed_r ? make_box(typed_l).erase() : make_box(typed_r).erase(); - }, - l, - r); + return with(left_ops(l), right_ops(r)).max(); } object_ref max(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> object_ref { - return typed_l > typed_r->data ? make_box(typed_l).erase() : make_box(typed_r).erase(); - }, - r, - l); + return with(left_ops(l), right_ops(r)).max(); } i64 max(i64 const l, i64 const r) @@ -1403,12 +1524,7 @@ namespace jank::runtime object_ref abs(object_ref const l) { - return visit_number_like( - [](auto const typed_l) -> object_ref { - return typed_l->data < 0ll ? make_box(-1ll * typed_l->data).erase() - : make_box(typed_l->data).erase(); - }, - l); + return left_ops(l).abs(); } i64 abs(obj::integer_ref const l) @@ -1465,45 +1581,17 @@ namespace jank::runtime f64 pow(object_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const r) -> f64 { - return visit_number_like( - [](auto const typed_r, auto const &typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - auto const typed_l_data{ to_real(typed_l) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l_data), static_cast(typed_r_data)); - }, - r, - typed_l->data); - }, - l, - r); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(obj::integer_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - auto const typed_l_data{ to_real(typed_l) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l_data), static_cast(typed_r_data)); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(object_ref const l, obj::integer_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l_data), static_cast(typed_r)); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(obj::integer_ref const l, obj::integer_ref const r) @@ -1518,60 +1606,32 @@ namespace jank::runtime f64 pow(obj::real_ref const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l), static_cast(typed_r_data)); - }, - r, - l->data); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(object_ref const l, obj::real_ref const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l_data), static_cast(typed_r)); - }, - l, - r->data); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(obj::real_ref const l, obj::integer_ref const r) { - return std::pow(l->data, static_cast(r->data)); + return std::pow(l->data, r->data); } f64 pow(obj::integer_ref const l, obj::real_ref const r) { - return std::pow(static_cast(l->data), r->data); + return std::pow(l->data, r->data); } f64 pow(object_ref const l, f64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l_data), static_cast(typed_r)); - }, - l, - r); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(f64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l), static_cast(typed_r_data)); - }, - r, - l); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(f64 const l, f64 const r) @@ -1581,36 +1641,22 @@ namespace jank::runtime f64 pow(i64 const l, f64 const r) { - return std::pow(static_cast(l), r); + return std::pow(l, r); } f64 pow(f64 const l, i64 const r) { - return std::pow(l, static_cast(r)); + return std::pow(l, r); } f64 pow(object_ref const l, i64 const r) { - return visit_number_like( - [](auto const typed_l, auto const typed_r) -> f64 { - auto const typed_l_data{ to_real(typed_l->data) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l_data), static_cast(typed_r)); - }, - l, - r); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(i64 const l, object_ref const r) { - return visit_number_like( - [](auto const typed_r, auto const typed_l) -> f64 { - auto const typed_r_data{ to_real(typed_r->data) }; - using C = std::common_type_t; - return std::pow(static_cast(typed_l), static_cast(typed_r_data)); - }, - r, - l); + return with(left_ops(l), right_ops(r)).pow(); } f64 pow(i64 const l, i64 const r) diff --git a/compiler+runtime/src/cpp/jank/runtime/core/meta.cpp b/compiler+runtime/src/cpp/jank/runtime/core/meta.cpp index 39c043a3a..aa6aeaf67 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/meta.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/meta.cpp @@ -46,7 +46,7 @@ namespace jank::runtime { throw std::runtime_error{ util::format("not metadatable: {} [{}]", typed_o->to_code_string(), - object_type_str(typed_o->base.type)) }; + object_type_str(typed_o->type)) }; } }, o, @@ -91,7 +91,7 @@ namespace jank::runtime { throw std::runtime_error{ util::format("not metadatable: {} [{}]", typed_o->to_code_string(), - object_type_str(typed_o->base.type)) }; + object_type_str(typed_o->type)) }; } }, o, diff --git a/compiler+runtime/src/cpp/jank/runtime/ns.cpp b/compiler+runtime/src/cpp/jank/runtime/ns.cpp index 7d74e4313..52459cdf4 100644 --- a/compiler+runtime/src/cpp/jank/runtime/ns.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/ns.cpp @@ -8,7 +8,8 @@ namespace jank::runtime { ns::ns(obj::symbol_ref const &name) - : name{ name } + : object{ obj_type } + , name{ name } , vars{ obj::persistent_hash_map::empty() } , aliases{ obj::persistent_hash_map::empty() } { diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/array_chunk.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/array_chunk.cpp index 9b14b3442..8cee5b45b 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/array_chunk.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/array_chunk.cpp @@ -6,26 +6,34 @@ namespace jank::runtime::obj { + array_chunk::array_chunk() + : object{ obj_type } + { + } + array_chunk::array_chunk(native_vector const &buffer) - : buffer{ buffer } + : object{ obj_type } + , buffer{ buffer } { } array_chunk::array_chunk(native_vector const &buffer, usize const offset) - : buffer{ buffer } + : object{ obj_type } + , buffer{ buffer } , offset{ offset } { } array_chunk::array_chunk(native_vector &&buffer, usize const offset) - : buffer{ std::move(buffer) } + : object{ obj_type } + , buffer{ std::move(buffer) } , offset{ offset } { } bool array_chunk::equal(object const &o) const { - return &o == &base; + return &o == this; } jtl::immutable_string array_chunk::to_string() const @@ -37,7 +45,7 @@ namespace jank::runtime::obj void array_chunk::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string array_chunk::to_code_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/atom.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/atom.cpp index 02d8c9598..f3246df62 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/atom.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/atom.cpp @@ -6,14 +6,20 @@ namespace jank::runtime::obj { + atom::atom() + : object{ obj_type } + { + } + atom::atom(object_ref const o) - : val{ o.data } + : object{ obj_type } + , val{ o.data } { } bool atom::equal(object const &o) const { - return &o == &base; + return &o == this; } jtl::immutable_string atom::to_string() const @@ -25,7 +31,7 @@ namespace jank::runtime::obj void atom::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string atom::to_code_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/big_integer.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/big_integer.cpp index 1dd1fd314..119a307b5 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/big_integer.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/big_integer.cpp @@ -7,7 +7,6 @@ namespace jank::runtime { - f64 operator+(native_big_integer const &l, f64 const &r) { return obj::big_integer::to_f64(l) + r; @@ -108,23 +107,30 @@ namespace jank::runtime { return l > r || l == r; } - } namespace jank::runtime::obj { + big_integer::big_integer() + : object{ obj_type } + { + } + big_integer::big_integer(native_big_integer const &val) - : data(val) + : object{ obj_type } + , data(val) { } big_integer::big_integer(native_big_integer &&val) - : data(std::move(val)) + : object{ obj_type } + , data(std::move(val)) { } big_integer::big_integer(i64 const val) - : data(val) + : object{ obj_type } + , data(val) { } @@ -154,11 +160,13 @@ namespace jank::runtime::obj } big_integer::big_integer(jtl::immutable_string const &s) + : object{ obj_type } { init(s); } big_integer::big_integer(jtl::immutable_string const &s, i64 const radix, bool const is_negative) + : object{ obj_type } { /* Radix passed from lexer, and it's made sure to be between 2 and 36. */ if(radix == 10) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/character.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/character.cpp index dba8969b0..7ba05b51c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/character.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/character.cpp @@ -33,13 +33,20 @@ namespace jank::runtime::obj } } + character::character() + : object{ obj_type } + { + } + character::character(jtl::immutable_string const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } character::character(char const ch) - : data{ 1, ch } + : object{ obj_type } + , data{ 1, ch } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/chunk_buffer.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/chunk_buffer.cpp index dcdd84cdd..52e290f21 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunk_buffer.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunk_buffer.cpp @@ -5,13 +5,21 @@ namespace jank::runtime::obj { + chunk_buffer::chunk_buffer() + : object{ obj_type } + { + buffer.reserve(capacity); + } + chunk_buffer::chunk_buffer(usize const capacity) - : capacity{ capacity } + : object{ obj_type } + , capacity{ capacity } { buffer.reserve(capacity); } chunk_buffer::chunk_buffer(object_ref const capacity) + : object{ obj_type } { auto const c(to_int(capacity)); if(c < 0) @@ -24,7 +32,7 @@ namespace jank::runtime::obj bool chunk_buffer::equal(object const &o) const { - return &o == &base; + return &o == this; } jtl::immutable_string chunk_buffer::to_string() const @@ -36,7 +44,7 @@ namespace jank::runtime::obj void chunk_buffer::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string chunk_buffer::to_code_string() const 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 7f4bdc6c0..e7b7f69ae 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp @@ -7,15 +7,22 @@ namespace jank::runtime::obj { + chunked_cons::chunked_cons() + : object{ obj_type } + { + } + chunked_cons::chunked_cons(object_ref const head, object_ref const tail) - : head{ head } + : object{ obj_type } + , head{ head } , tail{ tail } { jank_debug_assert(head.is_some()); } chunked_cons::chunked_cons(object_ref const meta, object_ref const head, object_ref const tail) - : head{ head } + : object{ obj_type } + , head{ head } , tail{ tail } , meta{ meta } { @@ -174,7 +181,7 @@ namespace jank::runtime::obj uhash chunked_cons::to_hash() const { - return hash::ordered(&base); + return hash::ordered(this); } cons_ref chunked_cons::conj(object_ref const head) const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp index 1baff1f0b..5a9c25d4f 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp @@ -5,8 +5,14 @@ namespace jank::runtime::obj { + cons::cons() + : object{ obj_type } + { + } + cons::cons(object_ref const head, object_ref const tail) - : head{ head } + : object{ obj_type } + , head{ head } , tail{ tail } { } @@ -63,7 +69,7 @@ namespace jank::runtime::obj return hash; } - return hash = hash::ordered(&base); + return hash = hash::ordered(this); } cons_ref cons::conj(object_ref const head) const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/delay.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/delay.cpp index 41c425990..beda2a4ea 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/delay.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/delay.cpp @@ -5,14 +5,20 @@ namespace jank::runtime::obj { + delay::delay() + : object{ obj_type } + { + } + delay::delay(object_ref const fn) - : fn{ fn } + : object{ obj_type } + , fn{ fn } { } bool delay::equal(object const &o) const { - return &o == &base; + return &o == this; } jtl::immutable_string delay::to_string() const @@ -24,7 +30,7 @@ namespace jank::runtime::obj void delay::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string delay::to_code_string() const 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 612cdd25d..0910b8f14 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 @@ -8,16 +8,23 @@ namespace jank::runtime::obj::detail { + template + base_persistent_map::base_persistent_map() + : object{ PT::obj_type } + { + } + template base_persistent_map::base_persistent_map(jtl::option const &meta) - : meta{ meta } + : object{ PT::obj_type } + , meta{ meta } { } template bool base_persistent_map::equal(object const &o) const { - if(&o == &base) + if(&o == this) { return true; } 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 b42ddcd61..2189f6b68 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 @@ -8,7 +8,8 @@ namespace jank::runtime::obj::detail base_persistent_map_sequence::base_persistent_map_sequence(object_ref const c, IT const &b, IT const &e) - : coll{ c } + : object{ PT::obj_type } + , coll{ c } , begin{ b } , end{ e } { @@ -81,7 +82,7 @@ namespace jank::runtime::obj::detail template uhash base_persistent_map_sequence::to_hash() const { - return hash::unordered(&static_cast(this)->base); + return hash::unordered(static_cast(this)); } template 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 130c3ee07..97e677ce7 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 @@ -15,7 +15,8 @@ namespace jank::runtime::obj::detail It const &b, It const &e, usize const s) - : coll{ c } + : object{ Derived::obj_type } + , coll{ c } , begin{ b } , end{ e } , size{ s } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/inst.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/inst.cpp index b7c73a8bd..9a729b988 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/inst.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/inst.cpp @@ -10,7 +10,8 @@ namespace jank::runtime::obj { inst::inst() - : value{ std::chrono::system_clock::now() } + : object{ obj_type } + , value{ std::chrono::system_clock::now() } { } @@ -57,7 +58,8 @@ namespace jank::runtime::obj #endif inst::inst(jtl::immutable_string const &s) - : value{ inst_from_string(s) } + : object{ obj_type } + , value{ inst_from_string(s) } { } 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 de5917f0a..a8c5daa1d 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp @@ -17,8 +17,14 @@ namespace jank::runtime::obj return lte(val, end); } + integer_range::integer_range() + : object{ obj_type } + { + } + integer_range::integer_range(integer_ref const end) - : start{ make_box(0) } + : object{ obj_type } + , start{ make_box(0) } , end{ end } , step{ make_box(1) } , bounds_check{ static_cast(positive_step_bounds_check) } @@ -26,7 +32,8 @@ namespace jank::runtime::obj } integer_range::integer_range(integer_ref const start, integer_ref const end) - : start{ start } + : object{ obj_type } + , start{ start } , end{ end } , step{ make_box(1) } , bounds_check{ static_cast(positive_step_bounds_check) } @@ -36,7 +43,8 @@ namespace jank::runtime::obj integer_range::integer_range(integer_ref const start, integer_ref const end, integer_ref const step) - : start{ start } + : object{ obj_type } + , start{ start } , end{ end } , step{ step } , bounds_check{ lt(static_cast(0), step.erase()) @@ -49,7 +57,8 @@ namespace jank::runtime::obj integer_ref const end, integer_ref const step, integer_range::bounds_check_t const bounds_check) - : start{ start } + : object{ obj_type } + , start{ start } , end{ end } , step{ step } , bounds_check{ bounds_check } @@ -153,7 +162,7 @@ namespace jank::runtime::obj uhash integer_range::to_hash() const { - return hash::ordered(&base); + return hash::ordered(this); } integer_range_ref integer_range::with_meta(object_ref const m) const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp index c147b1220..356b4d000 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp @@ -5,8 +5,14 @@ namespace jank::runtime::obj { + iterator::iterator() + : object{ obj_type } + { + } + iterator::iterator(object_ref const fn, object_ref const start) - : fn{ fn } + : object{ obj_type } + , fn{ fn } , current{ start } { } @@ -61,24 +67,24 @@ namespace jank::runtime::obj return runtime::sequence_equal(this, &o); } - void iterator::to_string(jtl::string_builder &buff) + void iterator::to_string(jtl::string_builder &buff) const { - runtime::to_string(seq(), buff); + runtime::to_string(const_cast(this)->seq(), buff); } - jtl::immutable_string iterator::to_string() + jtl::immutable_string iterator::to_string() const { - return runtime::to_string(seq()); + return runtime::to_string(const_cast(this)->seq()); } - jtl::immutable_string iterator::to_code_string() + jtl::immutable_string iterator::to_code_string() const { - return runtime::to_code_string(seq()); + return runtime::to_code_string(const_cast(this)->seq()); } uhash iterator::to_hash() const { - return hash::ordered(&base); + return hash::ordered(this); } cons_ref iterator::conj(object_ref const head) const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/jit_closure.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/jit_closure.cpp index 7ac05bc0c..9919471ac 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/jit_closure.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/jit_closure.cpp @@ -11,41 +11,48 @@ namespace jank::runtime::obj { + jit_closure::jit_closure() + : object{ obj_type } + { + } + jit_closure::jit_closure(arity_flag_t const arity_flags, void * const context) - : context{ context } + : object{ obj_type } + , context{ context } , arity_flags{ arity_flags } { } jit_closure::jit_closure(object_ref const meta) - : meta{ meta } + : object{ obj_type } + , meta{ meta } { } bool jit_closure::equal(object const &rhs) const { - return &base == &rhs; + return this == &rhs; } - jtl::immutable_string jit_closure::to_string() + jtl::immutable_string jit_closure::to_string() const { jtl::string_builder buff; to_string(buff); return buff.release(); } - void jit_closure::to_string(jtl::string_builder &buff) + void jit_closure::to_string(jtl::string_builder &buff) const { auto const name(get(meta.unwrap_or(jank_nil), __rt_ctx->intern_keyword("name").expect_ok())); util::format_to( buff, "#object [{} {} {}]", (name->type == object_type::nil ? "unknown" : expect_object(name)->data), - object_type_str(base.type), - &base); + object_type_str(type), + this); } - jtl::immutable_string jit_closure::to_code_string() + jtl::immutable_string jit_closure::to_code_string() const { return to_string(); } @@ -229,6 +236,6 @@ namespace jank::runtime::obj object_ref jit_closure::this_object_ref() { - return &this->base; + return this; } } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/jit_function.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/jit_function.cpp index 06c9badea..755298966 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/jit_function.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/jit_function.cpp @@ -11,40 +11,47 @@ namespace jank::runtime::obj { + jit_function::jit_function() + : object{ obj_type } + { + } + jit_function::jit_function(arity_flag_t const arity_flags) - : arity_flags{ arity_flags } + : object{ obj_type } + , arity_flags{ arity_flags } { } jit_function::jit_function(object_ref const meta) - : meta{ meta } + : object{ obj_type } + , meta{ meta } { } bool jit_function::equal(object const &rhs) const { - return &base == &rhs; + return this == &rhs; } - jtl::immutable_string jit_function::to_string() + jtl::immutable_string jit_function::to_string() const { jtl::string_builder buff; to_string(buff); return buff.release(); } - void jit_function::to_string(jtl::string_builder &buff) + void jit_function::to_string(jtl::string_builder &buff) const { auto const name(get(meta.unwrap_or(jank_nil), __rt_ctx->intern_keyword("name").expect_ok())); util::format_to( buff, "#object [{} {} {}]", (name->type == object_type::nil ? "unknown" : expect_object(name)->data), - object_type_str(base.type), - &base); + object_type_str(type), + this); } - jtl::immutable_string jit_function::to_code_string() + jtl::immutable_string jit_function::to_code_string() const { return to_string(); } @@ -218,6 +225,6 @@ namespace jank::runtime::obj object_ref jit_function::this_object_ref() { - return &this->base; + return this; } } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/keyword.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/keyword.cpp index 88c8c8a64..f0ba149b5 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/keyword.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/keyword.cpp @@ -5,22 +5,29 @@ namespace jank::runtime::obj { + keyword::keyword() + : object{ obj_type } + { + } + keyword::keyword(detail::must_be_interned, jtl::immutable_string_view const &s) - : sym{ make_box(s) } + : object{ obj_type } + , sym{ make_box(s) } { } keyword::keyword(detail::must_be_interned, jtl::immutable_string_view const &ns, jtl::immutable_string_view const &n) - : sym{ make_box(ns, n) } + : object{ obj_type } + , sym{ make_box(ns, n) } { } /* Keywords are interned, so we can always count on identity equality. */ bool keyword::equal(object const &o) const { - return &base == &o; + return this == &o; } static void to_string_impl(symbol const &sym, jtl::string_builder &buff) 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 328597091..8e54f29f6 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp @@ -11,14 +11,21 @@ namespace jank::runtime::obj { + lazy_sequence::lazy_sequence() + : object{ obj_type } + { + } + lazy_sequence::lazy_sequence(object_ref const fn) - : fn{ fn } + : object{ obj_type } + , fn{ fn } { jank_debug_assert(fn.is_some()); } lazy_sequence::lazy_sequence(object_ref const fn, object_ref const sequence) - : fn{ fn } + : object{ obj_type } + , fn{ fn } , s{ 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 2817fc676..688bd931f 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/multi_function.cpp @@ -13,7 +13,8 @@ namespace jank::runtime::obj object_ref const dispatch, object_ref const default_, object_ref const hierarchy) - : dispatch{ dispatch } + : object{ obj_type } + , dispatch{ dispatch } , default_dispatch_value{ default_ } , hierarchy{ hierarchy } , method_table{ persistent_hash_map::empty() } @@ -25,26 +26,26 @@ namespace jank::runtime::obj bool multi_function::equal(object const &rhs) const { - return &base == &rhs; + return this == &rhs; } - jtl::immutable_string multi_function::to_string() + jtl::immutable_string multi_function::to_string() const { jtl::string_builder buff; to_string(buff); return buff.release(); } - void multi_function::to_string(jtl::string_builder &buff) + void multi_function::to_string(jtl::string_builder &buff) const { util::format_to(buff, "#object [{} {} {}]", name->to_string(), - object_type_str(base.type), - &base); + object_type_str(type), + this); } - jtl::immutable_string multi_function::to_code_string() + jtl::immutable_string multi_function::to_code_string() const { return to_string(); } @@ -193,7 +194,7 @@ namespace jank::runtime::obj object_ref multi_function::this_object_ref() { - return &this->base; + return this; } multi_function_ref multi_function::reset() 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 1bcc265c6..3869defc3 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 @@ -5,7 +5,8 @@ namespace jank::runtime::obj { native_array_sequence::native_array_sequence(object_ref * const arr, usize const size) - : arr{ arr } + : object{ obj_type } + , arr{ arr } , size{ size } { jank_debug_assert(arr); @@ -15,7 +16,8 @@ namespace jank::runtime::obj native_array_sequence::native_array_sequence(object_ref * const arr, usize const index, usize const size) - : arr{ arr } + : object{ obj_type } + , arr{ arr } , index{ index } , size{ size } { diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_function_wrapper.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_function_wrapper.cpp index 1645ebb90..5ba8b6cc8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_function_wrapper.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_function_wrapper.cpp @@ -8,24 +8,31 @@ namespace jank::runtime::obj { + native_function_wrapper::native_function_wrapper() + : object{ obj_type } + { + } + native_function_wrapper::native_function_wrapper(detail::function_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } native_function_wrapper::native_function_wrapper(detail::function_type const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } bool native_function_wrapper::equal(object const &o) const { - return &base == &o; + return this == &o; } void native_function_wrapper::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string native_function_wrapper::to_string() const @@ -188,6 +195,6 @@ namespace jank::runtime::obj object_ref native_function_wrapper::this_object_ref() { - return &this->base; + return this; } } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_pointer_wrapper.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_pointer_wrapper.cpp index 75f5da6f6..e2df2598b 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_pointer_wrapper.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_pointer_wrapper.cpp @@ -4,8 +4,14 @@ namespace jank::runtime::obj { + native_pointer_wrapper::native_pointer_wrapper() + : object{ obj_type } + { + } + native_pointer_wrapper::native_pointer_wrapper(void * const d) - : data{ d } + : object{ obj_type } + , data{ d } { } @@ -22,7 +28,7 @@ namespace jank::runtime::obj void native_pointer_wrapper::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string native_pointer_wrapper::to_string() const 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 7603e8e3e..cb3c14429 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 @@ -4,21 +4,30 @@ namespace jank::runtime::obj { + native_vector_sequence::native_vector_sequence() + : object{ obj_type } + { + jank_debug_assert(!this->data.empty()); + } + native_vector_sequence::native_vector_sequence(native_vector const &data, usize index) - : data{ data } + : object{ obj_type } + , data{ data } , index{ index } { jank_debug_assert(!this->data.empty()); } native_vector_sequence::native_vector_sequence(native_vector &&data) - : data{ std::move(data) } + : object{ obj_type } + , data{ std::move(data) } { jank_debug_assert(!this->data.empty()); } native_vector_sequence::native_vector_sequence(native_vector &&data, usize index) - : data{ std::move(data) } + : object{ obj_type } + , data{ std::move(data) } , index{ index } { jank_debug_assert(!this->data.empty()); @@ -26,7 +35,8 @@ namespace jank::runtime::obj native_vector_sequence::native_vector_sequence(jtl::option const &meta, native_vector &&data) - : data{ std::move(data) } + : object{ obj_type } + , data{ std::move(data) } , meta{ meta } { } @@ -56,7 +66,7 @@ namespace jank::runtime::obj return buff.release(); } - uhash native_vector_sequence::to_hash() + uhash native_vector_sequence::to_hash() const { return hash::ordered(data.begin(), data.end()); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp index 76fb5940e..d239cbd17 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/nil.cpp @@ -4,18 +4,23 @@ namespace jank::runtime::obj { + nil::nil() + : object{ obj_type } + { + } + bool nil::equal(object const &o) const { return o.type == obj_type; } - jtl::immutable_string const &nil::to_string() const + jtl::immutable_string nil::to_string() const { static jtl::immutable_string const s{ "nil" }; return s; } - jtl::immutable_string const &nil::to_code_string() const + jtl::immutable_string nil::to_code_string() const { return to_string(); } @@ -42,7 +47,7 @@ namespace jank::runtime::obj object_ref nil::get(object_ref const) { - return &base; + return this; } object_ref nil::get(object_ref const, object_ref const fallback) @@ -52,7 +57,7 @@ namespace jank::runtime::obj object_ref nil::get_entry(object_ref) { - return &base; + return this; } bool nil::contains(object_ref) const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/number.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/number.cpp index 10bf11c54..623e06a08 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/number.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/number.cpp @@ -7,8 +7,14 @@ namespace jank::runtime::obj { /***** boolean *****/ + boolean::boolean() + : object{ obj_type } + { + } + boolean::boolean(bool const d) - : data{ d } + : object{ obj_type } + , data{ d } { } @@ -61,8 +67,14 @@ namespace jank::runtime::obj } /***** integer *****/ + integer::integer() + : object{ obj_type } + { + } + integer::integer(i64 const d) - : data{ d } + : object{ obj_type } + , data{ d } { } @@ -124,8 +136,14 @@ namespace jank::runtime::obj } /***** real *****/ + real::real() + : object{ obj_type } + { + } + real::real(f64 const d) - : data{ d } + : object{ obj_type } + , data{ d } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/opaque_box.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/opaque_box.cpp index 38e30e87c..5de368f20 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/opaque_box.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/opaque_box.cpp @@ -5,7 +5,8 @@ namespace jank::runtime::obj { opaque_box::opaque_box(jtl::ptr const data) - : data{ data } + : object{ obj_type } + , data{ data } { } @@ -22,7 +23,7 @@ namespace jank::runtime::obj void opaque_box::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string opaque_box::to_string() const 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 1890c9651..b13091c26 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 @@ -5,18 +5,26 @@ namespace jank::runtime::obj { + persistent_hash_set::persistent_hash_set() + : object{ obj_type } + { + } + persistent_hash_set::persistent_hash_set(value_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } persistent_hash_set::persistent_hash_set(value_type const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } persistent_hash_set::persistent_hash_set(jtl::option const &meta, value_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } , meta{ meta } { } @@ -43,7 +51,7 @@ namespace jank::runtime::obj bool persistent_hash_set::equal(object const &o) const { - if(&o == &base) + if(&o == this) { return true; } 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 e44056dab..f973f7dd0 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp @@ -6,14 +6,21 @@ namespace jank::runtime::obj { + persistent_list::persistent_list() + : object{ obj_type } + { + } + persistent_list::persistent_list(runtime::detail::native_persistent_list const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } persistent_list::persistent_list(object_ref const meta, runtime::detail::native_persistent_list const &d) - : data{ d } + : object{ obj_type } + , data{ d } , meta{ meta } { } 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 2516fc267..4114f76ba 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 @@ -5,25 +5,34 @@ namespace jank::runtime::obj { + persistent_sorted_set::persistent_sorted_set() + : object{ obj_type } + { + } + persistent_sorted_set::persistent_sorted_set(value_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } persistent_sorted_set::persistent_sorted_set( runtime::detail::native_persistent_sorted_set const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } persistent_sorted_set::persistent_sorted_set(object_ref const meta, value_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } , meta{ meta } { } persistent_sorted_set::persistent_sorted_set(jtl::option const &meta, value_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } , meta{ meta } { } @@ -50,7 +59,7 @@ namespace jank::runtime::obj bool persistent_sorted_set::equal(object const &o) const { - if(&o == &base) + if(&o == this) { return true; } 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 7221ddef5..ccb855482 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp @@ -8,13 +8,20 @@ namespace jank::runtime::obj { + persistent_string::persistent_string() + : object{ obj_type } + { + } + persistent_string::persistent_string(jtl::immutable_string const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } persistent_string::persistent_string(jtl::immutable_string &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } @@ -29,7 +36,7 @@ namespace jank::runtime::obj return data == s->data; } - jtl::immutable_string const &persistent_string::to_string() const + jtl::immutable_string persistent_string::to_string() const { return data; } 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 1ffe3d19a..a3557913f 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 @@ -5,15 +5,22 @@ namespace jank::runtime::obj { + persistent_string_sequence::persistent_string_sequence() + : object{ obj_type } + { + } + persistent_string_sequence::persistent_string_sequence(persistent_string_ref const s) - : str{ s } + : object{ obj_type } + , str{ s } { jank_debug_assert(!s->data.empty()); } persistent_string_sequence::persistent_string_sequence(persistent_string_ref const s, usize const i) - : str{ s } + : object{ obj_type } + , str{ s } , index{ i } { jank_debug_assert(!s->data.empty() && i < s->data.size()); 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 4e4c9f439..49cee633d 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp @@ -9,18 +9,26 @@ namespace jank::runtime::obj { + persistent_vector::persistent_vector() + : object{ obj_type } + { + } + persistent_vector::persistent_vector(value_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } persistent_vector::persistent_vector(value_type const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } persistent_vector::persistent_vector(jtl::option const &meta, value_type &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } , meta{ meta } { } @@ -61,7 +69,7 @@ namespace jank::runtime::obj bool persistent_vector::equal(object const &o) const { - if(&o == &base) + if(&o == this) { return true; } 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 73897a8ea..ef117ee3a 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 @@ -5,15 +5,22 @@ namespace jank::runtime::obj { + persistent_vector_sequence::persistent_vector_sequence() + : object{ obj_type } + { + } + persistent_vector_sequence::persistent_vector_sequence(persistent_vector_ref const v) - : vec{ v } + : object{ obj_type } + , vec{ v } { jank_debug_assert(!v->data.empty()); } persistent_vector_sequence::persistent_vector_sequence(persistent_vector_ref const v, usize const i) - : vec{ v } + : object{ obj_type } + , vec{ v } , index{ i } { jank_debug_assert(index < v->data.size()); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 626e9601d..12a3c509b 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -18,8 +18,14 @@ namespace jank::runtime::obj return lte(val, end); } + range::range() + : object{ obj_type } + { + } + range::range(object_ref const end) - : start{ make_box(0) } + : object{ obj_type } + , start{ make_box(0) } , end{ end } , step{ make_box(1) } , bounds_check{ static_cast(positive_step_bounds_check) } @@ -27,7 +33,8 @@ namespace jank::runtime::obj } range::range(object_ref const start, object_ref const end) - : start{ start } + : object{ obj_type } + , start{ start } , end{ end } , step{ make_box(1) } , bounds_check{ static_cast(positive_step_bounds_check) } @@ -35,7 +42,8 @@ namespace jank::runtime::obj } range::range(object_ref const start, object_ref const end, object_ref const step) - : start{ start } + : object{ obj_type } + , start{ start } , end{ end } , step{ step } , bounds_check{ is_pos(step) ? static_cast(positive_step_bounds_check) @@ -47,7 +55,8 @@ namespace jank::runtime::obj object_ref const end, object_ref const step, range::bounds_check_t const bounds_check) - : start{ start } + : object{ obj_type } + , start{ start } , end{ end } , step{ step } , bounds_check{ bounds_check } @@ -60,7 +69,8 @@ namespace jank::runtime::obj range::bounds_check_t const bounds_check, array_chunk_ref const chunk, range_ptr const chunk_next) - : start{ start } + : object{ obj_type } + , start{ start } , end{ end } , step{ step } , bounds_check{ bounds_check } @@ -210,24 +220,24 @@ namespace jank::runtime::obj return runtime::sequence_equal(this, &o); } - void range::to_string(jtl::string_builder &buff) + void range::to_string(jtl::string_builder &buff) const { - runtime::to_string(seq(), buff); + runtime::to_string(const_cast(this)->seq(), buff); } - jtl::immutable_string range::to_string() + jtl::immutable_string range::to_string() const { - return runtime::to_string(seq()); + return runtime::to_string(const_cast(this)->seq()); } - jtl::immutable_string range::to_code_string() + jtl::immutable_string range::to_code_string() const { - return runtime::to_code_string(seq()); + return runtime::to_code_string(const_cast(this)->seq()); } uhash range::to_hash() const { - return hash::ordered(&base); + return hash::ordered(this); } range_ptr range::with_meta(object_ref const m) const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/ratio.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/ratio.cpp index 39b952afa..909529f83 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/ratio.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/ratio.cpp @@ -65,7 +65,8 @@ namespace jank::runtime::obj } ratio::ratio(ratio_data const &data) - : data{ data } + : object{ obj_type } + , data{ data } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/re_matcher.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/re_matcher.cpp index 57673a760..e4c00df9c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/re_matcher.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/re_matcher.cpp @@ -5,7 +5,8 @@ namespace jank::runtime::obj { re_matcher::re_matcher(re_pattern_ref const re, jtl::immutable_string const &s) - : re{ re } + : object{ obj_type } + , re{ re } , match_input{ s.c_str() } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/re_pattern.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/re_pattern.cpp index 8d58a156d..73fc26dd8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/re_pattern.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/re_pattern.cpp @@ -3,9 +3,9 @@ namespace jank::runtime::obj { - re_pattern::re_pattern(jtl::immutable_string const &s) - : pattern{ s } + : object{ obj_type } + , pattern{ s } , regex{ s.c_str(), std::regex_constants::ECMAScript } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/reduced.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/reduced.cpp index 1e9fce965..7fd7f5a21 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/reduced.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/reduced.cpp @@ -3,15 +3,21 @@ namespace jank::runtime::obj { + reduced::reduced() + : object{ obj_type } + { + } + reduced::reduced(object_ref const o) - : val{ o } + : object{ obj_type } + , val{ o } { jank_debug_assert(val.is_some()); } bool reduced::equal(object const &o) const { - return &o == &base; + return &o == this; } jtl::immutable_string reduced::to_string() const @@ -23,7 +29,7 @@ namespace jank::runtime::obj void reduced::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string reduced::to_code_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp index fdd84f7d4..b4ea7a7d0 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp @@ -6,14 +6,21 @@ namespace jank::runtime::obj { + repeat::repeat() + : object{ obj_type } + { + } + repeat::repeat(object_ref const value) - : value{ value } + : object{ obj_type } + , value{ value } , count{ make_box(infinite) } { } repeat::repeat(object_ref const count, object_ref const value) - : value{ value } + : object{ obj_type } + , value{ value } , count{ count } { if(0 >= to_int(count)) @@ -93,24 +100,24 @@ namespace jank::runtime::obj return runtime::sequence_equal(this, &o); } - void repeat::to_string(jtl::string_builder &buff) + void repeat::to_string(jtl::string_builder &buff) const { - runtime::to_string(seq(), buff); + runtime::to_string(const_cast(this)->seq(), buff); } - jtl::immutable_string repeat::to_string() + jtl::immutable_string repeat::to_string() const { - return runtime::to_string(seq()); + return runtime::to_string(const_cast(this)->seq()); } - jtl::immutable_string repeat::to_code_string() + jtl::immutable_string repeat::to_code_string() const { - return runtime::to_code_string(seq()); + return runtime::to_code_string(const_cast(this)->seq()); } uhash repeat::to_hash() const { - return hash::ordered(&base); + return hash::ordered(this); } repeat_ref repeat::with_meta(object_ref const m) const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/symbol.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/symbol.cpp index 3461decde..a100a0005 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/symbol.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/symbol.cpp @@ -19,24 +19,33 @@ namespace jank::runtime::obj } } + symbol::symbol() + : object{ obj_type } + { + } + symbol::symbol(jtl::immutable_string const &d) + : object{ obj_type } { separate(*this, d); } symbol::symbol(jtl::immutable_string &&d) + : object{ obj_type } { separate(*this, std::move(d)); } symbol::symbol(jtl::immutable_string const &ns, jtl::immutable_string const &n) - : ns{ ns } + : object{ obj_type } + , ns{ ns } , name{ n } { } symbol::symbol(jtl::immutable_string &&ns, jtl::immutable_string &&n) - : ns{ std::move(ns) } + : object{ obj_type } + , ns{ std::move(ns) } , name{ std::move(n) } { } @@ -44,14 +53,16 @@ namespace jank::runtime::obj symbol::symbol(object_ref const meta, jtl::immutable_string const &ns, jtl::immutable_string const &n) - : ns{ ns } + : object{ obj_type } + , ns{ ns } , name{ n } , meta{ meta } { } symbol::symbol(object_ref const ns, object_ref const n) - : ns{ runtime::to_string(ns) } + : object{ obj_type } + , ns{ runtime::to_string(ns) } , name{ runtime::to_string(n) } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/tagged_literal.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/tagged_literal.cpp index eb05c786b..ffb74a59a 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/tagged_literal.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/tagged_literal.cpp @@ -10,7 +10,8 @@ namespace jank::runtime::obj { tagged_literal::tagged_literal(object_ref const tag, object_ref const form) - : tag{ tag } + : object{ obj_type } + , tag{ tag } , form{ form } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/transient_array_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/transient_array_map.cpp index 5d88bc685..2487e2e91 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/transient_array_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/transient_array_map.cpp @@ -11,13 +11,20 @@ namespace jank::runtime::obj { + transient_array_map::transient_array_map() + : object{ obj_type } + { + } + transient_array_map::transient_array_map(runtime::detail::native_array_map &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } transient_array_map::transient_array_map(runtime::detail::native_array_map const &d) - : data{ d } + : object{ obj_type } + , data{ d } { } @@ -29,12 +36,12 @@ namespace jank::runtime::obj bool transient_array_map::equal(object const &o) const { /* Transient equality, in Clojure, is based solely on identity. */ - return &base == &o; + return this == &o; } void transient_array_map::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string transient_array_map::to_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_map.cpp index 538a6be5c..a095220b3 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_map.cpp @@ -10,22 +10,31 @@ namespace jank::runtime::obj { + transient_hash_map::transient_hash_map() + : object{ obj_type } + { + } + transient_hash_map::transient_hash_map(runtime::detail::native_persistent_hash_map &&d) - : data{ std::move(d).transient() } + : object{ obj_type } + , data{ std::move(d).transient() } { } transient_hash_map::transient_hash_map(runtime::detail::native_persistent_hash_map const &d) - : data{ d.transient() } + : object{ obj_type } + , data{ d.transient() } { } transient_hash_map::transient_hash_map(runtime::detail::native_transient_hash_map &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } transient_hash_map::transient_hash_map(runtime::detail::native_array_map const &m) + : object{ obj_type } { for(auto const &e : m) { @@ -41,12 +50,12 @@ namespace jank::runtime::obj bool transient_hash_map::equal(object const &o) const { /* Transient equality, in Clojure, is based solely on identity. */ - return &base == &o; + return this == &o; } void transient_hash_map::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string transient_hash_map::to_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_set.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_set.cpp index c254e8791..168334fe8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_set.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/transient_hash_set.cpp @@ -6,18 +6,26 @@ namespace jank::runtime::obj { + transient_hash_set::transient_hash_set() + : object{ obj_type } + { + } + transient_hash_set::transient_hash_set(runtime::detail::native_persistent_hash_set &&d) - : data{ std::move(d).transient() } + : object{ obj_type } + , data{ std::move(d).transient() } { } transient_hash_set::transient_hash_set(runtime::detail::native_persistent_hash_set const &d) - : data{ d.transient() } + : object{ obj_type } + , data{ d.transient() } { } transient_hash_set::transient_hash_set(runtime::detail::native_transient_hash_set &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } @@ -29,7 +37,7 @@ namespace jank::runtime::obj bool transient_hash_set::equal(object const &o) const { /* Transient equality, in Clojure, is based solely on identity. */ - return &base == &o; + return this == &o; } jtl::immutable_string transient_hash_set::to_string() const @@ -41,7 +49,7 @@ namespace jank::runtime::obj void transient_hash_set::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string transient_hash_set::to_code_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_map.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_map.cpp index 7fbb68553..5b75eb4be 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_map.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_map.cpp @@ -9,18 +9,26 @@ namespace jank::runtime::obj { + transient_sorted_map::transient_sorted_map() + : object{ obj_type } + { + } + transient_sorted_map::transient_sorted_map(runtime::detail::native_persistent_sorted_map &&d) - : data{ std::move(d).transient() } + : object{ obj_type } + , data{ std::move(d).transient() } { } transient_sorted_map::transient_sorted_map(runtime::detail::native_persistent_sorted_map const &d) - : data{ d.transient() } + : object{ obj_type } + , data{ d.transient() } { } transient_sorted_map::transient_sorted_map(runtime::detail::native_transient_sorted_map &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } @@ -32,12 +40,12 @@ namespace jank::runtime::obj bool transient_sorted_map::equal(object const &o) const { /* Transient equality, in Clojure, is based solely on identity. */ - return &base == &o; + return this == &o; } void transient_sorted_map::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string transient_sorted_map::to_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_set.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_set.cpp index 0e92a615a..e28426591 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_set.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/transient_sorted_set.cpp @@ -6,18 +6,26 @@ namespace jank::runtime::obj { + transient_sorted_set::transient_sorted_set() + : object{ obj_type } + { + } + transient_sorted_set::transient_sorted_set(runtime::detail::native_persistent_sorted_set &&d) - : data{ std::move(d).transient() } + : object{ obj_type } + , data{ std::move(d).transient() } { } transient_sorted_set::transient_sorted_set(runtime::detail::native_persistent_sorted_set const &d) - : data{ d.transient() } + : object{ obj_type } + , data{ d.transient() } { } transient_sorted_set::transient_sorted_set(runtime::detail::native_transient_sorted_set &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } @@ -29,7 +37,7 @@ namespace jank::runtime::obj bool transient_sorted_set::equal(object const &o) const { /* Transient equality, in Clojure, is based solely on identity. */ - return &base == &o; + return this == &o; } jtl::immutable_string transient_sorted_set::to_string() const @@ -41,7 +49,7 @@ namespace jank::runtime::obj void transient_sorted_set::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string transient_sorted_set::to_code_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/transient_vector.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/transient_vector.cpp index 4c9ce26a2..daaceb219 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/transient_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/transient_vector.cpp @@ -8,18 +8,26 @@ namespace jank::runtime::obj { + transient_vector::transient_vector() + : object{ obj_type } + { + } + transient_vector::transient_vector(runtime::detail::native_persistent_vector &&d) - : data{ std::move(d).transient() } + : object{ obj_type } + , data{ std::move(d).transient() } { } transient_vector::transient_vector(runtime::detail::native_persistent_vector const &d) - : data{ d.transient() } + : object{ obj_type } + , data{ d.transient() } { } transient_vector::transient_vector(runtime::detail::native_transient_vector &&d) - : data{ std::move(d) } + : object{ obj_type } + , data{ std::move(d) } { } @@ -31,7 +39,7 @@ namespace jank::runtime::obj bool transient_vector::equal(object const &o) const { /* Transient equality, in Clojure, is based solely on identity. */ - return &base == &o; + return this == &o; } jtl::immutable_string transient_vector::to_string() const @@ -43,7 +51,7 @@ namespace jank::runtime::obj void transient_vector::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string transient_vector::to_code_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/uuid.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/uuid.cpp index 38717e840..7475da92d 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/uuid.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/uuid.cpp @@ -29,12 +29,14 @@ namespace jank::runtime::obj } uuid::uuid() - : value{ random() } + : object{ obj_type } + , value{ random() } { } uuid::uuid(jtl::immutable_string const &s) - : value{ from_string(s) } + : object{ obj_type } + , value{ from_string(s) } { } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/volatile.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/volatile.cpp index ad26b9787..58e4a9810 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/volatile.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/volatile.cpp @@ -3,15 +3,22 @@ namespace jank::runtime::obj { + volatile_::volatile_() + : object{ obj_type } + { + jank_debug_assert(val.is_some()); + } + volatile_::volatile_(object_ref const o) - : val{ o } + : object{ obj_type } + , val{ o } { jank_debug_assert(val.is_some()); } bool volatile_::equal(object const &o) const { - return &o == &base; + return &o == this; } jtl::immutable_string volatile_::to_string() const @@ -23,7 +30,7 @@ namespace jank::runtime::obj void volatile_::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "#object [{} {}]", object_type_str(base.type), &base); + util::format_to(buff, "#object [{} {}]", object_type_str(type), this); } jtl::immutable_string volatile_::to_code_string() const diff --git a/compiler+runtime/src/cpp/jank/runtime/object.cpp b/compiler+runtime/src/cpp/jank/runtime/object.cpp index 89878309e..f7fda8f01 100644 --- a/compiler+runtime/src/cpp/jank/runtime/object.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/object.cpp @@ -2,9 +2,42 @@ #include #include #include +#include namespace jank::runtime { + object::object(object_type const t) + : type{ t } + { + } + + bool object::equal(object const &o) const + { + return this == &o; + } + + jtl::immutable_string object::to_string() const + { + jtl::string_builder buff; + to_string(buff); + return buff.release(); + } + + void object::to_string(jtl::string_builder &buff) const + { + util::format_to(buff, "{}@{}", object_type_str(type), this); + } + + jtl::immutable_string object::to_code_string() const + { + return to_string(); + } + + uhash object::to_hash() const + { + return static_cast(reinterpret_cast(this)); + } + bool very_equal_to::operator()(object_ref const lhs, object_ref const rhs) const noexcept { if(lhs->type != rhs->type) diff --git a/compiler+runtime/src/cpp/jank/runtime/var.cpp b/compiler+runtime/src/cpp/jank/runtime/var.cpp index 44f739671..5566fbf8b 100644 --- a/compiler+runtime/src/cpp/jank/runtime/var.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/var.cpp @@ -14,14 +14,16 @@ namespace jank::runtime { var::var(ns_ref const &n, obj::symbol_ref const &name) - : n{ n } + : object{ obj_type } + , n{ n } , name{ name } , root{ make_box(this) } { } var::var(ns_ref const &n, obj::symbol_ref const &name, object_ref const root) - : n{ n } + : object{ obj_type } + , n{ n } , name{ name } , root{ root } { @@ -32,7 +34,8 @@ namespace jank::runtime object_ref const root, bool const dynamic, bool const thread_bound) - : n{ n } + : object{ obj_type } + , n{ n } , name{ name } , root{ root } , dynamic{ dynamic } @@ -182,14 +185,15 @@ namespace jank::runtime } var_thread_binding::var_thread_binding(object_ref const value, std::thread::id const id) - : value{ value } + : object{ obj_type } + , value{ value } , thread_id{ id } { } bool var_thread_binding::equal(object const &o) const { - return &base == &o; + return this == &o; } jtl::immutable_string var_thread_binding::to_string() const @@ -213,13 +217,14 @@ namespace jank::runtime } var_unbound_root::var_unbound_root(var_ref const var) - : var{ var } + : object{ obj_type } + , var{ var } { } bool var_unbound_root::equal(object const &o) const { - return &base == &o; + return this == &o; } jtl::immutable_string var_unbound_root::to_string() const @@ -231,7 +236,7 @@ namespace jank::runtime void var_unbound_root::to_string(jtl::string_builder &buff) const { - util::format_to(buff, "unbound@{} for var {}", &base, var->to_string()); + util::format_to(buff, "unbound@{} for var {}", this, var->to_string()); } jtl::immutable_string var_unbound_root::to_code_string() const