예제 #1
0
        public MiraeRuntimeResult Next()
        {
            if (!mBlockCodes.ContainsKey(mCurrentName))
            {
                // Wrong BlockName Error
                mRunType = MiraeRuntimeResultType.Error;
                return(new MiraeRuntimeResult(MiraeRuntimeResultType.Error, MiraeRuntimeError.WrongNetworkBlockName, new MiraeRuntimeResult.ResultTarget(mCurrentName, 0)));
            }

            #region CheckCurrentBlock
            if (mCurrentBlock == null)
            {
                var codes = mBlockCodes[mCurrentName];
                if (codes.Count == 0)
                {
                    if (IsCodeEnd())
                    {
                        // End
                        mRunType = MiraeRuntimeResultType.End;
                        return(new MiraeRuntimeResult(MiraeRuntimeResultType.End, MiraeRuntimeError.Success, null));
                    }
                }
                else
                {
                    if (mRunType != MiraeRuntimeResultType.Running)
                    {
                        mCurrentBlock = codes[0];
                    }
                }
            }
            #endregion

            if (mCurrentBlock == null)
            {
                if (IsCodeEnd())
                {
                    // End
                    mRunType = MiraeRuntimeResultType.End;
                    return(new MiraeRuntimeResult(MiraeRuntimeResultType.End, MiraeRuntimeError.Success, null));
                }
            }

            MiraeRuntimeError error = MiraeRuntimeError.Success;
            var block = mCurrentBlock;
            switch (block.BlockType)
            {
            case BlockType.If:
                error = RunIf(block as IfBlock);
                break;

            case BlockType.While:
                error = RunWhile(block as WhileBlock);
                break;

            case BlockType.CloseBracket:
                error = RunCloseBracekt(block as CloseBracektBlock);
                break;

            case BlockType.Condition:
                // WrongConditionPosition Error
                mRunType = MiraeRuntimeResultType.Error;
                return(new MiraeRuntimeResult(MiraeRuntimeResultType.Error, MiraeRuntimeError.WrongConditionPosition, new MiraeRuntimeResult.ResultTarget(mCurrentName, block.Id)));

            case BlockType.FunctionCall:
                RunFunctionCall(block as FunctionCallBlock);
                break;

            case BlockType.Execute:
                error = RunExecute(block as ExecuteBlock);
                break;

            default:
                // Unknown Block Error
                mRunType = MiraeRuntimeResultType.Error;
                return(new MiraeRuntimeResult(MiraeRuntimeResultType.Error, MiraeRuntimeError.UnknownBlock, new MiraeRuntimeResult.ResultTarget(mCurrentName, block.Id)));
            }
            if (error != MiraeRuntimeError.Success)
            {
                // error
                mRunType = MiraeRuntimeResultType.Error;
                return(new MiraeRuntimeResult(MiraeRuntimeResultType.Error, error, new MiraeRuntimeResult.ResultTarget(mCurrentName, block.Id)));
            }
            else
            {
                mRunType = MiraeRuntimeResultType.Running;
                if (block == null)
                {
                    return(new MiraeRuntimeResult(MiraeRuntimeResultType.Running, MiraeRuntimeError.Success, new MiraeRuntimeResult.ResultTarget(mCurrentName, 0)));
                }

                if (block.BlockType == BlockType.Execute)
                {
                    return(new MiraeRuntimeResult(MiraeRuntimeResultType.Running, MiraeRuntimeError.Success, new MiraeRuntimeResult.ResultTarget(mCurrentName, block.Id)));
                }
                else
                {
                    return(Next());
                }
            }
        }
예제 #2
0
 public MiraeRuntimeResult(MiraeRuntimeResultType result, MiraeRuntimeError error, ResultTarget target)
 {
     Result = result;
     Error  = error;
     Target = target;
 }