Exemple #1
0
        public bool Apply(out object answer, ref Control expression, ref Environment environment, object [] args)
        {
            switch (args.Length)
            {
            case 0: return(this.Call(out answer, ref expression, ref environment));

            case 1: return(this.Call(out answer, ref expression, ref environment, args [0]));

            case 2: return(this.Call(out answer, ref expression, ref environment, args [0], args [1]));

            case 3: return(this.Call(out answer, ref expression, ref environment, args [0], args [1], args [2]));

            default:
#if DEBUG
                this.BumpCallCount();
                SCode.location = "SimpleClosure.Apply";
                SCode.NoteCalls(this, this.lambdaBody);
#endif
                if (args.Length != this.arity)
                {
                    return(Error.WrongNumberOfArguments(out answer, ref expression, ref environment));
                }
                expression  = this.lambdaBody;
                environment = new SimpleEnvironment(this, args);
                answer      = null; // keep the compiler happy
                return(true);
            }
        }
Exemple #2
0
        public bool Apply(out object answer, ref Control expression, ref Environment environment, object [] args)
        {
#if DEBUG
            this.BumpCallCount();
            SCode.location = "StaticClosure.Apply";
            SCode.NoteCalls(this, this.closureLambda.Body);
#endif
            if (args.Length != this.arity)
            {
                throw new NotImplementedException();
            }
            expression  = this.closureLambda.Body;
            environment = new StaticEnvironment(this, args);
            answer      = null; // keep the compiler happy
            return(true);
        }
Exemple #3
0
        public bool Call(out object answer, ref Control expression, ref Environment environment, object arg0, object arg1)
        {
#if DEBUG
            SCode.location = "-";
            this.BumpCallCount();
            SCode.NoteCalls(this, this.lambdaBody);
            SCode.location = "SimpleClosure.Call2";
#endif
            if (this.arity != 2)
            {
                return(Error.WrongNumberOfArguments(out answer, ref expression, ref environment));
            }
            //if (callCount++ == Configuration.OptimizeThreshold  && this.StaticCells.Length != 0) this.XXOptimize ();

            expression  = this.lambdaBody;
            environment = new SmallEnvironment2(this, arg0, arg1);

            answer = null; // keep the compiler happy
            return(true);
        }
Exemple #4
0
        public bool Apply(out object answer, ref Control expression, ref Environment environment, object [] args)
        {
#if DEBUG
            SCode.location = "-";
            this.BumpCallCount();
            SCode.location = "StandardExtendedClosure.Apply";
            SCode.NoteCalls(this, this.closureLambda.Body);
#endif
            int  nargs     = args.Length;
            int  nparams   = this.closureLambda.Formals.Length; // param 0 is self
            int  formals   = (int)this.closureLambda.required;
            int  parms     = (int)this.closureLambda.optional + formals;
            bool rest_flag = this.closureLambda.rest;
            int  auxes     = nparams - (parms + (rest_flag ? 1 : 0));

            if (nargs < formals)
            {
                throw new NotImplementedException("Too few arguments.");
            }
            else if (!rest_flag & (nargs > parms))
            {
                throw new NotImplementedException("Too many arguments.");
            }
            int size = parms + (rest_flag ? 1 : 0) + auxes;

            int       argptr      = 0;
            int       frameptr    = 0;
            object [] framevector = new object [size];

            if (nargs <= parms)
            {
                int i;
                for (i = (nargs); --i >= 0;)
                {
                    framevector [frameptr++] = args [argptr++];
                }
                for (i = (parms - nargs); --i >= 0;)
                {
                    framevector [frameptr++] = Constant.DefaultObject;
                }
                if (rest_flag)
                {
                    framevector [frameptr++] = null;
                }
                for (i = auxes; --i >= 0;)
                {
                    framevector [frameptr++] = Constant.DefaultObject;
                }
            }
            else
            {
                // theRestMarker flag must be true
                int i;
                int listloc;
                for (i = (parms); --i >= 0;)
                {
                    framevector [frameptr++] = args [argptr++];
                }
                listloc = frameptr++;
                framevector [listloc] = null;
                for (i = auxes; --i >= 0;)
                {
                    throw new NotImplementedException();
                    //framevector [frameptr++] = Constant.Unassigned;
                }
                argptr = args.Length;
                for (i = (nargs - parms); --i >= 0;)
                {
                    framevector [listloc] = new Cons(args [--argptr], framevector [listloc]);
                }
            }
            expression  = this.closureLambda.Body;
            environment = new StandardEnvironment <StandardExtendedLambda, StandardExtendedClosure> (this, framevector);
            answer      = null;
            return(true);
        }