This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


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

Re: libgcj and GNU Classpath


Tom Tromey <tromey@cygnus.com> writes:

> One idea that's being discussed is to find some way to write the code
> once and then do the translation to JNI or CNI at compile time.
> Nothing concrete has been done here yet.  It might not even be
> possible to do, for all I know.

Oh, I'm sure it is possible.

As the most primitive approach, you can do:
        #ifdef CNI
          ...
        #else
          ...
        #endif

Of course we want to avoid too much duplication.
For example, in a header file we can define:
#ifdef CNI
#define JNIENV jenv /* must be declared in function header */
#define JvThrow(obj) _Jv_Throw(obj)
#else
#define JvThrow(cl, obj) JNIENV()->Thow(obj)
#endif

You can then write JnThrow(ex) and it will work for both JNI and CNI.

Accessing fields and methods in a convenient way may require
some more magic.  I have some ideas.  One plausible solution
is to use a pre-processor, that can convert code written in a
more abstract format, to emit eithr JNI or CNI code.

Of course being able to have one source file which can be selectively
compiled to either JNI or CNI is useful not only for standard Java
classes, but can also be useful for "users".

The ultimate in convenience is to be able to take a JNI file
and "optimize" it to CNI.  This might be easiest and best done
in the C++ compiler.  It might be easier now that G++ can
represent entire functions as trees.
-- 
	--Per Bothner
per@bothner.com   http://www.bothner.com/~per/

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