[armedbear-devel] JFLI added to ABCL-CONTRIB

Anton Vodonosov avodonosov at yandex.ru
Tue May 29 08:37:56 UTC 2012


29.05.2012, 11:30, "Mark Evenson" <evenson at panix.com>:
> [1]: http://trac.common-lisp.net/armedbear/changeset/13949
>

The changeset misses jfli.lisp, only jfii.asd.

>
> 2)  We should figure out which parts of [Anton's extensions][2] we
> should include, especially wrt to the need for 'asm.jar' for creating
> synthetic Java classes at runtime.
>
> [2]:
> https://gist.github.com/avodonosov/abcl-idea/blob/master/src/abclidea/lisp/jfli-abcl/jfli-abcl.lisp

I did only one fix (it is included in the jfli contrib, but without comment).

The change is in the function get-ref. 

To explain it's meaning we should first say that jfli, 
when working with native java objects, wraps the java object
into a lisp wrapper. 

The function get-ref returns the object referenced by
the lisp wrapper, i.e. the native java object (and if the argument is already
a native java object, as determined by the ABCL function java:java-object-p,
it returns the argument). This was the original version. 

In the original form, the function get-ref signaled an error
if we pass something that is not a jfli wrapper or native java object.
For example (get-ref (lambda () "hello")) signaled an error.

I've added an otherwise clause so that (get-ref (lambda () "hello")) returns
the lambda - in case of ABCL, object of lisp world are anyway java objects - 
it is possible for JVM to assign the value of (lambda () "hello") to any field
of type java.lang.Object.

I needed this change because I wanted to create java class 
   MY.MyAction extends com.intellij.openapi.actionSystem.AnAction,
which holds reference to a lisp function in a field named "func" 
of type java.land.Object.

This allowed me to create actions for Intellij IDEA as instances
of this class, and easily set different lisp functions as handlers for
different actions.

This usage is here, starting at line 211,
https://gist.github.com/avodonosov/abcl-idea/blob/fd017ed722bbdd66d40095a9494f25e9a0230427/src/abclidea/lisp/yanking.lisp

In particular:
(setf act-yank (myaction.new "yank" nil))
(setf (myaction.func act-yank)
      #'(lambda (action-event) 
          ...))

In the second setf, when we assign the value to the myaction.func
field, the jfli generated setter calls get-ref on the #(lambda (action-event) ...)
argument and stores the returned value in the "func" field of the action object.

That's the explanation why I changed it. Now the question, should this change
be included into ABCL version of jfli? I.e. should get-ref function just return it's
argument in otherwise clause?

I think yes.(probably adding a comment to the otherwise clause will be good).

Best regards,
- Anton




More information about the armedbear-devel mailing list