2005-01-25 19:40:57 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
2005-01-29 14:18:28 -05:00
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-01-25 19:40:57 -05:00
|
|
|
IN: kernel-internals
|
2005-01-29 14:18:28 -05:00
|
|
|
USING: generic math-internals kernel lists vectors ;
|
2005-01-25 19:40:57 -05:00
|
|
|
|
|
|
|
! An array is a range of memory storing pointers to other
|
|
|
|
! objects. Arrays are not used directly, and their access words
|
|
|
|
! are not bounds checked. Examples of abstractions built on
|
|
|
|
! arrays include vectors, hashtables, and tuples.
|
|
|
|
|
|
|
|
! These words are unsafe. I'd say "do not call them", but that
|
|
|
|
! Java-esque. By all means, do use arrays if you need something
|
|
|
|
! low-level... but be aware that vectors are usually a better
|
|
|
|
! choice.
|
|
|
|
|
2005-02-20 19:03:37 -05:00
|
|
|
BUILTIN: array 8 [ 1 "array-capacity" f ] ;
|
2005-01-25 19:40:57 -05:00
|
|
|
|
|
|
|
: array-nth ( n array -- obj )
|
2005-02-20 19:03:37 -05:00
|
|
|
#! Unsafe.
|
2005-01-25 19:40:57 -05:00
|
|
|
swap 2 fixnum+ slot ; inline
|
|
|
|
|
|
|
|
: set-array-nth ( obj n array -- )
|
2005-02-20 19:03:37 -05:00
|
|
|
#! Unsafe.
|
2005-01-25 19:40:57 -05:00
|
|
|
swap 2 fixnum+ set-slot ; inline
|
2005-01-27 20:06:10 -05:00
|
|
|
|
|
|
|
: (array>list) ( n i array -- list )
|
2005-02-20 19:03:37 -05:00
|
|
|
#! Unsafe.
|
2005-01-27 20:06:10 -05:00
|
|
|
pick pick fixnum<= [
|
|
|
|
3drop [ ]
|
|
|
|
] [
|
|
|
|
2dup array-nth >r >r 1 fixnum+ r> (array>list) r>
|
|
|
|
swap cons
|
|
|
|
] ifte ;
|
|
|
|
|
|
|
|
: array>list ( n array -- list )
|
2005-02-20 19:03:37 -05:00
|
|
|
#! Unsafe.
|
2005-01-27 20:06:10 -05:00
|
|
|
0 swap (array>list) ;
|