protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Variable == null)
            {
                return(Completion.Exception(Properties.Language.VariableNameException, this));
            }
            if (!(Variable is Identifier))
            {
                return(Completion.Exception(Properties.Language.OnlyVariableAccept, Variable));
            }
            string name = (Variable as Identifier).Variable;

            if (Value == null)
            {
                enviroment.RegisterValue(name, null);
                return(Completion.Void);
            }
            else
            {
                var c = Value.Execute(enviroment);
                if (!c.IsValue)
                {
                    return(c);
                }
                enviroment.RegisterValue(name, c.ReturnValue);
                return(c);
            }
        }
Пример #2
0
 private void OnRun(object sender, RoutedEventArgs e)
 {
     //ButtonStart.IsEnabled = false;
     //ButtonStop.IsEnabled = true;
     if (engine != null)
     {
         ///engine.Stop();
         /// engine = null;
     }
     engine = new ExecutionEnvironment();
     PlayScreen.Children.Clear();
     controls.Clear();
     CurrentEnviroment.Game.Instances.Clear();
     allEnvs.Clear();
     engine.RegisterValue("$$Player", this);
     foreach (Sprite sp in CurrentEnviroment.Game.Sprites)
     {
         CurrentEnviroment.Game.Instances.Add(new Instance(sp), sp);
         ExecutionEnvironment playEnv = new ExecutionEnvironment(engine);
         allEnvs.Add(sp, playEnv);
         playEnv.RegisterValue("$$INSTANCE$$", sp);
         playEnv.Execute(sp);
         foreach (var f in sp.Handlers)
         {
             if (f is StartEventHandler)
             {
                 new Thread(() =>
                 {
                     f.Execute(playEnv);
                 }).Start();
             }
         }
     }
 }
Пример #3
0
 public Completion Execute(ExecutionEnvironment enviroment)
 {
     if (string.IsNullOrEmpty(Name))
     {
         return(new Completion("Variable name can not be null", CompletionType.Exception));
     }
     enviroment.RegisterValue(Name, Value);
     return(new Completion(Value, CompletionType.Value));
 }
 protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
 {
     if (string.IsNullOrEmpty(Name))
     {
         return(new Completion(Properties.Language.VariableNameException, CompletionType.Exception));
     }
     enviroment.RegisterValue(Name, Value);
     return(new Completion(Value, CompletionType.Value));
 }
Пример #5
0
        public Completion Execute(Class m)
        {
            _current = m;
            if (_current == null)
            {
                return(null);
            }
            Completion c = Completion.Void;

            foreach (var func in _current.Functions)
            {
                if ("main".Equals(func.Format, StringComparison.OrdinalIgnoreCase))
                {
                    foreach (var v in _current.Variables)
                    {
                        RegisterValue(v.Name, v.Value);
                    }
                    var parameter = func.Params;
                    ExecutionEnvironment current = new ExecutionEnvironment(this);
                    ExecutionStarted?.Invoke(this, null);
                    foreach (var p in parameter)
                    {
                        current.RegisterValue(p.Name, null);
                    }
                    try
                    {
                        IsCompleted = false;
                        c           = func.Execute(current);
                        break;
                    }catch (Exception e)
                    {
                        IsCompleted = true;
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.StackTrace);
                        ExecutionAborted?.Invoke(this, new Completion(e.Message, CompletionType.Exception));
                        return(Completion.Void);
                    }
                }
            }
            IsCompleted = true;
            if (c.Type == CompletionType.Value)
            {
                ExecutionCompleted?.Invoke(this, c);
            }
            else if (c.Type == CompletionType.Exception)
            {
                ExecutionAborted?.Invoke(this, c);
            }
            else
            {
                ExecutionAborted?.Invoke(this, Completion.Exception("Unknown exception", null));
            }
            return(c);
        }
Пример #6
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);
        }
Пример #7
0
        public ExecutionEnvironment StartCall(ExecutionEnvironment e)
        {
            ExecutionEnvironment _env = new ExecutionEnvironment(new ExecutionEnvironment(e.Engine.BaseEnvironment, e.This));

            if (Params != null)
            {
                foreach (Parameter p in Params)
                {
                    _env.RegisterValue(p.Name, p.Value);
                }
            }
            return(_env);
        }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (enviroment.HasValue("$$ReflectionOnTouchSide&&"))
            {
                enviroment.SetValue("$$ReflectionOnTouchSide&&", true);
            }
            else
            {
                enviroment.RegisterValue("$$ReflectionOnTouchSide&&", true);
            }

            return(Completion.Void);
        }
