Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
 /// <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);
 }
Exemplo n.º 4
0
        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);
        }