AbSyn compFileFront(EmitInfo finfo, Stab stab, FILE *fin, int *plno) { FileName fn = emitSrcFile(finfo); AbSyn ab; FTypeNo ft = ftypeNo(fnameType(fn)); if (ft == FTYPENO_OLDABSYN) { comsgWarning(NULL, ALDOR_W_OldTypeAbsyn, cmdName); } if ((ft == FTYPENO_ABSYN) || (ft == FTYPENO_OLDABSYN)) { ab = compPhaseLoadAbSyn(finfo); } else { SrcLineList sll; TokenList tl; sll = compPhaseInclude(finfo, fin, plno); fintGetInitCompTime(); if (!compIsMoreAfterInclude(finfo)) { inclFree(sll); return 0; } tl = compPhaseScan (finfo, sll); tl = compPhaseSysCmd (finfo, tl); tl = compPhaseLinear (finfo, tl); ab = compPhaseParse (finfo, tl); inclFree(sll); listFreeDeeply(Token)(tl,tokFree); if (comsgErrorCount()) return ab; } ab = compPhaseAbNorm (finfo, ab, false); ab = compPhaseMacEx (finfo, ab); if (comsgErrorCount()) return ab; ab = compPhaseAbNorm (finfo, ab, true); ab = compPhaseAbCheck(finfo, ab); /* creates the .ax file */ if (!compIsMoreAfterSyntax(finfo)) return ab; compPhaseScoBind(finfo, stab, ab); if (comsgErrorCount()) { if (fintMode == FINT_LOOP) scoSetUndoState(); return ab; } compPhaseTInfer (finfo, stab, ab); if (comsgErrorCount()) { if (fintMode == FINT_LOOP) scoSetUndoState(); return ab; } return ab; }
local void testSymeSExpr() { String aSimpleDomain = "+++Comment\nDom: Category == with {f: () -> () ++ f\n}"; StringList lines = listList(String)(1, aSimpleDomain); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); initFile(); Stab stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); scopeBind(stab, absyn); typeInfer(stab, absyn); testTrue("Declare is sefo", abIsSefo(absyn)); testIntEqual("Error Count", 0, comsgErrorCount()); SymeList symes = stabGetMeanings(stab, ablogFalse(), symInternConst("Dom")); testIntEqual("unique meaning", 1, listLength(Syme)(symes)); Syme syme = car(symes); SExpr sx = symeSExprAList(syme); finiFile(); }
int compCFile(EmitInfo finfo) { compFileInit(finfo); compPhasePutObject(finfo); compFileFini(finfo); return comsgErrorCount(); }
Bool compIsMoreAfterInclude(EmitInfo finfo) { if (comsgErrorCount() != 0) return false; if (fintMode == FINT_LOOP) return true; return emitIsOutputNeeded(finfo, FTYPENO_ABSYN) || emitIsOutputNeeded(finfo, FTYPENO_OLDABSYN) || compIsMoreAfterSyntax(finfo); }
local void testAblog() { initFile(); ablogDebug = 0; String Boolean_imp = "import from Boolean"; String C0_def = "C0: Category == with"; String C1_def = "C1: Category == C0 with"; String D0_def = "D0: C0 with == add"; String D1_def = "D1: C1 with == add"; StringList lines = listList(String)(5, Boolean_imp, C0_def, C1_def, D0_def, D1_def); AbSynList code = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, code); abPutUse(absyn, AB_Use_NoValue); Stab file = stabFile(); Stab stab = stabPushLevel(file, sposNone, STAB_LEVEL_LARGE); scopeBind(stab, absyn); typeInfer(stab, absyn); testTrue("Declare is sefo", abIsSefo(absyn)); testIntEqual("Error Count", 0, comsgErrorCount()); Syme C0 = uniqueMeaning(stab, "C0"); Syme C1 = uniqueMeaning(stab, "C1"); Syme D0 = uniqueMeaning(stab, "D0"); Syme D1 = uniqueMeaning(stab, "D1"); AbSyn sefo1 = has(abFrSyme(D1), abFrSyme(C1)); AbSyn sefo0 = has(abFrSyme(D1), abFrSyme(C0)); tiSefo(stab, sefo0); tiSefo(stab, sefo1); AbLogic cond0 = ablogFrSefo(sefo0); AbLogic cond1 = ablogFrSefo(sefo1); afprintf(dbOut, "Implies: %pAbLogic %pAbLogic %d\n", cond1, cond0, ablogImplies(cond1, cond0)); afprintf(dbOut, "Implies: %pAbLogic %pAbLogic %d\n", cond0, cond1, ablogImplies(cond0, cond1)); testTrue("00", ablogImplies(cond0, cond0)); testTrue("10", ablogImplies(cond1, cond0)); testFalse("01",ablogImplies(cond0, cond1)); testTrue("11", ablogImplies(cond1, cond1)); }
Bool compIsMoreAfterSyntax(EmitInfo finfo) { if (comsgErrorCount() != 0) return false; if (fintMode == FINT_LOOP) return true; return emitIsOutputNeeded(finfo, FTYPENO_INTERMED) || emitIsOutputNeeded(finfo, FTYPENO_FOAMEXPR) || emitIsOutputNeeded(finfo, FTYPENO_SYMEEXPR) || emitIsOutputNeeded(finfo, FTYPENO_C) || emitIsOutputNeeded(finfo, FTYPENO_CPP) || emitIsOutputNeeded(finfo, FTYPENO_LISP) || emitIsOutputNeeded(finfo, FTYPENO_JAVA) || emitIsOutputNeeded(finfo, FTYPENO_EXEC); }
int compGLoopFinish(FileName fn, EmitInfo finfo) { int totErrors = comsgErrorCount(); /* Prevent calling gc upon exit */ stoCtl(StoCtl_GcLevel, StoCtl_GcLevel_Never); fintFini(); compFileFini(finfo); emitAllDone(); emitInfoFree(finfo); fnameFree(fn); compFini(); return totErrors; }
/* * Compile .fm or .ao file, returning error count. */ int compSavedFile(EmitInfo finfo) { Foam foam; Stab stab; compFileInit(finfo); stab = stabFile(); foam = compFileLoadFoam(finfo); compFileSave(finfo, stab, foam); compFileBack(finfo, foam); foamFree(foam); compFileFini(finfo); return comsgErrorCount(); }
local void testForeign() { String Boolean_imp = "import from Boolean"; String P_def = "Pointer: with == add"; String C_def = "C: with == add"; String F_def = "Foreign(T: Type): with == add"; String R_def = "R == Record(x: Pointer)"; String fn_imp = "import { fn: R -> () } from Foreign C"; String tst_def = "test(p: R): () == fn(p)"; StringList lines = listList(String)(7, Boolean_imp, P_def, C_def, F_def, R_def, fn_imp, tst_def); AbSynList absynList = listCons(AbSyn)(stdtypes(), abqParseLines(lines)); AbSyn absyn = abNewSequenceL(sposNone, absynList); Stab stab; Foam foam; initFile(); stab = stabFile(); abPutUse(absyn, AB_Use_NoValue); abPrintDb(absyn); scopeBind(stab, absyn); typeInfer(stab, absyn); testIntEqual("Error Count", 0, comsgErrorCount()); foam = generateFoam(stab, absyn, "test"); /* At this point, we should check that the 'test' function * calls 'fn' with a type of FOAM_Rec. In order to do this * nicely, there should be a decent way of searching a blob of * foam for certain properties. */ #if 0 FoamList pcall = foamFind(fmfAnd(fmfFoamTag(FOAM_PCall), fmfPCallProto(FOAM_Proto_C)), foam); testAIntEqual(FOAM_Rec, foamExprType(foam, pcall->first->foamPCall.argv[0])) #endif }
/* * Compile .as file, returning error count. */ int compSourceFile(EmitInfo finfo) { AbSyn ab; Stab stab; Foam foam; int msgCount; compFileInit(finfo); breakSetRoot(NULL); stab = stabFile(); ab = compFileFront(finfo, stab, NULL, NULL); breakSetRoot(ab); if (emitIsOutputNeededOrWarn(finfo, FTYPENO_CPP)) { /* Need to inspect finfo to get the filename */ FileName fn = emitFileName(finfo, FTYPENO_INTERMED); genCpp(ab,fnameDir(fn),fnameName(fn)); emitTheCpp(); } if (compIsMoreAfterFront(finfo)) { foam = compFileMiddle(finfo, stab, ab); compFileSave(finfo, stab, foam); compFileBack(finfo, foam); foamFree(foam); } msgCount = comsgErrorCount(); compFileFini(finfo); /* abFree(ab); !! ab is seeping into types. */ if (msgCount < 1) breakInterrupt(); return msgCount; }
int compInteractiveLoop(int argc, char **argv, FILE *fin, FILE *fout) { int iargc, totErrors, lineno; FileName fn; EmitInfo finfo; AbSyn ab; Stab stab; Foam foam; Bool readingInitFile = true, tmpHistory; Bool endOfInput = false; FILE *fin0 = fin; compInit(); iargc = cmdArguments(1, argc, argv); argc -= iargc; argv += iargc; emitDoneOptions(argc, argv); if (osFileIsThere(cmdInitFile)) { FileName fname; fname = fnameParse(cmdInitFile); fin = fileMustOpen(fname, osIoRdMode); fnameFree(fname); intStepNo = 0; tmpHistory = fintHistory; fintHistory = false; fprintf(fout, "Reading %s...\n", cmdInitFile); } else { intStepNo = 1; readingInitFile = false; tmpHistory = fintHistory; } fn = fnameStdin(); finfo = emitInfoNew(fn); lineno = 0; compFileInit(finfo); stab = stabFile(); comsgFini(); fintInit(); for (; !endOfInput; intStepNo++) { comsgInit(); breakSetRoot(NULL); car(stab)->isChecked = false; if (SetJmp(compFintJmpBuf)) { if (feof(fin)) break; } comsgPromptPrint(fin, fout, fintHistory ? "%%%d := " : "%%%d >> ", intStepNo); osSetBreakHandler(compFintBreakHandler0); ab = compFileFront(finfo, stab, fin, &lineno); breakSetRoot(ab); if (compIsMoreAfterFront(finfo) && !abIsEmptySequence(ab)) { ab = (AbSyn) fintWrap(ab, intStepNo); foam = compFileMiddle(finfo, stab, ab); if (foam) { Bool ok = fint(foam); if (ok && fintVerbose) fintPrintType(fout, ab); foamFree(foam); fintDisplayTimings(); } } comsgFini(); /* abFree(ab); !! ab is seeping into types. */ if (feof(fin)) { if (readingInitFile) { fclose(fin); fin = fin0; lineno = 0; readingInitFile = false; fintHistory = tmpHistory; intStepNo = 0; comsgFini(); } else endOfInput = true; } } totErrors = comsgErrorCount(); fintFini(); compFileFini(finfo); emitAllDone(); emitInfoFree(finfo); fnameFree(fn); compFini(); return totErrors; }