Beispiel #1
0
 public void RegisterFunction(string name, DelegateFunction func)
 {
     if (IsAborting)
     {
         throw new ExecutionAbortException(Properties.Language.ExecutionAborted);
     }
     currentFunctions[name] = func;
 }
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            ExecutionEnvironment current = new ExecutionEnvironment();

            foreach (var f in enviroment.Module.Functions)
            {
                if (Function.Equals(f.Name))
                {
                    for (int i = 0; i < Args.Count; i++)
                    {
                        Expression e    = Args[i];
                        string     name = ArgTyps[i];

                        Completion cp = e.Execute(enviroment);
                        if (cp.Type != CompletionType.Value)
                        {
                            return(cp);
                        }
                        current.RegisterValue(f.Params[i].Name, cp.ReturnValue);
                    }
                    var c = f.Execute(current);
                    return(c);
                }
            }
            DelegateFunction func       = enviroment.GetFunction(Function);
            List <object>    parameters = new List <object>();

            if (func != null)
            {
                try
                {
                    for (int i = 0; i < Args.Count; i++)
                    {
                        Expression e    = Args[i];
                        string     name = ArgTyps[i];

                        Completion cp = e.Execute(enviroment);
                        if (cp.Type != CompletionType.Value)
                        {
                            return(cp);
                        }
                        parameters.Add(cp.ReturnValue);
                    }
                    return(new Completion(func.Invoke(parameters.ToArray())));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
            return(Completion.Void);
        }
 public void RegisterFunction(string name, DelegateFunction func)
 {
     currentFunctions[name] = func;
 }
Beispiel #4
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            /*
             * if (DelegateFunction != null)
             * {
             *  List<object> ps = new List<object>();
             *  for (int i = 0; i < Args.Count; i++)
             *  {
             *      Expression e = Args[i];
             *      string name = ArgTyps[i];
             *
             *      Completion cp = e.Execute(enviroment);
             *      if (cp.Type != CompletionType.Value)
             *          return cp;
             *      ps.Add(cp.ReturnValue);
             *  }
             *  DelegateFunction.Invoke(ps.ToArray());
             *  return Completion.Void;
             * }*/
            foreach (var f in enviroment.Module.Functions)
            {
                if (Function.Equals(f.Name))
                {
                    ExecutionEnvironment current = new ExecutionEnvironment(enviroment.GetInstanceEnvironment());
                    for (int i = 0; i < Args.Count; i++)
                    {
                        Expression e    = Args[i];
                        string     name = ArgTyps[i];

                        Completion cp = e.Execute(enviroment);
                        if (cp.Type != CompletionType.Value)
                        {
                            return(cp);
                        }
                        current.RegisterValue(f.Params[i].Name, cp.ReturnValue);
                    }
                    var c = f.Execute(current);
                    return(c);
                }
            }
            DelegateFunction func       = enviroment.GetFunction(Function);
            List <object>    parameters = new List <object>();

            if (func != null)
            {
                try
                {
                    for (int i = 0; i < Args.Count; i++)
                    {
                        Expression e    = Args[i];
                        string     name = ArgTyps[i];
                        if (e == null)
                        {
                            return(Completion.Exception(Properties.Language.ParameterNullException, this));
                        }
                        Completion cp = e.Execute(enviroment);
                        if (cp.Type != CompletionType.Value)
                        {
                            return(cp);
                        }
                        parameters.Add(cp.ReturnValue);
                    }
                    return(new Completion(func.Invoke(parameters.ToArray())));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
            return(Completion.Void);
        }