     [ "__" append ] [ "_" append ] if ;
 
 HOOK: fortran-c-abi fortran-abi ( -- abi )
+M: bad-fortran-abi fortran-c-abi cdecl ;
 M: f2c-abi fortran-c-abi cdecl ;
 M: g95-abi fortran-c-abi cdecl ;
 M: gfortran-abi fortran-c-abi cdecl ;


SINGLETONS: f2c-abi g95-abi gfortran-abi intel-unix-abi intel-windows-abi ;

<< 
: add-f2c-libraries ( -- )
    "I77" "libI77.so" cdecl add-library
    "F77" "libF77.so" cdecl add-library ;

! os netbsd? [ add-f2c-libraries ] when
>>

: alien>nstring ( alien len encoding -- string )
    [ memory>byte-array ] dip decode ;

        [ 2nip [fortran-results>] ]
    } 4 ncleave 4 nappend ;

:: (fortran-invoke) ( return library function parameters -- quot )
    library library-fortran-abis get-global at dup bad-fortran-abi?
    [ '[ _ throw ] ]
    [ drop return library function parameters ((fortran-invoke)) ] if ;

MACRO: fortran-invoke ( return library function parameters -- )
    { [ 2drop nip set-fortran-abi ] [ (fortran-invoke) ] } 4 ncleave ;

