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: Some other oddities


Sean Luke wrote:
Thanks for stomping the class bug; turnaround time isn't crucial, as I've got a hack that gets around it for now. And I'm SHOCKED at the speed Kawa's running my examples when you load it down with type declarations. About 1.5 the speed of full, reasonably optimized Java.
> Really amazing!

50% faster than "full, reasonably optimized Java" is quite impressive
...

Please tell your friends, co-workers, stranger on the street of you like
Kawa!  I'm really bad at marketing, alas.

0. The syntax for making multidimensional arrays is lacking. To do this in Java:

    public static final int[][] b_heptomino = new int[][]
        {{0, 1, 1},
         {1, 1, 0},
     {0, 1, 1},
     {0, 0, 1}};

The best I've been able to manage is:

    (b-heptomino type: <int[][]>
        allocation: 'static
        init-form: (make <int[][]>
                    (make <int[]> 0 1 1)
                    (make <int[]> 1 1 0)
                    (make <int[]> 0 1 1)
                    (make <int[]> 0 0 1)))

If you use the latest (CVS) Kawa you can leave out the 'make'. So it's a little less verbose.

Avoiding the "redundant" <int[]> names is harder, since all of these are
expressions, not special syntax.  (In Java '{ ... }' is special syntax.)
Coming up with appropriate syntax that works for expressions (and not
just literals) is not obvious.  We could steal an idea from APL and
use a re-shape operator.  But this doesn't seem like high priority.
You can always write a macro.

1. The documentation says that to access fields defined in Scheme in a simple-class, you have to use (slot-ref foo 'bar), but for standard Java classes you can use (#:.bar foo).

Where does it say that? If you're look at the 2d-vector example, you're misunderstanding it. The point is specifically about the *lexical visibility* of the plain unadorned field name bar.

And in any case that has been fixed in CVS.

2. Load order for mutually-referential simple-classes seems to be broken, or at least inconsistent in an undocumented way.

The problem is the semantics of "load". It is defined to read and evaluate the expressions in order, which means limited support for forward references.

If you *compile* a module that define two mutually references classes,
I believe that should work.

In CVS, you can also have two mutually referential modules.

I have a class called <tutorial1> which has a method that looks like this:

    (define-simple-class <tutorial1> (<sim.engine.SimState>)
        ((start) :: <void>
            ..........
            (make <ca>) ....

I have another class called <ca> which has a method which like this:

    (define-simple-class <ca> (<sim.engine.Steppable>)
        ((step (state :: <sim.engine.SimState>)) :: <void>
            ..........
            (let ((tut :: <tutorial1> (as <tutorial1> state))) ....

As can be seen, they each refer to the other. If you load <tutorial1> before <ca> you get a warning:

(load "tutorial1.scm")
(load "ca.scm")
tutorial1.scm:40:13: warning - unknown class: ca


... and it works fine.

Yes - it just call (make <ca>) without optimizing it.


But if you load ca first before loading
tutorial1, kawa spits out a large Java error indicating that tutorial1 doesn't exist yet! Specifically:

(load "ca.scm")
ca.scm:13:36: unknown class: tutorial1
java.lang.RuntimeException: no such class: tutorial1
at gnu.bytecode.ObjectType.getReflectClass(ObjectType.java:77)
at gnu.bytecode.ClassType.addFields(ClassType.java:402)
at gnu.bytecode.ClassType.getFields(ClassType.java:306)
at gnu.bytecode.ClassType.getDeclaredField(ClassType.java:320)
........
Caused by: java.lang.ClassNotFoundException: tutorial1
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
........


What's failing, and why? Is it the tut :: <tutorial1> that requires tutorial1 exist?

I believe so. Kawa really wants to resolve a type in that context to a known class. It perhaps should be more lenient, but note does mean figuring what type to cast to at run-time, which is not going to be fast.

There are also class-loader issues.  If you so define-simple-class
in the interpreter, the class cannot be loaded by the system
classloader.

> or is it the case (which, btw, appears to be NECESSARY
if I want to call a function on the tutorial1 method that doesn't exist in its superclass -- very un-scheme-like :-( )

Not sure what if anything you're asking for here. -- --Per Bothner per@bothner.com http://per.bothner.com/


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