-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathObject.som
116 lines (90 loc) · 3.7 KB
/
Object.som
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"
$Id: Object.som 27 2009-07-31 11:17:53Z michael.haupt $
Copyright (c) 2001-2013 see AUTHORS file
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"
Object = nil (
class = primitive
objectSize = primitive "size in bytes"
"Comparing"
" If you override =, you MUST override hashcode as well. The rule
obj1 = obj2 => obj1 hashcode = obj2 hashcode
must be valid for all objects, or Hashtable will not work"
= other = ( ^self == other )
<> argument = ( ^(self = argument) not )
== other = primitive
~= other = (^ (self == other) not )
isNil = ( ^false )
notNil = ( ^true )
"Converting"
asString = ( ^'instance of ' + (self class) )
, element = ( ^(Vector new append: self) append: element )
hashcode = primitive
"Evaluating"
value = ( ^self )
"Convenience"
ifNil: aBlock = (^self)
ifNotNil: aBlock = (^aBlock value)
ifNil: noGoBlock ifNotNil: goBlock = (^goBlock value)
"Printing"
print = ( self asString print )
println = ( self print. system printNewline )
"Debugging"
inspect = primitive
halt = primitive
"Error handling"
error: string = ( '' println. ('ERROR: ' + string) println. system exit: 1 )
"Abstract method support"
subclassResponsibility = (
self error: 'This method is abstract and should be overridden'
)
"Error recovering"
doesNotUnderstand: selector arguments: arguments = (
self error:
('Method ' + selector + ' not found in class ' + self class name)
)
escapedBlock: block = (
self error: 'Block has escaped and cannot be executed'
)
unknownGlobal: name = ( ^system resolve: name )
"Reflection"
respondsTo: aSymbol = (
(self class hasMethod: aSymbol)
ifTrue: [ ^true ]
ifFalse: [ | cls |
cls := self class superclass.
[ cls isNil ] whileFalse: [
(cls hasMethod: aSymbol)
ifTrue: [ ^true ]
ifFalse: [ cls := cls superclass ] ].
^ false ]
)
perform: aSymbol = primitive
perform: aSymbol withArguments: args = primitive
perform: aSymbol inSuperclass: cls = primitive
perform: aSymbol withArguments: args inSuperclass: cls = primitive
instVarAt: idx = primitive
instVarAt: idx put: obj = primitive
instVarNamed: sym = primitive
isKindOf: class = (
| superclass |
self class == class ifTrue: [ ^ true ].
[(superclass := self class superclass) == nil] whileFalse: [
superclass == class ifTrue: [ ^ true ] ].
^ false
)
)