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