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
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)
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)
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
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)
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
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"
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
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)
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
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)
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)
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)
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)
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)
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
def null_callable(self, T): return ootype.null(T)
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
def to_rstr(s): if s is None: return ootype.null(ootype.String) return ootype.oostring(s, -1)
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)
def ll_inst_type(obj): if obj: return obj.meta else: # type(None) -> NULL (for now) return ootype.null(CLASSTYPE)
@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))
def null_instance(self): return ootype.null(PBCROOT)
def null_instance(self): return ootype.null(self.lowleveltype)
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)
def null_const(self): return ootype.null(self.LIST)
def is_null(self): return self.value is ootype.null(self.value._TYPE)
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)
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
def empty(self): return ootype.null(self.lowleveltype)
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)
def convert_const(self, value): if value is None: return ootype.null(self.lowleveltype) else: return Repr.convert_const(self, value)