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
|
|
|
|
|
|
|
! 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-06-10 17:41:41 -04:00
|
|
|
IN: math
|
|
|
|
DEFER: repeat
|
|
|
|
|
2005-05-05 22:30:58 -04:00
|
|
|
IN: kernel-internals
|
|
|
|
USING: kernel math-internals sequences ;
|
|
|
|
|
2005-05-14 17:18:45 -04:00
|
|
|
DEFER: array?
|
|
|
|
BUILTIN: array 8 array? ;
|
2005-01-25 19:40:57 -05:00
|
|
|
|
2005-04-11 23:05:05 -04:00
|
|
|
: array-capacity ( a -- n ) 1 slot ; inline
|
|
|
|
: array-nth ( n a -- obj ) swap 2 fixnum+ slot ; inline
|
|
|
|
: set-array-nth ( obj n a -- ) swap 2 fixnum+ set-slot ; inline
|
|
|
|
: dispatch ( n vtable -- ) 2 slot array-nth call ;
|
2005-01-27 20:06:10 -05:00
|
|
|
|
2005-04-11 23:05:05 -04:00
|
|
|
M: array length array-capacity ;
|
2005-04-02 02:39:33 -05:00
|
|
|
M: array nth array-nth ;
|
|
|
|
M: array set-nth set-array-nth ;
|
2005-06-10 16:08:00 -04:00
|
|
|
M: array resize resize-array ;
|
2005-06-10 17:41:41 -04:00
|
|
|
|
|
|
|
: copy-array ( to from -- )
|
|
|
|
dup array-capacity [
|
|
|
|
3dup swap array-nth pick rot set-array-nth
|
|
|
|
] repeat 2drop ;
|