--- a/JavaContext.st Mon Jan 12 23:18:07 1998 +0000
+++ b/JavaContext.st Fri Jan 16 16:12:55 1998 +0000
@@ -1,7 +1,7 @@
-'From Smalltalk/X, Version:3.3.1 on 7-jan-1998 at 9:54:49 pm' !
+'From Smalltalk/X, Version:3.3.1 on 15-jan-1998 at 4:28:10 pm' !
Context subclass:#JavaContext
- instanceVariableNames:'exArg byteCode constPool method'
+ instanceVariableNames:'exArg byteCode constPool method monitor'
classVariableNames:''
poolDictionaries:''
category:'Java-Support'
@@ -10,29 +10,30 @@
!JavaContext methodsFor:'ST context mimicri'!
-argAt:n
- |arg0Index|
+arg1Index
+ "the java stack contains the receiver in a non-static
+ method, as slot 0. Therefore, the first arg is found at slot2
+ if this is for a non-static method"
self method isStatic ifTrue:[
- arg0Index := 0
- ] ifFalse:[
- arg0Index := 1
+ ^ 1
].
- ^ self at:arg0Index+n
+ ^ 2
+!
+
+argAt:n
+ "return the i'th argument (1..nArgs)"
+
+ ^ self at:(self arg1Index - 1 + n)
"Created: / 2.1.1998 / 17:54:13 / cg"
"Modified: / 2.1.1998 / 21:39:30 / cg"
!
argAt:n put:value
- |arg0Index|
+ "change the i'th argument (1..nArgs)"
- self method isStatic ifTrue:[
- arg0Index := 0
- ] ifFalse:[
- arg0Index := 1
- ].
- ^ super argAt:arg0Index+n put:value
+ ^ super argAt:(self arg1Index - 1 + n) put:value
"Created: / 2.1.1998 / 17:54:34 / cg"
"Modified: / 2.1.1998 / 21:35:19 / cg"
@@ -41,20 +42,15 @@
args
"return an array filled with the arguments of this context"
- |n arg1Index|
+ |n|
n := self numArgs.
n == 0 ifTrue:[
- "/ little optimization here - avaoid creating empty containers
+ "/ little optimization here - avoid creating empty containers
^ #()
].
- self method isStatic ifTrue:[
- arg1Index := 1
- ] ifFalse:[
- arg1Index := 2
- ].
- ^ (Array new:n) replaceFrom:1 to:n with:self startingAt:arg1Index.
+ ^ (Array new:n) replaceFrom:1 to:n with:self startingAt:(self arg1Index).
"Created: / 2.1.1998 / 17:54:57 / cg"
"Modified: / 2.1.1998 / 21:34:44 / cg"
@@ -63,22 +59,17 @@
argsAndVars
"return an array filled with the arguments and variables of this context"
- |n arg1Index|
+ |n|
n := self numArgs + self numVars.
n == 0 ifTrue:[
- "/ little optimization here - avaoid creating empty containers
- ^ #()
+ "/ little optimization here - avoid creating empty containers
+ ^ #()
].
- self method isStatic ifTrue:[
- arg1Index := 1
- ] ifFalse:[
- arg1Index := 2
- ].
- ^ (Array new:n) replaceFrom:1 to:n with:self startingAt:arg1Index.
+ ^ (Array new:n) replaceFrom:1 to:n with:self startingAt:(self arg1Index).
"Created: / 2.1.1998 / 17:55:14 / cg"
- "Modified: / 2.1.1998 / 21:35:39 / cg"
+ "Modified: / 13.1.1998 / 15:44:56 / cg"
!
lineNumber
@@ -88,24 +79,28 @@
"/ 'ask line for pc:' print. pc printCR.
pc isNil ifTrue:[
- nr := self lineNumberFromMethod.
- nr notNil ifTrue:[
- ^ nr
- ].
- " '-> 0 [a]' printCR. "
- ^0
+ nr := self lineNumberFromMethod.
+ nr notNil ifTrue:[
+ ^ nr
+ ].
+ " '-> 0 [a]' printCR. "
+ ^0
].
nr := self method lineNumberForPC:pc.
nr isNil ifTrue:[
- " '-> 0 [b]' printCR. "
- ^ 0
+ nr := self lineNumberFromMethod.
+ nr notNil ifTrue:[
+ ^ nr
+ ].
+ " '-> 0 [b]' printCR. "
+ ^ 0
].
"/ '-> ' print. nr printCR.
^ nr.
"Created: / 1.5.1996 / 15:05:47 / cg"
- "Modified: / 6.1.1998 / 19:59:27 / cg"
+ "Modified: / 15.1.1998 / 15:25:29 / cg"
!
lineNumberFromMethod
@@ -138,7 +133,7 @@
numArgs
"return the number of args.
Redefined since Java keeps the receiver of a non-static method
- at local slot 0."
+ at local slot 1."
|n|
@@ -151,6 +146,34 @@
"Created: / 2.1.1998 / 22:21:24 / cg"
!
+numTemps
+ "return the number of temporary variables of the Method.
+ Redefined since Java keeps the receiver of a non-static method
+ at local slot 1."
+
+ |n|
+
+ n := self size - super numVars - super numArgs.
+ ^ n
+
+ "Created: / 13.1.1998 / 16:52:32 / cg"
+ "Modified: / 13.1.1998 / 17:23:27 / cg"
+!
+
+numVars
+ "return the number of locals.
+ Redefined since Java keeps the receiver of a non-static method
+ at local slot 0 and holds the args as locals."
+
+ |n|
+
+ n := super numVars.
+ ^ n - self numArgs
+
+ "Created: / 13.1.1998 / 17:03:08 / cg"
+ "Modified: / 13.1.1998 / 17:25:16 / cg"
+!
+
pc
lineNr isNil ifTrue:[^ nil].
^ super lineNumber
@@ -180,6 +203,44 @@
lineNr := newPC
"Created: / 5.1.1998 / 00:09:02 / cg"
+!
+
+temporaries
+ "return an array filled with the arguments and variables of this context"
+
+ |n nSkipped|
+
+ "/ the flas-numVars includes the receiver and args
+ nSkipped := super numVars "self numArgs + self numVars".
+ "/ but my context setup is args+numvars.
+ nSkipped := super numArgs + super numVars.
+
+ n := self size - nSkipped.
+ n == 0 ifTrue:[
+ "/ little optimization here - avaoid creating empty containers
+ ^ #()
+ ].
+
+ ^ (Array new:n) replaceFrom:1 to:n with:self startingAt:nSkipped+1.
+
+ "Created: / 13.1.1998 / 15:44:12 / cg"
+ "Modified: / 13.1.1998 / 17:22:54 / cg"
+!
+
+vars
+ "return an array filled with the local variables of this context"
+
+ |nonVars mySize|
+
+ mySize := self numVars.
+ mySize == 0 ifTrue:[
+ "/ little optimization here - avaoid creating empty containers
+ ^ #()
+ ].
+ nonVars := (self arg1Index-1) + self numArgs.
+ ^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1
+
+ "Created: / 13.1.1998 / 16:48:16 / cg"
! !
!JavaContext methodsFor:'exception handler support'!
@@ -261,5 +322,5 @@
!JavaContext class methodsFor:'documentation'!
version
- ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaContext.st,v 1.19 1998/01/12 14:24:25 cg Exp $'
+ ^ '$Header: /home/jv/Projects/SmalltalkX/repositories/cvs/stx/libjava/JavaContext.st,v 1.20 1998/01/16 16:11:14 cg Exp $'
! !