Major refactoring. Removed about 900 lines of code.
[panda.git] / st / SmallInteger.st
blobab8ad142de84ed0db3e5a34917bf21a2a184095e
2 Copyright (c) 2007 Luca Bruno
4 This file is part of Smalltalk YX.
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the 'Software'), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
25 SmallInteger method!
26 + aNumber
27         <primitive: 'SmallInteger_add'>
28         ^ self!
29 Annotation key: 'category' value: 'arithmetic'!
31 SmallInteger method!
32 - aNumber
33         <primitive: 'SmallInteger_minus'>
34         ^ self!
35 Annotation key: 'category' value: 'arithmetic'!
36         
37 SmallInteger method!
38 * aNumber
39         <primitive: 'SmallInteger_mul'>
40         ^ 42!
41 Annotation key: 'category' value: 'arithmetic'!
43 SmallInteger method!
44 < aNumber
45         <primitive: 'SmallInteger_lt'>
46         ^ self!
47 Annotation key: 'category' value: 'testing'!
49 SmallInteger method!
50 > aNumber
51         <primitive: 'SmallInteger_gt'>
52         ^ self!
53 Annotation key: 'category' value: 'testing'!
55 SmallInteger method!
56 <= aNumber
57         <primitive: 'SmallInteger_le'>
58         ^ self!
59 Annotation key: 'category' value: 'testing'!
61 SmallInteger method!
62 >= aNumber
63         <primitive: 'SmallInteger_ge'>
64         ^ self!
65 Annotation key: 'category' value: 'testing'!
67 SmallInteger method!
68 = aNumber
69         <primitive: 'SmallInteger_eq'>
70         ^ self!
71 Annotation key: 'category' value: 'testing'!
73 SmallInteger method!
74 fibonacci
75         self <= 2
76                 ifTrue: [ ^ 1 ]
77             ifFalse: [ ^ (self - 2) fibonacci + (self - 1) fibonacci ].!
78 Annotation key: 'category' value: 'mathematics'!
80         == aNumber
81         [
82                 <primitive: 'SmallInteger_eq'>
83                 ^ super == aNumber
84         ]
86         ~= aNumber
87         [
88                 <primitive: 'SmallInteger_ne'>
89                 ^ super ~= aNumber
90         ]
92         ~~ aNumber
93         [
94                 <primitive: 'SmallInteger_ne'>
95                 ^super ~~ aNumber
96         ]
98         quo: aNumber
99         [
100                 <primitive: 'SmallInteger_quo'>
101                 ^ super quo: aNumber
102         ]
104         \\ aNumber
105         [
106                 <primitive: 'SmallInteger_mod'>
107                 ^ super \\ aNumber
108         ]
111 SmallInteger methodsFor: 'bit-wise operations'
114         bitAnd: aNumber
116                 <primitive: 'SmallInteger_bitAnd'>
117                 ^super bitAnd: aNumber
118         ]
120         bitOr: aNumber
122                 <primitive: 'SmallInteger_bitOr'>
123                 ^ super bitOr: aNumber
124         ]
126         bitXor: aNumber
127         [
128                 <primitive: 'SmallInteger_bitXor'>
129                 ^ super bitXor: aNumber
130         ]
132         bitShift: aNumber
133         [
134                 <primitive: 'SmallInteger_bitShift'>
135         ^ super bitShift: aNumber
136         ]
139 SmallInteger methodsFor: 'testing'
142         isLargeInteger
143         [
144                 ^ false
145         ]
147         isSmallInteger
148         [
149                 ^ true
150         ]
153 SmallInteger methodsFor: 'coercing'
156         asInteger
157         [    
158                 ^ self
159         ]
161         asFloat
162         [
163                 <primitive: 'SmallInteger_asFloat'>
164                 self primitiveFailed
165         ]
167         asLargeInteger
168         [
169                 <primitive: 'SmallInteger_asLargeInteger'>
170                 self primitiveFailed
171         ]
173         print
174         [
175                 <primitive: 'SmallInteger_print'>
176                 self primitiveFailed
177         ]
179         zero
180         [
181                 ^ 0
182         ]
185         generality
186         [
187                 ^ 10
188         ]
190         unity
191         [
192                 ^ 1
193         ]