[pypy-svn] r25407 - in pypy/dist/pypy: annotation jit/codegen/llvm rpython rpython/lltypesystem rpython/rctypes rpython/rctypes/test translator/c/test
arigo at codespeak.net
arigo at codespeak.net
Wed Apr 5 18:57:58 CEST 2006
Author: arigo
Date: Wed Apr 5 18:57:55 2006
New Revision: 25407
Modified:
pypy/dist/pypy/annotation/bookkeeper.py
pypy/dist/pypy/jit/codegen/llvm/rgenop.py
pypy/dist/pypy/rpython/extregistry.py
pypy/dist/pypy/rpython/lltypesystem/lloperation.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/rctypes/rprimitive.py
pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
pypy/dist/pypy/rpython/rgenop.py
pypy/dist/pypy/translator/c/test/test_wrapping.py
Log:
(arre, arigo)
Remove the 'compute_result_annotation' support from bookkeeper.py.
Replaced all usages with extregistry usage.
Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py (original)
+++ pypy/dist/pypy/annotation/bookkeeper.py Wed Apr 5 18:57:55 2006
@@ -359,10 +359,10 @@
result = SomeBuiltin(BUILTIN_ANALYZERS[x], methodname="%s.%s" % (_module, x.__name__))
elif extregistry.is_registered(x):
result = extregistry.lookup(x).get_annotation(tp, x)
- elif hasattr(x, "compute_result_annotation"):
- result = SomeBuiltin(x.compute_result_annotation, methodname=x.__name__)
- elif hasattr(tp, "compute_annotation"):
- result = tp.compute_annotation()
+## elif hasattr(x, "compute_result_annotation"):
+## result = SomeBuiltin(x.compute_result_annotation, methodname=x.__name__)
+## elif hasattr(tp, "compute_annotation"):
+## result = tp.compute_annotation()
elif tp in EXTERNAL_TYPE_ANALYZERS:
result = SomeExternalObject(tp)
elif isinstance(x, lltype._ptr):
@@ -515,8 +515,8 @@
return s_None
elif t in EXTERNAL_TYPE_ANALYZERS:
return SomeExternalObject(t)
- elif hasattr(t, "compute_annotation"):
- return t.compute_annotation()
+## elif hasattr(t, "compute_annotation"):
+## return t.compute_annotation()
elif extregistry.is_registered_type(t):
return extregistry.lookup_type(t).get_annotation(t)
elif t.__module__ != '__builtin__' and t not in self.pbctypes:
Modified: pypy/dist/pypy/jit/codegen/llvm/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/rgenop.py Wed Apr 5 18:57:55 2006
@@ -227,18 +227,25 @@
LINKPAIR = lltype.GcStruct('tuple2', *fields)
# helpers
-def setannotation(func, TYPE):
- func.compute_result_annotation = lambda *args_s: TYPE
-
-def setspecialize(func):
- # for now
- def specialize_as_direct_call(hop):
- FUNCTYPE = lltype.FuncType([r.lowleveltype for r in hop.args_r], hop.r_result.lowleveltype)
- args_v = hop.inputargs(*hop.args_r)
- funcptr = lltype.functionptr(FUNCTYPE, func.__name__, _callable=func)
- cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
- return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
- func.specialize = specialize_as_direct_call
+def setannotation(func, annotation, specialize_as_constant=False):
+ if specialize_as_constant:
+ def specialize(hop):
+ llvalue = func(hop.args_s[0].const)
+ return hop.inputconst(lltype.typeOf(llvalue), llvalue)
+ else:
+ # specialize as direct_call
+ def specialize(hop):
+ FUNCTYPE = lltype.FuncType([r.lowleveltype for r in hop.args_r],
+ hop.r_result.lowleveltype)
+ args_v = hop.inputargs(*hop.args_r)
+ funcptr = lltype.functionptr(FUNCTYPE, func.__name__,
+ _callable=func)
+ cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
+ return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
+
+ extregistry.register_value(func,
+ compute_result_annotation = annotation,
+ specialize_call = specialize)
# annotations
from pypy.annotation import model as annmodel
@@ -251,35 +258,17 @@
setannotation(geninputarg, s_ConstOrVar)
setannotation(genop, s_ConstOrVar)
setannotation(genconst, s_ConstOrVar)
-revealconst.compute_result_annotation = lambda s_T, s_gv: annmodel.lltype_to_annotation(s_T.const)
+setannotation(revealconst, lambda s_T, s_gv: annmodel.lltype_to_annotation(
+ s_T.const))
+setannotation(isconst, annmodel.SomeBool())
setannotation(closeblock1, s_Link)
setannotation(closeblock2, s_LinkPair)
setannotation(closelink, None)
setannotation(closereturnlink, None)
-# specialize
-setspecialize(initblock)
-setspecialize(geninputarg)
-setspecialize(genop)
-setspecialize(genconst)
-setspecialize(revealconst)
-setspecialize(closeblock1)
-setspecialize(closeblock2)
-setspecialize(closelink)
-setspecialize(closereturnlink)
+setannotation(isptrtype, annmodel.SomeBool())
# XXX(for now) void constant constructors
-setannotation(constFieldName, s_ConstOrVar)
-setannotation(constTYPE, s_ConstOrVar)
-setannotation(placeholder, s_ConstOrVar)
-
-def set_specialize_void_constant_constructor(func):
- # for now
- def specialize_as_constant(hop):
- llvalue = func(hop.args_s[0].const)
- return hop.inputconst(lltype.typeOf(llvalue), llvalue)
- func.specialize = specialize_as_constant
-
-set_specialize_void_constant_constructor(placeholder)
-set_specialize_void_constant_constructor(constFieldName)
-set_specialize_void_constant_constructor(constTYPE)
+setannotation(constFieldName, s_ConstOrVar, specialize_as_constant=True)
+setannotation(constTYPE, s_ConstOrVar, specialize_as_constant=True)
+setannotation(placeholder, s_ConstOrVar, specialize_as_constant=True)
Modified: pypy/dist/pypy/rpython/extregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/extregistry.py (original)
+++ pypy/dist/pypy/rpython/extregistry.py Wed Apr 5 18:57:55 2006
@@ -26,16 +26,18 @@
def create_annotation_callable(annotation):
from pypy.annotation import model as annmodel
- if isinstance(annotation, annmodel.SomeObject):
+ if isinstance(annotation, annmodel.SomeObject) or annotation is None:
s_result = annotation
def annotation(*args):
return s_result
return annotation
-def create_entry(compute_result_annotation=None, compute_annotation=None,
+undefined = object()
+
+def create_entry(compute_result_annotation=undefined, compute_annotation=None,
specialize_call=None, get_repr=None):
- if compute_result_annotation is not None:
+ if compute_result_annotation is not undefined:
compute_result_annotation = create_annotation_callable(
compute_result_annotation)
return ExtRegistryFunc(compute_result_annotation, specialize_call)
@@ -44,14 +46,17 @@
get_repr)
def register_value(value, **kwargs):
+ assert value not in EXT_REGISTRY_BY_VALUE
EXT_REGISTRY_BY_VALUE[value] = create_entry(**kwargs)
return EXT_REGISTRY_BY_VALUE[value]
def register_type(t, **kwargs):
+ assert t not in EXT_REGISTRY_BY_TYPE
EXT_REGISTRY_BY_TYPE[t] = create_entry(**kwargs)
return EXT_REGISTRY_BY_TYPE[t]
def register_metatype(t, **kwargs):
+ assert t not in EXT_REGISTRY_BY_METATYPE
EXT_REGISTRY_BY_METATYPE[t] = create_entry(**kwargs)
return EXT_REGISTRY_BY_METATYPE[t]
Modified: pypy/dist/pypy/rpython/lltypesystem/lloperation.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lloperation.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/lloperation.py Wed Apr 5 18:57:55 2006
@@ -2,6 +2,9 @@
The table of all LL operations.
"""
+from pypy.rpython import extregistry
+
+
class LLOp(object):
def __init__(self, sideeffects=True, canfold=False, canraise=(), pyobj=False):
@@ -25,6 +28,11 @@
# The operation manipulates PyObjects
self.pyobj = pyobj
+ # XXX refactor extregistry to allow a single registration
+ extregistry.register_value(self,
+ compute_result_annotation = self.compute_result_annotation,
+ specialize_call = self.specialize)
+
# __________ make the LLOp instances callable from LL helpers __________
__name__ = property(lambda self: 'llop_'+self.opname)
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Wed Apr 5 18:57:55 2006
@@ -66,9 +66,10 @@
bltintyper = rtyper.type_system.rbuiltin.\
BUILTIN_TYPER[self.builtinfunc]
except (KeyError, TypeError):
- if hasattr(self.builtinfunc,"specialize"):
- bltintyper = self.builtinfunc.specialize
- elif extregistry.is_registered(self.builtinfunc):
+## if hasattr(self.builtinfunc,"specialize"):
+## bltintyper = self.builtinfunc.specialize
+## else
+ if extregistry.is_registered(self.builtinfunc):
entry = extregistry.lookup(self.builtinfunc)
bltintyper = entry.specialize_call
else:
Modified: pypy/dist/pypy/rpython/rctypes/rprimitive.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rprimitive.py (original)
+++ pypy/dist/pypy/rpython/rctypes/rprimitive.py Wed Apr 5 18:57:55 2006
@@ -10,21 +10,21 @@
from pypy.rpython.error import TyperError
from pypy.rpython.rctypes.rmodel import CTypesValueRepr
-ctypes_annotation_list = [
- (c_char, lltype.Char),
- (c_byte, lltype.Signed),
- (c_ubyte, lltype.Unsigned),
- (c_short, lltype.Signed),
- (c_ushort, lltype.Unsigned),
- (c_int, lltype.Signed),
- (c_uint, lltype.Unsigned),
- (c_long, lltype.Signed),
- (c_ulong, lltype.Unsigned),
- (c_longlong, lltype.SignedLongLong),
- (c_ulonglong, lltype.UnsignedLongLong),
- (c_float, lltype.Float),
- (c_double, lltype.Float),
-]
+ctypes_annotation_list = {
+ c_char: lltype.Char,
+ c_byte: lltype.Signed,
+ c_ubyte: lltype.Unsigned,
+ c_short: lltype.Signed,
+ c_ushort: lltype.Unsigned,
+ c_int: lltype.Signed,
+ c_uint: lltype.Unsigned,
+ c_long: lltype.Signed,
+ c_ulong: lltype.Unsigned,
+ c_longlong: lltype.SignedLongLong,
+ c_ulonglong: lltype.UnsignedLongLong,
+ c_float: lltype.Float,
+ c_double: lltype.Float,
+}.items() # nb. platform-dependent duplicate ctypes are removed
class PrimitiveRepr(CTypesValueRepr):
Modified: pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py (original)
+++ pypy/dist/pypy/rpython/rctypes/test/test_rctypes.py Wed Apr 5 18:57:55 2006
@@ -264,7 +264,9 @@
# result should be an integer
assert s.knowntype == int
t.buildrtyper().specialize()
- #d#t.view()
+
+ if conftest.option.view:
+ a.translator.view()
def x_test_compile_simple(self):
fn = compile(o_atoi, [str])
Modified: pypy/dist/pypy/rpython/rgenop.py
==============================================================================
--- pypy/dist/pypy/rpython/rgenop.py (original)
+++ pypy/dist/pypy/rpython/rgenop.py Wed Apr 5 18:57:55 2006
@@ -10,6 +10,7 @@
from pypy.rpython.module.support import init_opaque_object
from pypy.rpython.module.support import to_opaque_object, from_opaque_object
from pypy.rpython.module.support import from_rstr
+from pypy.rpython import extregistry
# for debugging, sanity checks in non-RPython code
@@ -254,18 +255,25 @@
# helpers
-def setannotation(func, TYPE):
- func.compute_result_annotation = lambda *args_s: TYPE
-
-def setspecialize(func):
- # for now
- def specialize_as_direct_call(hop):
- FUNCTYPE = lltype.FuncType([r.lowleveltype for r in hop.args_r], hop.r_result.lowleveltype)
- args_v = hop.inputargs(*hop.args_r)
- funcptr = lltype.functionptr(FUNCTYPE, func.__name__, _callable=func)
- cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
- return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
- func.specialize = specialize_as_direct_call
+def setannotation(func, annotation, specialize_as_constant=False):
+ if specialize_as_constant:
+ def specialize(hop):
+ llvalue = func(hop.args_s[0].const)
+ return hop.inputconst(lltype.typeOf(llvalue), llvalue)
+ else:
+ # specialize as direct_call
+ def specialize(hop):
+ FUNCTYPE = lltype.FuncType([r.lowleveltype for r in hop.args_r],
+ hop.r_result.lowleveltype)
+ args_v = hop.inputargs(*hop.args_r)
+ funcptr = lltype.functionptr(FUNCTYPE, func.__name__,
+ _callable=func)
+ cfunc = hop.inputconst(lltype.Ptr(FUNCTYPE), funcptr)
+ return hop.genop('direct_call', [cfunc] + args_v, hop.r_result)
+
+ extregistry.register_value(func,
+ compute_result_annotation = annotation,
+ specialize_call = specialize)
# annotations
from pypy.annotation import model as annmodel
@@ -278,7 +286,8 @@
setannotation(geninputarg, s_ConstOrVar)
setannotation(genop, s_ConstOrVar)
setannotation(genconst, s_ConstOrVar)
-revealconst.compute_result_annotation = lambda s_T, s_gv: annmodel.lltype_to_annotation(s_T.const)
+setannotation(revealconst, lambda s_T, s_gv: annmodel.lltype_to_annotation(
+ s_T.const))
setannotation(isconst, annmodel.SomeBool())
setannotation(closeblock1, s_Link)
setannotation(closeblock2, s_LinkPair)
@@ -287,32 +296,7 @@
setannotation(isptrtype, annmodel.SomeBool())
-# specialize
-setspecialize(initblock)
-setspecialize(geninputarg)
-setspecialize(genop)
-setspecialize(genconst)
-setspecialize(revealconst)
-setspecialize(isconst)
-setspecialize(closeblock1)
-setspecialize(closeblock2)
-setspecialize(closelink)
-setspecialize(closereturnlink)
-
-setspecialize(isptrtype)
-
# XXX(for now) void constant constructors
-setannotation(constFieldName, s_ConstOrVar)
-setannotation(constTYPE, s_ConstOrVar)
-setannotation(placeholder, s_ConstOrVar)
-
-def set_specialize_void_constant_constructor(func):
- # for now
- def specialize_as_constant(hop):
- llvalue = func(hop.args_s[0].const)
- return hop.inputconst(lltype.typeOf(llvalue), llvalue)
- func.specialize = specialize_as_constant
-
-set_specialize_void_constant_constructor(placeholder)
-set_specialize_void_constant_constructor(constFieldName)
-set_specialize_void_constant_constructor(constTYPE)
+setannotation(constFieldName, s_ConstOrVar, specialize_as_constant=True)
+setannotation(constTYPE, s_ConstOrVar, specialize_as_constant=True)
+setannotation(placeholder, s_ConstOrVar, specialize_as_constant=True)
Modified: pypy/dist/pypy/translator/c/test/test_wrapping.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_wrapping.py (original)
+++ pypy/dist/pypy/translator/c/test/test_wrapping.py Wed Apr 5 18:57:55 2006
@@ -32,7 +32,6 @@
global t # allow us to view later
t = TranslationContext(do_imports_immediately=False)
- do_register(t)
t.buildannotator()
rtyper = t.buildrtyper()
bk = rtyper.annotator.bookkeeper
@@ -192,44 +191,33 @@
return null
-"""
-The following registers the new mappings. The registration
-had to be done from a function, because we need to pass the
-translator in.
-
-Note that these registrations are for explicit wrapping/unwrapping
-which was the first thing I tried. Meanwhile similar functionality
-has been added to rclass.py to support automatic wrapping.
-"""
-
-def do_register(t):
- def compute_annotation_unwrap(s_wrapper, s_class):
- assert hasattr(s_class, 'descriptions'), 'need a class in unwrap 2nd arg'
- descs = s_class.descriptions
- assert len(descs) == 1, 'missing specialisation, classdesc not unique!'
- for desc in descs.keys():
- classdef = desc.getuniqueclassdef()
- return annmodel.SomeInstance(classdef)
-
- extregistry.register_value(ll_create_pywrapper,
- compute_result_annotation=annmodel.SomePtr(lltype.Ptr(lltype.PyObject)),
- specialize_call=rtype_wrap_object_create)
-
- extregistry.register_value(ll_fetch_pywrapper,
- compute_result_annotation=annmodel.SomePtr(lltype.Ptr(lltype.PyObject)),
- specialize_call=rtype_wrap_object_fetch)
-
- extregistry.register_value(ll_call_destructor,
- compute_result_annotation=lambda *args: None,
- specialize_call=rtype_destruct_object)
-
- extregistry.register_value(wrap_obj,
- compute_result_annotation=annmodel.SomeObject(),
- specialize_call=rtype_wrap_object)
-
- extregistry.register_value(unwrap_obj,
- compute_result_annotation=compute_annotation_unwrap,
- specialize_call=rtype_unwrap_object)
+def compute_annotation_unwrap(s_wrapper, s_class):
+ assert hasattr(s_class, 'descriptions'), 'need a class in unwrap 2nd arg'
+ descs = s_class.descriptions
+ assert len(descs) == 1, 'missing specialisation, classdesc not unique!'
+ for desc in descs.keys():
+ classdef = desc.getuniqueclassdef()
+ return annmodel.SomeInstance(classdef)
+
+extregistry.register_value(ll_create_pywrapper,
+ compute_result_annotation=annmodel.SomePtr(lltype.Ptr(lltype.PyObject)),
+ specialize_call=rtype_wrap_object_create)
+
+extregistry.register_value(ll_fetch_pywrapper,
+ compute_result_annotation=annmodel.SomePtr(lltype.Ptr(lltype.PyObject)),
+ specialize_call=rtype_wrap_object_fetch)
+
+extregistry.register_value(ll_call_destructor,
+ compute_result_annotation=lambda *args: None,
+ specialize_call=rtype_destruct_object)
+
+extregistry.register_value(wrap_obj,
+ compute_result_annotation=annmodel.SomeObject(),
+ specialize_call=rtype_wrap_object)
+
+extregistry.register_value(unwrap_obj,
+ compute_result_annotation=compute_annotation_unwrap,
+ specialize_call=rtype_unwrap_object)
# _______________________________________________-
# the actual tests
@@ -344,8 +332,9 @@
def wraptest(obj):
return obj
-wraptest.compute_result_annotation = lambda *args: annmodel.SomeObject()
-wraptest.specialize = rtype_wraptest
+extregistry.register_value(wraptest,
+ compute_result_annotation = annmodel.SomeObject(),
+ specialize_call = rtype_wraptest)
# not sure what to do with the above.
# use genpickle facility to produce a plain function?
@@ -398,4 +387,4 @@
if __name__=='__main__':
test_expose_classes()
-
\ No newline at end of file
+
More information about the Pypy-commit
mailing list