factor/basis/io/mmap/mmap.factor

41 lines
1.2 KiB
Factor
Raw Normal View History

2008-02-01 00:00:08 -05:00
! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-05-15 00:23:12 -04:00
USING: continuations destructors io.backend kernel quotations
sequences system alien alien.accessors accessors
2008-11-14 21:18:16 -05:00
sequences.private system vocabs.loader combinators
specialized-arrays.direct functors alien.c-types
io.mmap.functor ;
2007-09-20 18:09:08 -04:00
IN: io.mmap
2008-05-15 00:23:12 -04:00
TUPLE: mapped-file address handle length disposed ;
2007-09-20 18:09:08 -04:00
2008-05-15 00:23:12 -04:00
M: mapped-file length dup check-disposed length>> ;
2007-09-20 18:09:08 -04:00
M: mapped-file nth-unsafe
2008-05-15 00:23:12 -04:00
dup check-disposed address>> swap alien-unsigned-1 ;
2007-09-20 18:09:08 -04:00
M: mapped-file set-nth-unsafe
2008-05-15 00:23:12 -04:00
dup check-disposed address>> swap set-alien-unsigned-1 ;
2007-09-20 18:09:08 -04:00
INSTANCE: mapped-file sequence
2008-05-14 01:44:27 -04:00
HOOK: (mapped-file) io-backend ( path length -- address handle )
: <mapped-file> ( path length -- mmap )
[ [ normalize-path ] dip (mapped-file) ] keep
2008-05-14 01:44:27 -04:00
f mapped-file boa ;
HOOK: close-mapped-file io-backend ( mmap -- )
2008-05-15 00:23:12 -04:00
M: mapped-file dispose* ( mmap -- ) close-mapped-file ;
2007-09-20 18:09:08 -04:00
: with-mapped-file ( path length quot -- )
[ <mapped-file> ] dip with-disposal ; inline
2008-07-02 22:52:28 -04:00
2008-11-14 21:18:16 -05:00
APPLY: mapped-array-functor primitive-types
2008-07-02 22:52:28 -04:00
{
{ [ os unix? ] [ "io.unix.mmap" require ] }
{ [ os winnt? ] [ "io.windows.mmap" require ] }
} cond