public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
Make integer conversion functions use native_int
wilson (author)
Mon Jan 28 13:17:47 -0800 2008
commit  1b9f39ef83c1090840510e2a0cf87748b499d561
tree    6ad1a2a124c0a5090d28fdb37a4039d0ec18c051
parent  4bdea7dadb6d5d325fea50c9b25a121da42db501
...
10
11
12
13
14
15
 
16
17
18
...
25
26
27
28
 
29
30
31
...
10
11
12
 
13
14
15
16
17
18
...
25
26
27
 
28
29
30
31
0
@@ -10,9 +10,9 @@ typedef intptr_t native_int;
0
 /* OOP layout:
0
  * [30 bits of data | 2 bits of tag]
0
  * if tag == 00, the whole thing is a pointer to a memory location.
0
- * if tag == 11, the data is a symbol index
0
  * if tag == 01, the data is a fixnum
0
  * if tag == 10, the data is a literal
0
+ * if tag == 11, the data is any data, using the DATA_* macros
0
  */
0
 
0
 #define TAG_MASK 0x3
0
@@ -25,7 +25,7 @@ typedef intptr_t native_int;
0
 
0
 #define TAG(v) (((uintptr_t)v) & TAG_MASK)
0
 #define APPLY_TAG(v, tag) ((OBJECT)(((uintptr_t)v << TAG_SHIFT) | tag))
0
-#define STRIP_TAG(v) (((intptr_t)v) >> TAG_SHIFT)
0
+#define STRIP_TAG(v) (((uintptr_t)v) >> TAG_SHIFT)
0
 
0
 #define DATA_P(v) (TAG(v) == TAG_DATA)
0
 #define FIXNUM_P(v) (TAG(v) == TAG_FIXNUM)
...
180
181
182
183
 
184
185
186
187
188
189
190
191
 
 
192
 
 
193
194
195
196
197
198
 
199
200
 
 
201
202
203
204
205
206
207
...
210
211
212
213
214
 
 
215
 
 
216
217
218
219
220
221
 
222
223
 
 
224
225
226
227
228
229
230
...
234
235
236
237
238
 
239
 
 
240
241
242
243
244
...
180
181
182
 
183
184
185
186
187
188
189
 
 
190
191
192
193
194
195
 
196
197
198
199
200
201
 
202
203
204
205
 
 
206
207
208
...
211
212
213
 
 
214
215
216
217
218
219
 
220
221
222
223
224
225
 
226
227
228
229
 
 
230
231
232
...
236
237
238
 
 
239
240
241
242
243
 
244
245
246
0
@@ -180,28 +180,29 @@ void XFREE(void *p);
0
 #define FREE(v) XFREE(v)
0
 
0
 static inline native_int rbs_to_int(OBJECT obj) {
0
- return STRIP_TAG(obj);
0
+ return (native_int)STRIP_TAG(obj);
0
 }
0
 
0
 static inline OBJECT rbs_int_to_numeric(STATE, int num) {
0
   OBJECT ret;
0
   ret = APPLY_TAG(num, TAG_FIXNUM);
0
 
0
- /* Number is too big for fixnum. Use bignum. */
0
- if((int)rbs_to_int(ret) != num) {
0
+ /* Number is too big for Fixnum. Use Bignum. */
0
+ if((native_int)rbs_to_int(ret) != num) {
0
     return bignum_new(state, num);
0
+ } else {
0
+ return ret;
0
   }
0
- return ret;
0
 }
0
 
0
 static inline OBJECT rbs_uint_to_numeric(STATE, unsigned int num) {
0
   OBJECT ret;
0
+ ret = APPLY_TAG(num, TAG_FIXNUM);
0
 
0
- if (num > FIXNUM_MAX) {
0
+ /* Number is too big for Fixnum. Use Bignum. */
0
+ if((native_int)rbs_to_int(ret) != num) {
0
     return bignum_new_unsigned(state, num);
0
   } else {
0
- ret = APPLY_TAG(num, TAG_FIXNUM);
0
- rbs_to_int(ret);
0
     return ret;
0
   }
0
 }
0
@@ -210,21 +211,22 @@ static inline OBJECT rbs_ll_to_numeric(STATE, long long num) {
0
   OBJECT ret;
0
   ret = APPLY_TAG(num, TAG_FIXNUM);
0
 
0
- /* Number is too big for fixnum. Use bignum. */
0
- if((int)rbs_to_int(ret) != num) {
0
+ /* Number is too big for Fixnum. Use Bignum. */
0
+ if((native_int)rbs_to_int(ret) != num) {
0
     return bignum_from_ll(state, num);
0
+ } else {
0
+ return ret;
0
   }
0
- return ret;
0
 }
0
 
0
 static inline OBJECT rbs_ull_to_numeric(STATE, unsigned long long num) {
0
   OBJECT ret;
0
+ ret = APPLY_TAG(num, TAG_FIXNUM);
0
 
0
- if (num > FIXNUM_MAX) {
0
+ /* Number is too big for Fixnum. Use Bignum. */
0
+ if((native_int)rbs_to_int(ret) != num) {
0
     return bignum_from_ull(state, num);
0
   } else {
0
- ret = APPLY_TAG(num, TAG_FIXNUM);
0
- rbs_to_int(ret);
0
     return ret;
0
   }
0
 }
0
@@ -234,11 +236,11 @@ static inline OBJECT rbs_max_long_to_numeric(STATE, long long num) {
0
   ret = APPLY_TAG(num, TAG_FIXNUM);
0
 
0
   /* Number is too big for Fixnum. Use Bignum. */
0
- /* TODO - Change this to native_int when Fixnum becomes platform-specific */
0
- if((int)rbs_to_int(ret) != num) {
0
+ if((native_int)rbs_to_int(ret) != num) {
0
     return bignum_from_ll(state, num);
0
+ } else {
0
+ return ret;
0
   }
0
- return ret;
0
 }
0
 
0
 static inline double rbs_fixnum_to_double(OBJECT obj) {

Comments

    No one has commented yet.