Push() публичный Метод

public Push ( int x ) : void
x int
Результат void
Пример #1
0
        /// <summary>
        /// Recycle specified instance to pool.
        /// </summary>
        /// <param name="obj">Instance to recycle.</param>

        /// <summary>
        /// Recycle specified instance to pool.
        /// </summary>
        /// <param name="obj">Instance to recycle.</param>
        /// <param name="checkForDoubleRecycle">Check if instance already was recycled. Use false for performance boost.</param>
        public void Recycle(IPoolObject obj, bool checkForDoubleRecycle = true)
        {
            if ((object)obj != null)
            {
#if UNITY_EDITOR
                if ((object)obj.PoolContainer != (object)this)
                {
                    Debug.LogWarning("Invalid obj to recycle", (UnityEngine.Object)obj);
                    return;
                }
#endif
                var tr = obj.PoolTransform;
                if ((object)tr != null)
                {
                    tr.gameObject.SetActive(false);
                    if ((object)tr.parent != (object)_itemsRoot)
                    {
                        tr.SetParent(_itemsRoot, true);
                    }
                }
                if (checkForDoubleRecycle && _store.Contains(obj))
                {
#if UNITY_EDITOR
                    Debug.LogWarning("Object already was recycled", (UnityEngine.Object)obj);
#endif
                }
                else
                {
                    _store.Push(obj);
                }
            }
        }
        public TemplateRewriterContext Write(ScriptNode node)
        {
            if (node != null)
            {
                bool pushedWhileLoop = false;
                if (node is ScriptLoopStatementBase)
                {
                    _isWhileLoop.Push(node is ScriptWhileStatement);
                    pushedWhileLoop = true;
                }
                try {
                    WriteBegin(node);
                    node.Write(this);
                    WriteEnd(node);
                }
                finally {
                    if (pushedWhileLoop)
                    {
                        _isWhileLoop.Pop();
                    }

                    if (!IsBlockOrPage(node))
                    {
                        _previousRawStatement = node as ScriptRawStatement;
                    }
                }
            }
            return(this);
        }
Пример #3
0
        // pushes all what's required to perform a clr-to-script function call. function can be null if it's already
        // at vstack top.
        private int PushClrToScriptStackFrame(CallStackItemFlags flags, DynValue function, DynValue[] args)
        {
            if (function == null)
            {
                function = m_ValueStack.Peek();
            }
            else
            {
                m_ValueStack.Push(function);                  // func val
            }
            args = Internal_AdjustTuple(args);

            for (int i = 0; i < args.Length; i++)
            {
                m_ValueStack.Push(args[i]);
            }

            m_ValueStack.Push(DynValue.NewNumber(args.Length));              // func args count

            m_ExecutionStack.Push(new CallStackItem()
            {
                BasePointer      = m_ValueStack.Count,
                Debug_EntryPoint = function.Function.EntryPointByteCodeLocation,
                ReturnAddress    = -1,
                ClosureScope     = function.Function.ClosureContext,
                CallingSourceRef = SourceRef.GetClrLocation(),
                Flags            = flags
            });

            return(function.Function.EntryPointByteCodeLocation);
        }
Пример #4
0
        public void AddItem(T item, bool deactivate = true)
        {
            if (!pool.HasRoom)
            {
                if (!allowExpansion)
                {
                    return;
                }

                pool.Resize(pool.Capacity * 2);
                Debug.Log($"[GameObjectPool::AddItem]: Pool Resized to {pool.Capacity}");
            }

            trackedObjects++;
            pool.Push(item);

            if (!deactivate)
            {
                return;
            }

            var go = item.gameObject;

            if (go.activeSelf)
            {
                go.SetActive(false);
            }
        }
Пример #5
0
        internal void PushPipeArguments()
        {
            var pipeArguments = _availablePipeArguments.Count > 0 ? _availablePipeArguments.Pop() : new ScriptPipeArguments(4);

            _pipeArguments.Push(pipeArguments);
            _currentPipeArguments = pipeArguments;
        }
Пример #6
0
 /// <summary>
 /// Pushes the current Page being executed. This should have enough information so that layouts and sections can work correctly.
 /// </summary>
 /// <param name="sourceFile">The Page.</param>
 public void PushPage(ScriptPage page)
 {
     if (page == null)
     {
         throw new ArgumentNullException(nameof(page));
     }
     _pages.Push(page);
 }
