'Look up the stack for the given name.'

def _LookUpStack(self, name):

    i = (len(self.stack) - 1)
    while 1:
        frame = self.stack[i]
        if (name == '@index'):
            if (frame.index != (-1)):
                return frame.index
        else:
            context = frame.context
            if hasattr(context, 'get'):
                try:
                    return context[name]
                except KeyError:
                    pass
        i -= 1
        if (i <= (-1)):
            return self._Undefined(name)
