Beispiel #1
0
        static public object Initial(SCode expression, Environment environment)
        {
            object answer;

            Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
#if DEBUG
            Timer tosProbe = new Timer(SCode.TopOfStackProbe, null, 5, 3);
            SCode.topOfStackTimer = tosProbe;
#endif
            Control residual = expression.PartialEval(PartialEnvironment.Make((ITopLevelEnvironment)environment)).Residual;
            while (true)
            {
                answer = null;
                while (residual.EvalStep(out answer, ref residual, ref environment))
                {
                }
                ;
                if (answer == Interpreter.UnwindStack)
                {
                    // What are we doing here?  Someone unwound the stack!
                    // There are three possibilities to consider:
                    //  1) A cwcc has just performed a destructive read of the stack.
                    //     In this case, we convert the newly captured frame list
                    //     into a control point and reload it.
                    //
                    //  2) A within-continuation has blown away the stack in order
                    //     to install a different control point.  In this case we
                    //     reload the control point that was stored in the UnwinderState.
                    //
                    //  3) The stack was unwound in order to exit the interpreter.
                    //     In this case, we return from the initial continuation.
                    if (((UnwinderState)environment).IsExit)
                    {
                        answer = ((UnwinderState)environment).ExitValue;
                        break;
                    }
                    else
                    {
                        ControlPoint stateToRestore = ((UnwinderState)environment).ToControlPoint();

                        // the receiver gets control when the stack is put back.
                        Control receiver = ((UnwinderState)environment).Receiver;

                        // the rewind state goes in the closureEnvironment
                        environment = new RewindState(stateToRestore, receiver);

                        // Start reloading by returning control to the lowest
                        // frame.
                        residual = ((RewindState)environment).PopFrame();
                    }
                }
            }
            Debug.WriteLine("Interpreter exited with value " + answer.ToString());
            return(answer);
        }
Beispiel #2
0
        public static bool ScodeEval(out object answer, object arg0, object arg1)
        {
            Environment env = Environment.ToEnvironment(arg1);
            //CompileTimeEnvironment ctenv = (env is StandardEnvironment)
            //    ? new CompileTimeEnvironment (((StandardEnvironment) env).Closure.Lambda.Formals)
            //    : new CompileTimeEnvironment (null);
            SCode sarg0 = SCode.EnsureSCode(arg0);

            answer = new TailCallInterpreter(sarg0.PartialEval(PartialEnvironment.Make((ITopLevelEnvironment)env)).Residual, env);
            return(true);
        }