예제 #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
예제 #2
0
파일: test_rclass.py 프로젝트: alkorzt/pypy
 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
예제 #3
0
파일: constant.py 프로젝트: chyyuu/pygirl
 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)
예제 #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)
예제 #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)
예제 #6
0
파일: generator.py 프로젝트: njues/Sypy
    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
예제 #7
0
파일: constant.py 프로젝트: chyyuu/pygirl
 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)
예제 #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
예제 #9
0
파일: test_rclass.py 프로젝트: alkorzt/pypy
 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)
예제 #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"
예제 #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
예제 #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"
예제 #13
0
파일: gencl.py 프로젝트: TheDunn/flex-pypy
 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)
예제 #14
0
파일: rtuple.py 프로젝트: Debug-Orz/Sypy
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
예제 #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
예제 #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)
예제 #17
0
파일: constant.py 프로젝트: chyyuu/pygirl
    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)
예제 #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)
예제 #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)
예제 #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)
예제 #21
0
파일: constant.py 프로젝트: enyst/plexnet
    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        
예제 #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
예제 #23
0
 def null_callable(self, T):
     return ootype.null(T)
예제 #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
예제 #25
0
파일: support.py 프로젝트: Debug-Orz/Sypy
 def to_rstr(s):
     if s is None:
         return ootype.null(ootype.String)
     return ootype.oostring(s, -1)
예제 #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)
예제 #27
0
파일: constant.py 프로젝트: enyst/plexnet
 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)
예제 #28
0
파일: rclass.py 프로젝트: antoine1fr/pygirl
def ll_inst_type(obj):
    if obj:
        return obj.meta
    else:
        # type(None) -> NULL  (for now)
        return ootype.null(CLASSTYPE)
예제 #29
0
파일: rgenop.py 프로젝트: antoine1fr/pygirl
    @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))
예제 #30
0
파일: rpbc.py 프로젝트: antoine1fr/pygirl
 def null_instance(self):
     return ootype.null(PBCROOT)
예제 #31
0
 def null_instance(self):
     return ootype.null(PBCROOT)
예제 #32
0
 def null_instance(self):
     return ootype.null(self.lowleveltype)
예제 #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)
예제 #34
0
파일: rlist.py 프로젝트: alkorzt/pypy
 def null_const(self):
     return ootype.null(self.LIST)
예제 #35
0
 def to_rstr(s):
     if s is None:
         return ootype.null(ootype.String)
     return ootype.oostring(s, -1)
예제 #36
0
 def null_const(self):
     return ootype.null(self.LIST)
예제 #37
0
파일: constant.py 프로젝트: enyst/plexnet
 def is_null(self):
     return self.value is ootype.null(self.value._TYPE)
예제 #38
0
파일: constant.py 프로젝트: chyyuu/pygirl
 def is_null(self):
     return self.value is ootype.null(self.value._TYPE)
예제 #39
0
파일: constant.py 프로젝트: enyst/plexnet
 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)
예제 #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
예제 #41
0
 def empty(self):
     return ootype.null(self.lowleveltype)
예제 #42
0
파일: builtin.py 프로젝트: alkorzt/pypy
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
예제 #43
0
파일: constant.py 프로젝트: chyyuu/pygirl
 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)
예제 #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)
예제 #45
0
 def convert_const(self, value):
     if value is None:
         return ootype.null(self.lowleveltype)
     else:
         return Repr.convert_const(self, value)
예제 #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)
예제 #47
0
 def convert_const(self, value):
     if value is None:
         return ootype.null(self.lowleveltype)
     else:
         return Repr.convert_const(self, value)
예제 #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
예제 #49
0
파일: rclass.py 프로젝트: alkorzt/pypy
 def null_instance(self):
     return ootype.null(self.lowleveltype)
예제 #50
0
파일: rclass.py 프로젝트: chyyuu/pygirl
def ll_inst_type(obj):
    if obj:
        return obj.meta
    else:
        # type(None) -> NULL  (for now)
        return ootype.null(CLASSTYPE)