public DelegateFunction GetFunction(string name)
 {
     if (currentFunctions.ContainsKey(name))
     {
         return(currentFunctions[name]);
     }
     if (_parent != null)
     {
         return(_parent.GetFunction(name));
     }
     return(null);
 }
Example #2
0
        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);
        }
Example #3
0
 public DelegateFunction GetFunction(string name)
 {
     if (IsAborting)
     {
         throw new ExecutionAbortException(Properties.Language.ExecutionAborted);
     }
     if (currentFunctions.ContainsKey(name))
     {
         return(currentFunctions[name]);
     }
     if (_parent != null)
     {
         return(_parent.GetFunction(name));
     }
     return(null);
 }
Example #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);
        }