public QuotedFunction(QuotedFunction first, QuotedFunction second) { mSubFxns = new CatExpr(first.GetSubFxns().ToArray()); mSubFxns.AddRange(second.GetSubFxns().ToArray()); msDesc = "anonymous composed function"; msName = ""; for (int i = 0; i < mSubFxns.Count; ++i) { if (i > 0) { msName += " "; } msName += mSubFxns[i].GetName(); } try { mpFxnType = new CatQuotedType(CatTypeReconstructor.ComposeTypes(first.GetFxnType(), second.GetFxnType())); // TODO: remove once everythign tests okay. //mpFxnType = new CatQuotedType(CatTypeReconstructor.ComposeTypes(first.GetUnquotedFxnType(), second.GetUnquotedFxnType())); } catch (Exception e) { Output.WriteLine("unable to type quotation: " + ToString()); Output.WriteLine("type error: " + e.Message); mpFxnType = null; } }
public void AddFunctions(CatExpr fxns) { mFunctions.AddRange(fxns); msDesc = ""; if (Config.gbVerboseInference && Config.gbTypeChecking) { Output.WriteLine(""); Output.WriteLine("inferring type of " + msName); Output.WriteLine("==="); } try { mpFxnType = CatTypeReconstructor.Infer(mFunctions); } catch (Exception e) { Output.WriteLine("type error in function " + msName); Output.WriteLine(e.Message); mpFxnType = null; } }
public CatExpr PatternToFxns(INameLookup names, List <AstMacroTerm> pattern) { CatExpr ret = new CatExpr(); foreach (AstMacroTerm t in pattern) { if (t is AstMacroTypeVar) { string s = t.ToString(); if (!mCapturedVars.ContainsKey(s)) { throw new Exception("macro variable " + s + " was not captured"); } CatExpr expr = mCapturedVars[s]; ret.AddRange(expr); } else if (t is AstMacroStackVar) { string s = (t as AstMacroStackVar).msName; if (!mCapturedVars.ContainsKey(s)) { throw new Exception("macro variable " + s + " was not captured"); } CatExpr expr = mCapturedVars[s]; ret.AddRange(expr); } else if (t is AstMacroName) { string s = t.ToString(); if (s.Length < 1) { throw new Exception("internal error: macro name is empty string"); } Function f = names.ThrowingLookup(s); if (f == null) { if (Char.IsDigit(s[0])) { f = new PushInt(int.Parse(s)); } else { throw new Exception("Could not find function " + s); } } ret.Add(f); } else if (t is AstMacroQuote) { // TODO: handle typed terms within a quotation. AstMacroQuote macroQuote = t as AstMacroQuote; List <AstMacroTerm> localPattern = macroQuote.mTerms; PushFunction q = new PushFunction(PatternToFxns(names, localPattern)); ret.Add(q); } else { throw new Exception("unrecognized macro term " + t.ToString()); } } return(ret); }