Ejemplo n.º 1
0
 public CatFxnType GetFxnType()
 {
     if (mpFxnType == null)
     {
         mpFxnType = CatTypeReconstructor.Infer(this);
     }
     Trace.Assert(mpFxnType != null);
     return(mpFxnType);
 }
Ejemplo n.º 2
0
            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;
                }
            }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        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;
            }
        }
Ejemplo n.º 5
0
 public QuotedFunction(CatExpr children)
     : this(children, CatTypeReconstructor.Infer(children))
 {
 }