Пример #9
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Try == null || Try.Body.Count == 0)
            {
                return(Completion.Void);
            }
            ExecutionEnvironment te = new ExecutionEnvironment(enviroment);
            var c = Try.Execute(te);

            if (c.Type == CompletionType.Exception)
            {
                ExecutionEnvironment ec = new ExecutionEnvironment(enviroment);
                ec.RegisterValue("e", c.ReturnValue);
                if (Catch != null && Catch.Body.Count > 0)
                {
                    ExecutionEnvironment ee = new ExecutionEnvironment(ec);
                    c = Catch.Execute(ee);
                }
                else
                {
                    c = Completion.Void;
                }
                if (c.Type == CompletionType.Exception)
                {
                    return(c);
                }
            }
            Completion fc = Completion.Void;

            if (Finally != null && Finally.Body.Count > 0)
            {
                ExecutionEnvironment fe = new ExecutionEnvironment(enviroment);
                fc = Finally.Execute(fe);
            }
            if (c.Type == CompletionType.Return)
            {
                return(c);
            }
            else if (c.Type == CompletionType.Value)
            {
                return(c);
            }
            if (fc.Type == CompletionType.Return)
            {
                return(fc);
            }
            return(c);
        }
Пример #10
0
        public static DrawWindow GetCanvas(ExecutionEnvironment environment)
        {
            DrawWindow canvas = null;

            if (!environment.HasValue(CanvasName))
            {
                ExecutionEnvironment b = environment.GetBaseEnvironment();
                Application.Current.Dispatcher.Invoke(() =>
                {
                    canvas = new DrawWindow();
                    if (Application.Current.MainWindow != null)
                    {
                        canvas.Owner = Application.Current.MainWindow;
                    }
                    canvas.Show();
                });
                b.RegisterValue(CanvasName, canvas);
            }
            else
            {
                canvas = environment.GetValue(CanvasName) as DrawWindow;
            }
            return(canvas);
        }
Пример #11
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);
        }
Пример #12
0
        public Completion Execute(Class m)
        {
            IsAborting  = false;
            IsCompleted = false;
            _current    = m;
            if (_current == null)
            {
                return(null);
            }
            Completion           c           = Completion.Void;
            ExecutionEnvironment baseEnv     = this.GetBaseEnvironment();
            ExecutionEnvironment classEnv    = new ExecutionEnvironment(baseEnv);
            ExecutionEnvironment instanceEnv = new ExecutionEnvironment(classEnv);

            foreach (var v in m.Variables)
            {
                instanceEnv.RegisterValue(v.Name, v.Value);
            }
            foreach (var func in _current.Functions)
            {
                if ("main".Equals(func.Name, StringComparison.OrdinalIgnoreCase))
                {
                    var parameter = func.Params;
                    ExecutionEnvironment functionEnv = new ExecutionEnvironment(instanceEnv);
                    ExecutionStarted?.Invoke(this, null);
                    foreach (var p in parameter)
                    {
                        functionEnv.RegisterValue(p.Name, null);
                    }
                    foreach (var block in m.BlockStatements)
                    {
                        foreach (var s in block.Body)
                        {
                            if (s is ExpressionStatement)
                            {
                                Expression exp = (s as ExpressionStatement).Expression;
                                if (exp is VariableDeclarationExpression)
                                {
                                    exp.Execute(instanceEnv);
                                }
                            }
                        }
                    }
                    try
                    {
                        IsCompleted = false;
                        c           = func.Execute(functionEnv);
                        break;
                    }catch (Exception e)
                    {
                        IsCompleted = true;
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.StackTrace);
                        ExecutionAborted?.Invoke(this, new Completion(e.Message, CompletionType.Exception));
                        return(Completion.Void);
                    }
                }
            }
            IsCompleted = true;
            if (c.Type == CompletionType.Value)
            {
                ExecutionCompleted?.Invoke(this, c);
            }
            else if (c.Type == CompletionType.Exception)
            {
                ExecutionAborted?.Invoke(this, c);
            }
            else
            {
                ExecutionAborted?.Invoke(this, Completion.Exception(Properties.Language.UnknowException, null));
            }
            return(c);
        }