Пример #7
0
 public void Add(int i)
 {
     if (!ActiveSlots[i])
     {
         ActiveSlots[i] = true;
         ActiveIndices.Push(i);
     }
 }
Пример #8
0
 /// <summary>
 /// Pushes the source file path being executed. This should have enough information so that template loading/include can work correctly.
 /// </summary>
 /// <param name="sourceFile">The source file.</param>
 public void PushSourceFile(string sourceFile)
 {
     if (sourceFile == null)
     {
         throw new ArgumentNullException(nameof(sourceFile));
     }
     _sourceFiles.Push(sourceFile);
 }
Пример #9
0
 internal DebugWriter()
 {
     Symbols = new DebugInfo();
     scopes = new FastStack<ScopeSym>();
     funs = new FastStack<FunSym>();
     var glob = new ScopeSym(0, 0, 0, 0, 0) { EndOffset = Int32.MaxValue };
     scopes.Push(glob);
     Symbols.Scopes.Add(glob);
 }
Пример #10
0
 /// <summary>
 /// Push a new <see cref="CultureInfo"/> to be used when rendering/parsing numbers.
 /// </summary>
 /// <param name="culture">The new culture to use when rendering/parsing numbers</param>
 public void PushCulture(CultureInfo culture)
 {
     if (culture == null)
     {
         throw new ArgumentNullException(nameof(culture));
     }
     // Create a stack for cultures if they are actually used
     _cultures.Push(culture);
 }
Пример #11
0
 /// <summary>
 /// Pushes a new object context accessible to the template.
 /// </summary>
 /// <param name="scriptObject">The script object.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 public void PushGlobal(IScriptObject scriptObject)
 {
     if (scriptObject == null)
     {
         throw new ArgumentNullException(nameof(scriptObject));
     }
     _globalStores.Push(scriptObject);
     PushVariableScope(ScriptVariableScope.Local);
 }
Пример #12
0
 public void Add(Func <float, RuleResult> r, int i)
 {
     if (!ActiveSlots[i])
     {
         Active[i]      = r;
         ActiveSlots[i] = true;
         ActiveIndices.Push(i);
     }
 }
Пример #13
0
        public async Task <DynValue> CallAsync(DynValue function, DynValue[] args)
        {
            List <Processor> coroutinesStack = m_Parent != null ? m_Parent.m_CoroutinesStack : this.m_CoroutinesStack;

            if (coroutinesStack.Count > 0 && coroutinesStack[coroutinesStack.Count - 1] != this)
            {
                return(coroutinesStack[coroutinesStack.Count - 1].Call(function, args));
            }

            EnterProcessor();

            try
            {
                var stopwatch = this.m_Script.PerformanceStats.StartStopwatch(Diagnostics.PerformanceCounter.Execution);

                m_CanYield = false;

                try
                {
                    m_SavedInstructionPtr = PushClrToScriptStackFrame(CallStackItemFlags.CallEntryPoint, function, args);
                    DynValue retval;
                    while ((retval = Processing_Loop(m_SavedInstructionPtr, true)).Type == DataType.AwaitRequest)
                    {
                        await retval.Task;
                        m_ValueStack.Push(TaskWrapper.TaskResultToDynValue(m_Script, retval.Task));
                    }
                    return(retval);
                }
                finally
                {
                    m_CanYield = true;

                    if (stopwatch != null)
                    {
                        stopwatch.Dispose();
                    }
                }
            }
            finally
            {
                LeaveProcessor();
            }
        }
Пример #14
0
 /// <summary>
 /// Notifies this context when entering a loop.
 /// </summary>
 /// <param name="loop"></param>
 internal void EnterLoop(ScriptLoopStatementBase loop)
 {
     if (loop == null)
     {
         throw new ArgumentNullException(nameof(loop));
     }
     _loops.Push(loop);
     _loopStep = 0;
     PushVariableScope(ScriptVariableScope.Loop);
     OnEnterLoop(loop);
 }
