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 CatFxnType GetFxnType() { if (mpFxnType == null) { mpFxnType = CatTypeReconstructor.Infer(this); } Trace.Assert(mpFxnType != null); return(mpFxnType); }
public static CatFxnType ComposeTypes(CatFxnType left, CatFxnType right) { if (!Config.gbTypeChecking) { return(null); } CatTypeReconstructor inferer = new CatTypeReconstructor(); return(inferer.LocalComposeTypes(left, right)); }
public override void Eval(Executor exec) { QuotedFunction f = exec.TypedPeek <QuotedFunction>(); bool bVerbose = Config.gbVerboseInference; bool bInfer = Config.gbTypeChecking; Config.gbVerboseInference = true; Config.gbTypeChecking = true; try { CatFxnType ft = CatTypeReconstructor.Infer(f.GetSubFxns()); if (ft == null) { Output.WriteLine("type could not be inferred"); } } finally { Config.gbVerboseInference = bVerbose; Config.gbTypeChecking = bInfer; } }
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 PushFunction(CatExpr children) { mSubFxns = children.GetRange(0, children.Count); msDesc = "pushes an anonymous function onto the stack"; msName = "_function_"; if (Config.gbTypeChecking) { if (Config.gbVerboseInference) { Output.WriteLine("inferring type of quoted function " + msName); } try { // Quotations can be unclear? CatFxnType childType = CatTypeReconstructor.Infer(mSubFxns); // Honestly this should never be true. if (childType == null) { throw new Exception("unknown type error"); } mpFxnType = new CatQuotedType(childType); mpFxnType = CatVarRenamer.RenameVars(mpFxnType); } catch (Exception e) { Output.WriteLine("Could not type quotation: " + msName); Output.WriteLine("Type error: " + e.Message); mpFxnType = null; } } else { mpFxnType = null; } }
public QuotedFunction(CatExpr children) : this(children, CatTypeReconstructor.Infer(children)) { }
public static CatFxnType ComposeFxnTypes(CatFxnType f, CatFxnType g) { CatFxnType ft = CatTypeReconstructor.ComposeTypes(f, g); return(ft); }
public static CatFxnType ComposeTypes(CatFxnType left, CatFxnType right) { if (!Config.gbTypeChecking) return null; CatTypeReconstructor inferer = new CatTypeReconstructor(); return inferer.LocalComposeTypes(left, right); }