def ll_float(ll_str): from pypy.rpython.annlowlevel import hlstr from pypy.rlib.rarithmetic import break_up_float, parts_to_float s = hlstr(ll_str) assert s is not None n = len(s) beg = 0 while beg < n: if s[beg] == ' ': beg += 1 else: break if beg == n: raise ValueError end = n-1 while end >= 0: if s[end] == ' ': end -= 1 else: break assert end >= 0 sign, before_point, after_point, exponent = break_up_float(s[beg:end+1]) if not before_point and not after_point: raise ValueError return parts_to_float(sign, before_point, after_point, exponent)
def get_location_str(greenkey): greenargs = unwrap_greenkey(greenkey) fn = support.maybe_on_top_of_llinterp(rtyper, get_location_ptr) llres = fn(*greenargs) if not we_are_translated() and isinstance(llres, str): return llres return hlstr(llres)
def ll_splitlines(cls, LIST, ll_str, keep_newlines): from pypy.rpython.annlowlevel import hlstr s = hlstr(ll_str) STR = typeOf(ll_str) strlen = len(s) i = 0 j = 0 # The annotator makes sure this list is resizable. res = LIST.ll_newlist(0) while j < strlen: while i < strlen and s[i] != '\n' and s[i] != '\r': i += 1 eol = i if i < strlen: if s[i] == '\r' and i + 1 < strlen and s[i + 1] == '\n': i += 2 else: i += 1 if keep_newlines: eol = i list_length = res.ll_length() res._ll_resize_ge(list_length + 1) item = cls.ll_stringslice_startstop(ll_str, j, eol) res.ll_setitem_fast(list_length, item) j = i if j < strlen: list_length = res.ll_length() res._ll_resize_ge(list_length + 1) item = cls.ll_stringslice_startstop(ll_str, j, strlen) res.ll_setitem_fast(list_length, item) return res
def main(): loop(1) op = jit_hooks.resop_new(rop.INT_ADD, [jit_hooks.boxint_new(3), jit_hooks.boxint_new(4)], jit_hooks.boxint_new(1)) assert hlstr(jit_hooks.resop_getopname(op)) == 'int_add' assert jit_hooks.resop_getopnum(op) == rop.INT_ADD box = jit_hooks.resop_getarg(op, 0) assert jit_hooks.box_getint(box) == 3 box2 = jit_hooks.box_clone(box) assert box2 != box assert jit_hooks.box_getint(box2) == 3 assert not jit_hooks.box_isconst(box2) box3 = jit_hooks.box_constbox(box) assert jit_hooks.box_getint(box) == 3 assert jit_hooks.box_isconst(box3) box4 = jit_hooks.box_nonconstbox(box) assert not jit_hooks.box_isconst(box4) box5 = jit_hooks.boxint_new(18) jit_hooks.resop_setarg(op, 0, box5) assert jit_hooks.resop_getarg(op, 0) == box5 box6 = jit_hooks.resop_getresult(op) assert jit_hooks.box_getint(box6) == 1 jit_hooks.resop_setresult(op, box5) assert jit_hooks.resop_getresult(op) == box5
def f(x, y): y = const(hlstr(y)) if x > 0: l = [const("a"), const("b")] else: l = [const("a")] l += y return const("").join(l)
def test_simple(self): sb = StringBuilderRepr.ll_new(3) StringBuilderRepr.ll_append_char(sb, 'x') StringBuilderRepr.ll_append(sb, llstr("abc")) StringBuilderRepr.ll_append_slice(sb, llstr("foobar"), 2, 5) StringBuilderRepr.ll_append_multiple_char(sb, 'y', 3) s = StringBuilderRepr.ll_build(sb) assert hlstr(s) == "xabcobayyy"
def f(x, y): y = const(hlstr(y)) if x > 0: l = [const('a'), const('b')] else: l = [const('a')] l += y return const('').join(l)
def _normalize(x): if not isinstance(x, str): TYPE = lltype.typeOf(x) if (isinstance(TYPE, lltype.Ptr) and TYPE.TO._name == 'rpy_string' or getattr(TYPE, '_name', '') == 'String'): # ootype from pypy.rpython.annlowlevel import hlstr return hlstr(x) return x
def _get_str(self): # for debugging only from pypy.rpython.annlowlevel import hlstr from pypy.rpython.lltypesystem import rstr try: return hlstr(lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR), self.value)) except lltype.UninitializedMemoryAccess: return '<uninitialized string>'
def entrypoint1(r, string, repeat): r = array2list(r) string = hlstr(string) match = None for i in range(repeat): match = rsre_core.match(r, string) if match is None: return -1 else: return match.match_end
def f(code): interp = numpy_compile(hlstr(code)) interp.run(space) res = interp.results[-1] w_res = res.eval(0).wrap(interp.space) if isinstance(w_res, BoolObject): return float(w_res.boolval) elif isinstance(w_res, FloatObject): return w_res.floatval elif isinstance(w_res, IntObject): return w_res.intval else: return -42.
def posix_fakeimpl(arg): if s_arg == str: arg = hlstr(arg) st = getattr(os, name)(arg) fields = [TYPE for fieldname, TYPE in STAT_FIELDS] TP = TUPLE_TYPE(fields) ll_tup = lltype.malloc(TP.TO) for i, (fieldname, TYPE) in enumerate(STAT_FIELDS): val = getattr(st, fieldname) if isinstance(TYPE, lltype.Number): rffi.setintfield(ll_tup, 'item%d' % i, int(val)) elif TYPE is lltype.Float: setattr(ll_tup, 'item%d' % i, float(val)) else: setattr(ll_tup, 'item%d' % i, val) return ll_tup
def test_recursive_call_to_portal_from_blackhole(self): from pypy.rpython.annlowlevel import hlstr myjitdriver = JitDriver(greens = ['k'], reds = ['n']) def f(n, k): while n >= 0: myjitdriver.can_enter_jit(n=n, k=k) myjitdriver.jit_merge_point(n=n, k=k) if n == 3 and k == 0: return f(10, 1) n -= 1 if k == 1: return "string" return "xyz" res = self.meta_interp(f, [20, 0]) assert hlstr(res) == "string"
def test_context_manager(): state = [] class C: def __enter__(self): state.append('acquire') return self def __exit__(self, *args): if args[1] is not None: state.append('raised') state.append('release') def f(): try: with C() as c: state.append('use') raise ValueError except ValueError: pass return ', '.join(state) res = interpret(f, []) assert hlstr(res) == 'acquire, use, raised, release'
def ll_float(ll_str): from pypy.rpython.annlowlevel import hlstr from pypy.rlib.rfloat import rstring_to_float s = hlstr(ll_str) assert s is not None n = len(s) beg = 0 while beg < n: if s[beg] == ' ': beg += 1 else: break if beg == n: raise ValueError end = n-1 while end >= 0: if s[end] == ' ': end -= 1 else: break assert end >= 0 return rstring_to_float(s[beg:end+1])
def f(z): z = hlstr(z) x = newlist(sizehint=13) x += z return ''.join(x)
def can_inline(code, i): code = hlstr(code) return not JUMP_BACK in code
def f(a, b, c, d): a, b, c, d = hlstr(a), hlstr(b), hlstr(c), hlstr(d) return rfloat.parts_to_float(a, b, c, d)
def p(pc, code): code = hlstr(code) return "%s %d %s" % (code, pc, code[pc])
def main(bc, size): if not isinstance(bc, str): bc = hlstr(bc) # for tests a = numpy_compile(bc, size) a = a.compute()
def f(a, b, c, d): a, b, c, d = hlstr(a), hlstr(b), hlstr(c), hlstr(d) return rarithmetic.parts_to_float(a, b, c, d)
def test_hlstr(self): s = ootype.make_string("abc") assert hlstr(s) == "abc"
def _get_str(self): # for debugging only from pypy.rpython.annlowlevel import hlstr from pypy.rpython.lltypesystem import rstr return hlstr(lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR), self.value))
def f(): ptr = rgc.resizable_buffer_of_shape(STR, 2) ptr.chars[0] = 'a' ptr = rgc.resize_buffer(ptr, 1, 200) ptr.chars[1] = 'b' return hlstr(rgc.finish_building_buffer(ptr, 2)) == "ab"
def descr_name(self, space): return space.wrap(hlstr(jit_hooks.resop_getopname(self.op)))
def f(arg): s = oostr(hlstr(arg)) return s.ll_strlen()
def f(fn): fn = hlstr(fn) return os.path.isdir(fn)
def f(fn): fn = hlstr(fn) return os.path.exists(fn)
def p(code, pc): code = hlstr(code) return "%s %d %s" % (code, pc, code[pc])
def f(arg): s = llstr(hlstr(arg)) return len(s.chars)
def c(code, pc): return "L" not in hlstr(code)
def c(code, pc): return "l" not in hlstr(code)
def _get_str(self): # for debugging only from pypy.rpython.annlowlevel import hlstr return hlstr(ootype.cast_from_object(ootype.String, self.value))
def closure(i): if is_string: i = hlstr(i) getattr(state, fullfuncname)(i)
def entry_point(): from pypy.module.marshal.interp_marshal import loads code = loads(space, space.wrap(hlstr(read_code_ptr()))) assert isinstance(code, PyCode) code.exec_code(space, w_dict, w_dict)
def test_hlstr(self): s = mallocstr(3) s.chars[0] = "a" s.chars[1] = "b" s.chars[2] = "c" assert hlstr(s) == "abc"
def closure(i): if is_string: i = hlstr(i) for jd in self.jitdrivers_sd: getattr(jd.warmstate, fullfuncname)(i)
def p(pc, code): code = hlstr(code) return "'%s' at %d: %s" % (code, pc, code[pc])
def f(): ptr = rgc.resizable_buffer_of_shape(STR, 1) ptr.chars[0] = 'a' ptr = rgc.resize_buffer(ptr, 1, 2) ptr.chars[1] = 'b' return len(hlstr(rgc.finish_building_buffer(ptr, 2)))
def f(n, enable_opts): set_param(None, 'enable_opts', hlstr(enable_opts)) return g(n)
def f(s): return const("*") + const(hlstr(s)) + const("*") == const("*abba*")
def f(s): return const("*")+const(hlstr(s))+const("*") == const("*abba*")
def f(n, enable_opts): myjitdriver.set_param('enable_opts', hlstr(enable_opts)) return g(n)