当前位置: 首页>>代码示例>>Python>>正文


Python support.cdecl函数代码示例

本文整理汇总了Python中pypy.translator.c.support.cdecl函数的典型用法代码示例。如果您正苦于以下问题:Python cdecl函数的具体用法?Python cdecl怎么用?Python cdecl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cdecl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visitor_lines

 def visitor_lines(self, prefix, on_item):
     assert self.varlength == 1
     ARRAY = self.ARRAY
     # we need a unique name for this C variable, or at least one that does
     # not collide with the expression in 'prefix'
     i = 0
     varname = 'p0'
     while prefix.find(varname) >= 0:
         i += 1
         varname = 'p%d' % i
     body = list(on_item('(*%s)' % varname, ARRAY.OF))
     if body:
         yield '{'
         yield '\t%s = %s.items;' % (cdecl(self.itemtypename, '*' + varname),
                                     prefix)
         yield '\t%s = %s + %s.length;' % (cdecl(self.itemtypename,
                                                 '*%s_end' % varname),
                                           varname,
                                           prefix)
         yield '\twhile (%s != %s_end) {' % (varname, varname)
         for line in body:
             yield '\t\t' + line
         yield '\t\t%s++;' % varname
         yield '\t}'
         yield '}'
开发者ID:ieure,项目名称:pypy,代码行数:25,代码来源:node.py

示例2: get

    def get(self, obj, funcgen=None):
        if isinstance(obj, CConstant):
            return obj.c_name  # without further checks
        T = typeOf(obj)
        if isinstance(T, Primitive) or T == GCREF:
            return PrimitiveName[T](obj, self)
        elif isinstance(T, Ptr):
            if (isinstance(T.TO, OpaqueType) and
                T.TO.hints.get('c_pointer_typedef') is not None):
                if obj._obj is not None:
                    value = rffi.cast(rffi.SSIZE_T, obj)
                    return '((%s) %s)' % (cdecl(self.gettype(T), ''),
                                          self.get(value))
            if obj:   # test if the ptr is non-NULL
                try:
                    container = obj._obj
                except lltype.DelayedPointer:
                    # hack hack hack
                    name = obj._obj0
                    assert name.startswith('delayed!')
                    n = len('delayed!')
                    if len(name) == n:
                        raise
                    if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
                        if obj in self.idelayedfunctionnames:
                            return self.idelayedfunctionnames[obj][0]
                        funcname = name[n:]
                        funcname = self.namespace.uniquename('g_'+funcname)
                        self.idelayedfunctionnames[obj] = funcname, obj
                    else:
                        funcname = None      # can't use the name of a
                                             # delayed non-function ptr
                    self.delayedfunctionptrs.append(obj)
                    return funcname
                    # /hack hack hack
                else:
                    # hack hack hack
                    if obj in self.idelayedfunctionnames:
                        # this used to be a delayed function,
                        # make sure we use the same name
                        forcename = self.idelayedfunctionnames[obj][0]
                        node = self.getcontainernode(container,
                                                     forcename=forcename)
                        assert node.getptrname() == forcename
                        return forcename
                    # /hack hack hack

                if isinstance(container, int):
                    # special case for tagged odd-valued pointers
                    return '((%s) %d)' % (cdecl(self.gettype(T), ''),
                                          obj._obj)
                node = self.getcontainernode(container)
                if node._funccodegen_owner is None:
                    node._funccodegen_owner = funcgen
                return node.getptrname()
            else:
                return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
        else:
            raise Exception("don't know about %r" % (obj,))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:59,代码来源:database.py

