/// <summary> /// Compares two function types, by first normalizing so that they each have /// names of variables that correspond to the locations in the function /// </summary> public static bool CompareFxnTypes(CatFxnType f, CatFxnType g) { CatFxnType f2 = CatVarRenamer.RenameVars(f.AddImplicitRhoVariables()); CatFxnType g2 = CatVarRenamer.RenameVars(g.AddImplicitRhoVariables()); return(f2.IsSubtypeOf(g2)); }
public Method(Object o, MethodInfo mi) : base(mi.Name, "undocumented method from CLR") { mMethod = mi; mObject = o; string sType = MethodToTypeString(mi); mpFxnType = CatFxnType.Create(sType); mpFxnType = CatVarRenamer.RenameVars(mpFxnType); }
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 PrimitiveFunction(string sName, string sType, string sDesc, string sTags) : base(sName, sDesc, sTags) { mpFxnType = CatFxnType.Create(sType); mpFxnType = CatVarRenamer.RenameVars(mpFxnType); }
public CatFxnType LocalComposeTypes(CatFxnType left, CatFxnType right) { // Make sure that the variables on the left function and the variables // on the right function are different CatVarRenamer renamer = new CatVarRenamer(); left = renamer.Rename(left.AddImplicitRhoVariables()); renamer.ResetNames(); right = renamer.Rename(right.AddImplicitRhoVariables()); Log("=="); Log("Composing : " + left.ToString()); Log("with : " + right.ToString()); Log("Adding constraints"); Relation rLeft = FxnTypeToRelation(left); Relation rRight = FxnTypeToRelation(right); //TODO: remove //rLeft.UnrollRecursiveRelations(); //rRight.UnrollRecursiveRelations(); Relation result = new Relation(rLeft.GetLeft(), rRight.GetRight()); AddTopLevelConstraints(rLeft.GetRight(), rRight.GetLeft()); AddConstraint(CreateVar("result$"), result); Log("Constraints"); ComputeConstraintLists(); LogConstraints(); Log("Unifiers"); ComputeUnifiers(); foreach (string sVar in GetConstrainedVars()) { Constraint u = GetUnifierFor(sVar); Log("var: " + sVar + " = " + u); } Log("Composed Type"); Constraint c = GetResolvedUnifierFor("result$"); if (!(c is Relation)) throw new Exception("Resolved type is not a relation"); // TODO: remove // Relation r = c as Relation; // r.RollupRecursiveRelations(); CatKind k = ConstraintToCatKind(c); CatFxnType ft = k as CatFxnType; Log("raw type : " + ft.ToString()); Log("pretty type : " + ft.ToPrettyString()); Log("=="); CheckConstraintQueueEmpty(); // Check if the relation was valid, and thus the function type if (!ft.IsValid()) throw new Exception("invalid function type: " + ft.ToString()); return ft; }
public CatFxnType LocalComposeTypes(CatFxnType left, CatFxnType right) { // Make sure that the variables on the left function and the variables // on the right function are different CatVarRenamer renamer = new CatVarRenamer(); left = renamer.Rename(left.AddImplicitRhoVariables()); renamer.ResetNames(); right = renamer.Rename(right.AddImplicitRhoVariables()); Log("=="); Log("Composing : " + left.ToString()); Log("with : " + right.ToString()); Log("Adding constraints"); Relation rLeft = FxnTypeToRelation(left); Relation rRight = FxnTypeToRelation(right); //TODO: remove //rLeft.UnrollRecursiveRelations(); //rRight.UnrollRecursiveRelations(); Relation result = new Relation(rLeft.GetLeft(), rRight.GetRight()); AddTopLevelConstraints(rLeft.GetRight(), rRight.GetLeft()); AddConstraint(CreateVar("result$"), result); Log("Constraints"); ComputeConstraintLists(); LogConstraints(); Log("Unifiers"); ComputeUnifiers(); foreach (string sVar in GetConstrainedVars()) { Constraint u = GetUnifierFor(sVar); Log("var: " + sVar + " = " + u); } Log("Composed Type"); Constraint c = GetResolvedUnifierFor("result$"); if (!(c is Relation)) { throw new Exception("Resolved type is not a relation"); } // TODO: remove // Relation r = c as Relation; // r.RollupRecursiveRelations(); CatKind k = ConstraintToCatKind(c); CatFxnType ft = k as CatFxnType; Log("raw type : " + ft.ToString()); Log("pretty type : " + ft.ToPrettyString()); Log("=="); CheckConstraintQueueEmpty(); // Check if the relation was valid, and thus the function type if (!ft.IsValid()) { throw new Exception("invalid function type: " + ft.ToString()); } return(ft); }