* `kernel' language, elimination of pattern matching and translation to
* super combinators (lambda lifting).
*
- * Hugs 98 is Copyright (c) Mark P Jones, Alastair Reid and the Yale
- * Haskell Group 1994-99, and is distributed as Open Source software
- * under the Artistic License; see the file "Artistic" that is included
- * in the distribution for details.
+ * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
+ * Yale Haskell Group, and the Oregon Graduate Institute of Science and
+ * Technology, 1994-1999, All rights reserved. It is distributed as
+ * free software under the license in the file "License", which is
+ * included in the distribution.
*
* $RCSfile: compiler.c,v $
- * $Revision: 1.8 $
- * $Date: 1999/07/06 15:24:36 $
+ * $Revision: 1.20 $
+ * $Date: 2000/03/10 14:53:00 $
* ------------------------------------------------------------------------*/
#include "prelude.h"
#include "errors.h"
#include "Rts.h" /* for rts_eval and related stuff */
#include "RtsAPI.h" /* for rts_eval and related stuff */
+#include "SchedAPI.h" /* for RevertCAFs */
#include "Schedule.h"
#include "link.h"
static Cell local translate(e) /* Translate expression: */
Cell e; {
+#if 0
+ printf ( "translate: " );print(e,100);printf("\n");
+#endif
switch (whatIs(e)) {
case LETREC : snd(snd(e)) = translate(snd(snd(e)));
return expandLetrec(e);
case STRCELL :
case BIGCELL :
case CHARCELL : return e;
-
+#if IPARAM
+ case IPVAR : return nameId;
+#endif
case FINLIST : mapOver(translate,snd(e));
return mkConsList(snd(e));
nv));
}
- default : fprintf(stderr, "stuff=%d\n",whatIs(e));internal("translate");
+ default : fprintf(stderr, "stuff=%d\n",whatIs(e));
+ internal("translate");
}
return e;
}
static Void local transAlt(e) /* Translate alt: */
Cell e; { /* ([Pat], Rhs) ==> ([Pat], Rhs') */
+#if 0
+ printf ( "transAlt: " );print(snd(e),100);printf("\n");
+#endif
snd(e) = transRhs(snd(e));
}
List bs; { /* eliminating pattern matching on */
List newBinds = NIL; /* lhs of bindings. */
for (; nonNull(bs); bs=tl(bs)) {
+#if IPARAM
+ Cell v = fst(hd(bs));
+ while (isAp(v) && fst(v) == nameInd)
+ v = arg(v);
+ fst(hd(bs)) = v;
+ if (isVar(v)) {
+#else
if (isVar(fst(hd(bs)))) {
+#endif
mapProc(transAlt,snd(hd(bs)));
newBinds = cons(hd(bs),newBinds);
}
case STRCELL :
case CHARCELL :
-#if NPLUSK
case ADDPAT :
-#endif
case TUPLE :
case NAME : return pat;
Cell h = getHead(p);
if (h==nameFromInt || h==nameFromInteger || h==nameFromDouble)
return p;
-#if NPLUSK
else if (whatIs(h)==ADDPAT)
return ap(fun(p),refutePat(arg(p)));
-#endif
#if TREX
else if (isExt(h)) {
Cell pf = refutePat(extField(p));
if (h==nameFromInt ||
h==nameFromInteger || h==nameFromDouble)
return WILDCARD;
-#if NPLUSK
else if (whatIs(h)==ADDPAT)
return pat;
-#endif
#if TREX
else if (isExt(h)) {
Cell pf = matchPat(extField(pat));
return remPat(snd(pat),nv,lds);
}
-#if NPLUSK
case ADDPAT : return remPat1(arg(pat), /* n + k = expr */
ap(ap(ap(namePmSub,
arg(fun(pat))),
mkInt(snd(fun(fun(pat))))),
expr),
lds);
-#endif
case FINLIST : return remPat1(mkConsList(snd(pat)),expr,lds);
case AP : return pmcPair(co,sc,e);
-#if NPLUSK
case ADDPAT :
-#endif
#if TREX
case EXT :
#endif
Cell h = getHead(p);
switch (whatIs(h)) {
case CONFLDS : return fst(snd(p));
-#if NPLUSK
case ADDPAT : arg(fun(p)) = translate(arg(fun(p)));
return fun(p);
-#endif
#if TREX
case EXT : h = fun(fun(p));
arg(h) = translate(arg(h));
case CHARCELL : return 0;
#if TREX
case AP : switch (whatIs(fun(d))) {
-#if NPLUSK
case ADDPAT : return 1;
-#endif
case EXT : return 2;
default : return 0;
}
#else
-#if NPLUSK
case AP : return (whatIs(fun(d))==ADDPAT) ? 1 : 0;
-#else
- case AP : return 0; /* must be an Int or Float lit */
-#endif
#endif
}
internal("discrArity");
static Bool local eqNumDiscr(d1,d2) /* Determine whether two numeric */
Cell d1, d2; { /* descriptors have same value */
-#if NPLUSK
if (whatIs(fun(d1))==ADDPAT)
return whatIs(fun(d2))==ADDPAT && snd(fun(d1))==snd(fun(d2));
-#endif
if (isInt(arg(d1)))
return isInt(arg(d2)) && intOf(arg(d1))==intOf(arg(d2));
if (isFloat(arg(d1)))
/* Run thread (and any other runnable threads) */
/* Re-initialise the scheduler - ToDo: do I need this? */
- initScheduler();
+ /* JRS, 991118: on SM's advice, don't call initScheduler every time.
+ This causes an assertion failure in GC.c(revert_dead_cafs)
+ unless doRevertCAFs below is permanently TRUE.
+ */
+ /* initScheduler(); */
#ifdef CRUDE_PROFILING
cp_init();
#endif
- /* ToDo: don't really initScheduler every time. fix */
{
HaskellObj result; /* ignored */
sighandler_t old_ctrlbrk;
SchedulerStatus status;
- old_ctrlbrk = signal(SIGINT, eval_ctrlbrk);
- assert(old_ctrlbrk != SIG_ERR);
- status = rts_eval_(closureOfVar(v),10000,&result);
+ Bool doRevertCAFs = TRUE; /* do not change -- comment above */
+ old_ctrlbrk = signal(SIGINT, eval_ctrlbrk);
+ ASSERT(old_ctrlbrk != SIG_ERR);
+ status = rts_eval_(closureOfVar(v),10000,&result);
signal(SIGINT,old_ctrlbrk);
+ fflush (stderr);
+ fflush (stdout);
switch (status) {
case Deadlock:
- case AllBlocked: /* I don't understand the distinction - ADR */
- printf("{Deadlock}");
- RevertCAFs();
+ printf("{Deadlock or Blackhole}");
+ if (doRevertCAFs) RevertCAFs();
break;
case Interrupted:
printf("{Interrupted}");
- RevertCAFs();
+ if (doRevertCAFs) RevertCAFs();
break;
case Killed:
- printf("{Killed}");
- RevertCAFs();
+ printf("{Interrupted or Killed}");
+ if (doRevertCAFs) RevertCAFs();
break;
case Success:
- //fflush(stderr);fflush(stdout);
- //fprintf(stderr, "\n\nFinal top-of-stack is\n" );
- //printObj ( *(MainRegTable.rSp) );
- RevertCAFs();
+ if (doRevertCAFs) RevertCAFs();
break;
default:
internal("evalExp: Unrecognised SchedulerStatus");
}
+ deleteAllThreads();
fflush(stdout);
fflush(stderr);
}
Target i = 0;
List binds = NIL;
- /* a nasty hack. But I don't know an easier way to make */
- /* these things appear. */
- if (lastModule() == modulePrelude) {
- implementCfun ( nameCons, NIL );
- implementCfun ( nameNil, NIL );
- implementCfun ( nameUnit, NIL );
- }
-
{
List vss;
List vs;
binds = addGlobals(binds);
done();
-#if USE_HUGS_OPTIMIZER
- if (optimise) {
- t = length(binds);
- setGoal("Simplifying",t);
- optimiseTopBinds(binds);
- done();
- }
-#endif
setGoal("Generating code",t);
stgCGBinds(binds);
Name n; { /* generated function */
List defs = name(n).defn;
Int arity = length(fst(hd(defs)));
+#if 0
+ printf ( "compGenFn: " );print(defs,100);printf("\n");
+#endif
compiler(RESET);
currentName = n;
mapProc(transAlt,defs);
Void compiler(what)
Int what; {
switch (what) {
- case INSTALL :
+ case PREPREL :
case RESET : freeVars = NIL;
freeFuns = NIL;
freeBegin = mkOffset(0);
- //extraVars = NIL;
- //numExtraVars = 0;
- //localOffset = 0;
- //localArity = 0;
break;
case MARK : mark(freeVars);
mark(freeFuns);
- //mark(extraVars);
break;
+
+ case POSTPREL: break;
}
}