cdhash_cmp: can take rational literals
Rational literals are those integers suffixed with `r`. They tend to
be a part of more complex expressions like `123/456r`, but in theory
they can live alone. When such "bare" rational literals are passed to
case-when branch, we have to take care of them. Fixes [Bug #17854]
---
common.mk | 1 +
compile.c | 7 +++++++
internal/rational.h | 1 +
rational.c | 13 ++++++++++---
test/ruby/test_rational.rb | 7 +++++++
5 files changed, 26 insertions(+), 3 deletions(-)
cdhash_cmp: rational literals with fractions
Nobu kindly pointed out that rational literals can have fractions.
---
compile.c | 5 +++--
test/ruby/test_rational.rb | 4 ++++
2 files changed, 7 insertions(+), 2 deletions(-)
cdhash_cmp: can also take complex
There are complex literals `123i`, which can also be a case condition.
---
compile.c | 15 +++++++++++----
complex.c | 12 +++++++++---
internal/complex.h | 1 +
test/ruby/test_rational.rb | 4 ++++
4 files changed, 25 insertions(+), 7 deletions(-)
cdhash_cmp: recursively apply
For instance a rational's numerator can be a bignum. Comparison using
C's == can be insufficient.
---
compile.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
cdhash_cmp: should use ||
cf: https://github.com/ruby/ruby/pull/4469#discussion_r628386707
---
compile.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
test_cdhash: refactor change class
It is now strange to test Complex in a class named Rational_Test.
---
test/ruby/test_rational.rb | 15 ---------------
test/ruby/test_syntax.rb | 15 +++++++++++++++
2 files changed, 15 insertions(+), 15 deletions(-)
According to MSVC manual (*1), cl.exe can skip including a header file
when that:
- contains #pragma once, or
- starts with #ifndef, or
- starts with #if ! defined.
GCC has a similar trick (*2), but it acts more stricter (e. g. there
must be _no tokens_ outside of #ifndef...#endif).
Sun C lacked #pragma once for a looong time. Oracle Developer Studio
12.5 finally implemented it, but we cannot assume such recent version.
This changeset modifies header files so that each of them include
strictly one #ifndef...#endif. I believe this is the most portable way
to trigger compiler optimizations. [Bug #16770]
*1: https://docs.microsoft.com/en-us/cpp/preprocessor/once
*2: https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html
These headers need no rewrite. Just add some minor tweaks, like
addition of #include lines. Mainly cosmetic.
TIMET_MAX_PLUS_ONE was deleted because the macro was used from only
one place (directly write expression there).
One day, I could not resist the way it was written. I finally started
to make the code clean. This changeset is the beginning of a series of
housekeeping commits. It is a simple refactoring; split internal.h into
files, so that we can divide and concur in the upcoming commits. No
lines of codes are either added or removed, except the obvious file
headers/footers. The generated binary is identical to the one before.