1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types destructors kernel libc
12 ERROR: not-enough-pile-space pile ;
15 [ [ free ] when* f ] change-underlying drop ;
17 : <pile> ( size -- pile )
18 [ malloc ] keep 0 pile boa ;
20 : pile-empty ( pile -- )
23 : pile-alloc ( pile size -- alien )
25 [ [ ] [ size>> ] [ offset>> ] tri ] dip +
26 < [ not-enough-pile-space ] [ drop ] if
28 drop [ offset>> ] [ underlying>> ] bi <displaced-alien>
30 [ + ] curry change-offset drop
33 : <pile-c-object> ( pile c-type -- alien )
34 heap-size pile-alloc ; inline
36 : <pile-c-array> ( pile n c-type -- alien )
37 heap-size * pile-alloc ; inline
39 : pile-align ( pile align -- pile )
40 [ align ] curry change-offset ;