示例3: OP_FLAVORED_MALLOC_VARSIZE

    def OP_FLAVORED_MALLOC_VARSIZE(self, op):
        # XXX this function should DIE!, at least twice over
        # XXX I know this working in just one case, probably makes
        # sense to assert it here, rest is just copied
        flavor = op.args[0].value
        assert flavor == 'raw'
        TYPE = self.lltypemap(op.result).TO
        assert isinstance(TYPE, Array)
        assert TYPE._hints.get('nolength', False)
        # </obscure hack>
        typename = self.db.gettype(TYPE)
        lenfld = 'length'
        nodedef = self.db.gettypedefnode(TYPE)
        if isinstance(TYPE, Struct):
            arfld = TYPE._arrayfld
            lenfld = "%s.length" % nodedef.c_struct_field_name(arfld)
            VARPART = TYPE._flds[TYPE._arrayfld]
        else:
            VARPART = TYPE
        assert isinstance(VARPART, Array)
        itemtypename = self.db.gettype(VARPART.OF)
        elength = self.expr(op.args[2])
        eresult = self.expr(op.result)
        erestype = cdecl(typename, '*')
        if VARPART.OF is Void:    # strange
            esize = 'sizeof(%s)' % (cdecl(typename, ''),)
            result = '{\n'
        else:
            itemtype = cdecl(itemtypename, '')
            result = 'IF_VARSIZE_OVERFLOW(%s, %s, %s)\nelse {\n' % (
                elength,
                itemtype,
                eresult)
            esize = 'sizeof(%s)-sizeof(%s)+%s*sizeof(%s)' % (
                cdecl(typename, ''),
                itemtype,
                elength,
                itemtype)

        # ctypes Arrays have no length field
        if not VARPART._hints.get('nolength', False):
            result += '\nif(%s) %s->%s = %s;' % (eresult, eresult, lenfld, elength)
        if flavor == "raw": 
            result += "OP_RAW_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
        elif flavor == "stack": 
            result += "OP_STACK_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
        elif flavor == "cpy":
            xxx # this will never work, as I don't know which arg it would be
            # tests, tests, tests....
            cpytype = self.expr(op.args[2])
            result += "OP_CPY_MALLOC(%s, %s, %s);" % (cpytype, eresult, erestype)
        else:
            raise NotImplementedError
        
        result += '\n}'
        return result
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:56,代码来源:funcgen.py

示例4: get

    def get(self, obj):
        if isinstance(obj, ErrorValue):
            T = obj.TYPE
            if isinstance(T, Primitive):
                return PrimitiveErrorValue[T]
            elif isinstance(T, Ptr):
                return 'NULL'
            else:
                raise Exception("don't know about %r" % (T,))
        else:
            T = typeOf(obj)
            if isinstance(T, Primitive):
                return PrimitiveName[T](obj, self)
            elif isinstance(T, Ptr):
                if obj:   # test if the ptr is non-NULL
                    try:
                        container = obj._obj
                    except lltype.DelayedPointer:
                        # hack hack hack
                        name = obj._obj0
                        assert name.startswith('delayed!')
                        n = len('delayed!')
                        if len(name) == n:
                            raise
                        if id(obj) in self.delayedfunctionnames:
                            return self.delayedfunctionnames[id(obj)][0]
                        funcname = name[n:]
                        funcname = self.namespace.uniquename('g_' + funcname)
                        self.delayedfunctionnames[id(obj)] = funcname, obj
                        self.delayedfunctionptrs.append(obj)
                        return funcname
                        # /hack hack hack
                    else:
                        # hack hack hack
                        if id(obj) in self.delayedfunctionnames:
                            # this used to be a delayed function,
                            # make sure we use the same name
                            forcename = self.delayedfunctionnames[id(obj)][0]
                            node = self.getcontainernode(container,
                                                         forcename=forcename)
                            assert node.ptrname == forcename
                            return forcename
                        # /hack hack hack

                    if isinstance(container, int):
                        # special case for tagged odd-valued pointers
                        return '((%s) %d)' % (cdecl(self.gettype(T), ''),
                                              obj._obj)
                    node = self.getcontainernode(container)
                    return node.ptrname
                else:
                    return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
            else:
                raise Exception("don't know about %r" % (obj,))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:54,代码来源:database.py

示例5: definition

 def definition(self):
     gcpolicy = self.db.gcpolicy
     yield 'struct %s {' % self.name
     for fname, typename in self.gcfields:
         yield '\t' + cdecl(typename, fname) + ';'
     if not self.ARRAY._hints.get('nolength', False):
         yield '\tlong length;'
     line = '%s;' % cdecl(self.itemtypename, 'items[%d]'% self.varlength)
     if self.ARRAY.OF is Void:    # strange
         line = '/* %s */' % line
     yield '\t' + line
     yield '};'
开发者ID:antoine1fr,项目名称:pygirl,代码行数:12,代码来源:node.py

