public static CatList MakeUnit(Object x) { CatList result = new CatList(); result.Add(x); return(result); }
public static CatList MakePair(Object first, Object second) { CatList result = new CatList(); result.Add(first); result.Add(second); return(result); }
public CatList ToArray() { CatList[] a = new CatList[mDict.Count]; int i = 0; foreach (KeyValuePair <Object, Object> pair in mDict) { a[i++] = CatList.MakePair(pair.Value, pair.Key); } return(new CatList(a)); }
public bool TestFunction(Function f) { bool bRet = true; testCount += 1; CatMetaDataBlock md = f.GetMetaData(); if (md != null) { List <CatMetaData> tests = md.FindAll("test"); foreach (CatMetaData test in tests) { CatMetaData input = test.Find("in"); CatMetaData output = test.Find("out"); if (input == null || output == null) { Output.WriteLine("ill-formed test in " + f.GetName()); return(false); } try { Executor aux = new Executor(this); aux.Execute(input.GetContent()); CatList listInput = aux.GetStackAsList(); aux.Clear(); aux.Execute(output.GetContent()); CatList listOutput = aux.GetStackAsList(); aux.Clear(); if (!listInput.Equals(listOutput)) { Output.WriteLine("failed test for instruction " + f.GetName()); Output.WriteLine("test input program = " + input.GetContent()); Output.WriteLine("test output program = " + output.GetContent()); Output.WriteLine("input program result = " + listInput.ToString()); Output.WriteLine("output program result = " + listOutput.ToString()); bRet = false; } } catch (Exception e) { Output.WriteLine("failed test for instruction " + f.GetName()); Output.WriteLine("exception occured: " + e.Message); bRet = false; } } } return(bRet); }
public CatList ToList() { CatList ret = new CatList(); ret.Add(GetLabel()); if (Count > 0) { foreach (CatMetaData child in this) { ret.Add(child); } } else { ret.Add(GetContent()); } return(ret); }
public override bool Equals(object obj) { if (!(obj is CatList)) { return(false); } CatList x = obj as CatList; if (Count != x.Count) { return(false); } for (int i = 0; i < Count; ++i) { if (!this[i].Equals(x[i])) { return(false); } } return(true); }