Example #1
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            int argcount = 0;

            if (arguments != null)
            {
                argcount = arguments.Length;
            }

            if (this.arity != argcount)
            {
                if (!this.hasvariableparameters || this.arity - 1 > argcount)
                {
                    throw new InvalidOperationException("Invalid number of arguments");
                }
            }

            BindingEnvironment newenv = new BindingEnvironment(environment);

            if (this.hasvariableparameters)
            {
                for (int k = 0; k < this.arity - 1; k++)
                {
                    newenv.SetLocalValue(this.parameterNames[k], arguments[k]);
                }
                if (argcount == 0)
                {
                    newenv.SetLocalValue(this.parameterNames[0], new object[] { });
                }
                else
                {
                    object[] pars = new object[argcount - this.arity + 1];
                    Array.Copy(arguments, argcount - pars.Length, pars, 0, pars.Length);
                    newenv.SetLocalValue(this.parameterNames[this.arity - 1], pars);
                }
            }
            else
            {
                for (int k = 0; k < argcount; k++)
                {
                    newenv.SetLocalValue(this.parameterNames[k], arguments[k]);
                }
            }

            FunctionStatus fstatus = Machine.CurrentFunctionStatus;

            Machine.CurrentFunctionStatus = new FunctionStatus();

            try
            {
                this.body.Execute(newenv);

                return(Machine.CurrentFunctionStatus.ReturnValue);
            }
            finally
            {
                Machine.CurrentFunctionStatus = fstatus;
            }
        }
Example #2
0
        public object Invoke(IBindingEnvironment environment, object[] arguments)
        {
            int argcount = 0;

            if (arguments != null)
                argcount = arguments.Length;

            if (this.arity != argcount)
                if (!this.hasvariableparameters || this.arity - 1 > argcount)
                    throw new InvalidOperationException("Invalid number of arguments");

            BindingEnvironment newenv = new BindingEnvironment(environment);

            if (this.hasvariableparameters)
            {
                for (int k = 0; k < this.arity - 1; k++)
                    newenv.SetLocalValue(this.parameterNames[k], arguments[k]);
                if (argcount == 0)
                    newenv.SetLocalValue(this.parameterNames[0], new object[] { });
                else
                {
                    object[] pars = new object[argcount - this.arity + 1];
                    Array.Copy(arguments, argcount - pars.Length, pars, 0, pars.Length);
                    newenv.SetLocalValue(this.parameterNames[this.arity - 1], pars);
                }
            }
            else
                for (int k = 0; k < argcount; k++)
                    newenv.SetLocalValue(this.parameterNames[k], arguments[k]);

            FunctionStatus fstatus = Machine.CurrentFunctionStatus;

            Machine.CurrentFunctionStatus = new FunctionStatus();

            try
            {
                this.body.Execute(newenv);

                return Machine.CurrentFunctionStatus.ReturnValue;
            }
            finally
            {
                Machine.CurrentFunctionStatus = fstatus;
            }
        }