pypy / pypy / rpython / ootypesystem /

from pypy.rpython.ootypesystem import ootype

# ____________________________________________________________
# Implementation of the 'canfold' oo operations

def op_ooupcast(INST, inst):
    return ootype.ooupcast(INST, inst)
op_ooupcast.need_result_type = True

def op_oodowncast(INST, inst):
    return ootype.oodowncast(INST, inst)
op_oodowncast.need_result_type = True

def op_cast_to_object(inst):
    return ootype.cast_to_object(inst)

def op_cast_from_object(TYPE, obj):
    return ootype.cast_from_object(TYPE, obj)
op_cast_from_object.need_result_type = True

def op_oononnull(inst):
    return bool(inst)

def op_ooisnull(inst):
    return not op_oononnull(inst)

def op_oois(obj1, obj2):
    if is_inst(obj1):
        return obj1 == obj2   # NB. differently-typed NULLs must be equal
    elif isinstance(obj1, ootype._class):
        assert isinstance(obj2, ootype._class)
        return obj1 is obj2
    elif isinstance(obj1, ootype._object):
        assert isinstance(obj2, ootype._object)
        return obj1 == obj2
        assert False, "oois on something silly"

def op_ooisnot(obj1, obj2):
    return not op_oois(obj1, obj2)

def op_instanceof(inst, INST):
    return ootype.instanceof(inst, INST)

def op_classof(inst):
    return ootype.classof(inst)

def op_subclassof(class1, class2):
    return ootype.subclassof(class1, class2)

def op_oogetfield(inst, name):
    if not ootype.typeOf(inst)._hints.get('immutable'):
        raise TypeError("cannot fold oogetfield on mutable instance")
    return getattr(inst, name)

def is_inst(inst):
    T = ootype.typeOf(inst)
    return T is ootype.Object or T is ootype.Class or\
        isinstance(T, (ootype.Instance,

def checkinst(inst):
    assert is_inst(inst)

# ____________________________________________________________

def get_op_impl(opname):
    # get the op_xxx() function from the globals above
    return globals()['op_' + opname]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.