Beispiel #1
0
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();
}
Beispiel #2
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();
}
Beispiel #3
0
/*
 * Usage: showexports libName type-expression
 * Example: showexports libaldor.al 'List(Integer)'
 */
int
main(int argc, char *argv[])
{
	osInit();
	sxiInit();
	keyInit();
	ssymInit();
	dbInit();
	stabInitGlobal();
	tfInit();
	foamInit();
	optInit();
	tinferInit();
	pathInit();

	sposInit();
	ablogInit();
	comsgInit();

	macexInitFile();
	comsgInit();
	scobindInitFile();
	stabInitFile();

	fileAddLibraryDirectory(".");

	String archive = argv[1];
	String expression = argv[2];

	scmdHandleLibrary("LIB", archive);

	AbSyn ab = shexpParse(expression);
	Stab stab = stabFile();
	Syme syme = stabGetArchive(symInternConst("LIB"));
	AbSyn arAbSyn = abNewId(sposNone, symInternConst("LIB"));

	stabImportTForm(stab, tiGetTForm(stab, arAbSyn));
	abPutUse(ab, AB_Use_Value);
	scopeBind(stab, ab);
	typeInfer(stab, ab);
	TForm tf = tiGetTForm(stab, ab);

	SymeList list = tfStabGetDomImports(stab, tf);

	for (; list != listNil(Syme); list = cdr(list)) {
		Syme syme = car(list);
		aprintf("%s %d %d %s\n", symeString(syme),
			symeDefnNum(syme), symeConstNum(syme), tfPretty(symeType(syme)));
	}

	scobindFiniFile();
	stabFiniFile();
	comsgFini();
	macexFiniFile();

}
Beispiel #4
0
AbSyn
compPhaseTInfer(EmitInfo finfo, Stab stab, AbSyn ab)
{
	phStart(PH_TInfer);

	typeInfer(stab, ab);		/* annotates the tree in-place */

	phEnd((PhPrFun) abPrint, (PhPrFun) abPrettyPrint, (Pointer) ab);
	return ab;
}
Beispiel #5
0
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));
}
Beispiel #6
0
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
}
Beispiel #7
0
/*
 * Usage: showexports libName type-expression
 * Example: showexports libaldor.al 'List(Integer)'
 */
int
main(int argc, char *argv[])
{
	osInit();
	sxiInit();
	keyInit();
	ssymInit();
	dbInit();
	stabInitGlobal();
	tfInit();
	foamInit();
	optInit();
	tinferInit();
	pathInit();

	sposInit();
	ablogInit();
	comsgInit();

	macexInitFile();
	comsgInit();
	scobindInitFile();
	stabInitFile();

	fileAddLibraryDirectory(".");

	String archive = argv[1];
	String expression = argv[2];

	scmdHandleLibrary("LIB", archive);

	AbSyn ab = shexpParse(expression);
	Stab stab = stabFile();
	Syme syme = stabGetArchive(symInternConst("LIB"));
	AbSyn arAbSyn = abNewId(sposNone, symInternConst("LIB"));
	AbSyn boolean = abNewId(sposNone, symInternConst("Boolean"));

	stabImportTForm(stab, tiGetTForm(stab, arAbSyn));
	stabImportTForm(stab, tiGetTForm(stab, boolean));
	abPutUse(ab, AB_Use_Value);
	scopeBind(stab, ab);
	typeInfer(stab, ab);
	TForm tf = tiGetTForm(stab, ab);
	aprintf("Type: %s Cat: %d\n", tfPretty(tf), tfSatCat(tf));
	if (tfSatDom(tf)) {
		SymeList list = tfGetCatExports(tf);
		aprintf("Category\n");
		for (; list != listNil(Syme); list = cdr(list)) {
			Syme syme = car(list);
			aprintf("%5s %3d %s %pAbSynList\n", symeString(syme), symeHasDefault(syme),
				tfPretty(symeType(syme)), symeCondition(syme));
		}
	}
	else {
		aprintf(">>> Exports\n");
		SymeList list = tfStabGetDomImports(stab, tf);

		for (; list != listNil(Syme); list = cdr(list)) {
			Syme syme = car(list);
			aprintf("%s %d %d %s\n", symeString(syme),
				symeDefnNum(syme), symeConstNum(syme), tfPretty(symeType(syme)));
		}

		TQualList tqList;
		aprintf(">>> Cascades\n");
		tqList = tfGetDomCascades(tf);

		for (; tqList != listNil(TQual); tqList = cdr(tqList)) {
			TQual tq = car(tqList);
			aprintf("--> %s\n", tfPretty(tqBase(tq)));
		}
	}

	scobindFiniFile();
	stabFiniFile();
	comsgFini();
	macexFiniFile();

}