Ejemplo n.º 1
0
        internal override PartialResult PartialEval(PartialEnvironment environment)
        {
            bool changed = false;

            PartialResult [] ra = new PartialResult [this.components.Length];
            for (int i = 0; i < this.components.Length; i++)
            {
                ra [i] = this.components [i].PartialEval(environment);
                if (ra [i].Residual != this.components [i])
                {
                    changed = true;
                }
            }
            if (changed)
            {
                SCode [] components = new SCode [ra.Length];
                for (int i = 0; i < ra.Length; i++)
                {
                    components [i] = ra [i].Residual;
                }
                return(new PartialResult(new Combination(components)));
            }
            else
            {
                return(new PartialResult(this));
            }
        }
Ejemplo n.º 2
0
        internal override PartialResult PartialEval(PartialEnvironment environment)
        {
            PartialResult pred = this.predicate.PartialEval(environment);
            PartialResult alt  = this.alternative.PartialEval(environment);

            return(new PartialResult((pred.Residual == this.predicate &&
                                      alt.Residual == this.alternative) ? this : Disjunction.Make(pred.Residual, alt.Residual)));
        }
Ejemplo n.º 3
0
 public PartialClosure(LType lambda, PartialEnvironment environment)
 {
     this.lambda                    = lambda;
     this.environment               = environment;
     this.staticMapping             = environment.GetStaticMapping(lambda.FreeVariables);
     this.exportedTopLevelVariables = lambda.CallsTheEnvironment()
         ? noUnshadowedTopLevelVariables
         : ComputeUnshadowedTopLevelVariables(environment.TopLevelVariables, lambda.Formals);
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        internal override PartialResult PartialEval(PartialEnvironment environment)
        {
            PartialResult rator = this.components [0].PartialEval(environment);
            PartialResult rand0 = this.components [1].PartialEval(environment);
            PartialResult rand1 = this.components [2].PartialEval(environment);
            PartialResult rand2 = this.components [3].PartialEval(environment);

            return(new PartialResult(rator.Residual == this.components [0] &&
                                     rand0.Residual == this.components [1] &&
                                     rand1.Residual == this.components [2] &&
                                     rand2.Residual == this.components [3] ? this : Combination3.Make(rator.Residual, rand0.Residual, rand1.Residual, rand2.Residual)));
        }
Ejemplo n.º 7
0
        public static bool SystemPairCons(out object answer, object acode, object car, object cdr)
        {
            //TC typeCode = (TC) (int) acode; // for debugging porpoises

            switch ((TC)acode)
            {
            case TC.ACCESS:
                answer = Access.Make(car, (Symbol)cdr);
                break;

            case TC.ASSIGNMENT:
                answer = Assignment.Make(car, cdr);
                break;

            case TC.COMBINATION_1:
                answer = Combination1.Make(car, cdr);
                break;

            case TC.COMMENT:
                answer = Comment.Make(car, cdr);
                break;

            case TC.COMPLEX:
                answer = new Complex(car, cdr);
                break;

            case TC.DEFINITION:
                answer = Definition.Make((Symbol)car, cdr);
                break;

            case TC.DELAY:
                answer = new Delay(car, cdr);
                break;

            case TC.DISJUNCTION:
                answer = Disjunction.Make(car, cdr);
                break;

            case TC.ENTITY:
                answer = new Entity(car, cdr);
                break;

            case TC.LAMBDA:
                // passed in backwards.
                object [] names   = (object [])cdr;
                object [] formals = new object [names.Length - 1];
                Array.Copy(names, 1, formals, 0, formals.Length);
                SCode body = SCode.EnsureSCode(car);
                answer = Lambda.Make(names[0], formals, car);
                break;

            case TC.PCOMB1:
                answer = PrimitiveCombination1.Make((Primitive1)car, cdr);
                break;

            case TC.PROCEDURE:
                // Lambda had better be a `StandardLambda' because we are
                // constructing an closureEnvironment that needs to be first-class.

                Environment    env  = Environment.ToEnvironment(cdr);
                Lambda         ulam = (Lambda)car;
                Lambda         plam = (Lambda)ulam.PartialEval(PartialEnvironment.Make((ITopLevelEnvironment)env)).Residual;
                StandardLambda slam = (StandardLambda) new StandardLambda(plam.Name,
                                                                          plam.Formals,
                                                                          plam.Body,
                                                                          ulam.FreeVariables,
                                                                          plam.StaticMapping
                                                                          );
                answer = new StandardClosure(slam, env);
                break;

            case TC.RATNUM:
                answer = new Ratnum(car, cdr);
                break;

            case TC.SCODE_QUOTE:
                answer = Quotation.Make(car);
                break;

            case TC.SEQUENCE_2:
                answer = Sequence2.Make(car, cdr);
                break;

            case TC.UNINTERNED_SYMBOL:
                // What gives?  Uninterned strings are squirrely on the CLR.
                // We put them in a class object to have more control.
                answer = Symbol.MakeUninterned(new String((char [])car));
                break;

            case TC.WEAK_CONS:
                answer = new WeakCons(car, cdr);
                break;

            default:
                throw new NotImplementedException();
            }
            return(false);
        }
Ejemplo n.º 8
0
 internal override PartialResult PartialEval(PartialEnvironment environment)
 {
     return(new PartialResult(this));
 }
Ejemplo n.º 9
0
        internal override PartialResult PartialEval(PartialEnvironment environment)
        {
            PartialResult po = this.Operator.PartialEval(environment);

            return(new PartialResult((po.Residual == this.Operator) ? this : Combination0.Make(po.Residual)));
        }