Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from jank-lang/transient
Add initial transient support
- Loading branch information
Showing
27 changed files
with
932 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
namespace jank::runtime::behavior | ||
{ | ||
template <typename T> | ||
concept persistentable = requires(T * const t) { | ||
{ | ||
t->to_persistent() | ||
} -> std::convertible_to<object_ptr>; | ||
}; | ||
|
||
template <typename T> | ||
concept transientable = requires(T * const t) { | ||
{ | ||
t->to_transient() | ||
} -> std::convertible_to<object_ptr>; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include <jank/runtime/object.hpp> | ||
|
||
namespace jank::runtime | ||
{ | ||
template <> | ||
struct static_object<object_type::transient_hash_map> : gc | ||
{ | ||
static constexpr bool pointer_free{ false }; | ||
|
||
using value_type = detail::native_transient_hash_map; | ||
using persistent_type = static_object<object_type::persistent_hash_map>; | ||
|
||
static_object() = default; | ||
static_object(static_object &&) = default; | ||
static_object(static_object const &) = default; | ||
static_object(detail::native_persistent_hash_map const &d); | ||
static_object(detail::native_persistent_hash_map &&d); | ||
static_object(value_type &&d); | ||
|
||
static native_box<static_object> empty() | ||
{ | ||
static auto const ret(make_box<static_object>()); | ||
return ret; | ||
} | ||
|
||
/* behavior::objectable */ | ||
native_bool equal(object const &) const; | ||
native_persistent_string to_string() const; | ||
void to_string(fmt::memory_buffer &buff) const; | ||
native_hash to_hash() const; | ||
|
||
/* behavior::countable */ | ||
size_t count() const; | ||
|
||
/* behavior::associatively_readable */ | ||
object_ptr get(object_ptr const key) const; | ||
object_ptr get(object_ptr const key, object_ptr const fallback) const; | ||
object_ptr get_entry(object_ptr key) const; | ||
native_bool contains(object_ptr key) const; | ||
|
||
/* behavior::associatively_writable_in_place */ | ||
native_box<static_object> assoc_in_place(object_ptr const key, object_ptr const val); | ||
native_box<static_object> dissoc_in_place(object_ptr const key); | ||
|
||
/* behavior::consable_in_place */ | ||
native_box<static_object> cons_in_place(object_ptr head); | ||
|
||
/* behavior::persistentable */ | ||
native_box<persistent_type> to_persistent(); | ||
|
||
/* behavior::callable */ | ||
object_ptr call(object_ptr) const; | ||
object_ptr call(object_ptr, object_ptr) const; | ||
|
||
void assert_active() const; | ||
|
||
object base{ object_type::transient_hash_map }; | ||
value_type data; | ||
mutable native_hash hash{}; | ||
native_bool active{ true }; | ||
}; | ||
|
||
namespace obj | ||
{ | ||
using transient_hash_map = static_object<object_type::transient_hash_map>; | ||
using transient_hash_map_ptr = native_box<transient_hash_map>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
namespace jank::runtime | ||
{ | ||
template <> | ||
struct static_object<object_type::transient_set> : gc | ||
{ | ||
static constexpr bool pointer_free{ false }; | ||
|
||
using value_type = detail::native_transient_set; | ||
using persistent_type = static_object<object_type::persistent_set>; | ||
|
||
static_object() = default; | ||
static_object(static_object &&) noexcept = default; | ||
static_object(static_object const &) = default; | ||
static_object(detail::native_persistent_set const &d); | ||
static_object(detail::native_persistent_set &&d); | ||
static_object(value_type &&d); | ||
|
||
static native_box<static_object> empty() | ||
{ | ||
static auto const ret(make_box<static_object>()); | ||
return ret; | ||
} | ||
|
||
/* behavior::objectable */ | ||
native_bool equal(object const &) const; | ||
native_persistent_string to_string() const; | ||
void to_string(fmt::memory_buffer &buff) const; | ||
native_hash to_hash() const; | ||
|
||
/* behavior::countable */ | ||
size_t count() const; | ||
|
||
/* behavior::consable_in_place */ | ||
native_box<static_object> cons_in_place(object_ptr head); | ||
|
||
/* behavior::persistentable */ | ||
native_box<persistent_type> to_persistent(); | ||
|
||
/* behavior::callable */ | ||
object_ptr call(object_ptr const) const; | ||
object_ptr call(object_ptr const, object_ptr const fallback) const; | ||
|
||
/* behavior::associatively_readable */ | ||
object_ptr get(object_ptr const elem) const; | ||
object_ptr get(object_ptr const elem, object_ptr const fallback) const; | ||
object_ptr get_entry(object_ptr const elem) const; | ||
native_bool contains(object_ptr const elem) const; | ||
|
||
native_box<static_object> disjoin_in_place(object_ptr const elem); | ||
|
||
void assert_active() const; | ||
|
||
object base{ object_type::transient_set }; | ||
value_type data; | ||
mutable native_hash hash{}; | ||
native_bool active{ true }; | ||
}; | ||
|
||
namespace obj | ||
{ | ||
using transient_set = static_object<object_type::transient_set>; | ||
using transient_set_ptr = native_box<transient_set>; | ||
} | ||
} |
Oops, something went wrong.