84
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
159
|
3 |
All Rights Reserved
|
84
|
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 |
Object subclass:#ExecutableFunction
|
357
|
14 |
instanceVariableNames:'code*'
|
159
|
15 |
classVariableNames:'ExecutionErrorSignal InvalidCodeSignal'
|
84
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Methods'
|
|
18 |
!
|
|
19 |
|
|
20 |
ExecutableFunction comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
159
|
22 |
All Rights Reserved
|
92
|
23 |
|
379
|
24 |
$Header: /cvs/stx/stx/libbasic/ExecutableFunction.st,v 1.15 1995-08-10 12:27:36 claus Exp $
|
84
|
25 |
'!
|
|
26 |
|
|
27 |
!ExecutableFunction class methodsFor:'documentation'!
|
|
28 |
|
88
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
159
|
32 |
All Rights Reserved
|
88
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
379
|
45 |
$Header: /cvs/stx/stx/libbasic/ExecutableFunction.st,v 1.15 1995-08-10 12:27:36 claus Exp $
|
|
46 |
$Revision: 1.15 $
|
88
|
47 |
"
|
|
48 |
!
|
|
49 |
|
84
|
50 |
documentation
|
|
51 |
"
|
88
|
52 |
This is an abstract class, to merge common attributes of all kinds of
|
357
|
53 |
executable code objects; i.e. non-ST functions, Blocks and Methods
|
|
54 |
and whatever there might be in the future.
|
84
|
55 |
|
|
56 |
Instance variables:
|
|
57 |
|
225
|
58 |
code <not_an_object> the function pointer to the machine code.
|
|
59 |
Not accessable from smalltalk code.
|
328
|
60 |
(notice the '*' in the instVarNames definition)
|
225
|
61 |
|
|
62 |
|
107
|
63 |
|
225
|
64 |
Class variables:
|
|
65 |
|
|
66 |
ExecutionErrorSignal parent of all execution errors
|
|
67 |
(not raised itself)
|
|
68 |
|
|
69 |
InvalidCodeSignal codeObject is not executable
|
84
|
70 |
|
|
71 |
NOTICE: layout known by runtime system and compiler - do not change
|
|
72 |
"
|
|
73 |
! !
|
|
74 |
|
|
75 |
!ExecutableFunction class methodsFor:'queries'!
|
|
76 |
|
|
77 |
isBuiltInClass
|
|
78 |
"this class is known by the run-time-system"
|
|
79 |
|
|
80 |
^ true
|
|
81 |
! !
|
|
82 |
|
107
|
83 |
!ExecutableFunction class methodsFor:'initialization'!
|
|
84 |
|
|
85 |
initialize
|
|
86 |
InvalidCodeSignal isNil ifTrue:[
|
159
|
87 |
ExecutionErrorSignal := ErrorSignal newSignalMayProceed:true.
|
|
88 |
ExecutionErrorSignal nameClass:self message:#executionErrorSignal.
|
|
89 |
ExecutionErrorSignal notifierString:'execution error'.
|
|
90 |
|
|
91 |
InvalidCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
92 |
InvalidCodeSignal nameClass:self message:#invalidCodeSignal.
|
|
93 |
InvalidCodeSignal notifierString:'invalid code-object - not executable'.
|
107
|
94 |
]
|
|
95 |
! !
|
|
96 |
|
345
|
97 |
!ExecutableFunction class methodsFor:'Signal constants'!
|
159
|
98 |
|
|
99 |
executionErrorSignal
|
|
100 |
"return the parent-signal of all execution errors"
|
|
101 |
|
|
102 |
^ ExecutionErrorSignal
|
|
103 |
! !
|
|
104 |
|
84
|
105 |
!ExecutableFunction methodsFor:'accessing'!
|
|
106 |
|
|
107 |
instVarAt:index
|
|
108 |
"have to catch instVar access to code - since its no object"
|
|
109 |
|
|
110 |
(index == 1) ifTrue:[^ self code].
|
|
111 |
^ super instVarAt:index
|
|
112 |
!
|
|
113 |
|
|
114 |
instVarAt:index put:value
|
|
115 |
"have to catch instVar access to code - since its no object"
|
|
116 |
|
|
117 |
(index == 1) ifTrue:[^ self code:value].
|
|
118 |
^ super instVarAt:index put:value
|
|
119 |
!
|
|
120 |
|
|
121 |
code
|
|
122 |
"return the code field. This is not an object but the address of the machine instructions.
|
|
123 |
Therefore an integer representing the code-address is returned"
|
|
124 |
|
|
125 |
%{ /* NOCONTEXT */
|
357
|
126 |
extern OBJ __MKUINT();
|
|
127 |
unsigned addr;
|
84
|
128 |
|
92
|
129 |
if (_INST(code_) != nil) {
|
357
|
130 |
addr = (int)_INST(code_);
|
|
131 |
if (addr <= _MAX_INT) {
|
|
132 |
RETURN ( __MKSMALLINT(addr) );
|
|
133 |
}
|
|
134 |
RETURN ( __MKUINT(addr));
|
84
|
135 |
}
|
328
|
136 |
%}.
|
84
|
137 |
^ nil
|
|
138 |
! !
|
|
139 |
|
|
140 |
!ExecutableFunction methodsFor:'private accessing'!
|
|
141 |
|
|
142 |
code:anAddress
|
|
143 |
"set the code field - DANGER ALERT.
|
|
144 |
This is not an object but the address of the machine instructions.
|
|
145 |
Therefore the argument must be an integer representing this address.
|
|
146 |
You can crash Smalltalk very badly when playing around here ...
|
|
147 |
This method is for compiler support and very special cases (debugging) only
|
|
148 |
- do not use"
|
|
149 |
|
|
150 |
%{ /* NOCONTEXT */
|
328
|
151 |
|
249
|
152 |
if (__isSmallInteger(anAddress))
|
159
|
153 |
_INST(code_) = (OBJ)(_intVal(anAddress));
|
357
|
154 |
else {
|
360
|
155 |
_INST(code_) = (OBJ)(__longIntVal(anAddress));
|
357
|
156 |
}
|
328
|
157 |
%}
|
84
|
158 |
! !
|
|
159 |
|
|
160 |
!ExecutableFunction methodsFor:'error handling'!
|
|
161 |
|
|
162 |
invalidCode
|
|
163 |
"this error is triggered by the interpreter when something is wrong
|
107
|
164 |
with the code object (any error not handled by Method-signals).
|
84
|
165 |
In this case, the VM sends this to the bad method/block (the receiver).
|
|
166 |
Can only happen when the Compiler/runtime system is broken or
|
|
167 |
someone played around."
|
|
168 |
|
131
|
169 |
^ InvalidCodeSignal raise.
|
84
|
170 |
! !
|
|
171 |
|
357
|
172 |
!ExecutableFunction methodsFor:'printing & storing'!
|
|
173 |
|
|
174 |
printOn:aStream
|
|
175 |
|addr|
|
|
176 |
|
|
177 |
addr := self code.
|
|
178 |
addr isNil ifTrue:[^ super printOn:aStream].
|
|
179 |
|
|
180 |
aStream nextPutAll:self class name; nextPutAll:'(address: 0x';
|
|
181 |
nextPutAll:(addr printStringRadix:16); nextPutAll:')'
|
|
182 |
! !
|
|
183 |
|
84
|
184 |
!ExecutableFunction methodsFor:'binary storage'!
|
|
185 |
|
|
186 |
readBinaryContentsFrom: stream manager: manager
|
|
187 |
"make certain, that no invalid function addresses are created."
|
|
188 |
|
|
189 |
super readBinaryContentsFrom: stream manager: manager.
|
92
|
190 |
self code:nil.
|
84
|
191 |
! !
|