Problem with storing types in variables

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with storing types in variables

Peter-2
Hello ;)

A quick question:

 (float[][] length: 10)

works fine, as expected, however:

 (define faa float[][])
 (faa length: 10)

does not. This used to work in earlier versions of kawa, but now I get:

java.lang.ClassCastException: don't know how to coerce gnu.math.IntNum to float[]
        at gnu.bytecode.ObjectType.coerceFromObject(ObjectType.java:182)
        at gnu.kawa.reflect.Invoke.applyToObject(Invoke.java:191)
        at gnu.kawa.functions.ApplyToArgs.applyRest(ApplyToArgs.java:157)
        at gnu.kawa.functions.ApplyToArgs.applyToConsumerA2A(ApplyToArgs.java:134)
        at gnu.mapping.CallContext.runUntilDone(CallContext.java:586)
        at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:342)
        at gnu.expr.ModuleExp.evalModule(ModuleExp.java:211)
        at kawa.Shell.run(Shell.java:283)
        at kawa.Shell.run(Shell.java:196)
        at kawa.Shell.run(Shell.java:183)
        at kawa.repl.processArgs(repl.java:714)
        at kawa.repl.main(repl.java:820)

How do I call the constructor correctly, if it is called via a variable?

Thanks for any help with this!

Greetings, Peter
Reply | Threaded
Open this post in threaded view
|

Re: Problem with storing types in variables

Per Bothner
On 7/9/19 11:57 AM, Peter wrote:

> Hello ;)
>
> A quick question:
>
>   (float[][] length: 10)
>
> works fine, as expected, however:
>
>   (define faa float[][])
>   (faa length: 10)
>
> does not. This used to work in earlier versions of kawa, but now I get:

Currently, the length keyword is only supported when the array constructor
expression is inlined (optimized at compile-time).  However, it does not
work when array construction is called in "reflexive" mode at run-time.
(This broke when Kawa's 'apply' calling convention was re-done.)

A work-around is to use define-constant or the ! operator:
    (define-constant faa float[][])
or:
    (! faa float[][])

This allows the compiler to optimize the use of faa.

I'm working on fixing this.
--
        --Per Bothner
[hidden email]   http://per.bothner.com/
Reply | Threaded
Open this post in threaded view
|

Re: Problem with storing types in variables

Per Bothner
In reply to this post by Peter-2
On 7/9/19 11:57 AM, Peter wrote:
> however:
>
>   (define faa float[][])
>   (faa length: 10)
>
> does not. This used to work in earlier versions of kawa, but now I get:
>
> java.lang.ClassCastException: don't know how to coerce gnu.math.IntNum to float[]

Should work now (in git master).
--
        --Per Bothner
[hidden email]   http://per.bothner.com/