Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jianlingzhong committed Nov 27, 2024
1 parent 8bb4005 commit 57e6ed5
Show file tree
Hide file tree
Showing 6 changed files with 366 additions and 378 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace jank::runtime
[[gnu::always_inline, gnu::flatten, gnu::hot]]
inline auto make_box(obj::ratio_data const r)
{
return expect_object<runtime::obj::ratio>(obj::ratio::create(r.numerator, r.denominator));
return make_box<runtime::obj::ratio>(r);
}

[[gnu::always_inline, gnu::flatten, gnu::hot]]
Expand Down
49 changes: 21 additions & 28 deletions compiler+runtime/include/cpp/jank/runtime/obj/ratio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@

namespace jank::runtime
{
template <>
struct static_object<object_type::ratio_data> : gc
{
static constexpr native_bool pointer_free{ true };
static_object() = default;
static_object(static_object &&) = default;
static_object(static_object const &) = default;
static_object(native_integer const numerator, native_integer const denominator);

native_real to_real() const;
void simplify();

native_integer numerator{};
native_integer denominator{};
};

namespace obj
{
using ratio_data = static_object<object_type::ratio_data>;
struct ratio_data
{
ratio_data(native_integer const, native_integer const);
ratio_data(ratio_data const &);
native_real to_real() const;
native_integer to_integer() const;
native_integer numerator{};
native_integer denominator{};
};
}

template <>
Expand All @@ -31,8 +23,9 @@ namespace jank::runtime
static_object() = default;
static_object(static_object &&) = default;
static_object(static_object const &) = default;
static_object(obj::ratio_data const &);

static object_ptr create(native_integer const numerator, native_integer const denominator);
static object_ptr create(native_integer const, native_integer const);
/* behavior::object_like */
native_bool equal(object const &) const;
native_persistent_string to_string() const;
Expand All @@ -51,7 +44,7 @@ namespace jank::runtime
native_real to_real() const;

object base{ object_type::ratio };
obj::ratio_data data{};
obj::ratio_data data;
};

namespace obj
Expand All @@ -78,15 +71,6 @@ namespace jank::runtime
native_real operator-(native_real l, obj::ratio_data r);
obj::ratio_ptr operator-(obj::ratio_data l, native_integer r);
obj::ratio_ptr operator-(native_integer l, obj::ratio_data r);
object_ptr operator/(obj::ratio_data l, obj::ratio_data r);
object_ptr operator/(obj::integer_ptr l, obj::ratio_data r);
obj::ratio_ptr operator/(obj::ratio_data l, obj::integer_ptr r);
native_real operator/(obj::real_ptr l, obj::ratio_data r);
native_real operator/(obj::ratio_data l, obj::real_ptr r);
native_real operator/(obj::ratio_data l, native_real r);
native_real operator/(native_real l, obj::ratio_data r);
obj::ratio_ptr operator/(obj::ratio_data l, native_integer r);
object_ptr operator/(native_integer l, obj::ratio_data r);
object_ptr operator*(obj::ratio_data l, obj::ratio_data r);
object_ptr operator*(obj::integer_ptr l, obj::ratio_data r);
object_ptr operator*(obj::ratio_data l, obj::integer_ptr r);
Expand All @@ -96,6 +80,15 @@ namespace jank::runtime
native_real operator*(native_real l, obj::ratio_data r);
object_ptr operator*(obj::ratio_data l, native_integer r);
object_ptr operator*(native_integer l, obj::ratio_data r);
object_ptr operator/(obj::ratio_data l, obj::ratio_data r);
object_ptr operator/(obj::integer_ptr l, obj::ratio_data r);
obj::ratio_ptr operator/(obj::ratio_data l, obj::integer_ptr r);
native_real operator/(obj::real_ptr l, obj::ratio_data r);
native_real operator/(obj::ratio_data l, obj::real_ptr r);
native_real operator/(obj::ratio_data l, native_real r);
native_real operator/(native_real l, obj::ratio_data r);
obj::ratio_ptr operator/(obj::ratio_data l, native_integer r);
object_ptr operator/(native_integer l, obj::ratio_data r);
native_bool operator==(obj::ratio_data l, obj::ratio_data r);
native_bool operator==(obj::integer_ptr l, obj::ratio_data r);
native_bool operator==(obj::ratio_data l, obj::integer_ptr r);
Expand Down
1 change: 0 additions & 1 deletion compiler+runtime/include/cpp/jank/runtime/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace jank::runtime
integer,
real,
ratio,
ratio_data,

