local void testSymeAddCondition() { String B_imp = "import from Boolean"; String C_txt = "C: Category == with"; String D1_txt = "D1: with == add"; String D2_txt = "D2: with == add"; StringList lines = listList(String)(4, B_imp, C_txt, D1_txt, D2_txt); 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); AbSyn D1 = abFrSyme(uniqueMeaning(stabFile(), "D1")); AbSyn D2 = abFrSyme(uniqueMeaning(stabFile(), "D2")); AbSyn C = abFrSyme(uniqueMeaning(stabFile(), "C")); Syme syme1 = symeNewExport(symInternConst("syme2"), tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme1, sefo(has(D1, C)), true); testIntEqual("test1", 1, listLength(Sefo)(symeCondition(syme1))); Syme syme2 = symeNewExport(symInternConst("syme1"),tfNewAbSyn(TF_General, id("D")), car(stab)); symeAddCondition(syme2, sefo(and(has(D1, C), has(D2, C))), true); testIntEqual("test2", 2, listLength(Sefo)(symeCondition(syme2))); finiFile(); }
AbSyn abqParse(String txt) { SrcLine srcLine = slineNew(sposNone, 0, txt); return abqParseSrcLines(listList(SrcLine)(1, srcLine)); }
int main() { FILE* I = fopen(INPUT_FILE, "r"); if(I == NULL) { printf("Error. Could not open %s.\n", INPUT_FILE); exit(-1); } FILE* O = fopen(OUTPUT_FILE, "w"); if(O == NULL) { printf("Error. Could not open %s.\n", OUTPUT_FILE); exit(-1); } int nSent; Country* Sent; int nCount; Country* hCount; Country* tCount; readFile(I, &nSent, &Sent, &nCount, &hCount, &tCount); listList(Sent, hCount, tCount);//DEBUG Battle(&Sent, &hCount, &tCount, O); return 0; }
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(); }
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)); }
local void testDocco() { StringList text; AbSyn code; initFile(); text = listList(String)(3, "+++ Words", "a: B;", " ++ more words"); code = abqParseLinesAsSeq(text); testAIntEqual("an id", AB_Declare, abTag(code)); testStringEqual("docs", " Words\n more words\n", docString(abComment(abDefineeId(code)))); text = listList(String)(2, "a: B;", " ++ some words"); code = abqParseLinesAsSeq(text); testAIntEqual("an id", AB_Declare, abTag(code)); testStringEqual("docs", " some words\n", docString(abComment(abDefineeId(code)))); text = listList(String)(2, "+++ ZZZ", "a: B;"); code = abqParseLinesAsSeq(text); testAIntEqual("an id", AB_Declare, abTag(code)); testStringEqual("docs", " ZZZ\n", docString(abComment(abDefineeId(code)))); finiFile(); }
local AbSyn shexpParse(String txt) { AbSyn ab; TokenList tl; SrcLineList sll; SrcLine srcLine = slineNew(sposNone, 0, txt); sll = listList(SrcLine)(1, srcLine); tl = scan(sll); tl = linearize(tl); ab = parse(&tl); ab = abNormal(ab, false); ab = macroExpand(ab); ab = abNormal(ab, true); return ab; }
AbSyn stdtypes() { String Type_txt = "Type: with == add"; String Category_txt = "Category: with == add"; String Tuple_txt = "Tuple(T: Type): with == add"; String Cross_txt = "Cross(T: Tuple Type): with == add"; String Generator_txt = "Generator(T: Type): with == add"; String Map_txt = "(->)(A: Tuple Type, R: Tuple Type): with == add"; String Boolean_txt = "Boolean: with == add"; String Join_txt = "Join(T: Tuple Category): Category == with"; String Record_txt = "Record(T: Tuple Type): with == add"; StringList lines = listList(String)(9, Type_txt, Category_txt, Cross_txt, Tuple_txt, Map_txt, Boolean_txt, Join_txt, Generator_txt, Record_txt); AbSynList code = abqParseLines(lines); AbSyn absyn = abNewSequenceL(sposNone, code); return absyn; }
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 }