extended foreign decls
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Tue Jan 2 13:35:18 EST 2001
Tue, 2 Jan 2001 22:28:02 +1100, Fergus Henderson <fjh at cs.mu.oz.au> pisze:
> Doing it in a separate tool will lose efficiency in some important
> cases. If the compiler is compiling via C, then it can insert
> inline C code directly in the generated code, and thus get
> inlining. But I think a separate tool would have to put the C code in
> a separate C file, which would prevent inlining.
hsc2hs creates a .c file and a .h file for snippets of C code.
The .h file is included into the .hc file generated by ghc.
If you mark functions as inline, they will be really inlined.
BTW. gcc understoods the word "inline" differently than ISO/ANSI C99
defines it. The following files are produced from a simple source:
#include <errno.h>
#def inline HsInt get_errno (void) {return errno;}
It works with gcc and should work with a hypothetical C compiler which
understands inline correctly.
-------- .h file --------
#ifndef TEST_HS_H
#define TEST_HS_H
#if __GLASGOW_HASKELL__ && __GLASGOW_HASKELL__ < 409
#include <Rts.h>
#endif
#include <HsFFI.h>
#include <errno.h>
#ifdef __GNUC__
extern
#endif
inline HsInt get_errno (void) {return errno;}
#endif
-------- .c file --------
#include "Test.hs.h"
#ifndef __GNUC__
extern
#endif
inline HsInt get_errno (void)
#ifndef __GNUC__
;
#else
{return errno;}
#endif
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTÊPCZA
QRCZAK
More information about the FFI
mailing list