def getcfield(self, attr): if self.fields_dict is not None: self = jit.promote(self) attr = jit.promote_string(attr) try: return self._getcfield_const(attr) except KeyError: pass return W_CType.getcfield(self, attr)
def _promote(space, w_obj): """ Promote the first argument of the function and return it. Promote is by value for ints, floats, strs, unicodes (but not subclasses thereof) and by reference otherwise. (Unicodes not supported right now.) This function is experimental!""" from rpython.rlib import jit if space.is_w(space.type(w_obj), space.w_int): jit.promote(space.int_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_float): jit.promote(space.float_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_str): jit.promote_string(space.str_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_unicode): raise oefmt(space.w_TypeError, "promoting unicode unsupported") else: jit.promote(w_obj) return w_obj
def _promote(space, w_obj): """ Promote the first argument of the function and return it. Promote is by value for ints, floats, strs, unicodes (but not subclasses thereof) and by reference otherwise. (Unicodes not supported right now.) This function is experimental!""" from rpython.rlib import jit if space.is_w(space.type(w_obj), space.w_int): jit.promote(space.int_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_float): jit.promote(space.float_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_bytes): jit.promote_string(space.bytes_w(w_obj)) elif space.is_w(space.type(w_obj), space.w_unicode): raise oefmt(space.w_TypeError, "promoting unicode unsupported") else: jit.promote(w_obj) return w_obj
def lookup_where_with_method_cache(w_self, name): space = w_self.space promote(w_self) assert space.config.objspace.std.withmethodcache version_tag = promote(w_self.version_tag()) if version_tag is None: tup = w_self._lookup_where(name) return tup name = promote_string(name) w_class, w_value = w_self._pure_lookup_where_with_method_cache(name, version_tag) return w_class, unwrap_cell(space, w_value)
def getcfield(self, attr): ready = self._fields_dict is not None if not ready and self.size >= 0: self.force_lazy_struct() ready = True if ready: self = jit.promote(self) attr = jit.promote_string(attr) try: return self._getcfield_const(attr) except KeyError: pass return W_CType.getcfield(self, attr)
def getcfield(self, attr): # Returns a W_CField. Error cases: returns None if we are an # opaque struct; or raises KeyError if the particular field # 'attr' does not exist. The point of not directly building the # error here is to get the exact ctype in the error message: it # might be of the kind 'struct foo' or 'struct foo *'. if self._fields_dict is None: if self.size < 0: return None self.force_lazy_struct() self = jit.promote(self) attr = jit.promote_string(attr) return self._getcfield_const(attr) # <= KeyError here
def lookup_where_with_method_cache(w_self, name): space = w_self.space promote(w_self) assert space.config.objspace.std.withmethodcache version_tag = promote(w_self.version_tag()) if version_tag is None: tup = w_self._lookup_where(name) return tup name = promote_string(name) tup_w = w_self._pure_lookup_where_with_method_cache(name, version_tag) w_class, w_value = tup_w if space.config.objspace.std.withtypeversion and isinstance(w_value, MutableCell): return w_class, w_value.unwrap_cell(space) return tup_w # don't make a new tuple, reuse the old one
def lookup_where_with_method_cache(w_self, name): space = w_self.space promote(w_self) assert space.config.objspace.std.withmethodcache version_tag = promote(w_self.version_tag()) if version_tag is None: tup = w_self._lookup_where(name) return tup name = promote_string(name) tup_w = w_self._pure_lookup_where_with_method_cache(name, version_tag) w_class, w_value = tup_w if (space.config.objspace.std.withtypeversion and isinstance(w_value, MutableCell)): return w_class, w_value.unwrap_cell(space) return tup_w # don't make a new tuple, reuse the old one
def method_send(self, space, method, args_w, block): return space.send(self, jit.promote_string(method), args_w, block)
def class_name(self, space): return jit.promote_string(self.classname(space))
def descr_unpack_from(self, space, w_buffer, offset=0): return unpack_from(space, jit.promote_string(self.format), w_buffer, offset)
def descr_unpack(self, space, w_str): return unpack(space, jit.promote_string(self.format), w_str)
def descr_pack_into(self, space, w_buffer, offset, args_w): return pack_into(space, jit.promote_string(self.format), w_buffer, offset, args_w)
def decode_args(self, mand="", opt="", vargs=False, self_of=None): cf = self.cur_cf nargs = cf.nargs # Number of arguments passed mand = jit.promote_string(mand) opt = jit.promote_string(opt) self_of = jit.promote(self_of) if nargs < len(mand): if vargs: self.raise_helper("Parameters_Exception", [Builtins.Con_String(self, \ "Too few parameters (%d passed, but at least %d needed)." % (nargs, len(mand)))]) else: self.raise_helper("Parameters_Exception", [Builtins.Con_String(self, \ "Too few parameters (%d passed, but %d needed)." % (nargs, len(mand)))]) elif nargs > (len(mand) + len(opt)) and not vargs: raise Exception("XXX") if nargs == 0: if vargs: return (None, []) else: return (None, None) nrmp = [None] * (len(mand) + len(opt)) # Normal params i = 0 while i < (len(mand) + len(opt)): if i >= nargs: for j in range(i, nargs): nrmp[j] = None break if i < len(mand): t = mand[i] else: t = opt[i - len(mand)] o = cf.stack_get(cf.stackpe - nargs + i) if t == "!": assert self_of is not None if not isinstance(o, self_of): raise Exception("XXX") nrmp[i] = o i += 1 continue if t >= "a": if o is self.get_builtin(Builtins.BUILTIN_NULL_OBJ): nrmp[i] = None i += 1 continue t = chr(ord("A") + ord(t) - ord("a")) if t == "O": nrmp[i] = o else: if t == "C": Builtins.type_check_class(self, o) elif t == "D": Builtins.type_check_dict(self, o) elif t == "E": Builtins.type_check_exception(self, o) elif t == "F": Builtins.type_check_func(self, o) elif t == "I": Builtins.type_check_int(self, o) elif t == "L": Builtins.type_check_list(self, o) elif t == "M": Builtins.type_check_module(self, o) elif t == "N": Builtins.type_check_number(self, o) elif t == "S": Builtins.type_check_string(self, o) elif t == "W": Builtins.type_check_set(self, o) else: print t raise Exception("XXX") nrmp[i] = o i += 1 if vargs: vap = [None] * (nargs - i) for j in range(i, nargs): vap[j - i] = cf.stack_get(cf.stackpe - nargs + j) else: vap = None cf.stack_del_from(cf.stackpe - nargs) return (nrmp, vap)
def get(self): if isinstance(self.value, str): return jit.promote_string(self.value) else: return jit.promote(self.value)
def descr_pack(self, space, args_w): return pack(space, jit.promote_string(self.format), args_w)
def f(n): while n < 21: driver.jit_merge_point(n=n) promote_string(str(n % 3)) n += 1 return 0