class JvmBuiltInType(jvm.JvmClassType): """ Represents built-in types to JVM. May optionally be associated with an OOTYPE; if it is, then we will support lookup of the OOTYPE methods and will re-map them as needed to the JVM equivalents. """ def __init__(self, db, classty, OOTYPE): jvm.JvmClassType.__init__(self, classty.name) self.db = db self.OOTYPE = OOTYPE self.gen = Generifier(OOTYPE) def __eq__(self, other): return isinstance(other, JvmBuiltInType) and other.name == self.name def __hash__(self): return hash(self.name) def lookup_field(self, fieldnm): """ Given a field name, returns a jvm.Field object """ _, FIELDTY = self.OOTYPE._lookup_field(fieldnm) jfieldty = self.db.lltype_to_cts(FIELDTY) return jvm.Field( self.descriptor.class_name(), fieldnm, jfieldty, False) def lookup_method(self, methodnm): """ Given the method name, returns a jvm.Method object """ # Look for a shortcut method in our table of remappings: try: key = (self.OOTYPE.__class__, methodnm) return built_in_methods[key] except KeyError: pass # Otherwise, determine the Method object automagically # First, map the OOTYPE arguments and results to # the java types they will be at runtime. Note that # we must use the erased types for this. ARGS, RESULT = self.gen.erased_types(methodnm) jargtypes = [self.db.lltype_to_cts(P) for P in ARGS] jrettype = self.db.lltype_to_cts(RESULT) if self.OOTYPE.__class__ in bridged_objects: # Bridged objects are ones where we have written a java class # that has methods with the correct names and types already return jvm.Method.v(self, methodnm, jargtypes, jrettype) else: # By default, we assume it is a static method on the PyPy # object, that takes an instance of this object as the first # argument. The other arguments we just convert to java versions, # except for generics. jargtypes = [self] + jargtypes return jvm.Method.s(jPyPy, methodnm, jargtypes, jrettype)
def __init__(self, db, classty, OOTYPE): jvm.JvmClassType.__init__(self, classty.name) self.db = db self.OOTYPE = OOTYPE self.gen = Generifier(OOTYPE)