This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: module-implements


On Sep 13, 2010, at 11:59 PM, Per Bothner wrote:

On 09/13/2010 11:06 AM, Jamison Hope wrote:
Hey Per, am I missing something, or does module-implements not work?
...
Regardless of where in the file I put the "(module-implements
java.awt.event.ActionListener)" line, the resultant class only ever
implements java.lang.Runnable.

Indeed. This is an issue of compiler needing some information
before it is set/calculated. A general problem whenever forward
references are allowed. It's not clear what is the "right" solution,
but I notice that on 2008-12-23 I made a change for module-extends,
and so the logical change would be to do the same for module- implements.


The attached patch should work.

Confirmed. Overriding Syntax's scanForm rather than rewriteForm seems to do it. It looks like scanForm gets called earlier in the compilation process?


Also, the documentation says that if there is a module-implements
declaration, then (module-static #f) is implied.
But if I remove the explicit "(module-static #f)" and recompile, then
actionPerformed() and action$Mnperformed are static:

That seems to be fixed with the attached patch.

Yes.


I don't see any test cases in trunk/testsuite, so I imagine
module-implements has never left the experimental stage.

No, I believe it actually working at one point, but whatever change necessitated the 2008-12-23 change for module-extends probably also broke module-implements, and it wasn't caught because of a missing test-case. I'd like to add a test-case before I check the fix in.

How about something like:


;;; impl.scm
(module-implements java.awt.event.ActionListener)

(define (action-performed (e :: java.awt.event.ActionEvent))
  (format #t "~A~%" e))

;;; impl-test.scm
(test-begin "impl")

(define (arr->list a)
  (let ((n :: int a:length))
    (let loop ((i :: int 0) (lst '()))
      (if (= i n) (reverse lst)
          (loop (+ i 1) (cons (a i) lst))))))

(define (->boolean o) (if o #t #f))

(define (implements-interface? int cls)
(->boolean (memq int (arr->list (java.lang.Class:get-interfaces cls)))))


(test #t implements-interface? java.awt.event.ActionListener <impl>)
(test #f implements-interface? java.beans.PropertyChangeListener <impl>)


Thanks, Per!


-Jamie

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]