Beispiel #1
0
 public ExecutionEnvironment()
 {
     _parent = null;
 }
Beispiel #2
0
 public Completion Execute(ExecutionEnvironment enviroment)
 {
     return(Completion.Void);
 }
Beispiel #3
0
 public bool PopStack(out object execution, out ExecutionCallback callback, ExecutionEnvironment e)
 {
     execution = null;
     callback  = Callback;
     return(false);
 }
Beispiel #4
0
 protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
 {
     return(new Completion(Math.PI));
 }
Beispiel #5
0
 public ExecutionEnvironment(ExecutionEnvironment parent)
 {
     _parent      = parent;
     Engine       = parent.Engine;
     currentScope = new Dictionary <string, object>();
 }
 Completion ExecuteDateMinus(ExecutionEnvironment environment, object left, object right)
 {
     return(new Completion((DateTime)left - (DateTime)right));
 }
Beispiel #7
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            DateTime startTime;
            DateTime finishTime;
            double   orgin_x;
            double   orgin_y;
            double   totalTime;

            if (X == null)
            {
                return(Completion.Void);
            }
            double x = 0;

            try
            {
                var c = X.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                x = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", X));
            }
            if (Y == null)
            {
                return(Completion.Void);
            }
            double y = 0;

            try
            {
                var c = Y.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                y = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Y));
            }
            if (Time == null)
            {
                return(Completion.Void);
            }
            double time = 0;

            try
            {
                var c = Time.Execute(enviroment);
                if (c.Type != CompletionType.Value)
                {
                    return(c);
                }
                time = TypeConverters.GetValue <double>(c.ReturnValue);
            }
            catch
            {
                return(Completion.Exception("Wrong number format", Time));
            }

            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            if (x < 0)
            {
                x = 0;
            }
            if (x > CurrentEnviroment.ScreenWidth)
            {
                x = CurrentEnviroment.ScreenWidth;
            }
            if (y < 0)
            {
                y = 0;
            }
            if (y > CurrentEnviroment.ScreenHeight)
            {
                y = CurrentEnviroment.ScreenHeight;
            }
            orgin_x    = sp.X;
            orgin_y    = sp.Y;
            startTime  = DateTime.Now;
            finishTime = DateTime.Now.AddSeconds(time);
            totalTime  = (finishTime - startTime).TotalMilliseconds;

            while (true)
            {
                if (DateTime.Now > finishTime)
                {
                    break;
                }
                double duration = (DateTime.Now - startTime).TotalMilliseconds;

                sp.X = (int)(orgin_x + (x - orgin_x) * duration / totalTime);
                sp.Y = (int)(orgin_y + (y - orgin_y) * duration / totalTime);
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
                }));
                Thread.Sleep(100);
            }

            sp.X = (int)x;
            sp.Y = (int)y;
            App.Current.Dispatcher.InvokeAsync(new Action(() =>
            {
                (enviroment.GetValue("$$Player") as ScriptPlayer).DrawScript();
            }));
            return(Completion.Void);
        }
Beispiel #8
0
        public Completion Assign(ExecutionEnvironment environment, object value)
        {
            if (string.IsNullOrEmpty(SetMemberFunction))
            {
                return(Completion.Exception("this is can not set", this));
            }
            if (Object == null)
            {
                return(Completion.Exception("object parameter can not be null", this));
            }
            var tc = Object.Execute(environment);

            if (!tc.IsValue)
            {
                return(tc);
            }
            object obj = tc.ReturnValue;

            if (obj == null)
            {
                return(Completion.Exception("object value can not be null", Object));
            }
            object m = null;

            if (IsMemberRequired)
            {
                if (Member == null)
                {
                    return(Completion.Exception("member parameter can not be null", this));
                }
                var mc = Member.Execute(environment);
                if (!mc.IsValue)
                {
                    return(mc);
                }
                m = mc.ReturnValue;
            }
            Type t = obj.GetType();

            try
            {
                if (MemberType == MemberType.Function)
                {
                    MethodInfo set = t.GetMethod(SetMemberFunction);
                    if (set == null)
                    {
                        return(Completion.Exception("No member function for " + obj.GetType(), Member));
                    }
                    if (IsMemberRequired)
                    {
                        set.Invoke(obj, new object[] { m, value });
                    }
                    else
                    {
                        set.Invoke(obj, new object[] { value });
                    }
                    return(new Completion(value));
                }
                else if (MemberType == MemberType.Property)
                {
                    PropertyInfo set = t.GetProperty(SetMemberFunction);
                    if (set == null)
                    {
                        return(Completion.Exception("No member function for " + obj.GetType(), Member));
                    }
                    set.SetValue(obj, value);
                    return(new Completion(value));
                }
                else
                {
                    FieldInfo set = t.GetField(SetMemberFunction);
                    if (set == null)
                    {
                        return(Completion.Exception("No member function for " + obj.GetType(), Member));
                    }
                    set.SetValue(obj, value);
                    return(new Completion(value));
                }
            }catch (Exception e)
            {
                return(Completion.Exception(e.Message, this));
            }
        }
