Пример #1
0
        public int GetMaxConsumption()
        {
            int nCnt = 0;

            List <CatKind> list = mCons.GetKinds();

            for (int i = list.Count - 1; i >= 0; --i)
            {
                CatKind k = list[i];
                if (k is CatStackVar)
                {
                    if ((i == 0) && k.Equals(mProd.GetBottom()))
                    {
                        return(nCnt);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                nCnt++;
            }

            return(nCnt);
        }
Пример #2
0
        public override bool Equals(CatKind k)
        {
            if (!(k is CatTypeVector))
            {
                return(false);
            }
            CatTypeVector v1 = this;
            CatTypeVector v2 = k as CatTypeVector;

            while (!v1.IsEmpty() && !v2.IsEmpty())
            {
                CatKind t1 = v1.GetTop();
                CatKind t2 = v2.GetTop();
                if (!t1.Equals(t2))
                {
                    return(false);
                }
                v1 = v1.GetRest();
                v2 = v2.GetRest();
            }
            if (!v1.IsEmpty())
            {
                return(false);
            }
            if (!v2.IsEmpty())
            {
                return(false);
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// This function modifies the function
        /// </summary>
        public void RemoveImplicitRhoVariables(CatFxnType ft)
        {
            foreach (CatKind k in ft.GetChildKinds())
            {
                if (k is CatFxnType)
                {
                    RemoveImplicitRhoVariables(k as CatFxnType);
                }
            }

            if (!ft.GetCons().IsEmpty() && !ft.GetProd().IsEmpty())
            {
                CatKind k1 = ft.GetCons().GetBottom();
                CatKind k2 = ft.GetProd().GetBottom();

                // Does both consumption and production share the same
                // stack variable at the bottom, if so, then we might have
                // an implicit Rho variables
                if (k1 is CatStackVar && k1.Equals(k2))
                {
                    // try removing the stack variable
                    ft.GetCons().GetKinds().RemoveAt(0);
                    ft.GetProd().GetKinds().RemoveAt(0);

                    // is the variable used anywhere else?
                    // if so, then we have to restore it
                    // otherwise we leave it taken away
                    if (DoesVarExist(k1))
                    {
                        ft.GetCons().GetKinds().Insert(0, k1);
                        ft.GetProd().GetKinds().Insert(0, k2);
                    }
                }
            }
        }