Exemplo n.º 1
0
 public static void OutputInferredType(CatFxnType ft)
 {
     Log("After rewriting");
     Log(ft.ToPrettyString());
     Log("");
 }
Exemplo n.º 2
0
 public static void OutputInferredType(CatFxnType ft)
 {
     Log("After rewriting");
     Log(ft.ToPrettyString());
     Log("");
 }
Exemplo n.º 3
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);
        }