Exemplo n.º 1
0
 def fn_null():
     a = ootype.null(A)
     b = ootype.null(B)
     obj1 = ootype.cast_to_object(a)
     obj2 = ootype.cast_to_object(b)
     assert obj1 == obj2
     assert ootype.cast_from_object(A, obj1) == a
     assert ootype.cast_from_object(B, obj2) == b
Exemplo n.º 2
0
 def fn_null():
     a = ootype.null(A)
     b = ootype.null(B)
     obj1 = ootype.cast_to_object(a)
     obj2 = ootype.cast_to_object(b)
     assert obj1 == obj2
     assert ootype.cast_from_object(A, obj1) == a
     assert ootype.cast_from_object(B, obj2) == b
Exemplo n.º 3
0
 def record_dependencies(self):
     if self.value is ootype.null(self.value._TYPE):
         self.delegate_impl = None
         return
     StaticMethodConst.record_dependencies(self)
     self.delegate_impl = self.db.record_delegate_standalone_func_impl(
         self.value.graph)
Exemplo n.º 4
0
 def record_dependencies(self):
     if self.value is ootype.null(self.value._TYPE):
         self.delegate_impl = None
         return
     StaticMethodConst.record_dependencies(self)
     self.delegate_impl = self.db.record_delegate_standalone_func_impl(
         self.value.graph)
Exemplo n.º 5
0
 def fn_is_true(flag):
     if flag:
         a = ootype.new(A)
     else:
         a = ootype.null(A)
     obj = ootype.cast_to_object(a)
     return bool(obj)
Exemplo n.º 6
0
    def push_primitive_constant(self, TYPE, value):

        if TYPE is ootype.Void:
            return
        elif isinstance(value, CDefinedIntSymbolic):
            self.emit(jvm.ICONST, self.DEFINED_INT_SYMBOLICS[value.expr])
        elif TYPE in (ootype.Bool, ootype.Signed):
            self.emit(jvm.ICONST, int(value))
        elif TYPE is ootype.Unsigned:
            # Converts the unsigned int into its corresponding signed value:
            if value > 0x7FFFFFFF:
                value = -((int(value) ^ 0xFFFFFFFF)+1)
            self.emit(jvm.ICONST, value)
        elif TYPE is ootype.Char or TYPE is ootype.UniChar:
            self.emit(jvm.ICONST, ord(value))
        elif TYPE is ootype.SignedLongLong:
            self._push_long_constant(long(value))
        elif TYPE is ootype.UnsignedLongLong:
            # Converts the unsigned long into its corresponding signed value:
            if value > 0x7FFFFFFFFFFFFFFF:
                value = -((long(value) ^ 0xFFFFFFFFFFFFFFFF)+1)
            self._push_long_constant(value)
        elif TYPE is ootype.Float:
            self._push_double_constant(float(value))
        elif TYPE in (ootype.String, ootype.Unicode):
            if value == ootype.null(TYPE):
                self.emit(jvm.ACONST_NULL)
            else:
                self.load_string(value._str)
        else:
            assert False, 'Unknown constant type: %s' % TYPE
Exemplo n.º 7
0
 def record_dependencies(self):
     if self.value is ootype.null(self.value._TYPE):
         return
     for f_name, (FIELD_TYPE,
                  f_default) in self.value._TYPE._fields.iteritems():
         value = self.value._items[f_name]
         self._record_const_if_complex(FIELD_TYPE, value)
Exemplo n.º 8
0
    def setup_excdata(self):
        EXCDATA = ootype.Record({'exc_type': self.lltype_of_exception_type,
                                 'exc_value': self.lltype_of_exception_value})
        self.EXCDATA = EXCDATA

        exc_data = ootype.new(EXCDATA)
        null_type = ootype.null(self.lltype_of_exception_type)
        null_value = ootype.null(self.lltype_of_exception_value)

        self.exc_data_ptr = exc_data
        self.cexcdata = Constant(exc_data, self.EXCDATA)

        self.c_null_etype = Constant(null_type, self.lltype_of_exception_type)
        self.c_null_evalue = Constant(null_value, self.lltype_of_exception_value)

        return exc_data, null_type, null_value
