factor/basis/compiler/alien/alien.factor

29 lines
908 B
Factor
Raw Normal View History

! Copyright (C) 2008, 2010 Slava Pestov.
2008-09-10 23:11:03 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel namespaces make math sequences layouts
alien.c-types cpu.architecture ;
2008-09-10 23:11:03 -04:00
IN: compiler.alien
: large-struct? ( type -- ? )
dup c-struct? [ return-struct-in-registers? not ] [ drop f ] if ;
2008-09-10 23:11:03 -04:00
: alien-parameters ( params -- seq )
dup parameters>>
swap return>> large-struct? [ struct-return-pointer-type prefix ] when ;
2008-09-10 23:11:03 -04:00
: alien-return ( params -- type )
return>> dup large-struct? [ drop void ] when ;
2008-09-10 23:11:03 -04:00
: c-type-stack-align ( type -- align )
dup c-type-stack-align? [ c-type-align ] [ drop cell ] if ;
: parameter-align ( n type -- n delta )
2008-11-30 19:28:15 -05:00
[ c-type-stack-align align dup ] [ drop ] 2bi - ;
2008-09-10 23:11:03 -04:00
: parameter-offsets ( types -- total offsets )
2008-09-10 23:11:03 -04:00
[
0 [
[ parameter-align drop dup , ] keep stack-size +
] reduce cell align
] { } make ;