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: blog entry - Kawa in Computer Languages "shootout"


On Oct 22, 2010, at 12:00 AM, Per Bothner wrote:

On 10/20/2010 03:01 PM, Jamison Hope wrote:
Here's a chameneos-redux implementation.

I also updated the "shootout" blog entry:
http://per.bothner.com/blog/2010/Kawa-in-shootout/


I'm working on meteor-contest, but I'm getting compilation errors. I've whittled it down to the following, which works fine from the REPL. The problem seems to be when one class has, as a field, an array of elements of another class defined in the same module.

$ cat meteor.scm
(define-simple-class P ())

(define-simple-class S ()
  (pieces :: P[] init: (P[] length: 10))

  ((clone2) :: S
   (let ((s :: S (S)))
     (do ((i :: int 0 (+ i 1)))
         ((= i pieces:length))
       (set! (s:pieces i) #!null)) ;;<- NPE here
     s)))

Interactively:


$ rlwrap java kawa.repl
#|kawa:1|# (load "meteor.scm")
#|kawa:2|# ((S):clone2)
S@7546c1d4


but when I try to compile:

$ java kawa.repl --main -C meteor.scm
(compiling meteor.scm to meteor)
meteor.scm:10:8: caught exception in inline-compiler for #<procedure field> - java.lang.NullPointerException
gnu.bytecode.ArrayType.getReflectClass(ArrayType.java:69)
gnu.kawa.reflect.SlotGet.compile(SlotGet.java:291)
gnu.expr.ApplyExp.inlineCompile(ApplyExp.java:587)
gnu.expr.ApplyExp.compile(ApplyExp.java:174)
gnu.expr.ApplyExp.compile(ApplyExp.java:111)
gnu.expr.Expression.compile(Expression.java:166)
gnu.kawa.reflect.CompileArrays.compileArraySet(CompileArrays.java:74)
gnu.kawa.reflect.CompileArrays.compile(CompileArrays.java:49)
gnu.expr.ApplyExp.inlineCompile(ApplyExp.java:587)
gnu.expr.ApplyExp.compile(ApplyExp.java:174)
gnu.expr.ApplyExp.compile(ApplyExp.java:111)
<snip>

The compiler seems to be unaware of the type of the elements of s:pieces (which should be P). The exception is from elClass.getClassLoader(), where elClass is elements.getReflectClass().

As further evidence of this being the problem, the following compiles but fails at runtime:

$ cat test.scm
(define-simple-class A ())

(define-simple-class B ()
  (a :: A[] init: (A[] length: 2)))

(define b :: B (B))

$ java kawa.repl --main -C test.scm
(compiling test.scm to test)

$ java test
Exception in thread "main" java.lang.ClassFormatError: Field "a" in class B has illegal signature "[null"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java: 141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at test.<clinit>(test.scm)


By the way, thank you for the changes in r6772. I don't remember if I had requested that, but I know I had thought of it as a "wouldn't it be nice if…" as I started to look through some of the classes I have without no-argument constructors.

-Jamie

--
Jamison Hope
The PTR Group
www.theptrgroup.com




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