Exemplo n.º 9
0
 def fn_is_true(flag):
     if flag:
         a = ootype.new(A)
     else:
         a = ootype.null(A)
     obj = ootype.cast_to_object(a)
     return bool(obj)
Exemplo n.º 10
0
def error_value(T):
    if isinstance(T, lltype.Primitive):
        return PrimitiveErrorValue[T]
    elif isinstance(T, lltype.Ptr):
        return lltype.nullptr(T.TO)
    elif isinstance(T, ootype.OOType):
        return ootype.null(T)
    assert 0, "not implemented yet"
Exemplo n.º 11
0
def ll_tuplenext(iter):
    # for iterating over length 1 tuples only!
    t = iter.iterable
    if t:
        iter.iterable = ootype.null(ootype.typeOf(t))
        return t.item0
    else:
        raise StopIteration
Exemplo n.º 12
0
def error_value(T):
    if isinstance(T, lltype.Primitive):
        return PrimitiveErrorValue[T]
    elif isinstance(T, lltype.Ptr):
        return lltype.nullptr(T.TO)
    elif isinstance(T, ootype.OOType):
        return ootype.null(T)
    assert 0, "not implemented yet"
Exemplo n.º 13
0
 def check_declaration(self, arg):
     if isinstance(arg, Constant):
         if isinstance(arg.concretetype, (Record, Instance)):
             if arg.value is null(arg.concretetype):
                 return "nil"
         if isinstance(arg.concretetype, Instance):
             return self.declare_constant_instance(arg)
     return clrepr(arg)
Exemplo n.º 14
0
def ll_tuplenext(iter):
    # for iterating over length 1 tuples only!
    t = iter.iterable
    if t:
        iter.iterable = ootype.null(ootype.typeOf(t))
        return t.item0
    else:
        raise StopIteration
Exemplo n.º 15
0
    def setup_excdata(self):
        EXCDATA = ootype.Record({
            'exc_type': self.lltype_of_exception_type,
            'exc_value': self.lltype_of_exception_value
        })
        self.EXCDATA = EXCDATA

        exc_data = ootype.new(EXCDATA)
        null_type = ootype.null(self.lltype_of_exception_type)
        null_value = ootype.null(self.lltype_of_exception_value)

        self.exc_data_ptr = exc_data
        self.cexcdata = Constant(exc_data, self.EXCDATA)

        self.c_null_etype = Constant(null_type, self.lltype_of_exception_type)
        self.c_null_evalue = Constant(null_value,
                                      self.lltype_of_exception_value)

        return exc_data, null_type, null_value
Exemplo n.º 16
0
    def record_dependencies(self):
        # Near as I can tell, self.value is an ootype._custom_dict,
        # key_eq is a Python function and graph is, well, a method
        # graph that seems to be added to the function pointer
        # somewhere.  Adapted from cli/constant.py
        if self.value is ootype.null(self.value._TYPE):
            return
        self.eq_jcls = self.db.record_delegate_standalone_func_impl(self.value._dict.key_eq.graph)
        self.hash_jcls = self.db.record_delegate_standalone_func_impl(self.value._dict.key_hash.graph)

        CustomDictConst.record_dependencies(self)
Exemplo n.º 17
0
    def record_dependencies(self):
        # Near as I can tell, self.value is an ootype._custom_dict,
        # key_eq is a Python function and graph is, well, a method
        # graph that seems to be added to the function pointer
        # somewhere.  Adapted from cli/constant.py
        if self.value is ootype.null(self.value._TYPE):
            return
        self.eq_jcls = self.db.record_delegate_standalone_func_impl(
            self.value._dict.key_eq.graph)
        self.hash_jcls = self.db.record_delegate_standalone_func_impl(
            self.value._dict.key_hash.graph)

        CustomDictConst.record_dependencies(self)
