252
|
1 |
'From Smalltalk/X, Version:3.3.1 on 5-jan-1998 at 2:09:56 pm' !
|
|
2 |
|
|
3 |
Context subclass:#JavaContext
|
|
4 |
instanceVariableNames:'exArg byteCode constPool method'
|
28
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Java-Support'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!JavaContext methodsFor:'ST context mimicri'!
|
|
12 |
|
252
|
13 |
argAt:n
|
|
14 |
|arg0Index|
|
|
15 |
|
|
16 |
self method isStatic ifTrue:[
|
|
17 |
arg0Index := 0
|
|
18 |
] ifFalse:[
|
|
19 |
arg0Index := 1
|
|
20 |
].
|
|
21 |
^ self at:arg0Index+n
|
|
22 |
|
|
23 |
"Created: / 2.1.1998 / 17:54:13 / cg"
|
|
24 |
"Modified: / 2.1.1998 / 21:39:30 / cg"
|
|
25 |
!
|
117
|
26 |
|
252
|
27 |
argAt:n put:value
|
|
28 |
|arg0Index|
|
216
|
29 |
|
252
|
30 |
self method isStatic ifTrue:[
|
|
31 |
arg0Index := 0
|
|
32 |
] ifFalse:[
|
|
33 |
arg0Index := 1
|
|
34 |
].
|
|
35 |
^ super argAt:arg0Index+n put:value
|
|
36 |
|
|
37 |
"Created: / 2.1.1998 / 17:54:34 / cg"
|
|
38 |
"Modified: / 2.1.1998 / 21:35:19 / cg"
|
|
39 |
!
|
|
40 |
|
|
41 |
args
|
|
42 |
"return an array filled with the arguments of this context"
|
|
43 |
|
|
44 |
|n arg1Index|
|
28
|
45 |
|
252
|
46 |
n := self numArgs.
|
|
47 |
n == 0 ifTrue:[
|
|
48 |
"/ little optimization here - avaoid creating empty containers
|
|
49 |
^ #()
|
|
50 |
].
|
|
51 |
|
|
52 |
self method isStatic ifTrue:[
|
|
53 |
arg1Index := 1
|
|
54 |
] ifFalse:[
|
|
55 |
arg1Index := 2
|
41
|
56 |
].
|
252
|
57 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:arg1Index.
|
|
58 |
|
|
59 |
"Created: / 2.1.1998 / 17:54:57 / cg"
|
|
60 |
"Modified: / 2.1.1998 / 21:34:44 / cg"
|
|
61 |
!
|
|
62 |
|
|
63 |
argsAndVars
|
|
64 |
"return an array filled with the arguments and variables of this context"
|
|
65 |
|
|
66 |
|n arg1Index|
|
28
|
67 |
|
252
|
68 |
n := self numArgs + self numVars.
|
|
69 |
n == 0 ifTrue:[
|
|
70 |
"/ little optimization here - avaoid creating empty containers
|
|
71 |
^ #()
|
|
72 |
].
|
|
73 |
self method isStatic ifTrue:[
|
|
74 |
arg1Index := 1
|
|
75 |
] ifFalse:[
|
|
76 |
arg1Index := 2
|
|
77 |
].
|
|
78 |
^ (Array new:n) replaceFrom:1 to:n with:self startingAt:arg1Index.
|
|
79 |
|
|
80 |
"Created: / 2.1.1998 / 17:55:14 / cg"
|
|
81 |
"Modified: / 2.1.1998 / 21:35:39 / cg"
|
28
|
82 |
!
|
|
83 |
|
|
84 |
canReturn
|
|
85 |
^ false
|
|
86 |
|
|
87 |
"Created: 1.5.1996 / 15:05:36 / cg"
|
|
88 |
!
|
|
89 |
|
252
|
90 |
lineNumber
|
|
91 |
|nr pc|
|
156
|
92 |
|
252
|
93 |
pc := self pc.
|
43
|
94 |
|
211
|
95 |
"/ 'ask line for pc:' print. pc printCR.
|
|
96 |
pc isNil ifTrue:[" '-> 0 [a]' printCR. " ^0].
|
43
|
97 |
|
252
|
98 |
nr := self method lineNumberForPC:pc.
|
211
|
99 |
nr isNil ifTrue:[" '-> 0 [b]' printCR. " ^ 0].
|
|
100 |
"/ '-> ' print. nr printCR.
|
210
|
101 |
^ nr.
|
28
|
102 |
|
252
|
103 |
"Created: / 1.5.1996 / 15:05:47 / cg"
|
|
104 |
"Modified: / 4.1.1998 / 23:35:38 / cg"
|
28
|
105 |
!
|
|
106 |
|
252
|
107 |
lineNumberFromMethod
|
|
108 |
|m|
|
|
109 |
|
|
110 |
m := self method.
|
|
111 |
m notNil ifTrue:[
|
|
112 |
^ m lineNumber
|
|
113 |
].
|
|
114 |
^ nil
|
28
|
115 |
|
252
|
116 |
"Created: / 4.1.1998 / 23:34:45 / cg"
|
|
117 |
"Modified: / 4.1.1998 / 23:35:55 / cg"
|
|
118 |
!
|
|
119 |
|
|
120 |
method
|
|
121 |
"the method may be found in the interpreter temps ..."
|
|
122 |
|
|
123 |
(method isMemberOf:JavaMethod) ifTrue:[^ method].
|
|
124 |
^ super method
|
|
125 |
|
|
126 |
"Created: / 1.5.1996 / 15:03:43 / cg"
|
|
127 |
"Modified: / 2.1.1998 / 21:38:00 / cg"
|
28
|
128 |
!
|
|
129 |
|
|
130 |
methodHome
|
|
131 |
^ self
|
|
132 |
!
|
|
133 |
|
|
134 |
numArgs
|
252
|
135 |
"return the number of args.
|
|
136 |
Redefined since Java keeps the receiver of a non-static method
|
|
137 |
at local slot 0."
|
28
|
138 |
|
252
|
139 |
|n|
|
198
|
140 |
|
252
|
141 |
n := super numArgs.
|
|
142 |
self method isStatic ifFalse:[
|
|
143 |
n := n - 1
|
|
144 |
].
|
|
145 |
^ n
|
28
|
146 |
|
252
|
147 |
"Created: / 2.1.1998 / 22:21:24 / cg"
|
28
|
148 |
!
|
|
149 |
|
32
|
150 |
pc
|
252
|
151 |
lineNr isNil ifTrue:[^ nil].
|
|
152 |
^ super lineNumber
|
28
|
153 |
|
252
|
154 |
"Created: / 4.1.1998 / 23:33:48 / cg"
|
117
|
155 |
!
|
|
156 |
|
252
|
157 |
selector
|
|
158 |
"the selector can be extracted from the method.
|
|
159 |
the method may be found in the interpreter temps ..."
|
|
160 |
|
|
161 |
|s m|
|
|
162 |
|
|
163 |
selector isNil ifTrue:[
|
|
164 |
m := self method.
|
|
165 |
m notNil ifTrue:[
|
|
166 |
^ m name
|
|
167 |
]
|
|
168 |
].
|
|
169 |
^ super selector
|
|
170 |
|
|
171 |
"Modified: / 30.12.1997 / 17:22:06 / cg"
|
|
172 |
"Created: / 30.12.1997 / 17:23:47 / cg"
|
125
|
173 |
!
|
|
174 |
|
252
|
175 |
setPC:newPC
|
|
176 |
lineNr := newPC
|
|
177 |
|
|
178 |
"Created: / 5.1.1998 / 00:09:02 / cg"
|
|
179 |
! !
|
|
180 |
|
|
181 |
!JavaContext methodsFor:'exception handler support'!
|
117
|
182 |
|
252
|
183 |
markForException
|
|
184 |
"set the exception handler flag in the receiver.
|
|
185 |
The JVM needs this to enter an exception handler instead of restarting
|
|
186 |
from the beginning (when the context is restarted).
|
|
187 |
- a highly internal mechanism and not for public use."
|
117
|
188 |
|
252
|
189 |
%{ /* NOCONTEXT */
|
|
190 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__JAVA_EX_PEND));
|
|
191 |
%}
|
|
192 |
|
|
193 |
"Modified: 13.12.1995 / 19:05:22 / cg"
|
28
|
194 |
! !
|
|
195 |
|
|
196 |
!JavaContext methodsFor:'printing & storing'!
|
|
197 |
|
252
|
198 |
receiverPrintString
|
|
199 |
"return a string describing the receiver of the context"
|
52
|
200 |
|
252
|
201 |
|receiverClass receiverClassName newString implementorClass|
|
28
|
202 |
|
252
|
203 |
%{
|
|
204 |
/*
|
|
205 |
* special handling for (invalid) free objects.
|
|
206 |
* these only appear if some primitiveCode does not correctly use SEND macros,
|
|
207 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen.
|
|
208 |
*/
|
|
209 |
if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) {
|
|
210 |
receiverClassName = __MKSTRING("FreeObject");
|
|
211 |
}
|
|
212 |
%}.
|
|
213 |
receiverClassName notNil ifTrue:[^ receiverClassName].
|
228
|
214 |
|
252
|
215 |
receiverClass := receiver class.
|
|
216 |
receiverClassName := receiverClass name.
|
|
217 |
(receiverClass == SmallInteger) ifTrue:[
|
|
218 |
newString := '(' , receiver printString , ') ' , receiverClassName
|
228
|
219 |
] ifFalse:[
|
252
|
220 |
newString := receiverClassName
|
228
|
221 |
].
|
|
222 |
|
252
|
223 |
"
|
|
224 |
kludge to avoid slow search for containing class
|
|
225 |
"
|
|
226 |
(selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
|
|
227 |
implementorClass := self methodClass.
|
|
228 |
].
|
|
229 |
implementorClass notNil ifTrue: [
|
|
230 |
(implementorClass ~~ receiverClass) ifTrue: [
|
|
231 |
newString := newString , '>>>',
|
|
232 |
implementorClass name printString
|
|
233 |
]
|
|
234 |
] ifFalse:[
|
|
235 |
self searchClass ~~ receiverClass ifTrue:[
|
|
236 |
newString := newString , '>>>' , self searchClass name
|
|
237 |
].
|
|
238 |
"/ "
|
|
239 |
"/ kludge for doIt - these unbound methods are not
|
|
240 |
"/ found in the classes methodDictionary
|
|
241 |
"/ "
|
|
242 |
"/ (selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[
|
|
243 |
"/ newString := newString , '>>>**NONE**'
|
|
244 |
"/ ]
|
28
|
245 |
].
|
|
246 |
|
252
|
247 |
^ newString
|
28
|
248 |
|
|
249 |
! !
|
|
250 |
|
129
|
251 |
!JavaContext class methodsFor:'documentation'!
|
28
|
252 |
|
|
253 |
version
|
252
|
254 |
^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaContext.st,v 1.18 1998/01/05 18:47:12 cg Exp $'
|
28
|
255 |
! !
|