Пример #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TemplateContext" /> class.
        /// </summary>
        /// <param name="builtin">The builtin object used to expose builtin functions, default is <see cref="GetDefaultBuiltinObject"/>.</param>
        public TemplateContext(ScriptObject builtin)
        {
            BuiltinObject = builtin ?? GetDefaultBuiltinObject();
            EnableOutput  = true;
            EnableBreakAndContinueAsReturnOutsideLoop = false;
            LoopLimit      = 1000;
            RecursiveLimit = 100;
            MemberRenamer  = StandardMemberRenamer.Default;

            RegexTimeOut = TimeSpan.FromSeconds(10);

            TemplateLoaderParserOptions = new ParserOptions();
            TemplateLoaderLexerOptions  = LexerOptions.Default;

            NewLine = Environment.NewLine;

            _outputs = new FastStack <IScriptOutput>(4);
            _output  = new StringBuilderOutput();
            _outputs.Push(_output);

            _globalStores    = new FastStack <IScriptObject>(4);
            _localStores     = new FastStack <ScriptObject>(4);
            _loopStores      = new FastStack <ScriptObject>(4);
            _availableStores = new FastStack <ScriptObject>(4);
            _cultures        = new FastStack <CultureInfo>(4);
            _caseValues      = new FastStack <object>(4);

            _localTagsStack = new FastStack <Dictionary <object, object> >(1);
            _loopTagsStack  = new FastStack <Dictionary <object, object> >(1);
            _availableTags  = new FastStack <Dictionary <object, object> >(4);

            _sourceFiles = new FastStack <string>(4);

            _memberAccessors = new Dictionary <Type, IObjectAccessor>();
            _listAccessors   = new Dictionary <Type, IListAccessor>();
            _loops           = new FastStack <ScriptLoopStatementBase>(4);

            BlockDelegates = new FastStack <ScriptBlockStatement>(4);

            _availablePipeArguments = new FastStack <ScriptPipeArguments>(4);
            _pipeArguments          = new FastStack <ScriptPipeArguments>(4);

            _isFunctionCallDisabled = false;

            CachedTemplates = new Dictionary <string, Template>();

            Tags = new Dictionary <object, object>();

            PushPipeArguments();

            // Ensure that builtin is registered first
            PushGlobal(BuiltinObject);
        }
Пример #16
0
        public static void WorksForValueTypes()
        {
            var c = new FastStack <int>();

            c.Push(1);
            Assert.Equal(1, c.Count);
            Assert.Equal(1, c.Peek());
            Assert.Equal(1, c.Count);
            Assert.Equal(1, c.Pop());
            Assert.Equal(0, c.Count);
            c.Push(1);
            c.Push(2);
            Assert.Equal(2, c.Count);
            Assert.Equal(2, c.Peek());
            Assert.Equal(2, c.Count);
            Assert.Equal(2, c.Pop());
            Assert.Equal(1, c.Count);
            Assert.Equal(1, c.Peek());
            Assert.Equal(1, c.Count);
            Assert.Equal(1, c.Pop());
            Assert.Equal(0, c.Count);
        }
Пример #17
0
    public void ComputeSubTreeSize(int root)
    {
        const long X     = 1000000000;
        var        stack = new FastStack <long>(N + 1);

        stack.Push(root * X);
        par[root] = -1;
        d[root]   = 0;

        while (stack.Any())
        {
            var val = stack.Peek();
            var u   = (int)(val / X);
            var it  = (int)(val % X);

            if (it == G[u].Count)
            {
                stack.Pop();
                subTreeSize[u]++;
                if (par[u] >= 0)
                {
                    subTreeSize[par[u]] += subTreeSize[u];
                }
            }
            else
            {
                var to = G[u][it].to;
                stack.Last++;
                if (to == par[u])
                {
                    continue;
                }

                par[to] = u;
                d[to]   = d[u] + 1;
                stack.Push(to * X);
            }
        }
    }
Пример #18
0
        public static void WorksForReferenceTypes()
        {
            var c = new FastStack <string>();

            c.Push("1");
            Assert.Equal(1, c.Count);
            Assert.Equal("1", c.Peek());
            Assert.Equal(1, c.Count);
            Assert.Equal("1", c.Pop());
            Assert.Equal(0, c.Count);
            c.Push("1");
            c.Push("2");
            Assert.Equal(2, c.Count);
            Assert.Equal("2", c.Peek());
            Assert.Equal(2, c.Count);
            Assert.Equal("2", c.Pop());
            Assert.Equal(1, c.Count);
            Assert.Equal("1", c.Peek());
            Assert.Equal(1, c.Count);
            Assert.Equal("1", c.Pop());
            Assert.Equal(0, c.Count);
        }
Пример #19
0
        internal void PopPipeArguments()
        {
            if (_pipeArguments.Count == 0)
            {
                throw new InvalidOperationException("Cannot PopPipeArguments more than PushPipeArguments");
            }

            var pipeFrom = _pipeArguments.Pop();

            pipeFrom.Clear();
            _currentPipeArguments = _pipeArguments.Count > 0 ? _pipeArguments.Peek() : null;
            _availablePipeArguments.Push(pipeFrom);
        }
