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 |
|
249
|
13 |
ExecutableFunction subclass:#CompiledCode
|
357
|
14 |
instanceVariableNames:'flags byteCode literals'
|
106
|
15 |
classVariableNames:'NoByteCodeSignal InvalidByteCodeSignal
|
159
|
16 |
InvalidInstructionSignal BadLiteralsSignal
|
|
17 |
NonBooleanReceiverSignal ArgumentSignal'
|
84
|
18 |
poolDictionaries:''
|
|
19 |
category:'Kernel-Methods'
|
|
20 |
!
|
|
21 |
|
249
|
22 |
CompiledCode comment:'
|
84
|
23 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
159
|
24 |
All Rights Reserved
|
92
|
25 |
|
370
|
26 |
$Header: /cvs/stx/stx/libbasic/CompiledCode.st,v 1.16 1995-08-03 01:14:55 claus Exp $
|
84
|
27 |
'!
|
|
28 |
|
249
|
29 |
!CompiledCode class methodsFor:'documentation'!
|
84
|
30 |
|
88
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
159
|
34 |
All Rights Reserved
|
88
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
370
|
47 |
$Header: /cvs/stx/stx/libbasic/CompiledCode.st,v 1.16 1995-08-03 01:14:55 claus Exp $
|
88
|
48 |
"
|
|
49 |
!
|
|
50 |
|
84
|
51 |
documentation
|
|
52 |
"
|
|
53 |
This is an abstract class, to merge common attributes of Blocks and
|
328
|
54 |
Methods i.e. describe all objects consisting of either compiled or
|
|
55 |
interpreted code.
|
84
|
56 |
|
|
57 |
Instance variables:
|
|
58 |
|
357
|
59 |
flags <SmallInteger> special flag bits coded in a number
|
225
|
60 |
byteCode <ByteArray> bytecode if its an interpreted codeobject
|
|
61 |
literals <Array> the block/methods literal array
|
|
62 |
|
|
63 |
|
|
64 |
Class variables:
|
|
65 |
|
|
66 |
NoByteCodeSignal raised if a codeObject is about to be executed
|
|
67 |
which has neither code nor byteCode (i.e. both are nil)
|
|
68 |
InvalidByteCodeSignal raised if byteCode is not an instance of ByteArray
|
|
69 |
InvalidInstructionSignal raised if an invalid instruction opcode is encountered
|
|
70 |
BadLiteralsSignal raised if literalArray is not an array
|
|
71 |
NonBooleanReceiverSignal raised for conditional jumps where receiver is not a boolean
|
|
72 |
ArgumentSignal raised if argument count is not what the codeObject expects
|
|
73 |
|
|
74 |
all of these signals are children of ExecutionErrorSignal.
|
84
|
75 |
|
|
76 |
NOTICE: layout known by runtime system and compiler - do not change
|
|
77 |
"
|
|
78 |
! !
|
|
79 |
|
249
|
80 |
!CompiledCode class methodsFor:'initialization'!
|
106
|
81 |
|
|
82 |
initialize
|
|
83 |
NoByteCodeSignal isNil ifTrue:[
|
159
|
84 |
NoByteCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
85 |
NoByteCodeSignal nameClass:self message:#noByteCodeSignal.
|
|
86 |
NoByteCodeSignal notifierString:'nil byteCode in code-object - not executable'.
|
|
87 |
|
|
88 |
InvalidByteCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
89 |
InvalidByteCodeSignal nameClass:self message:#invalidByteCodeSignal.
|
|
90 |
InvalidByteCodeSignal notifierString:'invalid byteCode in code-object - not executable'.
|
|
91 |
|
|
92 |
InvalidInstructionSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
93 |
InvalidInstructionSignal nameClass:self message:#invalidInstructionSignal.
|
|
94 |
InvalidInstructionSignal notifierString:'invalid instruction in code-object - not executable'.
|
|
95 |
|
|
96 |
BadLiteralsSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
97 |
BadLiteralsSignal nameClass:self message:#badLiteralsSignal.
|
|
98 |
BadLiteralsSignal notifierString:'bad literal table in code-object - should not happen'.
|
|
99 |
|
|
100 |
NonBooleanReceiverSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
101 |
NonBooleanReceiverSignal nameClass:self message:#nonBooleanReceiverSignal.
|
|
102 |
NonBooleanReceiverSignal notifierString:'if/while on non-boolean receiver'.
|
|
103 |
|
|
104 |
ArgumentSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
105 |
ArgumentSignal nameClass:self message:#argumentSignal.
|
|
106 |
ArgumentSignal notifierString:'bad argument(s)'.
|
106
|
107 |
]
|
|
108 |
! !
|
|
109 |
|
345
|
110 |
!CompiledCode class methodsFor:'Signal constants'!
|
106
|
111 |
|
159
|
112 |
executionErrorSignal
|
|
113 |
"return the parent-signal of all execution errors"
|
106
|
114 |
|
159
|
115 |
^ ExecutionErrorSignal
|
106
|
116 |
!
|
|
117 |
|
|
118 |
argumentSignal
|
|
119 |
"return the signal raised when something's wrong with the
|
|
120 |
arguments"
|
|
121 |
|
|
122 |
^ ArgumentSignal
|
|
123 |
! !
|
|
124 |
|
249
|
125 |
!CompiledCode class methodsFor:'queries'!
|
84
|
126 |
|
|
127 |
isBuiltInClass
|
|
128 |
"this class is known by the run-time-system"
|
|
129 |
|
|
130 |
^ true
|
|
131 |
! !
|
|
132 |
|
249
|
133 |
!CompiledCode methodsFor:'accessing'!
|
84
|
134 |
|
|
135 |
byteCode
|
|
136 |
"return the bytecode (a ByteArray)"
|
|
137 |
|
|
138 |
^ byteCode
|
|
139 |
!
|
|
140 |
|
|
141 |
literals
|
|
142 |
"return the literal array"
|
|
143 |
|
|
144 |
^ literals
|
|
145 |
! !
|
|
146 |
|
328
|
147 |
!CompiledCode methodsFor:'queries'!
|
|
148 |
|
|
149 |
messages
|
|
150 |
"return a Set of all symbols referenced by this thingy.
|
|
151 |
(this is more than the message selectors, since also global names
|
|
152 |
and symbols found in immediate arrays are included)."
|
|
153 |
|
|
154 |
|symbolSet|
|
|
155 |
|
|
156 |
symbolSet := IdentitySet new.
|
|
157 |
literals notNil ifTrue:[
|
|
158 |
literals do: [ :lit |
|
370
|
159 |
lit isSymbol ifTrue: [
|
328
|
160 |
symbolSet add: lit
|
|
161 |
] ifFalse: [
|
370
|
162 |
lit isArray ifTrue: [
|
328
|
163 |
lit traverse: [ :el |
|
370
|
164 |
el isSymbol ifTrue: [symbolSet add: el]
|
328
|
165 |
]
|
|
166 |
]
|
|
167 |
]
|
|
168 |
]
|
|
169 |
].
|
|
170 |
^ symbolSet
|
|
171 |
|
|
172 |
"
|
|
173 |
(CompiledCode compiledMethodAt:#messages) messages
|
|
174 |
"
|
|
175 |
! !
|
|
176 |
|
249
|
177 |
!CompiledCode methodsFor:'private accessing'!
|
84
|
178 |
|
|
179 |
byteCode:aByteArray
|
|
180 |
"set the bytecode field - DANGER ALERT"
|
|
181 |
|
|
182 |
byteCode := aByteArray
|
|
183 |
!
|
|
184 |
|
|
185 |
literals:aLiteralArray
|
|
186 |
"set the literal array for evaluation - DANGER ALERT"
|
|
187 |
|
|
188 |
literals := aLiteralArray
|
357
|
189 |
!
|
|
190 |
|
|
191 |
dynamic:aBoolean
|
|
192 |
"set/clear the flag bit stating that the machine code was created
|
|
193 |
dynamically and should be flushed on image-restart.
|
|
194 |
Obsolete - now done in VM"
|
|
195 |
|
|
196 |
%{ /* NOCONTEXT */
|
|
197 |
|
|
198 |
int newFlags = _intVal(_INST(flags));
|
|
199 |
|
|
200 |
/* made this a primitive to get define in stc.h */
|
|
201 |
if (aBoolean == true)
|
|
202 |
newFlags |= F_DYNAMIC;
|
|
203 |
else
|
|
204 |
newFlags &= ~F_DYNAMIC;
|
|
205 |
|
|
206 |
_INST(flags) = _MKSMALLINT(newFlags);
|
|
207 |
%}
|
|
208 |
!
|
|
209 |
|
|
210 |
dynamic
|
|
211 |
"return the flag stating that the machine code was created
|
|
212 |
dynamically (from bytecode)."
|
|
213 |
|
|
214 |
%{ /* NOCONTEXT */
|
|
215 |
|
|
216 |
/* made this a primitive to get define in stc.h */
|
|
217 |
|
|
218 |
RETURN ((__intVal(_INST(flags)) & F_DYNAMIC) ? true : false);
|
|
219 |
%}
|
|
220 |
!
|
|
221 |
|
|
222 |
markFlag:aBoolean
|
|
223 |
"set/clear the mark flag bit.
|
|
224 |
This bit is not used by the VM, but instead free to mark codeObjects
|
|
225 |
for any (debugging/tracing) use. For example, the coverage test uses
|
|
226 |
these to mark reached methods. (inspired by a note in c.l.s)"
|
|
227 |
|
|
228 |
%{ /* NOCONTEXT */
|
|
229 |
|
|
230 |
int newFlags = _intVal(_INST(flags));
|
|
231 |
|
|
232 |
/* made this a primitive to get define in stc.h */
|
|
233 |
if (aBoolean == true)
|
|
234 |
newFlags |= F_MARKBIT;
|
|
235 |
else
|
|
236 |
newFlags &= ~F_MARKBIT;
|
|
237 |
|
|
238 |
_INST(flags) = _MKSMALLINT(newFlags);
|
|
239 |
%}
|
|
240 |
!
|
|
241 |
|
|
242 |
markFlag
|
|
243 |
"return the mark bits value as a boolean"
|
|
244 |
|
|
245 |
%{ /* NOCONTEXT */
|
|
246 |
|
|
247 |
/* made this a primitive to get define in stc.h */
|
|
248 |
|
|
249 |
RETURN ((__intVal(_INST(flags)) & F_MARKBIT) ? true : false);
|
|
250 |
%}
|
84
|
251 |
! !
|
|
252 |
|
249
|
253 |
!CompiledCode methodsFor:'error handling'!
|
84
|
254 |
|
|
255 |
noByteCode
|
|
256 |
"this error is triggered when the interpreter tries to execute a
|
|
257 |
code object, where the byteCode is nil.
|
|
258 |
Can only happen when Compiler/runtime system is broken or
|
359
|
259 |
someone played around with a block/method,
|
|
260 |
or if compilation of a lazy method fails
|
|
261 |
(the lazy method contains an error or
|
|
262 |
primitive code and there is no stc compiler available)."
|
84
|
263 |
|
131
|
264 |
^ NoByteCodeSignal raise.
|
84
|
265 |
!
|
|
266 |
|
|
267 |
invalidByteCode
|
|
268 |
"this error is triggered when the interpreter tries to execute a
|
|
269 |
code object, where the byteCode is nonNil, but not a ByteArray.
|
|
270 |
Can only happen when Compiler/runtime system is broken or
|
|
271 |
someone played around with a block/method."
|
|
272 |
|
131
|
273 |
^ InvalidByteCodeSignal raise.
|
84
|
274 |
!
|
|
275 |
|
|
276 |
invalidInstruction
|
|
277 |
"this error is triggered when the bytecode-interpreter tries to
|
|
278 |
execute an invalid bytecode instruction.
|
|
279 |
Can only happen when Compiler/runtime system is broken or
|
|
280 |
someone played around with the block/methods code."
|
|
281 |
|
131
|
282 |
^ InvalidInstructionSignal raise.
|
84
|
283 |
!
|
|
284 |
|
|
285 |
badLiteralTable
|
|
286 |
"this error is triggered, when a block/method is called with a bad literal
|
|
287 |
array (i.e. non-array) - this can only happen, if the
|
|
288 |
compiler is broken or someone played around with a block/methods
|
|
289 |
literal table or the GC is broken and corrupted it."
|
|
290 |
|
131
|
291 |
^ BadLiteralsSignal raise.
|
84
|
292 |
!
|
|
293 |
|
|
294 |
receiverNotBoolean:anObject
|
|
295 |
"this error is triggered when the bytecode-interpreter tries to
|
|
296 |
execute ifTrue:/ifFalse or whileTrue: type of expressions where the
|
|
297 |
receiver is neither true nor false."
|
|
298 |
|
131
|
299 |
^ NonBooleanReceiverSignal raise.
|
106
|
300 |
!
|
|
301 |
|
|
302 |
tooManyArguments
|
|
303 |
"this error is triggered, when a method/block tries to perform a send with
|
|
304 |
more arguments than supported by the interpreter. This can only happen,
|
|
305 |
if the compiler has been changed without updating the VM."
|
|
306 |
|
131
|
307 |
^ ArgumentSignal
|
159
|
308 |
raiseRequestWith:self
|
|
309 |
errorString:'too many args in send'
|
106
|
310 |
!
|
|
311 |
|
|
312 |
badArgumentArray
|
255
|
313 |
"this error is triggered, if a non array is passed to
|
|
314 |
#valueWithReceiver:.. methods"
|
106
|
315 |
|
131
|
316 |
^ ArgumentSignal
|
159
|
317 |
raiseRequestWith:self
|
|
318 |
errorString:'argumentArray must be an Array'
|
84
|
319 |
! !
|