persistent_string,
persistent_string_sequence,
Expand Down
46 changes: 23 additions & 23 deletions compiler+runtime/src/cpp/jank/runtime/core/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ namespace jank::runtime
[](auto const typed_l, auto const r) -> object_ptr {
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> object_ptr {
auto typed_l_data = to_number(typed_l);
auto typed_r_data = to_number(typed_r->data);
auto const typed_l_data{ to_number(typed_l) };
auto const typed_r_data{ to_number(typed_r->data) };
return make_box(std::fmod(typed_l_data, typed_r_data));
},
r,
Expand Down Expand Up @@ -618,8 +618,8 @@ namespace jank::runtime
[](auto const typed_l, auto const r) -> native_bool {
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_bool {
auto data_l = to_number(typed_l);
auto data_r = to_number(typed_r->data);
auto const data_l{ to_number(typed_l) };
auto const data_r{ to_number(typed_r->data) };

using C = std::common_type_t<decltype(data_l), decltype(data_r)>;
#pragma clang diagnostic push
Expand Down Expand Up @@ -1117,7 +1117,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto const typed_r_data{ to_number(typed_r->data) };
using C = std::common_type_t<decltype(typed_l), decltype(typed_r_data)>;
return std::min(static_cast<C>(typed_l), static_cast<C>(typed_r_data));
},
Expand All @@ -1129,7 +1129,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::min(static_cast<C>(typed_l_data), static_cast<C>(typed_r));
},
Expand All @@ -1151,7 +1151,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::min(static_cast<C>(typed_l_data), static_cast<C>(typed_r));
},
Expand All @@ -1163,7 +1163,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto const typed_r_data{ to_number(typed_r->data) };
using C = std::common_type_t<decltype(typed_r_data), decltype(typed_l)>;
return std::min(static_cast<C>(typed_r_data), static_cast<C>(typed_l));
},
Expand Down Expand Up @@ -1260,7 +1260,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto const typed_r_data{ to_number(typed_r->data) };
using C = std::common_type_t<decltype(typed_l), decltype(typed_r_data)>;
return std::max(static_cast<C>(typed_l), static_cast<C>(typed_r_data));
},
Expand All @@ -1272,7 +1272,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::max(static_cast<C>(typed_r), static_cast<C>(typed_l_data));
},
Expand All @@ -1294,7 +1294,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::max(static_cast<C>(typed_r), static_cast<C>(typed_l_data));
},
Expand All @@ -1306,7 +1306,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto const typed_r_data{ to_number(typed_r->data) };
using C = std::common_type_t<decltype(typed_l), decltype(typed_r_data)>;
return std::max(static_cast<C>(typed_l), static_cast<C>(typed_r_data));
},
Expand Down Expand Up @@ -1416,8 +1416,8 @@ namespace jank::runtime
[](auto const typed_l, auto const r) -> native_real {
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto typed_l_data = to_number(typed_l);
auto const typed_r_data{ to_number(typed_r->data) };
auto const typed_l_data{ to_number(typed_l) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r_data)>;
return std::pow(static_cast<C>(typed_l_data), static_cast<C>(typed_r_data));
},
Expand All @@ -1432,8 +1432,8 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto typed_l_data = to_number(typed_l);
auto const typed_r_data{ to_number(typed_r->data) };
auto const typed_l_data{ to_number(typed_l) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r_data)>;
return std::pow(static_cast<C>(typed_l_data), static_cast<C>(typed_r_data));
},
Expand All @@ -1445,7 +1445,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::pow(static_cast<C>(typed_l_data), static_cast<C>(typed_r));
},
Expand All @@ -1467,7 +1467,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto const typed_r_data{ to_number(typed_r->data) };
using C = std::common_type_t<decltype(typed_l), decltype(typed_r_data)>;
return std::pow(static_cast<C>(typed_l), static_cast<C>(typed_r_data));
},
Expand All @@ -1479,7 +1479,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::pow(static_cast<C>(typed_l_data), static_cast<C>(typed_r));
},
Expand All @@ -1501,7 +1501,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::pow(static_cast<C>(typed_l_data), static_cast<C>(typed_r));
},
Expand All @@ -1513,7 +1513,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto const typed_r_data{ to_number(typed_r->data) };
using C = std::common_type_t<decltype(typed_l), decltype(typed_r_data)>;
return std::pow(static_cast<C>(typed_l), static_cast<C>(typed_r_data));
},
Expand All @@ -1540,7 +1540,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_l, auto const typed_r) -> native_real {
auto typed_l_data = to_number(typed_l->data);
auto const typed_l_data{ to_number(typed_l->data) };
using C = std::common_type_t<decltype(typed_l_data), decltype(typed_r)>;
return std::pow(static_cast<C>(typed_l_data), static_cast<C>(typed_r));
},
Expand All @@ -1552,7 +1552,7 @@ namespace jank::runtime
{
return visit_number_like(
[](auto const typed_r, auto const typed_l) -> native_real {
auto typed_r_data = to_number(typed_r->data);
auto const typed_r_data{ to_number(typed_r->data) };
using C = std::common_type_t<decltype(typed_l), decltype(typed_r_data)>;
return std::pow(static_cast<C>(typed_l), static_cast<C>(typed_r_data));
},
Expand Down
Loading

0 comments on commit 57e6ed5

Please sign in to comment.