本文整理汇总了Python中pypy.rpython.annlowlevel.hlstr函数的典型用法代码示例。如果您正苦于以下问题:Python hlstr函数的具体用法?Python hlstr怎么用?Python hlstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hlstr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ll_float
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)
示例2: ll_splitlines
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
示例3: main
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
示例4: f
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)
示例5: test_simple
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"
示例6: _normalize
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
示例7: entrypoint1
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
示例8: posix_fakeimpl
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
示例9: test_recursive_call_to_portal_from_blackhole
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"
示例10: test_context_manager
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'
示例11: ll_float
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])
示例12: f
def f(fn):
fn = hlstr(fn)
return os.path.exists(fn)
示例13: f
def f(n, enable_opts):
set_param(None, 'enable_opts', hlstr(enable_opts))
return g(n)
示例14: p
def p(pc, code):
code = hlstr(code)
return "%s %d %s" % (code, pc, code[pc])
示例15: f
def f(arg):
s = llstr(hlstr(arg))
return len(s.chars)