* Hugs version 1.4, December 1997
*
* $RCSfile: interface.c,v $
- * $Revision: 1.45 $
- * $Date: 2000/04/05 09:22:28 $
+ * $Revision: 1.58 $
+ * $Date: 2000/05/12 13:34:07 $
* ------------------------------------------------------------------------*/
#include "hugsbasictypes.h"
#include "errors.h"
#include "object.h"
+#include "Rts.h" /* to make StgPtr visible in Assembler.h */
#include "Assembler.h" /* for wrapping GHC objects */
-
/*#define DEBUG_IFACE*/
#define VERBOSE FALSE
* Data declarations
* ------------------------------------------------------------------------*/
+static Type qualifyIfaceType ( Type unqual, List ctx )
+{
+ /* ctx :: [((QConId,VarId))] */
+ /* ctx is a list of (class name, tyvar) pairs.
+ Attach to unqual qualifiers taken from ctx
+ for each tyvar which appears in unqual.
+ */
+ List tyvarsMentioned; /* :: [VarId] */
+ List ctx2 = NIL;
+ Cell kinds = NIL;
+
+ if (isPolyType(unqual)) {
+ kinds = polySigOf(unqual);
+ unqual = monotypeOf(unqual);
+ }
+
+ assert(!isQualType(unqual));
+ tyvarsMentioned = ifTyvarsIn ( unqual );
+ for (; nonNull(ctx); ctx=tl(ctx)) {
+ ZPair ctxElem = hd(ctx); /* :: ((QConId, VarId)) */
+ if (nonNull(varIsMember(textOf(zsnd(ctxElem)),tyvarsMentioned)))
+ ctx2 = cons(ctxElem, ctx2);
+ }
+ if (nonNull(ctx2))
+ unqual = ap(QUAL,pair(reverse(ctx2),unqual));
+ if (nonNull(kinds))
+ unqual = mkPolyType(kinds,unqual);
+ return unqual;
+}
+
+
static Void startGHCDataDecl(line,ctx0,tycon,ktyvars,constrs0)
Int line;
List ctx0; /* [((QConId,VarId))] */
*/
{
Type ty, resTy, selTy, conArgTy;
- List tmp, conArgs, sels, constrs, fields, tyvarsMentioned;
- List ctx, ctx2;
+ List tmp, conArgs, sels, constrs, fields;
Triple constr;
Cell conid;
Pair conArg, ctxElem;
Text conArgNm;
Int conArgStrictness;
+ Int conStrictCompCount;
Text t = textOf(tycon);
# ifdef DEBUG_IFACE
conid = zfst(constr);
fields = zsnd(constr);
- /* Build type of constr and handle any selectors found.
- Also collect up tyvars occurring in the constr's arg
- types, so we can throw away irrelevant parts of the
- context later.
- */
+ /* Build type of constr and handle any selectors found. */
ty = resTy;
- tyvarsMentioned = NIL;
- /* tyvarsMentioned :: [VarId] */
+ conStrictCompCount = 0;
conArgs = reverse(fields);
for (; nonNull(conArgs); conArgs=tl(conArgs)) {
conArg = hd(conArgs); /* (Type,Text) */
conArgTy = zfst3(conArg);
conArgNm = zsnd3(conArg);
conArgStrictness = intOf(zthd3(conArg));
- tyvarsMentioned = dupListOnto(ifTyvarsIn(conArgTy),
- tyvarsMentioned);
- /* Not sure what the deal is with strictness. Do we need
- to notify the symbol table, or not? The Hugs desugarer?
- Currently disabled. */
- /* if (conArgStrictness > 0) conArgTy = bang(conArgTy); */
+ if (conArgStrictness > 0) conStrictCompCount++;
ty = fn(conArgTy,ty);
if (nonNull(conArgNm)) {
/* a field name is mentioned too */
selTy = fn(resTy,conArgTy);
if (whatIs(tycon(tc).kind) != STAR)
selTy = pair(POLYTYPE,pair(tycon(tc).kind, selTy));
+ selTy = qualifyIfaceType ( selTy, ctx0 );
selTy = tvsToOffsets(line,selTy, ktyvars);
sels = cons( zpair(conArgNm,selTy), sels);
}
}
/* Now ty is the constructor's type, not including context.
- Throw away any parts of the context not mentioned in
- tyvarsMentioned, and use it to qualify ty.
+ Throw away any parts of the context not mentioned in ty,
+ and use it to qualify ty.
*/
- ctx2 = NIL;
- for (ctx=ctx0; nonNull(ctx); ctx=tl(ctx)) {
- ctxElem = hd(ctx);
- /* ctxElem :: ((QConId,VarId)) */
- if (nonNull(cellIsMember(textOf(zsnd(ctxElem)),tyvarsMentioned)))
- ctx2 = cons(ctxElem, ctx2);
- }
- if (nonNull(ctx2))
- ty = ap(QUAL,pair(ctx2,ty));
+ ty = qualifyIfaceType ( ty, ctx0 );
/* stick the tycon's kind on, if not simply STAR */
if (whatIs(tycon(tc).kind) != STAR)
ty = tvsToOffsets(line,ty, ktyvars);
/* Finally, stick the constructor's type onto it. */
- hd(constrs) = ztriple(conid,fields,ty);
+ hd(constrs) = z4ble(conid,fields,ty,mkInt(conStrictCompCount));
}
/* Final result is that
- constrs :: [((ConId,[((Type,Text))],Type))]
- lists the constructors and their types
+ constrs :: [((ConId,[((Type,Text))],Type,Int))]
+ lists the constructors, their types and # strict comps
sels :: [((VarId,Type))]
lists the selectors and their types
*/
static List startGHCConstrs ( Int line, List cons, List sels )
{
- /* cons :: [((ConId,[((Type,Text,Int))],Type))] */
- /* sels :: [((VarId,Type))] */
- /* returns [Name] */
+ /* cons :: [((ConId,[((Type,Text,Int))],Type,Int))] */
+ /* sels :: [((VarId,Type))] */
+ /* returns [Name] */
List cs, ss;
Int conNo = length(cons)>1 ? 1 : 0;
for(cs=cons; nonNull(cs); cs=tl(cs), conNo++) {
}
-static Name startGHCConstr ( Int line, Int conNo, ZTriple constr )
+static Name startGHCConstr ( Int line, Int conNo, Z4Ble constr )
{
- /* constr :: ((ConId,[((Type,Text,Int))],Type)) */
+ /* constr :: ((ConId,[((Type,Text,Int))],Type,Int)) */
/* (ADR) ToDo: add rank2 annotation and existential annotation
* these affect how constr can be used.
*/
- Text con = textOf(zfst3(constr));
- Type type = zthd3(constr);
- Int arity = arityFromType(type);
+ Text con = textOf(zsel14(constr));
+ Type type = zsel34(constr);
+ Int arity = arityFromType(type);
+ Int nStrict = intOf(zsel44(constr));
Name n = findName(con); /* Allocate constructor fun name */
if (isNull(n)) {
n = newName(con,NIL);
textToStr(con)
EEND;
}
- name(n).arity = arity; /* Save constructor fun details */
- name(n).line = line;
- name(n).number = cfunNo(conNo);
- name(n).type = type;
+ name(n).arity = arity; /* Save constructor fun details */
+ name(n).line = line;
+ name(n).number = cfunNo(conNo);
+ name(n).type = type;
+ name(n).hasStrict = nStrict > 0;
return n;
}
* ------------------------------------------------------------------------*/
#define EXTERN_SYMS_ALLPLATFORMS \
- Sym(MainRegTable) \
+ SymX(MainRegTable) \
Sym(stg_gc_enter_1) \
Sym(stg_gc_noregs) \
Sym(stg_gc_seq_1) \
Sym(stg_chk_0) \
Sym(stg_chk_1) \
Sym(stg_gen_chk) \
- Sym(stg_exit) \
- Sym(stg_update_PAP) \
- Sym(stg_error_entry) \
- Sym(__ap_2_upd_info) \
- Sym(__ap_3_upd_info) \
- Sym(__ap_4_upd_info) \
- Sym(__ap_5_upd_info) \
- Sym(__ap_6_upd_info) \
- Sym(__ap_7_upd_info) \
- Sym(__ap_8_upd_info) \
- Sym(__sel_0_upd_info) \
- Sym(__sel_1_upd_info) \
- Sym(__sel_2_upd_info) \
- Sym(__sel_3_upd_info) \
- Sym(__sel_4_upd_info) \
- Sym(__sel_5_upd_info) \
- Sym(__sel_6_upd_info) \
- Sym(__sel_7_upd_info) \
- Sym(__sel_8_upd_info) \
- Sym(__sel_9_upd_info) \
- Sym(__sel_10_upd_info) \
- Sym(__sel_11_upd_info) \
- Sym(__sel_12_upd_info) \
- Sym(Upd_frame_info) \
- Sym(seq_frame_info) \
- Sym(CAF_BLACKHOLE_info) \
- Sym(IND_STATIC_info) \
- Sym(EMPTY_MVAR_info) \
- Sym(MUT_ARR_PTRS_FROZEN_info) \
- Sym(newCAF) \
- Sym(putMVarzh_fast) \
- Sym(newMVarzh_fast) \
- Sym(takeMVarzh_fast) \
- Sym(catchzh_fast) \
- Sym(raisezh_fast) \
- Sym(delayzh_fast) \
- Sym(yieldzh_fast) \
- Sym(killThreadzh_fast) \
- Sym(waitReadzh_fast) \
- Sym(waitWritezh_fast) \
- Sym(CHARLIKE_closure) \
- Sym(INTLIKE_closure) \
- Sym(suspendThread) \
- Sym(resumeThread) \
+ SymX(stg_exit) \
+ SymX(stg_update_PAP) \
+ SymX(stg_error_entry) \
+ SymX(__ap_2_upd_info) \
+ SymX(__ap_3_upd_info) \
+ SymX(__ap_4_upd_info) \
+ SymX(__ap_5_upd_info) \
+ SymX(__ap_6_upd_info) \
+ SymX(__ap_7_upd_info) \
+ SymX(__ap_8_upd_info) \
+ SymX(__sel_0_upd_info) \
+ SymX(__sel_1_upd_info) \
+ SymX(__sel_2_upd_info) \
+ SymX(__sel_3_upd_info) \
+ SymX(__sel_4_upd_info) \
+ SymX(__sel_5_upd_info) \
+ SymX(__sel_6_upd_info) \
+ SymX(__sel_7_upd_info) \
+ SymX(__sel_8_upd_info) \
+ SymX(__sel_9_upd_info) \
+ SymX(__sel_10_upd_info) \
+ SymX(__sel_11_upd_info) \
+ SymX(__sel_12_upd_info) \
+ SymX(Upd_frame_info) \
+ SymX(seq_frame_info) \
+ SymX(CAF_BLACKHOLE_info) \
+ SymX(IND_STATIC_info) \
+ SymX(EMPTY_MVAR_info) \
+ SymX(MUT_ARR_PTRS_FROZEN_info) \
+ SymX(newCAF) \
+ SymX(putMVarzh_fast) \
+ SymX(newMVarzh_fast) \
+ SymX(takeMVarzh_fast) \
+ SymX(catchzh_fast) \
+ SymX(raisezh_fast) \
+ SymX(delayzh_fast) \
+ SymX(yieldzh_fast) \
+ SymX(killThreadzh_fast) \
+ SymX(waitReadzh_fast) \
+ SymX(waitWritezh_fast) \
+ SymX(CHARLIKE_closure) \
+ SymX(INTLIKE_closure) \
+ SymX(suspendThread) \
+ SymX(resumeThread) \
Sym(stackOverflow) \
- Sym(int2Integerzh_fast) \
+ SymX(int2Integerzh_fast) \
Sym(stg_gc_unbx_r1) \
- Sym(ErrorHdrHook) \
- Sym(makeForeignObjzh_fast) \
- Sym(__encodeDouble) \
- Sym(decodeDoublezh_fast) \
- Sym(isDoubleNaN) \
- Sym(isDoubleInfinite) \
- Sym(isDoubleDenormalized) \
- Sym(isDoubleNegativeZero) \
- Sym(__encodeFloat) \
- Sym(decodeFloatzh_fast) \
- Sym(isFloatNaN) \
- Sym(isFloatInfinite) \
- Sym(isFloatDenormalized) \
- Sym(isFloatNegativeZero) \
- Sym(__int_encodeFloat) \
- Sym(__int_encodeDouble) \
- Sym(mpz_cmp_si) \
- Sym(mpz_cmp) \
- Sym(__mpn_gcd_1) \
- Sym(gcdIntegerzh_fast) \
- Sym(newArrayzh_fast) \
- Sym(unsafeThawArrayzh_fast) \
- Sym(newDoubleArrayzh_fast) \
- Sym(newFloatArrayzh_fast) \
- Sym(newAddrArrayzh_fast) \
- Sym(newWordArrayzh_fast) \
- Sym(newIntArrayzh_fast) \
- Sym(newCharArrayzh_fast) \
- Sym(newMutVarzh_fast) \
- Sym(quotRemIntegerzh_fast) \
- Sym(quotIntegerzh_fast) \
- Sym(remIntegerzh_fast) \
- Sym(divExactIntegerzh_fast) \
- Sym(divModIntegerzh_fast) \
- Sym(timesIntegerzh_fast) \
- Sym(minusIntegerzh_fast) \
- Sym(plusIntegerzh_fast) \
- Sym(addr2Integerzh_fast) \
- Sym(mkWeakzh_fast) \
- Sym(prog_argv) \
- Sym(prog_argc) \
+ SymX(ErrorHdrHook) \
+ SymX(mkForeignObjzh_fast) \
+ SymX(__encodeDouble) \
+ SymX(decodeDoublezh_fast) \
+ SymX(isDoubleNaN) \
+ SymX(isDoubleInfinite) \
+ SymX(isDoubleDenormalized) \
+ SymX(isDoubleNegativeZero) \
+ SymX(__encodeFloat) \
+ SymX(decodeFloatzh_fast) \
+ SymX(isFloatNaN) \
+ SymX(isFloatInfinite) \
+ SymX(isFloatDenormalized) \
+ SymX(isFloatNegativeZero) \
+ SymX(__int_encodeFloat) \
+ SymX(__int_encodeDouble) \
+ SymX(mpz_cmp_si) \
+ SymX(mpz_cmp) \
+ SymX(__mpn_gcd_1) \
+ SymX(gcdIntegerzh_fast) \
+ SymX(newArrayzh_fast) \
+ SymX(unsafeThawArrayzh_fast) \
+ SymX(newDoubleArrayzh_fast) \
+ SymX(newFloatArrayzh_fast) \
+ SymX(newAddrArrayzh_fast) \
+ SymX(newWordArrayzh_fast) \
+ SymX(newIntArrayzh_fast) \
+ SymX(newCharArrayzh_fast) \
+ SymX(newMutVarzh_fast) \
+ SymX(quotRemIntegerzh_fast) \
+ SymX(quotIntegerzh_fast) \
+ SymX(remIntegerzh_fast) \
+ SymX(divExactIntegerzh_fast) \
+ SymX(divModIntegerzh_fast) \
+ SymX(timesIntegerzh_fast) \
+ SymX(minusIntegerzh_fast) \
+ SymX(plusIntegerzh_fast) \
+ SymX(addr2Integerzh_fast) \
+ SymX(mkWeakzh_fast) \
+ SymX(prog_argv) \
+ SymX(prog_argc) \
Sym(resetNonBlockingFd) \
- Sym(getStablePtr) \
- Sym(stable_ptr_table) \
+ SymX(getStablePtr) \
+ SymX(stable_ptr_table) \
Sym(createAdjThunk) \
- Sym(shutdownHaskellAndExit) \
+ SymX(shutdownHaskellAndExit) \
Sym(stg_enterStackTop) \
- Sym(CAF_UNENTERED_entry) \
+ SymX(CAF_UNENTERED_entry) \
Sym(stg_yield_to_Hugs) \
Sym(StgReturn) \
Sym(init_stack) \
+ SymX(blockAsyncExceptionszh_fast) \
+ SymX(unblockAsyncExceptionszh_fast) \
\
/* needed by libHS_cbits */ \
SymX(malloc) \
SymX(lseek) \
SymX(write) \
Sym(getrusage) \
- Sym(gettimeofday) \
SymX(realloc) \
SymX(getcwd) \
SymX(free) \
SymX(chdir) \
SymX(execl) \
Sym(waitpid) \
- SymX(getenv)
+ SymX(getenv) \
#define EXTERN_SYMS_cygwin32 \
SymX(GetCurrentProcess) \
SymX(__imp__tzname) \
SymX(__imp__timezone) \
SymX(tzset) \
- Sym(log) \
- Sym(exp) \
+ SymX(log) \
+ SymX(exp) \
Sym(sqrt) \
Sym(sin) \
Sym(cos) \
- Sym(tan) \
- Sym(asin) \
- Sym(acos) \
- Sym(atan) \
- Sym(sinh) \
- Sym(cosh) \
- Sym(tanh) \
- Sym(pow) \
- Sym(__errno) \
+ SymX(pow) \
+ SymX(__errno) \
Sym(stat) \
- Sym(fstat)
+ Sym(fstat) \
+ Sym(gettimeofday) \
+ SymX(localtime) \
+ SymX(strftime) \
+ SymX(mktime) \
+ SymX(gmtime)
+
#define EXTERN_SYMS_linux \
- Sym(__errno_location) \
+ SymX(__errno_location) \
Sym(__xstat) \
Sym(__fxstat) \
Sym(__lxstat) \
SymX(mktime) \
SymX(gmtime) \
Sym(setitimer) \
+ Sym(chmod) \
+ Sym(gettimeofday) \
+#define EXTERN_SYMS_solaris2 \
+ SymX(gettimeofday) \
#if defined(linux_TARGET_OS)
-
/* entirely bogus claims about types of these symbols */
#define Sym(vvv) extern void (vvv);
#define SymX(vvv) /**/
#define Sym(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
- &(vvv) },
+ (void*)(&(vvv)) },
#define SymX(vvv) { MAYBE_LEADING_UNDERSCORE_STR(#vvv), \
- &(vvv) },
+ (void*)(&(vvv)) },
OSym rtsTab[]
= {
EXTERN_SYMS_ALLPLATFORMS
#undef SymX
-void init_stack;
/* A kludge to assist Win32 debugging. */
t = unZcodeThenFindText(nm2+first_real_char+7);
if (t == findText("PrelGHC")) return (4+NULL); /* kludge */
m = findModule(t);
- if (isNull(m)) goto not_found;
+ if (isNull(m)) goto dire_straits;
a = lookupOTabName ( m, nm );
if (a) return a;
- goto not_found;
+ goto dire_straits;
}
/* if not an RTS name, look in the
relevant module's object symbol table
*/
pp = strchr(nm2+first_real_char, '_');
- if (!pp || !isupper(nm2[first_real_char])) goto not_found;
+ if (!pp || !isupper(nm2[first_real_char])) goto dire_straits;
*pp = 0;
t = unZcodeThenFindText(nm2+first_real_char);
m = findModule(t);
- if (isNull(m)) goto not_found;
+ if (isNull(m)) goto dire_straits;
a = lookupOTabName ( m, nm ); /* RATIONALISE */
if (a) return a;
- not_found:
+ dire_straits:
+ /* make a desperate, last-ditch attempt to find it */
+ a = lookupOTabNameAbsolutelyEverywhere ( nm );
+ if (a) return a;
+
fprintf ( stderr,
"lookupObjName: can't resolve name `%s'\n",
nm );
- assert(4-4);
+ assert(0);
return NULL;
}