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