Пример #1
0
        public override bool EvalStep(out object answer, ref Control expression, ref Environment environment)
        {
#if DEBUG
            Warm("-");
            NoteCalls(this.lambda.Body);
            NoteCalls(this.rand);
            randTypeHistogram.Note(this.randType);
            bodyTypeHistogram.Note(this.bodyType);
            SCode.location = "SimpleLet1";
#endif

            object      evarg = null;
            Control     unev  = this.rand;
            Environment env   = environment;
            while (unev.EvalStep(out evarg, ref unev, ref env))
            {
            }
            ;
#if DEBUG
            SCode.location = "SimpleLet1";
#endif
            if (evarg == Interpreter.UnwindStack)
            {
                ((UnwinderState)env).AddFrame(new Let1Frame0(this, environment));
                answer      = Interpreter.UnwindStack;
                environment = env;
                return(false);
            }

            // this.closeCount += 1;
            // Use the base environment for lookup.
            object [] cells = environment.GetValueCells(this.lambda.StaticMapping);
#if DEBUG
            SCode.location = "SimpleLet1";
#endif
            SimpleClosure cl = new SimpleClosure(this.lambda, environment.BaseEnvironment, cells);


//            object evop = null;
//            Control unevop = this.rator;
//            env = environment;
//            while (unevop.EvalStep (out evop, ref unevop, ref env)) { };
//#if DEBUG
//            SCode.location = "SimpleLet1";
//#endif
//            if (evop == Interpreter.UnwindStack) {
//                throw new NotImplementedException ();
//                //((UnwinderState) env).AddFrame (new Combination1Frame1 (this, environment, evarg));
//                //answer = Interpreter.UnwindStack;
//                //environment = env;
//                //return false;
//            }
            expression  = this.lambda.Body;
            environment = new SmallEnvironment1(cl, evarg);
            answer      = null; // keep the compiler happy
            return(true);

            // return cl.Call (out answer, ref expression, ref environment, evarg);
        }
Пример #2
0
        public override bool EvalStep(out object answer, ref Control expression, ref Environment environment)
        {
#if DEBUG
            Warm("-");
            SCode.location = "Letrec1";
#endif
            object [] outerStaticCells = environment.StaticCells;
            object [] innerStaticCells = new object [outerStaticCells.Length + 1];
            for (int i = 0; i < outerStaticCells.Length; i++)
            {
                innerStaticCells [i + 1] = outerStaticCells [i];
            }
            SimpleClosure rec = new SimpleClosure(this.innerLambda, environment.BaseEnvironment, innerStaticCells);
            innerStaticCells [0] = rec;
            answer = rec;
            return(false);


//            object [] valueCells = environment.GetValueCells (this.lambda.StaticMapping);
//            object [] foo = environment.StaticCells;
//            if (foo != valueCells) throw new NotImplementedException ();
//#if DEBUG
//            SCode.location = "Letrec1";
//#endif
//            StaticClosure cl = new StaticClosure (this.lambda, environment.BaseEnvironment, valueCells);
//            Environment closed = new StaticEnvironment (cl, new object [] { this.rand0Value });

//            this.innerLambda.closeCount += 1;
//            object [] staticCells = closed.GetValueCells (this.innerLambda.StaticMapping);
//#if DEBUG
//            SCode.location = "Letrec1";
//#endif
//            // Use the base environment for lookup.
//            SimpleClosure newValue = new SimpleClosure (this.innerLambda, closed.BaseEnvironment, staticCells);

//            if (closed.AssignArgument0 (out answer, newValue)) throw new NotImplementedException ();

//            answer = newValue;
//            return false;
        }