Esempio n. 1
0
 def dup(self, position):
     """
     Perform a DUP operation on the stack.
     """
     idx = -1 * position
     try:
         self.push(self.values[idx])
     except IndexError:
         raise InsufficientStack("Insufficient stack items for DUP{0}".format(position))
Esempio n. 2
0
 def swap(self, position):
     """
     Perform a SWAP operation on the stack.
     """
     idx = -1 * position - 1
     try:
         self.values[-1], self.values[idx] = self.values[idx], self.values[-1]
     except IndexError:
         raise InsufficientStack("Insufficient stack items for SWAP{0}".format(position))
Esempio n. 3
0
    def pop(self, num_items=1, type_hint=None):
        """
        Pop an item off thes stack.

        Note: This function is optimized for speed over readability.
        """
        try:
            if num_items == 1:
                return next(self._pop(num_items, type_hint))
            else:
                return tuple(self._pop(num_items, type_hint))
        except IndexError:
            raise InsufficientStack("No stack items")