Пример #1
0
 protected void AbortExecution(bool invokeEvent)
 {
     IsAborted = true;
     //_breakPointInstruction = null;
     if (invokeEvent)
     {
         ExecutionAborted?.Invoke(this, new InstructionExecuteEventArgs(CurrentInstruction, CurrentInstructionIndex));
     }
 }
Пример #2
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);
        }
Пример #3
0
 private void HandleBeatLost()
 {
     BeatLost?.Invoke();
     if (_currentSong != null)
     {
         ExecutionAborted?.Invoke(_currentSong, 0);
         _currentSong = null;
     }
     _streakPower = 0;
     _streakScore = 0;
     HasBeat      = false;
     ResetBeatAfterSeconds(1);
 }
Пример #4
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);
        }