[gambit-list] What's going on with this expansion?

Marc Feeley feeley at iro.umontreal.ca
Wed Nov 16 15:52:56 EST 2011


On 2011-11-16, at 2:54 PM, Bradley Lucier wrote:

> Marc:
> 
> Here's the contents of a file:
> 
> (declare (standard-bindings)
> 	 (extended-bindings)
> 	 (block))
> 
> (declare (not inline))
> 
> (define (safe-fixnum-+ x y)
>  (declare (fixnum))
>  (+ x y))
> 
> Here's the expansion:
> 
> [Bradley-Luciers-MacBook-Pro:~/programs/gambc-v4_6_2-devel] lucier% gsc -c -expansion crap.scm
> Expansion:
> 
> (define safe-fixnum-+
>  (lambda (x y)
>    (if (and ('#<procedure #2 ##fixnum?> y) ('#<procedure #2 ##fixnum?> x))
>        (let ((temp.2 ('#<procedure #3 ##fx+?> x y)))
>          (if temp.2
>              temp.2
>              (if (and ('#<procedure #2 ##fixnum?> y) ('#<procedure #2 ##fixnum?> x))
>                  (let ((temp.5 ('#<procedure #3 ##fx+?> x y))) (if temp.5 temp.5 ('#<procedure #4 fx+> x y)))
>                  ('#<procedure #4 fx+> x y))))
>        (if (and ('#<procedure #2 ##fixnum?> y) ('#<procedure #2 ##fixnum?> x))
>            (let ((temp.8 ('#<procedure #3 ##fx+?> x y))) (if temp.8 temp.8 ('#<procedure #4 fx+> x y)))
>            ('#<procedure #4 fx+> x y)))))
> 
> 
> The C code generated by gsc matches the expansion.
> 
> This is very strange results---checking three times whether x and y are fixnums?  I can't understand this.

Yes very strange...  On the other hand testing for fixnum 3 times has the advantage that it tolerates cosmic rays which could change some bits in the processor for the values x and y...  Hey I could probably sell this idea to NASA or DoD!

Seriously, I will investigate.

Marc




More information about the Gambit-list mailing list