Пример #20
0
 private void Cleanup()
 {
     //_parent = null;
     _written.Clear();
     // TODO: do we need to clear the array
     //if (_takenCount != 0)
     //{
     //    Array.Clear(_taken, 0, _takenCount);
     //    _takenCount = 0;
     //}
     _taken.Clear();
     _cache.Push(this);
 }
Пример #21
0
        internal DebugWriter()
        {
            Symbols = new DebugInfo();
            scopes  = new FastStack <ScopeSym>();
            funs    = new FastStack <FunSym>();
            var glob = new ScopeSym(0, 0, 0, 0, 0, true)
            {
                EndOffset = Int32.MaxValue
            };

            scopes.Push(glob);
            Symbols.Scopes.Add(glob);
        }
Пример #22
0
        internal void PopPipeArguments()
        {
            if (_pipeArguments.Count == 0)
            {
                throw new InvalidOperationException("Cannot PopPipeArguments more than PushPipeArguments");
            }

            var pipeArguments = _pipeArguments.Pop();

            // Might be not null in case of an exception
            pipeArguments.Clear();
            _availablePipeArguments.Push(pipeArguments);
            _currentPipeArguments = _pipeArguments.Count > 0 ? _pipeArguments.Peek() : null;
        }
Пример #23
0
        public static void DoesntHoldReferences()
        {
            var wr1 = new WeakReference(new object());
            var wr2 = new WeakReference(new object());
            var c   = new FastStack <object>();

            c.Push(wr1.Target);
            c.Push(wr2.Target);
            GCEx.CollectAndWait();
            Assert.Equal(2, c.Count);
            Assert.True(wr1.IsAlive);
            Assert.True(wr2.IsAlive);
            c.Pop();
            GCEx.CollectAndWait();
            Assert.Equal(1, c.Count);
            Assert.True(wr1.IsAlive);
            Assert.False(wr2.IsAlive);
            c.Pop();
            GCEx.CollectAndWait();
            Assert.Equal(0, c.Count);
            Assert.False(wr1.IsAlive);
            Assert.False(wr2.IsAlive);
        }
Пример #24
0
        /// <summary>
        /// Pops a previous <see cref="ScriptVariableScope"/>.
        /// </summary>
        internal void PopVariableScope(ref FastStack <ScriptObject> stores)
        {
            if (stores.Count == 0)
            {
                // Should not happen at runtime
                throw new InvalidOperationException("Invalid number of matching push/pop VariableScope.");
            }

            var store = stores.Pop();

            // The store is cleanup once it is pushed back
            store.Clear();

            _availableStores.Push(store);
        }
Пример #25
0
        /// <summary>
        /// Push a new <see cref="ScriptVariableScope"/> for variables
        /// </summary>
        /// <param name="scope"></param>
        internal void PushVariableScope(ScriptVariableScope scope)
        {
            var store = _availableStores.Count > 0 ? _availableStores.Pop() : new ScriptObject();
            var tags  = _availableTags.Count > 0 ? _availableTags.Pop() : new Dictionary <object, object>();

            if (scope == ScriptVariableScope.Local)
            {
                _localStores.Push(store);
                _localTagsStack.Push(tags);
            }
            else
            {
                _loopStores.Push(store);
                _loopTagsStack.Push(tags);
            }
        }
Пример #26
0
    /// <summary>
    /// Recycles the given item and places it back in the pool for future reuse.
    /// </summary>
    /// <param name="item">The item to be recycled.</param>
    public void Recycle(T item)
    {
      Debug.Assert(item != null, "ResourcePool.Recycle(item) should not be called with null.");

      // Reset item if necessary.
      if (_uninitialize != null)
        _uninitialize(item);

      if (Enabled)
      {
        lock (_stack)
        {
          Debug.Assert(!_stack.Contains(item), "Cannot recycle item. Item is already in the resource pool.");
          _stack.Push(item);
        }
      }
    }
Пример #27
0
        /// <summary>
        /// Pops a previous <see cref="ScriptVariableScope"/>.
        /// </summary>
        /// <param name="scope"></param>
        internal void PopVariableScope(ScriptVariableScope scope)
        {
            Dictionary <object, object> tags;

            if (scope == ScriptVariableScope.Local)
            {
                PopVariableScope(ref _localStores);
                tags = _localTagsStack.Pop();
            }
            else
            {
                PopVariableScope(ref _loopStores);
                tags = _loopTagsStack.Pop();
            }
            // Make sure that tags are clear
            tags.Clear();
            _availableTags.Push(tags);
        }