Exemplo n.º 18
0
class OOWeakRefRepr(BaseWeakRefRepr):
    lowleveltype = ootype.WeakReference
    dead_wref = ootype.dead_wref
    null_wref = ootype.null(ootype.WeakReference)

    def rtype_simple_call(self, hop):
        v_wref, = hop.inputargs(self)
        cname = hop.inputconst(ootype.Void, 'll_deref')
        hop.exception_cannot_occur()
        if hop.r_result.lowleveltype is lltype.Void:  # known-to-be-dead weakref
            return hop.inputconst(lltype.Void, None)
        else:
            v_deref = hop.genop('oosend', [cname, v_wref],
                                resulttype=ootype.ROOT)
            return hop.genop('oodowncast', [v_deref], resulttype=hop.r_result)

    def _weakref_create(self, llinstance):
        return ootype.ooweakref_create(llinstance)
Exemplo n.º 19
0
    def specialize_call(self, hop):
        from pypy.rpython import rpbc
        PTR = hop.r_result.lowleveltype
        if isinstance(PTR, lltype.Ptr):
            T = lltype.Ptr
            opname = 'cast_pointer'
            null = lltype.nullptr(PTR.TO)
        elif isinstance(PTR, ootype.Instance):
            T = ootype.Instance
            opname = 'ooupcast'
            null = ootype.null(PTR)
        else:
            assert False

        if isinstance(hop.args_r[1], rpbc.NoneFrozenPBCRepr):
            return hop.inputconst(PTR, null)
        v_arg = hop.inputarg(hop.args_r[1], arg=1)
        assert isinstance(v_arg.concretetype, T)
        hop.exception_cannot_occur()
        return hop.genop(opname, [v_arg], resulttype=PTR)
Exemplo n.º 20
0
    def specialize_call(self, hop):
        from pypy.rpython import rpbc
        PTR = hop.r_result.lowleveltype
        if isinstance(PTR, lltype.Ptr):
            T = lltype.Ptr
            opname = 'cast_pointer'
            null = lltype.nullptr(PTR.TO)
        elif isinstance(PTR, ootype.Instance):
            T = ootype.Instance
            opname = 'ooupcast'
            null = ootype.null(PTR)
        else:
            assert False

        if isinstance(hop.args_r[1], rpbc.NoneFrozenPBCRepr):
            return hop.inputconst(PTR, null)
        v_arg = hop.inputarg(hop.args_r[1], arg=1)
        assert isinstance(v_arg.concretetype, T)
        hop.exception_cannot_occur()
        return hop.genop(opname, [v_arg], resulttype = PTR)
Exemplo n.º 21
0
    def _create_complex_const(self, value):

        """ A helper method which creates a Constant wrapper object for
        the given value.  Uses the types defined in the sub-class. """

        # Determine if the static type differs from the dynamic type.
        if isinstance(value, ootype._view):
            static_type = value._TYPE
            value = value._inst
        else:
            static_type = None

        # Find the appropriate kind of Const object.
        genoo = self.genoo
        uniq = self.db.unique()
        if isinstance(value, ootype._instance):
            return genoo.InstanceConst(self.db, value, static_type, uniq)
        elif isinstance(value, ootype._record):
            return genoo.RecordConst(self.db, value, uniq)
        elif isinstance(value, ootype._class):
            return genoo.ClassConst(self.db, value, uniq)
        elif isinstance(value, ootype._list):
            return genoo.ListConst(self.db, value, uniq)
        elif isinstance(value, ootype._array):
            return genoo.ArrayConst(self.db, value, uniq)
        elif isinstance(value, ootype._static_meth):
            return genoo.StaticMethodConst(self.db, value, uniq)
        elif isinstance(value, ootype._custom_dict):
            return genoo.CustomDictConst(self.db, value, uniq)
        elif isinstance(value, ootype._dict):
            return genoo.DictConst(self.db, value, uniq)
        elif isinstance(value, ootype._weak_reference):
            return genoo.WeakRefConst(self.db, value, uniq)
        elif value is ootype.null(value._TYPE):
            # for NULL values, we can just use "NULL" const.  This is
            # a fallback since we sometimes have constants of
            # unhandled types which are equal to NULL.
            return genoo.NullConst(self.db, value, uniq)
        else:
            assert False, 'Unknown constant: %s' % value        