示例6: get

    def get(self, obj):
        # XXX extra indent is preserve svn blame - kind of important IMHO (rxe)
        if 1:
            if isinstance(obj, CConstant):
                return obj.c_name  # without further checks
            T = typeOf(obj)
            if isinstance(T, Primitive) or T == GCREF:
                return PrimitiveName[T](obj, self)
            elif isinstance(T, Ptr):
                if obj:   # test if the ptr is non-NULL
                    try:
                        container = obj._obj
                    except lltype.DelayedPointer:
                        # hack hack hack
                        name = obj._obj0
                        assert name.startswith('delayed!')
                        n = len('delayed!')
                        if len(name) == n:
                            raise
                        if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
                            if id(obj) in self.delayedfunctionnames:
                                return self.delayedfunctionnames[id(obj)][0]
                            funcname = name[n:]
                            funcname = self.namespace.uniquename('g_'+funcname)
                            self.delayedfunctionnames[id(obj)] = funcname, obj
                        else:
                            funcname = None      # can't use the name of a
                                                 # delayed non-function ptr
                        self.delayedfunctionptrs.append(obj)
                        return funcname
                        # /hack hack hack
                    else:
                        # hack hack hack
                        if id(obj) in self.delayedfunctionnames:
                            # this used to be a delayed function,
                            # make sure we use the same name
                            forcename = self.delayedfunctionnames[id(obj)][0]
                            node = self.getcontainernode(container,
                                                         forcename=forcename)
                            assert node.ptrname == forcename
                            return forcename
                        # /hack hack hack

                    if isinstance(container, int):
                        # special case for tagged odd-valued pointers
                        return '((%s) %d)' % (cdecl(self.gettype(T), ''),
                                              obj._obj)
                    node = self.getcontainernode(container)
                    return node.ptrname
                else:
                    return '((%s) NULL)' % (cdecl(self.gettype(T), ''), )
            else:
                raise Exception("don't know about %r" % (obj,))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:53,代码来源:database.py

示例7: forward_declaration

 def forward_declaration(self):
     hash_typename = self.get_hash_typename()
     hash_offset = self.db.gctransformer.get_hash_offset(self.T)
     yield '%s {' % cdecl(hash_typename, '')
     yield '\tunion {'
     yield '\t\t%s;' % cdecl(self.implementationtypename, 'head')
     yield '\t\tchar pad[%s];' % name_signed(hash_offset, self.db)
     yield '\t} u;'
     yield '\tlong hash;'
     yield '};'
     yield '%s;' % (
         forward_cdecl(hash_typename, '_hash_' + self.name,
                       self.db.standalone, self.is_thread_local()),)
     yield '#define %s _hash_%s.u.head' % (self.name, self.name)
开发者ID:enyst,项目名称:plexnet,代码行数:14,代码来源:node.py

示例8: forward_declaration

 def forward_declaration(self):
     T = self.getTYPE()
     assert self.typename == self.implementationtypename  # no array part
     hash_typename = self.get_hash_typename()
     hash_offset = self.db.gctransformer.get_hash_offset(T)
     yield "%s {" % cdecl(hash_typename, "")
     yield "\tunion {"
     yield "\t\t%s;" % cdecl(self.implementationtypename, "head")
     yield "\t\tchar pad[%s];" % name_signed(hash_offset, self.db)
     yield "\t} u;"
     yield "\tlong hash;"
     yield "};"
     yield "%s;" % (forward_cdecl(hash_typename, "_hash_" + self.name, self.db.standalone, self.is_thread_local()),)
     yield "#define %s _hash_%s.u.head" % (self.name, self.name)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:14,代码来源:node.py

示例9: definition

 def definition(self):
     gcpolicy = self.db.gcpolicy
     yield "struct %s {" % self.name
     for fname, typename in self.gcfields:
         yield "\t" + cdecl(typename, fname) + ";"
     if not self.ARRAY._hints.get("nolength", False):
         yield "\tlong length;"
     line = "%s;" % cdecl(self.itemtypename, "items[%d]" % self.varlength)
     if self.ARRAY.OF is Void:  # strange
         line = "/* array of void */"
         if self.ARRAY._hints.get("nolength", False):
             line = "char _dummy; " + line
     yield "\t" + line
     yield "};"
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:14,代码来源:node.py

示例10: OP_DEBUG_LLINTERPCALL

 def OP_DEBUG_LLINTERPCALL(self, op):
     result = "abort();  /* debug_llinterpcall should be unreachable */"
     TYPE = self.lltypemap(op.result)
     if TYPE is not Void:
         typename = self.db.gettype(TYPE)
         result += "\n%s = (%s)0;" % (self.expr(op.result), cdecl(typename, ""))
     return result
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:7,代码来源:funcgen.py

