JavaContext.st
changeset 2678 c865275e48a7
parent 2396 fadc6d7a2f5b
child 2731 13f5be2bf83b
--- a/JavaContext.st	Fri Aug 16 19:52:36 2013 +0200
+++ b/JavaContext.st	Fri Sep 06 02:45:44 2013 +0200
@@ -20,7 +20,7 @@
 "
 "{ Package: 'stx:libjava' }"
 
-Context subclass:#JavaContext
+Context variableSubclass:#JavaContext
 	instanceVariableNames:'exArg exPC byteCode constPool acqrMonitors'
 	classVariableNames:''
 	poolDictionaries:''
@@ -60,6 +60,13 @@
 "
 ! !
 
+!JavaContext class methodsFor:'accessing'!
+
+finallyTokenClass
+    ^FinallyToken
+
+    "Created: / 18-04-2013 / 23:46:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
 !JavaContext methodsFor:'* As yet uncategorized *'!
 
@@ -96,7 +103,6 @@
     "Created: / 10-04-2012 / 11:09:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-
 !JavaContext methodsFor:'ST context mimicri'!
 
 arg1Index
@@ -323,7 +329,6 @@
     "Created: / 13.1.1998 / 16:48:16 / cg"
 ! !
 
-
 !JavaContext methodsFor:'accessing'!
 
 acquiredMonitors
@@ -353,6 +358,54 @@
     "Modified: / 17-11-2011 / 19:13:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 !
 
+methodFromClass
+    "Return the up-to-date method. Actyally, it fetches the method
+     from receiver's class"
+
+    |c sender sendersSelector m|
+
+    "mhmh - maybe I am a context for an unbound method (as generated by doIt);
+     look in the sender's context. Consider this a kludge.
+     Future versions of ST/X's message lookup may store the method in
+     the context.
+    "
+    sender := self sender.
+    sender notNil ifTrue:[
+        sendersSelector := sender selector.
+        sendersSelector notNil ifTrue:[
+            (sendersSelector startsWith:'valueWithReceiver:') ifTrue:[
+                m := sender receiver.
+                m isMethod ifTrue:[
+                    method := m.
+                    ^ m
+                ]
+            ]
+        ]
+    ].
+
+    c := self searchClass.
+    "
+     the below cannot happen in normal circumstances
+     (added to avoid recursive errors in case of a broken sender chain)
+    "
+    c isBehavior ifFalse:[
+        'Context [error]: non class in searchClass' errorPrintCR.
+        '      selector: ' errorPrint. selector errorPrint.
+        ' receiver: ' errorPrint. receiver errorPrintCR.
+        ^ nil
+    ].
+
+    c := c whichClassIncludesSelector:selector.
+    c notNil ifTrue:[
+        method := c compiledMethodAt:selector.
+        ^ method
+    ].
+
+    ^ nil
+
+    "Created: / 09-08-2013 / 02:25:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 programmingLanguage
 
     ^JavaLanguage instance
@@ -390,7 +443,6 @@
     "Modified: / 17-11-2011 / 19:14:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
 ! !
 
-
 !JavaContext methodsFor:'exception handler support'!
 
 exceptionArg:aJavaException
@@ -406,8 +458,34 @@
     "Created: / 7.1.1998 / 21:36:56 / cg"
 ! !
 
+!JavaContext methodsFor:'non local control flow'!
 
-!JavaContext methodsFor:'non local control flow'!
+restart
+    "Update the bytecode before restarting so
+     bytecode interpreter can execute new code, if any"
+
+    | m |
+
+    m := self methodFromClass.
+    m notNil ifTrue:[
+         byteCode := m byteCode.
+         constPool := m constantPool.
+    ].
+    ^super restart.
+
+    "Created: / 19-04-2013 / 13:33:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 09-08-2013 / 02:33:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+return
+    selector last == $V ifTrue:[ ^ self return:nil  ].
+    selector last == $; ifTrue:[ ^ self return:nil  ].
+    selector last == $D ifTrue:[ ^ self return:0.0  ].
+    selector last == $F ifTrue:[ ^ self return:0.0 asShortFloat  ].
+    ^self return: 0
+
+    "Created: / 18-04-2013 / 23:52:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
 unwindAndRestartForJavaException
 
@@ -451,7 +529,6 @@
     "Created: / 08-11-2011 / 22:00:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-
 !JavaContext methodsFor:'printing & storing'!
 
 receiverPrintString
@@ -510,7 +587,6 @@
     ^ newString
 ! !
 
-
 !JavaContext methodsFor:'queries'!
 
 hasStackToShow
@@ -540,7 +616,6 @@
     "Created: / 7.5.1998 / 01:26:19 / cg"
 ! !
 
-
 !JavaContext::FinallyToken methodsFor:'accessing'!
 
 context
@@ -575,7 +650,6 @@
     value := something.
 ! !
 
-
 !JavaContext::FinallyToken methodsFor:'actions'!
 
 pass
@@ -595,15 +669,14 @@
     "Created: / 04-04-2012 / 20:24:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-
 !JavaContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libjava/JavaContext.st,v 1.40 2013-02-25 11:15:31 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libjava/JavaContext.st,v 1.42 2013-09-06 00:41:22 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libjava/JavaContext.st,v 1.40 2013-02-25 11:15:31 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libjava/JavaContext.st,v 1.42 2013-09-06 00:41:22 vrany Exp $'
 !
 
 version_HG