本文整理汇总了Python中pypy.rlib.jit.hint函数的典型用法代码示例。如果您正苦于以下问题:Python hint函数的具体用法?Python hint怎么用?Python hint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_enter_jit
def on_enter_jit(self, invariants, reds, bytecode, pos):
# Now some strange code that makes a copy of the 'args' list in
# a complicated way... this is a workaround forcing the whole 'args'
# list to be virtual. It is a way to tell the JIT compiler that it
# doesn't have to worry about the 'args' list being unpredictably
# modified.
oldloops = invariants
oldargs = reds.args
argcount = promote(len(oldargs))
args = []
n = 0
while n < argcount:
hint(n, concrete=True)
args.append(oldargs[n])
n += 1
reds.args = args
# turn the green 'loops' from 'invariants' into a virtual list
oldloops = hint(oldloops, deepfreeze=True)
argcount = len(oldloops)
loops = []
n = 0
while n < argcount:
hint(n, concrete=True)
loops.append(oldloops[n])
n += 1
reds.loops = loops
示例2: f
def f(x):
while x > 0:
myjitdriver.can_enter_jit(x=x)
myjitdriver.jit_merge_point(x=x)
a = A()
hint(a, promote=True)
x -= 1
示例3: copy_and_basic_unify
def copy_and_basic_unify(self, other, heap, memo):
hint(self, concrete=True)
if isinstance(other, Atom) and (self is other or
other.name == self.name):
return self
else:
raise UnificationFailed
示例4: call_valuestack
def call_valuestack(self, w_func, nargs, frame):
if not self.config.objspace.disable_call_speedhacks:
# XXX start of hack for performance
from pypy.interpreter.function import Function, Method
hint(w_func.__class__, promote=True)
if isinstance(w_func, Method):
w_inst = w_func.w_instance
if w_inst is not None:
func = w_func.w_function
if isinstance(func, Function):
return func.funccall_obj_valuestack(w_inst, nargs, frame)
elif nargs > 0 and self.is_true(
self.abstract_isinstance(frame.peekvalue(nargs-1), # :-(
w_func.w_class)):
w_func = w_func.w_function
if isinstance(w_func, Function):
return w_func.funccall_valuestack(nargs, frame)
# XXX end of hack for performance
args = frame.make_arguments(nargs)
try:
return self.call_args(w_func, args)
finally:
if isinstance(args, ArgumentsFromValuestack):
args.frame = None
示例5: dispatch_jit
def dispatch_jit(self, pycode, next_instr, ec):
hint(None, global_merge_point=True)
pycode = hint(pycode, deepfreeze=True)
entry_fastlocals_w = self.jit_enter_frame(pycode, next_instr)
# For the sequel, force 'next_instr' to be unsigned for performance
next_instr = r_uint(next_instr)
co_code = pycode.co_code
try:
try:
while True:
hint(None, global_merge_point=True)
next_instr = self.handle_bytecode(co_code, next_instr, ec)
except Return:
w_result = self.popvalue()
self.blockstack = None
self.valuestack_w = None
return w_result
except Yield:
w_result = self.popvalue()
return w_result
finally:
self.jit_leave_frame(pycode, entry_fastlocals_w)
示例6: f
def f(v):
hint(None, global_merge_point=True)
s = S(1, 10)
v.s = s
g(v)
s2 = v.s
return s.x * 2 + s.y + s2.x * 2 + s2.y
示例7: f
def f(x):
hint(None, global_merge_point=True)
lst = g(x)
try:
return lst[0]
except IndexError:
return -42
示例8: ll_function
def ll_function(a, i):
a = hint(a, deepfreeze=True)
res = a[i]
res = hint(res, concrete=True)
res = hint(res, variable=True)
return res
示例9: ll_function
def ll_function(n):
hint(None, global_merge_point=True)
s = lltype.malloc(S)
c = ll_two(n, s)
k = hint(s.x, promote=True)
k += c
return hint(k, variable=True)
示例10: pushrevvalues
def pushrevvalues(self, n, values_w): # n should be len(values_w)
while True:
n -= 1
if n < 0:
break
hint(n, concrete=True)
self.pushvalue(values_w[n])
示例11: ll_three
def ll_three(s, k):
k = hint(k, promote=True)
if s.x > 6:
k *= hint(s.y, promote=True)
return k
else:
return hint(1, concrete=True)
示例12: interpret
def interpret(bytecode, args):
"""The interpreter's entry point and portal function.
"""
loops = []
stack = empty_stack()
pos = 0
while True:
tinyjitdriver.jit_merge_point(args=args, loops=loops, stack=stack, bytecode=bytecode, pos=pos)
bytecode = hint(bytecode, deepfreeze=True)
if pos >= len(bytecode):
break
opcode = bytecode[pos]
hint(opcode, concrete=True) # same as in tiny1.py
pos += 1
if opcode == "ADD":
stack = op2(stack, func_add_int, func_add_float)
elif opcode == "SUB":
stack = op2(stack, func_sub_int, func_sub_float)
elif opcode == "MUL":
stack = op2(stack, func_mul_int, func_mul_float)
elif opcode[0] == "#":
n = myint(opcode, start=1)
stack = Stack(args[n - 1], stack)
elif opcode.startswith("->#"):
n = myint(opcode, start=3)
if n > len(args):
raise IndexError
stack, args[n - 1] = stack.pop()
elif opcode == "{":
loops.append(pos)
elif opcode == "}":
stack, flag = stack.pop()
if flag.as_int() == 0:
loops.pop()
else:
pos = loops[-1]
# A common problem when interpreting loops or jumps: the 'pos'
# above is read out of a list, so the hint-annotator thinks
# it must be red (not a compile-time constant). But the
# hint(opcode, concrete=True) in the next iteration of the
# loop requires all variables the 'opcode' depends on to be
# green, including this 'pos'. We promote 'pos' to a green
# here, as early as possible. Note that in practice the 'pos'
# read out of the 'loops' list will be a compile-time constant
# because it was pushed as a compile-time constant by the '{'
# case above into 'loops', which is a virtual list, so the
# promotion below is just a way to make the colors match.
pos = promote(pos)
tinyjitdriver.can_enter_jit(args=args, loops=loops, stack=stack, bytecode=bytecode, pos=pos)
else:
try:
try:
v = IntBox(int(opcode))
except ValueError:
v = FloatBox(myfloat(opcode))
stack = Stack(v, stack)
except ValueError:
pass # ignore rest
return stack
示例13: get
def get(self, name):
self = hint(self, promote=True)
sc_version = hint(self.semiconstant_version, promote=True)
if self._is_semiconstant(name, sc_version):
return self._get_semiconstant(name, sc_version)
else:
return self._get_intern(name)
示例14: set_semiconstant
def set_semiconstant(self, name, val, local_only=False):
self = hint(self, promote=True)
sc_version = hint(self.semiconstant_version, promote=True)
self._set_intern(name, val, local_only)
if not self._is_semiconstant(name, sc_version):
self.semiconstants.append(name)
self.semiconstant_version = VersionTag()
示例15: ll_function
def ll_function(x):
mylist = hint(lst, deepfreeze=True)
try:
z = mylist[x]
except IndexError:
return -42
hint(z, concrete=True)
return z