Skip to content

Commit

Permalink
HsFFI.h + required refactoring of RTS include files.
Browse files Browse the repository at this point in the history
  • Loading branch information
atzedijkstra committed Mar 23, 2010
1 parent 7b670df commit 7a4dfe3
Show file tree
Hide file tree
Showing 15 changed files with 310 additions and 77 deletions.
26 changes: 13 additions & 13 deletions EHC/ehclib/base/include/HsBaseConfig.h.in
Expand Up @@ -307,19 +307,19 @@
#ifdef __UHC_BUILDS_O__

#if defined(__UHC_TARGET_BC__) || defined(__UHC_TARGET_C__)
# define HsBool Word
# define HsInt Word
# define HsWord64 Word64
# define HsWord32 Word32
# define HsWord16 Word16
# define HsWord8 Word8
# ifdef __UHC_TARGET_BC__
# define HS_BOOL_FALSE gb_False
# define HS_BOOL_TRUE gb_True
# else
# define HS_BOOL_FALSE 0
# define HS_BOOL_TRUE 1
# endif
// # define HsBool Word
// # define HsInt Word
// # define HsWord64 Word64
// # define HsWord32 Word32
// # define HsWord16 Word16
// # define HsWord8 Word8
// # ifdef __UHC_TARGET_BC__
// # define HS_BOOL_FALSE gb_False
// # define HS_BOOL_TRUE gb_True
// # else
// # define HS_BOOL_FALSE 0
// # define HS_BOOL_TRUE 1
// # endif
#endif /* __UHC_TARGET_BC__ */

#endif /* __UHC_BUILDS_O__ */
Expand Down
4 changes: 2 additions & 2 deletions EHC/src/ehc/Ty/Trf/Canonic.cag
Expand Up @@ -31,8 +31,8 @@ recursive canonicalization of inner components, type level beta
reduction and canonicalization alternately done.

A VarMp (substitution) with additional changes in the type is threaded.
Currently (20090821) only empty implicits (Impls_Tail) are replaced by
Impls_Nil, and removed in the type itself.
Currently (20090821) only empty implicits \verb@Impls_Tail@ are replaced by
\verb@Impls_Nil@, and removed in the type itself.
%%]

%%[(9 hmtyinfer) hs module {%{EH}Ty.Trf.Canonic} import({%{EH}Base.Common},{%{EH}Base.Builtin},{%{EH}Ty},{%{EH}VarMp},{%{EH}Substitutable},{%{EH}Ty.FitsInCommon2})
Expand Down
11 changes: 0 additions & 11 deletions EHC/src/rts/C/prim.cc
Expand Up @@ -55,17 +55,6 @@ PRIM Word primError(Word s)
return 0;
}


PRIM Word primMinInt()
{
return 0x10000000;
}
PRIM Word primMaxInt()
{
return 0x0FFFFFFF;
}


%%]


Expand Down
162 changes: 162 additions & 0 deletions EHC/src/rts/HsFFI.ch
@@ -0,0 +1,162 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% FFI: C level interface to types used by FFI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[8
#ifndef __HSFFI_H__
#define __HSFFI_H__
%%]