Пример #28
0
        public void Update(FastStack <TreePage> stack, TreePage newVal)
        {
            var oldNode = stack.Pop();

            stack.Push(newVal);

            var oldPageNumber = oldNode.PageNumber;
            var newPageNumber = newVal.PageNumber;

            if (oldPageNumber == newPageNumber)
            {
                _pagesByNum[oldPageNumber] = newVal;
                return;
            }

            _anyOverrides = true;
            _pagesByNum[oldPageNumber] = newVal;
            _pagesByNum.Add(newPageNumber, newVal);
        }
Пример #29
0
    public void StepAll(float dt)
    {
        for (int i = 0; i < ActiveIndices.Top; i++)
        {
            if (Active[i](dt) == RuleResult.Done)
            {
                ActiveSlots[i] = false;
            }
            else
            {
                SupportStack.Push(i);
            }
        }
        ActiveIndices.Clear();
        var tmp = SupportStack;

        SupportStack  = ActiveIndices;
        ActiveIndices = tmp;
    }
Пример #30
0
        void IWrapUpUpdate.OnWarpUpUpdate()
        {
            var time = Time.time;

            if (lastUpdateIndex == MaxActiveEvents)
            {
                return;
            }

            for (var i = 0; i < MaxActiveEvents; i++)
            {
                ref var activeEvent = ref activeAudioEvents[i];

                if (!activeEvent.IsAlive || !activeEvent.IsDone(time))
                {
                    continue;
                }

                freeIndexes.Push(i);
                activeEvent.IsAlive = false;
                activeEvent.ReturnToPool();
            }
        /// <summary>
        /// Recycle specified instance to pool.
        /// </summary>
        /// <param name="obj">Instance to recycle.</param>
        public void Recycle(IPoolObject obj)
        {
            if ((object)obj != null)
            {
#if UNITY_EDITOR
                if ((object)obj.PoolContainer != (object)this)
                {
                    Debug.LogWarning("Invalid obj to recycle", (UnityEngine.Object)obj);
                    return;
                }
#endif
                var tr = obj.PoolTransform;
                if ((object)tr != null)
                {
                    tr.gameObject.SetActive(false);
                }
                if (!_store.Contains(obj))
                {
                    _store.Push(obj);
                }
            }
        }
Пример #32
0
 private void DefloodLight(IEnumerable<Vector3i> start)
 {
     FastStack<Vector3i> q = new FastStack<Vector3i>();
     q.Initialize(1024);
     Vector3i ss = new Vector3i();
     foreach (var s in start)
     {
         q.Push(s);
         ss = s;
     }
     Dictionary<Vector3i, bool> reflood = new Dictionary<Vector3i, bool>();
     int searched = 1;
     for (; ; )
     {
         if (q.Count == 0)
         {
             break;
         }
         Vector3i v = q.Pop();
         searched++;
         if (distancesquare(v, new Vector3i(ss.x, ss.y, ss.z)) > maxlight * 2 * maxlight * 2)
         {
             continue;
         }
         int vblock = map.GetBlock(v.x, v.y, v.z);
         if (!data.GrassGrowsUnder(vblock)
             && data.GetLightRadius(vblock) == 0)
         {
             continue;
         }
         int vlight = LightGetBlock(v.x, v.y, v.z);
         if (vlight == maxlight
             || data.GetLightRadius(vblock) != 0)
         {
             reflood[v] = true;
             continue;
         }
         if (vlight == minlight)
         {
             continue;
         }
         SetLight(v.x, v.y, v.z, minlight);
         foreach (var n in BlocksNear(v.x, v.y, v.z))
         {
             if (!MapUtil.IsValidPos(map, n.x, n.y, n.z))
             {
                 continue;
             }
             if (LightGetBlock(n.x, n.y, n.z) < vlight)
             {
                 q.Push(n);
             }
             else
             {
                 reflood[n] = true;
             }
         }
     }
     //Console.WriteLine("reflood: {0}, searched: {1}", reflood.Keys.Count, searched);
     foreach (var p in reflood.Keys)
     {
         currentlightchunk = null;
         FloodLight(p.x, p.y, p.z);
     }
 }