override public IRTSDefine.Error onCompile(RTSList <IRTSLinker> compileList) { if (mId == IRTSDefine.Linker.TYPE) { if (mVarName == null) { return(0); } else { return(RTSUtil.isGoodName(mVarName) ? 0 : IRTSDefine.Error.Compiling_DenyLinker); } } else { if (mArg == null || mBody == null) { return(IRTSDefine.Error.Compiling_DenyLinker); } if (!((RTSBracketL)mArg).isVarList()) { return(IRTSDefine.Error.Compiling_DenyLinker); } compileList.add(mArg); compileList.add(mBody); return(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); }
override public IRTSDefine.Error onCompile(RTSList <IRTSLinker> compileList) { if (mBeConst) { return(0); } else if (mId == IRTSDefine.Linker.VARIABLE) { mConst = RTSConverter.getCompileValue(mSrc); if (mConst == null && !RTSUtil.isGoodName(mSrc)) { return(IRTSDefine.Error.Compiling_DenyLinker); } return(0); } else if (mId == IRTSDefine.Linker.FUNCTION) { if (!RTSUtil.isGoodName(mSrc)) { return(IRTSDefine.Error.Compiling_DenyLinker); } compileList.add(mArg); return(0); } else { return(IRTSDefine.Error.Compiling_DenyLinker); } }
public void setConsiderSeperator(bool value) { considerSeperator = value; if (value && RTSUtil.isNullOrEmpty(seperators)) { seperators = SEPERATORS; } }
public void setConsiderBracket(bool value) { considerBracket = value; if (value && RTSUtil.isNullOrEmpty(brackets)) { brackets = BRACKET_OPERATORS; } }
public void setConsiderOperator(bool value) { considerOperator = value; if (value && RTSUtil.isNullOrEmpty(operators)) { operators = OPERATORS; } }
public void addFunction(string funcName, IRTSFunction func) { if (mFuncs == null) { mFuncs = new System.Collections.Generic.Dictionary <string, IRTSFunction>(); } mFuncs[RTSUtil.keyOfFunc(funcName, func.argSize())] = func; }
public static string keyOfFunc(string funcName, int argCount) { if (argCount >= 0) { return(RTSUtil.linkString('-', funcName, argCount)); } else { return(funcName); } }
public override IRTSDefine.Error onCompile(RTSList <IRTSLinker> compileList) { if (!RTSUtil.isGoodName(mSrc)) { return(IRTSDefine.Error.Compiling_DenyLinker); } for (int i = 0; i < mArgs.length(); i++) { compileList.add(mArgs.get(i)); } return(0); }
override public IRTSDefine.Error onCompile(RTSList <IRTSLinker> compileList) { if (!RTSUtil.isGoodName(mSrc)) { return(IRTSDefine.Error.Compiling_DenyLinker); } if (mArg != null) { compileList.add(mArg); } return(0); }
public void removeFunction(string funcName, int argCount) { if (mFuncs == null) { return; } else { string key = RTSUtil.keyOfFunc(funcName, argCount); mFuncs.Remove(key); } }
public bool isVarList() { if (mChild is RTSCommaL) { return(((RTSCommaL)mChild).isVarList()); } else { return(mChild == null || (mChild.getId() == IRTSDefine.Linker.VARIABLE && RTSUtil.isGoodName(mChild.getSrc()))); } }
override public string ToString() { if (mCastType == null) { return(RTSUtil.linkString(' ', mSrc, mChild, RTSUtil.isNullOrEmpty(mSrc) ? null : (mSrc[0] + 1).ToString())); } else { return(RTSUtil.linkString(' ', '(', mCastType.typeName(), ')', mSrc, mChild, RTSUtil.isNullOrEmpty(mSrc) ? "" : (mSrc[0] + 1).ToString())); } }
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); } }
override public IRTSDefine.Error onCompile(util.RTSList <IRTSLinker> compileList) { if (mLeft == null || !RTSUtil.isGoodName(mDomain)) { return(IRTSDefine.Error.Compiling_DenyLinker); } if (mArgs != null && mArgs.getId() != IRTSDefine.Linker.BRACKET) { return(IRTSDefine.Error.Compiling_DenyLinker); } compileList.add(mLeft); compileList.add(mArgs); return(0); }
public void aliasFunction(string funcName, int argC, string alias) { if (mFuncs == null) { return; } string fname = RTSUtil.keyOfFunc(funcName, argC); IRTSFunction func; if (mFuncs.TryGetValue(fname, out func)) { mFuncs[RTSUtil.keyOfFunc(alias, argC)] = func; } }
public void LoadFunction(object target) { #if UNITY_EDITOR if (target == null) { return; } System.Type tp = target.GetType(); HashSet <RTSPluginAttribute> sets = new HashSet <RTSPluginAttribute>(); mFunctions[tp] = sets; MethodInfo[] methods = tp.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); //bool first = true; for (int i = 0; i < methods.Length; i++) { try { object[] cmds = methods[i].GetCustomAttributes(typeof(RTSPluginAttribute), true); if (cmds.Length > 0) { RTSPluginAttribute cmd = cmds[0] as RTSPluginAttribute; if (!RTSUtil.isGoodName(cmd.Name)) { continue; } RTSPluginDelegate func = (RTSPluginDelegate)System.Delegate.CreateDelegate(typeof(RTSPluginDelegate), target, methods[i].Name); RTSPluginFunc f = new RTSPluginFunc(null, func, cmd.ArgCount); if (cmd.IsCmd) { AddCommand(cmd.Name, f); } else { AddFunction(cmd.Name, f); } //Debug.LogFormat("Load Function: {0}" , desc(cmd)); if (!string.IsNullOrEmpty(cmd.Doc)) { sets.Add(cmd); } } } catch (System.Exception e) { PutLog(Level.error, e.ToString()); Debug.LogException(e); } } #endif }
public IRTSDefine.Stack run(IRTSStack stack) { if (mFunc == null) { mFunc = stack.getThread().getEngine().getFunction(mFuncName, mArgC); if (mFunc == null) { stack.getThread().catchError(IRTSDefine.Error.Runtime_NoFunctionDefine, "Don't find function defined:" + RTSUtil.keyOfFunc(mFuncName, mArgC)); return(0); } } while (mArgs != null && mArgCur < mArgs.length()) { IRTSRunner r = mArgs.get(mArgCur++); if (stack.getThread().loadRunner(r)) { return(0); } } if (!mLoaded) { mLoaded = true; object[] args = mArgC > 0 ? new object[mArgC] : null; if (args != null) { for (int i = 0; i < mArgC; i++) { IRTSRunner r = mArgs.get(i); if (r != null) { args[i] = r.getOutput(); } } } mFuncR = mFunc.createRunner(args); if (stack.getThread().loadRunner(mFuncR)) { return(0); } } mValue = mFuncR == null ? null : mFuncR.getOutput(); if (mCast != null) { mValue = mCast.castValue(mValue); } return(0); }
public bool isVarList() { for (int i = 0; i < mLins.length(); i++) { IRTSLinker l = mLins.get(i); if (l == null || l.getId() != IRTSDefine.Linker.VARIABLE) { return(false); } if (!RTSUtil.isGoodName(l.getSrc())) { return(false); } } return(true); }
public bool loadSource(string text) { if (RTSUtil.isNullOrEmpty(text)) { return(false); } mReader.Reload(text); mCompiling = mReader.hasNext(); if (mCompiling) { mBuild = true; mCompile = true; mTempLinker = new RTSExecL(); mCompileList.clear(); } return(mCompiling); }
public void catchError(IRTSDefine.Error error, object msg) { if (mEngine != null) { IRTSLog log = mEngine.getLogger(); if (log != null) { log.logError(RTSUtil.getEnumDescript(typeof(IRTSDefine.Error), (int)error) + ":" + msg); } mRunners.clear(); } while (mStack.getId() >= 0) { IRTSStack stack = mStack; mStack = stack.getSuper(); stack.onRemoved(); } }
override public string ToString() { System.Text.StringBuilder buf = new System.Text.StringBuilder(); if (mCastType != null) { buf.Append('(').Append(mCastType.typeName()).Append(')'); } if (mProperty != 0) { buf.Append(RTSUtil.propertyName(mProperty)); } buf.Append(mSrc); if (mArg != null) { buf.Append(mArg.ToString()); } return(buf.ToString()); }
public IRTSFunction getFunction(string funcName, int argCount) { if (mFuncs == null) { return(null); } else { IRTSFunction func; if (!mFuncs.TryGetValue(RTSUtil.keyOfFunc(funcName, argCount), out func) && argCount != -1) { if (!mFuncs.TryGetValue(funcName, out func)) { func = null; } } return(func); } }
override public IRTSLinker appendRightChild(IRTSLinker linker) { if (mVarName == null) { if (linker.getId() != IRTSDefine.Linker.VARIABLE || !RTSUtil.isGoodName(linker.getSrc())) { return(linker); } mVarName = linker.getSrc(); return(this); } else if (mArg == null) { if (linker.getId() != IRTSDefine.Linker.BRACKET) { return(linker); } mId = IRTSDefine.Linker.FUNCTION_DEFINE; mArg = linker; linker.setSuper(this); return(null); } else if (mBody == null) { if (linker.getId() != IRTSDefine.Linker.BRACKET_FLOWER) { return(linker); } mId = IRTSDefine.Linker.FUNCTION_DEFINE; mBody = linker; linker.setSuper(this); return(null); } else { return(linker); } }
public object ExecuteImmediate(string cmd) { 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(null); } } IRTSLinker root = mCompiler.getRootLinker(); if (root != null) { mImmediateT.loadRunner(root.createRunner()); while (!mImmediateT.isFinished()) { try { mImmediateT.run(mEngine); } catch (System.Exception ex) { mImmediateT.catchError(IRTSDefine.Error.Runtime_IndexOutOfBounds, ex.ToString()); break; } } return(mImmediateT.getOutput()); } else { return(null); } }
public void SetOperators(string operators) { this.considerOperator &= !RTSUtil.isNullOrEmpty(operators); this.operators = operators; }
public void SetBrackets(string brackets) { this.considerBracket &= !RTSUtil.isNullOrEmpty(brackets); this.brackets = brackets; }
override public string ToString() { return(RTSUtil.linkString(' ', mSrc, mVarName, mArg, mBody)); }
public void SetSeperator(string seperators) { this.seperators = seperators; considerSeperator &= !RTSUtil.isNullOrEmpty(seperators); }