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