Exemplo n.º 22
0
    def _create_complex_const(self, value):
        """ A helper method which creates a Constant wrapper object for
        the given value.  Uses the types defined in the sub-class. """

        # Determine if the static type differs from the dynamic type.
        if isinstance(value, ootype._view):
            static_type = value._TYPE
            value = value._inst
        else:
            static_type = None

        # Find the appropriate kind of Const object.
        genoo = self.genoo
        uniq = self.db.unique()
        if isinstance(value, ootype._instance):
            return genoo.InstanceConst(self.db, value, static_type, uniq)
        elif isinstance(value, ootype._record):
            return genoo.RecordConst(self.db, value, uniq)
        elif isinstance(value, ootype._class):
            return genoo.ClassConst(self.db, value, uniq)
        elif isinstance(value, ootype._list):
            return genoo.ListConst(self.db, value, uniq)
        elif isinstance(value, ootype._array):
            return genoo.ArrayConst(self.db, value, uniq)
        elif isinstance(value, ootype._static_meth):
            return genoo.StaticMethodConst(self.db, value, uniq)
        elif isinstance(value, ootype._custom_dict):
            return genoo.CustomDictConst(self.db, value, uniq)
        elif isinstance(value, ootype._dict):
            return genoo.DictConst(self.db, value, uniq)
        elif isinstance(value, ootype._weak_reference):
            return genoo.WeakRefConst(self.db, value, uniq)
        elif value is ootype.null(value._TYPE):
            # for NULL values, we can just use "NULL" const.  This is
            # a fallback since we sometimes have constants of
            # unhandled types which are equal to NULL.
            return genoo.NullConst(self.db, value, uniq)
        else:
            assert False, 'Unknown constant: %s' % value
Exemplo n.º 23
0
 def null_callable(self, T):
     return ootype.null(T)
Exemplo n.º 24
0
 def test_cast_record_mix_object(self):
     T = ootype.Record({'x': ootype.Signed})
     NULL = ootype.null(System.Object._INSTANCE)
     record = cast_record_to_object(ootype.new(T))
     assert record != NULL
     assert NULL != record
Exemplo n.º 25
0
 def to_rstr(s):
     if s is None:
         return ootype.null(ootype.String)
     return ootype.oostring(s, -1)
Exemplo n.º 26
0
def rtype_null(hop):
    hop.exception_cannot_occur()
    assert hop.args_s[0].is_constant()
    TYPE = hop.args_s[0].const
    nullvalue = ootype.null(TYPE)
    return hop.inputconst(TYPE, nullvalue)
Exemplo n.º 27
0
 def record_dependencies(self):
     if self.value is ootype.null(self.value._TYPE):
         return
     for f_name, (FIELD_TYPE, f_default) in self.value._TYPE._fields.iteritems():
         value = self.value._items[f_name]            
         self._record_const_if_complex(FIELD_TYPE, value)
Exemplo n.º 28
0
def ll_inst_type(obj):
    if obj:
        return obj.meta
    else:
        # type(None) -> NULL  (for now)
        return ootype.null(CLASSTYPE)
Exemplo n.º 29
0
    @specialize.arg(1)
    def genop2(self, opname, gv_arg1, gv_arg2):
        # XXX: this only serves to mask a bug in gencli which I don't
        # feel like fixing now. Try to uncomment this and run
        # test_goto_compile to see why it fails
        return Builder.genop2(self, opname, gv_arg1, gv_arg2)

    def emit(self, op):
        self.operations.append(op)

    def appendbranch(self, branch):
        self.parent.appendbranch(branch)

    def appendreturn(self, retlabel, gv_returnvar):
        self.parent.appendreturn(retlabel, gv_returnvar)

    def end(self):
        self.parent.end()

    def replayops(self):
        assert not self.isOpen
        assert not self.parent.isOpen
        il = self.parent.il
        il.MarkLabel(self.label)        
        for op in self.operations:
            op.emit()

