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 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 typeOf(s_val): lltype = annotation_to_lltype(s_val, info="in typeOf(): ") return immutablevalue(lltype)
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_cts(self, _tp): s_tp = annotation(_tp) TP = annotation_to_lltype(s_tp) return self.lltype_to_cts(TP)