[armedbear-devel] Question about jnew-runtime-class

archisman rudra archi.rudra at gmail.com
Fri Sep 21 14:39:28 UTC 2012


hopefully this is the correct list. If not please let me know.

I am trying to use abcl to generate jars to send off to a hadoop cluster
for execution. The svn version of the jnew-runtime-class does not store the
actual method bodies in the generated class file, but rather loads the
generated class file and sets the relevant field. Here is the relevant code

    (multiple-value-bind (class-file method-implementation-fields)
        (apply #'java::%jnew-runtime-class class-name stream args)
      (sys::put-memory-function memory-class-loader
                                class-name (sys::%get-output-stream-bytes
*      (let ((jclass (java:jcall "loadClass" memory-class-loader
*        (dolist (method method-implementation-fields)*
*          (setf (java:jfield jclass (car method)) (cdr method)))*

This means that the generated jar file cannot be easily used from standard
java code. I would like to add some code in the static initialization block
of generated class file to do something equivalent. I will have to save the
lambda expression for the method and have been experimenting as follows:

(defvar *cf*)
(defvar *mif*)

(with-open-file (stream "test.class" :direction :output :element-type
'(unsigned-byte 8))
  (multiple-value-bind (class-file method-implementation-field)
      (java::%jnew-runtime-class "test" stream :methods
`(("forty_two_method1" :int () ,(lambda (this) 42))))
    (setf *cf* class-file)
    (setf *mif* method-implementation-field)))

(with-open-file (stream "test_forms" :direction :output)
  (dolist (m *mif*)
    (system:dump-form (list (car m) (function-lambda-expression (cdr m)))

This assumes that the lambda expression does not refer to any variable or
user defined function, but perhaps the asdf-jar contrib might help here.

I was going to write the relevant code and start using it for my project,
but I was wondering if I am duplicating work that others have already done
or are doing and whether there are other libraries (jffli perhaps, I am not
very familiar with it) that have similar functionality. Also if there are
other interactions with other parts of the system that I am perhaps missing.

I would e grateful for any advice.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20120921/d2845e45/attachment.html>

More information about the armedbear-devel mailing list