swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC + Java


From: Marcus G. Daniels
Subject: Re: ObjC + Java
Date: 06 May 2001 14:57:48 -0600
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.7

>>>>> "PT" == Pietro Terna <address@hidden> writes:

PT>          1. Where can I find java-stub.el program?

It's in the Swarm source distribution in the java/ subdirectory.

PT>          2. How can I run it, in Linux or in W32 (may be, using
PT> Emacs as Lisp environment?).

Emacs lisp programs can be run like this:

   $ emacs -batch -l some-file.el -f some-function

Where some-file.el defines some-function. 

[That's just like running a Perl or Awk script.  It's as fast to
start because Emacs is `dumped' into a single binary and all of its
features are precompiled.  Using Emacs for processing Objective C
headers was natural because Emacs knows quite a bit about the
structure of C programs.  It has a notion of what an `expression' is,
can match braces, etc.  These things are harder to do in Perl and
other common scripting languages because they are usually line-
oriented.  In Emacs, you can move around a file at random, just as in
the editor.]

Anyway, to get started, you'd need a build of Swarm.  I'm assuming use
of bash as a shell on a GNU/Linux system.  The use of /src and /build
aren't crucial or hardwired anywhere, it's just my convention.

   $ cd /src
   $ tar zxf ~/swarm-2001-05-01.tar.gz
   $ export SWARMSRCDIR=/src/swarm-2001-05-01
   $ mkdir -p /build/swarm-jdk
   $ cd /build/swarm-jdk
   $ JAVAC=jikes $SWARMSRCDIR/configure --srcdir=$SWARMSRCDIR 
--with-jdkdir=/opt/jdk1.3
   $ make

To generate the Java stuff for Swarm under Sun JDK, the specific
commands that get run are like below.  Note that the build actually does
this for you -- this is just to clarify the context and command for the 
stubbing run itself:
 
   $ cd /build/swarm-jdk/java
   $ export TOP_BUILDDIR=/build/swarm-jdk
   $ export BUILDDIR=/build/swarm-jdk/java
   $ emacs -batch -l java-stub.elc -f java-run-all-unicode

In a c/ subdirectory what you end up with are a bunch of files with C
functions that follow the JNI naming conventions.  Inside each
function is code that explicitly issues Objective C methods via the
Objective C C API.  You also get a bunch of Java files in a swarm/
subdirectory that declare all the Java interfaces, naming all the
methods as `native'.

The environment variables above are so that the java-stub program can
locate other compiled elisp that it depends on, namely protocol.elc
and common.elc.  The location of the source code of Swarm is also
needed so that the protocol files can be found.

Note that it says "elc" not "el".  That's because the process of reading
all the protocol files, processing them, and generating stubs is compute
intensive enough that it is desirable to compile the elisp before running it.
The Makefiles that Swarm has now in the java/ subdirectory handle that
compilation, but you can do it by hand, too.  (Or just be patient.)

One thing that is needed is an alternative way to locate protocol
files.  Right now, this comes from SWARMSRCDIR environment variable and a
list of modules in etc/common.el.  The code that actually loads a file
for processing would need to be adapted to look elsewhere.  See the
function load-all-modules in etc/protocol.el for those mechanics. 
    
Besides that I think all that should be needed is a nicer way to
invoke the elisp code without specifying environment variables, say, some kind
of a wrapper script.  Another issue is getting the build to work without
depending on the Swarm _build_ Makefiles, since those files won't be available
for users.  There is probably enough information in the installed 
$SWARMHOME/etc/Makefile.common, and $SWARMHOME/etc/Makefile.rules, but
some details might need changing or extending.

What would be nice to have is a program that would be installed as a
part of every Swarm system that let the user have a Makefile target
like this:

libmypackage.so mypackage.jar: mypackage.h
        javastub mypackage.h

or:

mypackage.dll mypackage.jar: mypackage.h
        javastubdll mypackage.h

`xpcomstub' or `xpcomstubdll' scripts would be natural generalizations for
making components that would plug-in to the C++/JavaScript/Python Mozilla
environment.

To emphasize: all of the hairy stuff is in place to have this
work, it's just a matter of getting the Makefiles, command-line
processing, and wrapper scripts in place.  I could do it in a few
days, but I don't have time or incentive to do it.  If someone wanted
to raise a few thousand dollars, the SDG could find a hacker
to do the work (or I could do it given sufficient scheduling latitude).



Elisp documentation is available here:
 
  http://www.gnu.org/manual/elisp-manual-20-2.5/html_chapter/elisp_toc.html

And as much more up-to-date TeXinfo here:

  ftp://ftp.gnu.org/pub/gnu/emacs/elisp-manual-21-2.6.tar.gz


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]