Ruby: include/ruby/internal/arithmetic/st_data_t.h Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

st_data_t.h
Go to the documentation of this file.
1#ifndef RBIMPL_ARITHMERIC_ST_DATA_T_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_ARITHMERIC_ST_DATA_T_H
23#include "ruby/internal/arithmetic/fixnum.h"
24#include "ruby/internal/arithmetic/long.h"
25#include "ruby/internal/attr/artificial.h"
26#include "ruby/internal/attr/const.h"
27#include "ruby/internal/attr/constexpr.h"
28#include "ruby/internal/cast.h"
29#include "ruby/internal/value.h"
30#include "ruby/assert.h"
31#include "ruby/st.h"
32
33#define ST2FIX RB_ST2FIX
35#define RB_ST2FIX RB_ST2FIX
38 RBIMPL_ATTR_CONST_UNLESS_DEBUG()
39 RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(CXX14)
40 RBIMPL_ATTR_ARTIFICIAL()
58static inline VALUE
59RB_ST2FIX(st_data_t i)
60{
61 SIGNED_VALUE x = i;
62
63 if (x >= 0) {
64 x &= RUBY_FIXNUM_MAX;
65 }
66 else {
67 x |= RUBY_FIXNUM_MIN;
68 }
69
70 RBIMPL_ASSERT_OR_ASSUME(RB_FIXABLE(x));
71 unsigned long y = RBIMPL_CAST((unsigned long)x);
72 return RB_LONG2FIX(y);
73}
74
75#endif /* RBIMPL_ARITHMETIC_ST_DATA_T_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition artificial.h:43
assert.h
RBIMPL_ASSERT_OR_ASSUME
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition assert.h:229
const.h
Defines RBIMPL_ATTR_CONST.
RBIMPL_ATTR_CONST_UNLESS_DEBUG
#define RBIMPL_ATTR_CONST_UNLESS_DEBUG()
Enables RBIMPL_ATTR_CONST if and only if.
Definition const.h:41
constexpr.h
RBIMPL_ATTR_CONSTEXPR.
RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG
#define RBIMPL_ATTR_CONSTEXPR_UNLESS_DEBUG(_)
Enables RBIMPL_ATTR_CONSTEXPR if and only if.
Definition constexpr.h:79
fixnum.h
Handling of integers formerly known as Fixnums.
RB_FIXABLE
#define RB_FIXABLE(_)
Checks if the passed value is in range of fixnum.
Definition fixnum.h:52
RUBY_FIXNUM_MAX
#define RUBY_FIXNUM_MAX
Maximum possible value that a fixnum can represent.
Definition fixnum.h:55
RUBY_FIXNUM_MIN
#define RUBY_FIXNUM_MIN
Minimum possible value that a fixnum can represent.
Definition fixnum.h:58
long.h
Arithmetic conversion between C's long and Ruby's.
RB_LONG2FIX
#define RB_LONG2FIX
Just another name of RB_INT2FIX.
Definition long.h:55
RB_ST2FIX
static VALUE RB_ST2FIX(st_data_t i)
Converts a C's st_data_t into an instance of rb_cInteger.
Definition st_data_t.h:59
value.h
Defines VALUE and ID.
SIGNED_VALUE
intptr_t SIGNED_VALUE
A signed integer type that has the same width with VALUE.
Definition value.h:63
VALUE
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40