Beispiel #9
0
 public ExecutionEngine()
 {
     Instances       = new List <Instance>();
     BaseEnvironment = new ExecutionEnvironment(this);
     Threads         = new List <RunThread>();
 }
Beispiel #10
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            double result = ((_env.This as Instance).Class as Sprite).Direction;

            return(new Completion(result));
        }
Beispiel #11
0
        protected override Completion ExecuteImpl(ExecutionEnvironment environment)
        {
            if (Object == null)
            {
                return(Completion.Exception("object parameter can not be null", this));
            }
            var tc = Object.Execute(environment);

            if (!tc.IsValue)
            {
                return(tc);
            }
            object obj = tc.ReturnValue;

            if (obj == null)
            {
                return(Completion.Exception("object value can not be null", Object));
            }
            object m = null;

            if (IsMemberRequired)
            {
                if (Member == null)
                {
                    return(Completion.Exception("member parameter can not be null", this));
                }
                var mc = Member.Execute(environment);
                if (!mc.IsValue)
                {
                    return(mc);
                }
                m = mc.ReturnValue;
            }
            Type t = obj.GetType();

            try
            {
                if (MemberType == MemberType.Function)
                {
                    MethodInfo get = t.GetMethod(GetMemberFunction);
                    if (get == null)
                    {
                        return(Completion.Exception("No member function for " + obj.GetType(), Member));
                    }
                    object value = null;
                    if (IsMemberRequired)
                    {
                        value = get.Invoke(obj, new object[] { m });
                    }
                    else
                    {
                        value = get.Invoke(obj, new object[] {  });
                    }
                    return(new Completion(value));
                }
                else if (MemberType == MemberType.Property)
                {
                    PropertyInfo get = t.GetProperty(GetMemberFunction);
                    if (get == null)
                    {
                        return(Completion.Exception("No member function for " + obj.GetType(), Member));
                    }
                    object value = get.GetValue(obj);
                    return(new Completion(value));
                }
                else
                {
                    FieldInfo get = t.GetField(GetMemberFunction);
                    if (get == null)
                    {
                        return(Completion.Exception("No member function for " + obj.GetType(), Member));
                    }
                    object value = get.GetValue(obj);
                    return(new Completion(value));
                }
            }
            catch (Exception e)
            {
                return(Completion.Exception(e.Message, this));
            }
        }
Beispiel #12
0
 public Completion EndCall(ExecutionEnvironment e)
 {
     return(new Completion(result));
 }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            double result = (enviroment.GetValue("$$INSTANCE$$") as Sprite).Y;

            return(new Completion(result));;
        }
Beispiel #14
0
 public ExecutionEnvironment(ExecutionEnvironment parent)
 {
     _parent = parent;
 }
Beispiel #15
0
 public Completion EndCall(ExecutionEnvironment e)
 {
     return(Completion.Void);
 }
Beispiel #16
0
 protected abstract Completion ExecuteImpl(ExecutionEnvironment enviroment);
 Completion ExecuteStringAdd(ExecutionEnvironment environment, object left, object right)
 {
     return(new Completion(left + "" + right));
 }
