Beispiel #1
0
 public bool Execute(string cmd, int threadId)
 {
     if (!string.IsNullOrEmpty(cmd))
     {
         int        tid = FindFreeThread(threadId);
         IRTSThread t   = tid == -1 ? null : mThreads[tid];
         if (t == null)
         {
             return(false);
         }
         mCompiler.reset();
         mCompiler.loadSource(cmd);
         while (mCompiler.isCompiling())
         {
             IRTSDefine.Error error = mCompiler.onCompile(mEngine);
             if (error != 0)
             {
                 logError("rts compile error:" + RTSUtil.getEnumDescript(typeof(IRTSDefine.Error), (int)error) + "-" + mCompiler.getCompilingLinker());
                 return(false);
             }
         }
         IRTSLinker root = mCompiler.getRootLinker();
         if (root != null)
         {
             bool ret = t.loadRunner(root.createRunner());
             mExecUpdate |= ret;
             return(ret);
         }
         return(false);
     }
     return(false);
 }
Beispiel #2
0
        private int FindFreeThread(int threadId)
        {
            int        p = threadId;
            IRTSThread t = null;

            if (threadId >= 0)
            {
                t = threadId < mThreads.Length ? mThreads[threadId] : null;
                p = threadId;
            }
            else
            {
                for (int i = 1; i <= mThreads.Length; i++)
                {
                    p = i % mThreads.Length;
                    if (mThreads[p].isFinished())
                    {
                        t = mThreads[p];
                        break;
                    }
                }
            }
            if (t == null || !t.isFinished())
            {
                return(-1);
            }
            else
            {
                return(p);
            }
        }
Beispiel #3
0
 public object ExecuteFunction(string funcName, object[] args, bool immediate)
 {
     if (RTSUtil.isGoodName(funcName))
     {
         IRTSThread t = null;
         if (immediate)
         {
             t = mImmediateT;
         }
         else
         {
             int p = 0;
             for (int i = 1; i <= mThreads.Length; i++)
             {
                 p = i % mThreads.Length;
                 if (mThreads[p].isFinished())
                 {
                     t = mThreads[p];
                     break;
                 }
             }
         }
         if (t == null || !t.isFinished())
         {
             return(false);
         }
         IRTSFunction func = mEngine.getFunction(funcName, args == null ? 0 : args.Length);
         if (func == null)
         {
             return(false);
         }
         bool ret = t.loadRunner(func.createRunner(args));
         if (immediate)
         {
             while (!t.isFinished())
             {
                 t.run(mEngine);
             }
             return(t.getOutput());
         }
         else
         {
             mExecUpdate |= ret;
             return(ret);
         }
     }
     else
     {
         return(null);
     }
 }
Beispiel #4
0
            public static RTSStack getStack(IRTSThread thread, int id)
            {
                if (sStacks == null)
                {
                    sStacks = new Queue <RTSStack>(RTSCfg.CALL_STACK_CACHE);
                }
                RTSStack sec;

                if (sStacks.Count > 0)
                {
                    sec         = sStacks.Dequeue();
                    sec.mThread = thread;
                    sec.mId     = id;
                }
                else
                {
                    sec = new RTSStack(thread, id);
                }
                return(sec);
            }
Beispiel #5
0
 private RTSStack(IRTSThread thread, int id)
 {
     this.mId = id;
     mThread  = thread;
 }
Beispiel #6
0
 private RTSStack(IRTSThread thread)
 {
     mThread = thread;
 }