Exemple #1
0
def ann_weakref_deref(s_ptrtype, s_wref):
    if not (s_ptrtype.is_constant() and isinstance(s_ptrtype.const, lltype.Ptr)
            and s_ptrtype.const.TO._gckind == 'gc'):
        raise Exception("weakref_deref() arg 1 must be a constant "
                        "ptr type, got %s" % (s_ptrtype, ))
    if not (isinstance(s_wref, SomePtr) and s_wref.ll_ptrtype == WeakRefPtr):
        raise Exception("weakref_deref() arg 2 must be a WeakRefPtr, "
                        "got %s" % (s_wref, ))
    return SomePtr(s_ptrtype.const)
Exemple #2
0
def llcast_weakrefptr_to_ptr(s_ptrtype, s_wref):
    if not (s_ptrtype.is_constant()
            and isinstance(s_ptrtype.const, lltype.Ptr)):
        raise Exception("cast_weakrefptr_to_ptr() arg 1 must be a constant "
                        "ptr type, got %s" % (s_ptrtype, ))
    if not (isinstance(s_wref, SomePtr) and s_wref.ll_ptrtype == WeakRefPtr):
        raise Exception("cast_weakrefptr_to_ptr() arg 2 must be a WeakRefPtr, "
                        "got %s" % (s_wref, ))
    return SomePtr(s_ptrtype.const)
Exemple #3
0
def lltype_to_annotation(T):
    try:
        s = ll_to_annotation_map.get(T)
    except TypeError:
        s = None    # unhashable T, e.g. a Ptr(GcForwardReference())
    if s is None:
        if isinstance(T, lltype.Typedef):
            return lltype_to_annotation(T.OF)
        if isinstance(T, lltype.Number):
            return SomeInteger(knowntype=T._type)
        elif isinstance(T, lltype.InteriorPtr):
            return SomeInteriorPtr(T)
        else:
            return SomePtr(T)
    else:
        return s
Exemple #4
0
def llcast_ptr_to_weakrefptr(s_ptr):
    assert isinstance(s_ptr, SomePtr)
    return SomePtr(WeakRefPtr)
Exemple #5
0
def ann_weakref_create(s_obj):
    if (not isinstance(s_obj, SomePtr) or s_obj.ll_ptrtype.TO._gckind != 'gc'):
        raise Exception("bad type for argument to weakref_create(): %r" %
                        (s_obj, ))
    return SomePtr(WeakRefPtr)
Exemple #6
0
def ann_cast_adr_to_ptr(s, s_type):
    assert s_type.is_constant()
    return SomePtr(s_type.const)
Exemple #7
0
 def union((p1, p2)):
     if p1.ll_ptrtype != p2.ll_ptrtype:
         raise UnionError(p1, p2)
     return SomePtr(p1.ll_ptrtype)