internal Proc(IEnumerator _procedure, string _tag = "_", Func <bool> fnValidate = null) { ProcStack.PushLast(_procedure); ID = IDCounter++; Tag = _tag; Validator = fnValidate; }
public bool Frame(long realTimeMs) { if (null != GetOpCurr(realTimeMs)) { return(false); } IEnumerator procTop = null; while (ProcStack.Count > 0 && null == procTop) { procTop = ProcStack[ProcStack.Count - 1]; if (!procTop.MoveNext()) { ProcStack.PopLast(); procTop = null; } } if (null == procTop) { End(); return(false); } ExecutedTime = CSP.LazyInst.sw.ElapsedMilliseconds; return(EnqueueOperation(procTop.Current)); }
void PushStack(StackType type) { ProcStack newStack = new ProcStack(); newStack.StackType = type; curIndex++; switch (type) { case StackType.Dict: newStack.StackObj = new Dict(); break; case StackType.List: newStack.StackObj = new List(); newStack.StackCount = ReadInt32(); break; case StackType.Tuple: newStack.StackObj = new List <object>(); newStack.StackCount = ReadInt32(); break; } if (stack == null) { stack = new Stack <ProcStack>(); } stack.Push(newStack); }
public Proc QueueJump(IEnumerator queueJumper) { if (isActive) { Debug.LogError("UniKH/CSP/Proc: delay proc failed, this proc is currently running."); } ProcStack.StackPush(queueJumper); return(this); }
private void PushStack(StackType type) { ProcStack newStack = new ProcStack(); newStack.StackType = type; switch (type) { case StackType.Dict: newStack.StackObj = new PythonDictionary(); newStack.StackCount = -1; break; case StackType.List: newStack.StackObj = new PythonList(); newStack.StackCount = ReadInt32(); break; case StackType.Tuple: newStack.StackCount = ReadInt32(); newStack.StackObj = new List <object> (newStack.StackCount); break; case StackType.Set: newStack.StackObj = new SetCollection(); newStack.StackCount = ReadInt32(); break; case StackType.FrozenSet: newStack.StackCount = ReadInt32(); newStack.StackObj = new List <object> (newStack.StackCount); break; } if (_stack == null) { _stack = new Stack <ProcStack> (); } _stack.Push(newStack); }
private object UpdateStack(object res) { ProcStack curStack = _stack.Peek(); switch (curStack.StackType) { case StackType.Dict: PythonDictionary od = curStack.StackObj as PythonDictionary; if (curStack.HaveKey) { od[curStack.Key] = res; curStack.HaveKey = false; } else { curStack.HaveKey = true; curStack.Key = res; } break; case StackType.Tuple: List <object> objs = curStack.StackObj as List <object>; objs.Add(res); curStack.StackCount--; if (curStack.StackCount == 0) { _stack.Pop(); object tuple = PythonTuple.Make(objs); if (_stack.Count == 0) { _result = tuple; } return(tuple); } break; case StackType.List: PythonList ol = curStack.StackObj as PythonList; ol.AddNoLock(res); curStack.StackCount--; if (curStack.StackCount == 0) { _stack.Pop(); if (_stack.Count == 0) { _result = ol; } return(ol); } break; case StackType.Set: SetCollection os = curStack.StackObj as SetCollection; os.add(res); curStack.StackCount--; if (curStack.StackCount == 0) { _stack.Pop(); if (_stack.Count == 0) { _result = os; } return(os); } break; case StackType.FrozenSet: List <object> ofs = curStack.StackObj as List <object>; ofs.Add(res); curStack.StackCount--; if (curStack.StackCount == 0) { _stack.Pop(); object frozenSet = FrozenSetCollection.Make(TypeCache.FrozenSet, ofs); if (_stack.Count == 0) { _result = frozenSet; } return(frozenSet); } break; } return(null); }
public object ReadObject() { while (_myBytes.MoveNext()) { byte cur = _myBytes.Current; object res; switch ((char)cur) { case '(': PushStack(StackType.Tuple); break; case '[': PushStack(StackType.List); break; case '{': PushStack(StackType.Dict); break; case '<': PushStack(StackType.Set); break; case '>': PushStack(StackType.FrozenSet); break; case '0': // end of dictionary if (_stack == null || _stack.Count == 0) { throw PythonOps.ValueError("bad marshal data"); } _stack.Peek().StackCount = 0; break; // case 'c': break; default: res = YieldSimple(); if (_stack == null) { return(res); } do { res = UpdateStack(res); } while (res != null && _stack.Count > 0); if (_stack.Count == 0) { return(_result); } continue; } // handle empty lists/tuples... if (_stack != null && _stack.Count > 0 && _stack.Peek().StackCount == 0) { ProcStack ps = _stack.Pop(); res = ps.StackObj; if (ps.StackType == StackType.Tuple) { res = PythonTuple.Make(res); } else if (ps.StackType == StackType.FrozenSet) { res = FrozenSetCollection.Make(TypeCache.FrozenSet, res); } if (_stack.Count > 0) { // empty list/tuple do { res = UpdateStack(res); } while (res != null && _stack.Count > 0); if (_stack.Count == 0) { break; } } else { _result = res; break; } } } return(_result); }
private void PushStack (StackType type) { ProcStack newStack = new ProcStack (); newStack.StackType = type; switch (type) { case StackType.Dict: newStack.StackObj = new PythonDictionary (); newStack.StackCount = -1; break; case StackType.List: newStack.StackObj = new List (); newStack.StackCount = ReadInt32 (); break; case StackType.Tuple: newStack.StackCount = ReadInt32 (); newStack.StackObj = new List<object> (newStack.StackCount); break; case StackType.Set: newStack.StackObj = new SetCollection (); newStack.StackCount = ReadInt32 (); break; case StackType.FrozenSet: newStack.StackCount = ReadInt32 (); newStack.StackObj = new List<object> (newStack.StackCount); break; } if (_stack == null) _stack = new Stack<ProcStack> (); _stack.Push (newStack); }
void PushStack(StackType type) { ProcStack newStack = new ProcStack(); newStack.StackType = type; curIndex++; switch (type) { case StackType.Dict: newStack.StackObj = new Dict(); if (curIndex == myBytes.Length) throw Ops.EofError("EOF read where object expected"); if (myBytes[curIndex] == '0') newStack.StackCount = 0; else newStack.StackCount = -1; break; case StackType.List: newStack.StackObj = new List(); newStack.StackCount = ReadInt32(); break; case StackType.Tuple: newStack.StackObj = new List<object>(); newStack.StackCount = ReadInt32(); break; } if (stack == null) stack = new Stack<ProcStack>(); stack.Push(newStack); }
public bool EnqueueOperation(object yieldVal) { if (yieldVal is null) { // skip this frame return(EnqueueOperation(Skip.New.Start())); } if (yieldVal is WaitingOperation) { // WaitingOperation < CustomYieldInstruction < IEnumerator, the default SetOpCurr(yieldVal as WaitingOperation); return(false); } if (yieldVal is CustomYieldInstruction) { SetOpCurr(UnityCustomYieldInstruction.New.Start(yieldVal as CustomYieldInstruction)); return(false); } if (yieldVal is IEnumerator) { ProcStack.StackPush(yieldVal as IEnumerator); return(false); } if (yieldVal is Result) { Channel.QueuePush((yieldVal as Result).Val); return(true); } if (yieldVal is int) { float value = ((int)yieldVal); return(EnqueueOperation(UnitySecond.New.Start(value))); } if (yieldVal is uint) { float value = ((uint)yieldVal); return(EnqueueOperation(UnitySecond.New.Start(value))); } if (yieldVal is float) { return(EnqueueOperation(UnitySecond.New.Start((float)yieldVal))); } if (yieldVal is double) { return(EnqueueOperation(UnitySecond.New.Start((float)(double)yieldVal))); } if (yieldVal is decimal) { return(EnqueueOperation(RealSecond.New.Start((float)(decimal)yieldVal))); } if (yieldVal is AsyncOperation) { return(EnqueueOperation(UnityAsync.New.Start(yieldVal as AsyncOperation))); } if (yieldVal is WaitForSeconds) { var ts = (yieldVal as WaitForSeconds).GetType(); var field = ts.GetField("m_Seconds", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var sec = field.GetValue(yieldVal); return(EnqueueOperation(UnitySecond.New.Start((float)sec))); } if (yieldVal is WaitForEndOfFrame) { // WaitForEndOfFrame: skip this frame, but try execute in the next tickFrame return (EnqueueOperation(Skip.New .Start())); // todo: This implementation is incomplete, and it needs to be reconsidered in the future. } if (yieldVal is string) { // wait a frame and show this string Debug.Log(yieldVal); return(EnqueueOperation(Skip.New.Start())); } Debug.LogError(SGen.New["yield return value of type "][yieldVal.GetType()]["are not supported."].End); End(); return(false); }
object UpdateStack(object res) { ProcStack curStack = stack.Peek(); switch (curStack.StackType) { case StackType.Dict: Dict od = curStack.StackObj as Dict; if (curStack.HaveKey) { od.Add(curStack.Key, res); curStack.HaveKey = false; } else { curStack.HaveKey = true; curStack.Key = res; } if (curIndex == myBytes.Length) { throw Ops.EofError("EOF read where object expected"); } if (myBytes[curIndex] == '0') { stack.Pop(); if (stack.Count == 0) { result = od; } return(od); } break; case StackType.Tuple: List <object> objs = curStack.StackObj as List <object>; objs.Add(res); curStack.StackCount--; if (curStack.StackCount == 0) { stack.Pop(); object tuple = Tuple.Make(objs); if (stack.Count == 0) { result = tuple; } return(tuple); } break; case StackType.List: List ol = curStack.StackObj as List; ol.AddNoLock(res); curStack.StackCount--; if (curStack.StackCount == 0) { stack.Pop(); if (stack.Count == 0) { result = ol; } return(ol); } break; } return(null); }