%%[99
#ifdef __cplusplus
extern "C" {
#endif
%%]

%%[8
#include <inttypes.h>
#include <limits.h>
%%]

%%[97
#include <math.h>
#include <float.h>
%%]

%%[8
#include "config.h"
#include "base/sizes.h"
#include "base/basictypes.h"
#include "base/bits.h"
#ifdef __UHC_TARGET_BC__
#include "bc/base.h"
#include "bc/prim-bool.h"
#endif
%%]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Types
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[99
typedef Word HsChar;
typedef Int HsInt;
typedef Int8 HsInt8;
typedef Int16 HsInt16;
typedef Int32 HsInt32;
typedef Int64 HsInt64;
typedef Word HsWord;
typedef Word8 HsWord8;
typedef Word16 HsWord16;
typedef Word32 HsWord32;
typedef Word64 HsWord64;
typedef Float HsFloat;
typedef Double HsDouble;
typedef Word HsBool;
%%]

TBD: These are not yet sorted out properly

%%[99
typedef void* HsPtr; /* this should better match StgAddr */
typedef void (*HsFunPtr)(void); /* this should better match StgAddr */
typedef void* HsForeignPtr; /* ... and this StgForeignPtr */
typedef void* HsStablePtr;
typedef void* HsAddr; /* DEPRECATED */
typedef void* HsForeignObj; /* DEPRECATED */
%%]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Min & max values
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[99
/* this should correspond to the type of StgChar in StgTypes.h */
#define HS_CHAR_MIN 0
#define HS_CHAR_MAX Int8_MaxValue

#ifdef __UHC_TARGET_BC__
# define HS_BOOL_FALSE gb_False
# define HS_BOOL_TRUE gb_True
#else
# define HS_BOOL_FALSE 0
# define HS_BOOL_TRUE 1
#endif

#define HS_BOOL_MIN HS_BOOL_FALSE
#define HS_BOOL_MAX HS_BOOL_TRUE

#define HS_INT_MIN Int_MinValue
#define HS_INT_MAX Int_MaxValue
#define HS_WORD_MIN Word_MinValue
#define HS_WORD_MAX Word_MaxValue

#define HS_INT8_MIN Int8_MinValue
#define HS_INT8_MAX Int8_MaxValue
#define HS_INT16_MIN Int16_MinValue
#define HS_INT16_MAX Int16_MaxValue
#define HS_INT32_MIN Int32_MinValue
#define HS_INT32_MAX Int32_MaxValue
#define HS_INT64_MIN Int64_MinValue
#define HS_INT64_MAX Int64_MaxValue
#define HS_WORD8_MAX Word8_MaxValue
#define HS_WORD16_MAX Word16_MaxValue
#define HS_WORD32_MAX Word32_MaxValue
#define HS_WORD64_MAX Word64_MaxValue

#define HS_FLOAT_RADIX FLT_RADIX
#define HS_FLOAT_ROUNDS FLT_ROUNDS
#define HS_FLOAT_EPSILON FLT_EPSILON
#define HS_FLOAT_DIG FLT_DIG
#define HS_FLOAT_MANT_DIG FLT_MANT_DIG
#define HS_FLOAT_MIN FLT_MIN
#define HS_FLOAT_MIN_EXP FLT_MIN_EXP
#define HS_FLOAT_MIN_10_EXP FLT_MIN_10_EXP
#define HS_FLOAT_MAX FLT_MAX
#define HS_FLOAT_MAX_EXP FLT_MAX_EXP
#define HS_FLOAT_MAX_10_EXP FLT_MAX_10_EXP

#define HS_DOUBLE_RADIX DBL_RADIX
#define HS_DOUBLE_ROUNDS DBL_ROUNDS
#define HS_DOUBLE_EPSILON DBL_EPSILON
#define HS_DOUBLE_DIG DBL_DIG
#define HS_DOUBLE_MANT_DIG DBL_MANT_DIG
#define HS_DOUBLE_MIN DBL_MIN
#define HS_DOUBLE_MIN_EXP DBL_MIN_EXP
#define HS_DOUBLE_MIN_10_EXP DBL_MIN_10_EXP
#define HS_DOUBLE_MAX DBL_MAX
#define HS_DOUBLE_MAX_EXP DBL_MAX_EXP
#define HS_DOUBLE_MAX_10_EXP DBL_MAX_10_EXP
%%]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Interfaces
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Not yet supported

%%[99
%%]
extern void hs_init (int *argc, char **argv[]);
extern void hs_exit (void);
extern void hs_set_argv (int argc, char *argv[]);
extern void hs_add_root (void (*init_root)(void));

extern void hs_perform_gc (void);

extern void hs_free_stable_ptr (HsStablePtr sp);
extern void hs_free_fun_ptr (HsFunPtr fp);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% EOF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[99
#ifdef __cplusplus
}
#endif
%%]

%%[8
#endif /* __HSFFI_H__ */
%%]
30 changes: 30 additions & 0 deletions EHC/src/rts/base/sizes.ch
Expand Up @@ -65,6 +65,36 @@
#define Word8_MaxValue UINT8_MAX
%%]

%%[8
#ifdef __UHC_TARGET_BC__

# define Int_MinValue (Bits_MinSInt(Word,Word_SizeInBits,Word_SizeInBits-GB_Word_SizeOfWordTag)+1)
# define Int_MaxValue (Bits_MaxSInt(Word,Word_SizeInBits,Word_SizeInBits-GB_Word_SizeOfWordTag))
# if USE_64_BITS
# define Word_MinValue Word64_MinValue
# define Word_MaxValue (Word64_MaxValue >> GB_Word_SizeOfWordTag)
# else
# define Word_MinValue Word32_MinValue
# define Word_MaxValue (Word32_MaxValue >> GB_Word_SizeOfWordTag)
# endif

#else

# if USE_64_BITS
# define Int_MinValue Int64_MinValue
# define Int_MaxValue Int64_MaxValue
# define Word_MinValue Word64_MinValue
# define Word_MaxValue Word64_MaxValue
# else
# define Int_MinValue Int32_MinValue
# define Int_MaxValue Int32_MaxValue
# define Word_MinValue Word32_MinValue
# define Word_MaxValue Word32_MaxValue
# endif

#endif
%%]