Beispiel #18
0
        public Completion EndCall(ExecutionEnvironment _env)
        {
            object result = _env.GetValue(Variable);

            return(new Completion(result));
        }
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Left == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            if (Right == null)
            {
                return(Completion.Exception(Properties.Language.NullException, this));
            }
            var left = Left.Execute(enviroment);

            if (left.Type != CompletionType.Value)
            {
                return(left);
            }
            var right = Right.Execute(enviroment);

            if (right.Type != CompletionType.Value)
            {
                return(right);
            }
            if (IsLogicalOperator(Operator))
            {
                return(ExecuteLogical(enviroment, left.ReturnValue, right.ReturnValue));
            }
            if (Operator == Operator.Add)
            {
                if ((left.ReturnValue is string) || right.ReturnValue is string)
                {
                    return(ExecuteStringAdd(enviroment, left.ReturnValue, right.ReturnValue));
                }
            }
            if (Operator == Operator.Equal)
            {
                if (left.ReturnValue is string)
                {
                    return(new Completion(left.ReturnValue is string && (left.ReturnValue as string).Equals(right.ReturnValue)));
                }
                if (right.ReturnValue is string)
                {
                    return(new Completion(right.ReturnValue is string && (right.ReturnValue as string).Equals(left.ReturnValue)));
                }
                if (left.ReturnValue is bool)
                {
                    return(new Completion(right.ReturnValue is bool && (bool)right.ReturnValue == (bool)left.ReturnValue));
                }
                if (right.ReturnValue is bool)
                {
                    return(new Completion(left.ReturnValue is bool && (bool)left.ReturnValue == (bool)right.ReturnValue));
                }
                if (left.ReturnValue == null)
                {
                    if (right.ReturnValue == null)
                    {
                        return(new Completion(true));
                    }
                    else
                    {
                        return(new Completion(false));
                    }
                }
                if (right.ReturnValue == null)
                {
                    if (left.ReturnValue == null)
                    {
                        return(new Completion(true));
                    }
                    return(new Completion(false));
                }
            }
            if (Operator == Operator.NotEqual)
            {
                if (left.ReturnValue is string)
                {
                    return(new Completion(!(left.ReturnValue as string).Equals(right.ReturnValue)));
                }
                if (right.ReturnValue is string)
                {
                    return(new Completion(!(right.ReturnValue as string).Equals(left.ReturnValue)));
                }
                if (left.ReturnValue is bool)
                {
                    return(new Completion(!(right.ReturnValue is bool) || (bool)right.ReturnValue != (bool)left.ReturnValue));
                }
                if (right.ReturnValue is bool)
                {
                    return(new Completion(!(left.ReturnValue is bool) || (bool)left.ReturnValue != (bool)right.ReturnValue));
                }
                if (left.ReturnValue == null)
                {
                    if (right.ReturnValue != null)
                    {
                        return(new Completion(true));
                    }
                    else
                    {
                        return(new Completion(false));
                    }
                }
                if (right.ReturnValue == null)
                {
                    if (left.ReturnValue != null)
                    {
                        return(new Completion(true));
                    }
                    return(new Completion(false));
                }
            }
            if (Operator == Operator.Add)
            {
                if ((left.ReturnValue is DateTime) && right.ReturnValue is DateTime)
                {
                    return(ExecuteStringAdd(enviroment, left.ReturnValue, right.ReturnValue));
                }
            }
            Type T = TypeConverters.GetMaxTypes(left.ReturnValue, right.ReturnValue);

            if (T == null)
            {
                return(Completion.Exception(Properties.Language.NotNumber, this));
            }
            if (Operator == Operator.Mod || Operator == Operator.BitAnd || Operator == Operator.BitOr ||
                Operator == Operator.BitLeftShift || Operator == Operator.BitRightShift || Operator == Operator.BitExclusiveOr)
            {
                T = typeof(int);
            }
            if (T.Equals(typeof(char)))
            {
                try
                {
                    var l = TypeConverters.GetValue <char>(left.ReturnValue);
                    var r = TypeConverters.GetValue <char>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Mod:
                        return(new Completion(l % r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));

                    case Operator.BitAnd:
                        return(new Completion(l & r));

                    case Operator.BitOr:
                        return(new Completion(l | r));

                    case Operator.BitLeftShift:
                        return(new Completion(l << r));

                    case Operator.BitRightShift:
                        return(new Completion(l >> r));

                    case Operator.BitExclusiveOr:
                        return(new Completion(l ^ r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    return(Completion.Exception(e.Message, this));
                }
            }
            if (T.Equals(typeof(int)))
            {
                try
                {
                    var l = TypeConverters.GetValue <int>(left.ReturnValue);
                    var r = TypeConverters.GetValue <int>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Mod:
                        return(new Completion(l % r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));

                    case Operator.BitAnd:
                        return(new Completion(l & r));

                    case Operator.BitOr:
                        return(new Completion(l | r));

                    case Operator.BitLeftShift:
                        return(new Completion(l << r));

                    case Operator.BitRightShift:
                        return(new Completion(l >> r));

                    case Operator.BitExclusiveOr:
                        return(new Completion(l ^ r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                    return(Completion.Exception(e.Message, this));
                }
            }
            if (T.Equals(typeof(float)))
            {
                try
                {
                    var l = TypeConverters.GetValue <float>(left.ReturnValue);
                    var r = TypeConverters.GetValue <float>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
            if (T.Equals(typeof(long)))
            {
                try
                {
                    var l = TypeConverters.GetValue <long>(left.ReturnValue);
                    var r = TypeConverters.GetValue <long>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
            {
                try
                {
                    double l = TypeConverters.GetValue <double>(left.ReturnValue);
                    double r = TypeConverters.GetValue <double>(right.ReturnValue);
                    switch (Operator)
                    {
                    case Operator.Add:
                        return(new Completion(l + r));

                    case Operator.Minus:
                        return(new Completion(l - r));

                    case Operator.Mulitiply:
                        return(new Completion(l * r));

                    case Operator.Divide:
                        return(new Completion(l / r));

                    case Operator.Great:
                        return(new Completion(l > r));

                    case Operator.GreatOrEqual:
                        return(new Completion(l >= r));

                    case Operator.Less:
                        return(new Completion(l < r));

                    case Operator.LessOrEqual:
                        return(new Completion(l <= r));

                    case Operator.Equal:
                        return(new Completion(l == r));

                    case Operator.NotEqual:
                        return(new Completion(l != r));
                    }
                    return(Completion.Exception(Properties.Language.UnknowException, this));
                }
                catch (Exception e)
                {
                    return(Completion.Exception(e.Message, this));
                }
            }
        }
Beispiel #20
0
 public Completion EndCall(ExecutionEnvironment e)
 {
     return(new Completion(e.GetState("result")));
 }
Beispiel #21
0
 protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
 {
     return(new Completion(SpeachBase.GetSpeech(enviroment).Volume));
 }
Beispiel #22
0
        public Completion EndCall(ExecutionEnvironment e)
        {
            double r = random.Next((int)e.GetState("minimum"), (int)e.GetState("maximum"));

            return(new Completion(r));
        }
Beispiel #23
0
 public Completion Execute(ExecutionEnvironment enviroment)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            double result = (enviroment.GetValue("$$INSTANCE$$") as Sprite).X;

            return(new Completion(result));
        }
Beispiel #25
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            Sprite sp = enviroment.GetValue("$$INSTANCE$$") as Sprite;

            return(new Completion(sp.Size));
        }
Beispiel #26
0
 public ExecutionEnvironment StartCall(ExecutionEnvironment e)
 {
     degree = 0;
     return(e);
 }
Beispiel #27
0
        //execution

        public ExecutionEnvironment StartCall(ExecutionEnvironment e)
        {
            return(e);
        }
Beispiel #28
0
 Nullable <DateTime> Callback(object value, object exception, ExecutionEnvironment e)
 {
     degree = (double)value;
     return(null);
 }
Beispiel #29
0
 Nullable <DateTime> Callback(object value, object exception, ExecutionEnvironment e)
 {
     return(null);
 }
Beispiel #30
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);
        }