Beispiel #1
0
        private void OpSize(ParsedOpCode op)
        {
            var length = MainStack.Peek().Length;

            MainStack.Push(length);
        }
Beispiel #2
0
        private void OpInvert(ParsedOpCode op)
        {
            var value = MainStack.PopInt32();

            MainStack.Push(~value);
        }
Beispiel #3
0
 private void Op2Drop()
 {
     MainStack.Pop();
     MainStack.Pop();
 }
Beispiel #4
0
 private void OpFalse()
 {
     MainStack.Push(new byte[0]);
 }
Beispiel #5
0
        private void OpPick()
        {
            var n = MainStack.PopInt32();

            MainStack.Push(MainStack.Peek(n));
        }
Beispiel #6
0
        private void OpTuck()
        {
            var a = MainStack.Peek();

            MainStack.Push(a, 2);
        }
Beispiel #7
0
 private void OpNip()
 {
     MainStack.Pop(1);
 }
Beispiel #8
0
 private void OpOver()
 {
     MainStack.Push(MainStack.Peek(1));
 }
Beispiel #9
0
 private void OpDepth()
 {
     MainStack.Push(MainStack.Size());
 }
Beispiel #10
0
        private void OpDup()
        {
            var value = MainStack.Peek();

            MainStack.Push(value);
        }
Beispiel #11
0
 private void OpFromAltStack()
 {
     MainStack.Push(AltStack.Pop());
 }
Beispiel #12
0
 private void OpToAltStack()
 {
     AltStack.Push(MainStack.Pop());
 }
 public MainContainer(MainStack stack)
     : base(Containers.Main.ToString(), stack.Proxy.NativeView)
 {
     Stack = stack;
 }
Beispiel #14
0
 public Calculator(MainStack stack)
 {
     this.Stack = stack;
 }
Beispiel #15
0
        public void SplitIndex()
        {
            if (MainStack.Peek().Items.Count <= NodeSize)
            {
                //Do nothing since all splitting is done
            }

            //Continue to Split
            else
            {
                #region Initialize values

                //Values to be set and used
                Index       CurrentIndex = new Index(MainStack.Peek());
                Index       LeftIndex;
                Index       CenterIndex = new Index(NodeSize);
                Index       RightIndex  = new Index(NodeSize);
                List <Leaf> RightLeaves = new List <Leaf>();
                int         half        = CurrentIndex.Items.Count / 2;

                //Values to handle being the first root or
                //a non-inner index
                bool isFirstRootSplit = false;
                if (CurrentIndex.IndexList.Count == 0)
                {
                    isFirstRootSplit = true;
                }

                bool needToGetLeaves = false;
                if (CurrentIndex.LeafList != null)
                {
                    needToGetLeaves = true;
                }

                #endregion

                MainStack.Pop();

                #region If split at Root

                if (MainStack.Count == 0)
                {
                    //Root = CenterIndex

                    #region Set Right LeafList

                    //Set start to half if the Root doesn't
                    //reference any indexes
                    int rightCount = half + 1;
                    if (isFirstRootSplit)
                    {
                        rightCount = half;
                    }

                    //Enter Leaves into RightIndex
                    for (; rightCount < CurrentIndex.LeafList.Count; rightCount++)
                    {
                        RightLeaves.Add(CurrentIndex.LeafList[rightCount]);
                    }

                    #endregion

                    #region Set and Reference RightIndex's Indexes/Leaves

                    for (int i = half + 1; i < CurrentIndex.Items.Count; i++)
                    {
                        RightIndex.Items.Add(CurrentIndex.Items[i]);
                    }

                    if (isFirstRootSplit)
                    {
                        for (int i = 0; i < RightIndex.Items.Count; i++)
                        {
                            RightIndex.LeafList.Add(RightLeaves[i]);
                        }
                    }
                    else
                    {
                        for (int i = half; i < CurrentIndex.Items.Count; i++)
                        {
                            RightIndex.IndexList.Add(CurrentIndex.IndexList[i]);
                        }
                    }

                    #endregion

                    //Set Right Index Level
                    RightIndex.IndexLevel = CurrentIndex.IndexLevel;

                    //Dispose values
                    int disposeCount = CurrentIndex.Items.Count;
                    for (int i = half; i < disposeCount; i++)
                    {
                        CurrentIndex.Items.RemoveAt(i);
                        CurrentIndex.IndexList.RemoveAt(i);
                        CurrentIndex.LeafList.RemoveAt(i);
                    }

                    //Set Left Index and reference to CenterIndex
                    LeftIndex = new Index(CurrentIndex);
                    CenterIndex.IndexList.Add(LeftIndex);
                    CenterIndex.IndexList.Add(RightIndex);

                    //Set Index Levels and add CenterIndex
                    IncrementAllTreeLevels();
                    CenterIndex.IndexLevel = 0;
                    Root = new Index(CenterIndex);
                }

                #endregion

                #region If split elsewhere

                else
                {
                    #region Set Right LeafList

                    if (needToGetLeaves)
                    {
                        //Enter Leaves into RightIndex
                        for (int rightCount = half; rightCount < CurrentIndex.LeafList.Count; rightCount++)
                        {
                            RightLeaves.Add(CurrentIndex.LeafList[rightCount]);
                        }
                    }

                    #endregion

                    #region Set and Reference RightIndex's Indexes/Leaves

                    for (int i = half + 1; i < CurrentIndex.Items.Count; i++)
                    {
                        RightIndex.Items.Add(CurrentIndex.Items[i]);
                    }

                    if (needToGetLeaves)
                    {
                        for (int i = 0; i < RightIndex.Items.Count; i++)
                        {
                            RightIndex.LeafList.Add(RightLeaves[i]);
                        }
                    }
                    else
                    {
                        for (int i = half; i < CurrentIndex.Items.Count; i++)
                        {
                            RightIndex.IndexList.Add(CurrentIndex.IndexList[i]);
                        }
                    }

                    #endregion

                    //Set Right Index Level
                    RightIndex.IndexLevel = CurrentIndex.IndexLevel;

                    //Dispose values
                    int disposeCount = CurrentIndex.Items.Count;
                    for (int i = half; i < disposeCount; i++)
                    {
                        CurrentIndex.Items.RemoveAt(i);
                        CurrentIndex.IndexList.RemoveAt(i);
                        CurrentIndex.LeafList.RemoveAt(i);
                    }

                    //Add CurrentIndex to the Index up the tree
                    //with references
                    MainStack.Peek().Insert(CurrentIndex.Items[half], CurrentIndex, RightIndex);

                    //Recursively call SplitIndex until all
                    //Indexes are split that need it
                    SplitIndex();
                }

                #endregion
            }
        }