本文整理汇总了Python中pypy.annotation.policy.AnnotatorPolicy类的典型用法代码示例。如果您正苦于以下问题:Python AnnotatorPolicy类的具体用法?Python AnnotatorPolicy怎么用?Python AnnotatorPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnnotatorPolicy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_callback
def test_callback(self):
"""
Verify annotation when a callback function is in the arguments list.
"""
def d(y):
return eval("y()")
class DTestFuncEntry(ExtFuncEntry):
_about_ = d
name = "d"
signature_args = [annmodel.SomeGenericCallable(args=[], result=annmodel.SomeFloat())]
signature_result = annmodel.SomeFloat()
def callback():
return 2.5
def f():
return d(callback)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeFloat)
assert a.translator._graphof(callback)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:26,代码来源:test_extfunc.py
示例2: get_interpreter
def get_interpreter(func, values, view='auto', viewbefore='auto', policy=None,
someobjects=False, type_system="lltype", backendopt=False, config=None):
key = (func,) + tuple([typeOf(x) for x in values])+ (someobjects,
backendopt)
try:
(t, interp, graph) = _tcache[key]
except KeyError:
def annotation(x):
T = typeOf(x)
if T == Ptr(PyObject) and someobjects:
return object
elif T == Ptr(rstr.STR):
return str
else:
return lltype_to_annotation(T)
if policy is None and not someobjects:
from pypy.annotation.policy import AnnotatorPolicy
policy = AnnotatorPolicy()
policy.allow_someobjects = False
t, typer, graph = gengraph(func, [annotation(x) for x in values],
viewbefore, policy, type_system=type_system,
backendopt=backendopt, config=config)
interp = LLInterpreter(typer)
_tcache[key] = (t, interp, graph)
# keep the cache small
_lastinterpreted.append(key)
if len(_lastinterpreted) >= 4:
del _tcache[_lastinterpreted.pop(0)]
if view == 'auto':
view = conftest.option.view
if view:
t.view()
return interp, graph
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:35,代码来源:test_llinterp.py
示例3: __init__
def __init__(self, function, annotations, stackless=False, view=False, html=None, is_interactive=False, root = None, run_browser = True, policy = None):
if not use_browsertest and not _CLI_is_on_path():
py.test.skip('Javascript CLI (js) not found')
self.html = html
self.is_interactive = is_interactive
t = TranslationContext()
if policy is None:
from pypy.annotation.policy import AnnotatorPolicy
policy = AnnotatorPolicy()
policy.allow_someobjects = False
ann = t.buildannotator(policy=policy)
ann.build_types(function, annotations)
if view or option.view:
t.view()
t.buildrtyper(type_system="ootype").specialize()
if view or option.view:
t.view()
#self.js = JS(t, [function, callback_function], stackless)
self.js = JS(t, function, stackless)
self.js.write_source()
if root is None and use_tg:
from pypy.translator.js.demo.jsdemo.controllers import Root
self.root = Root
else:
self.root = root
self.run_browser = run_browser
self.function_calls = []
开发者ID:antoine1fr,项目名称:pygirl,代码行数:31,代码来源:runtest.py
示例4: test_register_external_tuple_args
def test_register_external_tuple_args(self):
"""
Verify the annotation of a registered external function which takes a
tuple argument.
"""
def function_with_tuple_arg():
"""
Dummy function which is declared via register_external to take a
tuple as an argument so that register_external's behavior for
tuple-taking functions can be verified.
"""
register_external(function_with_tuple_arg, [(int,)], int)
def f():
return function_with_tuple_arg((1,))
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
# Not a very good assertion, but at least it means _something_ happened.
assert isinstance(s, annmodel.SomeInteger)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:25,代码来源:test_extfunc.py
示例5: test_register_external_return_goes_back
def test_register_external_return_goes_back(self):
"""
Check whether it works to pass the same list from one external
fun to another
[bookkeeper and list joining issues]
"""
def function_with_list():
pass
register_external(function_with_list, [[int]], int)
def function_returning_list():
pass
register_external(function_returning_list, [], [int])
def f():
return function_with_list(function_returning_list())
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInteger)
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:25,代码来源:test_extfunc.py
示例6: test_basic
def test_basic(self):
"""
A ExtFuncEntry provides an annotation for a function, no need to flow
its graph.
"""
def b(x):
"NOT_RPYTHON"
return eval("x+40")
class BTestFuncEntry(ExtFuncEntry):
_about_ = b
name = "b"
signature_args = [annmodel.SomeInteger()]
signature_result = annmodel.SomeInteger()
def f():
return b(2)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInteger)
res = interpret(f, [])
assert res == 42
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:27,代码来源:test_extfunc.py
示例7: test_annotation_b
def test_annotation_b():
def f():
return b(1)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInteger)
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_extfunc.py
示例8: test_register_external_signature
def test_register_external_signature():
def f():
return dd(3)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInteger)
开发者ID:alkorzt,项目名称:pypy,代码行数:9,代码来源:test_extfunc.py
示例9: test_register_external_specialcase
def test_register_external_specialcase():
def f():
x = function_withspecialcase
return x(33) + x("aaa") + x([]) + "\n"
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeString)
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:test_extfunc.py
示例10: get_interpreter
def get_interpreter(
func,
values,
view="auto",
viewbefore="auto",
policy=None,
someobjects=False,
type_system="lltype",
backendopt=False,
config=None,
**extraconfigopts
):
extra_key = [(key, value) for key, value in extraconfigopts.iteritems()]
extra_key.sort()
extra_key = tuple(extra_key)
key = (func,) + tuple([typeOf(x) for x in values]) + (someobjects, backendopt, extra_key)
try:
(t, interp, graph) = _tcache[key]
except KeyError:
def annotation(x):
T = typeOf(x)
if T == Ptr(PyObject) and someobjects:
return object
else:
return lltype_to_annotation(T)
if policy is None and not someobjects:
from pypy.annotation.policy import AnnotatorPolicy
policy = AnnotatorPolicy()
policy.allow_someobjects = False
t, typer, graph = gengraph(
func,
[annotation(x) for x in values],
viewbefore,
policy,
type_system=type_system,
backendopt=backendopt,
config=config,
**extraconfigopts
)
interp = LLInterpreter(typer)
_tcache[key] = (t, interp, graph)
# keep the cache small
_lastinterpreted.append(key)
if len(_lastinterpreted) >= 4:
del _tcache[_lastinterpreted.pop(0)]
if view == "auto":
view = getattr(conftest.option, "view", False)
if view:
t.view()
return interp, graph
开发者ID:are-prabhu,项目名称:pypy,代码行数:54,代码来源:test_llinterp.py
示例11: test_callback
def test_callback():
def callback():
return 2.5
def f():
return d(callback)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeFloat)
assert a.translator._graphof(callback)
开发者ID:alkorzt,项目名称:pypy,代码行数:13,代码来源:test_extfunc.py
示例12: test_register_external_tuple_args
def test_register_external_tuple_args():
"""
Verify the annotation of a registered external function which takes a tuple
argument.
"""
def f():
return function_with_tuple_arg((1,))
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
# Not a very good assertion, but at least it means _something_ happened.
assert isinstance(s, annmodel.SomeInteger)
开发者ID:alkorzt,项目名称:pypy,代码行数:15,代码来源:test_extfunc.py
示例13: default_specialize
def default_specialize(pol, funcdesc, args_s):
name = funcdesc.name
if name.startswith('ll_') or name.startswith('_ll_'): # xxx can we do better?
return super(MixLevelAnnotatorPolicy, pol).default_specialize(
funcdesc, args_s)
else:
return AnnotatorPolicy.default_specialize(funcdesc, args_s)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:annlowlevel.py
示例14: test_register_external_signature
def test_register_external_signature(self):
"""
Test the standard interface for external functions.
"""
def dd():
pass
register_external(dd, [int], int)
def f():
return dd(3)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeInteger)
开发者ID:ieure,项目名称:pypy,代码行数:16,代码来源:test_extfunc.py
示例15: test_register_external_specialcase
def test_register_external_specialcase(self):
"""
When args=None, the external function accepts any arguments unmodified.
"""
def function_withspecialcase(arg):
return repr(arg)
register_external(function_withspecialcase, args=None, result=str)
def f():
x = function_withspecialcase
return x(33) + x("aaa") + x([]) + "\n"
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
s = a.build_types(f, [])
assert isinstance(s, annmodel.SomeString)
开发者ID:ieure,项目名称:pypy,代码行数:17,代码来源:test_extfunc.py
示例16: test_prebuilt_lock
def test_prebuilt_lock():
import thread
import pypy.module.thread.rpython.exttable # for declare()/declaretype()
lock0 = thread.allocate_lock()
lock1 = thread.allocate_lock()
lock1.acquire()
def fn(i):
lock = [lock0, lock1][i]
ok = lock.acquire(False)
if ok: lock.release()
return ok
policy = AnnotatorPolicy()
policy.allow_someobjects = False
res = interpret(fn, [0], policy=policy)
assert res is True
res = interpret(fn, [1], policy=policy)
assert res is False
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:17,代码来源:test_rexternalobj.py
示例17: test_lock_or_None
def test_lock_or_None():
import thread
import pypy.module.thread.rpython.exttable # for declare()/declaretype()
def makelock(i):
if i > 0:
return thread.allocate_lock()
else:
return None
def fn(i):
lock = makelock(i)
return lock is not None and lock.acquire(False)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
res = interpret(fn, [0], policy=policy)
assert res is False
res = interpret(fn, [1], policy=policy)
assert res is True
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:17,代码来源:test_rexternalobj.py
示例18: rcompile
def rcompile(rgenop, entrypoint, argtypes, random_seed=0, type_system='lltype'):
from pypy.translator.translator import TranslationContext
from pypy.annotation.policy import AnnotatorPolicy
from pypy import conftest
t = TranslationContext()
policy = AnnotatorPolicy()
policy.allow_someobjects = False
t.buildannotator(policy=policy).build_types(entrypoint, argtypes)
t.buildrtyper(type_system = type_system).specialize()
# note that backend optimizations will constant-fold simple operations,
# which is required by some backends that don't accept calls like
# genop1("add", constant, constant).
from pypy.translator.backendopt.all import backend_optimizations
backend_optimizations(t)
if conftest.option.view:
t.view()
entrygraph = t._graphof(entrypoint)
return compile_graph(rgenop, entrygraph, random_seed=random_seed)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:21,代码来源:graph2rgenop.py
示例19: test_list_of_str0
def test_list_of_str0(self):
str0 = annmodel.SomeString(no_nul=True)
def os_execve(l):
pass
register_external(os_execve, [[str0]], None)
def f(l):
return os_execve(l)
policy = AnnotatorPolicy()
policy.allow_someobjects = False
a = RPythonAnnotator(policy=policy)
a.build_types(f, [[str]]) # Does not raise
assert a.translator.config.translation.check_str_without_nul == False
# Now enable the str0 check, and try again with a similar function
a.translator.config.translation.check_str_without_nul = True
def g(l):
return os_execve(l)
raises(Exception, a.build_types, g, [[str]])
a.build_types(g, [[str0]]) # Does not raise
开发者ID:junion,项目名称:butlerbot-unstable,代码行数:24,代码来源:test_extfunc.py
示例20: __init__
def __init__(self, translator=None, policy=None, bookkeeper=None):
import pypy.rpython.ootypesystem.ooregistry # has side effects
import pypy.rpython.extfuncregistry # has side effects
import pypy.rlib.nonconst # has side effects
if translator is None:
# interface for tests
from pypy.translator.translator import TranslationContext
translator = TranslationContext()
translator.annotator = self
self.translator = translator
self.pendingblocks = {} # map {block: graph-containing-it}
self.bindings = {} # map Variables to SomeValues
self.annotated = {} # set of blocks already seen
self.added_blocks = None # see processblock() below
self.links_followed = {} # set of links that have ever been followed
self.notify = {} # {block: {positions-to-reflow-from-when-done}}
self.fixed_graphs = {} # set of graphs not to annotate again
self.blocked_blocks = {} # set of {blocked_block: graph}
# --- the following information is recorded for debugging only ---
# --- and only if annotation.model.DEBUG is kept to True
self.why_not_annotated = {
} # {block: (exc_type, exc_value, traceback)}
# records the location of BlockedInference
# exceptions that blocked some blocks.
self.blocked_graphs = {} # set of graphs that have blocked blocks
self.bindingshistory = {} # map Variables to lists of SomeValues
self.binding_caused_by = {} # map Variables to position_keys
# records the caller position that caused bindings of inputargs
# to be updated
self.binding_cause_history = {} # map Variables to lists of positions
# history of binding_caused_by, kept in sync with
# bindingshistory
self.reflowcounter = {}
self.return_bindings = {} # map return Variables to their graphs
# --- end of debugging information ---
self.frozen = False
if policy is None:
from pypy.annotation.policy import AnnotatorPolicy
self.policy = AnnotatorPolicy()
else:
self.policy = policy
if bookkeeper is None:
bookkeeper = Bookkeeper(self)
self.bookkeeper = bookkeeper
开发者ID:MichaelBlume,项目名称:pypy,代码行数:45,代码来源:annrpython.py
注:本文中的pypy.annotation.policy.AnnotatorPolicy类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论