2008-11-14 21:18:16 -05:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-12-02 22:50:34 -05:00
|
|
|
USING: io.mmap functors accessors alien.c-types math kernel
|
|
|
|
words fry ;
|
2008-11-14 21:18:16 -05:00
|
|
|
IN: io.mmap.functor
|
|
|
|
|
|
|
|
SLOT: address
|
|
|
|
SLOT: length
|
|
|
|
|
|
|
|
: mapped-file>direct ( mapped-file type -- alien length )
|
|
|
|
[ [ address>> ] [ length>> ] bi ] dip
|
|
|
|
heap-size [ 1- + ] keep /i ;
|
|
|
|
|
2008-12-02 22:50:34 -05:00
|
|
|
FUNCTOR: define-mapped-array ( T -- )
|
2008-11-14 21:18:16 -05:00
|
|
|
|
2008-12-02 22:50:34 -05:00
|
|
|
<mapped-A> DEFINES <mapped-${T}-array>
|
|
|
|
<A> IS <direct-${T}-array>
|
|
|
|
with-mapped-A-file DEFINES with-mapped-${T}-file
|
2008-11-14 21:18:16 -05:00
|
|
|
|
|
|
|
WHERE
|
|
|
|
|
2008-12-02 22:50:34 -05:00
|
|
|
: <mapped-A> ( mapped-file -- direct-array )
|
|
|
|
T mapped-file>direct <A> execute ; inline
|
|
|
|
|
|
|
|
: with-mapped-A-file ( path length quot -- )
|
|
|
|
'[ <mapped-A> execute @ ] with-mapped-file ; inline
|
2008-11-14 21:18:16 -05:00
|
|
|
|
|
|
|
;FUNCTOR
|