author | Claus Gittinger <cg@exept.de> |
Thu, 02 Sep 1999 23:44:11 +0200 | |
changeset 4670 | 21eec331e1e9 |
parent 4661 | 9ebc7608738d |
child 4827 | 905b98a07798 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
214 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Integer subclass:#SmallInteger |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
14 |
instanceVariableNames:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
15 |
classVariableNames:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
16 |
poolDictionaries:'' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
17 |
category:'Magnitude-Numbers' |
1 | 18 |
! |
19 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
20 |
!SmallInteger class methodsFor:'documentation'! |
1 | 21 |
|
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
214 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
68 | 36 |
documentation |
37 |
" |
|
88 | 38 |
SmallIntegers are Integers in the range of at least +/- 2^30 |
2785 | 39 |
(i.e. 31 bits, which is not a guaranteed: on an alpha, 63 bits are used, |
40 |
if the system was configured for 64bit mode). |
|
88 | 41 |
|
68 | 42 |
These are no real objects - they have no instances (not even storage !!) |
43 |
and cannot be subclassed. |
|
44 |
The reason is to save both storage and runtime by not collecting |
|
45 |
SmallIntegers in the system. SmallInts are marked by having the TAG_INT |
|
88 | 46 |
bit set, in contrast to all other objects which do not. |
47 |
Since this knowledge is hardwired into the system (and there is no |
|
48 |
class-field stored with SmallIntegers) there can be no subclass of |
|
49 |
SmallInteger (sorry). |
|
50 |
||
51 |
If you really need this kind of thing, create a subclass of Integer, |
|
52 |
with an instance variable holding the value. |
|
1295 | 53 |
|
54 |
[author:] |
|
2216 | 55 |
Claus Gittinger |
1556 | 56 |
|
57 |
[see also:] |
|
2216 | 58 |
Number |
59 |
Float Fraction FixedPoint |
|
60 |
LargeInteger |
|
68 | 61 |
" |
62 |
! ! |
|
1 | 63 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
64 |
!SmallInteger class methodsFor:'instance creation'! |
1 | 65 |
|
66 |
basicNew |
|
67 |
"catch instance creation |
|
68 |
- SmallIntegers cannot be created with new" |
|
69 |
||
70 |
self error:'instances of SmallInteger cannot be created with new' |
|
71 |
! |
|
72 |
||
73 |
basicNew:size |
|
74 |
"catch instance creation |
|
75 |
- SmallIntegers cannot be created with new" |
|
76 |
||
77 |
self error:'instances of SmallInteger cannot be created with new' |
|
78 |
! ! |
|
79 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
80 |
!SmallInteger class methodsFor:'bit mask constants'! |
701 | 81 |
|
82 |
bitMaskFor:index |
|
83 |
"return a bitmask for the index's bit (index starts at 1)" |
|
84 |
||
85 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
|
4523
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
86 |
^ SubscriptOutOfBoundsSignal |
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
87 |
raiseRequestWith:index |
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
88 |
errorString:'index out of bounds' |
701 | 89 |
]. |
90 |
^ 1 bitShift:(index - 1) |
|
91 |
! ! |
|
92 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
93 |
!SmallInteger class methodsFor:'constants'! |
1 | 94 |
|
95 |
maxBits |
|
68 | 96 |
"return the number of bits in instances of me. |
97 |
For very special uses only - not constant across implementations" |
|
1 | 98 |
|
99 |
%{ /* NOCONTEXT */ |
|
1133 | 100 |
RETURN ( __MKSMALLINT(N_INT_BITS) ); |
1 | 101 |
%} |
2 | 102 |
|
103 |
"SmallInteger maxBits" |
|
1 | 104 |
! |
105 |
||
106 |
maxBytes |
|
68 | 107 |
"return the number of bytes in instances of me. |
108 |
For very special uses only - not constant across implementations" |
|
1 | 109 |
|
110 |
%{ /* NOCONTEXT */ |
|
1133 | 111 |
RETURN ( __MKSMALLINT(N_INT_BITS / 8 + 1) ); |
1 | 112 |
%} |
2 | 113 |
|
3684 | 114 |
" |
115 |
SmallInteger maxBytes |
|
116 |
" |
|
1 | 117 |
! |
118 |
||
119 |
maxVal |
|
68 | 120 |
"return the largest Integer representable as SmallInteger. |
121 |
For very special uses only - not constant across implementations" |
|
1 | 122 |
|
123 |
%{ /* NOCONTEXT */ |
|
1133 | 124 |
RETURN ( __MKSMALLINT(_MAX_INT) ); |
1 | 125 |
%} |
2 | 126 |
|
127 |
"SmallInteger maxVal" |
|
701 | 128 |
! |
129 |
||
130 |
minVal |
|
131 |
"return the smallest Integer representable as SmallInteger. |
|
132 |
For very special uses only - not constant across implementations" |
|
133 |
||
134 |
%{ /* NOCONTEXT */ |
|
1133 | 135 |
RETURN ( __MKSMALLINT(_MIN_INT) ); |
701 | 136 |
%} |
137 |
||
138 |
"SmallInteger minVal" |
|
1 | 139 |
! ! |
140 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
141 |
!SmallInteger class methodsFor:'queries'! |
3 | 142 |
|
50 | 143 |
canBeSubclassed |
144 |
"return true, if its allowed to create subclasses of the receiver. |
|
3914 | 145 |
Return false here - since it is NOT possible for SmallInteger |
146 |
(due to the tagged representation of SmallIntegers)" |
|
50 | 147 |
|
148 |
^ false |
|
3914 | 149 |
|
150 |
"Modified: / 5.11.1998 / 16:11:27 / cg" |
|
1 | 151 |
! |
152 |
||
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
153 |
hasImmediateInstances |
4661 | 154 |
"return true if this class has immediate instances |
155 |
i.e. if the instances are represented in the pointer itself and |
|
156 |
no real object header/storage is used for the object. |
|
2672
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
157 |
Redefined from Behavior" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
158 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
159 |
^ true |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
160 |
|
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
161 |
"Created: 3.6.1997 / 12:01:26 / cg" |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
162 |
! |
dc3662188b2c
added #hasImmediateInstances for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2653
diff
changeset
|
163 |
|
701 | 164 |
isBuiltInClass |
1264 | 165 |
"return true if this class is known by the run-time-system. |
166 |
Here, true is returned." |
|
1 | 167 |
|
168 |
^ true |
|
1264 | 169 |
|
170 |
"Modified: 23.4.1996 / 16:00:33 / cg" |
|
1 | 171 |
! ! |
172 |
||
173 |
!SmallInteger methodsFor:'arithmetic'! |
|
174 |
||
175 |
* aNumber |
|
176 |
"return the product of the receivers value and the arguments value" |
|
177 |
||
178 |
%{ /* NOCONTEXT */ |
|
179 |
||
68 | 180 |
INT myValue, otherValue; |
181 |
unsigned INT productLow, productHi; |
|
182 |
int negative; |
|
183 |
||
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
184 |
# define low16Bits(foo) ((foo) & 0xFFFF) |
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
185 |
# define hi16Bits(foo) ((foo) >> 16) |
2785 | 186 |
# define low32Bits(foo) ((foo) & 0xFFFFFFFFL) |
187 |
# define hi32Bits(foo) ((foo) >> 32) |
|
95 | 188 |
|
189 |
/* |
|
190 |
* can we use long long arithmetic ? |
|
4176 | 191 |
* |
192 |
* long-long arithmetic seems to be buggy with some systems |
|
193 |
* (took me a while to find this out :-( |
|
194 |
* (try 10000 * 10000) |
|
95 | 195 |
*/ |
4176 | 196 |
#if defined(sparc) && defined(__GNUC__) && (__GNUC__ >= 2) |
4184 | 197 |
# define USE_LONGLONG_FOR_MUL |
4176 | 198 |
#endif |
199 |
||
200 |
#if defined(i386) && defined(__GNUC__) && (__GNUC__ >= 2) |
|
4184 | 201 |
# define USE_LONGLONG_FOR_MUL |
95 | 202 |
#endif |
1 | 203 |
|
252 | 204 |
if (__isSmallInteger(aNumber)) { |
4176 | 205 |
myValue = __intVal(self); |
206 |
otherValue = __intVal(aNumber); |
|
2785 | 207 |
|
4184 | 208 |
#if defined(USE_LONGLONG_FOR_MUL) |
4176 | 209 |
{ |
2785 | 210 |
# if defined(alpha) && !defined(alpha64) |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
211 |
# define LONGLONG INT64 |
2785 | 212 |
# else |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
213 |
# define LONGLONG long long |
2785 | 214 |
# endif |
4176 | 215 |
LONGLONG product; |
216 |
||
217 |
product = (LONGLONG)myValue * (LONGLONG)otherValue; |
|
218 |
if ((product >= (LONGLONG)_MIN_INT) |
|
219 |
&& (product <= (LONGLONG)_MAX_INT)) { |
|
220 |
RETURN ( __MKSMALLINT((INT)product) ); |
|
221 |
} |
|
222 |
if (product < 0) { |
|
223 |
negative = -1; |
|
224 |
product = -product; |
|
225 |
} else { |
|
226 |
negative = 1; |
|
227 |
} |
|
228 |
productHi = product >> 32; |
|
229 |
productLow = product & 0xFFFFFFFFL; |
|
230 |
} |
|
231 |
#else /* no long-long */ |
|
232 |
negative = 1; |
|
233 |
if (myValue < 0) { |
|
234 |
negative = -1; |
|
235 |
myValue = -myValue; |
|
236 |
} |
|
237 |
if (otherValue < 0) { |
|
238 |
negative = -negative; |
|
239 |
otherValue = -otherValue; |
|
240 |
} |
|
68 | 241 |
|
242 |
# if defined(__GNUC__) && defined(mc68k) |
|
4176 | 243 |
asm ("mulu%.l %3,%1:%0" |
244 |
: "=d" ((unsigned long)(productLow)), |
|
245 |
"=d" ((unsigned long)(productHi)) |
|
246 |
: "%0" ((unsigned long)(myValue)), |
|
247 |
"dmi" ((unsigned long)(otherValue))); |
|
68 | 248 |
# else |
249 |
# if defined (__GNUC__) && defined(i386) |
|
4176 | 250 |
asm ("mull %3" |
251 |
: "=a" ((unsigned long)(productLow)), |
|
252 |
"=d" ((unsigned long)(productHi)) |
|
253 |
: "%0" ((unsigned long)(myValue)), |
|
254 |
"rm" ((unsigned long)(otherValue))); |
|
68 | 255 |
# else |
4167 | 256 |
# if defined(WIN32) |
4176 | 257 |
asm { |
258 |
mov eax, myValue |
|
259 |
mov edx, otherValue |
|
260 |
mul edx |
|
261 |
mov productLow, eax |
|
262 |
mov productHi, edx |
|
263 |
} |
|
4167 | 264 |
# else /* generic */ |
4176 | 265 |
{ |
266 |
unsigned INT pHH, pHL, pLH, pLL; |
|
267 |
unsigned INT low1, low2, hi1, hi2; |
|
268 |
unsigned INT t; |
|
269 |
||
270 |
/* unsigned multiply myValue * otherValue -> productHi, productLow |
|
271 |
* |
|
272 |
* this is too slow: |
|
273 |
* since most machines can do 32*32 to 64 bit multiply, |
|
274 |
* (or at least 32*32 with Overflow check) |
|
275 |
* - need more assembler (inline) functions here |
|
276 |
*/ |
|
4167 | 277 |
# ifdef alpha64 |
4176 | 278 |
low1 = low32Bits((unsigned INT)myValue); |
279 |
hi1 = hi32Bits((unsigned INT)myValue); |
|
280 |
low2 = low32Bits((unsigned INT)otherValue); |
|
281 |
hi2 = hi32Bits((unsigned INT)otherValue); |
|
4167 | 282 |
# define LLMASK 0xC000000000000000L |
283 |
# else |
|
4176 | 284 |
low1 = low16Bits((unsigned INT)myValue); |
285 |
hi1 = hi16Bits((unsigned INT)myValue); |
|
286 |
low2 = low16Bits((unsigned INT)otherValue); |
|
287 |
hi2 = hi16Bits((unsigned INT)otherValue); |
|
4167 | 288 |
# define LLMASK 0xC0000000 |
289 |
# endif |
|
290 |
||
4176 | 291 |
pLH = low1 * hi2; |
292 |
pHL = hi1 * low2; |
|
293 |
pLL = low1 * low2; |
|
294 |
pHH = hi1 * hi2; |
|
68 | 295 |
|
4176 | 296 |
/* |
297 |
* the common case ... |
|
298 |
*/ |
|
299 |
if ((pHL == 0) |
|
300 |
&& (pLH == 0) |
|
301 |
&& (pHH == 0) |
|
302 |
&& ((pLL & LLMASK) == 0)) { |
|
303 |
if (negative < 0) { |
|
304 |
RETURN ( __MKSMALLINT(- ((INT)pLL)) ); |
|
305 |
} |
|
306 |
RETURN ( __MKSMALLINT((INT)pLL) ); |
|
307 |
} |
|
308 |
||
309 |
/* |
|
310 |
* pHH |--------|--------| |
|
311 |
* pLH |--------|--------| |
|
312 |
* pHL |--------|--------| |
|
313 |
* pLL |--------|--------| |
|
314 |
*/ |
|
4167 | 315 |
|
316 |
# ifdef alpha64 |
|
4176 | 317 |
t = low32Bits(pLH) + low32Bits(pHL) + hi32Bits(pLL); |
318 |
productLow = (t << 32) + low32Bits(pLL); |
|
319 |
productHi = pHH + hi32Bits(t) + hi32Bits(pHL) + hi32Bits(pLH); |
|
4167 | 320 |
# else |
4176 | 321 |
t = low16Bits(pLH) + low16Bits(pHL) + hi16Bits(pLL); |
322 |
productLow = (t << 16) + low16Bits(pLL); |
|
323 |
productHi = pHH + hi16Bits(t) + hi16Bits(pHL) + hi16Bits(pLH); |
|
4167 | 324 |
# endif |
4176 | 325 |
} |
4167 | 326 |
# endif /* ! WIN32 */ |
327 |
# endif /* ! (__GNUC__ && i386) */ |
|
328 |
# endif /* ! (__GNUC__ && mc68k) */ |
|
329 |
||
4176 | 330 |
if (productHi == 0) { |
331 |
if (negative < 0) { |
|
332 |
if (productLow <= -(_MIN_INT)) { |
|
333 |
RETURN ( __MKSMALLINT(-((INT)productLow)) ); |
|
334 |
} |
|
335 |
} else { |
|
336 |
if (productLow <= _MAX_INT) { |
|
337 |
RETURN ( __MKSMALLINT(productLow) ); |
|
338 |
} |
|
339 |
} |
|
340 |
} |
|
4167 | 341 |
#endif /* ! USE_LONGLONG */ |
342 |
||
343 |
#ifdef alpha64 |
|
4176 | 344 |
RETURN (__MKLARGEINT128(negative, productLow, productHi)); |
4167 | 345 |
#else |
4176 | 346 |
RETURN (__MKLARGEINT64(negative, productLow, productHi)); |
95 | 347 |
#endif |
283 | 348 |
} else if (__isFloatLike(aNumber)) { |
4176 | 349 |
OBJ newFloat; |
350 |
double val = (double)__intVal(self) * __floatVal(aNumber); |
|
351 |
||
352 |
__qMKFLOAT(newFloat, val); |
|
353 |
RETURN ( newFloat ); |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
354 |
} else if (__isShortFloat(aNumber)) { |
4176 | 355 |
OBJ newFloat; |
356 |
float val = (float)__intVal(self) * __shortFloatVal(aNumber); |
|
357 |
||
358 |
__qMKSFLOAT(newFloat, val); |
|
359 |
RETURN ( newFloat ); |
|
1 | 360 |
} |
2641 | 361 |
%}. |
1 | 362 |
^ aNumber productFromInteger:self |
363 |
! |
|
364 |
||
701 | 365 |
+ aNumber |
366 |
"return the sum of the receivers value and the arguments value" |
|
367 |
||
368 |
%{ /* NOCONTEXT */ |
|
369 |
||
370 |
if (__isSmallInteger(aNumber)) { |
|
371 |
#ifdef _ADD_IO_IO |
|
4167 | 372 |
RETURN ( _ADD_IO_IO(self, aNumber) ); |
701 | 373 |
#else |
4167 | 374 |
REGISTER INT sum; |
375 |
||
376 |
sum = __intVal(self) + __intVal(aNumber); |
|
377 |
if (__ISVALIDINTEGER(sum)) { |
|
378 |
RETURN ( __MKSMALLINT(sum) ); |
|
379 |
} |
|
380 |
RETURN ( __MKLARGEINT(sum) ); |
|
701 | 381 |
#endif |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
382 |
} else if (__isFloatLike(aNumber)) { |
4167 | 383 |
OBJ newFloat; |
384 |
double val = (double)__intVal(self) + __floatVal(aNumber); |
|
385 |
||
386 |
__qMKFLOAT(newFloat, val); |
|
387 |
RETURN ( newFloat ); |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
388 |
} else if (__isShortFloat(aNumber)) { |
4167 | 389 |
OBJ newFloat; |
390 |
float val = (float)__intVal(self) + __shortFloatVal(aNumber); |
|
391 |
||
392 |
__qMKSFLOAT(newFloat, val); |
|
393 |
RETURN ( newFloat ); |
|
701 | 394 |
} |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
395 |
%}. |
701 | 396 |
^ aNumber sumFromInteger:self |
397 |
! |
|
398 |
||
399 |
- aNumber |
|
400 |
"return the difference of the receivers value and the arguments value" |
|
401 |
||
402 |
%{ /* NOCONTEXT */ |
|
403 |
||
404 |
if (__isSmallInteger(aNumber)) { |
|
405 |
#ifdef _SUB_IO_IO |
|
4167 | 406 |
RETURN ( _SUB_IO_IO(self, aNumber) ); |
701 | 407 |
#else |
4167 | 408 |
REGISTER INT diff; |
409 |
||
410 |
diff = __intVal(self) - __intVal(aNumber); |
|
411 |
if (__ISVALIDINTEGER(diff)) { |
|
412 |
RETURN ( __MKSMALLINT(diff) ); |
|
413 |
} |
|
414 |
RETURN ( __MKLARGEINT(diff) ); |
|
701 | 415 |
#endif |
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
416 |
} else if (__isFloatLike(aNumber)) { |
4167 | 417 |
OBJ newFloat; |
418 |
double val = (double)__intVal(self) - __floatVal(aNumber); |
|
419 |
||
420 |
__qMKFLOAT(newFloat, val); |
|
421 |
RETURN ( newFloat ); |
|
3532
4b1a5cc57f8f
added int op shortFloat inline
Claus Gittinger <cg@exept.de>
parents:
3458
diff
changeset
|
422 |
} else if (__isShortFloat(aNumber)) { |
4167 | 423 |
OBJ newFloat; |
424 |
float val = (float)__intVal(self) - __shortFloatVal(aNumber); |
|
425 |
||
426 |
__qMKSFLOAT(newFloat, val); |
|
427 |
RETURN ( newFloat ); |
|
701 | 428 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
429 |
%}. |
701 | 430 |
^ aNumber differenceFromInteger:self |
431 |
! |
|
432 |
||
1 | 433 |
/ aNumber |
434 |
"return the quotient of the receivers value and the arguments value" |
|
435 |
||
436 |
%{ /* NOCONTEXT */ |
|
437 |
||
438 |
INT me, t, val; |
|
439 |
double dval; |
|
440 |
||
252 | 441 |
if (__isSmallInteger(aNumber)) { |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
442 |
val = __intVal(aNumber); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
443 |
if (val != 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
444 |
me = __intVal(self); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
445 |
t = me / val; |
1 | 446 |
#ifdef GOOD_OPTIMIZER |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
447 |
if (me % val == 0) { |
1 | 448 |
#else |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
449 |
/* this is stupid - all I want is to look for a remainder ... |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
450 |
but most compilers are too stupid and generate an extra modulus |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
451 |
instruction for "if (me % val)". |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
452 |
Even if most divide instructions already leave the remainder in |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
453 |
some register. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
454 |
Therefore I use a multiplication which is faster than a modulo |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
455 |
on most machines. Hint to GNU people :-) |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
456 |
*/ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
457 |
if ((t * val) == me) { |
1 | 458 |
#endif |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
459 |
RETURN ( __MKSMALLINT(t) ); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
460 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
461 |
} |
1 | 462 |
} else { |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
463 |
if (__isFloatLike(aNumber)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
464 |
dval = __floatVal(aNumber); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
465 |
if (dval != 0.0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
466 |
OBJ newFloat; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
467 |
double val = (double)__intVal(self) / dval; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
468 |
|
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
469 |
__qMKFLOAT(newFloat, val); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
470 |
RETURN ( newFloat ); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
471 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
472 |
} |
1 | 473 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
474 |
%}. |
1 | 475 |
aNumber isInteger ifTrue:[ |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
476 |
aNumber == 0 ifTrue:[ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
477 |
^ DivisionByZeroSignal raiseRequest. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
478 |
]. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
479 |
^ Fraction numerator:self denominator:aNumber |
1 | 480 |
]. |
481 |
^ aNumber quotientFromInteger:self |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
482 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
483 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
484 |
8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
485 |
9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
486 |
9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
487 |
9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
488 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
489 |
-8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
490 |
-9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
491 |
-9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
492 |
-9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
493 |
" |
1 | 494 |
! |
495 |
||
2 | 496 |
// aNumber |
1 | 497 |
"return the integer part of the quotient of the receivers value |
1884 | 498 |
and the arguments value. The result is truncated toward negative infinity |
499 |
and negative, if the operands signs differ. |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
500 |
Be careful with negative results: 9 // 4 = 2, |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
501 |
while -9 // 4 = -3. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
502 |
See #quo: which returns -2 in the latter." |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
503 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
504 |
%{ /* NOCONTEXT */ |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
505 |
INT dividend, divisor, rslt; |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
506 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
507 |
if (__isSmallInteger(aNumber)) { |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
508 |
divisor = __intVal(aNumber); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
509 |
if (divisor != 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
510 |
dividend = __intVal(self); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
511 |
rslt = dividend / divisor; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
512 |
/* |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
513 |
* Optimized to speed up positive result |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
514 |
*/ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
515 |
if (rslt <= 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
516 |
if (rslt == 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
517 |
if (dividend * divisor < 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
518 |
/* |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
519 |
* result (negative) has been truncated toward 0. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
520 |
* Return -1, because we truncate toward negative inf. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
521 |
*/ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
522 |
rslt = -1; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
523 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
524 |
} else { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
525 |
/* |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
526 |
* If result (negative) has been truncated toward 0, |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
527 |
* subtract 1, beacuse we truncate toward negative inf. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
528 |
*/ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
529 |
if (divisor > 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
530 |
if (rslt * divisor > dividend) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
531 |
rslt--; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
532 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
533 |
} else { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
534 |
if (rslt * divisor < dividend) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
535 |
rslt--; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
536 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
537 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
538 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
539 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
540 |
RETURN ( __MKSMALLINT(rslt) ); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
541 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
542 |
} else { |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
543 |
if (__isFraction(aNumber)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
544 |
OBJ t; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
545 |
INT num, den; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
546 |
|
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
547 |
t = __FractionInstPtr(aNumber)->f_numerator; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
548 |
if (__isSmallInteger(t)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
549 |
num = __intVal(t); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
550 |
t = __FractionInstPtr(aNumber)->f_denominator; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
551 |
if (__isSmallInteger(t)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
552 |
den = __intVal(t); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
553 |
RETURN ( __MKSMALLINT(__intVal(self) * den / num )); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
554 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
555 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
556 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
557 |
} |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
558 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
559 |
(aNumber = 0) ifTrue:[ |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
560 |
^ DivisionByZeroSignal raiseRequest. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
561 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
562 |
^ self retry:#// coercing:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
563 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
564 |
" |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
565 |
9 // 4 ~~ 2 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
566 |
-9 // 4 ~~ -3 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
567 |
9 // -4 ~~ -3 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
568 |
-9 // -4 ~~ 2 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
569 |
1 // 2 ~~ 0 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
570 |
-1 // 2 ~~ -1 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
571 |
1 // -2 ~~ -1 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
572 |
-1 // -2 ~~ 0 ifTrue:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
573 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
574 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
575 |
9 quo:4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
576 |
-9 quo:4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
577 |
9 quo:-4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
578 |
-9 quo:-4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
579 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
580 |
! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
581 |
|
2 | 582 |
\\ aNumber |
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
583 |
"Answer the integer remainder m defined by division with truncation toward |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
584 |
negative infinity. The remainder has the same sign as aNumber. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
585 |
m < |aNumber| AND there is an integer k with (k * aNumber + m) = self |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
586 |
Compare with #rem: |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
587 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
588 |
Redefined for speed." |
1 | 589 |
|
590 |
%{ /* NOCONTEXT */ |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
591 |
INT dividend, divisor, rem; |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
592 |
|
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
593 |
if (__isSmallInteger(aNumber) |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
594 |
&& (divisor = __intVal(aNumber)) != 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
595 |
/* |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
596 |
* Note that the sign of something modulo a negative number is undefined |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
597 |
* in C! |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
598 |
*/ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
599 |
dividend = __intVal(self); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
600 |
rem = dividend % divisor; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
601 |
if (rem) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
602 |
if ((rem < 0) != (divisor < 0)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
603 |
/* sign of remainder is different from sign of divisor */ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
604 |
rem = -rem; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
605 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
606 |
if ((dividend < 0) != (divisor < 0)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
607 |
/* different signs, so division would have returned a |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
608 |
* negative number. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
609 |
* C rounds toward zero, this code will simulate |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
610 |
* rounding towards negative infinity. |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
611 |
*/ |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
612 |
rem = divisor - rem; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
613 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
614 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
615 |
RETURN ( __MKSMALLINT(rem) ); |
1 | 616 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
617 |
%}. |
2 | 618 |
(aNumber = 0) ifTrue:[ |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
619 |
^ DivisionByZeroSignal raiseRequest. |
1 | 620 |
]. |
2 | 621 |
^ self retry:#\\ coercing:aNumber |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
622 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
623 |
" |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
624 |
9 \\ 4 == 1 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
625 |
-9 \\ 4 == 3 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
626 |
9 \\ -4 == -3 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
627 |
-9 \\ -4 == -1 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
628 |
(9 rem:4) == 1 ifFalse:[self halt]. |
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
629 |
(-9 rem:4) == -1 ifFalse:[self halt]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
630 |
" |
1 | 631 |
! |
632 |
||
633 |
abs |
|
634 |
"return the absolute value of the receiver |
|
635 |
reimplemented here for speed" |
|
636 |
||
637 |
%{ /* NOCONTEXT */ |
|
638 |
||
1133 | 639 |
INT val = __intVal(self); |
1 | 640 |
|
62 | 641 |
if (val >= 0) { |
214 | 642 |
RETURN (self); |
62 | 643 |
} |
1 | 644 |
if (val != _MIN_INT) { |
1133 | 645 |
RETURN ( __MKSMALLINT(-val) ); |
1 | 646 |
} |
3430 | 647 |
/* only reached for minVal */ |
648 |
RETURN( __MKLARGEINT(-_MIN_INT)); |
|
324 | 649 |
%}. |
3430 | 650 |
"/ "only reached for minVal" |
651 |
"/ ^ self negated |
|
1 | 652 |
! |
653 |
||
654 |
negated |
|
655 |
"return the negative value of the receiver |
|
656 |
reimplemented here for speed" |
|
657 |
||
658 |
%{ /* NOCONTEXT */ |
|
659 |
||
1133 | 660 |
INT val = __intVal(self); |
1 | 661 |
|
662 |
if (val != _MIN_INT) { |
|
1133 | 663 |
RETURN ( __MKSMALLINT(- val) ); |
1 | 664 |
} |
3430 | 665 |
/* only reached for minVal */ |
666 |
RETURN (__MKLARGEINT( -_MIN_INT)); |
|
324 | 667 |
%}. |
3430 | 668 |
"/ "only reached for minVal" |
669 |
"/ ^ (LargeInteger value:(SmallInteger maxVal)) + 1 |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
670 |
! |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
671 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
672 |
quo:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
673 |
"return the integer part of the quotient of the receivers value |
1884 | 674 |
and the arguments value. The result is truncated towards zero |
675 |
and negative, if the operands signs differ.. |
|
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
676 |
For positive results, this is the same as #//, |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
677 |
for negative results, the remainder is ignored. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
678 |
I.e.: '9 // 4 = 2' and '-9 // 4 = -3' |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
679 |
in contrast: '9 quo: 4 = 2' and '-9 quo: 4 = -2'" |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
680 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
681 |
%{ /* NOCONTEXT */ |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
682 |
INT val; |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
683 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
684 |
if (__isSmallInteger(aNumber)) { |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
685 |
val = __intVal(aNumber); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
686 |
if (val != 0) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
687 |
RETURN ( __MKSMALLINT(__intVal(self) / val) ); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
688 |
} |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
689 |
} else { |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
690 |
if (__isFraction(aNumber)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
691 |
OBJ t; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
692 |
INT num, den; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
693 |
|
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
694 |
t = __FractionInstPtr(aNumber)->f_numerator; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
695 |
if (__isSmallInteger(t)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
696 |
num = __intVal(t); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
697 |
t = __FractionInstPtr(aNumber)->f_denominator; |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
698 |
if (__isSmallInteger(t)) { |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
699 |
den = __intVal(t); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
700 |
RETURN ( __MKSMALLINT(__intVal(self) * den / num )); |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
701 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
702 |
} |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
703 |
} |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
704 |
} |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
705 |
%}. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
706 |
(aNumber = 0) ifTrue:[ |
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
4184
diff
changeset
|
707 |
^ DivisionByZeroSignal raiseRequest. |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
708 |
]. |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
709 |
^ self retry:#quo: coercing:aNumber |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
710 |
|
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
711 |
" |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
712 |
9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
713 |
-9 // 4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
714 |
9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
715 |
-9 quo:4 |
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
716 |
" |
1 | 717 |
! ! |
718 |
||
719 |
!SmallInteger methodsFor:'bit operators'! |
|
720 |
||
701 | 721 |
bitAnd:anInteger |
722 |
"return the bitwise-and of the receiver and the argument, anInteger" |
|
1 | 723 |
|
724 |
%{ /* NOCONTEXT */ |
|
725 |
||
701 | 726 |
/* anding the tags doesn't change it */ |
727 |
if (__isSmallInteger(anInteger)) { |
|
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
728 |
RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) ); |
1 | 729 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
730 |
%}. |
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
731 |
anInteger class == LargeInteger ifTrue:[ |
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
732 |
^ anInteger bitAnd:self |
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
733 |
]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
734 |
^ self retry:#bitAnd: coercing:anInteger |
701 | 735 |
|
736 |
"(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2" |
|
1 | 737 |
! |
738 |
||
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
739 |
bitAt:index |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
740 |
"return the value of the index's bit (index starts at 1). |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
741 |
Notice: the result of bitAt: on negative receivers is not |
4523
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
742 |
defined in the language standard (since the implementation |
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
743 |
is free to choose any internal representation for integers)" |
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
744 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
745 |
|mask| |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
746 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
747 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
4523
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
748 |
^ SubscriptOutOfBoundsSignal |
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
749 |
raiseRequestWith:index |
28d9633c9cb4
subscriptBoundsError when accessing bad bits
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
750 |
errorString:'index out of bounds' |
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
751 |
]. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
752 |
mask := 1 bitShift:(index - 1). |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
753 |
((self bitAnd:mask) == 0) ifTrue:[^ 0]. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
754 |
^ 1 |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
755 |
! |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
756 |
|
3156 | 757 |
bitClear:anInteger |
758 |
"return the bitwise-and of the receiver and the complement of the argument, anInteger, |
|
759 |
returning the receiver with bits of the argument cleared." |
|
760 |
||
761 |
%{ /* NOCONTEXT */ |
|
762 |
||
763 |
/* anding the tags doesn't change it */ |
|
764 |
if (__isSmallInteger(anInteger)) { |
|
4167 | 765 |
RETURN ( ((OBJ) (((INT)self & ~(INT)anInteger) | TAG_INT)) ); |
3156 | 766 |
} |
767 |
%}. |
|
768 |
^ self retry:#bitClear: coercing:anInteger |
|
769 |
||
770 |
" |
|
771 |
(2r001010100 bitClear:2r00001111) radixPrintStringRadix:2 |
|
772 |
" |
|
773 |
! |
|
774 |
||
701 | 775 |
bitInvert |
776 |
"return the value of the receiver with all bits inverted" |
|
62 | 777 |
|
1 | 778 |
%{ /* NOCONTEXT */ |
779 |
||
701 | 780 |
/* invert anything except tag bits */ |
781 |
RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) ); |
|
782 |
%} |
|
783 |
! |
|
1 | 784 |
|
701 | 785 |
bitOr:anInteger |
786 |
"return the bitwise-or of the receiver and the argument, anInteger" |
|
787 |
||
788 |
%{ /* NOCONTEXT */ |
|
789 |
||
790 |
/* oring the tags doesn't change it */ |
|
791 |
if (__isSmallInteger(anInteger)) { |
|
792 |
RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) ); |
|
1 | 793 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
794 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
795 |
^ self retry:#bitOr: coercing:anInteger |
701 | 796 |
|
797 |
"(2r000000100 bitOr:2r00000011) radixPrintStringRadix:2" |
|
1 | 798 |
! |
799 |
||
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
800 |
bitShift32:shiftCount |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
801 |
"return the value of the receiver shifted by shiftCount bits, |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
802 |
but only within 32 bits, shifting into/out-of the sign bit. |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
803 |
May be useful for communication interfaces, to create ST-numbers |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
804 |
from a signed 32bit int value given as individual bytes." |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
805 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
806 |
%{ /* NOCONTEXT */ |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
807 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
808 |
INT bits, count; |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
809 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
810 |
if (__isSmallInteger(shiftCount)) { |
4167 | 811 |
count = __intVal(shiftCount); |
812 |
if (count >= 32) { |
|
813 |
RETURN (__MKSMALLINT(0)); |
|
814 |
} |
|
815 |
||
816 |
bits = __intVal(self); |
|
817 |
if (count > 0) { |
|
818 |
bits = bits << count; |
|
819 |
} else { |
|
820 |
bits = bits >> (-count); |
|
821 |
} |
|
2785 | 822 |
#ifdef alpha64 |
4167 | 823 |
bits &= 0xFFFFFFFFL; |
2785 | 824 |
#endif |
4167 | 825 |
RETURN (__MKINT(bits)); |
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
826 |
} |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
827 |
%}. |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
828 |
^ self primitiveFailed |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
829 |
|
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
830 |
" |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
831 |
128 bitShift:24 |
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
832 |
128 bitShift32:24 |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
833 |
|
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
834 |
1 bitShift:31 |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
835 |
1 bitShift32:31 |
1506
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
836 |
" |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
837 |
! |
3b4ff5941981
added bitShift32: for int32 arithmetic
Claus Gittinger <cg@exept.de>
parents:
1336
diff
changeset
|
838 |
|
1 | 839 |
bitShift:shiftCount |
840 |
"return the value of the receiver shifted by shiftCount bits; |
|
62 | 841 |
leftShift if shiftCount > 0; rightShift otherwise. |
95 | 842 |
Notice: the result of bitShift: on negative receivers is not |
4177 | 843 |
defined in the language standard (since the implementation |
844 |
is free to choose any internal representation for integers)" |
|
1 | 845 |
|
846 |
%{ /* NOCONTEXT */ |
|
847 |
||
848 |
INT bits, count; |
|
849 |
||
252 | 850 |
if (__isSmallInteger(shiftCount)) { |
4177 | 851 |
bits = __intVal(self); |
852 |
if (bits == 0) { |
|
853 |
RETURN (self); |
|
854 |
} |
|
855 |
||
856 |
count = __intVal(shiftCount); |
|
857 |
||
858 |
if (count > 0) { |
|
859 |
/* |
|
860 |
* a left shift |
|
861 |
*/ |
|
4183
4a745f6f47b6
oops - longlong shift fails with i386,GCC
Claus Gittinger <cg@exept.de>
parents:
4177
diff
changeset
|
862 |
#if defined(USE_LONGLONG_FOR_SHIFT) |
4177 | 863 |
if (count <= N_INT_BITS) { |
864 |
unsigned LONGLONG result; |
|
865 |
||
4183
4a745f6f47b6
oops - longlong shift fails with i386,GCC
Claus Gittinger <cg@exept.de>
parents:
4177
diff
changeset
|
866 |
result = (unsigned LONGLONG)bits; |
4177 | 867 |
result <<= count; |
868 |
if (result <= _MAX_INT) { |
|
869 |
RETURN ( __MKSMALLINT(result) ); |
|
870 |
} |
|
871 |
{ |
|
872 |
RETURN (__MKLARGEINT64(1, (INT)(result >> 32), (INT)(result & 0xFFFFFFFF))); |
|
873 |
} |
|
874 |
} |
|
95 | 875 |
#else |
4177 | 876 |
/* |
877 |
* check for overflow |
|
878 |
*/ |
|
879 |
if (count < (N_INT_BITS-1)) { |
|
880 |
if (! (bits >> (N_INT_BITS - 1 - count))) { |
|
881 |
RETURN ( __MKSMALLINT(bits << count) ); |
|
882 |
} |
|
883 |
/* |
|
884 |
* so, there is an overflow ... |
|
885 |
* handle it as largeInteger |
|
886 |
*/ |
|
887 |
/* FALL THROUGH */ |
|
888 |
} |
|
95 | 889 |
#endif |
4177 | 890 |
} else { |
891 |
if (count == 0) { |
|
892 |
RETURN (self); |
|
893 |
} |
|
894 |
||
895 |
/* |
|
896 |
* right shifts cannot overflow |
|
897 |
* |
|
898 |
* some machines ignore shifts bigger than |
|
899 |
* the number of bits in an int ... |
|
900 |
*/ |
|
901 |
count = -count; |
|
902 |
if (count > (N_INT_BITS-1)) { |
|
903 |
RETURN (__MKSMALLINT(0)); |
|
904 |
} |
|
905 |
||
906 |
RETURN ( __MKSMALLINT(bits >> count) ); |
|
907 |
} |
|
1 | 908 |
} |
85 | 909 |
%}. |
910 |
(shiftCount isMemberOf:SmallInteger) ifTrue:[ |
|
4177 | 911 |
^ (LargeInteger value:self) bitShift:shiftCount |
85 | 912 |
]. |
1 | 913 |
^ self bitShift:(shiftCount coerce:1) |
914 |
! |
|
915 |
||
701 | 916 |
bitTest:aMask |
917 |
"return true, if any bit from aMask is set in the receiver" |
|
1 | 918 |
|
919 |
%{ /* NOCONTEXT */ |
|
920 |
||
701 | 921 |
/* and all bits except tag */ |
922 |
if (__isSmallInteger(aMask)) { |
|
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
923 |
RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false ); |
1 | 924 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
925 |
%}. |
4613
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
926 |
aMask class == LargeInteger ifTrue:[ |
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
927 |
^ (aMask bitAnd:self) ~~ 0 |
a722d598c1bb
faster and:/bitTest: with a largeInteger
Claus Gittinger <cg@exept.de>
parents:
4523
diff
changeset
|
928 |
]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
929 |
^ self retry:#bitTest: coercing:aMask |
1 | 930 |
! |
931 |
||
932 |
bitXor:anInteger |
|
13 | 933 |
"return the bitwise-exclusive-or of the receiver and the argument, anInteger" |
1 | 934 |
|
935 |
%{ /* NOCONTEXT */ |
|
936 |
||
937 |
/* xoring the tags turns it off - or it in again */ |
|
252 | 938 |
if (__isSmallInteger(anInteger)) { |
214 | 939 |
RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) ); |
1 | 940 |
} |
1716
52fc3e02c5bd
use new MKLARGEINT64 to generate 64 bit result;
Claus Gittinger <cg@exept.de>
parents:
1695
diff
changeset
|
941 |
%}. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
942 |
^ self retry:#bitXor: coercing:anInteger |
1 | 943 |
! |
944 |
||
3683 | 945 |
clearBit:anInteger |
946 |
"return a new number where the specified bit is off. |
|
947 |
Bits are counted from 1 starting with the least significant." |
|
948 |
||
949 |
%{ /* NOCONTEXT */ |
|
950 |
||
951 |
if (__isSmallInteger(anInteger)) { |
|
4167 | 952 |
int index = __intVal(anInteger); |
3683 | 953 |
|
954 |
#ifdef alpha64 |
|
4167 | 955 |
if (index <= 63) |
3683 | 956 |
#else |
4167 | 957 |
if (index <= 30) |
3683 | 958 |
#endif |
4167 | 959 |
{ |
960 |
INT mask = __MASKSMALLINT(1 << (index-1)); |
|
961 |
||
962 |
RETURN ( ((OBJ) ((INT)self & ~(INT)mask)) ); |
|
963 |
} |
|
964 |
RETURN (self); |
|
3683 | 965 |
} |
966 |
%}. |
|
967 |
^ self retry:#clearBit: coercing:anInteger |
|
968 |
||
969 |
" |
|
970 |
(16r401 clearBit:1 ) hexPrintString |
|
971 |
(16r3fffffff clearBit:1) hexPrintString |
|
972 |
(16r3fffffff clearBit:29) hexPrintString |
|
973 |
(16r3fffffff clearBit:30) hexPrintString |
|
974 |
(16r3fffffff clearBit:31) hexPrintString |
|
975 |
(16r3fffffff bitAt:30) hexPrintString |
|
976 |
(16r3fffffff bitAt:29) hexPrintString |
|
977 |
(16r40000001 clearBit:1) hexPrintString |
|
978 |
(16rF0000001 clearBit:29) hexPrintString |
|
979 |
(16rF0000001 clearBit:30) hexPrintString |
|
980 |
(16rF0000001 clearBit:31) hexPrintString |
|
981 |
(16rF0000001 clearBit:32) hexPrintString |
|
982 |
" |
|
983 |
||
984 |
||
985 |
! |
|
986 |
||
701 | 987 |
highBit |
988 |
"return the bitIndex of the highest bit set. The returned bitIndex |
|
989 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
1 | 990 |
|
991 |
%{ /* NOCONTEXT */ |
|
992 |
||
701 | 993 |
INT mask, index, bits; |
994 |
||
1133 | 995 |
bits = __intVal(self); |
701 | 996 |
if (bits == 0) { |
1133 | 997 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 998 |
} |
2785 | 999 |
|
2653 | 1000 |
#ifdef alpha64 |
2781 | 1001 |
mask = 0x2000000000000000L; |
701 | 1002 |
index = 62; |
1003 |
#else |
|
1004 |
mask = 0x20000000; |
|
1005 |
index = 30; |
|
1006 |
#endif |
|
2785 | 1007 |
|
701 | 1008 |
while (index) { |
1009 |
if (bits & mask) break; |
|
1010 |
mask = mask >> 1; |
|
1011 |
index--; |
|
1 | 1012 |
} |
1133 | 1013 |
RETURN ( __MKSMALLINT(index) ); |
1 | 1014 |
%} |
701 | 1015 |
"2r000100 highBit" |
1016 |
"2r010100 highBit" |
|
1017 |
"2r000001 highBit" |
|
1018 |
"0 highBit" |
|
1019 |
"SmallInteger maxVal highBit" |
|
1020 |
! |
|
1021 |
||
1022 |
lowBit |
|
1023 |
"return the bitIndex of the lowest bit set. The returned bitIndex |
|
1024 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
1025 |
||
1026 |
%{ /* NOCONTEXT */ |
|
1027 |
||
1028 |
INT mask, index, bits; |
|
1029 |
||
1133 | 1030 |
bits = __intVal(self); |
701 | 1031 |
if (bits == 0) { |
4167 | 1032 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 1033 |
} |
2431 | 1034 |
|
1035 |
if ((bits & 0xFFFFFF) == 0) { |
|
4167 | 1036 |
mask = 0x1000000; |
1037 |
index = 25; |
|
2431 | 1038 |
} else { |
4167 | 1039 |
if ((bits & 0xFFFF) == 0) { |
1040 |
mask = 0x10000; |
|
1041 |
index = 17; |
|
1042 |
} else { |
|
1043 |
if ((bits & 0xFF) == 0) { |
|
1044 |
mask = 0x100; |
|
1045 |
index = 9; |
|
1046 |
} else { |
|
1047 |
mask = 1; |
|
1048 |
index = 1; |
|
1049 |
} |
|
1050 |
} |
|
2431 | 1051 |
} |
1052 |
||
2653 | 1053 |
#ifdef alpha64 |
701 | 1054 |
while (index != 63) { |
1055 |
#else |
|
1056 |
while (index != 31) { |
|
1057 |
#endif |
|
4167 | 1058 |
if (bits & mask) { |
1059 |
RETURN ( __MKSMALLINT(index) ); |
|
1060 |
} |
|
1061 |
mask = mask << 1; |
|
1062 |
index++; |
|
701 | 1063 |
} |
1133 | 1064 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 1065 |
%} |
2431 | 1066 |
" |
1067 |
2r000100 lowBit |
|
1068 |
2r010010 lowBit |
|
1069 |
2r100001 lowBit |
|
1070 |
16r1000 lowBit |
|
1071 |
16r1000000 lowBit |
|
1072 |
0 lowBit |
|
1073 |
" |
|
1 | 1074 |
! ! |
1075 |
||
1076 |
!SmallInteger methodsFor:'byte access'! |
|
1077 |
||
1078 |
digitAt:index |
|
1079 |
"return 8 bits of value, starting at byte index" |
|
1080 |
||
1081 |
%{ /* NOCONTEXT */ |
|
1082 |
||
357 | 1083 |
REGISTER INT val; |
1084 |
INT idx; |
|
1 | 1085 |
|
252 | 1086 |
if (__isSmallInteger(index)) { |
4167 | 1087 |
val = __intVal(self); |
1088 |
if (val < 0) |
|
1089 |
val = -val; |
|
1090 |
switch (idx = __intVal(index)) { |
|
1091 |
case 1: |
|
1092 |
break; |
|
1093 |
case 2: |
|
1094 |
val = (val >> 8); |
|
1095 |
break; |
|
1096 |
case 3: |
|
1097 |
val = (val >> 16); |
|
1098 |
break; |
|
1099 |
case 4: |
|
1100 |
val = (val >> 24); |
|
1101 |
break; |
|
2653 | 1102 |
#ifdef alpha64 |
4167 | 1103 |
case 5: |
1104 |
val = (val >> 32); |
|
1105 |
break; |
|
1106 |
case 6: |
|
1107 |
val = (val >> 40); |
|
1108 |
break; |
|
1109 |
case 7: |
|
1110 |
val = (val >> 48); |
|
1111 |
break; |
|
1112 |
case 8: |
|
1113 |
val = (val >> 56); |
|
1114 |
break; |
|
1 | 1115 |
#endif |
4167 | 1116 |
default: |
1117 |
if (idx < 1) |
|
1118 |
goto bad; /* sorry */ |
|
1119 |
RETURN (__MKSMALLINT(0)); |
|
1120 |
} |
|
1121 |
RETURN ( __MKSMALLINT( val & 0xFF) ); |
|
1 | 1122 |
} |
357 | 1123 |
bad: ; |
77 | 1124 |
%}. |
1125 |
index > 0 ifFalse:[ |
|
4167 | 1126 |
" |
1127 |
index less than 1 - not allowed |
|
1128 |
" |
|
1129 |
^ self primitiveFailed |
|
77 | 1130 |
]. |
1131 |
^ 0 |
|
62 | 1132 |
|
357 | 1133 |
" |
1134 |
(16r12345678 digitAt:1) printStringRadix:16 |
|
1135 |
(16r12345678 digitAt:3) printStringRadix:16 |
|
1136 |
(16r12345678 digitAt:15) printStringRadix:16 |
|
1137 |
(16r12345678 digitAt:0) printStringRadix:16 |
|
1138 |
(16r12345678 digitAt:-10) printStringRadix:16 |
|
1139 |
" |
|
701 | 1140 |
! |
1141 |
||
3892 | 1142 |
digitByteAt:index |
1143 |
"return 8 bits of my signed value, starting at byte index. |
|
1144 |
For positive receivers, this is the same as #digitAt:; |
|
1145 |
for negative ones, the actual bit representation is returned." |
|
1146 |
||
1147 |
%{ /* NOCONTEXT */ |
|
1148 |
||
1149 |
REGISTER INT val; |
|
1150 |
INT idx; |
|
1151 |
||
1152 |
if (__isSmallInteger(index)) { |
|
4167 | 1153 |
val = __intVal(self); |
1154 |
switch (idx = __intVal(index)) { |
|
1155 |
case 1: |
|
1156 |
break; |
|
1157 |
case 2: |
|
1158 |
val = (val >> 8); |
|
1159 |
break; |
|
1160 |
case 3: |
|
1161 |
val = (val >> 16); |
|
1162 |
break; |
|
1163 |
case 4: |
|
1164 |
val = (val >> 24); |
|
1165 |
break; |
|
3892 | 1166 |
#ifdef alpha64 |
4167 | 1167 |
case 5: |
1168 |
val = (val >> 32); |
|
1169 |
break; |
|
1170 |
case 6: |
|
1171 |
val = (val >> 40); |
|
1172 |
break; |
|
1173 |
case 7: |
|
1174 |
val = (val >> 48); |
|
1175 |
break; |
|
1176 |
case 8: |
|
1177 |
val = (val >> 56); |
|
1178 |
break; |
|
3892 | 1179 |
#endif |
4167 | 1180 |
default: |
1181 |
if (idx < 1) |
|
1182 |
goto bad; /* sorry */ |
|
1183 |
if (val < 0) { |
|
1184 |
RETURN (__MKSMALLINT(0xFF)); |
|
1185 |
} |
|
1186 |
RETURN (__MKSMALLINT(0)); |
|
1187 |
} |
|
1188 |
RETURN ( __MKSMALLINT( val & 0xFF) ); |
|
3892 | 1189 |
} |
1190 |
bad: ; |
|
1191 |
%}. |
|
1192 |
index > 0 ifFalse:[ |
|
4167 | 1193 |
" |
1194 |
index less than 1 - not allowed |
|
1195 |
" |
|
1196 |
^ self primitiveFailed |
|
3892 | 1197 |
]. |
1198 |
^ 0 |
|
1199 |
||
1200 |
" |
|
1201 |
(10 digitByteAt:1) printStringRadix:16 |
|
1202 |
(10 digitByteAt:3) printStringRadix:16 |
|
1203 |
(-10 digitByteAt:1) printStringRadix:16 |
|
1204 |
(-10 digitByteAt:3) printStringRadix:16 |
|
1205 |
" |
|
1206 |
! |
|
1207 |
||
701 | 1208 |
digitLength |
2815 | 1209 |
"return the number bytes required to represent this Integer. |
1210 |
For negative receivers, the digitLength of its absolute value |
|
1211 |
is returned." |
|
1212 |
||
1213 |
%{ /* NOCONTEXT */ |
|
1214 |
||
1215 |
INT val = __intVal(self); |
|
1216 |
||
1217 |
if (val < 0) { |
|
4167 | 1218 |
val = -val; |
2815 | 1219 |
} |
1220 |
#ifdef alpha64 |
|
1221 |
if (val & 0xFFFFFFFF00000000L) { |
|
4167 | 1222 |
if (val & 0xFFFF000000000000L) { |
1223 |
if (val & 0xFF00000000000000L) { |
|
1224 |
RETURN ( __MKSMALLINT(8)); |
|
1225 |
} else { |
|
1226 |
RETURN ( __MKSMALLINT(7)); |
|
1227 |
} |
|
1228 |
} else { |
|
1229 |
if (val & 0x0000FF0000000000L) { |
|
1230 |
RETURN ( __MKSMALLINT(6)); |
|
1231 |
} else { |
|
1232 |
RETURN ( __MKSMALLINT(5)); |
|
1233 |
} |
|
1234 |
} |
|
2815 | 1235 |
} |
1236 |
#endif |
|
1237 |
||
1238 |
if (val & 0xFFFF0000) { |
|
4167 | 1239 |
if (val & 0xFF000000) { |
1240 |
RETURN ( __MKSMALLINT(4)); |
|
1241 |
} else { |
|
1242 |
RETURN ( __MKSMALLINT(3)); |
|
1243 |
} |
|
2815 | 1244 |
} else { |
4167 | 1245 |
if (val & 0x0000FF00) { |
1246 |
RETURN ( __MKSMALLINT(2)); |
|
1247 |
} else { |
|
1248 |
RETURN ( __MKSMALLINT(1)); |
|
1249 |
} |
|
2815 | 1250 |
} |
1251 |
||
1252 |
%}. |
|
701 | 1253 |
^ self abs highBit - 1 // 8 + 1 |
2815 | 1254 |
|
1255 |
" |
|
1256 |
16rFF00000000000000 digitLength |
|
1257 |
-16rFF00000000000000 digitLength |
|
1258 |
||
1259 |
16rFF000000 digitLength |
|
1260 |
16rFF0000 digitLength |
|
1261 |
16rFF00 digitLength |
|
1262 |
16rFF digitLength |
|
1263 |
-16rFF000000 digitLength |
|
1264 |
-16rFF0000 digitLength |
|
1265 |
-16rFF00 digitLength |
|
1266 |
-16rFF digitLength |
|
1267 |
" |
|
1 | 1268 |
! ! |
1269 |
||
701 | 1270 |
!SmallInteger methodsFor:'catching messages'! |
1 | 1271 |
|
701 | 1272 |
basicAt:index |
1273 |
"catch indexed access - report an error |
|
1274 |
defined here since basicAt: in Object ommits the SmallInteger check." |
|
1275 |
||
1276 |
self notIndexed |
|
1 | 1277 |
! |
1278 |
||
701 | 1279 |
basicAt:index put:anObject |
1280 |
"catch indexed access - report an error |
|
1281 |
defined here since basicAt:put: in Object ommits the SmallInteger check." |
|
1282 |
||
1283 |
self notIndexed |
|
1284 |
! |
|
1 | 1285 |
|
701 | 1286 |
basicSize |
1287 |
"return the number of indexed instvars - SmallIntegers have none. |
|
1288 |
Defined here since basicSize in Object ommits the SmallInteger check." |
|
1289 |
||
1290 |
^ 0 |
|
1291 |
! |
|
1292 |
||
1293 |
size |
|
1294 |
"return the number of indexed instvars - SmallIntegers have none." |
|
1295 |
||
1296 |
^ 0 |
|
1 | 1297 |
! ! |
1298 |
||
1299 |
!SmallInteger methodsFor:'coercing and converting'! |
|
1300 |
||
701 | 1301 |
asCharacter |
1302 |
"Return a character with the receiver as ascii value" |
|
41 | 1303 |
|
701 | 1304 |
^ Character value:self |
1 | 1305 |
! |
1306 |
||
1307 |
asFloat |
|
1308 |
"return a Float with same value as receiver" |
|
1309 |
||
1310 |
%{ /* NOCONTEXT */ |
|
1311 |
||
1312 |
OBJ newFloat; |
|
1133 | 1313 |
double dVal = (double)__intVal(self); |
1 | 1314 |
|
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1315 |
__qMKFLOAT(newFloat, dVal); |
1 | 1316 |
RETURN ( newFloat ); |
1317 |
%} |
|
1318 |
! |
|
1319 |
||
1320 |
asLargeInteger |
|
1321 |
"return a LargeInteger with same value as receiver" |
|
1322 |
||
1323 |
^ LargeInteger value:self |
|
1324 |
! |
|
1325 |
||
1199 | 1326 |
asShortFloat |
1327 |
"return a ShortFloat with same value as receiver" |
|
1328 |
||
1329 |
%{ /* NOCONTEXT */ |
|
1330 |
||
1331 |
OBJ dummy = @global(ShortFloat); |
|
1332 |
OBJ newFloat; |
|
1333 |
float fVal = (float)__intVal(self); |
|
1334 |
||
1695
465e1eba8e8e
removed useless context-arg of all qMK macros - needs full recompile.
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
1335 |
__qMKSFLOAT(newFloat, fVal); |
1199 | 1336 |
RETURN ( newFloat ); |
1337 |
%} |
|
1338 |
! |
|
1339 |
||
701 | 1340 |
coerce:aNumber |
1341 |
"return aNumber converted into receivers type" |
|
1342 |
||
1343 |
^ aNumber asInteger |
|
1344 |
! |
|
1345 |
||
1346 |
generality |
|
1347 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
1348 |
||
1349 |
^ 20 |
|
1336 | 1350 |
! |
1351 |
||
1352 |
signExtendedByteValue |
|
1353 |
"return a smallInteger from sign-extending the 8'th bit. |
|
1354 |
May be useful for communication interfaces" |
|
1355 |
||
1356 |
%{ /* NOCONTEXT */ |
|
2781 | 1357 |
INT i = __intVal(self); |
1336 | 1358 |
|
1359 |
if (i & 0x80) { |
|
4167 | 1360 |
i = i | ~0xFFL; |
1336 | 1361 |
} else { |
4167 | 1362 |
i = i & 0x7F; |
1336 | 1363 |
} |
1364 |
||
1365 |
RETURN (__MKSMALLINT(i)); |
|
1366 |
%} |
|
1367 |
||
1368 |
" |
|
1369 |
16rFF signExtendedByteValue |
|
1370 |
16r7F signExtendedByteValue |
|
1371 |
" |
|
1372 |
! |
|
1373 |
||
1374 |
signExtendedShortValue |
|
1375 |
"return a smallInteger from sign-extending the 16'th bit. |
|
1376 |
May be useful for communication interfaces" |
|
1377 |
||
1378 |
%{ /* NOCONTEXT */ |
|
2781 | 1379 |
INT i = __intVal(self); |
1336 | 1380 |
|
1381 |
if (i & 0x8000) { |
|
4167 | 1382 |
i = i | ~0xFFFFL; |
1336 | 1383 |
} else { |
4167 | 1384 |
i = i & 0x7FFF; |
1336 | 1385 |
} |
1386 |
||
1387 |
RETURN (__MKSMALLINT(i)); |
|
1388 |
%} |
|
1389 |
||
1390 |
" |
|
3892 | 1391 |
16rFFFF signExtendedShortValue |
1336 | 1392 |
16r7FFF signExtendedShortValue |
1393 |
" |
|
701 | 1394 |
! ! |
1395 |
||
1396 |
!SmallInteger methodsFor:'comparing'! |
|
1397 |
||
1398 |
< aNumber |
|
1399 |
"return true, if the argument is greater than the receiver" |
|
1400 |
||
1401 |
%{ /* NOCONTEXT */ |
|
1402 |
||
1403 |
if (__isSmallInteger(aNumber)) { |
|
1404 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1405 |
RETURN ( (__intVal(self) < __intVal(aNumber)) ? true : false ); |
701 | 1406 |
#else |
1407 |
/* tag bit does not change ordering */ |
|
1408 |
RETURN ( ((INT)self < (INT)aNumber) ? true : false ); |
|
1409 |
#endif |
|
1410 |
} |
|
1411 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1412 |
RETURN ( ((double)__intVal(self) < __floatVal(aNumber)) ? true : false ); |
701 | 1413 |
} |
1414 |
%} |
|
1415 |
. |
|
1416 |
^ aNumber lessFromInteger:self |
|
1417 |
"^ self retry:#< coercing:aNumber" |
|
1418 |
! |
|
1419 |
||
1420 |
<= aNumber |
|
1421 |
"return true, if the argument is greater or equal" |
|
1422 |
||
1423 |
%{ /* NOCONTEXT */ |
|
1424 |
||
1425 |
if (__isSmallInteger(aNumber)) { |
|
1426 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1427 |
RETURN ( (__intVal(self) <= __intVal(aNumber)) ? true : false ); |
701 | 1428 |
#else |
1429 |
/* tag bit does not change ordering */ |
|
1430 |
RETURN ( ((INT)self <= (INT)aNumber) ? true : false ); |
|
1431 |
#endif |
|
1432 |
} |
|
1433 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1434 |
RETURN ( ((double)__intVal(self) <= __floatVal(aNumber)) ? true : false ); |
701 | 1435 |
} |
1436 |
%} |
|
1437 |
. |
|
1438 |
^ self retry:#<= coercing:aNumber |
|
1439 |
! |
|
1440 |
||
1441 |
= aNumber |
|
1442 |
"return true, if the arguments value is equal to mine" |
|
1443 |
||
1444 |
%{ /* NOCONTEXT */ |
|
1445 |
||
1446 |
if (aNumber == self) { |
|
1447 |
RETURN ( true ); |
|
1448 |
} |
|
1449 |
if (! __isNonNilObject(aNumber)) { |
|
1450 |
/* a smallint or nil */ |
|
1451 |
RETURN ( false ); |
|
1452 |
} |
|
1453 |
||
1454 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1455 |
RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? true : false ); |
701 | 1456 |
} |
1457 |
%} |
|
1458 |
. |
|
1459 |
aNumber respondsToArithmetic ifFalse:[^ false]. |
|
1460 |
^ self retry:#= coercing:aNumber |
|
1461 |
! |
|
1462 |
||
1463 |
> aNumber |
|
1464 |
"return true, if the argument is less than the receiver" |
|
1465 |
||
1466 |
%{ /* NOCONTEXT */ |
|
1467 |
||
1468 |
if (__isSmallInteger(aNumber)) { |
|
1469 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1470 |
RETURN ( (__intVal(self) > __intVal(aNumber)) ? true : false ); |
701 | 1471 |
#else |
1472 |
/* tag bit does not change ordering */ |
|
1473 |
RETURN ( ((INT)self > (INT)aNumber) ? true : false ); |
|
1474 |
#endif |
|
1475 |
} |
|
1476 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1477 |
RETURN ( ((double)__intVal(self) > __floatVal(aNumber)) ? true : false ); |
701 | 1478 |
} |
1479 |
%} |
|
1480 |
. |
|
1481 |
^ self retry:#> coercing:aNumber |
|
1482 |
! |
|
1483 |
||
1484 |
>= aNumber |
|
1485 |
"return true, if the argument is less or equal" |
|
1486 |
||
1487 |
%{ /* NOCONTEXT */ |
|
1488 |
||
1489 |
if (__isSmallInteger(aNumber)) { |
|
1490 |
#ifdef POSITIVE_ADDRESSES |
|
1133 | 1491 |
RETURN ( (__intVal(self) >= __intVal(aNumber)) ? true : false ); |
701 | 1492 |
#else |
1493 |
/* tag bit does not change ordering */ |
|
1494 |
RETURN ( ((INT)self >= (INT)aNumber) ? true : false ); |
|
1495 |
#endif |
|
1496 |
} |
|
1497 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1498 |
RETURN ( ((double)__intVal(self) >= __floatVal(aNumber)) ? true : false ); |
701 | 1499 |
} |
1500 |
%} |
|
1501 |
. |
|
1502 |
^ self retry:#>= coercing:aNumber |
|
1503 |
! |
|
1 | 1504 |
|
701 | 1505 |
hash |
1506 |
"return an integer useful for hashing on value" |
|
1507 |
||
1508 |
self >= 0 ifTrue:[^ self]. |
|
1509 |
^ self negated |
|
1510 |
! |
|
1511 |
||
1512 |
identityHash |
|
1513 |
"return an integer useful for hashing on identity" |
|
1514 |
||
1964
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
1515 |
self >= 0 ifTrue:[^ self]. |
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
1516 |
^ self negated |
1963
ea26c7b9ca1d
experimental: new hash value for smallInts
Claus Gittinger <cg@exept.de>
parents:
1893
diff
changeset
|
1517 |
|
1964
20bb7197d19f
oops - the last one was no good
Claus Gittinger <cg@exept.de>
parents:
1963
diff
changeset
|
1518 |
"Modified: 11.11.1996 / 18:42:14 / cg" |
701 | 1519 |
! |
1520 |
||
1521 |
max:aNumber |
|
1522 |
"return the receiver or the argument, whichever is greater" |
|
1523 |
||
1524 |
%{ /* NOCONTEXT */ |
|
1525 |
||
1526 |
if (__isSmallInteger(aNumber)) { |
|
2216 | 1527 |
#if TAG_INT == 1 |
1528 |
/* tag bit does not change ordering */ |
|
1529 |
if ((INT)(self) > (INT)(aNumber)) |
|
701 | 1530 |
#else |
2216 | 1531 |
if (__intVal(self) > __intVal(aNumber)) |
701 | 1532 |
#endif |
2216 | 1533 |
{ |
701 | 1534 |
RETURN ( self ); |
1535 |
} |
|
1536 |
RETURN ( aNumber ); |
|
1537 |
} |
|
1538 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1539 |
if ( (double)__intVal(self) > __floatVal(aNumber) ) { |
701 | 1540 |
RETURN ( self ); |
1541 |
} |
|
1542 |
RETURN ( aNumber ); |
|
1543 |
} |
|
2216 | 1544 |
%}. |
1545 |
"/ fallback for non-smallInteger argument |
|
1546 |
||
701 | 1547 |
(self > aNumber) ifTrue:[^ self]. |
1548 |
^ aNumber |
|
1549 |
! |
|
1550 |
||
1551 |
min:aNumber |
|
1552 |
"return the receiver or the argument, whichever is smaller" |
|
1553 |
||
1554 |
%{ /* NOCONTEXT */ |
|
1555 |
||
1556 |
if (__isSmallInteger(aNumber)) { |
|
2216 | 1557 |
#if TAG_INT == 1 |
1558 |
/* tag bit does not change ordering */ |
|
1559 |
if ((INT)(self) < (INT)(aNumber)) |
|
701 | 1560 |
#else |
2216 | 1561 |
if (__intVal(self) < __intVal(aNumber)) |
701 | 1562 |
#endif |
2216 | 1563 |
{ |
701 | 1564 |
RETURN ( self ); |
1565 |
} |
|
1566 |
RETURN ( aNumber ); |
|
1567 |
} |
|
1568 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1569 |
if ( (double)__intVal(self) < __floatVal(aNumber) ) { |
701 | 1570 |
RETURN ( self ); |
1571 |
} |
|
1572 |
RETURN ( aNumber ); |
|
1573 |
} |
|
2216 | 1574 |
%}. |
1575 |
"/ fallback for non-smallInteger argument |
|
1576 |
||
701 | 1577 |
(self < aNumber) ifTrue:[^ self]. |
1578 |
^ aNumber |
|
1579 |
! |
|
1580 |
||
1581 |
~= aNumber |
|
1582 |
"return true, if the arguments value is not equal to mine" |
|
1583 |
||
1584 |
%{ /* NOCONTEXT */ |
|
1585 |
||
1586 |
if (aNumber == self) { |
|
1587 |
RETURN ( false ); |
|
1588 |
} |
|
1589 |
if (! __isNonNilObject(aNumber)) { |
|
1590 |
/* a smallint or nil */ |
|
1591 |
RETURN ( true ); |
|
1592 |
} |
|
1593 |
||
1594 |
if (__isFloatLike(aNumber)) { |
|
1133 | 1595 |
RETURN ( ((double)__intVal(self) == __floatVal(aNumber)) ? false : true ); |
701 | 1596 |
} |
2216 | 1597 |
%}. |
701 | 1598 |
aNumber respondsToArithmetic ifFalse:[^ true]. |
1599 |
^ self retry:#~= coercing:aNumber |
|
1600 |
! ! |
|
1601 |
||
1602 |
!SmallInteger methodsFor:'copying'! |
|
1603 |
||
1604 |
deepCopy |
|
1605 |
"return a deep copy of myself |
|
1606 |
- reimplemented here since smallintegers are unique" |
|
1607 |
||
1608 |
^ self |
|
1609 |
! |
|
1610 |
||
1611 |
deepCopyUsing:aDictionary |
|
1612 |
"return a deep copy of myself |
|
1613 |
- reimplemented here since smallintegers are unique" |
|
1614 |
||
1615 |
^ self |
|
1616 |
! |
|
1617 |
||
1618 |
shallowCopy |
|
1619 |
"return a shallow copy of myself |
|
1620 |
- reimplemented here since smallintegers are unique" |
|
1621 |
||
1622 |
^ self |
|
1623 |
! |
|
1624 |
||
1625 |
simpleDeepCopy |
|
1626 |
"return a deep copy of myself |
|
1627 |
- reimplemented here since smallintegers are unique" |
|
1628 |
||
1629 |
^ self |
|
1 | 1630 |
! ! |
1631 |
||
214 | 1632 |
!SmallInteger methodsFor:'iteration'! |
1 | 1633 |
|
1634 |
timesRepeat:aBlock |
|
357 | 1635 |
"evaluate the argument, aBlock self times. |
1636 |
Reimplemented as primitive for speed" |
|
1 | 1637 |
|
357 | 1638 |
%{ |
1639 |
REGISTER INT tmp; |
|
1640 |
static struct inlineCache blockVal = __ILC0(0); |
|
1 | 1641 |
|
357 | 1642 |
tmp = __intVal(self); |
1643 |
if (tmp > 0) { |
|
1644 |
if (__isBlockLike(aBlock) |
|
1133 | 1645 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(0))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1646 |
{ |
2254 | 1647 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1648 |
|
2216 | 1649 |
/* |
2678 | 1650 |
* specially tuned version for compiled blocks, |
1651 |
* (the most common case) |
|
2216 | 1652 |
*/ |
4167 | 1653 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 1654 |
#ifdef PARANOIA |
4167 | 1655 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 1656 |
#endif |
1657 |
) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1658 |
|
357 | 1659 |
#ifdef NEW_BLOCK_CALL |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1660 |
|
2254 | 1661 |
# define BLOCK_ARG aBlock |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1662 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1663 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1664 |
|
2254 | 1665 |
# define BLOCK_ARG rHome |
1666 |
REGISTER OBJ rHome; |
|
2678 | 1667 |
|
1668 |
/* |
|
1669 |
* home on stack - no need to refetch |
|
1670 |
*/ |
|
2254 | 1671 |
rHome = __BlockInstPtr(aBlock)->b_home; |
1672 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1673 |
#endif |
2254 | 1674 |
{ |
2604
7f11d9ba8d03
NT compiler has trouble with unrolled loops ...
Claus Gittinger <cg@exept.de>
parents:
2470
diff
changeset
|
1675 |
#ifdef WIN32 |
7f11d9ba8d03
NT compiler has trouble with unrolled loops ...
Claus Gittinger <cg@exept.de>
parents:
2470
diff
changeset
|
1676 |
# undef UNROLL_LOOPS |
7f11d9ba8d03
NT compiler has trouble with unrolled loops ...
Claus Gittinger <cg@exept.de>
parents:
2470
diff
changeset
|
1677 |
#endif |
2693 | 1678 |
|
2216 | 1679 |
#ifdef UNROLL_LOOPS |
1680 |
||
2254 | 1681 |
/* |
1682 |
* you are not supposed to program like this - I know what I do |
|
1683 |
*/ |
|
1684 |
while (tmp > 8) { |
|
1685 |
if (InterruptPending != nil) goto interrupted0; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1686 |
continue0: |
2254 | 1687 |
(*codeVal)(BLOCK_ARG); |
1688 |
if (InterruptPending != nil) goto interrupted1; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1689 |
continue1: |
2254 | 1690 |
(*codeVal)(BLOCK_ARG); |
1691 |
if (InterruptPending != nil) goto interrupted2; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1692 |
continue2: |
2254 | 1693 |
(*codeVal)(BLOCK_ARG); |
1694 |
if (InterruptPending != nil) goto interrupted3; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1695 |
continue3: |
2254 | 1696 |
(*codeVal)(BLOCK_ARG); |
1697 |
if (InterruptPending != nil) goto interrupted4; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1698 |
continue4: |
2254 | 1699 |
(*codeVal)(BLOCK_ARG); |
1700 |
if (InterruptPending != nil) goto interrupted5; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1701 |
continue5: |
2254 | 1702 |
(*codeVal)(BLOCK_ARG); |
1703 |
if (InterruptPending != nil) goto interrupted6; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1704 |
continue6: |
2254 | 1705 |
(*codeVal)(BLOCK_ARG); |
1706 |
if (InterruptPending != nil) goto interrupted7; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1707 |
continue7: |
2254 | 1708 |
(*codeVal)(BLOCK_ARG); |
1709 |
tmp -= 8; |
|
1710 |
} |
|
2216 | 1711 |
#endif /* UNROLL_LOOPS */ |
2254 | 1712 |
do { |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1713 |
if (InterruptPending != nil) goto interruptedX; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1714 |
continueX: |
2254 | 1715 |
(*codeVal)(BLOCK_ARG); |
1716 |
} while(--tmp); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1717 |
|
2254 | 1718 |
RETURN (self); |
2693 | 1719 |
if (0) { |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1720 |
#ifdef UNROLL_LOOPS |
2693 | 1721 |
interrupted0: |
1722 |
__interruptL(@line); goto continue0; |
|
1723 |
interrupted1: |
|
1724 |
__interruptL(@line); goto continue1; |
|
1725 |
interrupted2: |
|
1726 |
__interruptL(@line); goto continue2; |
|
1727 |
interrupted3: |
|
1728 |
__interruptL(@line); goto continue3; |
|
1729 |
interrupted4: |
|
1730 |
__interruptL(@line); goto continue4; |
|
1731 |
interrupted5: |
|
1732 |
__interruptL(@line); goto continue5; |
|
1733 |
interrupted6: |
|
1734 |
__interruptL(@line); goto continue6; |
|
1735 |
interrupted7: |
|
1736 |
__interruptL(@line); goto continue7; |
|
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1737 |
#endif /* UNROLL_LOOPS */ |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1738 |
interruptedX: |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
1739 |
__interruptL(@line); goto continueX; |
2693 | 1740 |
} |
394 | 1741 |
} |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1742 |
} |
394 | 1743 |
} |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1744 |
|
2216 | 1745 |
# undef BLOCK_ARG |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1746 |
|
400 | 1747 |
#ifdef NEW_BLOCK_CALL |
2216 | 1748 |
# define BLOCK_ARG aBlock |
1749 |
# define IBLOCK_ARG nil |
|
400 | 1750 |
#else |
2216 | 1751 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
1752 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
400 | 1753 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
1754 |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1755 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1756 |
* sorry - must check for the blocks code within the loops; |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1757 |
* it could be recompiled or flushed (in the interrupt) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1758 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1759 |
do { |
2254 | 1760 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1761 |
|
2254 | 1762 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1763 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1764 |
* arg is a compiled block with code - |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1765 |
* directly call it without going through Block>>value |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1766 |
* however, if there is an interrupt, refetch the code pointer. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1767 |
*/ |
2649 | 1768 |
/* stay here, while no interrupts are pending ... */ |
1769 |
do { |
|
4167 | 1770 |
(*codeVal)(BLOCK_ARG); |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1771 |
if (InterruptPending != nil) goto outerLoop; |
2649 | 1772 |
} while (--tmp); |
4167 | 1773 |
RETURN (self); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1774 |
} else { |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1775 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1776 |
|
2216 | 1777 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1778 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1779 |
* arg is a compiled block with bytecode - |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1780 |
* directly call interpreter without going through Block>>value |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1781 |
*/ |
2216 | 1782 |
__interpret(aBlock, 0, nil, IBLOCK_ARG, nil, nil); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1783 |
} else { |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1784 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1785 |
* arg is something else - call it with #value |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1786 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1787 |
(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal); |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1788 |
} |
400 | 1789 |
} |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1790 |
outerLoop: ; |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
1791 |
} while (--tmp); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1792 |
|
2216 | 1793 |
# undef BLOCK_ARG |
1794 |
# undef IBLOCK_ARG |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1795 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1796 |
RETURN (self); |
357 | 1797 |
} |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
1798 |
|
394 | 1799 |
/* |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1800 |
* not a block-like thingy - call it with #value |
394 | 1801 |
*/ |
1802 |
do { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1803 |
if (InterruptPending != nil) __interruptL(@line); |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1804 |
(*blockVal.ilc_func)(aBlock, @symbol(value), nil, &blockVal); |
394 | 1805 |
} while(--tmp); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1806 |
RETURN (self); |
357 | 1807 |
} |
1808 |
%} |
|
1809 |
||
1810 |
"/ |count "{ Class: SmallInteger }" | |
|
1811 |
"/ |
|
1812 |
"/ count := self. |
|
1813 |
"/ [count > 0] whileTrue:[ |
|
1814 |
"/ aBlock value. |
|
1815 |
"/ count := count - 1 |
|
1816 |
"/ ] |
|
1 | 1817 |
! |
1818 |
||
701 | 1819 |
to:stop by:incr do:aBlock |
1820 |
"reimplemented as primitive for speed" |
|
1821 |
||
1822 |
%{ |
|
1823 |
REGISTER INT tmp, step; |
|
1824 |
REGISTER INT final; |
|
1825 |
static struct inlineCache blockVal = __ILC1(0); |
|
1826 |
||
1827 |
if (__bothSmallInteger(incr, stop)) { |
|
1133 | 1828 |
tmp = __intVal(self); |
1829 |
final = __intVal(stop); |
|
1830 |
step = __intVal(incr); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1831 |
|
701 | 1832 |
if (__isBlockLike(aBlock) |
1133 | 1833 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1834 |
{ |
2254 | 1835 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1836 |
|
2216 | 1837 |
/* |
1838 |
* specially tuned version for static compiled blocks, called with |
|
1839 |
* home on the stack (the most common case) |
|
1840 |
*/ |
|
4167 | 1841 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
2678 | 1842 |
#ifdef PARANOIA |
4167 | 1843 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
2678 | 1844 |
#endif |
1845 |
) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1846 |
|
701 | 1847 |
#ifdef NEW_BLOCK_CALL |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1848 |
|
2254 | 1849 |
# define BLOCK_ARG aBlock |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1850 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1851 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1852 |
|
2254 | 1853 |
# define BLOCK_ARG rHome |
1854 |
REGISTER OBJ rHome; |
|
1855 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
1856 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1857 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1858 |
#endif |
2254 | 1859 |
{ |
1860 |
if (step < 0) { |
|
1861 |
if (step == -1) { |
|
1862 |
while (tmp >= final) { |
|
1863 |
if (InterruptPending != nil) __interruptL(@line); |
|
1864 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
1865 |
tmp--; |
|
2216 | 1866 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1867 |
} else { |
2254 | 1868 |
while (tmp >= final) { |
2216 | 1869 |
if (InterruptPending != nil) __interruptL(@line); |
2254 | 1870 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
2216 | 1871 |
tmp += step; |
1872 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1873 |
} |
2254 | 1874 |
} else { |
1875 |
if (step == 1) { |
|
1876 |
while (tmp <= final) { |
|
1877 |
if (InterruptPending != nil) __interruptL(@line); |
|
1878 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
1879 |
tmp++; |
|
1880 |
} |
|
1881 |
} else { |
|
4167 | 1882 |
while (tmp <= final) { |
2254 | 1883 |
if (InterruptPending != nil) __interruptL(@line); |
1884 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
1885 |
tmp += step; |
|
1886 |
} |
|
1887 |
} |
|
2216 | 1888 |
} |
2254 | 1889 |
RETURN (self); |
2216 | 1890 |
} |
1891 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1892 |
} |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1893 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1894 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1895 |
* sorry - must check for the blocks code within the loops; |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1896 |
* it could be recompiled or flushed (in the interrupt) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1897 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1898 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1899 |
# undef BLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1900 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1901 |
#ifdef NEW_BLOCK_CALL |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1902 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1903 |
# define IBLOCK_ARG nil |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1904 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1905 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1906 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1907 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1908 |
|
701 | 1909 |
if (step < 0) { |
1910 |
while (tmp >= final) { |
|
2254 | 1911 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1912 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1913 |
if (InterruptPending != nil) __interruptL(@line); |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1914 |
|
2254 | 1915 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 1916 |
/* |
1917 |
* arg is a compiled block with code - |
|
1918 |
* directly call it without going through Block>>value |
|
1919 |
*/ |
|
2254 | 1920 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1921 |
} else { |
2216 | 1922 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1923 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1924 |
* arg is a compiled block with bytecode - |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1925 |
* directly call interpreter without going through Block>>value |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1926 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1927 |
#ifdef PASS_ARG_POINTER |
2216 | 1928 |
{ |
1929 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1930 |
|
2216 | 1931 |
idx = __MKSMALLINT(tmp); |
1932 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
|
1933 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1934 |
#else |
2216 | 1935 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __MKSMALLINT(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1936 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1937 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1938 |
} else { |
2216 | 1939 |
/* |
1940 |
* arg is something else - call it with #value |
|
1941 |
*/ |
|
1942 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __MKSMALLINT(tmp)); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1943 |
} |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1944 |
} |
701 | 1945 |
tmp += step; |
1946 |
} |
|
1947 |
} else { |
|
1948 |
while (tmp <= final) { |
|
2254 | 1949 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1950 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1951 |
if (InterruptPending != nil) __interruptL(@line); |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1952 |
|
2254 | 1953 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 1954 |
/* |
1955 |
* arg is a compiled block with code - |
|
1956 |
* directly call it without going through Block>>value |
|
1957 |
*/ |
|
2254 | 1958 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
2216 | 1959 |
} else { |
1960 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
1961 |
/* |
|
1962 |
* arg is a compiled block with bytecode - |
|
1963 |
* directly call interpreter without going through Block>>value |
|
1964 |
*/ |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1965 |
#ifdef PASS_ARG_POINTER |
2216 | 1966 |
{ |
1967 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1968 |
|
2216 | 1969 |
idx = __MKSMALLINT(tmp); |
1970 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
|
1971 |
} |
|
701 | 1972 |
#else |
2216 | 1973 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __MKSMALLINT(tmp)); |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1974 |
#endif |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1975 |
|
2216 | 1976 |
} else { |
1977 |
/* |
|
1978 |
* arg is something else - call it with #value: |
|
1979 |
*/ |
|
1980 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __MKSMALLINT(tmp)); |
|
1981 |
} |
|
1982 |
} |
|
1983 |
tmp += step; |
|
1984 |
} |
|
701 | 1985 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1986 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1987 |
# undef BLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1988 |
# undef IBLOCK_ARG |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1989 |
|
701 | 1990 |
} else { |
1991 |
/* |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1992 |
* arg is something else - call it with #value: |
701 | 1993 |
*/ |
1994 |
if (step < 0) { |
|
1995 |
while (tmp >= final) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
1996 |
if (InterruptPending != nil) __interruptL(@line); |
701 | 1997 |
|
1998 |
(*blockVal.ilc_func)(aBlock, |
|
1999 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
2000 |
nil, &blockVal, |
1133 | 2001 |
__MKSMALLINT(tmp)); |
701 | 2002 |
tmp += step; |
2003 |
} |
|
2004 |
} else { |
|
2005 |
while (tmp <= final) { |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2006 |
if (InterruptPending != nil) __interruptL(@line); |
701 | 2007 |
|
2008 |
(*blockVal.ilc_func)(aBlock, |
|
2009 |
@symbol(value:), |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
2010 |
nil, &blockVal, |
1133 | 2011 |
__MKSMALLINT(tmp)); |
701 | 2012 |
tmp += step; |
2013 |
} |
|
2014 |
} |
|
2015 |
} |
|
2016 |
RETURN ( self ); |
|
2017 |
} |
|
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1556
diff
changeset
|
2018 |
%}. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2019 |
"/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2020 |
"/ arrive here if stop is not a smallInteger |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2021 |
"/ pass on to super ... |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2022 |
|
701 | 2023 |
^ super to:stop by:incr do:aBlock |
2024 |
||
2025 |
" |
|
2026 |
1 to:10 by:3 do:[:i | i printNewline] |
|
2027 |
" |
|
2028 |
! |
|
2029 |
||
1 | 2030 |
to:stop do:aBlock |
62 | 2031 |
"evaluate aBlock for every integer between (and including) the receiver |
2032 |
and the argument, stop. |
|
357 | 2033 |
Reimplemented as primitive for speed" |
1 | 2034 |
|
2035 |
%{ |
|
2036 |
REGISTER INT tmp; |
|
2037 |
INT final; |
|
216 | 2038 |
static struct inlineCache blockVal = __ILC1(0); |
1 | 2039 |
|
252 | 2040 |
if (__isSmallInteger(stop)) { |
1133 | 2041 |
tmp = __intVal(self); |
2042 |
final = __intVal(stop); |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2043 |
|
214 | 2044 |
if (__isBlockLike(aBlock) |
1133 | 2045 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2046 |
{ |
2216 | 2047 |
/* |
2048 |
* specially tuned version for the most common case, |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2049 |
* where called with home on the stack |
2216 | 2050 |
*/ |
2254 | 2051 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2052 |
|
4167 | 2053 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2254 | 2054 |
|
13 | 2055 |
#ifdef NEW_BLOCK_CALL |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2056 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2057 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2058 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2059 |
#else |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2060 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2061 |
# define BLOCK_ARG rHome |
2216 | 2062 |
REGISTER OBJ rHome; |
2063 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
2064 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2065 |
#endif |
400 | 2066 |
{ |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2067 |
|
2678 | 2068 |
#ifdef PARANOIA |
2069 |
if (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC))) |
|
2070 |
#endif |
|
2071 |
{ |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2072 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2073 |
* static compiled blocks ... |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2074 |
*/ |
2216 | 2075 |
#ifdef UNROLL_LOOPS |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2076 |
/* |
2693 | 2077 |
* The following code is designed to run as fast as possible; |
2078 |
* - taken branches only if interrupts are pending |
|
2079 |
* - only forward branches (which are usually predicted as not taken) |
|
2080 |
* - unrolled the loop |
|
2081 |
* |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2082 |
* you are not supposed to program like this - I know what I do |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2083 |
*/ |
2693 | 2084 |
# if TAG_INT==1 |
2770 | 2085 |
INT t8 = (INT)(__MKSMALLINT(tmp+8)); |
2086 |
tmp = (INT)(__MKSMALLINT(tmp)); |
|
2087 |
final = (INT)(__MKSMALLINT(final)); |
|
2693 | 2088 |
# else |
2770 | 2089 |
INT t8 = tmp+8; |
2693 | 2090 |
# endif |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2091 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2092 |
for (;;) { |
2693 | 2093 |
|
2094 |
while (t8 <= final) { |
|
2095 |
# if TAG_INT==1 |
|
2770 | 2096 |
t8 += (INT)(__MASKSMALLINT(8)); |
2693 | 2097 |
# else |
2098 |
t8 += 8; |
|
2099 |
# endif |
|
2100 |
if (InterruptPending != nil) goto interrupted0; |
|
2101 |
continue0: |
|
2102 |
# if TAG_INT==1 |
|
2103 |
(*codeVal)(BLOCK_ARG, tmp); |
|
2104 |
# else |
|
2105 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2106 |
# endif |
|
2107 |
if (InterruptPending != nil) goto interrupted1; |
|
2108 |
continue1: |
|
2109 |
# if TAG_INT==1 |
|
2770 | 2110 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(1)) ); |
2693 | 2111 |
# else |
2112 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+1)); |
|
2113 |
# endif |
|
2114 |
if (InterruptPending != nil) goto interrupted2; |
|
2115 |
continue2: |
|
2116 |
# if TAG_INT==1 |
|
2770 | 2117 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(2)) ); |
2693 | 2118 |
# else |
2119 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+2)); |
|
2120 |
# endif |
|
2121 |
if (InterruptPending != nil) goto interrupted3; |
|
2122 |
continue3: |
|
2123 |
# if TAG_INT==1 |
|
2770 | 2124 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(3)) ); |
2693 | 2125 |
# else |
2126 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+3)); |
|
2127 |
# endif |
|
2128 |
if (InterruptPending != nil) goto interrupted4; |
|
2129 |
continue4: |
|
2130 |
# if TAG_INT==1 |
|
2770 | 2131 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(4)) ); |
2693 | 2132 |
# else |
2133 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+4)); |
|
2134 |
# endif |
|
2135 |
if (InterruptPending != nil) goto interrupted5; |
|
2136 |
continue5: |
|
2137 |
# if TAG_INT==1 |
|
2770 | 2138 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(5)) ); |
2693 | 2139 |
# else |
2140 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+5)); |
|
2141 |
# endif |
|
2142 |
if (InterruptPending != nil) goto interrupted6; |
|
2143 |
continue6: |
|
2144 |
# if TAG_INT==1 |
|
2770 | 2145 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(6)) ); |
2693 | 2146 |
# else |
2147 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+6)); |
|
2148 |
# endif |
|
2149 |
if (InterruptPending != nil) goto interrupted7; |
|
2150 |
continue7: |
|
2151 |
# if TAG_INT==1 |
|
2770 | 2152 |
(*codeVal)(BLOCK_ARG, tmp+(INT)(__MASKSMALLINT(7)) ); |
2693 | 2153 |
# else |
2154 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp+7)); |
|
2155 |
# endif |
|
2156 |
||
2157 |
# if TAG_INT==1 |
|
2770 | 2158 |
tmp += (INT)(__MASKSMALLINT(8)); |
2693 | 2159 |
# else |
2160 |
tmp += 8; |
|
2161 |
# endif |
|
2162 |
} |
|
4167 | 2163 |
while (tmp <= final) { |
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2164 |
if (InterruptPending != nil) goto interruptedX; |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2165 |
continueX: |
2693 | 2166 |
# if TAG_INT==1 |
2167 |
(*codeVal)(BLOCK_ARG, tmp); |
|
2770 | 2168 |
tmp += (INT)(__MASKSMALLINT(1)); |
2693 | 2169 |
# else |
2170 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2171 |
tmp++; |
|
2172 |
# endif |
|
4167 | 2173 |
} |
2174 |
RETURN (self); |
|
2693 | 2175 |
|
2216 | 2176 |
if (0) { |
2177 |
/* |
|
2178 |
* no discussion about those gotos ... |
|
2179 |
* ... its better for your CPU's pipelines |
|
2180 |
* (if you dont understand why, just dont argue). |
|
2181 |
*/ |
|
2182 |
interrupted7: |
|
2183 |
__interruptL(@line); goto continue7; |
|
2184 |
interrupted6: |
|
2185 |
__interruptL(@line); goto continue6; |
|
2186 |
interrupted5: |
|
2187 |
__interruptL(@line); goto continue5; |
|
2188 |
interrupted4: |
|
2189 |
__interruptL(@line); goto continue4; |
|
2190 |
interrupted3: |
|
2191 |
__interruptL(@line); goto continue3; |
|
2192 |
interrupted2: |
|
2193 |
__interruptL(@line); goto continue2; |
|
2194 |
interrupted1: |
|
2195 |
__interruptL(@line); goto continue1; |
|
2196 |
interrupted0: |
|
2197 |
__interruptL(@line); goto continue0; |
|
2824
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2198 |
interruptedX: |
5295fc0fddb7
oops - right shift by int-size did not work on some machines
Claus Gittinger <cg@exept.de>
parents:
2815
diff
changeset
|
2199 |
__interruptL(@line); goto continueX; |
2216 | 2200 |
} |
2640 | 2201 |
} |
2641 | 2202 |
#else |
2640 | 2203 |
while (tmp <= final) { |
2204 |
if (InterruptPending != nil) __interruptL(@line); |
|
2205 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2206 |
tmp ++; |
|
2216 | 2207 |
} |
2640 | 2208 |
RETURN (self); |
2641 | 2209 |
#endif /* UNROLL_LOOPS */ |
2216 | 2210 |
} |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2211 |
|
2216 | 2212 |
/* |
2213 |
* mhmh - seems to be a block with dynamic code |
|
2214 |
* must refetch, to allow dynamic recompilation or code flush. |
|
2215 |
*/ |
|
2216 |
while (tmp <= final) { |
|
2217 |
if (InterruptPending != nil) __interruptL(@line); |
|
2254 | 2218 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) == (OBJFUNC)nil) break; |
2219 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2216 | 2220 |
tmp ++; |
2221 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2222 |
|
2216 | 2223 |
if (tmp > final) { |
2224 |
RETURN (self); |
|
2225 |
} |
|
2226 |
} |
|
2227 |
} |
|
2228 |
} |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2229 |
|
2216 | 2230 |
# undef BLOCK_ARG |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2231 |
|
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2232 |
#ifdef NEW_BLOCK_CALL |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2233 |
# define BLOCK_ARG aBlock |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2234 |
# define IBLOCK_ARG nil |
400 | 2235 |
#else |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2236 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2237 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
400 | 2238 |
#endif |
1036
d79dc9e4c6f5
binary storage stuff is not needed here
Claus Gittinger <cg@exept.de>
parents:
927
diff
changeset
|
2239 |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2240 |
/* |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2241 |
* sorry - must check for the blocks code within the loops; |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2242 |
* it could be recompiled or flushed (in the interrupt) |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2243 |
*/ |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2244 |
while (tmp <= final) { |
2254 | 2245 |
REGISTER OBJFUNC codeVal; |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2246 |
|
2254 | 2247 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2216 | 2248 |
/* |
2249 |
* arg is a compiled block with code - |
|
2250 |
* directly call it without going through Block>>value |
|
2251 |
*/ |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2252 |
|
4167 | 2253 |
/* stay here, while no interrupts are pending ... */ |
2254 |
do { |
|
2255 |
(*codeVal)(BLOCK_ARG, __MKSMALLINT(tmp)); |
|
2256 |
if (InterruptPending != nil) goto outerLoop; |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2257 |
tmp++; |
4167 | 2258 |
} while (tmp <= final); |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2259 |
RETURN (self); |
2216 | 2260 |
} else { |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2261 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2262 |
|
2216 | 2263 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
2264 |
/* |
|
2265 |
* arg is a compiled block with bytecode - |
|
2266 |
* directly call interpreter without going through Block>>value |
|
2267 |
*/ |
|
400 | 2268 |
#ifdef PASS_ARG_POINTER |
2216 | 2269 |
{ |
2270 |
OBJ idx; |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2271 |
|
2216 | 2272 |
idx = __MKSMALLINT(tmp); |
2273 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &idx); |
|
2274 |
} |
|
400 | 2275 |
#else |
2216 | 2276 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, __MKSMALLINT(tmp)); |
400 | 2277 |
#endif |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2278 |
|
2216 | 2279 |
} else { |
2280 |
/* |
|
2281 |
* arg is something else - call it with #value: |
|
2282 |
*/ |
|
2283 |
(*blockVal.ilc_func)(aBlock, @symbol(value:), nil, &blockVal, __MKSMALLINT(tmp)); |
|
2284 |
} |
|
2285 |
} |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2286 |
outerLoop: ; |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2287 |
tmp++; |
214 | 2288 |
} |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2289 |
|
2216 | 2290 |
# undef BLOCK_ARG |
2291 |
# undef IBLOCK_ARG |
|
1 | 2292 |
|
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2293 |
RETURN (self); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2294 |
} |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2295 |
/* |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2296 |
* arg is something else - call it with #value: |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2297 |
*/ |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2298 |
while (tmp <= final) { |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2299 |
if (InterruptPending != nil) __interruptL(@line); |
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2300 |
|
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2301 |
(*blockVal.ilc_func)(aBlock, |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2302 |
@symbol(value:), |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2303 |
nil, &blockVal, |
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2304 |
__MKSMALLINT(tmp)); |
2650
8a31202275ff
oops - last optimization was wrong
Claus Gittinger <cg@exept.de>
parents:
2649
diff
changeset
|
2305 |
tmp++; |
214 | 2306 |
} |
2307 |
RETURN ( self ); |
|
1 | 2308 |
} |
400 | 2309 |
%}. |
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2310 |
|
400 | 2311 |
"/ |
2312 |
"/ arrive here if stop is not a smallInteger |
|
2187
37b82d044439
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
1964
diff
changeset
|
2313 |
"/ pass on to super ... |
400 | 2314 |
"/ |
62 | 2315 |
^ super to:stop do:aBlock |
2316 |
||
216 | 2317 |
" |
2318 |
1 to:10 do:[:i | i printNewline] |
|
2319 |
" |
|
701 | 2320 |
! ! |
1 | 2321 |
|
701 | 2322 |
!SmallInteger methodsFor:'misc math'! |
1 | 2323 |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2324 |
divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2325 |
"return an array filled with self // aNumber and |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2326 |
self \\ aNumber. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2327 |
The result is only defined for positive receiver and |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2328 |
argument." |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2329 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2330 |
%{ /* NOCONTEXT */ |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2331 |
INT val, div, mod, mySelf; |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2332 |
|
3984
45a76e2f4236
Fix so that // and \\ truncate towards negative infinity and
Stefan Vogel <sv@exept.de>
parents:
3914
diff
changeset
|
2333 |
if (__isSmallInteger(aNumber) && |
4167 | 2334 |
(val = __intVal(aNumber)) > 0) { |
2335 |
mySelf = __intVal(self); |
|
2336 |
div = mySelf / val; |
|
2337 |
mod = mySelf % val; |
|
2338 |
||
2339 |
RETURN (__ARRAY_WITH2( __MKSMALLINT(div), |
|
2340 |
__MKSMALLINT(mod))); |
|
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2341 |
} |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2342 |
%}. |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2343 |
^ super divMod:aNumber |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2344 |
|
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2345 |
" |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2346 |
10 // 3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2347 |
10 \\ 3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2348 |
10 divMod:3 |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2349 |
" |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2350 |
! |
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2351 |
|
701 | 2352 |
gcd:anInteger |
2353 |
"return the greatest common divisor (Euclid's algorithm). |
|
2354 |
This has been redefined here for more speed since due to the |
|
2355 |
use of gcd in Fraction code, it has become time-critical for |
|
2356 |
some code. (thanx to MessageTally)" |
|
2357 |
||
2358 |
%{ /* NOCONTEXT */ |
|
1 | 2359 |
|
701 | 2360 |
if (__isSmallInteger(anInteger)) { |
4167 | 2361 |
INT orgArg, ttt, selfInt, orgSelfInt, temp; |
2362 |
||
2363 |
ttt = orgArg = __intVal(anInteger); |
|
2364 |
if (ttt) { |
|
2365 |
selfInt = orgSelfInt = __intVal(self); |
|
2366 |
while (ttt != 0) { |
|
2367 |
temp = selfInt % ttt; |
|
2368 |
selfInt = ttt; |
|
2369 |
ttt = temp; |
|
2370 |
} |
|
2371 |
/* |
|
2372 |
* since its not defined in C, what the sign of |
|
2373 |
* a modulus result is when the arg is negative, |
|
2374 |
* change it explicitely here ... |
|
2375 |
*/ |
|
2376 |
if (orgArg < 0) { |
|
2377 |
/* result should be negative */ |
|
2378 |
if (orgSelfInt > 0) selfInt = -selfInt; |
|
2379 |
} else { |
|
2380 |
/* result should be positive */ |
|
2381 |
if (orgSelfInt < 0) selfInt = -selfInt; |
|
2382 |
} |
|
2383 |
RETURN ( __MKSMALLINT(selfInt) ); |
|
2384 |
} |
|
1 | 2385 |
} |
2386 |
%} |
|
2387 |
. |
|
701 | 2388 |
^ super gcd:anInteger |
2389 |
! |
|
62 | 2390 |
|
2430
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2391 |
gcd_helper:anInteger |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2392 |
"same as gcd - see knuth & Integer>>gcd:" |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2393 |
|
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2394 |
^ self gcd:anInteger |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2395 |
|
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2396 |
"Created: 1.3.1997 / 16:58:01 / cg" |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2397 |
! |
cbbf16de1bd7
better gcd for large numbers.
Claus Gittinger <cg@exept.de>
parents:
2254
diff
changeset
|
2398 |
|
701 | 2399 |
intlog10 |
2400 |
"return the truncation of log10 of the receiver - |
|
2401 |
stupid implementation; used to find out the number of digits needed |
|
2402 |
to print a number/and for conversion to a LargeInteger. |
|
2403 |
Implemented that way, to allow for tiny systems without a Float class |
|
2404 |
(i.e. without log)." |
|
2 | 2405 |
|
701 | 2406 |
self <= 0 ifTrue:[ |
2407 |
self error:'logarithm of negative integer' |
|
2 | 2408 |
]. |
701 | 2409 |
self < 10 ifTrue:[^ 1]. |
2410 |
self < 100 ifTrue:[^ 2]. |
|
2411 |
self < 1000 ifTrue:[^ 3]. |
|
2412 |
self < 10000 ifTrue:[^ 4]. |
|
2413 |
self < 100000 ifTrue:[^ 5]. |
|
2414 |
self < 1000000 ifTrue:[^ 6]. |
|
2415 |
self < 10000000 ifTrue:[^ 7]. |
|
2416 |
self < 100000000 ifTrue:[^ 8]. |
|
2417 |
self < 1000000000 ifTrue:[^ 9]. |
|
2418 |
^ 10 |
|
2 | 2419 |
! ! |
2420 |
||
3135 | 2421 |
!SmallInteger methodsFor:'modulo arithmetic'! |
2 | 2422 |
|
701 | 2423 |
plus:aNumber |
2424 |
"return the sum of the receiver and the argument, as SmallInteger. |
|
2425 |
The argument must be another SmallInteger. |
|
3135 | 2426 |
If the result overflows the smallInteger range, the value modulo the |
701 | 2427 |
smallInteger range is returned (i.e. the low bits of the sum). |
3135 | 2428 |
This is of course not always correct, but some code does a modulo anyway |
701 | 2429 |
and can therefore speed things up by not going through LargeIntegers." |
41 | 2430 |
|
701 | 2431 |
%{ /* NOCONTEXT */ |
2432 |
||
2433 |
if (__isSmallInteger(aNumber)) { |
|
4167 | 2434 |
INT sum; |
2435 |
||
2436 |
sum = __intVal(self) + __intVal(aNumber); |
|
2785 | 2437 |
#ifdef alpha64 |
4167 | 2438 |
sum &= 0x7FFFFFFFFFFFFFFFL; |
2785 | 2439 |
#else |
4167 | 2440 |
sum &= 0x7FFFFFFF; |
2785 | 2441 |
#endif |
4167 | 2442 |
RETURN ( __MKSMALLINT(sum)); |
701 | 2443 |
} |
2785 | 2444 |
%}. |
701 | 2445 |
self primitiveFailed |
2 | 2446 |
! |
2447 |
||
701 | 2448 |
subtract:aNumber |
2449 |
"return the difference of the receiver and the argument, as SmallInteger. |
|
2450 |
The argument must be another SmallInteger. |
|
3135 | 2451 |
If the result overflows the smallInteger range, the value modulo the |
701 | 2452 |
smallInteger range is returned (i.e. the low bits of the sum). |
3135 | 2453 |
This is of course not always correct, but some code does a modulo anyway |
701 | 2454 |
and can therefore speed things up by not going through LargeIntegers." |
2455 |
||
2456 |
%{ /* NOCONTEXT */ |
|
2 | 2457 |
|
701 | 2458 |
if (__isSmallInteger(aNumber)) { |
4167 | 2459 |
INT diff; |
2460 |
||
2461 |
diff = __intVal(self) - __intVal(aNumber); |
|
2785 | 2462 |
#ifdef alpha64 |
4167 | 2463 |
diff &= 0x7FFFFFFFFFFFFFFFL; |
2785 | 2464 |
#else |
4167 | 2465 |
diff &= 0x7FFFFFFF; |
2785 | 2466 |
#endif |
4167 | 2467 |
RETURN ( __MKSMALLINT(diff)); |
701 | 2468 |
} |
2216 | 2469 |
%}. |
701 | 2470 |
self primitiveFailed |
2471 |
! |
|
2472 |
||
2473 |
times:aNumber |
|
2474 |
"return the product of the receiver and the argument, as SmallInteger. |
|
2475 |
The argument must be another SmallInteger. |
|
3135 | 2476 |
If the result overflows the smallInteger range, the value modulo the |
701 | 2477 |
smallInteger range is returned (i.e. the low bits of the product). |
3135 | 2478 |
This is of course not always correct, but some code does a modulo anyway |
701 | 2479 |
and can therefore speed things up by not going through LargeIntegers." |
2480 |
||
2481 |
%{ /* NOCONTEXT */ |
|
2482 |
||
2483 |
if (__isSmallInteger(aNumber)) { |
|
4167 | 2484 |
INT prod; |
2485 |
||
2486 |
prod = __intVal(self) * __intVal(aNumber); |
|
2785 | 2487 |
#ifdef alpha64 |
4167 | 2488 |
prod &= 0x7FFFFFFFFFFFFFFFL; |
2785 | 2489 |
#else |
4167 | 2490 |
prod &= 0x7FFFFFFF; |
2785 | 2491 |
#endif |
4167 | 2492 |
RETURN ( __MKSMALLINT(prod)); |
701 | 2493 |
} |
2216 | 2494 |
%}. |
701 | 2495 |
self primitiveFailed |
1 | 2496 |
! ! |
2497 |
||
2498 |
!SmallInteger methodsFor:'printing & storing'! |
|
2499 |
||
62 | 2500 |
printOn:aStream |
68 | 2501 |
"append my printstring (base 10) to aStream." |
62 | 2502 |
|
2503 |
aStream nextPutAll:(self printString) |
|
2504 |
! |
|
2505 |
||
701 | 2506 |
printOn:aStream base:radix |
2507 |
"append my printstring in any number base to aStream. |
|
2508 |
The radix argument should be between 2 and 36." |
|
2509 |
||
2510 |
aStream nextPutAll:(self printStringRadix:radix) |
|
2511 |
! |
|
2512 |
||
1 | 2513 |
printString |
2514 |
"return my printstring (base 10)" |
|
2515 |
||
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2516 |
"since this was heavily used in some applications, |
68 | 2517 |
here is an exception to the rule of basing printString |
2518 |
upon the printOn: method." |
|
2519 |
||
1 | 2520 |
%{ /* NOCONTEXT */ |
2521 |
||
2522 |
char buffer[30]; |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2523 |
char *cp; |
1 | 2524 |
OBJ newString; |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2525 |
INT myValue; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2526 |
int negative = 0; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2527 |
|
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2528 |
#ifdef SLOW_CODE |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2529 |
/* |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2530 |
* this takes twice as long as the code below ... |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2531 |
* (printf is soooo slow) |
369 | 2532 |
*/ |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2533 |
# ifdef alpha64 |
2781 | 2534 |
sprintf(buffer, "%ld", __intVal(self)); |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2535 |
# else |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2536 |
sprintf(buffer, "%d", __intVal(self)); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2537 |
# endif |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2538 |
newString = __MKSTRING(buffer COMMA_SND); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2539 |
|
2781 | 2540 |
#else |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2541 |
myValue = __intVal(self); |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2542 |
if (myValue == 0) { |
4167 | 2543 |
RETURN (__MKSTRING_L("0", 1)); |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2544 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2545 |
if (myValue < 0) { |
4167 | 2546 |
negative = 1; |
2547 |
myValue = -myValue; |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2548 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2549 |
cp = buffer + sizeof(buffer) - 1; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2550 |
*cp-- = '\0'; |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2551 |
while (myValue != 0) { |
4167 | 2552 |
*cp = '0' + (myValue % 10); |
2553 |
myValue = myValue / 10; |
|
2554 |
cp--; |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2555 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2556 |
if (negative) { |
4167 | 2557 |
*cp-- = '-'; |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2558 |
} |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2559 |
newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); |
2781 | 2560 |
#endif |
282 | 2561 |
if (newString != nil) { |
4167 | 2562 |
RETURN (newString); |
282 | 2563 |
} |
2564 |
%}. |
|
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2565 |
"/ only arrive here, |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2566 |
"/ when having memory problems (i.e. no space for string) ... |
282 | 2567 |
^ super printString |
3704
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2568 |
|
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2569 |
" |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2570 |
1234 printString |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2571 |
0 printString |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2572 |
-100 printString |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2573 |
" |
4dd3cb7ae956
SmallInteger>>printString now twice as fast (for andi and olbi)
Claus Gittinger <cg@exept.de>
parents:
3684
diff
changeset
|
2574 |
|
1 | 2575 |
! |
2576 |
||
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2577 |
printStringRadix:base |
62 | 2578 |
"return my printstring (optimized for bases 16, 10 and 8)" |
1 | 2579 |
|
3705 | 2580 |
|s| |
2581 |
||
2582 |
%{ |
|
2583 |
char buffer[64+3]; /* for alpha, base 2 plus sign */ |
|
2584 |
char *cp; |
|
1 | 2585 |
OBJ newString; |
3705 | 2586 |
INT myValue; |
2587 |
int negative = 0; |
|
3706 | 2588 |
INT __base; |
1 | 2589 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2590 |
if (__isSmallInteger(base)) { |
3707 | 2591 |
__base = __intVal(base); |
3706 | 2592 |
|
3705 | 2593 |
#ifdef SLOW_CODE |
4167 | 2594 |
switch (__base) { |
2595 |
case 10: |
|
2788 | 2596 |
#ifdef alpha64 |
4167 | 2597 |
format = "%ld"; |
2781 | 2598 |
#else |
4167 | 2599 |
format = "%d"; |
2781 | 2600 |
#endif |
4167 | 2601 |
break; |
2602 |
case 16: |
|
2788 | 2603 |
#ifdef alpha64 |
4167 | 2604 |
format = "%lx"; |
2781 | 2605 |
#else |
4167 | 2606 |
format = "%x"; |
3705 | 2607 |
#endif |
4167 | 2608 |
break; |
2609 |
case 8: |
|
3705 | 2610 |
#ifdef alpha64 |
4167 | 2611 |
format = "%lo"; |
3705 | 2612 |
#else |
4167 | 2613 |
format = "%o"; |
2781 | 2614 |
#endif |
4167 | 2615 |
break; |
2616 |
} |
|
2617 |
||
2618 |
if (format) { |
|
2619 |
/* |
|
2620 |
* actually only needed on sparc: since thisContext is |
|
2621 |
* in a global register, which gets destroyed by printf, |
|
2622 |
* manually save it here - very stupid ... |
|
2623 |
*/ |
|
2624 |
__BEGIN_PROTECT_REGISTERS__ |
|
2625 |
||
2626 |
sprintf(buffer, format, __intVal(self)); |
|
2627 |
||
2628 |
__END_PROTECT_REGISTERS__ |
|
2629 |
||
2630 |
newString = __MKSTRING(buffer COMMA_SND); |
|
2631 |
if (newString != nil) { |
|
2632 |
RETURN (newString); |
|
2633 |
} |
|
2634 |
} |
|
3705 | 2635 |
#else |
4167 | 2636 |
if ((__base <= 36) && (__base > 1)) { |
2637 |
myValue = __intVal(self); |
|
2638 |
if (myValue == 0) { |
|
2639 |
RETURN (__MKSTRING_L("0", 1)); |
|
2640 |
} |
|
2641 |
if (myValue < 0) { |
|
2642 |
negative = 1; |
|
2643 |
myValue = -myValue; |
|
2644 |
} |
|
2645 |
cp = buffer + sizeof(buffer) - 1; |
|
2646 |
*cp-- = '\0'; |
|
2647 |
while (myValue != 0) { |
|
2648 |
int digit; |
|
2649 |
||
2650 |
digit = myValue % __base; |
|
2651 |
if (digit <= 9) { |
|
2652 |
*cp = '0' + digit; |
|
2653 |
} else { |
|
2654 |
*cp = 'A' + digit - 10; |
|
2655 |
} |
|
2656 |
myValue = myValue / __base; |
|
2657 |
cp--; |
|
2658 |
} |
|
2659 |
if (negative) { |
|
2660 |
*cp-- = '-'; |
|
2661 |
} |
|
2662 |
newString = __MKSTRING_L(cp+1, (buffer + sizeof(buffer) - 2 - cp)); |
|
2663 |
if (newString != nil) { |
|
2664 |
RETURN (newString); |
|
2665 |
} |
|
2666 |
} |
|
3705 | 2667 |
#endif |
1 | 2668 |
} |
314 | 2669 |
%}. |
3705 | 2670 |
"/ arrive here, for bad base, |
2671 |
"/ or when having memory problems (i.e. no space for string) ... |
|
2672 |
||
2673 |
"/ |
|
2674 |
"/ fall back for seldom used bases |
|
2675 |
"/ Notice: cannt use super>>printStringRadix: here, |
|
2676 |
"/ since that would lead to endless recursion ... |
|
2677 |
"/ (a consequence of reversing printOn / printString functionality) |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2678 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2679 |
s := WriteStream on:(String new:10). |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2680 |
super printOn:s base:base. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2681 |
^ s contents. |
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2682 |
|
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2683 |
" |
3705 | 2684 |
127 printStringRadix:16 |
2685 |
123 printStringRadix:16 |
|
2686 |
123 printStringRadix:10 |
|
2687 |
123 printStringRadix:8 |
|
2688 |
123 printStringRadix:3 |
|
2689 |
123 printStringRadix:2 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2690 |
123 printStringRadix:1 |
3705 | 2691 |
|
2692 |
-127 printStringRadix:16 |
|
2693 |
-123 printStringRadix:16 |
|
2694 |
-123 printStringRadix:10 |
|
2695 |
-123 printStringRadix:8 |
|
2696 |
-123 printStringRadix:3 |
|
2697 |
-123 printStringRadix:2 |
|
3189
f07145cc8ef7
Have to call "super #printOn:base:" in #printString.
Stefan Vogel <sv@exept.de>
parents:
3156
diff
changeset
|
2698 |
" |
1 | 2699 |
! |
2700 |
||
2701 |
printfPrintString:formatString |
|
2702 |
"non-portable, but sometimes useful. |
|
2703 |
return a printed representation of the receiver |
|
62 | 2704 |
as specified by formatString, which is defined by the C- |
2705 |
function 'printf'. |
|
2706 |
No checking for string overrun - the resulting string |
|
2707 |
must be shorter than 256 chars or else ... |
|
2781 | 2708 |
This method is NONSTANDARD and may be removed without notice; |
2709 |
it is provided to allow special conversions in very special |
|
2710 |
situaltions. |
|
2711 |
Notice that a conversion may not be portable; for example, |
|
2712 |
to correctly convert an int on a 64-bit alpha, a %ld is required, |
|
2713 |
while other systems may be happy with a %d ... |
|
2714 |
Use at your own risk (if at all)" |
|
1 | 2715 |
|
13 | 2716 |
%{ /* STACK: 400 */ |
1 | 2717 |
|
2718 |
char buffer[256]; |
|
314 | 2719 |
OBJ s; |
1 | 2720 |
|
62 | 2721 |
if (__isString(formatString)) { |
379 | 2722 |
/* |
2723 |
* actually only needed on sparc: since thisContext is |
|
2724 |
* in a global register, which gets destroyed by printf, |
|
2725 |
* manually save it here - very stupid ... |
|
2726 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2727 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2728 |
|
1133 | 2729 |
sprintf(buffer, __stringVal(formatString), __intVal(self)); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2730 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2731 |
__END_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
2732 |
|
1133 | 2733 |
s = __MKSTRING(buffer COMMA_SND); |
314 | 2734 |
if (s != nil) { |
2735 |
RETURN (s); |
|
2736 |
} |
|
1 | 2737 |
} |
314 | 2738 |
%}. |
1 | 2739 |
self primitiveFailed |
2740 |
||
2741 |
"123 printfPrintString:'%%d -> %d'" |
|
2742 |
"123 printfPrintString:'%%6d -> %6d'" |
|
2743 |
"123 printfPrintString:'%%x -> %x'" |
|
2744 |
"123 printfPrintString:'%%4x -> %4x'" |
|
2745 |
"123 printfPrintString:'%%04x -> %04x'" |
|
2746 |
! ! |
|
701 | 2747 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2748 |
!SmallInteger methodsFor:'private'! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2749 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2750 |
sign:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2751 |
"private: for protocol completeness with LargeIntegers" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2752 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2753 |
|absVal| |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2754 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2755 |
absVal := self abs. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2756 |
aNumber < 0 ifTrue:[ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2757 |
^ absVal negated |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2758 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2759 |
aNumber == 0 ifTrue:[^ 0]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2760 |
^ absVal |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2761 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2762 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2763 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2764 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2765 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2766 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2767 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2768 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2769 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2770 |
! ! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2771 |
|
701 | 2772 |
!SmallInteger methodsFor:'testing'! |
2773 |
||
2774 |
between:min and:max |
|
2775 |
"return true if the receiver is less than or equal to the argument max |
|
2776 |
and greater than or equal to the argument min. |
|
2777 |
- reimplemented here for speed" |
|
2778 |
||
2779 |
%{ /* NOCONTEXT */ |
|
2780 |
||
2781 |
if (__bothSmallInteger(min, max)) { |
|
2782 |
REGISTER INT selfVal; |
|
2783 |
||
1133 | 2784 |
selfVal = __intVal(self); |
2785 |
if (selfVal < __intVal(min)) { |
|
701 | 2786 |
RETURN ( false ); |
2787 |
} |
|
1133 | 2788 |
if (selfVal > __intVal(max)) { |
701 | 2789 |
RETURN ( false ); |
2790 |
} |
|
2791 |
RETURN ( true ); |
|
2792 |
} |
|
2216 | 2793 |
%}. |
701 | 2794 |
(self < min) ifTrue:[^ false]. |
2795 |
(self > max) ifTrue:[^ false]. |
|
2796 |
^ true |
|
2797 |
! |
|
2798 |
||
2799 |
even |
|
2800 |
"return true, if the receiver is even" |
|
2801 |
||
2802 |
%{ /* NOCONTEXT */ |
|
2803 |
||
2216 | 2804 |
RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? false : true ); |
701 | 2805 |
%} |
2806 |
! |
|
2807 |
||
2808 |
negative |
|
2809 |
"return true, if the receiver is less than zero |
|
2810 |
reimplemented here for speed" |
|
2811 |
||
2812 |
%{ /* NOCONTEXT */ |
|
2813 |
||
2216 | 2814 |
#if TAG_INT == 1 |
701 | 2815 |
/* tag bit does not change sign */ |
2816 |
RETURN ( ((INT)(self) < 0) ? true : false ); |
|
2216 | 2817 |
#else |
2818 |
RETURN ( (__intVal(self) < 0) ? true : false ); |
|
701 | 2819 |
#endif |
2820 |
%} |
|
2821 |
! |
|
2822 |
||
2823 |
odd |
|
2824 |
"return true, if the receiver is odd" |
|
2825 |
||
2826 |
%{ /* NOCONTEXT */ |
|
2827 |
||
2216 | 2828 |
RETURN ( ((INT)self & (INT)__MASKSMALLINT(1)) ? true : false ); |
701 | 2829 |
%} |
2830 |
! |
|
2831 |
||
2832 |
positive |
|
2833 |
"return true, if the receiver is not negative |
|
2834 |
reimplemented here for speed" |
|
2835 |
||
2836 |
%{ /* NOCONTEXT */ |
|
2837 |
||
2216 | 2838 |
#if TAG_INT == 1 |
701 | 2839 |
/* tag bit does not change sign */ |
2840 |
RETURN ( ((INT)(self) >= 0) ? true : false ); |
|
2216 | 2841 |
#else |
2842 |
RETURN ( (__intVal(self) >= 0) ? true : false ); |
|
701 | 2843 |
#endif |
2844 |
%} |
|
2845 |
! |
|
2846 |
||
2847 |
sign |
|
2848 |
"return the sign of the receiver |
|
2849 |
reimplemented here for speed" |
|
2850 |
||
2851 |
%{ /* NOCONTEXT */ |
|
2852 |
||
1133 | 2853 |
INT val = __intVal(self); |
701 | 2854 |
|
2855 |
if (val < 0) { |
|
1133 | 2856 |
RETURN ( __MKSMALLINT(-1) ); |
701 | 2857 |
} |
2858 |
if (val > 0) { |
|
1133 | 2859 |
RETURN ( __MKSMALLINT(1) ); |
701 | 2860 |
} |
1133 | 2861 |
RETURN ( __MKSMALLINT(0) ); |
701 | 2862 |
%} |
2863 |
! |
|
2864 |
||
2865 |
strictlyPositive |
|
2866 |
"return true, if the receiver is greater than zero |
|
2867 |
reimplemented here for speed" |
|
2868 |
||
2869 |
%{ /* NOCONTEXT */ |
|
2870 |
||
2216 | 2871 |
#if TAG_INT == 1 |
701 | 2872 |
/* tag bit does not change sign */ |
2873 |
RETURN ( ((INT)(self) > 0) ? true : false ); |
|
2216 | 2874 |
#else |
2875 |
RETURN ( (__intVal(self) > 0) ? true : false ); |
|
701 | 2876 |
#endif |
2877 |
%} |
|
2878 |
! ! |
|
2879 |
||
1842
b28609c73839
added divMod: for faster largeNumber printString generation.
Claus Gittinger <cg@exept.de>
parents:
1716
diff
changeset
|
2880 |
!SmallInteger class methodsFor:'documentation'! |
701 | 2881 |
|
2882 |
version |
|
4661 | 2883 |
^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.119 1999-09-01 20:02:49 cg Exp $' |
701 | 2884 |
! ! |