core: Use integer>fixnum instead of >fixnum for ``nth`` and other sequence operations. Fixes #581.

db4
Doug Coleman 2012-07-25 18:24:43 -07:00
parent 106ecdb6dd
commit 4a14bd407d
5 changed files with 13 additions and 10 deletions

View File

@ -5,8 +5,8 @@ IN: arrays
M: array clone (clone) ; inline
M: array length length>> ; inline
M: array nth-unsafe [ >fixnum ] dip array-nth ; inline
M: array set-nth-unsafe [ >fixnum ] dip set-array-nth ; inline
M: array nth-unsafe [ integer>fixnum ] dip array-nth ; inline
M: array set-nth-unsafe [ integer>fixnum ] dip set-array-nth ; inline
M: array resize resize-array ; inline
M: array equal? over array? [ sequence= ] [ 2drop f ] if ;
M: object new-sequence drop 0 <array> ; inline

View File

@ -1,6 +1,7 @@
USING: arrays byte-arrays kernel math math.order math.parser
namespaces sequences kernel.private sequences.private strings
sbufs tools.test vectors assocs generic vocabs.loader ;
sbufs tools.test vectors assocs generic vocabs.loader
generic.single ;
IN: sequences.tests
[ "empty" ] [ { } [ "empty" ] [ "not empty" ] if-empty ] unit-test
@ -213,7 +214,9 @@ unit-test
[ V{ "a" "b" } V{ } ] [ { "X" "a" "b" } { "X" } drop-prefix [ >vector ] bi@ ] unit-test
[ 1 ] [ 0.5 { 1 2 3 } nth ] unit-test
[ 0.5 10 iota nth ] [ no-method? ] must-fail-with
[ 0.5 { 1 2 3 } nth ] [ no-method? ] must-fail-with
[ 0.5 "asdfasdf" nth ] [ no-method? ] must-fail-with
! Pathological case
[ "ihbye" ] [ "hi" <reversed> "bye" append ] unit-test

View File

@ -106,7 +106,7 @@ TUPLE: iota { n integer read-only } ;
: iota ( n -- iota ) \ iota boa ; inline
M: iota length n>> ; inline
M: iota nth-unsafe drop ; inline
M: iota nth-unsafe drop integer>fixnum ; inline
INSTANCE: iota immutable-sequence
@ -634,7 +634,7 @@ ERROR: assert-sequence got expected ;
<PRIVATE
: sequence-hashcode-step ( oldhash newpart -- newhash )
>fixnum swap [
integer>fixnum swap [
[ -2 fixnum-shift-fast ] [ 5 fixnum-shift-fast ] bi
fixnum+fast fixnum+fast
] keep fixnum-bitxor ; inline
@ -845,7 +845,7 @@ PRIVATE>
#! We can't use case here since combinators depends on
#! sequences
pick length dup 0 3 between? [
>fixnum {
integer>fixnum {
[ drop nip ]
[ 2drop first ]
[ [ drop first2 ] dip call ]

View File

@ -63,11 +63,11 @@ M: string length
length>> ; inline
M: string nth-unsafe
[ >fixnum ] dip string-nth ; inline
[ integer>fixnum ] dip string-nth ; inline
M: string set-nth-unsafe
dup reset-string-hashcode
[ >fixnum ] [ >fixnum ] [ ] tri* set-string-nth ; inline
[ integer>fixnum ] [ integer>fixnum ] [ ] tri* set-string-nth ; inline
M: string clone
(clone) [ clone ] change-aux ; inline

View File

@ -18,7 +18,7 @@ M: vector like
] unless ; inline
M: vector new-sequence
drop [ f <array> ] [ >fixnum ] bi vector boa ; inline
drop [ f <array> ] [ integer>fixnum ] bi vector boa ; inline
M: vector equal?
over vector? [ sequence= ] [ 2drop f ] if ;