1 ! Copyright (C) 2009 Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.data destructors kernel libc math ;
11 ERROR: not-enough-pile-space pile ;
14 [ [ free ] when* f ] change-underlying drop ;
16 : <pile> ( size -- pile )
17 [ malloc ] keep 0 pile boa ;
19 : pile-empty ( pile -- )
22 : pile-alloc ( pile size -- alien )
24 [ [ ] [ size>> ] [ offset>> ] tri ] dip +
25 < [ not-enough-pile-space ] [ drop ] if
27 drop [ offset>> ] [ underlying>> ] bi <displaced-alien>
29 [ + ] curry change-offset drop
32 : <pile-c-object> ( pile c-type -- alien )
33 heap-size pile-alloc ; inline
35 : <pile-c-array> ( pile n c-type -- alien )
36 heap-size * pile-alloc ; inline
38 : pile-align ( pile align -- pile )
39 [ align ] curry change-offset ;