global_rgenop = RCliGenOp()
RCliGenOp.constPrebuiltGlobal = global_rgenop.genconst
zero_const = ObjectConst(ootype.null(ootype.ROOT))
Exemplo n.º 30
0
 def null_instance(self):
     return ootype.null(PBCROOT)
Exemplo n.º 31
0
 def null_instance(self):
     return ootype.null(PBCROOT)
Exemplo n.º 32
0
 def null_instance(self):
     return ootype.null(self.lowleveltype)
Exemplo n.º 33
0
def rtype_null(hop):
    assert hop.args_s[0].is_constant()
    TYPE = hop.args_s[0].const
    nullvalue = ootype.null(TYPE)
    return hop.inputconst(TYPE, nullvalue)
Exemplo n.º 34
0
 def null_const(self):
     return ootype.null(self.LIST)
Exemplo n.º 35
0
 def to_rstr(s):
     if s is None:
         return ootype.null(ootype.String)
     return ootype.oostring(s, -1)
Exemplo n.º 36
0
 def null_const(self):
     return ootype.null(self.LIST)
Exemplo n.º 37
0
 def is_null(self):
     return self.value is ootype.null(self.value._TYPE)
Exemplo n.º 38
0
 def is_null(self):
     return self.value is ootype.null(self.value._TYPE)
Exemplo n.º 39
0
 def record_dependencies(self):
     if self.value is ootype.null(self.value._TYPE):
         return
     if hasattr(self.value, 'graph'):
         self.db.pending_function(self.value.graph)
     self.delegate_type = self.db.record_delegate(self.value._TYPE)
Exemplo n.º 40
0
def null(I_OR_SM):
    assert I_OR_SM.is_constant()
    null = ootype.null(I_OR_SM.const)
    r = lltype_to_annotation(ootype.typeOf(null))
    return r
Exemplo n.º 41
0
 def empty(self):
     return ootype.null(self.lowleveltype)
Exemplo n.º 42
0
def null(I_OR_SM):
    assert I_OR_SM.is_constant()
    null = ootype.null(I_OR_SM.const)
    r = lltype_to_annotation(ootype.typeOf(null))
    return r
Exemplo n.º 43
0
 def record_dependencies(self):
     if self.value is ootype.null(self.value._TYPE):
         return
     self.db.pending_function(self.value.graph)
     self.delegate_type = self.db.record_delegate(self.value._TYPE)
Exemplo n.º 44
0
def rtype_null(hop):
    hop.exception_cannot_occur()
    assert hop.args_s[0].is_constant()
    TYPE = hop.args_s[0].const
    nullvalue = ootype.null(TYPE)
    return hop.inputconst(TYPE, nullvalue)
Exemplo n.º 45
0
 def convert_const(self, value):
     if value is None:
         return ootype.null(self.lowleveltype)
     else:
         return Repr.convert_const(self, value)
Exemplo n.º 46
0
def rtype_null(hop):
    assert hop.args_s[0].is_constant()
    TYPE = hop.args_s[0].const
    nullvalue = ootype.null(TYPE)
    return hop.inputconst(TYPE, nullvalue)
Exemplo n.º 47
0
 def convert_const(self, value):
     if value is None:
         return ootype.null(self.lowleveltype)
     else:
         return Repr.convert_const(self, value)
Exemplo n.º 48
0
 def test_cast_record_mix_object(self):
     T = ootype.Record({'x': ootype.Signed})
     NULL = ootype.null(System.Object._INSTANCE)
     record = cast_record_to_object(ootype.new(T))
     assert record != NULL
     assert NULL != record
Exemplo n.º 49
0
 def null_instance(self):
     return ootype.null(self.lowleveltype)
Exemplo n.º 50
0
def ll_inst_type(obj):
    if obj:
        return obj.meta
    else:
        # type(None) -> NULL  (for now)
        return ootype.null(CLASSTYPE)