%%[8
#define Byte_SizeInBits 8
#define Byte_SizeInBits_Log 3
Expand Down
32 changes: 32 additions & 0 deletions EHC/src/rts/bc/base.ch
@@ -0,0 +1,32 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Basics for bc interpreter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[8
#ifndef __BC_BASE_H__
#define __BC_BASE_H__
%%]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Configuration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Nr of bits used for tagging a word.

%%[8
#define GB_Word_SizeOfWordTag 2
%%]

Construct a Enum Node from a tag

%%[8
#define GB_MkConEnumNodeAsTag(tg) (tg)
%%]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% EOF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[8
#endif /* __BC_BASE_H__ */
%%]
19 changes: 19 additions & 0 deletions EHC/src/rts/bc/prim-bool.cc
@@ -0,0 +1,19 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Primitives for boolean
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[8
#include "../HsFFI.h"
%%]

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Constants
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[8
PRIM Word gb_False
= GB_MkConEnumNodeAsTag( 0 ) ;
PRIM Word gb_True
= GB_MkConEnumNodeAsTag( 1 ) ;

%%]
34 changes: 0 additions & 34 deletions EHC/src/rts/bc/prim.cc
Expand Up @@ -24,11 +24,6 @@
PRIM Word gb_Unit
= GB_MkConEnumNodeAsTag( 0 ) ;

PRIM Word gb_False
= GB_MkConEnumNodeAsTag( 0 ) ;
PRIM Word gb_True
= GB_MkConEnumNodeAsTag( 1 ) ;

#if ! USE_EHC_MM
GB_Node gb_Nil_Node
= GB_MkConEnumNode( GB_Tag_List_Nil ) ;
Expand Down Expand Up @@ -231,35 +226,6 @@ PRIM GB_NodePtr primDivModInt( GB_Int x, GB_Int y )

%%]

%%[95
PRIM Word primMaxInt()
{
// return GB_Int2GBInt(Bits_MaxSInt(Word,Word_SizeInBits,GB_Word_SizeInBits-GB_Word_SizeOfWordTag)) ;
return (Bits_MaxSInt(Word,Word_SizeInBits,GB_Word_SizeInBits-GB_Word_SizeOfWordTag)) ;
}

PRIM Word primMinInt()
{
// return GB_Int2GBInt(Bits_MinSInt(Word,Word_SizeInBits,GB_Word_SizeInBits-GB_Word_SizeOfWordTag)+1) ;
return (Bits_MinSInt(Word,Word_SizeInBits,GB_Word_SizeInBits-GB_Word_SizeOfWordTag)+1) ;
}
%%]

%%[97
PRIM Word primMaxWord()
{
// printf( "primMaxWord %x\n", Word32_MaxValue >> GB_Word_SizeOfWordTag ) ;
return Word32_MaxValue >> GB_Word_SizeOfWordTag ;
}

PRIM Word primMinWord()
{
return Word32_MinValue ;
}
%%]



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% bitwise logical operators
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
4 changes: 0 additions & 4 deletions EHC/src/rts/bc/types.ch
Expand Up @@ -21,8 +21,6 @@
typedef Word GB_Word ;
typedef SWord GB_SWord ;

#define GB_Word_SizeInBits Word_SizeInBits

typedef GB_Word* GB_WordPtr ;
typedef GB_WordPtr GB_Ptr ;
typedef GB_Ptr* GB_PtrPtr ;
Expand Down Expand Up @@ -86,7 +84,6 @@ typedef union GB_WordEquiv {
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%[8
#define GB_Word_SizeOfWordTag 2
#define GB_Word_TagMask Bits_Size2LoMask(GB_Word,GB_Word_SizeOfWordTag)
#define GB_Word_IntMask (~ GB_Word_TagMask)
#define GB_Word_TagPtr 0
Expand Down Expand Up @@ -322,7 +319,6 @@ static inline Bool gb_NH_HasTraceableFields( GB_NodeHeader h ) {
#if ! USE_EHC_MM
# define GB_MkConEnumNode(tg) { GB_MkConHeader(0,tg) }
#endif
#define GB_MkConEnumNodeAsTag(tg) (tg /* GB_Int2GBInt(tg) */)

#define GB_FillNodeFlds1(n,x1) { (n)->content.fields[0] = Cast(GB_Word,x1);}
#define GB_FillNodeFlds2(n,x1,x2) {GB_FillNodeFlds1(n,x1 );(n)->content.fields[1] = Cast(GB_Word,x2);}
Expand Down

0 comments on commit 7a4dfe3

Please sign in to comment.