]> gitweb.factorcode.org Git - factor.git/blob - basis/io/mmap/functor/functor.factor
Merge branch 'master' into experimental
[factor.git] / basis / io / mmap / functor / functor.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.mmap functors accessors alien.c-types math kernel
4 words fry ;
5 IN: io.mmap.functor
6
7 SLOT: address
8 SLOT: length
9
10 : mapped-file>direct ( mapped-file type -- alien length )
11     [ [ address>> ] [ length>> ] bi ] dip
12     heap-size [ 1- + ] keep /i ;
13
14 FUNCTOR: define-mapped-array ( T -- )
15
16 <mapped-A>         DEFINES <mapped-${T}-array>
17 <A>                IS      <direct-${T}-array>
18 with-mapped-A-file DEFINES with-mapped-${T}-file
19
20 WHERE
21
22 : <mapped-A> ( mapped-file -- direct-array )
23     T mapped-file>direct <A> ; inline
24
25 : with-mapped-A-file ( path length quot -- )
26     '[ <mapped-A> @ ] with-mapped-file ; inline
27
28 ;FUNCTOR