This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Strange error message
- From: Per Bothner <per at bothner dot com>
- To: Yaroslav Kavenchuk <kavenchuk at gmail dot com>
- Cc: kawa at sourceware dot org
- Date: Tue, 27 Oct 2009 13:52:52 -0700
- Subject: Re: Strange error message
- References: <4AE5B9BB.80006@gmail.com>
On 10/26/2009 08:01 AM, Yaroslav Kavenchuk wrote:
When I add wrong `toString` method to example from
http://www.gnu.org/software/kawa/Defining-new-classes.html :
This one is tricky. The problem is that plusp is undefined,
which means the compiler creates a dynamic variable, which
means the class needs a static link.
The compiler tries to emit a warning:
/tmp/ex.scm:4:1: warning - simple class requiring lexical link - use
define-class instead
However, the compiler crashes in code-generation before the
warning is printed (though after it is generated). Changing
the warning to an error would avoid the problem, but some
programs would no longer compile. They would need to be
changed to use define-class rather than define-simple-class:
(define-class <2d-vector> () interface: #f
...)
There is a related problem if you try to access a non-static
module-level function or variable:
(define yy 12)
(define (incr) (set! yy (+ yy 1)))
(define-simple-class Twodvector ()
(y type: <double>)
((*init* (x0 :: <double>) (y0 :: <double>))
(set! y y0))
((*init* (xy0 :: <double>))
(invoke-special Twodvector (this) '*init* xy0 xy0))
((xxtoString)
yy))
/tmp/ex.scm:6: internal error while compiling /tmp/ex.scm
java.lang.Error: attempting to push dead variable
Exactly what's going on is puzzling ....
$ cat ex.scm
(define-simple-class <2d-vector> ()
(x type: <double> init-keyword: x:)
(y type: <double> init-keyword: y:)
(zero-2d :: <2d-vector> allocation: 'static
init-value: (make <2d-vector> 0))
;; An object initializer (constructor) method.
((*init* (x0 :: <double>) (y0 :: <double>))
(set! x x0)
(set! y y0))
((*init* (xy0 :: <double>))
;; Call above 2-argument constructor.
(invoke-special <2d-vector> (this) '*init* xy0 xy0))
;; Need a default constructor as well, for the (make ..) below.
((*init*) #!void)
((add (other :: <2d-vector>)) :: <2d-vector>
;; Kawa compiles this using primitive Java types!
(make <2d-vector>
x: (+ x (slot-ref other 'x))
y: (+ y (slot-ref other 'y))))
((scale (factor :: <double>)) :: <2d-vector>
(make <2d-vector> x: (* factor x) y: (* factor y)))
((toString) :: java.lang.String
(let ((sbuf :: java.lang.StringBuffer
(make java.lang.StringBuffer "2d-vector: ")))
(when (plusp x)
(sbuf:append (java.lang.Double:toString x))
(sbuf:append " ")
(sbuf:append (java.lang.Double:toString y)))
(*:toString sbuf)))
)
I get strange error message:
$ kawa -C ex.scm
(compiling ex.scm to ex)
ex.scm:10: internal error while compiling ex.scm
java.lang.Error: passing Uninitialized<$N2d$Mnvector> as parameter
at gnu.bytecode.CodeAttr.emitInvokeMethod(CodeAttr.java:1471)
at gnu.bytecode.CodeAttr.emitInvokeVirtual(CodeAttr.java:1515)
at gnu.expr.ApplyExp.compile(ApplyExp.java:392)
at gnu.expr.ApplyExp.compile(ApplyExp.java:110)
at gnu.expr.Expression.compileWithPosition(Expression.java:133)
at gnu.expr.ClassExp.compileMembers(ClassExp.java:522)
at gnu.expr.ClassInitializer.<init>(ClassInitializer.java:16)
at gnu.expr.ClassExp.compileSetField(ClassExp.java:779)
at gnu.expr.SetExp.compile(SetExp.java:172)
at gnu.expr.Expression.compileNotePosition(Expression.java:159)
at gnu.expr.Expression.compileWithPosition(Expression.java:145)
at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1617)
at gnu.expr.Compilation.generateBytecode(Compilation.java:2017)
at gnu.expr.Compilation.process(Compilation.java:1893)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:307)
at gnu.expr.ModuleInfo.loadByStages(ModuleInfo.java:292)
at kawa.repl.compileFiles(repl.java:718)
at kawa.repl.processArgs(repl.java:408)
at kawa.repl.main(repl.java:762)
--
--Per Bothner
per@bothner.com http://per.bothner.com/