示例11: OP_CAST_WEAKADR_TO_PTR

 def OP_CAST_WEAKADR_TO_PTR(self, op):
     TYPE = self.lltypemap(op.result)
     assert TYPE != PyObjPtr
     typename = self.db.gettype(TYPE)
     return '%s = (%s)REVEAL_POINTER(%s);' % (self.expr(op.result),
                                                cdecl(typename, ''),
                                                self.expr(op.args[0]))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:funcgen.py

示例12: implementation

 def implementation(self):
     hash_typename = self.get_hash_typename()
     hash = self.db.gcpolicy.get_prebuilt_hash(self.obj)
     assert hash is not None
     lines = list(self.initializationexpr())
     lines.insert(0, "%s = { {" % (cdecl(hash_typename, "_hash_" + self.name, self.is_thread_local()),))
     lines.append("}, %s /* hash */ };" % name_signed(hash, self.db))
     return lines
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:8,代码来源:node.py

示例13: name_signed

def name_signed(value, db):
    if isinstance(value, Symbolic):
        if isinstance(value, FieldOffset):
            structnode = db.gettypedefnode(value.TYPE)
            return 'offsetof(%s, %s)'%(
                cdecl(db.gettype(value.TYPE), ''),
                structnode.c_struct_field_name(value.fldname))
        elif isinstance(value, ItemOffset):
            if value.TYPE != Void:
                return '(sizeof(%s) * %s)'%(
                    cdecl(db.gettype(value.TYPE), ''), value.repeat)
            else:
                return '0'
        elif isinstance(value, ArrayItemsOffset):
            if isinstance(value.TYPE, FixedSizeArray):
                return '0'
            elif value.TYPE.OF != Void:
                return 'offsetof(%s, items)'%(
                    cdecl(db.gettype(value.TYPE), ''))
            else:
                return 'sizeof(%s)'%(cdecl(db.gettype(value.TYPE), ''),)
        elif isinstance(value, ArrayLengthOffset):
            return 'offsetof(%s, length)'%(
                cdecl(db.gettype(value.TYPE), ''))
        elif isinstance(value, CompositeOffset):
            names = [name_signed(item, db) for item in value.offsets]
            return '(%s)' % (' + '.join(names),)
        elif type(value) == AddressOffset:
            return '0'
        elif type(value) == GCHeaderOffset:
            return '0'
        elif isinstance(value, CDefinedIntSymbolic):
            return str(value.expr)
        elif isinstance(value, ComputedIntSymbolic):
            value = value.compute_fn()
        elif isinstance(value, CConstant):
            return value.c_name
        else:
            raise Exception("unimplemented symbolic %r"%value)
    if value is None:
        assert not db.completed
        return None
    if value == -sys.maxint-1:   # blame C
        return '(-%dL-1L)' % sys.maxint
    else:
        return '%dL' % value
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:46,代码来源:primitive.py

示例14: OP_FLAVORED_MALLOC

 def OP_FLAVORED_MALLOC(self, op):
     # XXX this function should DIE!
     TYPE = self.lltypemap(op.result).TO
     typename = self.db.gettype(TYPE)
     eresult = self.expr(op.result)
     esize = 'sizeof(%s)' % cdecl(typename, '')
     erestype = cdecl(typename, '*')
     flavor = op.args[0].value
     if flavor == "raw": 
         return "OP_RAW_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
     elif flavor == "stack": 
         return "OP_STACK_MALLOC(%s, %s, %s);" % (esize, eresult, erestype)
     elif flavor == "cpy":
         cpytype = self.expr(op.args[2])
         return "OP_CPY_MALLOC(%s, %s, %s);" % (cpytype, eresult, erestype)
     else:
         raise NotImplementedError
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:17,代码来源:funcgen.py

示例15: implementation

 def implementation(self):
     if llgroup.member_of_group(self.obj):
         return []
     lines = list(self.initializationexpr())
     lines[0] = '%s = %s' % (
         cdecl(self.implementationtypename, self.name, self.is_thread_local()),
         lines[0])
     lines[-1] += ';'
     return lines
开发者ID:enyst,项目名称:plexnet,代码行数:9,代码来源:node.py


注:本文中的pypy.translator.c.support.cdecl函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。