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
|
84
|
14 |
instanceVariableNames:'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 |
|
328
|
26 |
$Header: /cvs/stx/stx/libbasic/CompiledCode.st,v 1.12 1995-05-01 21:29:03 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 |
"
|
328
|
47 |
$Header: /cvs/stx/stx/libbasic/CompiledCode.st,v 1.12 1995-05-01 21:29:03 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 |
|
225
|
59 |
byteCode <ByteArray> bytecode if its an interpreted codeobject
|
|
60 |
literals <Array> the block/methods literal array
|
|
61 |
|
|
62 |
|
|
63 |
Class variables:
|
|
64 |
|
|
65 |
NoByteCodeSignal raised if a codeObject is about to be executed
|
|
66 |
which has neither code nor byteCode (i.e. both are nil)
|
|
67 |
InvalidByteCodeSignal raised if byteCode is not an instance of ByteArray
|
|
68 |
InvalidInstructionSignal raised if an invalid instruction opcode is encountered
|
|
69 |
BadLiteralsSignal raised if literalArray is not an array
|
|
70 |
NonBooleanReceiverSignal raised for conditional jumps where receiver is not a boolean
|
|
71 |
ArgumentSignal raised if argument count is not what the codeObject expects
|
|
72 |
|
|
73 |
all of these signals are children of ExecutionErrorSignal.
|
84
|
74 |
|
|
75 |
NOTICE: layout known by runtime system and compiler - do not change
|
|
76 |
"
|
|
77 |
! !
|
|
78 |
|
249
|
79 |
!CompiledCode class methodsFor:'initialization'!
|
106
|
80 |
|
|
81 |
initialize
|
|
82 |
NoByteCodeSignal isNil ifTrue:[
|
159
|
83 |
NoByteCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
84 |
NoByteCodeSignal nameClass:self message:#noByteCodeSignal.
|
|
85 |
NoByteCodeSignal notifierString:'nil byteCode in code-object - not executable'.
|
|
86 |
|
|
87 |
InvalidByteCodeSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
88 |
InvalidByteCodeSignal nameClass:self message:#invalidByteCodeSignal.
|
|
89 |
InvalidByteCodeSignal notifierString:'invalid byteCode in code-object - not executable'.
|
|
90 |
|
|
91 |
InvalidInstructionSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
92 |
InvalidInstructionSignal nameClass:self message:#invalidInstructionSignal.
|
|
93 |
InvalidInstructionSignal notifierString:'invalid instruction in code-object - not executable'.
|
|
94 |
|
|
95 |
BadLiteralsSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
96 |
BadLiteralsSignal nameClass:self message:#badLiteralsSignal.
|
|
97 |
BadLiteralsSignal notifierString:'bad literal table in code-object - should not happen'.
|
|
98 |
|
|
99 |
NonBooleanReceiverSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
100 |
NonBooleanReceiverSignal nameClass:self message:#nonBooleanReceiverSignal.
|
|
101 |
NonBooleanReceiverSignal notifierString:'if/while on non-boolean receiver'.
|
|
102 |
|
|
103 |
ArgumentSignal := ExecutionErrorSignal newSignalMayProceed:true.
|
|
104 |
ArgumentSignal nameClass:self message:#argumentSignal.
|
|
105 |
ArgumentSignal notifierString:'bad argument(s)'.
|
106
|
106 |
]
|
|
107 |
! !
|
|
108 |
|
249
|
109 |
!CompiledCode class methodsFor:'signal access'!
|
106
|
110 |
|
159
|
111 |
executionErrorSignal
|
|
112 |
"return the parent-signal of all execution errors"
|
106
|
113 |
|
159
|
114 |
^ ExecutionErrorSignal
|
106
|
115 |
!
|
|
116 |
|
|
117 |
argumentSignal
|
|
118 |
"return the signal raised when something's wrong with the
|
|
119 |
arguments"
|
|
120 |
|
|
121 |
^ ArgumentSignal
|
|
122 |
! !
|
|
123 |
|
249
|
124 |
!CompiledCode class methodsFor:'queries'!
|
84
|
125 |
|
|
126 |
isBuiltInClass
|
|
127 |
"this class is known by the run-time-system"
|
|
128 |
|
|
129 |
^ true
|
|
130 |
! !
|
|
131 |
|
249
|
132 |
!CompiledCode methodsFor:'accessing'!
|
84
|
133 |
|
|
134 |
byteCode
|
|
135 |
"return the bytecode (a ByteArray)"
|
|
136 |
|
|
137 |
^ byteCode
|
|
138 |
!
|
|
139 |
|
|
140 |
literals
|
|
141 |
"return the literal array"
|
|
142 |
|
|
143 |
^ literals
|
|
144 |
! !
|
|
145 |
|
328
|
146 |
!CompiledCode methodsFor:'queries'!
|
|
147 |
|
|
148 |
messages
|
|
149 |
"return a Set of all symbols referenced by this thingy.
|
|
150 |
(this is more than the message selectors, since also global names
|
|
151 |
and symbols found in immediate arrays are included)."
|
|
152 |
|
|
153 |
|symbolSet|
|
|
154 |
|
|
155 |
symbolSet := IdentitySet new.
|
|
156 |
literals notNil ifTrue:[
|
|
157 |
literals do: [ :lit |
|
|
158 |
(lit isSymbol) ifTrue: [
|
|
159 |
symbolSet add: lit
|
|
160 |
] ifFalse: [
|
|
161 |
(lit isKindOf:Array) ifTrue: [
|
|
162 |
lit traverse: [ :el |
|
|
163 |
(el isSymbol) ifTrue: [symbolSet add: el]
|
|
164 |
]
|
|
165 |
]
|
|
166 |
]
|
|
167 |
]
|
|
168 |
].
|
|
169 |
^ symbolSet
|
|
170 |
|
|
171 |
"
|
|
172 |
(CompiledCode compiledMethodAt:#messages) messages
|
|
173 |
"
|
|
174 |
! !
|
|
175 |
|
249
|
176 |
!CompiledCode methodsFor:'private accessing'!
|
84
|
177 |
|
|
178 |
byteCode:aByteArray
|
|
179 |
"set the bytecode field - DANGER ALERT"
|
|
180 |
|
|
181 |
byteCode := aByteArray
|
|
182 |
!
|
|
183 |
|
|
184 |
literals:aLiteralArray
|
|
185 |
"set the literal array for evaluation - DANGER ALERT"
|
|
186 |
|
|
187 |
literals := aLiteralArray
|
|
188 |
! !
|
|
189 |
|
249
|
190 |
!CompiledCode methodsFor:'error handling'!
|
84
|
191 |
|
|
192 |
noByteCode
|
|
193 |
"this error is triggered when the interpreter tries to execute a
|
|
194 |
code object, where the byteCode is nil.
|
|
195 |
Can only happen when Compiler/runtime system is broken or
|
328
|
196 |
someone played around with a block/method.
|
|
197 |
(late news: also used for lazy compilation of methods)"
|
84
|
198 |
|
131
|
199 |
^ NoByteCodeSignal raise.
|
84
|
200 |
!
|
|
201 |
|
|
202 |
invalidByteCode
|
|
203 |
"this error is triggered when the interpreter tries to execute a
|
|
204 |
code object, where the byteCode is nonNil, but not a ByteArray.
|
|
205 |
Can only happen when Compiler/runtime system is broken or
|
|
206 |
someone played around with a block/method."
|
|
207 |
|
131
|
208 |
^ InvalidByteCodeSignal raise.
|
84
|
209 |
!
|
|
210 |
|
|
211 |
invalidInstruction
|
|
212 |
"this error is triggered when the bytecode-interpreter tries to
|
|
213 |
execute an invalid bytecode instruction.
|
|
214 |
Can only happen when Compiler/runtime system is broken or
|
|
215 |
someone played around with the block/methods code."
|
|
216 |
|
131
|
217 |
^ InvalidInstructionSignal raise.
|
84
|
218 |
!
|
|
219 |
|
|
220 |
badLiteralTable
|
|
221 |
"this error is triggered, when a block/method is called with a bad literal
|
|
222 |
array (i.e. non-array) - this can only happen, if the
|
|
223 |
compiler is broken or someone played around with a block/methods
|
|
224 |
literal table or the GC is broken and corrupted it."
|
|
225 |
|
131
|
226 |
^ BadLiteralsSignal raise.
|
84
|
227 |
!
|
|
228 |
|
|
229 |
receiverNotBoolean:anObject
|
|
230 |
"this error is triggered when the bytecode-interpreter tries to
|
|
231 |
execute ifTrue:/ifFalse or whileTrue: type of expressions where the
|
|
232 |
receiver is neither true nor false."
|
|
233 |
|
131
|
234 |
^ NonBooleanReceiverSignal raise.
|
106
|
235 |
!
|
|
236 |
|
|
237 |
tooManyArguments
|
|
238 |
"this error is triggered, when a method/block tries to perform a send with
|
|
239 |
more arguments than supported by the interpreter. This can only happen,
|
|
240 |
if the compiler has been changed without updating the VM."
|
|
241 |
|
131
|
242 |
^ ArgumentSignal
|
159
|
243 |
raiseRequestWith:self
|
|
244 |
errorString:'too many args in send'
|
106
|
245 |
!
|
|
246 |
|
|
247 |
badArgumentArray
|
255
|
248 |
"this error is triggered, if a non array is passed to
|
|
249 |
#valueWithReceiver:.. methods"
|
106
|
250 |
|
131
|
251 |
^ ArgumentSignal
|
159
|
252 |
raiseRequestWith:self
|
|
253 |
errorString:'argumentArray must be an Array'
|
84
|
254 |
! !
|