-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port conversions to c++ #200
base: main
Are you sure you want to change the base?
Conversation
b7ef90d
to
df695e3
Compare
70472ad
to
d9ae65c
Compare
This is awesome! Will do a live code review on the next live stream! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is 🔥 Thanks for opening the PR. Comments below or for the first 200 lines.
jsrc/conversions.cpp
Outdated
[[nodiscard]] constexpr auto | ||
in_range(V value) -> bool { | ||
if constexpr (std::is_same_v<bool, V>) { | ||
(void)value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems indeed unnecessary, I think I had some compiler errors with bool at the time, but don't remember exactly what
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the reason for the special case, however, I think I'll just disable the warning
../jsrc/conversions.cpp:29:45: error: comparison of constant ‘-9223372036854775808’ with boolean expression is always true [-Werror=bool-compare]
--
jsrc/conversions.cpp
Outdated
|
||
template <> | ||
[[nodiscard]] auto | ||
convert<D, bool>(J jt, array w, void *yv, D fuzz) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to avoid the D macro
convert<D, bool>(J jt, array w, void *yv, D fuzz) -> bool { | |
convert<D, bool>(J jt, array w, void *yv, double fuzz) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe same goes for all the others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did D
-> double
and I
-> int64_t
(and one last B
-> bool
)
most others are j specific structs
ps. typedefs not macros
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The different width integer types (1, 2, 3, 4 bytes; UC, US...) could possibly be replaced, but seeing the compiler, I'd postpone that to whenever those typedefs are refactored.
template <> | ||
[[nodiscard]] auto | ||
convert<Z, D>(J jt, array w, void *yv, D fuzz) -> bool { | ||
if (fuzz != 0.0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original test was if (fuzz)
, not sure if these have differences
jsrc/conversions.cpp
Outdated
return convert<B, X>(jt, | ||
w, | ||
yv, | ||
[=](auto v) { | ||
int64_t u[] = {v}; | ||
return jtvec(jt, INT, 1L, u); | ||
}) && | ||
!jt->jerr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See if you can do something like this: (not {v}
might not work.
return convert<B, X>(jt, | |
w, | |
yv, | |
[=](auto v) { | |
int64_t u[] = {v}; | |
return jtvec(jt, INT, 1L, u); | |
}) && | |
!jt->jerr; | |
auto name_me = [=](auto v) { return jtvec(jt, INT, 1L, {v}); }; | |
return convert<B, X>(jt, w, yv, name_me) && !jt->jerr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{v}
won't work in the parameter list, the function takes void*
switch (mode) { | ||
case XMFLR: p = e; break; | ||
case XMCEIL: p = ceil(p); break; | ||
case XMEXACT: | ||
ASSERT(TEQ(p, e), EVDOMAIN); | ||
p = e; | ||
break; | ||
case XMEXMT: | ||
if (!TEQ(p, e)) { return jtvec(jt, INT, 0L, &iotavec[-IOTAVECBEGIN]); } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch (mode) { | |
case XMFLR: p = e; break; | |
case XMCEIL: p = ceil(p); break; | |
case XMEXACT: | |
ASSERT(TEQ(p, e), EVDOMAIN); | |
p = e; | |
break; | |
case XMEXMT: | |
if (!TEQ(p, e)) { return jtvec(jt, INT, 0L, &iotavec[-IOTAVECBEGIN]); } | |
} | |
if (!TEQ(p, e)) return jtvec(jt, INT, 0L, &iotavec[-IOTAVECBEGIN]); | |
p = mode == XMEXACT ? e : ceil(p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor would invalidate the meaning of the modes (if the comments are up to date)
Lines 20 to 23 in 5f03cf2
#define XMFLR 0 /* floor, round down */ | |
#define XMCEIL 1 /* ceiling, round up */ | |
#define XMEXACT 2 /* exact, error if impossible */ | |
#define XMEXMT 3 /* exact, empty if impossible */ |
e35c7cc
to
ddbcc44
Compare
Also use std::copy_n() instead of std::copy() in convert() Also also, I kind of understand, but wtf: std::numeric_limits<T>::min() and std::numeric_limits<T>::lowest() Now fixed behaviour with double (and bool)
CI compiler is giving somewhat ambiguous error:
No idea how it thinks Turned out the CI compiler had different idea of |
The macro definition had parentheses, which made it work
984cba4
to
1224af8
Compare
1224af8
to
c993b44
Compare
b4051a4
to
86ae356
Compare
The main funtion doing the conversion work is
convert<From, To>()
. The external interface is unchanged (except B -> bool).From
may exceedTo
s value range.std::optional<T>
, astd::nullopt
signals failure and is checkedAlso added template parameter to specify return type of
pointer_to_values()
(e9e7f41).This changes the semantics of
set_value_at()
to depend on the type of thevalue
:This allows use of
set_value_at()
with types wider than, or not convertible to,int64_t
.However, this requires more care with the
value
parameter, it must be the correct type (correct bit width), to get the correct stride.