1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 // ArrayStack: A stack, implemented as a growable array
11 static const int builtinSize = 8;
14 ArrayStack(Compiler *comp, int initialSize = builtinSize)
18 if (initialSize > builtinSize)
20 maxIndex = initialSize;
21 data = new(compiler, CMK_ArrayStack) T[initialSize];
25 maxIndex = builtinSize;
34 if (tosIndex == maxIndex)
37 data[tosIndex] = item;
43 // get a new chunk 2x the size of the old one
46 noway_assert(maxIndex*2 > maxIndex);
47 data = new(compiler, CMK_ArrayStack) T[maxIndex*2];
48 for (int i=0; i<maxIndex; i++)
55 // reverse the top N in the stack
56 void ReverseTop(int number)
61 assert(number <= tosIndex);
63 int start = tosIndex - number;
65 while (offset < number/2)
68 int index = start+offset;
69 int otherIndex = tosIndex - 1 - offset;
71 data[index] = data[otherIndex];
72 data[otherIndex] = temp;
82 return data[tosIndex];
88 return data[tosIndex-1];
94 return data[tosIndex-1];
97 // return the i'th from the top
100 assert(tosIndex > idx);
101 return data[tosIndex - 1 - idx];
104 // return a reference to the i'th from the top
107 assert(tosIndex > idx);
108 return data[tosIndex - 1 - idx];
116 // return the bottom of the stack
119 assert(tosIndex > 0);
123 // return the i'th from the bottom
126 assert(tosIndex > indx);
136 Compiler *compiler; // needed for allocation
137 int tosIndex; // first free location
140 // initial allocation
141 T builtinData[builtinSize];