def lowlevelspecialize(funcdesc, args_s, key_for_args): args_s, key1, ignored, builder = flatten_star_args(funcdesc, args_s) key = [] new_args_s = [] for i, s_obj in enumerate(args_s): if i in key_for_args: key.append(key_for_args[i]) new_args_s.append(s_obj) elif isinstance(s_obj, annmodel.SomePBC): assert s_obj.is_constant(), "ambiguous low-level helper specialization" key.append(KeyComp(s_obj.const)) new_args_s.append(s_obj) else: new_args_s.append(annmodel.not_const(s_obj)) try: key.append(annmodel.annotation_to_lltype(s_obj)) except ValueError: # passing non-low-level types to a ll_* function is allowed # for module/ll_* key.append(s_obj.__class__) key = (tuple(key),) if key1 is not None: key += (key1,) flowgraph = funcdesc.cachedgraph(key, builder=builder) args_s[:] = new_args_s return flowgraph
def annotation_to_lltype(cls, ann): if isinstance(ann, SomeChar): return ootype.Char elif isinstance(ann, SomeString): return ootype.String else: return annotation_to_lltype(ann)
def call(p, args): args_s, kwds_s = args.unpack() if kwds_s: raise Exception("keyword arguments to call to a low-level fn ptr") info = "argument to ll function pointer call" llargs = [annotation_to_lltype(s_arg, info)._defl() for s_arg in args_s] v = p.ll_ptrtype._example()(*llargs) return ll_to_annotation(v)
def call(m, args): args_s, kwds_s = args.unpack() if kwds_s: raise Exception("keyword arguments to call to a low-level static method") info = "argument to ll static method call" llargs = [annotation_to_lltype(s_arg, info)._defl() for s_arg in args_s] v = m.method._example()(*llargs) return ll_to_annotation(v)
def default_specialize(funcdesc, args_s): key = [] new_args_s = [] for s_obj in args_s: if isinstance(s_obj, annmodel.SomePBC): assert s_obj.is_constant(), "ambiguous low-level helper specialization" key.append(KeyComp(s_obj.const)) new_args_s.append(s_obj) else: new_args_s.append(annmodel.not_const(s_obj)) try: key.append(annmodel.annotation_to_lltype(s_obj)) except ValueError: # passing non-low-level types to a ll_* function is allowed # for module/ll_* key.append(s_obj.__class__) flowgraph = funcdesc.cachedgraph(tuple(key)) args_s[:] = new_args_s return flowgraph
def cast_primitive(T, s_v): assert T.is_constant() return ll_to_annotation(lltype.cast_primitive(T.const, annotation_to_lltype(s_v)._defl()))
def specialize__genconst(pol, funcdesc, args_s, i): # XXX this is specific to the JIT TYPE = annmodel.annotation_to_lltype(args_s[i], 'genconst') args_s[i] = annmodel.lltype_to_annotation(TYPE) alt_name = funcdesc.name + "__%s" % (TYPE._short_name(),) return funcdesc.cachedgraph(TYPE, alt_name=valid_identifier(alt_name))
def simple_call(m, *args_s): llargs = [annotation_to_lltype(arg_s)._example() for arg_s in args_s] smeth = m.method._example() v = smeth(*llargs) return ll_to_annotation(v)
def typeOf(s_val): lltype = annotation_to_lltype(s_val, info="in typeOf(): ") return immutablevalue(lltype)
def specialize__genconst(pol, funcdesc, args_s, i): # XXX this is specific to the JIT TYPE = annmodel.annotation_to_lltype(args_s[i], 'genconst') args_s[i] = annmodel.lltype_to_annotation(TYPE) alt_name = funcdesc.name + "__%s" % (TYPE._short_name(), ) return funcdesc.cachedgraph(TYPE, alt_name=valid_identifier(alt_name))
def setattr(r, s_attr, s_value): assert s_attr.is_constant(), "setattr on ref %r with non-constant field-name" % r.ootype v = annotation_to_lltype(s_value) example = r.ootype._example() if example is not None: setattr(r.ootype._example(), s_attr.const, v._example())
def annotation_to_cts(self, _tp): s_tp = annotation(_tp) TP = annotation_to_lltype(s_tp) return self.lltype_to_cts(TP)
def setattr(p, s_attr, s_value): # just doing checking assert s_attr.is_constant(), "setattr on ptr %r with non-constant field-name" % p.ll_ptrtype example = p.ll_ptrtype._example() if getattr(example, s_attr.const) is not None: # ignore Void s_value v_lltype = annotation_to_lltype(s_value) setattr(example, s_attr.const, v_lltype._defl())
def annotation_to_lltype(cls, ann): from pypy.annotation import model as annmodel return annmodel.annotation_to_lltype(ann)
def cast_primitive(T, s_v): assert T.is_constant() return ll_to_annotation( lltype.cast_primitive(T.const, annotation_to_lltype(s_v)._defl()))