'return compiled code object. if filename is None
invent an artificial filename which displays
the source/line position of the caller frame.'

def compile(self, filename=None, mode='exec', flag=generators.compiler_flag, dont_inherit=0, _genframe=None):

    if ((not filename) or py.path.local(filename).check(file=0)):
        if (_genframe is None):
            _genframe = sys._getframe(1)
        (fn, lineno) = (_genframe.f_code.co_filename, _genframe.f_lineno)
        base = ('<%d-codegen    ' % self._compilecounter)
        self.__class__._compilecounter += 1
        if (not filename):
            filename = (base + ('%s:%d>' % (fn, lineno)))
        else:
            filename = (base + ('%r    %s:%d>' % (filename, fn, lineno)))
    source = ('\n'.join(self.lines) + '\n')
    try:
        co = cpy_compile(source, filename, mode, flag)
    except SyntaxError:
        ex = sys.exc_info()[1]
        msglines = self.lines[:ex.lineno]
        if ex.offset:
            msglines.append((('    ' * ex.offset) + '^'))
        msglines.append(('(code    was    compiled    probably    from    here:    %s)' % filename))
        newex = SyntaxError('\n'.join(msglines))
        newex.offset = ex.offset
        newex.lineno = ex.lineno
        newex.text = ex.text
        raise newex
    else:
        if (flag & _AST_FLAG):
            return co
        lines = [(x + '\n') for x in self.lines]
        py.std.linecache.cache[filename] = (1, None, lines, filename)
        return co
