author | Claus Gittinger <cg@exept.de> |
Wed, 07 Feb 1996 15:11:43 +0100 | |
changeset 939 | ffee570b0f09 |
parent 927 | 8d8edf9df0ae |
child 1036 | d79dc9e4c6f5 |
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 |
|
701 | 14 |
instanceVariableNames:'' |
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Magnitude-Numbers' |
|
1 | 18 |
! |
19 |
||
68 | 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. |
|
68 | 52 |
" |
53 |
! ! |
|
1 | 54 |
|
55 |
!SmallInteger class methodsFor:'instance creation'! |
|
56 |
||
57 |
basicNew |
|
58 |
"catch instance creation |
|
59 |
- SmallIntegers cannot be created with new" |
|
60 |
||
61 |
self error:'instances of SmallInteger cannot be created with new' |
|
62 |
! |
|
63 |
||
64 |
basicNew:size |
|
65 |
"catch instance creation |
|
66 |
- SmallIntegers cannot be created with new" |
|
67 |
||
68 |
self error:'instances of SmallInteger cannot be created with new' |
|
69 |
! ! |
|
70 |
||
701 | 71 |
!SmallInteger class methodsFor:'binary storage'! |
72 |
||
73 |
binaryDefinitionFrom: stream manager: manager |
|
74 |
"read the binary representation as stored in storeBinaryOn:" |
|
75 |
||
76 |
| value | |
|
77 |
||
78 |
value := stream next bitAnd: 16r7F. |
|
79 |
value > 16r3F ifTrue: [ |
|
80 |
value := value - 16r80 |
|
81 |
]. |
|
82 |
value := (value bitShift: 8) bitOr: stream next. |
|
83 |
value := (value bitShift: 8) bitOr: stream next. |
|
84 |
value := (value bitShift: 8) bitOr: stream next. |
|
85 |
^ value |
|
86 |
! ! |
|
87 |
||
88 |
!SmallInteger class methodsFor:'bit mask constants'! |
|
89 |
||
90 |
bitMaskFor:index |
|
91 |
"return a bitmask for the index's bit (index starts at 1)" |
|
92 |
||
93 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
|
94 |
^ self error:'index out of bounds' |
|
95 |
]. |
|
96 |
^ 1 bitShift:(index - 1) |
|
97 |
! ! |
|
98 |
||
1 | 99 |
!SmallInteger class methodsFor:'constants'! |
100 |
||
101 |
maxBits |
|
68 | 102 |
"return the number of bits in instances of me. |
103 |
For very special uses only - not constant across implementations" |
|
1 | 104 |
|
105 |
%{ /* NOCONTEXT */ |
|
106 |
RETURN ( _MKSMALLINT(N_INT_BITS) ); |
|
107 |
%} |
|
2 | 108 |
|
109 |
"SmallInteger maxBits" |
|
1 | 110 |
! |
111 |
||
112 |
maxBytes |
|
68 | 113 |
"return the number of bytes in instances of me. |
114 |
For very special uses only - not constant across implementations" |
|
1 | 115 |
|
116 |
%{ /* NOCONTEXT */ |
|
117 |
RETURN ( _MKSMALLINT(N_INT_BITS / 8 + 1) ); |
|
118 |
%} |
|
2 | 119 |
|
120 |
"SmallInteger maxBytes" |
|
1 | 121 |
! |
122 |
||
123 |
maxVal |
|
68 | 124 |
"return the largest Integer representable as SmallInteger. |
125 |
For very special uses only - not constant across implementations" |
|
1 | 126 |
|
127 |
%{ /* NOCONTEXT */ |
|
128 |
RETURN ( _MKSMALLINT(_MAX_INT) ); |
|
129 |
%} |
|
2 | 130 |
|
131 |
"SmallInteger maxVal" |
|
701 | 132 |
! |
133 |
||
134 |
minVal |
|
135 |
"return the smallest Integer representable as SmallInteger. |
|
136 |
For very special uses only - not constant across implementations" |
|
137 |
||
138 |
%{ /* NOCONTEXT */ |
|
139 |
RETURN ( _MKSMALLINT(_MIN_INT) ); |
|
140 |
%} |
|
141 |
||
142 |
"SmallInteger minVal" |
|
1 | 143 |
! ! |
144 |
||
3 | 145 |
!SmallInteger class methodsFor:'queries'! |
146 |
||
50 | 147 |
canBeSubclassed |
148 |
"return true, if its allowed to create subclasses of the receiver. |
|
68 | 149 |
Return nil here - since it is NOT possible for SmallInteger" |
50 | 150 |
|
151 |
^ false |
|
1 | 152 |
! |
153 |
||
701 | 154 |
isBuiltInClass |
155 |
"this class is known by the run-time-system" |
|
1 | 156 |
|
157 |
^ true |
|
158 |
! ! |
|
159 |
||
160 |
!SmallInteger methodsFor:'arithmetic'! |
|
161 |
||
162 |
* aNumber |
|
163 |
"return the product of the receivers value and the arguments value" |
|
164 |
||
165 |
%{ /* NOCONTEXT */ |
|
166 |
||
68 | 167 |
INT myValue, otherValue; |
168 |
unsigned INT productLow, productHi; |
|
169 |
int negative; |
|
170 |
||
95 | 171 |
# define lowBits(foo) ((foo) & 0xFFFF) |
172 |
# define hiBits(foo) ((foo) >> 16) |
|
173 |
||
174 |
/* |
|
175 |
* can we use long long arithmetic ? |
|
176 |
*/ |
|
177 |
#if defined(__GNUC__) && (__GNUC__ >= 2) |
|
178 |
/* |
|
179 |
* commented, since long-long arithmetic seems to |
|
180 |
* be buggy in some implementations (sparc) ... |
|
181 |
* (took me a while to find this out :-( |
|
182 |
*/ |
|
183 |
# ifdef NOTDEF |
|
184 |
# define _LONGLONG |
|
185 |
# endif |
|
186 |
#endif |
|
1 | 187 |
|
252 | 188 |
if (__isSmallInteger(aNumber)) { |
214 | 189 |
myValue = _intVal(self); |
190 |
otherValue = _intVal(aNumber); |
|
95 | 191 |
#if defined(_LONGLONG) |
214 | 192 |
{ |
193 |
long long product; |
|
13 | 194 |
|
214 | 195 |
product = (long long)myValue * (long long)otherValue; |
196 |
if ((product >= (long long)_MIN_INT) |
|
197 |
&& (product <= (long long)_MAX_INT)) { |
|
198 |
RETURN ( _MKSMALLINT((int)product) ); |
|
199 |
} |
|
200 |
if (product < 0) { |
|
201 |
negative = 1; |
|
202 |
product = -product; |
|
203 |
} else { |
|
204 |
negative = 0; |
|
205 |
} |
|
206 |
productHi = product >> 32; |
|
207 |
productLow = product & 0xFFFFFFFF; |
|
208 |
} |
|
13 | 209 |
#else |
214 | 210 |
negative = 0; |
211 |
if (myValue < 0) { |
|
212 |
negative = 1; |
|
213 |
myValue = -myValue; |
|
214 |
} |
|
215 |
if (otherValue < 0) { |
|
216 |
negative = (1 - negative); |
|
217 |
otherValue = -otherValue; |
|
218 |
} |
|
68 | 219 |
|
220 |
# if defined(__GNUC__) && defined(mc68k) |
|
214 | 221 |
asm ("mulu%.l %3,%1:%0" |
222 |
: "=d" ((unsigned long)(productLow)), |
|
223 |
"=d" ((unsigned long)(productHi)) |
|
224 |
: "%0" ((unsigned long)(myValue)), |
|
225 |
"dmi" ((unsigned long)(otherValue))); |
|
68 | 226 |
# else |
227 |
# if defined (__GNUC__) && defined(i386) |
|
214 | 228 |
asm ("mull %3" |
229 |
: "=a" ((unsigned long)(productLow)), |
|
230 |
"=d" ((unsigned long)(productHi)) |
|
231 |
: "%0" ((unsigned long)(myValue)), |
|
232 |
"rm" ((unsigned long)(otherValue))); |
|
68 | 233 |
# else |
214 | 234 |
{ |
235 |
unsigned INT pHH, pHL, pLH, pLL; |
|
236 |
unsigned INT low1, low2, hi1, hi2; |
|
237 |
unsigned INT t; |
|
68 | 238 |
|
214 | 239 |
/* unsigned multiply myValue * otherValue -> productHi, productLow |
240 |
* |
|
241 |
* this is too slow: |
|
242 |
* since most machines can do 32*32 to 64 bit multiply, |
|
243 |
* (or at least 32*32 with Overflow check) |
|
244 |
* - need more assembler (inline) functions here |
|
245 |
*/ |
|
246 |
low1 = lowBits(myValue); |
|
247 |
hi1 = hiBits(myValue); |
|
248 |
low2 = lowBits(otherValue); |
|
249 |
hi2 = hiBits(otherValue); |
|
68 | 250 |
|
214 | 251 |
pLH = low1 * hi2; |
252 |
pHL = hi1 * low2; |
|
253 |
pLL = low1 * low2; |
|
68 | 254 |
|
214 | 255 |
/* |
256 |
* the common case ... |
|
257 |
*/ |
|
258 |
if ((pHL == 0) |
|
259 |
&& (pLH == 0) |
|
260 |
&& ((pLL & 0xC0000000) == 0)) { |
|
261 |
if (negative) { |
|
262 |
RETURN ( _MKSMALLINT(- ((INT)pLL)) ); |
|
263 |
} |
|
264 |
RETURN ( _MKSMALLINT((INT)pLL) ); |
|
265 |
} |
|
68 | 266 |
|
214 | 267 |
pHH = hi1 * hi2; |
68 | 268 |
|
214 | 269 |
/* |
270 |
* pHH |--------|--------| |
|
271 |
* pLH |--------|--------| |
|
272 |
* pHL |--------|--------| |
|
273 |
* pLL |--------|--------| |
|
274 |
*/ |
|
68 | 275 |
|
214 | 276 |
t = lowBits(pLH) + lowBits(pHL) + hiBits(pLL); |
277 |
productLow = (t << 16) + lowBits(pLL); |
|
278 |
productHi = pHH + hiBits(t) + hiBits(pHL) + hiBits(pLH); |
|
279 |
} |
|
68 | 280 |
# endif |
281 |
# endif |
|
214 | 282 |
if (productHi == 0) { |
283 |
if (negative) { |
|
284 |
if (productLow <= -(_MIN_INT)) { |
|
285 |
RETURN ( _MKSMALLINT(-((INT)productLow)) ); |
|
286 |
} |
|
287 |
} else { |
|
288 |
if (productLow <= _MAX_INT) { |
|
289 |
RETURN ( _MKSMALLINT(productLow) ); |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
95 | 293 |
#endif |
294 |
||
214 | 295 |
{ |
296 |
static struct inlineCache val = _ILC5; |
|
297 |
OBJ aLarge; |
|
68 | 298 |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
299 |
aLarge = (*val.ilc_func)(@global(LargeInteger), |
214 | 300 |
@symbol(sign:value16:value16:value16:value16:), |
301 |
CON_COMMA nil, &val, |
|
302 |
negative ? _MKSMALLINT(-1) : _MKSMALLINT(1), |
|
303 |
_MKSMALLINT(lowBits(productLow)), |
|
304 |
_MKSMALLINT(hiBits(productLow)), |
|
305 |
_MKSMALLINT(lowBits(productHi)), |
|
306 |
_MKSMALLINT(hiBits(productHi)) ); |
|
307 |
RETURN(aLarge); |
|
308 |
} |
|
283 | 309 |
} else if (__isFloatLike(aNumber)) { |
214 | 310 |
OBJ newFloat; |
533
c75af3681d0f
attention qMKFLOAT macro may perform a GC - dont use floatVal
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
311 |
double val = (double)_intVal(self) * _floatVal(aNumber); |
1 | 312 |
|
533
c75af3681d0f
attention qMKFLOAT macro may perform a GC - dont use floatVal
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
313 |
_qMKFLOAT(newFloat, val, SENDER); |
214 | 314 |
RETURN ( newFloat ); |
1 | 315 |
} |
316 |
%} |
|
317 |
. |
|
318 |
^ aNumber productFromInteger:self |
|
319 |
! |
|
320 |
||
701 | 321 |
+ aNumber |
322 |
"return the sum of the receivers value and the arguments value" |
|
323 |
||
324 |
%{ /* NOCONTEXT */ |
|
325 |
||
326 |
if (__isSmallInteger(aNumber)) { |
|
327 |
#ifdef _ADD_IO_IO |
|
328 |
RETURN ( _ADD_IO_IO(self, aNumber) ); |
|
329 |
#else |
|
330 |
REGISTER INT sum; |
|
331 |
||
332 |
sum = _intVal(self) + _intVal(aNumber); |
|
333 |
if ((sum >= _MIN_INT) && (sum <= _MAX_INT)) { |
|
334 |
RETURN ( _MKSMALLINT(sum) ); |
|
335 |
} |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
336 |
RETURN ( __MKLARGEINT(sum) ); |
701 | 337 |
#endif |
338 |
} |
|
339 |
if (__isFloatLike(aNumber)) { |
|
340 |
OBJ newFloat; |
|
341 |
double val = (double)_intVal(self) + _floatVal(aNumber); |
|
342 |
||
343 |
_qMKFLOAT(newFloat, val, SENDER); |
|
344 |
RETURN ( newFloat ); |
|
345 |
} |
|
346 |
%} |
|
347 |
. |
|
348 |
^ aNumber sumFromInteger:self |
|
349 |
! |
|
350 |
||
351 |
- aNumber |
|
352 |
"return the difference of the receivers value and the arguments value" |
|
353 |
||
354 |
%{ /* NOCONTEXT */ |
|
355 |
||
356 |
if (__isSmallInteger(aNumber)) { |
|
357 |
#ifdef _SUB_IO_IO |
|
358 |
RETURN ( _SUB_IO_IO(self, aNumber) ); |
|
359 |
#else |
|
360 |
REGISTER INT diff; |
|
361 |
||
362 |
diff = _intVal(self) - _intVal(aNumber); |
|
363 |
if ((diff >= _MIN_INT) && (diff <= _MAX_INT)) { |
|
364 |
RETURN ( _MKSMALLINT(diff) ); |
|
365 |
} |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
366 |
RETURN ( __MKLARGEINT(diff) ); |
701 | 367 |
#endif |
368 |
} |
|
369 |
if (__isFloatLike(aNumber)) { |
|
370 |
OBJ newFloat; |
|
371 |
double val = (double)_intVal(self) - _floatVal(aNumber); |
|
372 |
||
373 |
_qMKFLOAT(newFloat, val, SENDER); |
|
374 |
RETURN ( newFloat ); |
|
375 |
} |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
376 |
%}. |
701 | 377 |
^ aNumber differenceFromInteger:self |
378 |
! |
|
379 |
||
1 | 380 |
/ aNumber |
381 |
"return the quotient of the receivers value and the arguments value" |
|
382 |
||
383 |
%{ /* NOCONTEXT */ |
|
384 |
||
385 |
INT me, t, val; |
|
386 |
double dval; |
|
387 |
||
252 | 388 |
if (__isSmallInteger(aNumber)) { |
214 | 389 |
val = _intVal(aNumber); |
390 |
if (val != 0) { |
|
391 |
me = _intVal(self); |
|
392 |
t = me / val; |
|
1 | 393 |
#ifdef GOOD_OPTIMIZER |
214 | 394 |
if (me % val) { |
1 | 395 |
#else |
214 | 396 |
/* this is stupid - all I want is to look for a remainder ... |
397 |
but most compilers are too stupid and generate an extra modulu |
|
398 |
instruction for "if (me % val)". |
|
399 |
Even if most divide instructions already leave the remainder in |
|
400 |
some register. |
|
401 |
Therefore I use a multiplication which is faster than a modulu |
|
402 |
on most machines. Hint to GNU people :-) |
|
403 |
*/ |
|
404 |
if ((t * val) == me) { |
|
1 | 405 |
#endif |
214 | 406 |
RETURN ( _MKSMALLINT(t) ); |
407 |
} |
|
408 |
} |
|
1 | 409 |
} else { |
283 | 410 |
if (__isFloatLike(aNumber)) { |
214 | 411 |
dval = _floatVal(aNumber); |
412 |
if (dval != 0.0) { |
|
413 |
OBJ newFloat; |
|
533
c75af3681d0f
attention qMKFLOAT macro may perform a GC - dont use floatVal
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
414 |
double val = (double)_intVal(self) / dval; |
62 | 415 |
|
533
c75af3681d0f
attention qMKFLOAT macro may perform a GC - dont use floatVal
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
416 |
_qMKFLOAT(newFloat, val, SENDER); |
214 | 417 |
RETURN ( newFloat ); |
418 |
} |
|
419 |
} |
|
1 | 420 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
421 |
%}. |
1 | 422 |
aNumber isInteger ifTrue:[ |
324 | 423 |
aNumber == 0 ifTrue:[ |
214 | 424 |
^ DivisionByZeroSignal raise. |
425 |
]. |
|
426 |
^ Fraction numerator:self denominator:aNumber |
|
1 | 427 |
]. |
428 |
^ aNumber quotientFromInteger:self |
|
927
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 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
431 |
8 / 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 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
434 |
9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
435 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
436 |
-8 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
437 |
-9 / 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
438 |
-9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
439 |
-9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
440 |
" |
1 | 441 |
! |
442 |
||
2 | 443 |
// aNumber |
1 | 444 |
"return the integer part of the quotient of the receivers value |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
445 |
and the arguments value. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
446 |
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
|
447 |
while -9 // 4 = -3. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
448 |
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
|
449 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
450 |
%{ /* NOCONTEXT */ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
451 |
INT val, rslt; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
452 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
453 |
if (__isSmallInteger(aNumber)) { |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
454 |
val = _intVal(aNumber); |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
455 |
if (val != 0) { |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
456 |
rslt = _intVal(self) / val; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
457 |
if (rslt < 0) { |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
458 |
if (_intVal(self) % val) |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
459 |
rslt--; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
460 |
} |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
461 |
RETURN ( _MKSMALLINT(rslt) ); |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
462 |
} |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
463 |
} else { |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
464 |
if (__isFraction(aNumber)) { |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
465 |
OBJ t; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
466 |
INT num, den; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
467 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
468 |
t = _FractionInstPtr(aNumber)->f_numerator; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
469 |
if (__isSmallInteger(t)) { |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
470 |
num = _intVal(t); |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
471 |
t = _FractionInstPtr(aNumber)->f_denominator; |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
472 |
if (__isSmallInteger(t)) { |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
473 |
den = _intVal(t); |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
474 |
RETURN ( _MKSMALLINT(_intVal(self) * den / num )); |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
475 |
} |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
476 |
} |
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 |
} |
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 |
(aNumber = 0) ifTrue:[ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
481 |
^ DivisionByZeroSignal raise. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
482 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
483 |
^ self retry:#// coercing:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
484 |
|
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 // 4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
487 |
-9 // 4 => -3 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
488 |
9 // -4 => -3 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
489 |
-9 // -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 |
9 quo:4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
492 |
-9 quo:4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
493 |
9 quo:-4 => -2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
494 |
-9 quo:-4 => 2 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
495 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
496 |
! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
497 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
498 |
quo:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
499 |
"return the integer part of the quotient of the receivers value |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
500 |
and the arguments value. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
501 |
For positive results, this is the same as #//, |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
502 |
for negative results, the remainder is ignored. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
503 |
I.e.: '9 // 4 = 2' and '-9 // 4 = -3' |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
504 |
in contrast: '9 quo: 4 = 2' and '-9 quo: 4 = -2'" |
1 | 505 |
|
506 |
%{ /* NOCONTEXT */ |
|
507 |
INT val; |
|
508 |
||
252 | 509 |
if (__isSmallInteger(aNumber)) { |
214 | 510 |
val = _intVal(aNumber); |
511 |
if (val != 0) { |
|
512 |
RETURN ( _MKSMALLINT(_intVal(self) / val) ); |
|
513 |
} |
|
2 | 514 |
} else { |
214 | 515 |
if (__isFraction(aNumber)) { |
516 |
OBJ t; |
|
517 |
INT num, den; |
|
2 | 518 |
|
214 | 519 |
t = _FractionInstPtr(aNumber)->f_numerator; |
252 | 520 |
if (__isSmallInteger(t)) { |
214 | 521 |
num = _intVal(t); |
522 |
t = _FractionInstPtr(aNumber)->f_denominator; |
|
252 | 523 |
if (__isSmallInteger(t)) { |
214 | 524 |
den = _intVal(t); |
525 |
RETURN ( _MKSMALLINT(_intVal(self) * den / num )); |
|
526 |
} |
|
527 |
} |
|
528 |
} |
|
1 | 529 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
530 |
%}. |
2 | 531 |
(aNumber = 0) ifTrue:[ |
214 | 532 |
^ DivisionByZeroSignal raise. |
1 | 533 |
]. |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
534 |
^ self retry:#quo: coercing:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
535 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
536 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
537 |
9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
538 |
-9 // 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
539 |
9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
540 |
-9 quo:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
541 |
" |
1 | 542 |
! |
543 |
||
2 | 544 |
\\ aNumber |
1 | 545 |
"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
|
546 |
divided by the arguments value. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
547 |
This is not always the same as the result as obtained from #rem:" |
1 | 548 |
|
549 |
%{ /* NOCONTEXT */ |
|
550 |
INT mySelf, val; |
|
551 |
||
252 | 552 |
if (__isSmallInteger(aNumber)) { |
214 | 553 |
mySelf = _intVal(self); |
554 |
if (mySelf < 0) mySelf = -mySelf; |
|
555 |
val = _intVal(aNumber); |
|
556 |
if (val != 0) { |
|
557 |
if (val < 0) { |
|
558 |
RETURN ( _MKSMALLINT(-(mySelf % -val)) ); |
|
559 |
} |
|
560 |
RETURN ( _MKSMALLINT(mySelf % val) ); |
|
561 |
} |
|
1 | 562 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
563 |
%}. |
2 | 564 |
(aNumber = 0) ifTrue:[ |
214 | 565 |
^ DivisionByZeroSignal raise. |
1 | 566 |
]. |
2 | 567 |
^ self retry:#\\ coercing:aNumber |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
568 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
569 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
570 |
9 \\ 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
571 |
-9 \\ 4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
572 |
9 rem:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
573 |
-9 rem:4 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
574 |
" |
1 | 575 |
! |
576 |
||
577 |
abs |
|
578 |
"return the absolute value of the receiver |
|
579 |
reimplemented here for speed" |
|
580 |
||
581 |
%{ /* NOCONTEXT */ |
|
582 |
||
583 |
INT val = _intVal(self); |
|
584 |
||
62 | 585 |
if (val >= 0) { |
214 | 586 |
RETURN (self); |
62 | 587 |
} |
1 | 588 |
if (val != _MIN_INT) { |
214 | 589 |
RETURN ( _MKSMALLINT(-val) ); |
1 | 590 |
} |
324 | 591 |
%}. |
1 | 592 |
"only reached for minVal" |
593 |
^ self negated |
|
594 |
! |
|
595 |
||
596 |
negated |
|
597 |
"return the negative value of the receiver |
|
598 |
reimplemented here for speed" |
|
599 |
||
600 |
%{ /* NOCONTEXT */ |
|
601 |
||
602 |
INT val = _intVal(self); |
|
603 |
||
604 |
if (val != _MIN_INT) { |
|
214 | 605 |
RETURN ( _MKSMALLINT(- val) ); |
1 | 606 |
} |
324 | 607 |
%}. |
608 |
"only reached for minVal" |
|
1 | 609 |
^ (LargeInteger value:(SmallInteger maxVal)) + 1 |
610 |
! ! |
|
611 |
||
701 | 612 |
!SmallInteger methodsFor:'binary storage'! |
1 | 613 |
|
701 | 614 |
hasSpecialBinaryRepresentation |
615 |
"return true, if the receiver has a special binary representation" |
|
1 | 616 |
|
701 | 617 |
^ true |
1 | 618 |
! |
619 |
||
701 | 620 |
storeBinaryOn: stream manager: manager |
621 |
"append a binary representation onto stream. |
|
622 |
Redefined since SmallIntegers are stored as their value with the 32nd bit |
|
623 |
set as a tag. |
|
624 |
To make the binary file a bit more compact, zeros and single byte ints |
|
625 |
are stored with a more compact representation (using special type-codes)." |
|
62 | 626 |
|
701 | 627 |
self == 0 ifTrue:[ |
628 |
stream nextPut: manager codeForZero. |
|
629 |
^ self |
|
1 | 630 |
]. |
701 | 631 |
(self between:0 and:255) ifTrue:[ |
632 |
stream nextPut: manager codeForByteInteger. |
|
633 |
stream nextPut: self. |
|
634 |
^ self |
|
635 |
]. |
|
636 |
stream nextPut: (((self bitShift: -24) bitAnd: 16rFF) bitOr: 16r80). |
|
637 |
stream nextPut: ((self bitShift: -16) bitAnd: 16rFF). |
|
638 |
stream nextPut: ((self bitShift: -8) bitAnd: 16rFF). |
|
639 |
stream nextPut: (self bitAnd: 16rFF) |
|
1 | 640 |
! ! |
641 |
||
642 |
!SmallInteger methodsFor:'bit operators'! |
|
643 |
||
644 |
allMask:anInteger |
|
62 | 645 |
"return true if all 1-bits in anInteger are also 1 in the receiver" |
646 |
||
647 |
^ (self bitAnd:anInteger) == anInteger |
|
1 | 648 |
|
62 | 649 |
"2r00001111 allMask:2r00000001" |
650 |
"2r00001111 allMask:2r00011110" |
|
651 |
"2r00001111 allMask:2r00000000" |
|
1 | 652 |
! |
653 |
||
654 |
anyMask:anInteger |
|
62 | 655 |
"return true if any 1-bits in anInteger is also 1 in the receiver. |
656 |
(somewhat incorrect, if the mask is zero)" |
|
1 | 657 |
|
62 | 658 |
^ (self bitAnd:anInteger) ~~ 0 |
659 |
||
660 |
"2r00001111 anyMask:2r00000001" |
|
661 |
"2r00001111 anyMask:2r11110000" |
|
1 | 662 |
! |
663 |
||
701 | 664 |
bitAnd:anInteger |
665 |
"return the bitwise-and of the receiver and the argument, anInteger" |
|
1 | 666 |
|
667 |
%{ /* NOCONTEXT */ |
|
668 |
||
701 | 669 |
/* anding the tags doesn't change it */ |
670 |
if (__isSmallInteger(anInteger)) { |
|
671 |
RETURN ( ((OBJ) ((INT)self & (INT)anInteger)) ); |
|
1 | 672 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
673 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
674 |
^ self retry:#bitAnd: coercing:anInteger |
701 | 675 |
|
676 |
"(2r001010100 bitAnd:2r00001111) radixPrintStringRadix:2" |
|
1 | 677 |
! |
678 |
||
701 | 679 |
bitAt:index |
680 |
"return the value of the index's bit (index starts at 1). |
|
681 |
Notice: the result of bitAt: on negative receivers is not |
|
682 |
defined in the language standard (since the implementation |
|
683 |
is free to choose any internal representation for integers)" |
|
684 |
||
685 |
|mask| |
|
686 |
||
687 |
(index between:1 and:SmallInteger maxBits) ifFalse:[ |
|
688 |
^ self error:'index out of bounds' |
|
689 |
]. |
|
690 |
mask := 1 bitShift:(index - 1). |
|
691 |
((self bitAnd:mask) == 0) ifTrue:[^ 0]. |
|
692 |
^ 1 |
|
693 |
! |
|
694 |
||
695 |
bitInvert |
|
696 |
"return the value of the receiver with all bits inverted" |
|
62 | 697 |
|
1 | 698 |
%{ /* NOCONTEXT */ |
699 |
||
701 | 700 |
/* invert anything except tag bits */ |
701 |
RETURN ( ((OBJ) ((INT)self ^ ~TAG_MASK)) ); |
|
702 |
%} |
|
703 |
! |
|
1 | 704 |
|
701 | 705 |
bitOr:anInteger |
706 |
"return the bitwise-or of the receiver and the argument, anInteger" |
|
707 |
||
708 |
%{ /* NOCONTEXT */ |
|
709 |
||
710 |
/* oring the tags doesn't change it */ |
|
711 |
if (__isSmallInteger(anInteger)) { |
|
712 |
RETURN ( ((OBJ) ((INT)self | (INT)anInteger)) ); |
|
1 | 713 |
} |
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
714 |
%}. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
715 |
^ self retry:#bitOr: coercing:anInteger |
701 | 716 |
|
717 |
"(2r000000100 bitOr:2r00000011) radixPrintStringRadix:2" |
|
1 | 718 |
! |
719 |
||
720 |
bitShift:shiftCount |
|
721 |
"return the value of the receiver shifted by shiftCount bits; |
|
62 | 722 |
leftShift if shiftCount > 0; rightShift otherwise. |
95 | 723 |
Notice: the result of bitShift: on negative receivers is not |
214 | 724 |
defined in the language standard (since the implementation |
725 |
is free to choose any internal representation for integers)" |
|
1 | 726 |
|
727 |
%{ /* NOCONTEXT */ |
|
728 |
||
729 |
INT bits, count; |
|
730 |
||
252 | 731 |
if (__isSmallInteger(shiftCount)) { |
214 | 732 |
count = _intVal(shiftCount); |
733 |
bits = _intVal(self); |
|
734 |
if (count > 0) { |
|
95 | 735 |
#if defined(_LONGLONG) |
214 | 736 |
unsigned long long result; |
95 | 737 |
|
214 | 738 |
result = bits; |
739 |
if (count <= N_INT_BITS) { |
|
740 |
result <<= count; |
|
741 |
if (result <= _MAX_INT) { |
|
742 |
RETURN ( _MKSMALLINT(result) ); |
|
743 |
} |
|
744 |
{ |
|
745 |
static struct inlineCache val = _ILC5; |
|
746 |
OBJ aLarge; |
|
95 | 747 |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
817
diff
changeset
|
748 |
aLarge = (*val.ilc_func)(@global(LargeInteger), |
214 | 749 |
@symbol(sign:value16:value16:value16:value16:), |
750 |
CON_COMMA nil, &val, |
|
751 |
_MKSMALLINT(1), |
|
752 |
_MKSMALLINT(lowBits(result)), |
|
753 |
_MKSMALLINT(hiBits(result)), |
|
754 |
_MKSMALLINT(lowBits(result >> 32)), |
|
755 |
_MKSMALLINT(hiBits(result >> 32)) ); |
|
756 |
RETURN(aLarge); |
|
757 |
} |
|
758 |
} |
|
95 | 759 |
#else |
214 | 760 |
/* |
761 |
* check for overflow |
|
762 |
*/ |
|
763 |
if (count < (N_INT_BITS-1)) { |
|
764 |
if (! (bits >> (N_INT_BITS - 1 - count))) { |
|
765 |
RETURN ( _MKSMALLINT(bits << count) ); |
|
766 |
} |
|
767 |
/* |
|
768 |
* so, there is an overflow ... |
|
769 |
* handle it as largeInteger |
|
770 |
*/ |
|
771 |
/* FALL THROUGH */ |
|
772 |
} |
|
95 | 773 |
#endif |
214 | 774 |
} else { |
775 |
/* |
|
776 |
* right shifts cannot overflow |
|
777 |
*/ |
|
778 |
if (count < 0) { |
|
779 |
/* |
|
780 |
* some machines ignore shifts bigger than |
|
781 |
* the number of bits in an int ... |
|
782 |
*/ |
|
783 |
if (count < (-N_INT_BITS-1)) |
|
784 |
RETURN (_MKSMALLINT(0)); |
|
785 |
RETURN ( _MKSMALLINT(bits >> -count) ); |
|
786 |
} |
|
787 |
RETURN (self ); |
|
788 |
} |
|
1 | 789 |
} |
85 | 790 |
%}. |
791 |
(shiftCount isMemberOf:SmallInteger) ifTrue:[ |
|
214 | 792 |
^ (LargeInteger value:self) bitShift:shiftCount |
85 | 793 |
]. |
1 | 794 |
^ self bitShift:(shiftCount coerce:1) |
795 |
! |
|
796 |
||
701 | 797 |
bitTest:aMask |
798 |
"return true, if any bit from aMask is set in the receiver" |
|
1 | 799 |
|
800 |
%{ /* NOCONTEXT */ |
|
801 |
||
701 | 802 |
/* and all bits except tag */ |
803 |
if (__isSmallInteger(aMask)) { |
|
804 |
RETURN ( ((INT)self & ((INT)aMask & ~TAG_MASK)) ? true : false ); |
|
1 | 805 |
} |
806 |
%} |
|
807 |
. |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
808 |
^ self retry:#bitTest: coercing:aMask |
1 | 809 |
! |
810 |
||
811 |
bitXor:anInteger |
|
13 | 812 |
"return the bitwise-exclusive-or of the receiver and the argument, anInteger" |
1 | 813 |
|
814 |
%{ /* NOCONTEXT */ |
|
815 |
||
816 |
/* xoring the tags turns it off - or it in again */ |
|
252 | 817 |
if (__isSmallInteger(anInteger)) { |
214 | 818 |
RETURN ( (OBJ)( ((INT)self ^ (INT)anInteger) | TAG_INT) ); |
1 | 819 |
} |
820 |
%} |
|
821 |
. |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
822 |
^ self retry:#bitXor: coercing:anInteger |
1 | 823 |
! |
824 |
||
701 | 825 |
highBit |
826 |
"return the bitIndex of the highest bit set. The returned bitIndex |
|
827 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
1 | 828 |
|
829 |
%{ /* NOCONTEXT */ |
|
830 |
||
701 | 831 |
INT mask, index, bits; |
832 |
||
833 |
bits = _intVal(self); |
|
834 |
if (bits == 0) { |
|
835 |
RETURN ( _MKSMALLINT(-1) ); |
|
836 |
} |
|
837 |
#ifdef alpha |
|
838 |
mask = 0x2000000000000000; |
|
839 |
index = 62; |
|
840 |
#else |
|
841 |
mask = 0x20000000; |
|
842 |
index = 30; |
|
843 |
#endif |
|
844 |
while (index) { |
|
845 |
if (bits & mask) break; |
|
846 |
mask = mask >> 1; |
|
847 |
index--; |
|
1 | 848 |
} |
701 | 849 |
RETURN ( _MKSMALLINT(index) ); |
1 | 850 |
%} |
701 | 851 |
"2r000100 highBit" |
852 |
"2r010100 highBit" |
|
853 |
"2r000001 highBit" |
|
854 |
"0 highBit" |
|
855 |
"SmallInteger maxVal highBit" |
|
856 |
! |
|
857 |
||
858 |
lowBit |
|
859 |
"return the bitIndex of the lowest bit set. The returned bitIndex |
|
860 |
starts at 1 for the least significant bit. Returns -1 if no bit is set." |
|
861 |
||
862 |
%{ /* NOCONTEXT */ |
|
863 |
||
864 |
INT mask, index, bits; |
|
865 |
||
866 |
bits = _intVal(self); |
|
867 |
if (bits == 0) { |
|
868 |
RETURN ( _MKSMALLINT(-1) ); |
|
869 |
} |
|
870 |
mask = 1; |
|
871 |
index = 1; |
|
872 |
#ifdef alpha |
|
873 |
while (index != 63) { |
|
874 |
#else |
|
875 |
while (index != 31) { |
|
876 |
#endif |
|
877 |
if (bits & mask) { |
|
878 |
RETURN ( _MKSMALLINT(index) ); |
|
879 |
} |
|
880 |
mask = mask << 1; |
|
881 |
index++; |
|
882 |
} |
|
883 |
RETURN ( _MKSMALLINT(-1) ); |
|
884 |
%} |
|
885 |
"2r000100 lowBit" |
|
886 |
"2r010010 lowBit" |
|
887 |
"2r100001 lowBit" |
|
888 |
"0 lowBit" |
|
889 |
! |
|
890 |
||
891 |
noMask:anInteger |
|
892 |
"return true if no 1-bit in anInteger is 1 in the receiver" |
|
893 |
||
894 |
^ (self bitAnd:anInteger) == 0 |
|
895 |
||
896 |
"2r00001111 noMask:2r00000001" |
|
897 |
"2r00001111 noMask:2r11110000" |
|
1 | 898 |
! ! |
899 |
||
900 |
!SmallInteger methodsFor:'byte access'! |
|
901 |
||
902 |
digitAt:index |
|
903 |
"return 8 bits of value, starting at byte index" |
|
904 |
||
905 |
%{ /* NOCONTEXT */ |
|
906 |
||
357 | 907 |
REGISTER INT val; |
908 |
INT idx; |
|
1 | 909 |
|
252 | 910 |
if (__isSmallInteger(index)) { |
214 | 911 |
val = _intVal(self); |
912 |
if (val < 0) |
|
913 |
val = -val; |
|
357 | 914 |
switch (idx = _intVal(index)) { |
214 | 915 |
case 1: |
357 | 916 |
break; |
214 | 917 |
case 2: |
357 | 918 |
val = (val >> 8); |
919 |
break; |
|
214 | 920 |
case 3: |
357 | 921 |
val = (val >> 16); |
922 |
break; |
|
214 | 923 |
case 4: |
357 | 924 |
val = (val >> 24); |
925 |
break; |
|
1 | 926 |
#ifdef alpha |
214 | 927 |
case 5: |
357 | 928 |
val = (val >> 32); |
929 |
break; |
|
214 | 930 |
case 6: |
357 | 931 |
val = (val >> 40); |
932 |
break; |
|
214 | 933 |
case 7: |
357 | 934 |
val = (val >> 48); |
935 |
break; |
|
214 | 936 |
case 8: |
357 | 937 |
val = (val >> 56); |
938 |
break; |
|
1 | 939 |
#endif |
357 | 940 |
default: |
941 |
if (idx < 1) |
|
942 |
goto bad; /* sorry */ |
|
943 |
val = 0; |
|
944 |
break; |
|
214 | 945 |
} |
357 | 946 |
RETURN ( _MKSMALLINT( val & 0xFF) ); |
1 | 947 |
} |
357 | 948 |
bad: ; |
77 | 949 |
%}. |
950 |
index > 0 ifFalse:[ |
|
357 | 951 |
" |
952 |
index less than 1 - not allowed |
|
953 |
" |
|
954 |
^ self primitiveFailed |
|
77 | 955 |
]. |
956 |
^ 0 |
|
62 | 957 |
|
357 | 958 |
" |
959 |
(16r12345678 digitAt:1) printStringRadix:16 |
|
960 |
(16r12345678 digitAt:3) printStringRadix:16 |
|
961 |
(16r12345678 digitAt:15) printStringRadix:16 |
|
962 |
(16r12345678 digitAt:0) printStringRadix:16 |
|
963 |
(16r12345678 digitAt:-10) printStringRadix:16 |
|
964 |
" |
|
701 | 965 |
! |
966 |
||
967 |
digitLength |
|
968 |
"return the number bytes used by this Integer" |
|
969 |
||
970 |
^ self abs highBit - 1 // 8 + 1 |
|
1 | 971 |
! ! |
972 |
||
701 | 973 |
!SmallInteger methodsFor:'catching messages'! |
1 | 974 |
|
701 | 975 |
basicAt:index |
976 |
"catch indexed access - report an error |
|
977 |
defined here since basicAt: in Object ommits the SmallInteger check." |
|
978 |
||
979 |
self notIndexed |
|
1 | 980 |
! |
981 |
||
701 | 982 |
basicAt:index put:anObject |
983 |
"catch indexed access - report an error |
|
984 |
defined here since basicAt:put: in Object ommits the SmallInteger check." |
|
985 |
||
986 |
self notIndexed |
|
987 |
! |
|
1 | 988 |
|
701 | 989 |
basicSize |
990 |
"return the number of indexed instvars - SmallIntegers have none. |
|
991 |
Defined here since basicSize in Object ommits the SmallInteger check." |
|
992 |
||
993 |
^ 0 |
|
994 |
! |
|
995 |
||
996 |
size |
|
997 |
"return the number of indexed instvars - SmallIntegers have none." |
|
998 |
||
999 |
^ 0 |
|
1 | 1000 |
! ! |
1001 |
||
1002 |
!SmallInteger methodsFor:'coercing and converting'! |
|
1003 |
||
701 | 1004 |
asCharacter |
1005 |
"Return a character with the receiver as ascii value" |
|
41 | 1006 |
|
701 | 1007 |
^ Character value:self |
1 | 1008 |
! |
1009 |
||
1010 |
asFloat |
|
1011 |
"return a Float with same value as receiver" |
|
1012 |
||
1013 |
%{ /* NOCONTEXT */ |
|
1014 |
||
1015 |
OBJ newFloat; |
|
587 | 1016 |
double dVal = (double)_intVal(self); |
1 | 1017 |
|
587 | 1018 |
_qMKFLOAT(newFloat, dVal, SENDER); |
1 | 1019 |
RETURN ( newFloat ); |
1020 |
%} |
|
1021 |
! |
|
1022 |
||
1023 |
asLargeInteger |
|
1024 |
"return a LargeInteger with same value as receiver" |
|
1025 |
||
1026 |
^ LargeInteger value:self |
|
1027 |
! |
|
1028 |
||
701 | 1029 |
coerce:aNumber |
1030 |
"return aNumber converted into receivers type" |
|
1031 |
||
1032 |
^ aNumber asInteger |
|
1033 |
! |
|
1034 |
||
1035 |
generality |
|
1036 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
1037 |
||
1038 |
^ 20 |
|
1039 |
! ! |
|
1040 |
||
1041 |
!SmallInteger methodsFor:'comparing'! |
|
1042 |
||
1043 |
< aNumber |
|
1044 |
"return true, if the argument is greater than the receiver" |
|
1045 |
||
1046 |
%{ /* NOCONTEXT */ |
|
1047 |
||
1048 |
if (__isSmallInteger(aNumber)) { |
|
1049 |
#ifdef POSITIVE_ADDRESSES |
|
1050 |
RETURN ( (_intVal(self) < _intVal(aNumber)) ? true : false ); |
|
1051 |
#else |
|
1052 |
/* tag bit does not change ordering */ |
|
1053 |
RETURN ( ((INT)self < (INT)aNumber) ? true : false ); |
|
1054 |
#endif |
|
1055 |
} |
|
1056 |
if (__isFloatLike(aNumber)) { |
|
1057 |
RETURN ( ((double)_intVal(self) < _floatVal(aNumber)) ? true : false ); |
|
1058 |
} |
|
1059 |
%} |
|
1060 |
. |
|
1061 |
^ aNumber lessFromInteger:self |
|
1062 |
"^ self retry:#< coercing:aNumber" |
|
1063 |
! |
|
1064 |
||
1065 |
<= aNumber |
|
1066 |
"return true, if the argument is greater or equal" |
|
1067 |
||
1068 |
%{ /* NOCONTEXT */ |
|
1069 |
||
1070 |
if (__isSmallInteger(aNumber)) { |
|
1071 |
#ifdef POSITIVE_ADDRESSES |
|
1072 |
RETURN ( (_intVal(self) <= _intVal(aNumber)) ? true : false ); |
|
1073 |
#else |
|
1074 |
/* tag bit does not change ordering */ |
|
1075 |
RETURN ( ((INT)self <= (INT)aNumber) ? true : false ); |
|
1076 |
#endif |
|
1077 |
} |
|
1078 |
if (__isFloatLike(aNumber)) { |
|
1079 |
RETURN ( ((double)_intVal(self) <= _floatVal(aNumber)) ? true : false ); |
|
1080 |
} |
|
1081 |
%} |
|
1082 |
. |
|
1083 |
^ self retry:#<= coercing:aNumber |
|
1084 |
! |
|
1085 |
||
1086 |
= aNumber |
|
1087 |
"return true, if the arguments value is equal to mine" |
|
1088 |
||
1089 |
%{ /* NOCONTEXT */ |
|
1090 |
||
1091 |
if (aNumber == self) { |
|
1092 |
RETURN ( true ); |
|
1093 |
} |
|
1094 |
if (! __isNonNilObject(aNumber)) { |
|
1095 |
/* a smallint or nil */ |
|
1096 |
RETURN ( false ); |
|
1097 |
} |
|
1098 |
||
1099 |
if (__isFloatLike(aNumber)) { |
|
1100 |
RETURN ( ((double)_intVal(self) == _floatVal(aNumber)) ? true : false ); |
|
1101 |
} |
|
1102 |
%} |
|
1103 |
. |
|
1104 |
aNumber respondsToArithmetic ifFalse:[^ false]. |
|
1105 |
^ self retry:#= coercing:aNumber |
|
1106 |
! |
|
1107 |
||
1108 |
> aNumber |
|
1109 |
"return true, if the argument is less than the receiver" |
|
1110 |
||
1111 |
%{ /* NOCONTEXT */ |
|
1112 |
||
1113 |
if (__isSmallInteger(aNumber)) { |
|
1114 |
#ifdef POSITIVE_ADDRESSES |
|
1115 |
RETURN ( (_intVal(self) > _intVal(aNumber)) ? true : false ); |
|
1116 |
#else |
|
1117 |
/* tag bit does not change ordering */ |
|
1118 |
RETURN ( ((INT)self > (INT)aNumber) ? true : false ); |
|
1119 |
#endif |
|
1120 |
} |
|
1121 |
if (__isFloatLike(aNumber)) { |
|
1122 |
RETURN ( ((double)_intVal(self) > _floatVal(aNumber)) ? true : false ); |
|
1123 |
} |
|
1124 |
%} |
|
1125 |
. |
|
1126 |
^ self retry:#> coercing:aNumber |
|
1127 |
! |
|
1128 |
||
1129 |
>= aNumber |
|
1130 |
"return true, if the argument is less or equal" |
|
1131 |
||
1132 |
%{ /* NOCONTEXT */ |
|
1133 |
||
1134 |
if (__isSmallInteger(aNumber)) { |
|
1135 |
#ifdef POSITIVE_ADDRESSES |
|
1136 |
RETURN ( (_intVal(self) >= _intVal(aNumber)) ? true : false ); |
|
1137 |
#else |
|
1138 |
/* tag bit does not change ordering */ |
|
1139 |
RETURN ( ((INT)self >= (INT)aNumber) ? true : false ); |
|
1140 |
#endif |
|
1141 |
} |
|
1142 |
if (__isFloatLike(aNumber)) { |
|
1143 |
RETURN ( ((double)_intVal(self) >= _floatVal(aNumber)) ? true : false ); |
|
1144 |
} |
|
1145 |
%} |
|
1146 |
. |
|
1147 |
^ self retry:#>= coercing:aNumber |
|
1148 |
! |
|
1 | 1149 |
|
701 | 1150 |
hash |
1151 |
"return an integer useful for hashing on value" |
|
1152 |
||
1153 |
self >= 0 ifTrue:[^ self]. |
|
1154 |
^ self negated |
|
1155 |
! |
|
1156 |
||
1157 |
identityHash |
|
1158 |
"return an integer useful for hashing on identity" |
|
1159 |
||
1160 |
self >= 0 ifTrue:[^ self]. |
|
1161 |
^ self negated |
|
1162 |
! |
|
1163 |
||
1164 |
max:aNumber |
|
1165 |
"return the receiver or the argument, whichever is greater" |
|
1166 |
||
1167 |
%{ /* NOCONTEXT */ |
|
1168 |
||
1169 |
if (__isSmallInteger(aNumber)) { |
|
1170 |
#ifdef POSITIVE_ADDRESSES |
|
1171 |
if (_intVal(self) > _intVal(aNumber)) { |
|
1172 |
#else |
|
1173 |
/* tag bit does not change ordering */ |
|
1174 |
if ((INT)(self) > (INT)(aNumber)) { |
|
1175 |
#endif |
|
1176 |
RETURN ( self ); |
|
1177 |
} |
|
1178 |
RETURN ( aNumber ); |
|
1179 |
} |
|
1180 |
if (__isFloatLike(aNumber)) { |
|
1181 |
if ( (double)_intVal(self) > _floatVal(aNumber) ) { |
|
1182 |
RETURN ( self ); |
|
1183 |
} |
|
1184 |
RETURN ( aNumber ); |
|
1185 |
} |
|
1186 |
%} |
|
1187 |
. |
|
1188 |
(self > aNumber) ifTrue:[^ self]. |
|
1189 |
^ aNumber |
|
1190 |
! |
|
1191 |
||
1192 |
min:aNumber |
|
1193 |
"return the receiver or the argument, whichever is smaller" |
|
1194 |
||
1195 |
%{ /* NOCONTEXT */ |
|
1196 |
||
1197 |
if (__isSmallInteger(aNumber)) { |
|
1198 |
#ifdef POSITIVE_ADDRESSES |
|
1199 |
if (_intVal(self) < _intVal(aNumber)) { |
|
1200 |
#else |
|
1201 |
/* tag bit does not change ordering */ |
|
1202 |
if ((INT)(self) < (INT)(aNumber)) { |
|
1203 |
#endif |
|
1204 |
RETURN ( self ); |
|
1205 |
} |
|
1206 |
RETURN ( aNumber ); |
|
1207 |
} |
|
1208 |
if (__isFloatLike(aNumber)) { |
|
1209 |
if ( (double)_intVal(self) < _floatVal(aNumber) ) { |
|
1210 |
RETURN ( self ); |
|
1211 |
} |
|
1212 |
RETURN ( aNumber ); |
|
1213 |
} |
|
1214 |
%} |
|
1215 |
. |
|
1216 |
(self < aNumber) ifTrue:[^ self]. |
|
1217 |
^ aNumber |
|
1218 |
! |
|
1219 |
||
1220 |
~= aNumber |
|
1221 |
"return true, if the arguments value is not equal to mine" |
|
1222 |
||
1223 |
%{ /* NOCONTEXT */ |
|
1224 |
||
1225 |
if (aNumber == self) { |
|
1226 |
RETURN ( false ); |
|
1227 |
} |
|
1228 |
if (! __isNonNilObject(aNumber)) { |
|
1229 |
/* a smallint or nil */ |
|
1230 |
RETURN ( true ); |
|
1231 |
} |
|
1232 |
||
1233 |
if (__isFloatLike(aNumber)) { |
|
1234 |
RETURN ( ((double)_intVal(self) == _floatVal(aNumber)) ? false : true ); |
|
1235 |
} |
|
1236 |
%} |
|
1237 |
. |
|
1238 |
aNumber respondsToArithmetic ifFalse:[^ true]. |
|
1239 |
^ self retry:#~= coercing:aNumber |
|
1240 |
! ! |
|
1241 |
||
1242 |
!SmallInteger methodsFor:'copying'! |
|
1243 |
||
1244 |
deepCopy |
|
1245 |
"return a deep copy of myself |
|
1246 |
- reimplemented here since smallintegers are unique" |
|
1247 |
||
1248 |
^ self |
|
1249 |
! |
|
1250 |
||
1251 |
deepCopyUsing:aDictionary |
|
1252 |
"return a deep copy of myself |
|
1253 |
- reimplemented here since smallintegers are unique" |
|
1254 |
||
1255 |
^ self |
|
1256 |
! |
|
1257 |
||
1258 |
shallowCopy |
|
1259 |
"return a shallow copy of myself |
|
1260 |
- reimplemented here since smallintegers are unique" |
|
1261 |
||
1262 |
^ self |
|
1263 |
! |
|
1264 |
||
1265 |
simpleDeepCopy |
|
1266 |
"return a deep copy of myself |
|
1267 |
- reimplemented here since smallintegers are unique" |
|
1268 |
||
1269 |
^ self |
|
1 | 1270 |
! ! |
1271 |
||
214 | 1272 |
!SmallInteger methodsFor:'iteration'! |
1 | 1273 |
|
1274 |
timesRepeat:aBlock |
|
357 | 1275 |
"evaluate the argument, aBlock self times. |
1276 |
Reimplemented as primitive for speed" |
|
1 | 1277 |
|
357 | 1278 |
|home| |
1279 |
%{ |
|
1280 |
REGISTER INT tmp; |
|
1281 |
REGISTER OBJFUNC code; |
|
1282 |
static struct inlineCache blockVal = __ILC0(0); |
|
1283 |
REGISTER OBJ rHome; |
|
1 | 1284 |
|
357 | 1285 |
tmp = __intVal(self); |
1286 |
if (tmp > 0) { |
|
1287 |
if (__isBlockLike(aBlock) |
|
1288 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(0))) { |
|
394 | 1289 |
if ((code = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
357 | 1290 |
#ifdef NEW_BLOCK_CALL |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1291 |
do { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1292 |
if (InterruptPending != nil) __interrupt__(CONARG); |
394 | 1293 |
(*code)(aBlock COMMA_CON); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1294 |
} while(--tmp); |
394 | 1295 |
RETURN (self); |
357 | 1296 |
#else /* old BLOCK_CALL */ |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1297 |
/* |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1298 |
* arg is a compiled block - |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1299 |
* directly call it without going through "Block-value" |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1300 |
*/ |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1301 |
rHome = _BlockInstPtr(aBlock)->b_home; |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1302 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
394 | 1303 |
/* |
1304 |
* home will not move - keep in in a register |
|
1305 |
*/ |
|
1306 |
# if defined(UNROLL_LOOPS) |
|
1307 |
while (tmp > 4) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1308 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1309 |
(*code)(rHome COMMA_CON); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1310 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1311 |
(*code)(rHome COMMA_CON); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1312 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1313 |
(*code)(rHome COMMA_CON); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1314 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1315 |
(*code)(rHome COMMA_CON); |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1316 |
tmp -= 4; |
394 | 1317 |
} |
1318 |
# endif |
|
1319 |
do { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1320 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1321 |
(*code)(rHome COMMA_CON); |
394 | 1322 |
} while(--tmp); |
1323 |
RETURN (self); |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1324 |
} |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1325 |
home = rHome; |
357 | 1326 |
do { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1327 |
if (InterruptPending != nil) __interrupt__(CONARG); |
357 | 1328 |
(*code)(home COMMA_CON); |
1329 |
} while(--tmp); |
|
394 | 1330 |
RETURN (self); |
357 | 1331 |
#endif /* NEW_BLOCK_CALL */ |
394 | 1332 |
} |
1333 |
if (_BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
1334 |
/* |
|
1335 |
* an interpreted block |
|
1336 |
*/ |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1337 |
home = _BlockInstPtr(aBlock)->b_home; |
400 | 1338 |
#if defined(mips) || defined(rs6000) |
1339 |
# define INDIRECT_CALL_IS_FASTER |
|
1340 |
#endif |
|
1341 |
||
1342 |
#ifdef PASS_ARG_POINTER |
|
1343 |
# ifdef INDIRECT_CALL_IS_FASTER |
|
1344 |
code = __interpret; |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1345 |
# define INTERPRET (*code) |
400 | 1346 |
# else |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1347 |
# define INTERPRET __interpret |
400 | 1348 |
# endif |
1349 |
#else |
|
1350 |
# ifdef INDIRECT_CALL_IS_FASTER |
|
1351 |
code = interpret; |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1352 |
# define INTERPRET (*code) |
400 | 1353 |
# else |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1354 |
# define INTERPRET interpret |
400 | 1355 |
# endif |
1356 |
#endif |
|
1357 |
#ifdef NEW_BLOCK_CALL |
|
1358 |
# define HOME nil |
|
1359 |
#else |
|
1360 |
# define HOME home |
|
1361 |
#endif |
|
1362 |
#if defined(UNROLL_LOOPS) |
|
1363 |
while (tmp > 4) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1364 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1365 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1366 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1367 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1368 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1369 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1370 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1371 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil); |
400 | 1372 |
tmp -= 4; |
1373 |
} |
|
1374 |
#endif |
|
394 | 1375 |
do { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1376 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1377 |
INTERPRET(aBlock, 0, nil, HOME COMMA_SND, nil); |
394 | 1378 |
} while(--tmp); |
1379 |
RETURN (self); |
|
1380 |
} |
|
357 | 1381 |
} |
394 | 1382 |
/* |
1383 |
* arg is something else - call it with value" |
|
1384 |
*/ |
|
1385 |
do { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1386 |
if (InterruptPending != nil) __interrupt__(CONARG); |
394 | 1387 |
|
1388 |
(*blockVal.ilc_func)(aBlock, @symbol(value), CON_COMMA nil, &blockVal); |
|
1389 |
} while(--tmp); |
|
357 | 1390 |
} |
400 | 1391 |
#undef INTERPRET |
1392 |
#undef HOME |
|
357 | 1393 |
%} |
1394 |
||
1395 |
"/ |count "{ Class: SmallInteger }" | |
|
1396 |
"/ |
|
1397 |
"/ count := self. |
|
1398 |
"/ [count > 0] whileTrue:[ |
|
1399 |
"/ aBlock value. |
|
1400 |
"/ count := count - 1 |
|
1401 |
"/ ] |
|
1 | 1402 |
! |
1403 |
||
701 | 1404 |
to:stop by:incr do:aBlock |
1405 |
"reimplemented as primitive for speed" |
|
1406 |
||
1407 |
|home| |
|
1408 |
%{ |
|
1409 |
REGISTER INT tmp, step; |
|
1410 |
REGISTER INT final; |
|
1411 |
REGISTER OBJFUNC code; |
|
1412 |
static struct inlineCache blockVal = __ILC1(0); |
|
1413 |
REGISTER OBJ rHome; |
|
1414 |
||
1415 |
if (__bothSmallInteger(incr, stop)) { |
|
1416 |
tmp = _intVal(self); |
|
1417 |
final = _intVal(stop); |
|
1418 |
step = _intVal(incr); |
|
1419 |
if (__isBlockLike(aBlock) |
|
1420 |
&& ((code = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
|
1421 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) { |
|
1422 |
#ifdef NEW_BLOCK_CALL |
|
1423 |
if (step < 0) { |
|
1424 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1425 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1426 |
(*code)(aBlock, CON_COMMA _MKSMALLINT(tmp)); |
1427 |
tmp += step; |
|
1428 |
} |
|
1429 |
} else { |
|
1430 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1431 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1432 |
(*code)(aBlock, CON_COMMA _MKSMALLINT(tmp)); |
1433 |
tmp += step; |
|
1434 |
} |
|
1435 |
} |
|
1436 |
#else |
|
1437 |
/* |
|
1438 |
* arg is a compiled block - |
|
1439 |
* directly call it without going through "Block-value" |
|
1440 |
*/ |
|
1441 |
home = _BlockInstPtr(aBlock)->b_home; |
|
1442 |
rHome = home; |
|
1443 |
if (step < 0) { |
|
1444 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
|
1445 |
/* |
|
1446 |
* home is on stack - will not move |
|
1447 |
*/ |
|
1448 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1449 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1450 |
(*code)(rHome, CON_COMMA _MKSMALLINT(tmp)); |
1451 |
tmp += step; |
|
1452 |
} |
|
1453 |
} else { |
|
1454 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1455 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1456 |
(*code)(home, CON_COMMA _MKSMALLINT(tmp)); |
1457 |
tmp += step; |
|
1458 |
} |
|
1459 |
} |
|
1460 |
} else { |
|
1461 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
|
1462 |
/* |
|
1463 |
* home is on stack - will not move |
|
1464 |
*/ |
|
1465 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1466 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1467 |
(*code)(rHome, CON_COMMA _MKSMALLINT(tmp)); |
1468 |
tmp += step; |
|
1469 |
} |
|
1470 |
} else { |
|
1471 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1472 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1473 |
(*code)(home, CON_COMMA _MKSMALLINT(tmp)); |
1474 |
tmp += step; |
|
1475 |
} |
|
1476 |
} |
|
1477 |
} |
|
1478 |
#endif |
|
1479 |
} else { |
|
1480 |
/* |
|
1481 |
* arg is something else - call it with value" |
|
1482 |
*/ |
|
1483 |
if (step < 0) { |
|
1484 |
while (tmp >= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1485 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1486 |
|
1487 |
(*blockVal.ilc_func)(aBlock, |
|
1488 |
@symbol(value:), |
|
1489 |
CON_COMMA nil, &blockVal, |
|
1490 |
_MKSMALLINT(tmp)); |
|
1491 |
tmp += step; |
|
1492 |
} |
|
1493 |
} else { |
|
1494 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1495 |
if (InterruptPending != nil) __interrupt__(CONARG); |
701 | 1496 |
|
1497 |
(*blockVal.ilc_func)(aBlock, |
|
1498 |
@symbol(value:), |
|
1499 |
CON_COMMA nil, &blockVal, |
|
1500 |
_MKSMALLINT(tmp)); |
|
1501 |
tmp += step; |
|
1502 |
} |
|
1503 |
} |
|
1504 |
} |
|
1505 |
RETURN ( self ); |
|
1506 |
} |
|
1507 |
%} |
|
1508 |
. |
|
1509 |
^ super to:stop by:incr do:aBlock |
|
1510 |
||
1511 |
" |
|
1512 |
1 to:10 by:3 do:[:i | i printNewline] |
|
1513 |
" |
|
1514 |
! |
|
1515 |
||
1 | 1516 |
to:stop do:aBlock |
62 | 1517 |
"evaluate aBlock for every integer between (and including) the receiver |
1518 |
and the argument, stop. |
|
357 | 1519 |
Reimplemented as primitive for speed" |
1 | 1520 |
|
77 | 1521 |
|home| |
1 | 1522 |
%{ |
1523 |
REGISTER INT tmp; |
|
1524 |
INT final; |
|
1525 |
REGISTER OBJFUNC code; |
|
216 | 1526 |
static struct inlineCache blockVal = __ILC1(0); |
2 | 1527 |
REGISTER OBJ rHome; |
1 | 1528 |
|
252 | 1529 |
if (__isSmallInteger(stop)) { |
214 | 1530 |
tmp = _intVal(self); |
1531 |
final = _intVal(stop); |
|
1532 |
if (__isBlockLike(aBlock) |
|
1533 |
&& (_BlockInstPtr(aBlock)->b_nargs == _MKSMALLINT(1))) { |
|
400 | 1534 |
if ((code = _BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
13 | 1535 |
#ifdef NEW_BLOCK_CALL |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1536 |
while (tmp <= final) { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1537 |
if (InterruptPending != nil) __interrupt__(CONARG); |
400 | 1538 |
(*code)(aBlock, CON_COMMA _MKSMALLINT(tmp)); |
1539 |
tmp++; |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1540 |
} |
77 | 1541 |
#else /* old BLOCK_CALL */ |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1542 |
/* |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1543 |
* arg is a compiled block - |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1544 |
* directly call it without going through "Block-value" |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1545 |
*/ |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1546 |
rHome = _BlockInstPtr(aBlock)->b_home; |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1547 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) { |
400 | 1548 |
/* |
1549 |
* home will not move - keep in in a register |
|
1550 |
* since this is also the most common case, |
|
1551 |
* its worth trading a bit memory for speed here ... |
|
1552 |
*/ |
|
394 | 1553 |
# if defined(UNROLL_LOOPS) |
400 | 1554 |
{ |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1555 |
int t4; |
370 | 1556 |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1557 |
while ((t4 = tmp+4) < final) { |
400 | 1558 |
OBJ idx = _MKSMALLINT(tmp); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1559 |
if (InterruptPending != nil) __interrupt__(CONARG); |
400 | 1560 |
(*code)(rHome, CON_COMMA idx); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1561 |
if (InterruptPending != nil) __interrupt__(CONARG); |
400 | 1562 |
(*code)(rHome, CON_COMMA _ADD_INT(idx, 1)); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1563 |
if (InterruptPending != nil) __interrupt__(CONARG); |
400 | 1564 |
(*code)(rHome, CON_COMMA _ADD_INT(idx,2)); |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1565 |
if (InterruptPending != nil) __interrupt__(CONARG); |
400 | 1566 |
(*code)(rHome, CON_COMMA _ADD_INT(idx,3)); |
1567 |
tmp = t4; |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1568 |
} |
400 | 1569 |
} |
1570 |
# endif |
|
1571 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1572 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1573 |
(*code)(rHome, CON_COMMA _MKSMALLINT(tmp)); |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1574 |
tmp++; |
400 | 1575 |
} |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1576 |
} else { |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1577 |
home = rHome; |
400 | 1578 |
while (tmp <= final) { |
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1579 |
if (InterruptPending != nil) __interrupt__(CONARG); |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1580 |
(*code)(home, CON_COMMA _MKSMALLINT(tmp)); |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1581 |
tmp++; |
370 | 1582 |
} |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1583 |
} |
400 | 1584 |
RETURN (self); |
1585 |
#endif /* NEW_BLOCK_CALL */ |
|
1586 |
} |
|
1587 |
if (_BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
1588 |
/* |
|
1589 |
* an interpreted block |
|
1590 |
*/ |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1591 |
home = _BlockInstPtr(aBlock)->b_home; |
400 | 1592 |
#ifdef PASS_ARG_POINTER |
1593 |
# ifdef INDIRECT_CALL_IS_FASTER |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1594 |
code = __interpret; |
400 | 1595 |
# define INTERPRET (*code) |
1596 |
# else |
|
1597 |
# define INTERPRET __interpret |
|
394 | 1598 |
# endif |
400 | 1599 |
#else |
1600 |
# ifdef INDIRECT_CALL_IS_FASTER |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1601 |
code = interpret; |
400 | 1602 |
# define INTERPRET (*code) |
1603 |
# else |
|
1604 |
# define INTERPRET interpret |
|
1605 |
# endif |
|
1606 |
#endif |
|
1607 |
#ifdef NEW_BLOCK_CALL |
|
1608 |
# define HOME nil |
|
1609 |
#else |
|
1610 |
# define HOME home |
|
1611 |
#endif |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1612 |
while (tmp <= final) { |
400 | 1613 |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1614 |
if (InterruptPending != nil) __interrupt__(CONARG); |
400 | 1615 |
#ifdef PASS_ARG_POINTER |
1616 |
{ |
|
1617 |
OBJ idx; |
|
1618 |
idx = __MKSMALLINT(tmp); |
|
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1619 |
INTERPRET(aBlock, 1, nil, HOME COMMA_SND, nil, &idx); |
400 | 1620 |
} |
1621 |
#else |
|
1622 |
INTERPRET(aBlock, 1, nil, HOME COMMA_SND, nil, __MKSMALLINT(tmp)); |
|
1623 |
#endif |
|
214 | 1624 |
tmp++; |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1625 |
} |
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
400
diff
changeset
|
1626 |
RETURN (self); |
214 | 1627 |
} |
400 | 1628 |
} |
1629 |
/* |
|
1630 |
* arg is something else - call it with value" |
|
1631 |
*/ |
|
1632 |
while (tmp <= final) { |
|
817
9ae0381e25e8
renamed interrupt -> __interrupt__ and __interrupt to __iinterrupt__
Claus Gittinger <cg@exept.de>
parents:
809
diff
changeset
|
1633 |
if (InterruptPending != nil) __interrupt__(CONARG); |
1 | 1634 |
|
400 | 1635 |
(*blockVal.ilc_func)(aBlock, |
214 | 1636 |
@symbol(value:), |
1637 |
CON_COMMA nil, &blockVal, |
|
1638 |
_MKSMALLINT(tmp)); |
|
400 | 1639 |
tmp++; |
214 | 1640 |
} |
1641 |
RETURN ( self ); |
|
1 | 1642 |
} |
400 | 1643 |
%}. |
1644 |
"/ |
|
1645 |
"/ arrive here if stop is not a smallInteger |
|
1646 |
"/ |
|
1647 |
||
62 | 1648 |
^ super to:stop do:aBlock |
1649 |
||
216 | 1650 |
" |
1651 |
1 to:10 do:[:i | i printNewline] |
|
1652 |
" |
|
701 | 1653 |
! ! |
1 | 1654 |
|
701 | 1655 |
!SmallInteger methodsFor:'misc math'! |
1 | 1656 |
|
701 | 1657 |
gcd:anInteger |
1658 |
"return the greatest common divisor (Euclid's algorithm). |
|
1659 |
This has been redefined here for more speed since due to the |
|
1660 |
use of gcd in Fraction code, it has become time-critical for |
|
1661 |
some code. (thanx to MessageTally)" |
|
1662 |
||
1663 |
%{ /* NOCONTEXT */ |
|
1 | 1664 |
|
701 | 1665 |
if (__isSmallInteger(anInteger)) { |
1666 |
INT orgArg, ttt, selfInt, temp; |
|
1667 |
||
1668 |
ttt = orgArg = _intVal(anInteger); |
|
1669 |
if (ttt) { |
|
1670 |
selfInt = _intVal(self); |
|
1671 |
while (ttt != 0) { |
|
1672 |
temp = selfInt % ttt; |
|
1673 |
selfInt = ttt; |
|
1674 |
ttt = temp; |
|
214 | 1675 |
} |
1676 |
/* |
|
701 | 1677 |
* since its not defined in what the sign of |
1678 |
* a modulu result is when the arg is negative, |
|
1679 |
* change it explicitely here ... |
|
214 | 1680 |
*/ |
701 | 1681 |
if (orgArg < 0) { |
1682 |
/* result should be negative */ |
|
1683 |
if (selfInt > 0) selfInt = -selfInt; |
|
214 | 1684 |
} else { |
701 | 1685 |
/* result should be positive */ |
1686 |
if (selfInt < 0) selfInt = -selfInt; |
|
214 | 1687 |
} |
701 | 1688 |
RETURN ( _MKSMALLINT(selfInt) ); |
214 | 1689 |
} |
1 | 1690 |
} |
1691 |
%} |
|
1692 |
. |
|
701 | 1693 |
^ super gcd:anInteger |
1694 |
! |
|
62 | 1695 |
|
701 | 1696 |
intlog10 |
1697 |
"return the truncation of log10 of the receiver - |
|
1698 |
stupid implementation; used to find out the number of digits needed |
|
1699 |
to print a number/and for conversion to a LargeInteger. |
|
1700 |
Implemented that way, to allow for tiny systems without a Float class |
|
1701 |
(i.e. without log)." |
|
2 | 1702 |
|
701 | 1703 |
self <= 0 ifTrue:[ |
1704 |
self error:'logarithm of negative integer' |
|
2 | 1705 |
]. |
701 | 1706 |
self < 10 ifTrue:[^ 1]. |
1707 |
self < 100 ifTrue:[^ 2]. |
|
1708 |
self < 1000 ifTrue:[^ 3]. |
|
1709 |
self < 10000 ifTrue:[^ 4]. |
|
1710 |
self < 100000 ifTrue:[^ 5]. |
|
1711 |
self < 1000000 ifTrue:[^ 6]. |
|
1712 |
self < 10000000 ifTrue:[^ 7]. |
|
1713 |
self < 100000000 ifTrue:[^ 8]. |
|
1714 |
self < 1000000000 ifTrue:[^ 9]. |
|
1715 |
^ 10 |
|
2 | 1716 |
! ! |
1717 |
||
701 | 1718 |
!SmallInteger methodsFor:'modulu arithmetic'! |
2 | 1719 |
|
701 | 1720 |
plus:aNumber |
1721 |
"return the sum of the receiver and the argument, as SmallInteger. |
|
1722 |
The argument must be another SmallInteger. |
|
1723 |
If the result overflows the smallInteger range, the value modulu the |
|
1724 |
smallInteger range is returned (i.e. the low bits of the sum). |
|
1725 |
This is of course not always correct, but some code does a modulu anyway |
|
1726 |
and can therefore speed things up by not going through LargeIntegers." |
|
41 | 1727 |
|
701 | 1728 |
%{ /* NOCONTEXT */ |
1729 |
||
1730 |
if (__isSmallInteger(aNumber)) { |
|
1731 |
RETURN ( _MKSMALLINT((_intVal(self) + _intVal(aNumber)) & 0x7FFFFFFF) ); |
|
1732 |
} |
|
1733 |
%} |
|
1734 |
. |
|
1735 |
self primitiveFailed |
|
2 | 1736 |
! |
1737 |
||
701 | 1738 |
subtract:aNumber |
1739 |
"return the difference of the receiver and the argument, as SmallInteger. |
|
1740 |
The argument must be another SmallInteger. |
|
1741 |
If the result overflows the smallInteger range, the value modulu the |
|
1742 |
smallInteger range is returned (i.e. the low bits of the sum). |
|
1743 |
This is of course not always correct, but some code does a modulu anyway |
|
1744 |
and can therefore speed things up by not going through LargeIntegers." |
|
1745 |
||
1746 |
%{ /* NOCONTEXT */ |
|
2 | 1747 |
|
701 | 1748 |
if (__isSmallInteger(aNumber)) { |
1749 |
RETURN ( _MKSMALLINT((_intVal(self) - _intVal(aNumber)) & 0x7FFFFFFF) ); |
|
1750 |
} |
|
1751 |
%} |
|
1752 |
. |
|
1753 |
self primitiveFailed |
|
1754 |
! |
|
1755 |
||
1756 |
times:aNumber |
|
1757 |
"return the product of the receiver and the argument, as SmallInteger. |
|
1758 |
The argument must be another SmallInteger. |
|
1759 |
If the result overflows the smallInteger range, the value modulu the |
|
1760 |
smallInteger range is returned (i.e. the low bits of the product). |
|
1761 |
This is of course not always correct, but some code does a modulu anyway |
|
1762 |
and can therefore speed things up by not going through LargeIntegers." |
|
1763 |
||
1764 |
%{ /* NOCONTEXT */ |
|
1765 |
||
1766 |
if (__isSmallInteger(aNumber)) { |
|
1767 |
RETURN ( _MKSMALLINT((_intVal(self) * _intVal(aNumber)) & 0x7FFFFFFF) ); |
|
1768 |
} |
|
1769 |
%} |
|
1770 |
. |
|
1771 |
self primitiveFailed |
|
1 | 1772 |
! ! |
1773 |
||
1774 |
!SmallInteger methodsFor:'printing & storing'! |
|
1775 |
||
62 | 1776 |
printOn:aStream |
68 | 1777 |
"append my printstring (base 10) to aStream." |
62 | 1778 |
|
1779 |
aStream nextPutAll:(self printString) |
|
1780 |
! |
|
1781 |
||
701 | 1782 |
printOn:aStream base:radix |
1783 |
"append my printstring in any number base to aStream. |
|
1784 |
The radix argument should be between 2 and 36." |
|
1785 |
||
1786 |
aStream nextPutAll:(self printStringRadix:radix) |
|
1787 |
! |
|
1788 |
||
1 | 1789 |
printString |
1790 |
"return my printstring (base 10)" |
|
1791 |
||
68 | 1792 |
"since printf knows pretty good how to do this, |
1793 |
here is an exception to the rule of basing printString |
|
1794 |
upon the printOn: method." |
|
1795 |
||
1 | 1796 |
%{ /* NOCONTEXT */ |
1797 |
||
1798 |
char buffer[30]; |
|
1799 |
OBJ newString; |
|
369 | 1800 |
/* |
1801 |
* actually only needed on sparc: since thisContext is |
|
1802 |
* in a global register, which gets destroyed by printf, |
|
1803 |
* manually save it here - very stupid ... |
|
1804 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1805 |
__BEGIN_PROTECT_REGISTERS__ |
1 | 1806 |
|
1807 |
sprintf(buffer, "%d", _intVal(self)); |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1808 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1809 |
__END_PROTECT_REGISTERS__ |
369 | 1810 |
|
314 | 1811 |
newString = _MKSTRING(buffer COMMA_SND); |
282 | 1812 |
if (newString != nil) { |
305 | 1813 |
RETURN (newString); |
282 | 1814 |
} |
1815 |
%}. |
|
1816 |
^ super printString |
|
1 | 1817 |
! |
1818 |
||
1819 |
printStringRadix:radix |
|
62 | 1820 |
"return my printstring (optimized for bases 16, 10 and 8)" |
1 | 1821 |
|
1822 |
%{ /* NOCONTEXT */ |
|
1823 |
||
1824 |
char *format = (char *)0; |
|
1825 |
char buffer[30]; |
|
1826 |
OBJ newString; |
|
1827 |
||
252 | 1828 |
if (__isSmallInteger(radix)) { |
214 | 1829 |
switch (_intVal(radix)) { |
1830 |
case 10: |
|
1831 |
format = "%d"; |
|
1832 |
break; |
|
1833 |
case 16: |
|
1834 |
format = "%x"; |
|
1835 |
break; |
|
1836 |
case 8: |
|
1837 |
format = "%o"; |
|
1838 |
break; |
|
1839 |
} |
|
1 | 1840 |
} |
1841 |
||
1842 |
if (format) { |
|
379 | 1843 |
/* |
1844 |
* actually only needed on sparc: since thisContext is |
|
1845 |
* in a global register, which gets destroyed by printf, |
|
1846 |
* manually save it here - very stupid ... |
|
1847 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1848 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1849 |
|
214 | 1850 |
sprintf(buffer, format, _intVal(self)); |
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1851 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1852 |
__END_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1853 |
|
324 | 1854 |
newString = _MKSTRING(buffer COMMA_SND); |
1855 |
if (newString != nil) { |
|
282 | 1856 |
RETURN (newString); |
324 | 1857 |
} |
1 | 1858 |
} |
314 | 1859 |
%}. |
1860 |
" |
|
1861 |
fall back for seldom used bases |
|
1862 |
" |
|
1 | 1863 |
^ super printStringRadix:radix |
62 | 1864 |
|
1865 |
"123 printStringRadix:16" |
|
1866 |
"123 printStringRadix:8" |
|
1867 |
"123 printStringRadix:2" |
|
1868 |
"123 printStringRadix:3" |
|
1869 |
"123 printStringRadix:1" |
|
1 | 1870 |
! |
1871 |
||
1872 |
printfPrintString:formatString |
|
1873 |
"non-portable, but sometimes useful. |
|
1874 |
return a printed representation of the receiver |
|
62 | 1875 |
as specified by formatString, which is defined by the C- |
1876 |
function 'printf'. |
|
1877 |
No checking for string overrun - the resulting string |
|
1878 |
must be shorter than 256 chars or else ... |
|
1879 |
This method is NONSTANDARD and may be removed without notice." |
|
1 | 1880 |
|
13 | 1881 |
%{ /* STACK: 400 */ |
1 | 1882 |
|
1883 |
char buffer[256]; |
|
314 | 1884 |
OBJ s; |
1 | 1885 |
|
62 | 1886 |
if (__isString(formatString)) { |
379 | 1887 |
/* |
1888 |
* actually only needed on sparc: since thisContext is |
|
1889 |
* in a global register, which gets destroyed by printf, |
|
1890 |
* manually save it here - very stupid ... |
|
1891 |
*/ |
|
809
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1892 |
__BEGIN_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1893 |
|
214 | 1894 |
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
|
1895 |
|
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1896 |
__END_PROTECT_REGISTERS__ |
5eef87c2907b
e convenient macro for register saving (sparc only)
Claus Gittinger <cg@exept.de>
parents:
701
diff
changeset
|
1897 |
|
314 | 1898 |
s = _MKSTRING(buffer COMMA_SND); |
1899 |
if (s != nil) { |
|
1900 |
RETURN (s); |
|
1901 |
} |
|
1 | 1902 |
} |
314 | 1903 |
%}. |
1 | 1904 |
self primitiveFailed |
1905 |
||
1906 |
"123 printfPrintString:'%%d -> %d'" |
|
1907 |
"123 printfPrintString:'%%6d -> %6d'" |
|
1908 |
"123 printfPrintString:'%%x -> %x'" |
|
1909 |
"123 printfPrintString:'%%4x -> %4x'" |
|
1910 |
"123 printfPrintString:'%%04x -> %04x'" |
|
1911 |
! ! |
|
701 | 1912 |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1913 |
!SmallInteger methodsFor:'private'! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1914 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1915 |
sign:aNumber |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1916 |
"private: for protocol completeness with LargeIntegers" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1917 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1918 |
|absVal| |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1919 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1920 |
absVal := self abs. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1921 |
aNumber < 0 ifTrue:[ |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1922 |
^ absVal negated |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1923 |
]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1924 |
aNumber == 0 ifTrue:[^ 0]. |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1925 |
^ absVal |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1926 |
|
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1927 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1928 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1929 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1930 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1931 |
-4 sign:-1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1932 |
-4 sign:0 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1933 |
-4 sign:1 |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1934 |
" |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1935 |
! ! |
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
1936 |
|
701 | 1937 |
!SmallInteger methodsFor:'testing'! |
1938 |
||
1939 |
between:min and:max |
|
1940 |
"return true if the receiver is less than or equal to the argument max |
|
1941 |
and greater than or equal to the argument min. |
|
1942 |
- reimplemented here for speed" |
|
1943 |
||
1944 |
%{ /* NOCONTEXT */ |
|
1945 |
||
1946 |
if (__bothSmallInteger(min, max)) { |
|
1947 |
REGISTER INT selfVal; |
|
1948 |
||
1949 |
selfVal = _intVal(self); |
|
1950 |
if (selfVal < _intVal(min)) { |
|
1951 |
RETURN ( false ); |
|
1952 |
} |
|
1953 |
if (selfVal > _intVal(max)) { |
|
1954 |
RETURN ( false ); |
|
1955 |
} |
|
1956 |
RETURN ( true ); |
|
1957 |
} |
|
1958 |
%} |
|
1959 |
. |
|
1960 |
(self < min) ifTrue:[^ false]. |
|
1961 |
(self > max) ifTrue:[^ false]. |
|
1962 |
^ true |
|
1963 |
! |
|
1964 |
||
1965 |
even |
|
1966 |
"return true, if the receiver is even" |
|
1967 |
||
1968 |
%{ /* NOCONTEXT */ |
|
1969 |
||
1970 |
#ifdef POSITIVE_ADDRESSES |
|
1971 |
RETURN ( ((INT)self & 1) ? false : true ); |
|
1972 |
#else |
|
1973 |
RETURN ( ((INT)self & ((INT)_MKSMALLINT(1) & ~TAG_INT)) ? false : true ); |
|
1974 |
#endif |
|
1975 |
%} |
|
1976 |
! |
|
1977 |
||
1978 |
negative |
|
1979 |
"return true, if the receiver is less than zero |
|
1980 |
reimplemented here for speed" |
|
1981 |
||
1982 |
%{ /* NOCONTEXT */ |
|
1983 |
||
1984 |
#ifdef POSITIVE_ADDRESSES |
|
1985 |
RETURN ( (_intVal(self) < 0) ? true : false ); |
|
1986 |
#else |
|
1987 |
/* tag bit does not change sign */ |
|
1988 |
RETURN ( ((INT)(self) < 0) ? true : false ); |
|
1989 |
#endif |
|
1990 |
%} |
|
1991 |
! |
|
1992 |
||
1993 |
odd |
|
1994 |
"return true, if the receiver is odd" |
|
1995 |
||
1996 |
%{ /* NOCONTEXT */ |
|
1997 |
||
1998 |
#ifdef POSITIVE_ADDRESSES |
|
1999 |
RETURN ( ((INT)self & 1) ? true : false ); |
|
2000 |
#else |
|
2001 |
RETURN ( ((INT)self & ((INT)_MKSMALLINT(1) & ~TAG_INT)) ? true : false ); |
|
2002 |
#endif |
|
2003 |
%} |
|
2004 |
! |
|
2005 |
||
2006 |
positive |
|
2007 |
"return true, if the receiver is not negative |
|
2008 |
reimplemented here for speed" |
|
2009 |
||
2010 |
%{ /* NOCONTEXT */ |
|
2011 |
||
2012 |
#ifdef POSITIVE_ADDRESSES |
|
2013 |
RETURN ( (_intVal(self) >= 0) ? true : false ); |
|
2014 |
#else |
|
2015 |
/* tag bit does not change sign */ |
|
2016 |
RETURN ( ((INT)(self) >= 0) ? true : false ); |
|
2017 |
#endif |
|
2018 |
%} |
|
2019 |
! |
|
2020 |
||
2021 |
sign |
|
2022 |
"return the sign of the receiver |
|
2023 |
reimplemented here for speed" |
|
2024 |
||
2025 |
%{ /* NOCONTEXT */ |
|
2026 |
||
2027 |
INT val = _intVal(self); |
|
2028 |
||
2029 |
if (val < 0) { |
|
2030 |
RETURN ( _MKSMALLINT(-1) ); |
|
2031 |
} |
|
2032 |
if (val > 0) { |
|
2033 |
RETURN ( _MKSMALLINT(1) ); |
|
2034 |
} |
|
2035 |
RETURN ( _MKSMALLINT(0) ); |
|
2036 |
%} |
|
2037 |
! |
|
2038 |
||
2039 |
strictlyPositive |
|
2040 |
"return true, if the receiver is greater than zero |
|
2041 |
reimplemented here for speed" |
|
2042 |
||
2043 |
%{ /* NOCONTEXT */ |
|
2044 |
||
2045 |
#ifdef POSITIVE_ADDRESSES |
|
2046 |
RETURN ( (_intVal(self) > 0) ? true : false ); |
|
2047 |
#else |
|
2048 |
/* tag bit does not change sign */ |
|
2049 |
RETURN ( ((INT)(self) > 0) ? true : false ); |
|
2050 |
#endif |
|
2051 |
%} |
|
2052 |
! ! |
|
2053 |
||
2054 |
!SmallInteger class methodsFor:'documentation'! |
|
2055 |
||
2056 |
version |
|
927
8d8edf9df0ae
fixed \\ vs. rem: and // vs. quo: stupidities;
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
2057 |
^ '$Header: /cvs/stx/stx/libbasic/SmallInteger.st,v 1.44 1996-02-02 16:20:51 cg Exp $' |
701 | 2058 |
! ! |