--- a/JavaLookup.st Fri Oct 04 12:49:16 2013 +0100
+++ b/JavaLookup.st Fri Oct 04 17:02:03 2013 +0100
@@ -309,32 +309,78 @@
lookupMethodForSelector: selector directedTo: initialSearchClass for: receiver withArguments: argArrayOrNil from: sendingContext ilc: ilc
"
As a courtesy to a Smalltalker, try to map smalltalk selectors to a java ones.
- Returns JavaMethodDescriptor or nil."
+ Returns a method or nil"
- | name nameSizePlusOne candidates finder static cls m |
+ | name nameSizePlusOne candidates finder static cls m ifacesQ ifacesSeen |
+
+ "/ First, lookup possible extension methods in interfaces...
+ (initialSearchClass isMetaclass not and:[initialSearchClass interfaces notEmptyOrNil ] ) ifTrue:[
+ ifacesQ := OrderedCollection with: (initialSearchClass interfaces).
+ ifacesSeen := Set new.
+ [ ifacesQ notEmpty ] whileTrue:[
+ | ifaces newIfaces extension |
+
+ ifaces := ifacesQ removeFirst.
+ extension := nil.
+ ifaces do:[:iface |
+ (ifacesSeen includes: iface) ifFalse:[
+ | m |
+
+ ifacesSeen add: iface.
+ m := iface compiledMethodAt: selector.
+ m notNil ifTrue:[
+ extension notNil ifTrue:[
+ "/ Ambiguous, return error trampoline
+ | sel |
+
+ sel :=
+ #( ambiguousMessageSend
+ ambiguousMessageSendWith:
+ ambiguousMessageSendWith:With:
+ ambiguousMessageSendWith:With:With:
+ ambiguousMessageSendWith:With:With:With:
+ ambiguousMessageSendWith:With:With:With:With:
+ ambiguousMessageSendWith:With:With:With:With:With:
+ ambiguousMessageSendWith:With:With:With:With:With:With:
+ ambiguousMessageSendWith:With:With:With:With:With:With:With:
+ ) at: selector numArgs + 1.
+ ^ self class compiledMethodAt: sel.
+ ] ifFalse:[
+ extension := m.
+ ].
+ ].
+ ].
+ ].
+ extension notNil ifTrue:[ ^ extension ].
+ newIfaces := Set new.
+ ifaces do:[:iface| newIfaces addAll: iface interfaces ].
+ newIfaces notEmpty ifTrue:[
+ ifacesQ add: newIfaces.
+ ].
+ ].
+ ].
+
+
name := selector upTo: $:.
nameSizePlusOne := name size + 1.
static := receiver isBehavior.
candidates := OrderedCollection new.
- finder := [
- :cls |
- cls methodDictionary
- keysAndValuesDo: [
- :sel :mthd |
- "candidates may contain a method with same selector ->
- do not add super-class's method"
- (candidates contains: [:each | each selector == sel ]) ifFalse: [
- (mthd mclass ~~ ProxyMethod
- and: [
- ((sel size >= nameSizePlusOne)
- and: [ (sel at: nameSizePlusOne) == $( and: [ (sel startsWith: name) ] ])
- and: [ mthd descriptor numArgs == argArrayOrNil size ]
- ])
- ifTrue: [ candidates add: mthd ]
- ]
+ finder := [:cls |
+ cls methodDictionary keysAndValuesDo: [:sel :mthd |
+ "candidates may contain a method with same selector ->
+ do not add super-class's method"
+ (candidates contains: [:each | each selector == sel ]) ifFalse: [
+ (mthd mclass ~~ ProxyMethod
+ and: [
+ ((sel size >= nameSizePlusOne)
+ and: [ (sel at: nameSizePlusOne) == $( and: [ (sel startsWith: name) ] ])
+ and: [ mthd descriptor numArgs == argArrayOrNil size ]
+ ])
+ ifTrue: [ candidates add: mthd ]
]
+ ]
].
- "Search class for method candidates"
+ "Search class for method candidates"
cls := initialSearchClass theNonMetaclass.
static ifTrue: [ finder value: cls ] ifFalse: [
[ cls notNil and: [ cls ~~ JavaObject ] ] whileTrue: [
@@ -403,9 +449,9 @@
"Created: / 19-11-2011 / 13:03:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 01-01-2012 / 19:58:59 / kursjan <kursjan@fit.cvut.cz>"
"Modified (comment): / 02-01-2012 / 10:35:25 / kursjan <kursjan@fit.cvut.cz>"
- "Modified: / 17-03-2012 / 17:22:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 18-11-2012 / 18:17:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 16-12-2012 / 13:59:55 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+ "Modified: / 04-10-2013 / 15:44:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLookup::Smalltalk2Java methodsFor:'lookup (old)'!
@@ -550,6 +596,115 @@
"Created: / 06-09-2011 / 22:20:34 / Jan Kurs <kursjan@fit.cvut.cz>"
! !
+!JavaLookup::Smalltalk2Java methodsFor:'trampolines'!
+
+ambiguousMessageSend
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: #()
+ )
+
+ "Created: / 19-08-2010 / 22:05:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1)
+ )
+
+ "Created: / 19-08-2010 / 22:06:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1 with: a2
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1 with: a2)
+ )
+
+ "Created: / 19-08-2010 / 22:06:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1 with: a2 with: a3
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1 with: a2 with: a3)
+ )
+
+ "Created: / 19-08-2010 / 22:06:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1 with: a2 with: a3 with: a4)
+ )
+
+ "Created: / 19-08-2010 / 22:06:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
+ with: a5
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5)
+ )
+
+ "Created: / 19-08-2010 / 22:07:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6)
+ )
+
+ "Created: / 19-08-2010 / 22:07:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6 with: a7
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6 with: a7)
+ )
+
+ "Created: / 19-08-2010 / 22:07:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+ambiguousMessageSendWith: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6 with: a7 with: a8
+
+ ^self ambiguousMessage:
+ (Message
+ selector: thisContext selector
+ arguments: (Array with: a1 with: a2 with: a3 with: a4
+ with: a5 with: a6 with: a7 with: a8)
+ )
+
+ "Created: / 19-08-2010 / 22:08:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!JavaLookup::Smalltalk2Java methodsFor:'utilities'!
addSelector:selector withMethod:proxy toClass:class