(let [x (float -199)]
    (.draw batch ^TextureRegion @hud-corner-top-left
           x
           (float -32)))

That's an interop call to libgdx. That generated the disassembly I pasted 
before.

On Wednesday, February 24, 2016 at 5:05:30 AM UTC-7, Nicola Mometto wrote:
>
>
> > On 24 Feb 2016, at 11:58, Michael du Breuil <wicked.she...@gmail.com 
> <javascript:>> wrote: 
> > 
> > That just performs a runtime cast to a variable then reference the 
> variable later, which is even worse. 
> > 
> > float x = RT.uncheckedFloatCast(-199L);((SpriteBatch)batch) 
> >       
> .draw((TextureRegion)((IFn)const__5.getRawRoot()).invoke(const__42.getRawRoot()),
>  
> x, 
> > 
> >       RT.uncheckedFloatCast(-32L)); 
> > 
>
>
> No it doesn't. 
>
> having 
>
> (ns test) 
>
> (definterface Foo 
>   (x [^float y])) 
>
> (let [a (float 1)] 
>   (defn y [b] 
>     (.x ^Foo b a))) 
>
> This is the disassemble of y's invoke method: 
>
>   public java.lang.Object invoke(java.lang.Object); 
>     Code: 
>          0: aload_1 
>          1: aconst_null 
>          2: astore_1 
>          3: checkcast     #18                 // class test/Foo 
>          6: aload_0 
>          7: getfield      #14                 // Field a:F 
>         10: invokeinterface #22,  2           // InterfaceMethod 
> test/Foo.x:(F)Ljava/lang/Object; 
>         15: areturn 
>
> No float cast involved there. The primitive float is closed over and used 
> directly. 
>
> > I definitely expected the compiler to pay attention to it, although I 
> also discovered at the same time that the compilier doesn't actually 
> resolve expressions like (+ (* 2 4) 1) to just be 9 at compile time either, 
> even though all the values were constants. Both of these are a problem 
> because they are inside the hot loop of the program. (There are some 
> constant math expressions that are only expressions as it is easier to 
> read/change ^:const named things then to just put one resultant number. 
> > 
> > Is it worth opening a Jira issue for resolving either or both of these 
> at compile time? I looked a briefly at the definition for (float ) but I'm 
> not at all familiar with how the byte code is generated and how to actually 
> replace that with what I'm looking for. 
>
> Sure, although I don't think doing this kind of constant folding this is 
> going to be a priority. 
>
> > 
> > On Wednesday, February 24, 2016 at 3:58:46 AM UTC-7, Nicola Mometto 
> wrote: 
> > Those are runtime casts, this is the expected behaviour (although one 
> could argue that clojure should be able to optimize them away at compile 
> time). 
> > 
> > If you want to avoid the runtime casting, you can do something like 
> this: 
> > 
> > (let [x (float 123)] 
> >   (defn y [..] 
> >     (.foo bar x))) 
> > 
> > 
> > > On 24 Feb 2016, at 10:53, Michael du Breuil <wicked.she...@gmail.com> 
> wrote: 
> > > 
> > > The following (this is interop with libgdx if anyone is curious, 
> hud-corner-top-left is a delayed TextureRegion 
> > > 
> > > (.draw batch ^TextureRegion @hud-corner-top-left 
> > >            (float -199) 
> > >            (float -32)) 
> > > 
> > > Which yields the following: 
> > >       
> .draw((TextureRegion)((IFn)const__5.getRawRoot()).invoke(const__41.getRawRoot()),
>  
>
> > >       RT.uncheckedFloatCast(-199L), 
> > >       RT.uncheckedFloatCast(-32L));null;((SpriteBatch)batch) 
> > > 
> > > Unless I'm missing something on how to interpret bytecode :) I can 
> post more source if you want but that is one interop call and its generated 
> code, the rest will look the same. 
> > > 
> > > On Wednesday, February 24, 2016 at 3:44:11 AM UTC-7, Nicola Mometto 
> wrote: 
> > > Can you post the code? 
> > > 
> > > > On 24 Feb 2016, at 10:26, Michael du Breuil <wicked.she...@gmail.com> 
> wrote: 
> > > > 
> > > > I have some interop code that I have carefully specified all the 
> arguments to be in the correct type (IE the function signature takes 3 
> floats, so I cast everything to float so that I can avoid reflection). What 
> I'm surprised by is compile time constants such as (float -173) or (float 
> 8.5) are not saved as the correct primitive type, using jd-gui I see that 
> these were actually turned into RT.uncheckedFloatCast(-173L), and 
> RT.uncheckedFloatCast(8.5D), respectively. Why isn't this just saved as a 
> the correct primitive directly in the generated bytecode? This is with 
> clojure 1.8.0 
> > > > 
> > > > -- 
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "Clojure" group. 
> > > > To post to this group, send email to clo...@googlegroups.com 
> > > > Note that posts from new members are moderated - please be patient 
> with your first post. 
> > > > To unsubscribe from this group, send email to 
> > > > clojure+u...@googlegroups.com 
> > > > For more options, visit this group at 
> > > > http://groups.google.com/group/clojure?hl=en 
> > > > --- 
> > > > You received this message because you are subscribed to the Google 
> Groups "Clojure" group. 
> > > > To unsubscribe from this group and stop receiving emails from it, 
> send an email to clojure+u...@googlegroups.com. 
> > > > For more options, visit https://groups.google.com/d/optout. 
> > > 
> > > 
> > > -- 
> > > You received this message because you are subscribed to the Google 
> > > Groups "Clojure" group. 
> > > To post to this group, send email to clo...@googlegroups.com 
> > > Note that posts from new members are moderated - please be patient 
> with your first post. 
> > > To unsubscribe from this group, send email to 
> > > clojure+u...@googlegroups.com 
> > > For more options, visit this group at 
> > > http://groups.google.com/group/clojure?hl=en 
> > > --- 
> > > You received this message because you are subscribed to the Google 
> Groups "Clojure" group. 
> > > To unsubscribe from this group and stop receiving emails from it, send 
> an email to clojure+u...@googlegroups.com. 
> > > For more options, visit https://groups.google.com/d/optout. 
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Clojure" group. 
> > To post to this group, send email to clo...@googlegroups.com 
> <javascript:> 
> > Note that posts from new members are moderated - please be patient with 
> your first post. 
> > To unsubscribe from this group, send email to 
> > clojure+u...@googlegroups.com <javascript:> 
> > For more options, visit this group at 
> > http://groups.google.com/group/clojure?hl=en 
> > --- 
> > You received this message because you are subscribed to the Google 
> Groups "Clojure" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to clojure+u...@googlegroups.com <javascript:>. 
> > For more options, visit https://groups.google.com/d/optout. 
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to