Fix custom-inlining for mod and rem, which was converting these calls to bitand in some cases, even if the input was not known to be an integer. Fixes #243

db4
Slava Pestov 2011-10-09 13:51:27 -07:00
parent b4588629ab
commit 901ee2434c
2 changed files with 8 additions and 4 deletions

View File

@ -155,6 +155,8 @@ GENERIC: void-generic ( obj -- * )
[ 0 ] [ 5 [ 1 mod ] compile-call ] unit-test
[ 0 ] [ 5 [ 1 rem ] compile-call ] unit-test
[ 0.5 ] [ 5.5 [ 1 mod ] compile-call ] unit-test
[ 0.5 ] [ 5.5 [ 1 rem ] compile-call ] unit-test
[ 5 ] [ 5 [ -1 bitand ] compile-call ] unit-test
[ 0 ] [ 5 [ 0 bitand ] compile-call ] unit-test

View File

@ -1,4 +1,4 @@
! Copyright (C) 2008, 2010 Slava Pestov, Daniel Ehrenberg.
! Copyright (C) 2008, 2011 Slava Pestov, Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types kernel sequences words fry generic
generic.single accessors classes.tuple classes classes.algebra
@ -23,9 +23,11 @@ IN: compiler.tree.propagation.transforms
] [ drop f ] if
] "custom-inlining" set-word-prop
: rem-custom-inlining ( #call -- quot/f )
second value-info literal>> dup integer?
[ power-of-2? [ 1 - bitand ] f ? ] [ drop f ] if ;
: rem-custom-inlining ( inputs -- quot/f )
dup first value-info class integer class<= [
second value-info literal>> dup integer?
[ power-of-2? [ 1 - bitand ] f ? ] [ drop f ] if
] [ drop f ] if ;
{
mod-integer-integer